31 require_once __DIR__ .
'/Maintenance.php';
40 parent::__construct();
42 $this->
addOption(
'async',
'Don\'t fix anything directly, just queue the jobs' );
43 $this->
addOption(
'title',
'Fix only redirects pointing to this page',
false,
true );
44 $this->
addOption(
'dry-run',
'Perform a dry run, fix nothing' );
69 'pa.page_namespace AS pa_namespace',
70 'pa.page_title AS pa_title',
71 'pb.page_namespace AS pb_namespace',
72 'pb.page_title AS pb_title',
75 'rd_from = pa.page_id',
76 'rd_namespace = pb.page_namespace',
77 'rd_title = pb.page_title',
79 'rd_interwiki IS NULL OR rd_interwiki = ' .
$dbr->addQuotes(
'' ),
80 'pb.page_is_redirect' => 1,
84 $conds[
'pb.page_namespace'] =
$title->getNamespace();
85 $conds[
'pb.page_title'] =
$title->getDBkey();
89 $res =
$dbr->select( $tables, $fields, $conds, __METHOD__ );
91 if ( !
$res->numRows() ) {
92 $this->
output(
"No double redirects found.\n" );
98 $processedTitles =
"\n";
100 foreach (
$res as $row ) {
101 $titleA = Title::makeTitle( $row->pa_namespace, $row->pa_title );
102 $titleB = Title::makeTitle( $row->pb_namespace, $row->pb_title );
103 if ( !$titleA->canExist() || !$titleB->canExist() ) {
104 $this->
error(
"Cannot fix redirect from" .
105 ( $titleA->canExist() ?
"" :
" invalid" ) .
" title " . $titleA->getPrefixedText()
107 ( $titleB->canExist() ?
"" :
" invalid" ) .
" target " . $titleB->getPrefixedText()
113 $processedTitles .=
"* [[$titleA]]\n";
116 'reason' =>
'maintenance',
117 'redirTitle' => $titleB->getPrefixedDBkey()
123 $this->
error(
"Error fixing " . $titleA->getPrefixedText()
124 .
": " .
$job->getLastError() .
"\n" );
128 if ( count( $jobs ) > DoubleRedirectJob::MAX_DR_JOBS_COUNTER ) {
134 if ( ++$n % 100 == 0 ) {
135 $this->
output(
"$n...\n" );
139 if ( count( $jobs ) ) {
142 $this->
output(
"$n double redirects processed" . $processedTitles .
"\n" );
145 protected function queueJobs( $jobs, $dryrun =
false ) {
146 $this->
output(
"Queuing batch of " . count( $jobs ) .
" double redirects.\n" );
147 MediaWikiServices::getInstance()->getJobQueueGroup()->push( $dryrun ? [] : $jobs );
152 require_once RUN_MAINTENANCE_IF_MAIN;
Fix any double redirects after moving a page.
Maintenance script that fixes double redirects.
queueJobs( $jobs, $dryrun=false)
__construct()
Default constructor.
execute()
Do the actual work.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
if(count( $args)< 1) $job