3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
21 namespace MediaWiki\SpecialPage
;
23 use MediaWiki\Title\Title
;
26 use Wikimedia\Rdbms\IDatabase
;
27 use Wikimedia\Rdbms\IResultWrapper
;
30 * Base class for a "wanted" query page like WantedPages, WantedTemplates, etc
33 * @ingroup SpecialPage
35 abstract class WantedQueryPage
extends QueryPage
{
36 public function isExpensive() {
40 public function isSyndicated() {
45 * Cache page existence for performance
47 * @param IDatabase $db
48 * @param IResultWrapper $res
50 protected function preprocessResults( $db, $res ) {
51 $this->executeLBFromResultWrapper( $res );
55 * Should formatResult() always check page existence, even if
56 * the results are fresh? This is a (hopefully temporary)
57 * kluge for Special:WantedFiles, which may contain false
58 * positives for files that exist e.g. in a shared repo (bug
63 protected function forceExistenceCheck() {
68 * Format an individual result
72 * @param Skin $skin Skin to use for UI elements
73 * @param stdClass $result Result row
76 public function formatResult( $skin, $result ) {
77 $linkRenderer = $this->getLinkRenderer();
78 $title = Title
::makeTitleSafe( $result->namespace, $result->title
);
79 if ( $title instanceof Title
) {
80 if ( $this->isCached() ||
$this->forceExistenceCheck() ) {
81 $pageLink = $this->existenceCheck( $title )
82 ?
'<del>' . $linkRenderer->makeLink( $title ) . '</del>'
83 : $linkRenderer->makeLink( $title );
85 $pageLink = $linkRenderer->makeBrokenLink( $title );
87 return $this->getLanguage()->specialList( $pageLink, $this->makeWlhLink( $title, $result ) );
89 return $this->msg( 'wantedpages-badtitle', $result->title
)->escaped();
94 * Does the Title currently exists
96 * This method allows a subclass to override this check
97 * (For example, wantedfiles, would want to check if the file exists
98 * not just that a page in the file namespace exists).
100 * This will only control if the link is crossed out. Whether or not the link
101 * is blue vs red is controlled by if the title exists.
103 * @note This will only be run if the page is cached (ie $wgMiserMode = true)
104 * unless forceExistenceCheck() is true.
106 * @stable to override
108 * @param Title $title
111 protected function existenceCheck( Title
$title ) {
112 return $title->isKnown();
116 * Make a "what links here" link for a given title
118 * @param Title $title Title to make the link for
119 * @param stdClass $result Result row
122 protected function makeWlhLink( $title, $result ) {
123 $wlh = SpecialPage
::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
124 $label = $this->msg( 'nlinks' )->numParams( $result->value
)->text();
125 return $this->getLinkRenderer()->makeLink( $wlh, $label );
129 * Order by title for pages with the same number of links to them
131 * @stable to override
135 protected function getOrderFields() {
136 return [ 'value DESC', 'namespace', 'title' ];
140 * Do not order descending for all order fields. We will use DESC only on one field, see
141 * getOrderFields above. This overwrites sortDescending from QueryPage::getOrderFields().
142 * Do NOT change this to true unless you remove the phrase DESC in getOrderFields above.
143 * If you do a database error will be thrown due to double adding DESC to query!
145 * @stable to override
149 protected function sortDescending() {
154 * Also use the order fields returned by getOrderFields when fetching from the cache.
155 * @stable to override
159 protected function getCacheOrderFields() {
160 return $this->getOrderFields();
165 /** @deprecated class alias since 1.41 */
166 class_alias( WantedQueryPage
::class, 'WantedQueryPage' );