/** @var User */
private static $user;
+ /**
+ * @param Title $title
+ * @param array $params
+ */
+ function __construct( Title $title, array $params ) {
+ parent::__construct( 'fixDoubleRedirect', $title, $params );
+ $this->reason = $params['reason'];
+ $this->redirTitle = Title::newFromText( $params['redirTitle'] );
+ }
+
/**
* Insert jobs into the job queue to fix redirects to the given title
* @param string $reason The reason for the fix, see message
# Need to use the master to get the redirect table updated in the same transaction
$dbw = wfGetDB( DB_MASTER );
$res = $dbw->select(
- array( 'redirect', 'page' ),
- array( 'page_namespace', 'page_title' ),
- array(
+ [ 'redirect', 'page' ],
+ [ 'page_namespace', 'page_title' ],
+ [
'page_id = rd_from',
'rd_namespace' => $redirTitle->getNamespace(),
'rd_title' => $redirTitle->getDBkey()
- ), __METHOD__ );
+ ], __METHOD__ );
if ( !$res->numRows() ) {
return;
}
- $jobs = array();
+ $jobs = [];
foreach ( $res as $row ) {
$title = Title::makeTitle( $row->page_namespace, $row->page_title );
if ( !$title ) {
continue;
}
- $jobs[] = new self( $title, array(
+ $jobs[] = new self( $title, [
'reason' => $reason,
- 'redirTitle' => $redirTitle->getPrefixedDBkey() ) );
+ 'redirTitle' => $redirTitle->getPrefixedDBkey() ] );
# Avoid excessive memory usage
if ( count( $jobs ) > 10000 ) {
JobQueueGroup::singleton()->push( $jobs );
- $jobs = array();
+ $jobs = [];
}
}
JobQueueGroup::singleton()->push( $jobs );
}
- /**
- * @param Title $title
- * @param array|bool $params
- */
- function __construct( $title, $params = false ) {
- parent::__construct( 'fixDoubleRedirect', $title, $params );
- $this->reason = $params['reason'];
- $this->redirTitle = Title::newFromText( $params['redirTitle'] );
- }
-
/**
* @return bool
*/
$reason = wfMessage( 'double-redirect-fixed-' . $this->reason,
$this->redirTitle->getPrefixedText(), $newTitle->getPrefixedText()
)->inContentLanguage()->text();
- $article->doEditContent( $newContent, $reason, EDIT_UPDATE | EDIT_SUPPRESS_RC, false, $user );
+ $flags = EDIT_UPDATE | EDIT_SUPPRESS_RC | EDIT_INTERNAL;
+ $article->doEditContent( $newContent, $reason, $flags, false, $user );
$wgUser = $oldUser;
return true;
*
* @param Title $title
*
- * @return bool If the specified title is not a redirect, or if it is a circular redirect
+ * @return Title|bool The final Title after following all redirects, or false if
+ * the page is not a redirect or the redirect loops.
*/
public static function getFinalDestination( $title ) {
$dbw = wfGetDB( DB_MASTER );
// Circular redirect check
- $seenTitles = array();
+ $seenTitles = [];
$dest = false;
while ( true ) {
}
$row = $dbw->selectRow(
- array( 'redirect', 'page' ),
- array( 'rd_namespace', 'rd_title', 'rd_interwiki' ),
- array(
+ [ 'redirect', 'page' ],
+ [ 'rd_namespace', 'rd_title', 'rd_interwiki' ],
+ [
'rd_from=page_id',
'page_namespace' => $title->getNamespace(),
'page_title' => $title->getDBkey()
- ), __METHOD__ );
+ ], __METHOD__ );
if ( !$row ) {
# No redirect from here, chain terminates
break;