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