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