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
|
|
|
|
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" );
|
2015-12-31 00:07:37 +00:00
|
|
|
$dbr = $this->getDB( DB_SLAVE );
|
2009-08-02 19:35:17 +00:00
|
|
|
$result = $dbr->select(
|
|
|
|
|
array( 'page' ),
|
2010-05-22 16:50:39 +00:00
|
|
|
array( 'page_namespace', 'page_title', 'page_latest' ),
|
2009-08-02 19:35:17 +00:00
|
|
|
array( 'page_is_redirect' => 1 ) );
|
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
|
|
|
|
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 );
|
|
|
|
|
$rev = Revision::newFromId( $row->page_latest );
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( $rev ) {
|
2012-06-11 10:35:46 +00:00
|
|
|
$target = $rev->getContent()->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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$maintClass = "CheckBadRedirects";
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|