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
21 * @ingroup SpecialPage
24 use Wikimedia\Rdbms\ResultWrapper
;
27 * A special page listing redirects to non existent page. Those should be
28 * fixed to point to an existing page.
30 * @ingroup SpecialPage
32 class BrokenRedirectsPage
extends QueryPage
{
33 function __construct( $name = 'BrokenRedirects' ) {
34 parent
::__construct( $name );
37 public function isExpensive() {
41 function isSyndicated() {
45 function sortDescending() {
49 function getPageHeader() {
50 return $this->msg( 'brokenredirectstext' )->parseAsBlock();
53 public function getQueryInfo() {
54 $dbr = wfGetDB( DB_REPLICA
);
63 'namespace' => 'p1.page_namespace',
64 'title' => 'p1.page_title',
65 'value' => 'p1.page_title',
70 // Exclude pages that don't exist locally as wiki pages,
71 // but aren't "broken" either.
72 // Special pages and interwiki links
74 'rd_interwiki IS NULL OR rd_interwiki = ' . $dbr->addQuotes( '' ),
75 'p2.page_namespace IS NULL',
81 'p2' => [ 'LEFT JOIN', [
82 'rd_namespace=p2.page_namespace',
83 'rd_title=p2.page_title'
92 function getOrderFields() {
93 return [ 'rd_namespace', 'rd_title', 'rd_from' ];
98 * @param object $result Result row
101 function formatResult( $skin, $result ) {
102 $fromObj = Title
::makeTitle( $result->namespace, $result->title
);
103 if ( isset( $result->rd_title
) ) {
104 $toObj = Title
::makeTitle( $result->rd_namespace
, $result->rd_title
);
106 $blinks = $fromObj->getBrokenLinksFrom(); # TODO: check for redirect, not for links
114 $linkRenderer = $this->getLinkRenderer();
115 // $toObj may very easily be false if the $result list is cached
116 if ( !is_object( $toObj ) ) {
117 return '<del>' . $linkRenderer->makeLink( $fromObj ) . '</del>';
120 $from = $linkRenderer->makeKnownLink(
124 [ 'redirect' => 'no' ]
127 // if the page is editable, add an edit link
129 // check user permissions
130 $this->getUser()->isAllowed( 'edit' ) &&
131 // check, if the content model is editable through action=edit
132 ContentHandler
::getForTitle( $fromObj )->supportsDirectEditing()
134 $links[] = $linkRenderer->makeKnownLink(
136 $this->msg( 'brokenredirects-edit' )->text(),
138 [ 'action' => 'edit' ]
141 $to = $linkRenderer->makeBrokenLink( $toObj );
142 $arr = $this->getLanguage()->getArrow();
144 $out = $from . $this->msg( 'word-separator' )->escaped();
146 if ( $this->getUser()->isAllowed( 'delete' ) ) {
147 $links[] = $linkRenderer->makeKnownLink(
149 $this->msg( 'brokenredirects-delete' )->text(),
151 [ 'action' => 'delete' ]
156 $out .= $this->msg( 'parentheses' )->rawParams( $this->getLanguage()
157 ->pipeList( $links ) )->escaped();
159 $out .= " {$arr} {$to}";
165 * Cache page content model for performance
167 * @param IDatabase $db
168 * @param ResultWrapper $res
170 function preprocessResults( $db, $res ) {
171 $this->executeLBFromResultWrapper( $res );
174 protected function getGroupName() {
175 return 'maintenance';