Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 1 |
WantedQueryPage | |
0.00% |
0 / 21 |
|
0.00% |
0 / 10 |
210 | |
0.00% |
0 / 1 |
isExpensive | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isSyndicated | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
preprocessResults | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
forceExistenceCheck | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
formatResult | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
30 | |||
existenceCheck | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
makeWlhLink | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getOrderFields | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
sortDescending | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getCacheOrderFields | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | namespace MediaWiki\SpecialPage; |
22 | |
23 | use MediaWiki\Title\Title; |
24 | use Skin; |
25 | use stdClass; |
26 | use Wikimedia\Rdbms\IDatabase; |
27 | use Wikimedia\Rdbms\IResultWrapper; |
28 | |
29 | /** |
30 | * Base class for a "wanted" query page like WantedPages, WantedTemplates, etc |
31 | * |
32 | * @stable to extend |
33 | * @ingroup SpecialPage |
34 | */ |
35 | abstract class WantedQueryPage extends QueryPage { |
36 | public function isExpensive() { |
37 | return true; |
38 | } |
39 | |
40 | public function isSyndicated() { |
41 | return false; |
42 | } |
43 | |
44 | /** |
45 | * Cache page existence for performance |
46 | * @stable to override |
47 | * @param IDatabase $db |
48 | * @param IResultWrapper $res |
49 | */ |
50 | protected function preprocessResults( $db, $res ) { |
51 | $this->executeLBFromResultWrapper( $res ); |
52 | } |
53 | |
54 | /** |
55 | * Should formatResult() always check page existence, even if |
56 | * the results are fresh? This is a (hopefully temporary) |
57 | * kluge for Special:WantedFiles, which may contain false |
58 | * positives for files that exist e.g. in a shared repo (bug |
59 | * 6220). |
60 | * @stable to override |
61 | * @return bool |
62 | */ |
63 | protected function forceExistenceCheck() { |
64 | return false; |
65 | } |
66 | |
67 | /** |
68 | * Format an individual result |
69 | * |
70 | * @stable to override |
71 | * |
72 | * @param Skin $skin Skin to use for UI elements |
73 | * @param stdClass $result Result row |
74 | * @return string |
75 | */ |
76 | public function formatResult( $skin, $result ) { |
77 | $linkRenderer = $this->getLinkRenderer(); |
78 | $title = Title::makeTitleSafe( $result->namespace, $result->title ); |
79 | if ( $title instanceof Title ) { |
80 | if ( $this->isCached() || $this->forceExistenceCheck() ) { |
81 | $pageLink = $this->existenceCheck( $title ) |
82 | ? '<del>' . $linkRenderer->makeLink( $title ) . '</del>' |
83 | : $linkRenderer->makeLink( $title ); |
84 | } else { |
85 | $pageLink = $linkRenderer->makeBrokenLink( $title ); |
86 | } |
87 | return $this->getLanguage()->specialList( $pageLink, $this->makeWlhLink( $title, $result ) ); |
88 | } else { |
89 | return $this->msg( 'wantedpages-badtitle', $result->title )->escaped(); |
90 | } |
91 | } |
92 | |
93 | /** |
94 | * Does the Title currently exists |
95 | * |
96 | * This method allows a subclass to override this check |
97 | * (For example, wantedfiles, would want to check if the file exists |
98 | * not just that a page in the file namespace exists). |
99 | * |
100 | * This will only control if the link is crossed out. Whether or not the link |
101 | * is blue vs red is controlled by if the title exists. |
102 | * |
103 | * @note This will only be run if the page is cached (ie $wgMiserMode = true) |
104 | * unless forceExistenceCheck() is true. |
105 | * @since 1.24 |
106 | * @stable to override |
107 | * |
108 | * @param Title $title |
109 | * @return bool |
110 | */ |
111 | protected function existenceCheck( Title $title ) { |
112 | return $title->isKnown(); |
113 | } |
114 | |
115 | /** |
116 | * Make a "what links here" link for a given title |
117 | * |
118 | * @param Title $title Title to make the link for |
119 | * @param stdClass $result Result row |
120 | * @return string |
121 | */ |
122 | protected function makeWlhLink( $title, $result ) { |
123 | $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() ); |
124 | $label = $this->msg( 'nlinks' )->numParams( $result->value )->text(); |
125 | return $this->getLinkRenderer()->makeLink( $wlh, $label ); |
126 | } |
127 | |
128 | /** |
129 | * Order by title for pages with the same number of links to them |
130 | * |
131 | * @stable to override |
132 | * @return array |
133 | * @since 1.29 |
134 | */ |
135 | protected function getOrderFields() { |
136 | return [ 'value DESC', 'namespace', 'title' ]; |
137 | } |
138 | |
139 | /** |
140 | * Do not order descending for all order fields. We will use DESC only on one field, see |
141 | * getOrderFields above. This overwrites sortDescending from QueryPage::getOrderFields(). |
142 | * Do NOT change this to true unless you remove the phrase DESC in getOrderFields above. |
143 | * If you do a database error will be thrown due to double adding DESC to query! |
144 | * |
145 | * @stable to override |
146 | * @return bool |
147 | * @since 1.29 |
148 | */ |
149 | protected function sortDescending() { |
150 | return false; |
151 | } |
152 | |
153 | /** |
154 | * Also use the order fields returned by getOrderFields when fetching from the cache. |
155 | * @stable to override |
156 | * @return array |
157 | * @since 1.29 |
158 | */ |
159 | protected function getCacheOrderFields() { |
160 | return $this->getOrderFields(); |
161 | } |
162 | |
163 | } |
164 | |
165 | /** @deprecated class alias since 1.41 */ |
166 | class_alias( WantedQueryPage::class, 'WantedQueryPage' ); |