Legoktm has uploaded a new change for review. https://gerrit.wikimedia.org/r/194709
Change subject: Update CentralAuthUser::chooseHomeWiki() per Keegan ...................................................................... Update CentralAuthUser::chooseHomeWiki() per Keegan 1. User groups in order of: checkuser, oversight, bureaucrat, sysop 2. Edit count 3. Earliest registration date 4. Randomness Bug: T91703 Change-Id: I69a91cdde2a881f0fb46ebffca700c07acbf3de1 --- M includes/CentralAuthUser.php M tests/CentralAuthUserTest.php 2 files changed, 106 insertions(+), 18 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralAuth refs/changes/09/194709/1 diff --git a/includes/CentralAuthUser.php b/includes/CentralAuthUser.php index 1c8a9b4..2e2d6dc 100644 --- a/includes/CentralAuthUser.php +++ b/includes/CentralAuthUser.php @@ -736,34 +736,46 @@ } // Sysops get priority - $priorityGroups = array( 'sysop', 'bureaucrat', 'steward' ); - $workingSet = array(); - foreach ( $migrationSet as $wiki => $local ) { - if ( array_intersect( $priorityGroups, $local['groups'] ) ) { - if ( $local['editCount'] ) { - // Ignore unused sysop accounts - $workingSet[$wiki] = $local; + $found = array(); + $priorityGroups = array( 'checkuser', 'oversight', 'bureaucrat', 'sysop' ); + foreach ( $priorityGroups as $group ) { + foreach ( $migrationSet as $wiki => $local ) { + if ( in_array( $group, $local['groups'] ) ) { + $found[] = $wiki; } + } + if ( count( $found ) === 1 ) { + // Easy! + return $found[0]; + } elseif ( $found ) { + // We'll check edit counts now... + break; } } - if ( !$workingSet ) { + if ( !$found ) { // No privileged accounts; look among the plebes... - $workingSet = $migrationSet; + $found = array_keys( $migrationSet ); } $maxEdits = -1; $homeWiki = null; - foreach ( $workingSet as $wiki => $local ) { - if ( $local['editCount'] > $maxEdits ) { + foreach ( $found as $wiki ) { + $count = $migrationSet[$wiki]['editCount']; + if ( $count > $maxEdits ) { $homeWiki = $wiki; - $maxEdits = $local['editCount']; + $maxEdits = $count; + } elseif ( $count === $maxEdits ) { + // Tie, check earlier registration + // Note that registration might be "null", which means they're a super old account. + if ( $migrationSet[$wiki]['registration'] < $migrationSet[$homeWiki]['registration'] ) { + $homeWiki = $wiki; + } elseif ( $migrationSet[$wiki]['registration'] === $migrationSet[$homeWiki]['registration'] ) { + // Another tie? Screw it, pick one randomly. + $wikis = array( $wiki, $homeWiki ); + $homeWiki = $wikis[mt_rand( 0, 1 )]; + } } - } - - if ( !isset( $homeWiki ) ) { - throw new Exception( "Logic error in migration: " . - "Unable to determine primary account for $this->mName" ); } return $homeWiki; @@ -2082,7 +2094,9 @@ 'user_email', 'user_email_authenticated', 'user_password', - 'user_editcount' ); + 'user_editcount', + 'user_registration', + ); $conds = array( 'user_name' => $this->mName ); $row = $db->selectRow( 'user', $fields, $conds, __METHOD__ ); if ( !$row ) { @@ -2104,6 +2118,8 @@ 'email' => $row->user_email, 'emailAuthenticated' => wfTimestampOrNull( TS_MW, $row->user_email_authenticated ), + 'registration' => + wfTimestampOrNull( TS_MW, $row->user_registration ), 'password' => $row->user_password, 'editCount' => $row->user_editcount, 'groups' => array(), diff --git a/tests/CentralAuthUserTest.php b/tests/CentralAuthUserTest.php index beea7b0..a5f5591 100644 --- a/tests/CentralAuthUserTest.php +++ b/tests/CentralAuthUserTest.php @@ -75,6 +75,78 @@ } /** + * @covers CentralAuthUser::chooseHomeWiki + * @dataProvider provideChooseHomeWiki + */ + public function testChooseHomeWiki( $attached, $expected) { + $ca = new CentralAuthUser( 'FooBar' ); + $this->assertEquals( $expected, $ca->chooseHomeWiki( $attached ) ); + } + + public static function provideChooseHomeWiki() { + return array( + // Groups win + array( array( + 'foowiki' => array( + 'groups' => array( 'sysop' ), + ), + 'barwiki' => array( + 'groups' => array( 'checkuser' ), + ), + ), 'barwiki' ), + // Groups tie, editcount wins + array( array( + 'foowiki' => array( + 'groups' => array( 'sysop', 'checkuser' ), + 'editCount' => '100', + ), + 'barwiki' => array( + 'groups' => array( 'checkuser' ), + 'editCount' => '100000000', + ), + ), 'barwiki' ), + // No groups, Editcount wins + array( array( + 'foowiki' => array( + 'groups' => array(), + 'editCount' => '100' + ), + 'barwiki' => array( + 'groups' => array(), + 'editCount' => '1000' + ), + ), 'barwiki' ), + // Edit count ties, super old registration (null) wins + array( array( + 'foowiki' => array( + 'groups' => array(), + 'editCount' => '5', + 'registration' => null + ), + 'barwiki' => array( + 'groups' => array(), + 'editCount' => '5', + 'registration' => '20150305220251', + ), + ), 'foowiki' ), + // Edit count ties, registration wins + array( array( + 'foowiki' => array( + 'groups' => array(), + 'editCount' => '5', + 'registration' => '20100305220251' + ), + 'barwiki' => array( + 'groups' => array(), + 'editCount' => '5', + 'registration' => '20150305220251', + ), + ), 'foowiki' ) + + ); + } + + /** * @covers CentralAuthUser::getPasswordFromString * @dataProvider provideGetPasswordFromString */ -- To view, visit https://gerrit.wikimedia.org/r/194709 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I69a91cdde2a881f0fb46ebffca700c07acbf3de1 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/CentralAuth Gerrit-Branch: master Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits