49 $async = $this->hasOption(
'async' );
50 $dryrun = $this->hasOption(
'dry-run' );
52 if ( $this->hasOption(
'title' ) ) {
53 $title = Title::newFromText( $this->getOption(
'title' ) );
54 if ( !$title || !$title->isRedirect() ) {
55 $this->fatalError( $title->getPrefixedText() .
" is not a redirect!\n" );
61 $dbr = $this->getReplicaDB();
65 $queryBuilder = $dbr->newSelectQueryBuilder()
67 'pa_namespace' =>
'pa.page_namespace',
68 'pa_title' =>
'pa.page_title',
69 'pb_namespace' =>
'pb.page_namespace',
70 'pb_title' =>
'pb.page_title',
73 ->join(
'page',
'pa',
'rd_from = pa.page_id' )
74 ->join(
'page',
'pb', [
'rd_namespace = pb.page_namespace',
'rd_title = pb.page_title' ] )
76 ->where( [
'rd_interwiki' =>
'',
'pb.page_is_redirect' => 1 ] );
78 if ( $title !=
null ) {
79 $queryBuilder->andWhere( [
80 'pb.page_namespace' => $title->getNamespace(),
81 'pb.page_title' => $title->getDBkey()
84 $res = $queryBuilder->caller( __METHOD__ )->fetchResultSet();
86 if ( !$res->numRows() ) {
87 $this->output(
"No double redirects found.\n" );
93 $processedTitles =
"\n";
95 $services = $this->getServiceContainer();
96 foreach ( $res as $row ) {
97 $titleA = Title::makeTitle( $row->pa_namespace, $row->pa_title );
98 $titleB = Title::makeTitle( $row->pb_namespace, $row->pb_title );
99 if ( !$titleA->canExist() || !$titleB->canExist() ) {
100 $this->error(
"Cannot fix redirect from" .
101 ( $titleA->canExist() ?
"" :
" invalid" ) .
" title " . $titleA->getPrefixedText()
103 ( $titleB->canExist() ?
"" :
" invalid" ) .
" target " . $titleB->getPrefixedText()
109 $processedTitles .=
"* [[$titleA]]\n";
114 'reason' =>
'maintenance',
115 'redirTitle' => $titleB->getPrefixedDBkey()
117 $services->getRevisionLookup(),
118 $services->getMagicWordFactory(),
119 $services->getWikiPageFactory()
125 $this->error(
"Error fixing " . $titleA->getPrefixedText()
126 .
": " .
$job->getLastError() .
"\n" );
130 if ( count( $jobs ) > DoubleRedirectJob::MAX_DR_JOBS_COUNTER ) {
136 if ( ++$n % 100 == 0 ) {
137 $this->output(
"$n...\n" );
141 if ( count( $jobs ) ) {
144 $this->output(
"$n double redirects processed" . $processedTitles .
"\n" );