r99109 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99108‎ | r99109 | r99110 >
Date:14:36, 6 October 2011
Author:happy-melon
Status:ok (Comments)
Tags:
Comment:
Massive amount of type hinting so we can actually see what's going on.
Modified paths:
  • /trunk/extensions/CentralAuth/CentralAuthUser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralAuth/CentralAuthUser.php
@@ -20,6 +20,9 @@
2121 /*private*/ var $mVersion = 4;
2222 /*private*/ var $mDelayInvalidation = 0;
2323
 24+ var $mAttachedArray, $mEmail, $mEmailAuthenticated, $mHomeWiki, $mHidden, $mLocked, $mAttachedList, $mAuthenticationTimestamp;
 25+ var $mGroups, $mRights, $mPassword, $mAuthToken, $mSalt, $mGlobalId, $mFromMaster, $mIsAttached, $mRegistration;
 26+
2427 static $mCacheVars = array(
2528 'mGlobalId',
2629 'mSalt',
@@ -83,6 +86,8 @@
8487 /**
8588 * Create a CentralAuthUser object from a joined globaluser/localuser row
8689 *
 90+ * @param $row ResourceWrapper|object
 91+ * @param $fromMaster bool
8792 * @return CentralAuthUser
8893 */
8994 public static function newFromRow( $row, $fromMaster = false ) {
@@ -182,6 +187,7 @@
183188
184189 $sets = array();
185190 foreach ( $resSets as $row ) {
 191+ /* @var $row object */
186192 $sets[$row->ggr_group] = WikiSet::newFromRow( $row );
187193 }
188194
@@ -190,6 +196,7 @@
191197 $groups = array();
192198
193199 foreach ( $res as $row ) {
 200+ /** @var $set User|bool */
194201 $set = @$sets[$row->ggp_group];
195202 $rights[] = array( 'right' => $row->ggp_permission, 'set' => $set ? $set->getID() : false );
196203 $groups[$row->ggp_group] = 1;
@@ -201,6 +208,9 @@
202209
203210 /**
204211 * Load user state from a joined globaluser/localuser row
 212+ *
 213+ * @param $row ResourceWrapper|object
 214+ * @param $fromMaster bool
205215 */
206216 protected function loadFromRow( $row, $fromMaster = false ) {
207217 if ( $row ) {
@@ -228,6 +238,10 @@
229239
230240 /**
231241 * Load data from memcached
 242+ *
 243+ * @param $cache Array
 244+ * @param $fromMaster Bool
 245+ * @return bool
232246 */
233247 protected function loadFromCache( $cache = null, $fromMaster = false ) {
234248 wfProfileIn( __METHOD__ );
@@ -254,6 +268,9 @@
255269
256270 /**
257271 * Load user state from a cached array.
 272+ *
 273+ * @param $object Array
 274+ * @param $fromMaster Bool
258275 */
259276 protected function loadFromCacheObject( $object, $fromMaster = false ) {
260277 wfDebugLog( 'CentralAuth', "Loading CentralAuthUser for user {$this->mName} from cache object" );
@@ -306,6 +323,7 @@
307324
308325 /**
309326 * Return the global account ID number for this account, if it exists.
 327+ * @return Int
310328 */
311329 public function getId() {
312330 $this->loadState();
@@ -314,6 +332,7 @@
315333
316334 /**
317335 * Generate a valid memcached key for caching the object's data.
 336+ * @return String
318337 */
319338 protected function getCacheKey() {
320339 return "centralauth-user-" . md5( $this->mName );
@@ -321,6 +340,7 @@
322341
323342 /**
324343 * Return the global account's name, whether it exists or not.
 344+ * @return String
325345 */
326346 public function getName() {
327347 return $this->mName;
@@ -435,6 +455,11 @@
436456 * Register a new, not previously existing, central user account
437457 * Remaining fields are expected to be filled out shortly...
438458 * eeeyuck
 459+ *
 460+ * @param $password String
 461+ * @param $email String
 462+ * @param $realname String
 463+ * @return bool
439464 */
440465 function register( $password, $email, $realname ) {
441466 $dbw = self::getCentralDB();
@@ -503,6 +528,11 @@
504529
505530 /**
506531 * Store global user data in the auth server's main table.
 532+ *
 533+ * @param $salt String
 534+ * @param $hash String
 535+ * @param $email String
 536+ * @param $emailAuth String timestamp
507537 * @return bool Whether we were successful or not.
508538 */
509539 protected function storeGlobalData( $salt, $hash, $email, $emailAuth ) {
@@ -591,10 +621,11 @@
592622 /**
593623 * Go through a list of migration data looking for those which
594624 * can be automatically migrated based on the available criteria.
595 - * @param array $migrationSet
596 - * @param string $passwords Optional, pre-authenticated passwords.
597 - * Should match an account which is known
598 - * to be attached.
 625+ *
 626+ * @param $migrationSet Array
 627+ * @param $passwords Array Optional, pre-authenticated passwords.
 628+ * Should match an account which is known to be attached.
 629+ * @return Array of <wiki> => <authentication method>
599630 */
600631 function prepareMigration( $migrationSet, $passwords = array() ) {
601632 // If the primary account has an e-mail address set,
@@ -655,13 +686,11 @@
656687 * Do a dry run -- pick a winning master account and try to auto-merge
657688 * as many as possible, but don't perform any actions yet.
658689 *
659 - * @param array $passwords
660 - * @param string &$home set to false if no permission to do checks
661 - * @param array &$attached on success, list of wikis which will be auto-attached
662 - * @param array &$unattached on success, list of wikis which won't be auto-attached
663 - * @param array &$methods on success, associative array of each wiki's attachment method
664 - * @param array &$blocked true if the home wiki is blocked
665 - *
 690+ * @param $passwords array
 691+ * @param &$home String set to false if no permission to do checks
 692+ * @param &$attached Array on success, list of wikis which will be auto-attached
 693+ * @param &$unattached Array on success, list of wikis which won't be auto-attached
 694+ * @param &$methods Array on success, associative array of each wiki's attachment method *
666695 * @return Status object
667696 */
668697 function migrationDryRun( $passwords, &$home, &$attached, &$unattached, &$methods ) {
@@ -718,6 +747,8 @@
719748 /**
720749 * Pick a winning master account and try to auto-merge as many as possible.
721750 * @fixme add some locking or something
 751+ *
 752+ * @param $passwords Array
722753 * @return bool Whether full automatic migration completed successfully.
723754 */
724755 protected function attemptAutoMigration( $passwords = array() ) {
@@ -928,6 +959,8 @@
929960
930961 /**
931962 * Delete a global account
 963+ *
 964+ * @return Status
932965 */
933966 function adminDelete() {
934967 global $wgMemc;
@@ -940,6 +973,7 @@
941974 array( 'lu_name' => $this->mName ), __METHOD__ );
942975 $name = $this->getName();
943976 foreach ( $localUserRes as $localUserRow ) {
 977+ /** @var $localUserRow object */
944978 $wiki = $localUserRow->lu_wiki;
945979 wfDebug( __METHOD__ . ": Fixing password on $wiki\n" );
946980 $lb = wfGetLB( $wiki );
@@ -972,6 +1006,8 @@
9731007
9741008 /**
9751009 * Lock a global account
 1010+ *
 1011+ * @return Status
9761012 */
9771013 function adminLock() {
9781014 $dbw = self::getCentralDB();
@@ -991,6 +1027,8 @@
9921028
9931029 /**
9941030 * Unlock a global account
 1031+ *
 1032+ * @return Status
9951033 */
9961034 function adminUnlock() {
9971035 $dbw = self::getCentralDB();
@@ -1010,6 +1048,9 @@
10111049
10121050 /**
10131051 * Change account hiding level.
 1052+ *
 1053+ * @param $level String CentralAuthUser::HIDDEN_ class constant
 1054+ * @return Status
10141055 */
10151056 function adminSetHidden( $level ) {
10161057 $dbw = self::getCentralDB();
@@ -1029,6 +1070,7 @@
10301071
10311072 /**
10321073 * Suppresses all user accounts in all wikis.
 1074+ * @param $reason String
10331075 */
10341076 function suppress( $reason ) {
10351077 global $wgUser;
@@ -1037,6 +1079,8 @@
10381080
10391081 /**
10401082 * Unsuppresses all user accounts in all wikis.
 1083+ *
 1084+ * @param $reason String
10411085 */
10421086 function unsuppress( $reason ) {
10431087 global $wgUser;
@@ -1044,10 +1088,9 @@
10451089 }
10461090
10471091 /**
1048 - * @param $suppress
1049 - * @param $by
1050 - * @param $reason
1051 - * @return void
 1092+ * @param $suppress Bool
 1093+ * @param $by String
 1094+ * @param $reason String
10521095 */
10531096 protected function doCrosswikiSuppression( $suppress, $by, $reason ) {
10541097 global $wgCentralAuthWikisPerSuppressJob;
@@ -1078,6 +1121,12 @@
10791122
10801123 /**
10811124 * Suppresses a local account of a user.
 1125+ *
 1126+ * @param $suppress Bool
 1127+ * @param $wiki String
 1128+ * @param $by String
 1129+ * @param $reason String
 1130+ * @return Array|null Error array on failure
10821131 */
10831132 public function doLocalSuppression( $suppress, $wiki, $by, $reason ) {
10841133 global $wgConf;
@@ -1137,12 +1186,13 @@
11381187 RevisionDeleteUser::unsuppressUserName( $this->mName, $data['id'], $dbw );
11391188 }
11401189 }
 1190+ return null;
11411191 }
11421192
11431193 /**
11441194 * Add a local account record for the given wiki to the central database.
1145 - * @param string $wikiID
1146 - * @param int $localid
 1195+ * @param $wikiID String
 1196+ * @param $method String
11471197 *
11481198 * Prerequisites:
11491199 * - completed migration state
@@ -1272,10 +1322,10 @@
12731323 }
12741324
12751325 /**
1276 - * @param $plaintext User-provided password plaintext.
1277 - * @param $salt The hash "salt", eg a local id for migrated passwords.
1278 - * @param $encrypted Fully salted and hashed database crypto text from db.
1279 - * @return bool true on match.
 1326+ * @param $plaintext String User-provided password plaintext.
 1327+ * @param $salt String The hash "salt", eg a local id for migrated passwords.
 1328+ * @param $encrypted String Fully salted and hashed database crypto text from db.
 1329+ * @return Bool true on match.
12801330 */
12811331 protected function matchHash( $plaintext, $salt, $encrypted ) {
12821332 if ( User::comparePasswords( $encrypted, $plaintext, $salt ) ) {
@@ -1335,6 +1385,7 @@
13361386
13371387 $dbs = array();
13381388 foreach ( $result as $row ) {
 1389+ /** @var $row object */
13391390 $dbs[] = $row->ln_wiki;
13401391 }
13411392
@@ -1396,6 +1447,8 @@
13971448 /**
13981449 * Troll through the full set of local databases and list those
13991450 * which exist into the 'localnames' table.
 1451+ *
 1452+ * @return Bool whether any results were found
14001453 */
14011454 function importLocalNames() {
14021455 $rows = array();
@@ -1463,6 +1516,7 @@
14641517
14651518 $wikis = array();
14661519 foreach ( $result as $row ) {
 1520+ /** @var $row object */
14671521 $wikis[] = $row->lu_wiki;
14681522 }
14691523
@@ -1505,6 +1559,7 @@
15061560
15071561 $wikis = array();
15081562 foreach ( $result as $row ) {
 1563+ /** @var $row object */
15091564 $wikis[$row->lu_wiki] = array(
15101565 'wiki' => $row->lu_wiki,
15111566 'attachedTimestamp' => wfTimestampOrNull( TS_MW,
@@ -1522,10 +1577,10 @@
15231578 }
15241579
15251580 /**
1526 - * Find any remaining migration records for this username
1527 - * which haven't gotten attached to some global account.
 1581+ * Find any remaining migration records for this username which haven't gotten attached to some global account.
 1582+ * Formatted as associative array with some data.
15281583 *
1529 - * Formatted as associative array with some data.
 1584+ * @return Array
15301585 */
15311586 public function queryUnattached() {
15321587 $wikiIDs = $this->listUnattached();
@@ -1545,6 +1600,9 @@
15461601
15471602 /**
15481603 * Fetch a row of user data needed for migration.
 1604+ *
 1605+ * @param $wikiID String
 1606+ * @return Array
15491607 */
15501608 protected function localUserData( $wikiID ) {
15511609 $lb = wfGetLB( $wikiID );
@@ -1568,6 +1626,8 @@
15691627 return false;
15701628 }
15711629
 1630+ /** @var $row object */
 1631+
15721632 $data = array(
15731633 'wiki' => $wikiID,
15741634 'id' => $row->user_id,
@@ -1667,7 +1727,8 @@
16681728
16691729 /**
16701730 * Set the account's password
1671 - * @param string $password plaintext
 1731+ * @param $password String plaintext
 1732+ * @return Bool true
16721733 */
16731734 function setPassword( $password ) {
16741735 list( $salt, $hash ) = $this->saltedPassword( $password );
@@ -1760,10 +1821,12 @@
17611822 /**
17621823 * Set a global cookie that auto-authenticates the user on other wikis
17631824 * Called on login.
 1825+ *
 1826+ * @param $remember Bool|User
17641827 * @return Session ID
17651828 */
17661829 function setGlobalCookies( $remember = false ) {
1767 - if ( is_object( $remember ) ) {
 1830+ if ( $remember instanceof User ) {
17681831 // Older code passed a user object here. Be kind and do what they meant to do.
17691832 $remember = $remember->getOption( 'rememberpassword' );
17701833 }
@@ -1804,6 +1867,8 @@
18051868 * Get the domain parameter for setting a global cookie.
18061869 * This allows other extensions to easily set global cookies without directly relying on
18071870 * $wgCentralAuthCookieDomain (in case CentralAuth's implementation changes at some point).
 1871+ *
 1872+ * @return String
18081873 */
18091874 static function getCookieDomain() {
18101875 global $wgCentralAuthCookieDomain;
@@ -1812,6 +1877,9 @@
18131878
18141879 /**
18151880 * Check a global auth token against the one we know of in the database.
 1881+ *
 1882+ * @param $token String
 1883+ * @return Bool
18161884 */
18171885 function validateAuthToken( $token ) {
18181886 return ( $token == $this->getAuthToken() );
@@ -1943,6 +2011,7 @@
19442012 $groups = array();
19452013
19462014 foreach ( $res as $row ) {
 2015+ /** @var $row object */
19472016 $groups[] = $row->ggp_group;
19482017 }
19492018
@@ -1963,6 +2032,7 @@
19642033 $rights = array();
19652034
19662035 foreach ( $res as $row ) {
 2036+ /** @var $row object */
19672037 $rights[] = $row->ggp_permission;
19682038 }
19692039
@@ -1988,6 +2058,7 @@
19892059 $rights = array();
19902060
19912061 foreach ( $res as $row ) {
 2062+ /** @var $row object */
19922063 $rights[] = $row->ggp_permission;
19932064 }
19942065
@@ -2058,6 +2129,8 @@
20592130
20602131 /**
20612132 * Get the central session data
 2133+ *
 2134+ * @return Array
20622135 */
20632136 static function getSession() {
20642137 global $wgCentralAuthCookies, $wgCentralAuthCookiePrefix;
@@ -2080,13 +2153,15 @@
20812154
20822155 /**
20832156 * Set the central session data
 2157+ *
 2158+ * @param $data Array
20842159 * @return ID
20852160 */
20862161 static function setSession( $data ) {
20872162 global $wgCentralAuthCookies, $wgCentralAuthCookiePrefix;
20882163 global $wgMemc;
20892164 if ( !$wgCentralAuthCookies ) {
2090 - return;
 2165+ return null;
20912166 }
20922167 if ( !isset( $_COOKIE[$wgCentralAuthCookiePrefix . 'Session'] ) ) {
20932168 $id = wfGenerateToken();
@@ -2119,6 +2194,9 @@
21202195
21212196 /**
21222197 * Check if the user is attached on a given wiki id.
 2198+ *
 2199+ * @param $wiki String
 2200+ * @return Bool
21232201 */
21242202 public function attachedOn( $wiki ) {
21252203 return $this->exists() && in_array( $wiki, $this->mAttachedArray );

Comments

#Comment by Aaron Schulz (talk | contribs)   22:50, 31 October 2011

Not type hinting, but documentation.

Status & tagging log