Fixed spacing in db/debug/diff/externalstore/objectcache folder
[mediawiki.git] / includes / specials / SpecialBrokenRedirects.php
blobb2ddc2209cf42f058ccd531e63e2b71a999427d7
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 {
32 function __construct( $name = 'BrokenRedirects' ) {
33 parent::__construct( $name );
36 function isExpensive() {
37 return true;
40 function isSyndicated() {
41 return false;
44 function sortDescending() {
45 return false;
48 function getPageHeader() {
49 return $this->msg( 'brokenredirectstext' )->parseAsBlock();
52 function getQueryInfo() {
53 $dbr = wfGetDB( DB_SLAVE );
55 return array(
56 'tables' => array(
57 'redirect',
58 'p1' => 'page',
59 'p2' => 'page',
61 'fields' => array(
62 'namespace' => 'p1.page_namespace',
63 'title' => 'p1.page_title',
64 'value' => 'p1.page_title',
65 'rd_namespace',
66 'rd_title',
68 'conds' => array(
69 // Exclude pages that don't exist locally as wiki pages,
70 // but aren't "broken" either.
71 // Special pages and interwiki links
72 'rd_namespace >= 0',
73 'rd_interwiki IS NULL OR rd_interwiki = ' . $dbr->addQuotes( '' ),
74 'p2.page_namespace IS NULL',
76 'join_conds' => array(
77 'p1' => array( 'JOIN', array(
78 'rd_from=p1.page_id',
79 ) ),
80 'p2' => array( 'LEFT JOIN', array(
81 'rd_namespace=p2.page_namespace',
82 'rd_title=p2.page_title'
83 ) ),
88 /**
89 * @return array
91 function getOrderFields() {
92 return array( 'rd_namespace', 'rd_title', 'rd_from' );
95 /**
96 * @param Skin $skin
97 * @param object $result Result row
98 * @return string
100 function formatResult( $skin, $result ) {
101 $fromObj = Title::makeTitle( $result->namespace, $result->title );
102 if ( isset( $result->rd_title ) ) {
103 $toObj = Title::makeTitle( $result->rd_namespace, $result->rd_title );
104 } else {
105 $blinks = $fromObj->getBrokenLinksFrom(); # TODO: check for redirect, not for links
106 if ( $blinks ) {
107 $toObj = $blinks[0];
108 } else {
109 $toObj = false;
113 // $toObj may very easily be false if the $result list is cached
114 if ( !is_object( $toObj ) ) {
115 return '<del>' . Linker::link( $fromObj ) . '</del>';
118 $from = Linker::linkKnown(
119 $fromObj,
120 null,
121 array(),
122 array( 'redirect' => 'no' )
124 $links = array();
125 $links[] = Linker::linkKnown(
126 $fromObj,
127 $this->msg( 'brokenredirects-edit' )->escaped(),
128 array(),
129 array( 'action' => 'edit' )
131 $to = Linker::link(
132 $toObj,
133 null,
134 array(),
135 array(),
136 array( 'broken' )
138 $arr = $this->getLanguage()->getArrow();
140 $out = $from . $this->msg( 'word-separator' )->escaped();
142 if ( $this->getUser()->isAllowed( 'delete' ) ) {
143 $links[] = Linker::linkKnown(
144 $fromObj,
145 $this->msg( 'brokenredirects-delete' )->escaped(),
146 array(),
147 array( 'action' => 'delete' )
151 $out .= $this->msg( 'parentheses' )->rawParams( $this->getLanguage()->pipeList( $links ) )->escaped();
152 $out .= " {$arr} {$to}";
154 return $out;
157 protected function getGroupName() {
158 return 'maintenance';