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
|
|
|
|
2024-10-16 00:39:55 +00:00
|
|
|
use MediaWiki\Maintenance\Maintenance;
|
2020-06-03 00:04:27 +00:00
|
|
|
use MediaWiki\Revision\SlotRecord;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2020-06-03 00:04:27 +00:00
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
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" );
|
2024-01-17 18:53:40 +00:00
|
|
|
$dbr = $this->getReplicaDB();
|
2022-07-11 13:51:08 +00:00
|
|
|
$result = $dbr->newSelectQueryBuilder()
|
|
|
|
|
->select( [ 'page_namespace', 'page_title', 'page_latest' ] )
|
|
|
|
|
->from( 'page' )
|
|
|
|
|
->where( [ 'page_is_redirect' => 1 ] )
|
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
|
->fetchResultSet();
|
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
|
|
|
|
2023-08-31 09:21:12 +00:00
|
|
|
$revLookup = $this->getServiceContainer()->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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
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;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|