r97794 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97793‎ | r97794 | r97795 >
Date:06:10, 22 September 2011
Author:tstarling
Status:ok
Tags:
Comment:
Fix for r76344: you can't access $wgUser during the CentralAuthAutoCreate hook, because it's the same object that invoked CentralAuth via UserLoadFromSession, after mLoadedItems is set to true but before any data is initialised. The calling code in CentralAuth does permissions checks correctly, by creating a new User object for the anonymous user who is logging in. That's what I've implemented here too.

Most of the changes here are just propagating the anonymous user object through the call stack.
Modified paths:
  • /trunk/extensions/TitleBlacklist/TitleBlacklist.hooks.php (modified) (history)
  • /trunk/extensions/TitleBlacklist/TitleBlacklist.list.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TitleBlacklist/TitleBlacklist.hooks.php
@@ -74,10 +74,10 @@
7575 *
7676 * @return bool Acceptable
7777 */
78 - private static function acceptNewUserName( $userName, &$err, $override = true ) {
79 - global $wgUser;
 78+ private static function acceptNewUserName( $userName, $permissionsUser, &$err, $override = true ) {
8079 $title = Title::makeTitleSafe( NS_USER, $userName );
81 - $blacklisted = TitleBlacklist::singleton()->userCannot( $title, $wgUser, 'new-account', $override );
 80+ $blacklisted = TitleBlacklist::singleton()->userCannot( $title, $permissionsUser,
 81+ 'new-account', $override );
8282 if( $blacklisted instanceof TitleBlacklistEntry ) {
8383 $message = $blacklisted->getErrorMessage( 'new-account' );
8484 $err = wfMsgWikiHtml( $message, $blacklisted->getRaw(), $userName );
@@ -94,13 +94,15 @@
9595 public static function abortNewAccount( $user, &$message ) {
9696 global $wgUser, $wgRequest;
9797 $override = $wgRequest->getCheck( 'wpIgnoreTitleBlacklist' );
98 - return self::acceptNewUserName( $user->getName(), $message, $override );
 98+ return self::acceptNewUserName( $user->getName(), $wgUser, $message, $override );
9999 }
100100
101101 /** CentralAuthAutoCreate hook */
102102 public static function centralAuthAutoCreate( $user, $userName ) {
103103 $message = ''; # Will be ignored
104 - return self::acceptNewUserName( $userName, $message );
 104+ $anon = new User;
 105+ global $wgUser;
 106+ return self::acceptNewUserName( $userName, $anon, $message );
105107 }
106108
107109 /**
@@ -169,9 +171,9 @@
170172
171173 /** UserCreateForm hook based on the one from AntiSpoof extension */
172174 public static function addOverrideCheckbox( &$template ) {
173 - global $wgRequest;
 175+ global $wgRequest, $wgUser;
174176
175 - if ( TitleBlacklist::userCanOverride( 'new-account' ) ) {
 177+ if ( TitleBlacklist::userCanOverride( $wgUser, 'new-account' ) ) {
176178 $template->addInputItem( 'wpIgnoreTitleBlacklist',
177179 $wgRequest->getCheck( 'wpIgnoreTitleBlacklist' ),
178180 'checkbox', 'titleblacklist-override' );
Index: trunk/extensions/TitleBlacklist/TitleBlacklist.list.php
@@ -152,7 +152,7 @@
153153 * otherwise FALSE
154154 */
155155 public function userCannot( $title, $user, $action = 'edit', $override = true ) {
156 - if( $override && self::userCanOverride( $action ) ) {
 156+ if( $override && self::userCanOverride( $user, $action ) ) {
157157 return false;
158158 } else {
159159 return $this->isBlacklisted( $title, $action );
@@ -283,10 +283,9 @@
284284 *
285285 * @return bool
286286 */
287 - public static function userCanOverride( $action ) {
288 - global $wgUser;
289 - return $wgUser->isAllowed( 'tboverride' ) ||
290 - ( $action == 'new-account' && $wgUser->isAllowed( 'tboverride-account' ) );
 287+ public static function userCanOverride( $user, $action ) {
 288+ return $user->isAllowed( 'tboverride' ) ||
 289+ ( $action == 'new-account' && $user->isAllowed( 'tboverride-account' ) );
291290 }
292291 }
293292

Follow-up revisions

RevisionCommit summaryAuthorDate
r97796Add another hook parameter and extensive documentation to CentralAuthAutoCrea...tstarling06:19, 22 September 2011
r97798MFT r97794, r97797: Fixed TitleBlacklist which was causing "Invalid argument ...tstarling06:32, 22 September 2011
r98759MFT r92930, r96665, r97650, r97701, r97702, r97733, r97794, r97892reedy13:31, 3 October 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r76344Title blacklist:...vasilievvv21:55, 8 November 2010

Status & tagging log