Index: trunk/extensions/CentralAuth/CentralAuthUser.php |
— | — | @@ -20,6 +20,9 @@ |
21 | 21 | /*private*/ var $mVersion = 4; |
22 | 22 | /*private*/ var $mDelayInvalidation = 0; |
23 | 23 | |
| 24 | + var $mAttachedArray, $mEmail, $mEmailAuthenticated, $mHomeWiki, $mHidden, $mLocked, $mAttachedList, $mAuthenticationTimestamp; |
| 25 | + var $mGroups, $mRights, $mPassword, $mAuthToken, $mSalt, $mGlobalId, $mFromMaster, $mIsAttached, $mRegistration; |
| 26 | + |
24 | 27 | static $mCacheVars = array( |
25 | 28 | 'mGlobalId', |
26 | 29 | 'mSalt', |
— | — | @@ -83,6 +86,8 @@ |
84 | 87 | /** |
85 | 88 | * Create a CentralAuthUser object from a joined globaluser/localuser row |
86 | 89 | * |
| 90 | + * @param $row ResourceWrapper|object |
| 91 | + * @param $fromMaster bool |
87 | 92 | * @return CentralAuthUser |
88 | 93 | */ |
89 | 94 | public static function newFromRow( $row, $fromMaster = false ) { |
— | — | @@ -182,6 +187,7 @@ |
183 | 188 | |
184 | 189 | $sets = array(); |
185 | 190 | foreach ( $resSets as $row ) { |
| 191 | + /* @var $row object */ |
186 | 192 | $sets[$row->ggr_group] = WikiSet::newFromRow( $row ); |
187 | 193 | } |
188 | 194 | |
— | — | @@ -190,6 +196,7 @@ |
191 | 197 | $groups = array(); |
192 | 198 | |
193 | 199 | foreach ( $res as $row ) { |
| 200 | + /** @var $set User|bool */ |
194 | 201 | $set = @$sets[$row->ggp_group]; |
195 | 202 | $rights[] = array( 'right' => $row->ggp_permission, 'set' => $set ? $set->getID() : false ); |
196 | 203 | $groups[$row->ggp_group] = 1; |
— | — | @@ -201,6 +208,9 @@ |
202 | 209 | |
203 | 210 | /** |
204 | 211 | * Load user state from a joined globaluser/localuser row |
| 212 | + * |
| 213 | + * @param $row ResourceWrapper|object |
| 214 | + * @param $fromMaster bool |
205 | 215 | */ |
206 | 216 | protected function loadFromRow( $row, $fromMaster = false ) { |
207 | 217 | if ( $row ) { |
— | — | @@ -228,6 +238,10 @@ |
229 | 239 | |
230 | 240 | /** |
231 | 241 | * Load data from memcached |
| 242 | + * |
| 243 | + * @param $cache Array |
| 244 | + * @param $fromMaster Bool |
| 245 | + * @return bool |
232 | 246 | */ |
233 | 247 | protected function loadFromCache( $cache = null, $fromMaster = false ) { |
234 | 248 | wfProfileIn( __METHOD__ ); |
— | — | @@ -254,6 +268,9 @@ |
255 | 269 | |
256 | 270 | /** |
257 | 271 | * Load user state from a cached array. |
| 272 | + * |
| 273 | + * @param $object Array |
| 274 | + * @param $fromMaster Bool |
258 | 275 | */ |
259 | 276 | protected function loadFromCacheObject( $object, $fromMaster = false ) { |
260 | 277 | wfDebugLog( 'CentralAuth', "Loading CentralAuthUser for user {$this->mName} from cache object" ); |
— | — | @@ -306,6 +323,7 @@ |
307 | 324 | |
308 | 325 | /** |
309 | 326 | * Return the global account ID number for this account, if it exists. |
| 327 | + * @return Int |
310 | 328 | */ |
311 | 329 | public function getId() { |
312 | 330 | $this->loadState(); |
— | — | @@ -314,6 +332,7 @@ |
315 | 333 | |
316 | 334 | /** |
317 | 335 | * Generate a valid memcached key for caching the object's data. |
| 336 | + * @return String |
318 | 337 | */ |
319 | 338 | protected function getCacheKey() { |
320 | 339 | return "centralauth-user-" . md5( $this->mName ); |
— | — | @@ -321,6 +340,7 @@ |
322 | 341 | |
323 | 342 | /** |
324 | 343 | * Return the global account's name, whether it exists or not. |
| 344 | + * @return String |
325 | 345 | */ |
326 | 346 | public function getName() { |
327 | 347 | return $this->mName; |
— | — | @@ -435,6 +455,11 @@ |
436 | 456 | * Register a new, not previously existing, central user account |
437 | 457 | * Remaining fields are expected to be filled out shortly... |
438 | 458 | * eeeyuck |
| 459 | + * |
| 460 | + * @param $password String |
| 461 | + * @param $email String |
| 462 | + * @param $realname String |
| 463 | + * @return bool |
439 | 464 | */ |
440 | 465 | function register( $password, $email, $realname ) { |
441 | 466 | $dbw = self::getCentralDB(); |
— | — | @@ -503,6 +528,11 @@ |
504 | 529 | |
505 | 530 | /** |
506 | 531 | * 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 |
507 | 537 | * @return bool Whether we were successful or not. |
508 | 538 | */ |
509 | 539 | protected function storeGlobalData( $salt, $hash, $email, $emailAuth ) { |
— | — | @@ -591,10 +621,11 @@ |
592 | 622 | /** |
593 | 623 | * Go through a list of migration data looking for those which |
594 | 624 | * 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> |
599 | 630 | */ |
600 | 631 | function prepareMigration( $migrationSet, $passwords = array() ) { |
601 | 632 | // If the primary account has an e-mail address set, |
— | — | @@ -655,13 +686,11 @@ |
656 | 687 | * Do a dry run -- pick a winning master account and try to auto-merge |
657 | 688 | * as many as possible, but don't perform any actions yet. |
658 | 689 | * |
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 * |
666 | 695 | * @return Status object |
667 | 696 | */ |
668 | 697 | function migrationDryRun( $passwords, &$home, &$attached, &$unattached, &$methods ) { |
— | — | @@ -718,6 +747,8 @@ |
719 | 748 | /** |
720 | 749 | * Pick a winning master account and try to auto-merge as many as possible. |
721 | 750 | * @fixme add some locking or something |
| 751 | + * |
| 752 | + * @param $passwords Array |
722 | 753 | * @return bool Whether full automatic migration completed successfully. |
723 | 754 | */ |
724 | 755 | protected function attemptAutoMigration( $passwords = array() ) { |
— | — | @@ -928,6 +959,8 @@ |
929 | 960 | |
930 | 961 | /** |
931 | 962 | * Delete a global account |
| 963 | + * |
| 964 | + * @return Status |
932 | 965 | */ |
933 | 966 | function adminDelete() { |
934 | 967 | global $wgMemc; |
— | — | @@ -940,6 +973,7 @@ |
941 | 974 | array( 'lu_name' => $this->mName ), __METHOD__ ); |
942 | 975 | $name = $this->getName(); |
943 | 976 | foreach ( $localUserRes as $localUserRow ) { |
| 977 | + /** @var $localUserRow object */ |
944 | 978 | $wiki = $localUserRow->lu_wiki; |
945 | 979 | wfDebug( __METHOD__ . ": Fixing password on $wiki\n" ); |
946 | 980 | $lb = wfGetLB( $wiki ); |
— | — | @@ -972,6 +1006,8 @@ |
973 | 1007 | |
974 | 1008 | /** |
975 | 1009 | * Lock a global account |
| 1010 | + * |
| 1011 | + * @return Status |
976 | 1012 | */ |
977 | 1013 | function adminLock() { |
978 | 1014 | $dbw = self::getCentralDB(); |
— | — | @@ -991,6 +1027,8 @@ |
992 | 1028 | |
993 | 1029 | /** |
994 | 1030 | * Unlock a global account |
| 1031 | + * |
| 1032 | + * @return Status |
995 | 1033 | */ |
996 | 1034 | function adminUnlock() { |
997 | 1035 | $dbw = self::getCentralDB(); |
— | — | @@ -1010,6 +1048,9 @@ |
1011 | 1049 | |
1012 | 1050 | /** |
1013 | 1051 | * Change account hiding level. |
| 1052 | + * |
| 1053 | + * @param $level String CentralAuthUser::HIDDEN_ class constant |
| 1054 | + * @return Status |
1014 | 1055 | */ |
1015 | 1056 | function adminSetHidden( $level ) { |
1016 | 1057 | $dbw = self::getCentralDB(); |
— | — | @@ -1029,6 +1070,7 @@ |
1030 | 1071 | |
1031 | 1072 | /** |
1032 | 1073 | * Suppresses all user accounts in all wikis. |
| 1074 | + * @param $reason String |
1033 | 1075 | */ |
1034 | 1076 | function suppress( $reason ) { |
1035 | 1077 | global $wgUser; |
— | — | @@ -1037,6 +1079,8 @@ |
1038 | 1080 | |
1039 | 1081 | /** |
1040 | 1082 | * Unsuppresses all user accounts in all wikis. |
| 1083 | + * |
| 1084 | + * @param $reason String |
1041 | 1085 | */ |
1042 | 1086 | function unsuppress( $reason ) { |
1043 | 1087 | global $wgUser; |
— | — | @@ -1044,10 +1088,9 @@ |
1045 | 1089 | } |
1046 | 1090 | |
1047 | 1091 | /** |
1048 | | - * @param $suppress |
1049 | | - * @param $by |
1050 | | - * @param $reason |
1051 | | - * @return void |
| 1092 | + * @param $suppress Bool |
| 1093 | + * @param $by String |
| 1094 | + * @param $reason String |
1052 | 1095 | */ |
1053 | 1096 | protected function doCrosswikiSuppression( $suppress, $by, $reason ) { |
1054 | 1097 | global $wgCentralAuthWikisPerSuppressJob; |
— | — | @@ -1078,6 +1121,12 @@ |
1079 | 1122 | |
1080 | 1123 | /** |
1081 | 1124 | * 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 |
1082 | 1131 | */ |
1083 | 1132 | public function doLocalSuppression( $suppress, $wiki, $by, $reason ) { |
1084 | 1133 | global $wgConf; |
— | — | @@ -1137,12 +1186,13 @@ |
1138 | 1187 | RevisionDeleteUser::unsuppressUserName( $this->mName, $data['id'], $dbw ); |
1139 | 1188 | } |
1140 | 1189 | } |
| 1190 | + return null; |
1141 | 1191 | } |
1142 | 1192 | |
1143 | 1193 | /** |
1144 | 1194 | * 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 |
1147 | 1197 | * |
1148 | 1198 | * Prerequisites: |
1149 | 1199 | * - completed migration state |
— | — | @@ -1272,10 +1322,10 @@ |
1273 | 1323 | } |
1274 | 1324 | |
1275 | 1325 | /** |
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. |
1280 | 1330 | */ |
1281 | 1331 | protected function matchHash( $plaintext, $salt, $encrypted ) { |
1282 | 1332 | if ( User::comparePasswords( $encrypted, $plaintext, $salt ) ) { |
— | — | @@ -1335,6 +1385,7 @@ |
1336 | 1386 | |
1337 | 1387 | $dbs = array(); |
1338 | 1388 | foreach ( $result as $row ) { |
| 1389 | + /** @var $row object */ |
1339 | 1390 | $dbs[] = $row->ln_wiki; |
1340 | 1391 | } |
1341 | 1392 | |
— | — | @@ -1396,6 +1447,8 @@ |
1397 | 1448 | /** |
1398 | 1449 | * Troll through the full set of local databases and list those |
1399 | 1450 | * which exist into the 'localnames' table. |
| 1451 | + * |
| 1452 | + * @return Bool whether any results were found |
1400 | 1453 | */ |
1401 | 1454 | function importLocalNames() { |
1402 | 1455 | $rows = array(); |
— | — | @@ -1463,6 +1516,7 @@ |
1464 | 1517 | |
1465 | 1518 | $wikis = array(); |
1466 | 1519 | foreach ( $result as $row ) { |
| 1520 | + /** @var $row object */ |
1467 | 1521 | $wikis[] = $row->lu_wiki; |
1468 | 1522 | } |
1469 | 1523 | |
— | — | @@ -1505,6 +1559,7 @@ |
1506 | 1560 | |
1507 | 1561 | $wikis = array(); |
1508 | 1562 | foreach ( $result as $row ) { |
| 1563 | + /** @var $row object */ |
1509 | 1564 | $wikis[$row->lu_wiki] = array( |
1510 | 1565 | 'wiki' => $row->lu_wiki, |
1511 | 1566 | 'attachedTimestamp' => wfTimestampOrNull( TS_MW, |
— | — | @@ -1522,10 +1577,10 @@ |
1523 | 1578 | } |
1524 | 1579 | |
1525 | 1580 | /** |
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. |
1528 | 1583 | * |
1529 | | - * Formatted as associative array with some data. |
| 1584 | + * @return Array |
1530 | 1585 | */ |
1531 | 1586 | public function queryUnattached() { |
1532 | 1587 | $wikiIDs = $this->listUnattached(); |
— | — | @@ -1545,6 +1600,9 @@ |
1546 | 1601 | |
1547 | 1602 | /** |
1548 | 1603 | * Fetch a row of user data needed for migration. |
| 1604 | + * |
| 1605 | + * @param $wikiID String |
| 1606 | + * @return Array |
1549 | 1607 | */ |
1550 | 1608 | protected function localUserData( $wikiID ) { |
1551 | 1609 | $lb = wfGetLB( $wikiID ); |
— | — | @@ -1568,6 +1626,8 @@ |
1569 | 1627 | return false; |
1570 | 1628 | } |
1571 | 1629 | |
| 1630 | + /** @var $row object */ |
| 1631 | + |
1572 | 1632 | $data = array( |
1573 | 1633 | 'wiki' => $wikiID, |
1574 | 1634 | 'id' => $row->user_id, |
— | — | @@ -1667,7 +1727,8 @@ |
1668 | 1728 | |
1669 | 1729 | /** |
1670 | 1730 | * Set the account's password |
1671 | | - * @param string $password plaintext |
| 1731 | + * @param $password String plaintext |
| 1732 | + * @return Bool true |
1672 | 1733 | */ |
1673 | 1734 | function setPassword( $password ) { |
1674 | 1735 | list( $salt, $hash ) = $this->saltedPassword( $password ); |
— | — | @@ -1760,10 +1821,12 @@ |
1761 | 1822 | /** |
1762 | 1823 | * Set a global cookie that auto-authenticates the user on other wikis |
1763 | 1824 | * Called on login. |
| 1825 | + * |
| 1826 | + * @param $remember Bool|User |
1764 | 1827 | * @return Session ID |
1765 | 1828 | */ |
1766 | 1829 | function setGlobalCookies( $remember = false ) { |
1767 | | - if ( is_object( $remember ) ) { |
| 1830 | + if ( $remember instanceof User ) { |
1768 | 1831 | // Older code passed a user object here. Be kind and do what they meant to do. |
1769 | 1832 | $remember = $remember->getOption( 'rememberpassword' ); |
1770 | 1833 | } |
— | — | @@ -1804,6 +1867,8 @@ |
1805 | 1868 | * Get the domain parameter for setting a global cookie. |
1806 | 1869 | * This allows other extensions to easily set global cookies without directly relying on |
1807 | 1870 | * $wgCentralAuthCookieDomain (in case CentralAuth's implementation changes at some point). |
| 1871 | + * |
| 1872 | + * @return String |
1808 | 1873 | */ |
1809 | 1874 | static function getCookieDomain() { |
1810 | 1875 | global $wgCentralAuthCookieDomain; |
— | — | @@ -1812,6 +1877,9 @@ |
1813 | 1878 | |
1814 | 1879 | /** |
1815 | 1880 | * Check a global auth token against the one we know of in the database. |
| 1881 | + * |
| 1882 | + * @param $token String |
| 1883 | + * @return Bool |
1816 | 1884 | */ |
1817 | 1885 | function validateAuthToken( $token ) { |
1818 | 1886 | return ( $token == $this->getAuthToken() ); |
— | — | @@ -1943,6 +2011,7 @@ |
1944 | 2012 | $groups = array(); |
1945 | 2013 | |
1946 | 2014 | foreach ( $res as $row ) { |
| 2015 | + /** @var $row object */ |
1947 | 2016 | $groups[] = $row->ggp_group; |
1948 | 2017 | } |
1949 | 2018 | |
— | — | @@ -1963,6 +2032,7 @@ |
1964 | 2033 | $rights = array(); |
1965 | 2034 | |
1966 | 2035 | foreach ( $res as $row ) { |
| 2036 | + /** @var $row object */ |
1967 | 2037 | $rights[] = $row->ggp_permission; |
1968 | 2038 | } |
1969 | 2039 | |
— | — | @@ -1988,6 +2058,7 @@ |
1989 | 2059 | $rights = array(); |
1990 | 2060 | |
1991 | 2061 | foreach ( $res as $row ) { |
| 2062 | + /** @var $row object */ |
1992 | 2063 | $rights[] = $row->ggp_permission; |
1993 | 2064 | } |
1994 | 2065 | |
— | — | @@ -2058,6 +2129,8 @@ |
2059 | 2130 | |
2060 | 2131 | /** |
2061 | 2132 | * Get the central session data |
| 2133 | + * |
| 2134 | + * @return Array |
2062 | 2135 | */ |
2063 | 2136 | static function getSession() { |
2064 | 2137 | global $wgCentralAuthCookies, $wgCentralAuthCookiePrefix; |
— | — | @@ -2080,13 +2153,15 @@ |
2081 | 2154 | |
2082 | 2155 | /** |
2083 | 2156 | * Set the central session data |
| 2157 | + * |
| 2158 | + * @param $data Array |
2084 | 2159 | * @return ID |
2085 | 2160 | */ |
2086 | 2161 | static function setSession( $data ) { |
2087 | 2162 | global $wgCentralAuthCookies, $wgCentralAuthCookiePrefix; |
2088 | 2163 | global $wgMemc; |
2089 | 2164 | if ( !$wgCentralAuthCookies ) { |
2090 | | - return; |
| 2165 | + return null; |
2091 | 2166 | } |
2092 | 2167 | if ( !isset( $_COOKIE[$wgCentralAuthCookiePrefix . 'Session'] ) ) { |
2093 | 2168 | $id = wfGenerateToken(); |
— | — | @@ -2119,6 +2194,9 @@ |
2120 | 2195 | |
2121 | 2196 | /** |
2122 | 2197 | * Check if the user is attached on a given wiki id. |
| 2198 | + * |
| 2199 | + * @param $wiki String |
| 2200 | + * @return Bool |
2123 | 2201 | */ |
2124 | 2202 | public function attachedOn( $wiki ) { |
2125 | 2203 | return $this->exists() && in_array( $wiki, $this->mAttachedArray ); |