r103183 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103182‎ | r103183 | r103184 >
Date:15:57, 15 November 2011
Author:reedy
Status:ok
Tags:
Comment:
Moar documentation
Modified paths:
  • /trunk/extensions/CentralAuth/CentralAuth.php (modified) (history)
  • /trunk/extensions/CentralAuth/CentralAuthHooks.php (modified) (history)
  • /trunk/extensions/CentralAuth/CentralAuthPlugin.php (modified) (history)
  • /trunk/extensions/CentralAuth/CentralAuthUser.php (modified) (history)
  • /trunk/extensions/CentralAuth/CentralAuthUserArray.php (modified) (history)
  • /trunk/extensions/CentralAuth/SuppressUserJob.php (modified) (history)
  • /trunk/extensions/CentralAuth/WikiSet.php (modified) (history)
  • /trunk/extensions/CentralAuth/specials/SpecialGlobalGroupMembership.php (modified) (history)
  • /trunk/extensions/CentralAuth/specials/SpecialMergeAccount.php (modified) (history)
  • /trunk/extensions/CentralAuth/specials/SpecialWikiSets.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralAuth/CentralAuthPlugin.php
@@ -86,9 +86,8 @@
8787 *
8888 * @param $username String: username.
8989 * @return bool
90 - * @public
9190 */
92 - function strictUserAuth( $username ) {
 91+ public function strictUserAuth( $username ) {
9392 // Authenticate locally if the global account doesn't exist,
9493 // or the local account isn't attached
9594 // If strict is on, local authentication won't work at all
@@ -104,10 +103,10 @@
105104 * The User object is passed by reference so it can be modified; don't
106105 * forget the & on your function declaration.
107106 *
108 - * @param User $user
109 - * @public
 107+ * @param $user User
 108+ * @return bool
110109 */
111 - function updateUser( &$user ) {
 110+ public function updateUser( &$user ) {
112111 $central = CentralAuthUser::getInstance( $user );
113112 if ( $central->exists() && $central->isAttached() &&
114113 $central->getEmail() != $user->getEmail() )
@@ -132,9 +131,8 @@
133132 * This is just a question, and shouldn't perform any actions.
134133 *
135134 * @return bool
136 - * @public
137135 */
138 - function autoCreate() {
 136+ public function autoCreate() {
139137 global $wgGroupPermissions;
140138 // Yes unless account creation is restricted on this wiki
141139 return !empty( $wgGroupPermissions['*']['createaccount'] )
@@ -148,9 +146,8 @@
149147 * @param $user User object.
150148 * @param $password String: password.
151149 * @return bool
152 - * @public
153150 */
154 - function setPassword( $user, $password ) {
 151+ public function setPassword( $user, $password ) {
155152 // Fixme: password changes should happen through central interface.
156153 $central = CentralAuthUser::getInstance( $user );
157154 if ( $central->isAttached() ) {
@@ -167,9 +164,8 @@
168165 *
169166 * @param $user User object.
170167 * @return bool
171 - * @public
172168 */
173 - function updateExternalDB( $user ) {
 169+ public function updateExternalDB( $user ) {
174170 return true;
175171 }
176172
@@ -177,9 +173,8 @@
178174 * Check to see if external accounts can be created.
179175 * Return true if external accounts can be created.
180176 * @return bool
181 - * @public
182177 */
183 - function canCreateAccounts() {
 178+ public function canCreateAccounts() {
184179 // Require accounts to be created through the central login interface?
185180 return true;
186181 }
@@ -196,9 +191,8 @@
197192 * @param string $email
198193 * @param string $realname
199194 * @return bool
200 - * @public
201195 */
202 - function addUser( $user, $password, $email = '', $realname = '' ) {
 196+ public function addUser( $user, $password, $email = '', $realname = '' ) {
203197 global $wgCentralAuthAutoNew;
204198 if ( $wgCentralAuthAutoNew ) {
205199 $central = CentralAuthUser::getInstance( $user );
@@ -220,9 +214,8 @@
221215 * This is just a question, and shouldn't perform any actions.
222216 *
223217 * @return bool
224 - * @public
225218 */
226 - function strict() {
 219+ public function strict() {
227220 global $wgCentralAuthStrict;
228221 return $wgCentralAuthStrict;
229222 }
@@ -236,9 +229,9 @@
237230 * forget the & on your function declaration.
238231 *
239232 * @param $user User object.
240 - * @public
 233+ * @param $autocreate bool
241234 */
242 - function initUser( &$user, $autocreate = false ) {
 235+ public function initUser( &$user, $autocreate = false ) {
243236 if ( $autocreate ) {
244237 $central = CentralAuthUser::getInstance( $user );
245238 if ( $central->exists() ) {
@@ -249,17 +242,26 @@
250243 }
251244 }
252245
 246+ /**
 247+ * @param User $user
 248+ * @return CentralAuthUser
 249+ */
253250 public function getUserInstance( User &$user ) {
254251 return CentralAuthUser::getInstance( $user );
255252 }
256 -
 253+
 254+ /**
 255+ * @param $template
 256+ * @param $type
 257+ * @return mixed
 258+ */
257259 public function modifyUITemplate( &$template, &$type ) {
258260 global $wgCentralAuthCookies;
259261
260262 $template->set( 'usedomain', false );
261263
262264 if ( !$wgCentralAuthCookies ) return;
263 -
 265+
264266 $label = Xml::checkLabel( wfMsg( 'centralauth-login-global' ), 'wpCentralLogin', 'wpCentralLogin', true, array( 'tabindex' => '4' ) );
265267 $field = <<<HTML
266268 <tr id="mw-centralauth-login">
Index: trunk/extensions/CentralAuth/CentralAuthUserArray.php
@@ -9,6 +9,9 @@
1010 class CentralAuthUserArrayFromResult extends UserArrayFromResult {
1111 var $globalData;
1212
 13+ /**
 14+ * @param $res ResultWrapper
 15+ */
1316 function __construct( $res ) {
1417 parent::__construct( $res );
1518
@@ -40,6 +43,9 @@
4144 array_keys( $this->globalData ) ) . "\n" );
4245 }
4346
 47+ /**
 48+ * @param $row
 49+ */
4450 function setCurrent( $row ) {
4551 parent::setCurrent( $row );
4652
Index: trunk/extensions/CentralAuth/CentralAuthUser.php
@@ -1341,6 +1341,12 @@
13421342 return false;
13431343 }
13441344
 1345+ /**
 1346+ * @param $passwords
 1347+ * @param $salt
 1348+ * @param $encrypted
 1349+ * @return bool
 1350+ */
13451351 protected function matchHashes( $passwords, $salt, $encrypted ) {
13461352 foreach ( $passwords as $plaintext ) {
13471353 if ( $this->matchHash( $plaintext, $salt, $encrypted ) ) {
Index: trunk/extensions/CentralAuth/CentralAuth.php
@@ -250,6 +250,15 @@
251251 $wgLogActionsHandlers["gblrights/{$type}"] = 'efHandleWikiSetLogEntry';
252252 }
253253
 254+/**
 255+ * @param $type
 256+ * @param $action
 257+ * @param $title
 258+ * @param $skin Skin
 259+ * @param $params
 260+ * @param $filterWikilinks bool
 261+ * @return String
 262+ */
254263 function efHandleWikiSetLogEntry( $type, $action, $title, $skin, $params, $filterWikilinks = false ) {
255264 $link = $skin ? $skin->makeLinkObj( $title, htmlspecialchars( $params[0] ) ) : $params[0];
256265
Index: trunk/extensions/CentralAuth/specials/SpecialGlobalGroupMembership.php
@@ -90,12 +90,22 @@
9191 return CentralAuthUser::availableGlobalGroups();
9292 }
9393
 94+ /**
 95+ * @param $user User
 96+ * @param $output
 97+ */
9498 protected function showLogFragment( $user, $output ) {
9599 $pageTitle = Title::makeTitleSafe( NS_USER, $user->getName() );
96100 $output->addHTML( Xml::element( 'h2', null, LogPage::logName( 'gblrights' ) . "\n" ) );
97101 LogEventsList::showLogExtract( $output, 'gblrights', $pageTitle->getPrefixedText() );
98102 }
99103
 104+ /**
 105+ * @param $user User
 106+ * @param $oldGroups
 107+ * @param $newGroups
 108+ * @param $reason
 109+ */
100110 function addLogEntry( $user, $oldGroups, $newGroups, $reason ) {
101111 $log = new LogPage( 'gblrights' );
102112
Index: trunk/extensions/CentralAuth/specials/SpecialMergeAccount.php
@@ -105,6 +105,9 @@
106106 $this->mSessionKey = $key;
107107 }
108108
 109+ /**
 110+ * @return array|mixed
 111+ */
109112 private function getWorkingPasswords() {
110113 wfSuppressWarnings();
111114 $passwords = unserialize(
@@ -139,6 +142,11 @@
140143 unset( $_SESSION['wsCentralAuthMigration'][$this->mSessionToken] );
141144 }
142145
 146+ /**
 147+ * @param $text
 148+ * @param $key
 149+ * @return array
 150+ */
143151 function xorString( $text, $key ) {
144152 if ( $key != '' ) {
145153 for ( $i = 0; $i < strlen( $text ); $i++ ) {
Index: trunk/extensions/CentralAuth/specials/SpecialWikiSets.php
@@ -156,6 +156,11 @@
157157 }
158158 }
159159
 160+ /**
 161+ * @param $name
 162+ * @param $value
 163+ * @return string
 164+ */
160165 function buildTypeSelector( $name, $value ) {
161166 $select = new XmlSelect( $name, 'set-type', $value );
162167 foreach ( array( WikiSet::OPTIN, WikiSet::OPTOUT ) as $type ) {
@@ -164,6 +169,10 @@
165170 return $select->getHTML();
166171 }
167172
 173+ /**
 174+ * @param $list array
 175+ * @return string
 176+ */
168177 function buildWikiList( $list ) {
169178 sort( $list );
170179 $html = '<ul>';
@@ -278,6 +287,7 @@
279288
280289 $set = WikiSet::newFromID( $set );
281290 if ( !$set ) {
 291+ // FIXME: $subpage is undefined
282292 $this->buildMainView( '<strong class="error">' . wfMsgHtml( 'centralauth-editset-notfound', $subpage ) . '</strong>' );
283293 return;
284294 }
Index: trunk/extensions/CentralAuth/SuppressUserJob.php
@@ -22,7 +22,11 @@
2323 * @return bool
2424 */
2525 public function run() {
26 - extract( $this->params );
 26+ $username = $this->params['username'];
 27+ $by = $this->params['by'];
 28+ $wikis = $this->params['wikis'];
 29+ $suppress = $this->params['suppress'];
 30+ $reason = $this->params['reason'];
2731 $user = new CentralAuthUser( $username );
2832 if ( !$user->exists() ) {
2933 wfDebugLog( 'suppressjob', "Requested to suppress non-existent user {$username} by {$by}." );
Index: trunk/extensions/CentralAuth/CentralAuthHooks.php
@@ -18,6 +18,8 @@
1919
2020 /**
2121 * Add a little pretty to the preferences user info section
 22+ *
 23+ * @param $user User
2224 */
2325 static function onGetPreferences( $user, &$preferences ) {
2426 global $wgUser, $wgLang;
@@ -410,6 +412,8 @@
411413
412414 /**
413415 * Helper function for onUserLoadFromSession
 416+ * @param $user User
 417+ * @param $token
414418 */
415419 static function initSession( $user, $token ) {
416420 $userName = $user->getName();
@@ -564,6 +568,11 @@
565569 return true;
566570 }
567571
 572+ /**
 573+ * @param $user User
 574+ * @param $rights
 575+ * @return bool
 576+ */
568577 static function onUserGetRights( $user, &$rights ) {
569578 if ( !$user->isAnon() ) {
570579 $centralUser = CentralAuthUser::getInstance( $user );
@@ -591,6 +600,10 @@
592601
593602 /**
594603 * Destroy local login cookies so that remote logout works
 604+ * @param $user User
 605+ * @param $session
 606+ * @param $cookies
 607+ * @return bool
595608 */
596609 static function onUserSetCookies( $user, &$session, &$cookies ) {
597610 global $wgCentralAuthCookies;
@@ -624,6 +637,13 @@
625638 return true;
626639 }
627640
 641+ /**
 642+ * @param $title Title
 643+ * @param $user User
 644+ * @param $action
 645+ * @param $result
 646+ * @return bool
 647+ */
628648 static function onGetUserPermissionsErrorsExpensive( $title, $user, $action, &$result ) {
629649 global $wgCentralAuthLockedCanEdit;
630650
@@ -644,6 +664,12 @@
645665 return true;
646666 }
647667
 668+ /**
 669+ * @param $auth
 670+ * @param $user User
 671+ * @param $params
 672+ * @return bool
 673+ */
648674 static function onSecurePoll_GetUserParams( $auth, $user, &$params ) {
649675 if ( $user->isAnon() ) {
650676 return true;
Index: trunk/extensions/CentralAuth/WikiSet.php
@@ -27,19 +27,60 @@
2828
2929 protected static function memcKey( $k ) { return "wikiset:{$k}"; }
3030
 31+ /**
 32+ * @return int
 33+ */
3134 public function getId() { return $this->mId; }
 35+
 36+ /**
 37+ * @return bool
 38+ */
3239 public function exists() { return (bool)$this->getID(); }
 40+
 41+ /**
 42+ * @return string
 43+ */
3344 public function getName() { return $this->mName; }
 45+
 46+ /**
 47+ * @param $n
 48+ * @param $commit bool
 49+ */
3450 public function setName( $n, $commit = false ) { return $this->setDbField( 'ws_name', $n, $commit ); }
 51+
 52+ /**
 53+ * @return array
 54+ */
3555 public function getWikisRaw() { return $this->mWikis; }
 56+
 57+ /**
 58+ * @param $w
 59+ * @param $commit bool
 60+ */
3661 public function setWikisRaw( $w, $commit = false ) { return $this->setDbField( 'ws_wikis', $w, $commit ); }
 62+
 63+ /**
 64+ * @return string
 65+ */
3766 public function getType() { return $this->mType; }
 67+
 68+ /**
 69+ * @param $t
 70+ * @param bool $commit bool
 71+ * @return bool
 72+ */
3873 public function setType( $t, $commit = false ) {
3974 if ( !in_array( $t, array( self::OPTIN, self::OPTOUT ) ) ) {
4075 return false;
4176 }
4277 return $this->setDbField( 'ws_type', $t, $commit );
4378 }
 79+
 80+ /**
 81+ * @param $field
 82+ * @param $value
 83+ * @param $commit
 84+ */
4485 protected function setDbField( $field, $value, $commit ) {
4586 $map = array( 'ws_name' => 'mName', 'ws_type' => 'mType', 'ws_wikis' => 'mWikis' );
4687 $mname = $map[$field];
@@ -49,6 +90,10 @@
5091 }
5192 }
5293
 94+ /**
 95+ * @param $row
 96+ * @return null|WikiSet
 97+ */
5398 public static function newFromRow( $row ) {
5499 if ( !$row ) {
55100 return null;
@@ -61,6 +106,11 @@
62107 );
63108 }
64109
 110+ /**
 111+ * @param $name
 112+ * @param $useCache bool
 113+ * @return null|WikiSet
 114+ */
65115 public static function newFromName( $name, $useCache = true ) {
66116 if ( $useCache ) {
67117 global $wgMemc;
@@ -86,6 +136,11 @@
87137 return $ws;
88138 }
89139
 140+ /**
 141+ * @param $id
 142+ * @param $useCache bool
 143+ * @return null|WikiSet
 144+ */
90145 public static function newFromID( $id, $useCache = true ) {
91146 if ( $useCache ) {
92147 global $wgMemc;
@@ -111,6 +166,9 @@
112167 return $ws;
113168 }
114169
 170+ /**
 171+ * @return bool
 172+ */
115173 public function commit() {
116174 $dbw = CentralAuthUser::getCentralDB();
117175 $dbw->replace( 'wikiset', array( 'ws_id' ),
@@ -129,6 +187,9 @@
130188 return (bool)$dbw->affectedRows();
131189 }
132190
 191+ /**
 192+ * @return bool
 193+ */
133194 public function delete() {
134195 $dbw = CentralAuthUser::getCentralDB();
135196 $dbw->delete( 'wikiset', array( 'ws_id' => $this->mId ), __METHOD__ );
@@ -152,14 +213,21 @@
153214 $wgMemc->set( self::memcKey( $this->mId ), $data );
154215 }
155216
 217+ /**
 218+ * @return array
 219+ */
156220 public function getWikis() {
157221 if ( $this->mType == self::OPTIN ) {
158222 return $this->mWikis;
 223+ } else {
 224+ return array_diff( CentralAuthUser::getWikiList(), $this->mWikis );
159225 }
160 - else
161 - return array_diff( CentralAuthUser::getWikiList(), $this->mWikis );
162226 }
163227
 228+ /**
 229+ * @param $wiki string
 230+ * @return bool
 231+ */
164232 public function inSet( $wiki = '' ) {
165233 if ( !$wiki ) {
166234 $wiki = wfWikiID();
@@ -167,6 +235,9 @@
168236 return in_array( $wiki, $this->getWikis() );
169237 }
170238
 239+ /**
 240+ * @return array
 241+ */
171242 public function getRestrictedGroups() {
172243 $dbr = CentralAuthUser::getCentralSlaveDB();
173244 $r = $dbr->select(
@@ -179,6 +250,9 @@
180251 return $result;
181252 }
182253
 254+ /**
 255+ * @return array
 256+ */
183257 public static function getAllWikiSets() {
184258 $dbr = CentralAuthUser::getCentralSlaveDB();
185259 $res = $dbr->select( 'wikiset', '*', false, __METHOD__ );
@@ -189,12 +263,21 @@
190264 return $result;
191265 }
192266
 267+ /**
 268+ * @param $group
 269+ * @return int
 270+ */
193271 public static function getWikiSetForGroup( $group ) {
194272 $dbr = CentralAuthUser::getCentralSlaveDB();
195273 $res = $dbr->selectRow( 'global_group_restrictions', '*', array( 'ggr_group' => $group ), __METHOD__ );
196274 return $res ? $res->ggr_set : 0;
197275 }
198276
 277+ /**
 278+ * @static
 279+ * @param $type
 280+ * @return string
 281+ */
199282 public static function formatType( $type ) {
200283 return wfMsgHtml( "centralauth-rightslog-set-{$type}" );
201284 }

Status & tagging log