Merge "Special:Upload should not crash on failing previews"
[mediawiki.git] / includes / specials / SpecialBrokenRedirects.php
blobb730ecd789d1c613040c7a9493b0f9623a0a823f
1 <?php
2 /**
3 * Implements Special:Brokenredirects
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.
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.
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
20 * @file
21 * @ingroup SpecialPage
24 /**
25 * A special page listing redirects to non existent page. Those should be
26 * fixed to point to an existing page.
28 * @ingroup SpecialPage
30 class BrokenRedirectsPage extends QueryPage {
31 function __construct( $name = 'BrokenRedirects' ) {
32 parent::__construct( $name );
35 public function isExpensive() {
36 return true;
39 function isSyndicated() {
40 return false;
43 function sortDescending() {
44 return false;
47 function getPageHeader() {
48 return $this->msg( 'brokenredirectstext' )->parseAsBlock();
51 public function getQueryInfo() {
52 $dbr = wfGetDB( DB_REPLICA );
54 return [
55 'tables' => [
56 'redirect',
57 'p1' => 'page',
58 'p2' => 'page',
60 'fields' => [
61 'namespace' => 'p1.page_namespace',
62 'title' => 'p1.page_title',
63 'value' => 'p1.page_title',
64 'rd_namespace',
65 'rd_title',
67 'conds' => [
68 // Exclude pages that don't exist locally as wiki pages,
69 // but aren't "broken" either.
70 // Special pages and interwiki links
71 'rd_namespace >= 0',
72 'rd_interwiki IS NULL OR rd_interwiki = ' . $dbr->addQuotes( '' ),
73 'p2.page_namespace IS NULL',
75 'join_conds' => [
76 'p1' => [ 'JOIN', [
77 'rd_from=p1.page_id',
78 ] ],
79 'p2' => [ 'LEFT JOIN', [
80 'rd_namespace=p2.page_namespace',
81 'rd_title=p2.page_title'
82 ] ],
87 /**
88 * @return array
90 function getOrderFields() {
91 return [ 'rd_namespace', 'rd_title', 'rd_from' ];
94 /**
95 * @param Skin $skin
96 * @param object $result Result row
97 * @return string
99 function formatResult( $skin, $result ) {
100 $fromObj = Title::makeTitle( $result->namespace, $result->title );
101 if ( isset( $result->rd_title ) ) {
102 $toObj = Title::makeTitle( $result->rd_namespace, $result->rd_title );
103 } else {
104 $blinks = $fromObj->getBrokenLinksFrom(); # TODO: check for redirect, not for links
105 if ( $blinks ) {
106 $toObj = $blinks[0];
107 } else {
108 $toObj = false;
112 $linkRenderer = $this->getLinkRenderer();
113 // $toObj may very easily be false if the $result list is cached
114 if ( !is_object( $toObj ) ) {
115 return '<del>' . $linkRenderer->makeLink( $fromObj ) . '</del>';
118 $from = $linkRenderer->makeKnownLink(
119 $fromObj,
120 null,
122 [ 'redirect' => 'no' ]
124 $links = [];
125 // if the page is editable, add an edit link
126 if (
127 // check user permissions
128 $this->getUser()->isAllowed( 'edit' ) &&
129 // check, if the content model is editable through action=edit
130 ContentHandler::getForTitle( $fromObj )->supportsDirectEditing()
132 $links[] = $linkRenderer->makeKnownLink(
133 $fromObj,
134 $this->msg( 'brokenredirects-edit' )->text(),
136 [ 'action' => 'edit' ]
139 $to = $linkRenderer->makeBrokenLink( $toObj );
140 $arr = $this->getLanguage()->getArrow();
142 $out = $from . $this->msg( 'word-separator' )->escaped();
144 if ( $this->getUser()->isAllowed( 'delete' ) ) {
145 $links[] = $linkRenderer->makeKnownLink(
146 $fromObj,
147 $this->msg( 'brokenredirects-delete' )->text(),
149 [ 'action' => 'delete' ]
153 if ( $links ) {
154 $out .= $this->msg( 'parentheses' )->rawParams( $this->getLanguage()
155 ->pipeList( $links ) )->escaped();
157 $out .= " {$arr} {$to}";
159 return $out;
163 * Cache page content model for performance
165 * @param IDatabase $db
166 * @param ResultWrapper $res
168 function preprocessResults( $db, $res ) {
169 $this->executeLBFromResultWrapper( $res );
172 protected function getGroupName() {
173 return 'maintenance';