Merge "Add CollationFa"
[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 /**
25 * Class definition for a wanted query page like
26 * WantedPages, WantedTemplates, etc
27 * @ingroup SpecialPage
28 */
29 abstract class WantedQueryPage extends QueryPage {
30 function isExpensive() {
31 return true;
32 }
33
34 function isSyndicated() {
35 return false;
36 }
37
38 /**
39 * Cache page existence for performance
40 * @param IDatabase $db
41 * @param ResultWrapper $res
42 */
43 function preprocessResults( $db, $res ) {
44 $this->executeLBFromResultWrapper( $res );
45 }
46
47 /**
48 * Should formatResult() always check page existence, even if
49 * the results are fresh? This is a (hopefully temporary)
50 * kluge for Special:WantedFiles, which may contain false
51 * positives for files that exist e.g. in a shared repo (bug
52 * 6220).
53 * @return bool
54 */
55 function forceExistenceCheck() {
56 return false;
57 }
58
59 /**
60 * Format an individual result
61 *
62 * @param Skin $skin Skin to use for UI elements
63 * @param object $result Result row
64 * @return string
65 */
66 public function formatResult( $skin, $result ) {
67 $linkRenderer = $this->getLinkRenderer();
68 $title = Title::makeTitleSafe( $result->namespace, $result->title );
69 if ( $title instanceof Title ) {
70 if ( $this->isCached() || $this->forceExistenceCheck() ) {
71 $pageLink = $this->existenceCheck( $title )
72 ? '<del>' . $linkRenderer->makeLink( $title ) . '</del>'
73 : $linkRenderer->makeLink( $title );
74 } else {
75 $pageLink = $linkRenderer->makeLink(
76 $title,
77 null,
78 [],
79 [],
80 [ 'broken' ]
81 );
82 }
83 return $this->getLanguage()->specialList( $pageLink, $this->makeWlhLink( $title, $result ) );
84 } else {
85 return $this->msg( 'wantedpages-badtitle', $result->title )->escaped();
86 }
87 }
88
89 /**
90 * Does the Title currently exists
91 *
92 * This method allows a subclass to override this check
93 * (For example, wantedfiles, would want to check if the file exists
94 * not just that a page in the file namespace exists).
95 *
96 * This will only control if the link is crossed out. Whether or not the link
97 * is blue vs red is controlled by if the title exists.
98 *
99 * @note This will only be run if the page is cached (ie $wgMiserMode = true)
100 * unless forceExistenceCheck() is true.
101 * @since 1.24
102 * @return bool
103 */
104 protected function existenceCheck( Title $title ) {
105 return $title->isKnown();
106 }
107
108 /**
109 * Make a "what links here" link for a given title
110 *
111 * @param Title $title Title to make the link for
112 * @param object $result Result row
113 * @return string
114 */
115 private function makeWlhLink( $title, $result ) {
116 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
117 $label = $this->msg( 'nlinks' )->numParams( $result->value )->escaped();
118 return Linker::link( $wlh, $label );
119 }
120 }