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 MediaWiki\MediaWikiServices
;
25 use Wikimedia\Rdbms\IResultWrapper
;
26 use Wikimedia\Rdbms\IDatabase
;
29 * A special page listing redirects to non existent page. Those should be
30 * fixed to point to an existing page.
32 * @ingroup SpecialPage
34 class SpecialBrokenRedirects
extends QueryPage
{
35 function __construct( $name = 'BrokenRedirects' ) {
36 parent
::__construct( $name );
39 public function isExpensive() {
43 function isSyndicated() {
47 function sortDescending() {
51 function getPageHeader() {
52 return $this->msg( 'brokenredirectstext' )->parseAsBlock();
55 public function getQueryInfo() {
56 $dbr = wfGetDB( DB_REPLICA
);
65 'namespace' => 'p1.page_namespace',
66 'title' => 'p1.page_title',
72 // Exclude pages that don't exist locally as wiki pages,
73 // but aren't "broken" either.
74 // Special pages and interwiki links
76 'rd_interwiki IS NULL OR rd_interwiki = ' . $dbr->addQuotes( '' ),
77 'p2.page_namespace IS NULL',
83 'p2' => [ 'LEFT JOIN', [
84 'rd_namespace=p2.page_namespace',
85 'rd_title=p2.page_title'
94 function getOrderFields() {
95 return [ 'rd_namespace', 'rd_title', 'rd_from' ];
100 * @param object $result Result row
103 function formatResult( $skin, $result ) {
104 $fromObj = Title
::makeTitle( $result->namespace, $result->title
);
105 if ( isset( $result->rd_title
) ) {
106 $toObj = Title
::makeTitle( $result->rd_namespace
, $result->rd_title
, $result->rd_fragment
);
108 $blinks = $fromObj->getBrokenLinksFrom(); # TODO: check for redirect, not for links
116 $linkRenderer = $this->getLinkRenderer();
117 $permissionManager = MediaWikiServices
::getInstance()->getPermissionManager();
119 // $toObj may very easily be false if the $result list is cached
120 if ( !is_object( $toObj ) ) {
121 return '<del>' . $linkRenderer->makeLink( $fromObj ) . '</del>';
124 $from = $linkRenderer->makeKnownLink(
128 [ 'redirect' => 'no' ]
131 // if the page is editable, add an edit link
133 // check user permissions
134 $permissionManager->userHasRight( $this->getUser(), 'edit' ) &&
135 // check, if the content model is editable through action=edit
136 ContentHandler
::getForTitle( $fromObj )->supportsDirectEditing()
138 $links[] = $linkRenderer->makeKnownLink(
140 $this->msg( 'brokenredirects-edit' )->text(),
142 [ 'action' => 'edit' ]
145 $to = $linkRenderer->makeBrokenLink( $toObj, $toObj->getFullText() );
146 $arr = $this->getLanguage()->getArrow();
148 $out = $from . $this->msg( 'word-separator' )->escaped();
150 if ( $permissionManager->userHasRight( $this->getUser(), 'delete' ) ) {
151 $links[] = $linkRenderer->makeKnownLink(
153 $this->msg( 'brokenredirects-delete' )->text(),
155 [ 'action' => 'delete' ]
160 $out .= $this->msg( 'parentheses' )->rawParams( $this->getLanguage()
161 ->pipeList( $links ) )->escaped();
163 $out .= " {$arr} {$to}";
168 public function execute( $par ) {
169 $this->addHelpLink( 'Help:Redirects' );
170 parent
::execute( $par );
174 * Cache page content model for performance
176 * @param IDatabase $db
177 * @param IResultWrapper $res
179 function preprocessResults( $db, $res ) {
180 $this->executeLBFromResultWrapper( $res );
183 protected function getGroupName() {
184 return 'maintenance';