r35686 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r35685‎ | r35686 | r35687 >
Date:20:02, 1 June 2008
Author:vasilievvv
Status:old
Tags:
Comment:
* Prevent locked accounts from editing
* Allow stewards to hide accounts from Special:GlobalUsers
* Some random code cleanup
Modified paths:
  • /trunk/extensions/CentralAuth/CentralAuth.i18n.php (modified) (history)
  • /trunk/extensions/CentralAuth/CentralAuth.php (modified) (history)
  • /trunk/extensions/CentralAuth/CentralAuthHooks.php (modified) (history)
  • /trunk/extensions/CentralAuth/CentralAuthUser.php (modified) (history)
  • /trunk/extensions/CentralAuth/SpecialCentralAuth.php (modified) (history)
  • /trunk/extensions/CentralAuth/SpecialGlobalGroupMembership.php (modified) (history)
  • /trunk/extensions/CentralAuth/SpecialGlobalGroupPermissions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralAuth/SpecialGlobalGroupMembership.php
@@ -9,7 +9,7 @@
1010 class SpecialGlobalGroupMembership extends UserrightsPage {
1111 var $mGlobalUser;
1212 function SpecialGlobalGroupMembership() {
13 - SpecialPage::SpecialPage( 'GlobalGroupMembership' );
 13+ parent::__construct( 'GlobalGroupMembership' );
1414 wfLoadExtensionMessages('SpecialCentralAuth');
1515
1616 global $wgUser;
Index: trunk/extensions/CentralAuth/CentralAuthUser.php
@@ -900,6 +900,44 @@
901901 }
902902
903903 /**
 904+ * Hide a global account
 905+ */
 906+ function adminHide() {
 907+ $dbw = self::getCentralDB();
 908+ $dbw->begin();
 909+ $dbw->update( 'globaluser', array( 'gu_hidden' => 1 ),
 910+ array( 'gu_name' => $this->mName ), __METHOD__ );
 911+ if ( !$dbw->affectedRows() ) {
 912+ $dbw->commit();
 913+ return Status::newFatal( 'centralauth-admin-hide-nonexistent', $this->mName );
 914+ }
 915+ $dbw->commit();
 916+
 917+ $this->invalidateCache();
 918+
 919+ return Status::newGood();
 920+ }
 921+
 922+ /**
 923+ * Unhide a global account
 924+ */
 925+ function adminUnhide() {
 926+ $dbw = self::getCentralDB();
 927+ $dbw->begin();
 928+ $dbw->update( 'globaluser', array( 'gu_hidden' => 0 ),
 929+ array( 'gu_name' => $this->mName ), __METHOD__ );
 930+ if ( !$dbw->affectedRows() ) {
 931+ $dbw->commit();
 932+ return Status::newFatal( 'centralauth-admin-unhide-nonexistent', $this->mName );
 933+ }
 934+ $dbw->commit();
 935+
 936+ $this->invalidateCache();
 937+
 938+ return Status::newGood();
 939+ }
 940+
 941+ /**
904942 * Add a local account record for the given wiki to the central database.
905943 * @param string $wikiID
906944 * @param int $localid
Index: trunk/extensions/CentralAuth/SpecialGlobalGroupPermissions.php
@@ -27,7 +27,7 @@
2828 class SpecialGlobalGroupPermissions extends SpecialPage
2929 {
3030 function __construct() {
31 - SpecialPage::SpecialPage('GlobalGroupPermissions', 'globalgrouppermissions');
 31+ parent::__construct('GlobalGroupPermissions', 'globalgrouppermissions');
3232 wfLoadExtensionMessages('SpecialCentralAuth');
3333 }
3434
Index: trunk/extensions/CentralAuth/CentralAuth.php
@@ -150,6 +150,7 @@
151151 $wgHooks['UserGetRights'][] = 'CentralAuthHooks::onUserGetRights';
152152 $wgHooks['UserSetCookies'][] = 'CentralAuthHooks::onUserSetCookies';
153153 $wgHooks['UserLoadDefaults'][] = 'CentralAuthHooks::onUserLoadDefaults';
 154+$wgHooks['getUserPermissionsErrorsExpensive'][] = 'CentralAuthHooks::onGetUserPermissionsErrorsExpensive';
154155
155156 // For interaction with the Special:Renameuser extension
156157 $wgHooks['RenameUserAbort'][] = 'CentralAuthHooks::onRenameUserAbort';
@@ -176,6 +177,8 @@
177178 $wgLogActions['globalauth/delete'] = 'centralauth-log-entry-delete';
178179 $wgLogActions['globalauth/lock'] = 'centralauth-log-entry-lock';
179180 $wgLogActions['globalauth/unlock'] = 'centralauth-log-entry-unlock';
 181+$wgLogActions['globalauth/hide'] = 'centralauth-log-entry-hide';
 182+$wgLogActions['globalauth/unhide'] = 'centralauth-log-entry-unhide';
180183
181184 $wgLogTypes[] = 'gblrights';
182185 $wgLogNames['gblrights'] = 'centralauth-rightslog-name';
Index: trunk/extensions/CentralAuth/SpecialCentralAuth.php
@@ -66,7 +66,7 @@
6767 return;
6868 }
6969
70 - $deleted = $locked = $unlocked = false;
 70+ $deleted = $locked = $unlocked = $hidden = $unhidden = false;
7171
7272 if( $this->mPosted ) {
7373 if ( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
@@ -111,6 +111,26 @@
112112 $unlocked = true;
113113 $this->logAction( 'unlock', $this->mUserName, $wgRequest->getVal( 'reason' ) );
114114 }
 115+ } elseif( $this->mMethod == 'hide' ) {
 116+ $status = $globalUser->adminHide();
 117+ if ( !$status->isGood() ) {
 118+ $this->showStatusError( $status->getWikiText() );
 119+ } else {
 120+ global $wgLang;
 121+ $this->showSuccess( 'centralauth-admin-hide-success', $this->mUserName );
 122+ $hidden = true;
 123+ $this->logAction( 'hide', $this->mUserName, $wgRequest->getVal( 'reason' ) );
 124+ }
 125+ } elseif( $this->mMethod == 'unhide' ) {
 126+ $status = $globalUser->adminUnhide();
 127+ if ( !$status->isGood() ) {
 128+ $this->showStatusError( $status->getWikiText() );
 129+ } else {
 130+ global $wgLang;
 131+ $this->showSuccess( 'centralauth-admin-unhide-success', $this->mUserName );
 132+ $unhidden = true;
 133+ $this->logAction( 'unhide', $this->mUserName, $wgRequest->getVal( 'reason' ) );
 134+ }
115135 } else {
116136 $this->showError( 'centralauth-admin-bad-input' );
117137 }
@@ -120,11 +140,17 @@
121141 $this->showUsernameForm();
122142 if ( !$deleted ) {
123143 $this->showInfo();
124 - $this->showDeleteForm();
 144+ $this->showActionForm( 'delete' );
125145 if( !$globalUser->isLocked() && !$locked )
126 - $this->showLockForm();
 146+ $this->showActionForm( 'lock' );
127147 if( $globalUser->isLocked() && !$unlocked )
128 - $this->showUnlockForm();
 148+ $this->showActionForm( 'unlock' );
 149+ if( !$globalUser->isHidden() && !$hidden ) {
 150+ $this->showActionForm( 'hide' );
 151+ }
 152+ if( $globalUser->isHidden() && !$unhidden ) {
 153+ $this->showActionForm( 'unhide' );
 154+ }
129155 }
130156 }
131157
@@ -309,66 +335,26 @@
310336 Xml::check( 'wpWikis[]', false, array( 'value' => $wikiID ) );
311337 }
312338
313 - function showDeleteForm() {
 339+ function showActionForm( $action ) {
314340 global $wgOut, $wgUser;
315341 $wgOut->addHtml(
316 - Xml::element( 'h2', array(), wfMsg( 'centralauth-admin-delete-title' ) ) .
 342+ Xml::element( 'h2', array(), wfMsg( "centralauth-admin-{$action}-title" ) ) .
317343 Xml::openElement( 'form', array(
318344 'method' => 'POST',
319345 'action' => $this->getTitle()->getFullUrl( 'target=' . urlencode( $this->mUserName ) ) ) ) .
320 - Xml::hidden( 'wpMethod', 'delete' ) .
 346+ Xml::hidden( 'wpMethod', $action ) .
321347 Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
322 - wfMsgExt( 'centralauth-admin-delete-description', 'parse' ) .
 348+ wfMsgExt( "centralauth-admin-{$action}-description", 'parse' ) .
323349 '<p>' .
324 - Xml::label( wfMsgHtml( 'centralauth-admin-reason' ), 'delete-reason' ) .
325 - Xml::input( 'reason', false, false, array( 'id' => 'delete-reason' ) ) .
 350+ Xml::label( wfMsgHtml( 'centralauth-admin-reason' ), "{$action}-reason" ) . ' ' .
 351+ Xml::input( 'reason', false, false, array( 'id' => "{$action}-reason" ) ) .
326352 '</p>' .
327353 '<p>' .
328 - Xml::submitButton( wfMsg( 'centralauth-admin-delete-button' ) ) .
 354+ Xml::submitButton( wfMsg( "centralauth-admin-{$action}-button" ) ) .
329355 '</p>' .
330356 '</form>' );
331357 }
332358
333 - function showLockForm() {
334 - global $wgOut, $wgUser;
335 - $wgOut->addHtml(
336 - Xml::element( 'h2', array(), wfMsg( 'centralauth-admin-lock-title' ) ) .
337 - Xml::openElement( 'form', array(
338 - 'method' => 'POST',
339 - 'action' => $this->getTitle()->getFullUrl( 'target=' . urlencode( $this->mUserName ) ) ) ) .
340 - Xml::hidden( 'wpMethod', 'lock' ) .
341 - Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
342 - wfMsgExt( 'centralauth-admin-lock-description', 'parse' ) .
343 - '<p>' .
344 - Xml::label( wfMsgHtml( 'centralauth-admin-reason' ), 'lock-reason' ) .
345 - Xml::input( 'reason', false, false, array( 'id' => 'lock-reason' ) ) .
346 - '</p>' .
347 - '<p>' .
348 - Xml::submitButton( wfMsg( 'centralauth-admin-lock-button' ) ) .
349 - '</p>' .
350 - '</form>' );
351 - }
352 -
353 - function showUnlockForm() {
354 - global $wgOut, $wgUser;
355 - $wgOut->addHtml(
356 - Xml::element( 'h2', array(), wfMsg( 'centralauth-admin-unlock-title' ) ) .
357 - Xml::openElement( 'form', array(
358 - 'method' => 'POST',
359 - 'action' => $this->getTitle()->getFullUrl( 'target=' . urlencode( $this->mUserName ) ) ) ) .
360 - Xml::hidden( 'wpMethod', 'unlock' ) .
361 - Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
362 - wfMsgExt( 'centralauth-admin-unlock-description', 'parse' ) .
363 - '<p>' .
364 - Xml::label( wfMsgHtml( 'centralauth-admin-reason' ), 'unlock-reason' ) .
365 - Xml::input( 'reason', false, false, array( 'id' => 'unlock-reason' ) ) .
366 - '</p>' .
367 - '<p>' .
368 - Xml::submitButton( wfMsg( 'centralauth-admin-unlock-button' ) ) .
369 - '</p>' .
370 - '</form>' );
371 - }
372 -
373359 function logAction( $action, $target, $reason = '' ) {
374360 $log = new LogPage( 'globalauth' ); //Not centralauth because of some weird length limitiations
375361 $log->addEntry( $action, Title::newFromText( "User:{$target}@global" ), $reason );
Index: trunk/extensions/CentralAuth/CentralAuthHooks.php
@@ -471,4 +471,18 @@
472472 }
473473 return true;
474474 }
 475+
 476+ static function onGetUserPermissionsErrorsExpensive( $title, $user, $action, &$result ) {
 477+ if( $action == 'read' || $user->isAnon() ) {
 478+ return true;
 479+ }
 480+ $centralUser = CentralAuthUser::getInstance( $user );
 481+ if( !($centralUser->exists() && !$centralUser->isAttached()) ) {
 482+ return true;
 483+ }
 484+ if( $centralUser->isLocked() ) {
 485+ $result = 'centralauth-error-locked';
 486+ return false;
 487+ }
 488+ }
475489 }
Index: trunk/extensions/CentralAuth/CentralAuth.i18n.php
@@ -69,6 +69,7 @@
7070 'centralauth-notice-dryrun' => "<div class='successbox'>Demo mode only</div><br clear='all'/>",
7171
7272 'centralauth-disabled-dryrun' => "Account unification is currently in a demo / debugging mode, so actual merging operations are disabled. Sorry!",
 73+ 'centralauth-error-locked' => 'You cannot edit because your account is locked.',
7374
7475 // Appended to various messages above
7576 'centralauth-readmore-text' => ":''[[meta:Help:Unified login|Read more about '''unified login''']]…''",
@@ -160,7 +161,17 @@
161162 'centralauth-admin-unlock-button' => 'Unlock this account',
162163 'centralauth-admin-unlock-success' => 'Successfully unlocked the global account for "<nowiki>$1</nowiki>"',
163164 'centralauth-admin-unlock-nonexistent' => 'Error: the global account "<nowiki>$1</nowiki>" does not exist.',
164 - 'centralauth-admin-reason' => 'Reason: ',
 165+ 'centralauth-admin-hide-title' => 'Hide account',
 166+ 'centralauth-admin-hide-description' => 'Hidden accounts are not shown on [[Special:GlobalUsers]].',
 167+ 'centralauth-admin-hide-button' => 'Hide this account',
 168+ 'centralauth-admin-hide-success' => 'Successfully hid the global account for "<nowiki>$1</nowiki>"',
 169+ 'centralauth-admin-hide-nonexistent' => 'Error: the global account "<nowiki>$1</nowiki>" does not exist.',
 170+ 'centralauth-admin-unhide-title' => 'Unhide account',
 171+ 'centralauth-admin-unhide-description' => 'Unhiding account will make it again appear on [[Special:GlobalUsers]].',
 172+ 'centralauth-admin-unhide-button' => 'Unhide this account',
 173+ 'centralauth-admin-unhide-success' => 'Successfully unhid the global account for "<nowiki>$1</nowiki>"',
 174+ 'centralauth-admin-unhide-nonexistent' => 'Error: the global account "<nowiki>$1</nowiki>" does not exist.',
 175+ 'centralauth-admin-reason' => 'Reason:',
165176
166177 // List of global users
167178 'globalusers' => 'Global user list',
@@ -206,6 +217,8 @@
207218 'centralauth-log-entry-delete' => 'deleted global account "<nowiki>$1</nowiki>"',
208219 'centralauth-log-entry-lock' => 'locked global account "<nowiki>$1</nowiki>"',
209220 'centralauth-log-entry-unlock' => 'unlocked global account "<nowiki>$1</nowiki>"',
 221+ 'centralauth-log-entry-hide' => 'hid global account "<nowiki>$1</nowiki>"',
 222+ 'centralauth-log-entry-unhide' => 'unhid global account "<nowiki>$1</nowiki>"',
210223
211224 'centralauth-rightslog-name' => 'Global rights log',
212225 'centralauth-rightslog-entry-usergroups' => 'changed global group membership for $1 from $2 to $3',

Status & tagging log