1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
<?php
/**
* Class definition for a wanted query page.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @ingroup SpecialPage
*/
/**
* Class definition for a wanted query page like
* WantedPages, WantedTemplates, etc
* @ingroup SpecialPage
*/
abstract class WantedQueryPage extends QueryPage {
function isExpensive() {
return true;
}
function isSyndicated() {
return false;
}
/**
* Cache page existence for performance
* @param IDatabase $db
* @param ResultWrapper $res
*/
function preprocessResults( $db, $res ) {
if ( !$res->numRows() ) {
return;
}
$batch = new LinkBatch;
foreach ( $res as $row ) {
$batch->add( $row->namespace, $row->title );
}
$batch->execute();
// Back to start for display
$res->seek( 0 );
}
/**
* Should formatResult() always check page existence, even if
* the results are fresh? This is a (hopefully temporary)
* kluge for Special:WantedFiles, which may contain false
* positives for files that exist e.g. in a shared repo (bug
* 6220).
* @return bool
*/
function forceExistenceCheck() {
return false;
}
/**
* Format an individual result
*
* @param Skin $skin Skin to use for UI elements
* @param object $result Result row
* @return string
*/
public function formatResult( $skin, $result ) {
$title = Title::makeTitleSafe( $result->namespace, $result->title );
if ( $title instanceof Title ) {
if ( $this->isCached() || $this->forceExistenceCheck() ) {
$pageLink = $this->existenceCheck( $title )
? '<del>' . Linker::link( $title ) . '</del>'
: Linker::link( $title );
} else {
$pageLink = Linker::link(
$title,
null,
array(),
array(),
array( 'broken' )
);
}
return $this->getLanguage()->specialList( $pageLink, $this->makeWlhLink( $title, $result ) );
} else {
return $this->msg( 'wantedpages-badtitle', $result->title )->escaped();
}
}
/**
* Does the Title currently exists
*
* This method allows a subclass to override this check
* (For example, wantedfiles, would want to check if the file exists
* not just that a page in the file namespace exists).
*
* This will only control if the link is crossed out. Whether or not the link
* is blue vs red is controlled by if the title exists.
*
* @note This will only be run if the page is cached (ie $wgMiserMode = true)
* unless forceExistenceCheck() is true.
* @since 1.24
* @return bool
*/
protected function existenceCheck( Title $title ) {
return $title->isKnown();
}
/**
* Make a "what links here" link for a given title
*
* @param Title $title Title to make the link for
* @param object $result Result row
* @return string
*/
private function makeWlhLink( $title, $result ) {
$wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
$label = $this->msg( 'nlinks' )->numParams( $result->value )->escaped();
return Linker::link( $wlh, $label );
}
}
|