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