55 $title = Title::newFromText( $this->
getOption(
'title' ) );
56 if ( !$title || !$title->isRedirect() ) {
57 $this->
fatalError( $title->getPrefixedText() .
" is not a redirect!\n" );
67 $queryBuilder = $dbr->newSelectQueryBuilder()
69 'pa_namespace' =>
'pa.page_namespace',
70 'pa_title' =>
'pa.page_title',
71 'pb_namespace' =>
'pb.page_namespace',
72 'pb_title' =>
'pb.page_title',
75 ->join(
'page',
'pa',
'rd_from = pa.page_id' )
76 ->join(
'page',
'pb', [
'rd_namespace = pb.page_namespace',
'rd_title = pb.page_title' ] )
78 ->where( [
'rd_interwiki' =>
'',
'pb.page_is_redirect' => 1 ] );
80 if ( $title !=
null ) {
81 $queryBuilder->andWhere( [
82 'pb.page_namespace' => $title->getNamespace(),
83 'pb.page_title' => $title->getDBkey()
86 $res = $queryBuilder->caller( __METHOD__ )->fetchResultSet();
88 if ( !$res->numRows() ) {
89 $this->
output(
"No double redirects found.\n" );
95 $processedTitles =
"\n";
98 foreach ( $res as $row ) {
99 $titleA = Title::makeTitle( $row->pa_namespace, $row->pa_title );
100 $titleB = Title::makeTitle( $row->pb_namespace, $row->pb_title );
101 if ( !$titleA->canExist() || !$titleB->canExist() ) {
102 $this->
error(
"Cannot fix redirect from" .
103 ( $titleA->canExist() ?
"" :
" invalid" ) .
" title " . $titleA->getPrefixedText()
105 ( $titleB->canExist() ?
"" :
" invalid" ) .
" target " . $titleB->getPrefixedText()
111 $processedTitles .=
"* [[$titleA]]\n";
116 'reason' =>
'maintenance',
117 'redirTitle' => $titleB->getPrefixedDBkey()
119 $services->getRevisionLookup(),
120 $services->getMagicWordFactory(),
121 $services->getWikiPageFactory()
127 $this->
error(
"Error fixing " . $titleA->getPrefixedText()
128 .
": " .
$job->getLastError() .
"\n" );
132 if ( count( $jobs ) > DoubleRedirectJob::MAX_DR_JOBS_COUNTER ) {
138 if ( ++$n % 100 == 0 ) {
139 $this->
output(
"$n...\n" );
143 if ( count( $jobs ) ) {
146 $this->
output(
"$n double redirects processed" . $processedTitles .
"\n" );