41 $title = Title::newFromText( $this->
getOption(
'title' ) );
42 if ( !$title || !$title->isRedirect() ) {
43 $this->
fatalError( $title->getPrefixedText() .
" is not a redirect!\n" );
53 $queryBuilder = $dbr->newSelectQueryBuilder()
55 'pa_namespace' =>
'pa.page_namespace',
56 'pa_title' =>
'pa.page_title',
57 'pb_namespace' =>
'pb.page_namespace',
58 'pb_title' =>
'pb.page_title',
61 ->join(
'page',
'pa',
'rd_from = pa.page_id' )
62 ->join(
'page',
'pb', [
'rd_namespace = pb.page_namespace',
'rd_title = pb.page_title' ] )
64 ->where( [
'rd_interwiki' =>
'',
'pb.page_is_redirect' => 1 ] );
66 if ( $title !=
null ) {
67 $queryBuilder->andWhere( [
68 'pb.page_namespace' => $title->getNamespace(),
69 'pb.page_title' => $title->getDBkey()
72 $res = $queryBuilder->caller( __METHOD__ )->fetchResultSet();
74 if ( !$res->numRows() ) {
75 $this->
output(
"No double redirects found.\n" );
81 $processedTitles =
"\n";
84 foreach ( $res as $row ) {
85 $titleA = Title::makeTitle( $row->pa_namespace, $row->pa_title );
86 $titleB = Title::makeTitle( $row->pb_namespace, $row->pb_title );
87 if ( !$titleA->canExist() || !$titleB->canExist() ) {
88 $this->
error(
"Cannot fix redirect from" .
89 ( $titleA->canExist() ?
"" :
" invalid" ) .
" title " . $titleA->getPrefixedText()
91 ( $titleB->canExist() ?
"" :
" invalid" ) .
" target " . $titleB->getPrefixedText()
97 $processedTitles .=
"* [[$titleA]]\n";
102 'reason' =>
'maintenance',
103 'redirTitle' => $titleB->getPrefixedDBkey()
105 $services->getRevisionLookup(),
106 $services->getMagicWordFactory(),
107 $services->getWikiPageFactory()
113 $this->
error(
"Error fixing " . $titleA->getPrefixedText()
114 .
": " .
$job->getLastError() .
"\n" );
118 if ( count( $jobs ) > DoubleRedirectJob::MAX_DR_JOBS_COUNTER ) {
124 if ( ++$n % 100 == 0 ) {
125 $this->
output(
"$n...\n" );
129 if ( count( $jobs ) ) {
132 $this->
output(
"$n double redirects processed" . $processedTitles .
"\n" );