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