2008-08-09 00:17:00 +00:00
|
|
|
<?php
|
2009-08-02 19:35:17 +00:00
|
|
|
/**
|
2012-06-16 20:35:13 +00:00
|
|
|
* Check that pages marked as being redirects really are.
|
2009-08-02 19:35:17 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2010-10-03 09:25:28 +00:00
|
|
|
* @file
|
2009-08-02 19:35:17 +00:00
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2020-06-03 00:04:27 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
use MediaWiki\Revision\SlotRecord;
|
|
|
|
|
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2008-08-09 00:17:00 +00:00
|
|
|
|
2012-06-16 20:35:13 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script to check that pages marked as being redirects really are.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2009-08-02 19:35:17 +00:00
|
|
|
class CheckBadRedirects extends Maintenance {
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription( 'Check for bad redirects' );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2008-08-09 00:17:00 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function execute() {
|
|
|
|
|
$this->output( "Fetching redirects...\n" );
|
2016-09-05 19:55:19 +00:00
|
|
|
$dbr = $this->getDB( DB_REPLICA );
|
2009-08-02 19:35:17 +00:00
|
|
|
$result = $dbr->select(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'page' ],
|
|
|
|
|
[ 'page_namespace', 'page_title', 'page_latest' ],
|
2020-06-07 16:23:08 +00:00
|
|
|
[ 'page_is_redirect' => 1 ],
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$count = $result->numRows();
|
2011-03-17 09:05:34 +00:00
|
|
|
$this->output( "Found $count redirects.\n" .
|
2014-04-23 18:08:42 +00:00
|
|
|
"Checking for bad redirects:\n\n" );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2020-06-03 00:04:27 +00:00
|
|
|
$revLookup = MediaWikiServices::getInstance()->getRevisionLookup();
|
2010-05-22 16:50:39 +00:00
|
|
|
foreach ( $result as $row ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
$title = Title::makeTitle( $row->page_namespace, $row->page_title );
|
2020-06-03 00:04:27 +00:00
|
|
|
$revRecord = $revLookup->getRevisionById( $row->page_latest );
|
|
|
|
|
if ( $revRecord ) {
|
|
|
|
|
$target = $revRecord->getContent( SlotRecord::MAIN )->getRedirectTarget();
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( !$target ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->output( $title->getPrefixedText() . "\n" );
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-08-09 00:17:00 +00:00
|
|
|
}
|
2011-03-17 09:05:34 +00:00
|
|
|
$this->output( "\nDone.\n" );
|
2008-08-09 00:17:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = CheckBadRedirects::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|