Krenair

CA global rename changes #2

Feb 6th, 2013
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 7.91 KB | None | 0 0
  1. diff --git a/CentralAuth.i18n.php b/CentralAuth.i18n.php
  2. index 1d63842..5b38d75 100644
  3. --- a/CentralAuth.i18n.php
  4. +++ b/CentralAuth.i18n.php
  5. @@ -220,6 +220,7 @@ The passwords for local accounts created before the merge will revert to their p
  6.         'action-centralauth-globalrename' => 'globally rename a user',
  7.         'centralauth-globalrename-nonexistent' => 'Global account "<nowiki>$1</nowiki>" does not exist.',
  8.         'centralauth-globalrename-in-progress' => 'There is already a global rename in progress for <nowiki>$1</nowiki>.',
  9. +       'centralauth-globalrename-tempdisallowed' => 'Global account "<nowiki>$1</nowiki>" has more than $2 edits. Globally renaming such accounts has been temporarily disallowed while the code is experime
  10.  
  11.         // List of global users
  12.         'globalusers'                    => 'Global user list',
  13. @@ -747,6 +748,7 @@ See also:
  14.  * $4 - the new username',
  15.         'right-centralauth-globalrename' => '{{doc-right|centralauth-globalrename}}',
  16.         'centralauth-globalrename-in-progress' => 'Error message shown when a global rename is already in progress on this username.',
  17. +       'centralauth-globalrename-tempdisallowed' => 'Error message shown when trying to rename a user with too many edits (default: 5000). This limitation will hopefully go away when we\'re happy with the
  18.  );
  19.  
  20.  /** Afrikaans (Afrikaans)
  21. diff --git a/CentralAuthHooks.php b/CentralAuthHooks.php
  22. index ee9191f..7725528 100644
  23. --- a/CentralAuthHooks.php
  24. +++ b/CentralAuthHooks.php
  25. @@ -864,7 +864,11 @@ class CentralAuthHooks {
  26.          * @param &$retval int a LoginForm class constant to return from authenticateUserData (default is LoginForm::ABORTED)
  27.          */
  28.         static function onAbortLogin( $user, $password, &$retval ) {
  29. -               if ( !CentralAuthUser::getCentralDB()->lockIsFree( "centralauth-globalrename:" . $user->getName(), __METHOD__ ) ) {
  30. +               global $wgMemc;
  31. +               if (
  32. +                       !CentralAuthUser::getCentralDB()->lockIsFree( "centralauth-globalrename:" . $user->getName(), __METHOD__ ) ||
  33. +                       $wgMemc->get( CentralAuthUser::memcKey( 'globalrename', sha1( $user->getName() ) ) )
  34. +               ) {
  35.                         $retval = LoginForm::ABORTED;
  36.                         return false;
  37.                 }
  38. diff --git a/LocalRenameUserJob.php b/LocalRenameUserJob.php
  39. index d1d117d..e67c068 100644
  40. --- a/LocalRenameUserJob.php
  41. +++ b/LocalRenameUserJob.php
  42. @@ -21,19 +21,13 @@ class CentralAuthLocalRenameUserJob extends Job {
  43.                 );
  44.  
  45.                 if ( $rus->rename() ) {
  46. -                       // TODO: For renames of more than RENAMEUSER_CONTRIBJOB (default: 5000), this might need to take place in CentralAuthHooks::onRenameUserComplete
  47. -                       $wikiListKey = CentralAuthUser::memcKey( 'globalrename', sha1( $from ) );
  48. +                       // TODO: For renames of more than RENAMEUSER_CONTRIBJOB (default: 5000), we might want to do this in CentralAuthHooks::onRenameUserComplete instead
  49. +                       $wikiListKey = CentralAuthUser::memcKey( 'globalrename', sha1( $to ) );
  50.                         $wikiList = $wgMemc->get( $wikiListKey ); // TODO: Find a way to completely disable global renaming if memcache isn't available on all wikis. We can't just quit here if we see that
  51.                         $wikiList = array_diff( $wikiList, array( $wgDBname ) ); // Remove this wiki from the list.
  52.                         if ( count( $wikiList ) == 0 ) {
  53.                                 $wgMemc->delete( $wikiListKey );
  54.  
  55. -                               // Unlock the user
  56. -                               if ( !$this->params['startedLocked'] ) { // If the user was locked before we started renaming, we need to make sure we don't unlock them silently at the end.
  57. -                                       $globalUser = new CentralAuthUser( $to );
  58. -                                       $globalUser->adminUnlock();
  59. -                               }
  60. -
  61.                                 // Make log entry on the wiki which this rename job was started on.
  62.                                 $db = wfGetDB( DB_MASTER, array(), $this->params['startedFrom'] );
  63.                                 $title = Title::newFromText( "User:{$from}@global" );
  64. diff --git a/specials/SpecialCentralAuth.php b/specials/SpecialCentralAuth.php
  65. index c1edb7a..e7b6be4 100644
  66. --- a/specials/SpecialCentralAuth.php
  67. +++ b/specials/SpecialCentralAuth.php
  68. @@ -25,7 +25,7 @@ class SpecialCentralAuth extends SpecialPage {
  69.                 $this->mCanOversight = $this->getUser()->isAllowed( 'centralauth-oversight' );
  70.                 $this->mCanEdit = $this->mCanUnmerge || $this->mCanLock || $this->mCanOversight;
  71.                 AutoLoader::loadClass( 'SpecialRenameuser' );
  72. -               $this->mCanRename = $this->getUser()->isAllowed( 'centralauth-globalrename' ) && class_exists( 'SpecialRenameuser', false );
  73. +               $this->mCanRename = $this->getUser()->isAllowed( 'centralauth-globalrename' ) && class_exists( 'RenameuserSQL', false ) && property_exists( 'RenameuserSQL', 'checkIfUserExists' );
  74.                 $this->getOutput()->addModules( 'ext.centralauth' );
  75.                 $this->getOutput()->addModuleStyles( 'ext.centralauth.noflash' );
  76.                 $this->getOutput()->addJsConfigVars( 'wgMergeMethodDescriptions', $this->getMergeMethodDescriptions() );
  77. @@ -217,6 +217,11 @@ class SpecialCentralAuth extends SpecialPage {
  78.                                 return true;
  79.                         }
  80.  
  81. +                       if ( $this->evaluateTotalEditcount() > RENAMEUSER_CONTRIBJOB ) {
  82. +                               $this->showError( 'centralauth-globalrename-tempdisallowed', $globalUser->getName(), RENAMEUSER_CONTRIBJOB );
  83. +                               return true;
  84. +                       }
  85. +
  86.                         $currentName = $globalUser->getName();
  87.                         $newName = $this->getRequest()->getText( 'newname' );
  88.  
  89. @@ -241,12 +246,6 @@ class SpecialCentralAuth extends SpecialPage {
  90.                         $cdb->lock( "centralauth-globalrename:" . $currentName, __METHOD__ );
  91.                         $cdb->lock( "centralauth-globalrename:" . $newName, __METHOD__ );
  92.  
  93. -                       $startedLocked = $globalUser->isLocked();
  94. -                       // Lock the user before we start changing anything.
  95. -                       if ( !$startedLocked ) {
  96. -                               $globalUser->adminLock();
  97. -                       }
  98. -
  99.                         // Update the globaluser and localuser tables. The existing hooks should deal with globalnames/localnames...
  100.                         $tables = array( 'globaluser' => 'gu', 'localuser' => 'lu' );
  101.                         foreach ( $tables as $table => $prefix ) {
  102. @@ -267,7 +266,6 @@ class SpecialCentralAuth extends SpecialPage {
  103.                                         'from' => $globalUser->getName(),
  104.                                         'to' => $newName,
  105.                                         'reason' => $this->getRequest()->getText( 'reason' ),
  106. -                                       'startedLocked' => $startedLocked,
  107.                                         'startedFrom' => $wgDBname,
  108.                                         'startedByName' => $this->getUser()->getName(),
  109.                                         'startedById' => $this->getUser()->getID(),
  110. @@ -276,7 +274,7 @@ class SpecialCentralAuth extends SpecialPage {
  111.                         );
  112.  
  113.                         global $wgMemc;
  114. -                       $wgMemc->set( CentralAuthUser::memcKey( 'globalrename', sha1( $currentName ) ), $globalUser->listAttached() );
  115. +                       $wgMemc->set( CentralAuthUser::memcKey( 'globalrename', sha1( $newName ) ), $globalUser->listAttached() );
  116.  
  117.                         // Put the job into the queue on each wiki it needs to run on
  118.                         foreach ( $globalUser->listAttached() as $wiki ) {
Advertisement
Add Comment
Please, Sign In to add comment