Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/165092
Change subject: [WIP] GlobalRename: Do page moves in a separate job
......................................................................
[WIP] GlobalRename: Do page moves in a separate job
Bug: 71676
Change-Id: I1e215bbb7e9ddf15bed3f0fce658539a4b794732
---
A includes/LocalRenameJob/LocalPageMoveJob.php
M includes/LocalRenameJob/LocalRenameUserJob.php
2 files changed, 129 insertions(+), 29 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralAuth
refs/changes/92/165092/1
diff --git a/includes/LocalRenameJob/LocalPageMoveJob.php
b/includes/LocalRenameJob/LocalPageMoveJob.php
new file mode 100644
index 0000000..08affd4
--- /dev/null
+++ b/includes/LocalRenameJob/LocalPageMoveJob.php
@@ -0,0 +1,99 @@
+<?php
+
+/**
+ * Job class to move a set of pages
+ */
+class LocalPageMoveJob extends Job {
+ /**
+ * @var bool
+ */
+ private $setAFOverride;
+
+ /**
+ * @var bool
+ */
+ private $setTBOverride;
+
+ /**
+ * @param array $params
+ */
+ public function __construct( $params ) {
+ parent::__construct(
+ 'LocalUserMergeJob',
+ Title::newFromText( 'Global rename local page move job'
),
+ $params
+ );
+ }
+
+ public function run() {
+ // Need to set $wgUser so the move log is attributed correctly.
+ global $wgUser;
+ $oldUser = $wgUser;
+ $wgUser = User::newFromName( $this->params['renamer'] );
+ foreach ( $this->params['pages'] as $current => $target ) {
+ $this->movePage(
+ Title::newFromText( $current ),
+ Title::newFromText( $target )
+ );
+ }
+
+ // Cleanup
+ $wgUser = $oldUser;
+ }
+
+ protected function movePage( Title $oldPage, Title $newPage ) {
+ if ( $newPage->exists() && !$oldPage->isValidMoveTarget(
$newPage ) ) {
+ wfDebugLog( 'CentralAuthRename', "Could not move
$oldPage to $newPage" );
+ // @todo log this somewhere publicly?
+ } else {
+ $msg = wfMessage( 'centralauth-rename-movelog' )
+ ->params( $this->params['from'],
$this->params['to'] )
+ ->inContentLanguage()
+ ->text();
+ $errors = $oldPage->moveTo( $newPage, false, $msg,
!$this->params['suppressredirects'] );
+ if ( is_array( $errors ) ) {
+ // AbuseFilter or TitleBlacklist might be
interfering, bug 67875
+ if ( $errors[0][0] === 'hookaborted' ) {
+ wfDebugLog( 'CentralAuthRename', "Page
move prevented by hook: {$oldPage->getPrefixedText()} ->
{$newPage->getPrefixedText()}" );
+ $this->disableMoveBlockingThings();
+ // Do it again
+ $oldPage->moveTo( $newPage, false,
$msg, !$this->params['suppressredirects'] );
+ $this->enableMoveBlockingThings();
+ }
+ }
+ }
+
+ }
+
+ /**
+ * FIXME: on a of scale one to evil, this is super evil
+ */
+ private function disableMoveBlockingThings() {
+ global $wgUser;
+ if ( !$wgUser->isAllowed( 'abusefilter-bypass' ) ) {
+ $wgUser->mRights[] = 'abusefilter-bypass';
+ $this->setAFOverride = true;
+ }
+
+ if ( !$wgUser->isAllowed( 'tboverride' ) ) {
+ $wgUser->mRights[] = 'tboverride';
+ $this->setTBOverride = true;
+ }
+ }
+
+ private function enableMoveBlockingThings() {
+ global $wgUser;
+ $rights = array();
+ if ( $this->setAFOverride ) {
+ $rights[] = 'abusefilter-bypass';
+ $this->setAFOverride = false;
+ }
+ if ( $this->setTBOverride ) {
+ $rights[] = 'tboverride';
+ $this->setTBOverride = false;
+ }
+
+ $wgUser->mRights = array_diff( $wgUser->mRights, $rights );
+ }
+
+}
\ No newline at end of file
diff --git a/includes/LocalRenameJob/LocalRenameUserJob.php
b/includes/LocalRenameJob/LocalRenameUserJob.php
index 12bdd2a..4f427d4 100644
--- a/includes/LocalRenameJob/LocalRenameUserJob.php
+++ b/includes/LocalRenameJob/LocalRenameUserJob.php
@@ -6,6 +6,11 @@
*/
class LocalRenameUserJob extends LocalRenameJob {
/**
+ * How many page moves per each job
+ */
+ const MOVES_PER_JOB = 25;
+
+ /**
* @var bool
*/
private $setAFOverride;
@@ -85,11 +90,9 @@
}
/**
- * Logic is mainly borrowed from SpecialRenameuser
+ * Queue up jobs to move pages
*/
public function movePages() {
- global $wgUser;
-
$from = $this->params['from'];
$to = $this->params['to'];
@@ -97,7 +100,7 @@
$toTitle = Title::makeTitleSafe( NS_USER, $to );
$dbr = wfGetDB( DB_SLAVE );
- $pages = $dbr->select(
+ $rows = $dbr->select(
'page',
array( 'page_namespace', 'page_title' ),
array(
@@ -108,38 +111,36 @@
__METHOD__
);
- // Need to play with $wgUser so the move log is attributed
properly
- $oldUser = $wgUser;
- $wgUser = $this->getRenameUser();
+ $jobParams = array(
+ 'to' => $to,
+ 'from' => $from,
+ 'renamer' => $this->getRenameUser()->getName(),
+ 'suppressredirects' =>
$this->params['suppressredirects'],
+ );
+ $jobs = array();
+ $pages = array();
- foreach ( $pages as $row ) {
+ foreach ( $rows as $row ) {
$oldPage = Title::newFromRow( $row );
$newPage = Title::makeTitleSafe( $row->page_namespace,
preg_replace( '!^[^/]+!', $toTitle->getDBkey(),
$row->page_title ) );
- # Do not autodelete or anything, title must not exist
- if ( $newPage->exists() &&
!$oldPage->isValidMoveTarget( $newPage ) ) {
- wfDebugLog( 'CentralAuthRename', "Could not
move $oldPage to $newPage" );
- // @todo log this somewhere publicly?
- } else {
- $msg = wfMessage( 'centralauth-rename-movelog' )
- ->params( $from, $to )
- ->inContentLanguage()
- ->text();
- $errors = $oldPage->moveTo( $newPage, false,
$msg, !$this->params['suppressredirects'] );
- if ( is_array( $errors ) ) {
- // AbuseFilter or TitleBlacklist might
be interfering, bug 67875
- if ( $errors[0][0] === 'hookaborted' ) {
- wfDebugLog(
'CentralAuthRename', "Page move prevented by hook:
{$oldPage->getPrefixedText()} -> {$newPage->getPrefixedText()}" );
-
$this->disableMoveBlockingThings();
- // Do it again
- $oldPage->moveTo( $newPage,
false, $msg, !$this->params['suppressredirects'] );
-
$this->enableMoveBlockingThings();
- }
- }
+ $pages[$oldPage->getPrefixedText()] =
$newPage->getPrefixedText();
+ if ( count( $pages ) > self::MOVES_PER_JOB ) {
+ $jobs[] = new LocalPageMoveJob(
+ $jobParams + array( 'pages' => $pages )
+ );
+ $pages = array();
}
}
- $wgUser = $oldUser; // good manners to cleanup
+ // Anything left over...
+ if ( $pages ) {
+ $jobs[] = new LocalPageMoveJob(
+ $jobParams + array( 'pages' => $pages )
+ );
+ }
+
+ JobQueueGroup::singleton()->push( $jobs );
}
protected function done() {
--
To view, visit https://gerrit.wikimedia.org/r/165092
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1e215bbb7e9ddf15bed3f0fce658539a4b794732
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralAuth
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits