Merge "Fix uncaught ApiFormatXml exception with api debuginfo"
[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 DatabaseBase $db
41 * @param ResultWrapper $res
42 */
43 function preprocessResults( $db, $res ) {
44 if ( !$res->numRows() ) {
45 return;
46 }
47
48 $batch = new LinkBatch;
49 foreach ( $res as $row ) {
50 $batch->add( $row->namespace, $row->title );
51 }
52 $batch->execute();
53
54 // Back to start for display
55 $res->seek( 0 );
56 }
57
58 /**
59 * Should formatResult() always check page existence, even if
60 * the results are fresh? This is a (hopefully temporary)
61 * kluge for Special:WantedFiles, which may contain false
62 * positives for files that exist e.g. in a shared repo (bug
63 * 6220).
64 * @return bool
65 */
66 function forceExistenceCheck() {
67 return false;
68 }
69
70 /**
71 * Format an individual result
72 *
73 * @param Skin $skin Skin to use for UI elements
74 * @param object $result Result row
75 * @return string
76 */
77 public function formatResult( $skin, $result ) {
78 $title = Title::makeTitleSafe( $result->namespace, $result->title );
79 if ( $title instanceof Title ) {
80 if ( $this->isCached() || $this->forceExistenceCheck() ) {
81 $pageLink = $title->isKnown()
82 ? '<del>' . Linker::link( $title ) . '</del>'
83 : Linker::link(
84 $title,
85 null,
86 array(),
87 array(),
88 array( 'broken' )
89 );
90 } else {
91 $pageLink = Linker::link(
92 $title,
93 null,
94 array(),
95 array(),
96 array( 'broken' )
97 );
98 }
99 return $this->getLanguage()->specialList( $pageLink, $this->makeWlhLink( $title, $result ) );
100 } else {
101 return $this->msg( 'wantedpages-badtitle', $result->title )->escaped();
102 }
103 }
104
105 /**
106 * Make a "what links here" link for a given title
107 *
108 * @param Title $title Title to make the link for
109 * @param object $result Result row
110 * @return string
111 */
112 private function makeWlhLink( $title, $result ) {
113 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
114 $label = $this->msg( 'nlinks' )->numParams( $result->value )->escaped();
115 return Linker::link( $wlh, $label );
116 }
117 }