This will probably break something somewhere so when it does please yell at me on IRC and I'll fix it.
*
* @ingroup API
*/
-abstract class ApiBase {
+abstract class ApiBase extends ContextSource {
// These constants allow modules to specify exactly how to treat incoming parameters.
$this->mMainModule = $mainModule;
$this->mModuleName = $moduleName;
$this->mModulePrefix = $modulePrefix;
+
+ if ( !$this->isMain() ) {
+ $this->setContext( $this->mMainModule );
+ }
}
/*****************************************************************************
* The object will have the WebRequest and the User object set to the ones
* used in this instance.
*
+ * @deprecated 1.19 use getContext to get the current context
* @return RequestContext
*/
public function createContext() {
- global $wgUser;
-
- $context = new RequestContext;
- $context->setRequest( $this->getMain()->getRequest() );
- $context->setUser( $wgUser ); /// @todo FIXME: we should store the User object
-
- return $context;
+ return $this->getContext();
}
/**
$userWatching = $titleObj->userIsWatching();
- global $wgUser;
switch ( $watchlist ) {
case 'watch':
return true;
? 'watchdefault' : 'watchcreations';
}
# Watch the article based on the user preference
- return (bool)$wgUser->getOption( $userOption );
+ return (bool)$this->getUser()->getOption( $userOption );
case 'nochange':
return $userWatching;
return;
}
- global $wgUser;
+ $user = $this->getUser();
if ( $value ) {
- WatchAction::doWatch( $titleObj, $wgUser );
+ WatchAction::doWatch( $titleObj, $user );
} else {
- WatchAction::doUnwatch( $titleObj, $wgUser );
+ WatchAction::doUnwatch( $titleObj, $user );
}
}
ApiBase::dieDebug( __METHOD__, "Boolean param $encParamName's default is set to '$default'" );
}
- $value = $this->getMain()->getRequest()->getCheck( $encParamName );
+ $value = $this->getRequest()->getCheck( $encParamName );
} else {
- $value = $this->getMain()->getRequest()->getVal( $encParamName, $default );
+ $value = $this->getRequest()->getVal( $encParamName, $default );
if ( isset( $value ) && $type == 'namespace' ) {
$type = MWNamespace::getValidNamespaces();
* @return User
*/
public function getWatchlistUser( $params ) {
- global $wgUser;
if ( !is_null( $params['owner'] ) && !is_null( $params['token'] ) ) {
$user = User::newFromName( $params['owner'], false );
if ( !$user->getId() ) {
$this->dieUsage( 'Incorrect watchlist token provided -- please set a correct token in Special:Preferences', 'bad_wltoken' );
}
} else {
- if ( !$wgUser->isLoggedIn() ) {
+ if ( !$this->getUser()->isLoggedIn() ) {
$this->dieUsage( 'You must be logged-in to have a watchlist', 'notloggedin' );
}
- $user = $wgUser;
+ $user = $this->getUser();
}
return $user;
}
* of success. If it fails, the result will specify the nature of the error.
*/
public function execute() {
- global $wgUser;
+ $user = $this->getUser();
$params = $this->extractRequestParams();
if ( $params['gettoken'] ) {
- $res['blocktoken'] = $wgUser->editToken( '', $this->getMain()->getRequest() );
+ $res['blocktoken'] = $user->editToken( '', $this->getMain()->getRequest() );
$this->getResult()->addValue( null, $this->getModuleName(), $res );
return;
}
- if ( !$wgUser->isAllowed( 'block' ) ) {
+ if ( !$user->isAllowed( 'block' ) ) {
$this->dieUsageMsg( 'cantblock' );
}
# bug 15810: blocked admins should have limited access here
- if ( $wgUser->isBlocked() ) {
+ if ( $user->isBlocked() ) {
$status = SpecialBlock::checkUnblockSelf( $params['user'] );
if ( $status !== true ) {
$this->dieUsageMsg( array( $status ) );
}
}
- if ( $params['hidename'] && !$wgUser->isAllowed( 'hideuser' ) ) {
+ if ( $params['hidename'] && !$user->isAllowed( 'hideuser' ) ) {
$this->dieUsageMsg( 'canthide' );
}
- if ( $params['noemail'] && !SpecialBlock::canBlockEmail( $wgUser ) ) {
+ if ( $params['noemail'] && !SpecialBlock::canBlockEmail( $user ) ) {
$this->dieUsageMsg( 'cantblock-email' );
}
}
public function execute() {
- global $wgUser;
+ $user = $this->getUser();
$params = $this->extractRequestParams();
if ( is_null( $params['text'] ) && is_null( $params['appendtext'] ) &&
}
// Some functions depend on $wgTitle == $ep->mTitle
+ // TODO: Make them not or check if they still do
global $wgTitle;
$wgTitle = $titleObj;
}
// Now let's check whether we're even allowed to do this
- $errors = $titleObj->getUserPermissionsErrors( 'edit', $wgUser );
+ $errors = $titleObj->getUserPermissionsErrors( 'edit', $user );
if ( !$titleObj->exists() ) {
- $errors = array_merge( $errors, $titleObj->getUserPermissionsErrors( 'create', $wgUser ) );
+ $errors = array_merge( $errors, $titleObj->getUserPermissionsErrors( 'create', $user ) );
}
if ( count( $errors ) ) {
$this->dieUsageMsg( $errors[0] );
$reqArr['wpStarttime'] = wfTimestampNow(); // Fake wpStartime
}
- if ( $params['minor'] || ( !$params['notminor'] && $wgUser->getOption( 'minordefault' ) ) ) {
+ if ( $params['minor'] || ( !$params['notminor'] && $user->getOption( 'minordefault' ) ) ) {
$reqArr['wpMinoredit'] = '';
}
$oldRequest = $wgRequest;
$wgRequest = $req;
- $status = $ep->internalAttemptSave( $result, $wgUser->isAllowed( 'bot' ) && $params['bot'] );
+ $status = $ep->internalAttemptSave( $result, $user->isAllowed( 'bot' ) && $params['bot'] );
$wgRequest = $oldRequest;
global $wgMaxArticleSize;
}
public function execute() {
- global $wgUser;
-
$params = $this->extractRequestParams();
// Validate target
}
// Check permissions and errors
- $error = SpecialEmailUser::getPermissionsError( $wgUser, $params['token'] );
+ $error = SpecialEmailUser::getPermissionsError( $this->getUser(), $params['token'] );
if ( $error ) {
$this->dieUsageMsg( array( $error ) );
}
}
public function execute() {
- global $wgUser;
-
$this->params = $this->extractRequestParams();
// Extract the file and archiveName from the request parameters
$this->validateParameters();
// Check whether we're allowed to revert this file
- $this->checkPermissions( $wgUser );
+ $this->checkPermissions( $this->getUser() );
$sourceUrl = $this->file->getArchiveVirtualUrl( $this->archiveName );
$status = $this->file->upload( $sourceUrl, $this->params['comment'], $this->params['comment'] );
}
public function execute() {
- global $wgUser;
-
+ $user = $this->getUser();
$params = $this->extractRequestParams();
$isUpload = false;
if ( isset( $params['interwikisource'] ) ) {
- if ( !$wgUser->isAllowed( 'import' ) ) {
+ if ( !$user->isAllowed( 'import' ) ) {
$this->dieUsageMsg( 'cantimport' );
}
if ( !isset( $params['interwikipage'] ) ) {
);
} else {
$isUpload = true;
- if ( !$wgUser->isAllowed( 'importupload' ) ) {
+ if ( !$user->isAllowed( 'importupload' ) ) {
$this->dieUsageMsg( 'cantimport-upload' );
}
$source = ImportStreamSource::newFromUpload( 'xml' );
wfSetupSession();
}
- $context = $this->createContext();
+ $context = new DerivativeContext( $this->getContext() );
$context->setRequest( $req );
+ /*$context = $this->createContext();
+ $context->setRequest( $req );*/
$loginForm = new LoginForm();
$loginForm->setContext( $context );
+ $user = $this->getUser();
- global $wgCookiePrefix, $wgUser, $wgPasswordAttemptThrottle;
+ global $wgCookiePrefix, $wgPasswordAttemptThrottle;
$authRes = $loginForm->authenticateUserData();
switch ( $authRes ) {
case LoginForm::SUCCESS:
- $wgUser->setOption( 'rememberpassword', 1 );
- $wgUser->setCookies( $this->getMain()->getRequest() );
+ $user->setOption( 'rememberpassword', 1 );
+ $user->setCookies( $this->getMain()->getRequest() );
// Run hooks.
// @todo FIXME: Split back and frontend from this hook.
// @todo FIXME: This hook should be placed in the backend
$injected_html = '';
- wfRunHooks( 'UserLoginComplete', array( &$wgUser, &$injected_html ) );
+ wfRunHooks( 'UserLoginComplete', array( &$user, &$injected_html ) );
$result['result'] = 'Success';
- $result['lguserid'] = intval( $wgUser->getId() );
- $result['lgusername'] = $wgUser->getName();
- $result['lgtoken'] = $wgUser->getToken();
+ $result['lguserid'] = intval( $user->getId() );
+ $result['lgusername'] = $user->getName();
+ $result['lgtoken'] = $user->getToken();
$result['cookieprefix'] = $wgCookiePrefix;
$result['sessionid'] = session_id();
break;
}
public function execute() {
- global $wgUser;
- $oldName = $wgUser->getName();
- $wgUser->logout();
+ $user = $this->getUser();
+ $oldName = $user->getName();
+ $user->logout();
// Give extensions to do something after user logout
$injected_html = '';
- wfRunHooks( 'UserLogoutComplete', array( &$wgUser, &$injected_html, $oldName ) );
+ wfRunHooks( 'UserLogoutComplete', array( &$user, &$injected_html, $oldName ) );
}
public function isReadMode() {
private $mPrinter;
private $mModules, $mModuleNames, $mFormats, $mFormatNames;
- private $mResult, $mAction, $mShowVersions, $mEnableWrite, $mRequest;
+ private $mResult, $mAction, $mShowVersions, $mEnableWrite/*, $mRequest*/;
private $mInternalMode, $mSquidMaxage, $mModule;
private $mCacheMode = 'private';
/**
* Constructs an instance of ApiMain that utilizes the module and format specified by $request.
*
- * @param $request WebRequest - if this is an instance of FauxRequest, errors are thrown and no printing occurs
+ * @param $context IContextSource|WebRequest - if this is an instance of FauxRequest, errors are thrown and no printing occurs
* @param $enableWrite bool should be set to true if the api may modify data
*/
- public function __construct( $request, $enableWrite = false ) {
- $this->mInternalMode = ( $request instanceof FauxRequest );
+ public function __construct( $context = null, $enableWrite = false ) {
+ if ( $context === null ) {
+ $context = RequestContext::getMain();
+ } elseif ( $context instanceof WebRequest ) {
+ // BC for pre-1.19
+ $request = $context;
+ $context = RequestContext::getMain();
+ $context->setRequest( $request );
+ }
+ // We set a derivative context so we can change stuff later
+ $this->setContext( new DerivativeContext( $context ) );
+
+ $this->mInternalMode = ( $this->getRequest() instanceof FauxRequest );
// Special handling for the main module: $parent === $this
parent::__construct( $this, $this->mInternalMode ? 'main_int' : 'main' );
// Remove all modules other than login
global $wgUser;
- if ( $request->getVal( 'callback' ) !== null ) {
+ if ( $this->getRequest()->getVal( 'callback' ) !== null ) {
// JSON callback allows cross-site reads.
// For safety, strip user credentials.
wfDebug( "API: stripping user credentials for JSON callback\n" );
$wgUser = new User();
+ $this->getContext()->setUser( $wgUser );
}
}
$this->mShowVersions = false;
$this->mEnableWrite = $enableWrite;
- $this->mRequest = &$request;
+ //$this->mRequest = &$request;
$this->mSquidMaxage = - 1; // flag for executeActionWithErrorHandling()
$this->mCommit = false;
* Return the request object that contains client's request
* @return WebRequest
*/
- public function getRequest() {
+ /*public function getRequest() {
return $this->mRequest;
- }
+ }*/
/**
* Get the ApiResult object associated with current request
if ( !isset( $moduleParams['token'] ) ) {
$this->dieUsageMsg( array( 'missingparam', 'token' ) );
} else {
- global $wgUser;
- if ( !$wgUser->matchEditToken( $moduleParams['token'], $salt, $this->getRequest() ) ) {
+ if ( !$this->getUser()->matchEditToken( $moduleParams['token'], $salt, $this->getRequest() ) ) {
$this->dieUsageMsg( 'sessionfailure' );
}
}
* @param $module ApiBase An Api module
*/
protected function checkExecutePermissions( $module ) {
- global $wgUser;
+ $user = $this->getUser();
if ( $module->isReadMode() && !in_array( 'read', User::getGroupPermissions( array( '*' ) ), true ) &&
- !$wgUser->isAllowed( 'read' ) )
+ !$user->isAllowed( 'read' ) )
{
$this->dieUsageMsg( 'readrequired' );
}
if ( !$this->mEnableWrite ) {
$this->dieUsageMsg( 'writedisabled' );
}
- if ( !$wgUser->isAllowed( 'writeapi' ) ) {
+ if ( !$user->isAllowed( 'writeapi' ) ) {
$this->dieUsageMsg( 'writerequired' );
}
if ( wfReadOnly() ) {
*/
protected function setupExternalResponse( $module, $params ) {
// Ignore mustBePosted() for internal calls
- if ( $module->mustBePosted() && !$this->mRequest->wasPosted() ) {
+ if ( $module->mustBePosted() && !$this->getRequest()->wasPosted() ) {
$this->dieUsageMsg( array( 'mustbeposted', $this->mAction ) );
}
*/
public function canApiHighLimits() {
if ( !isset( $this->mCanApiHighLimits ) ) {
- global $wgUser;
- $this->mCanApiHighLimits = $wgUser->isAllowed( 'apihighlimits' );
+ $this->mCanApiHighLimits = $this->getUser()->isAllowed( 'apihighlimits' );
}
return $this->mCanApiHighLimits;
}
public function execute() {
- global $wgUser;
+ $user = $this->getUser();
$params = $this->extractRequestParams();
if ( is_null( $params['reason'] ) ) {
$params['reason'] = '';
&& !RepoGroup::singleton()->getLocalRepo()->findFile( $toTitle )
&& wfFindFile( $toTitle ) )
{
- if ( !$params['ignorewarnings'] && $wgUser->isAllowed( 'reupload-shared' ) ) {
+ if ( !$params['ignorewarnings'] && $user->isAllowed( 'reupload-shared' ) ) {
$this->dieUsageMsg( 'sharedfile-exists' );
- } elseif ( !$wgUser->isAllowed( 'reupload-shared' ) ) {
+ } elseif ( !$user->isAllowed( 'reupload-shared' ) ) {
$this->dieUsageMsg( 'cantoverwrite-sharedfile' );
}
}
}
$r = array( 'from' => $fromTitle->getPrefixedText(), 'to' => $toTitle->getPrefixedText(), 'reason' => $params['reason'] );
- if ( !$params['noredirect'] || !$wgUser->isAllowed( 'suppressredirect' ) ) {
+ if ( !$params['noredirect'] || !$user->isAllowed( 'suppressredirect' ) ) {
$r['redirectcreated'] = '';
}
// The parser needs $wgTitle to be set, apparently the
// $title parameter in Parser::parse isn't enough *sigh*
- global $wgParser, $wgUser, $wgTitle, $wgLang;
+ // TODO: Does this still need $wgTitle?
+ global $wgParser, $wgTitle, $wgLang;
// Currently unnecessary, code to act as a safeguard against any change in current behaviour of uselang breaks
$oldLang = null;
}
if ( $params['pst'] || $params['onlypst'] ) {
- $this->pstText = $wgParser->preSaveTransform( $this->text, $titleObj, $wgUser, $popts );
+ $this->pstText = $wgParser->preSaveTransform( $this->text, $titleObj, $this->getUser(), $popts );
}
if ( $params['onlypst'] ) {
// Build a result and bail out
* Patrols the article or provides the reason the patrol failed.
*/
public function execute() {
- global $wgUser;
-
$params = $this->extractRequestParams();
$rc = RecentChange::newFromID( $params['rcid'] );
if ( !$rc instanceof RecentChange ) {
$this->dieUsageMsg( array( 'nosuchrcid', $params['rcid'] ) );
}
- $retval = $rc->doMarkPatrolled( $wgUser );
+ $retval = $rc->doMarkPatrolled( $this->getUser() );
if ( $retval ) {
$this->dieUsageMsg( reset( $retval ) );
}
public function execute() {
- global $wgUser, $wgRestrictionLevels;
+ global $wgRestrictionLevels;
$params = $this->extractRequestParams();
$titleObj = Title::newFromText( $params['title'] );
$this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
}
- $errors = $titleObj->getUserPermissionsErrors( 'protect', $wgUser );
+ $errors = $titleObj->getUserPermissionsErrors( 'protect', $this->getUser() );
if ( $errors ) {
// We don't care about multiple errors, just report one of them
$this->dieUsageMsg( reset( $errors ) );
* Purges the cache of a page
*/
public function execute() {
- global $wgUser;
+ $user = $this->getUser();
$params = $this->extractRequestParams();
- if ( !$wgUser->isAllowed( 'purge' ) && !$this->getMain()->isInternalMode() &&
- !$this->getMain()->getRequest()->wasPosted() ) {
+ if ( !$user->isAllowed( 'purge' ) && !$this->getMain()->isInternalMode() &&
+ !$this->getRequest()->wasPosted() ) {
$this->dieUsageMsg( array( 'mustbeposted', $this->getModuleName() ) );
}
$r['purged'] = '';
if( $forceLinkUpdate ) {
- if ( !$wgUser->pingLimiter() ) {
+ if ( !$user->pingLimiter() ) {
global $wgParser, $wgEnableParserCache;
$popts = new ParserOptions();
$p_result = $wgParser->parse( $article->getContent(), $title, $popts );
* @return void
*/
public function showHiddenUsersAddBlockInfo( $showBlockInfo ) {
- global $wgUser;
- $userCanViewHiddenUsers = $wgUser->isAllowed( 'hideuser' );
+ $userCanViewHiddenUsers = $this->getUser()->isAllowed( 'hideuser' );
if ( $showBlockInfo || !$userCanViewHiddenUsers ) {
$this->addTables( 'ipblocks' );
}
public function execute() {
- global $wgUser, $wgContLang;
+ global $wgContLang;
$params = $this->extractRequestParams();
$this->requireMaxOneParameter( $params, 'users', 'ip' );
$this->addWhereIf( "ipb_range_end > ipb_range_start", isset( $show['range'] ) );
}
- if ( !$wgUser->isAllowed( 'hideuser' ) ) {
+ if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
$this->addWhereFld( 'ipb_deleted', 0 );
}
}
public function execute() {
- global $wgUser;
+ $user = $this->getUser();
// Before doing anything at all, let's check permissions
- if ( !$wgUser->isAllowed( 'deletedhistory' ) ) {
+ if ( !$user->isAllowed( 'deletedhistory' ) ) {
$this->dieUsage( 'You don\'t have permission to view deleted revision information', 'permissiondenied' );
}
$this->addWhere( 'ar_text_id = old_id' );
// This also means stricter restrictions
- if ( !$wgUser->isAllowed( 'undelete' ) ) {
+ if ( !$user->isAllowed( 'undelete' ) ) {
$this->dieUsage( 'You don\'t have permission to view deleted revision content', 'permissiondenied' );
}
}
if ( $fld_token ) {
// Undelete tokens are identical for all pages, so we cache one here
- $token = $wgUser->editToken( '', $this->getMain()->getRequest() );
+ $token = $user->editToken( '', $this->getMain()->getRequest() );
}
$dir = $params['dir'];
}
public function execute() {
- global $wgUser;
+ $user = $this->getUser();
// Before doing anything at all, let's check permissions
- if ( !$wgUser->isAllowed( 'deletedhistory' ) ) {
+ if ( !$user->isAllowed( 'deletedhistory' ) ) {
$this->dieUsage( 'You don\'t have permission to view deleted file information', 'permissiondenied' );
}
}
}
- if ( !$wgUser->isAllowed( 'suppressrevision' ) ) {
+ if ( !$user->isAllowed( 'suppressrevision' ) ) {
// Filter out revisions that the user is not allowed to see. There
// is no way to indicate that we have skipped stuff because the
// continuation parameter is fa_name
* Get information about watched status and put it in $this->watched
*/
private function getWatchedInfo() {
- global $wgUser;
+ $user = $this->getUser();
- if ( $wgUser->isAnon() || count( $this->everything ) == 0 ) {
+ if ( $user->isAnon() || count( $this->everything ) == 0 ) {
return;
}
$this->addFields( array( 'wl_title', 'wl_namespace' ) );
$this->addWhere( array(
$lb->constructSet( 'wl', $db ),
- 'wl_user' => $wgUser->getID()
+ 'wl_user' => $user->getID()
) );
$res = $this->select( __METHOD__ );
* @param $resultPageSet ApiPageSet
*/
public function run( $resultPageSet = null ) {
- global $wgUser;
$params = $this->extractRequestParams();
$result = $this->getResult();
$qp = new $this->qpMap[$params['page']]();
- if ( !$qp->userCanExecute( $wgUser ) ) {
+ if ( !$qp->userCanExecute( $this->getUser() ) ) {
$this->dieUsageMsg( 'specialpage-cantexecute' );
}
* @param $resultPageSet ApiPageSet
*/
public function run( $resultPageSet = null ) {
- global $wgUser;
+ $user = $this->getUser();
/* Get the parameters of the request. */
$params = $this->extractRequestParams();
// Check permissions
if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ) {
- if ( !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() ) {
+ if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
$this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' );
}
}
/* Set up internal members based upon params. */
$this->initProperties( $prop );
- if ( $this->fld_patrolled && !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() ) {
+ if ( $this->fld_patrolled && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
$this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' );
}
// We're after the revision table, and the corresponding page
// row for anything we retrieve. We may also need the
// recentchanges row and/or tag summary row.
- global $wgUser;
+ $user = $this->getUser();
$tables = array( 'page', 'revision' ); // Order may change
$this->addWhere( 'page_id=rev_page' );
);
}
- if ( !$wgUser->isAllowed( 'hideuser' ) ) {
+ if ( !$user->isAllowed( 'hideuser' ) ) {
$this->addWhere( $this->getDB()->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' );
}
// We only want pages by the specified users.
if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ||
$this->fld_patrolled ) {
- if ( !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() ) {
+ if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
$this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' );
}
}
protected function getCurrentUserInfo() {
- global $wgUser, $wgRequest, $wgHiddenPrefs;
+ global $wgRequest, $wgHiddenPrefs;
+ $user = $this->getUser();
$result = $this->getResult();
$vals = array();
- $vals['id'] = intval( $wgUser->getId() );
- $vals['name'] = $wgUser->getName();
+ $vals['id'] = intval( $user->getId() );
+ $vals['name'] = $user->getName();
- if ( $wgUser->isAnon() ) {
+ if ( $user->isAnon() ) {
$vals['anon'] = '';
}
if ( isset( $this->prop['blockinfo'] ) ) {
- if ( $wgUser->isBlocked() ) {
- $vals['blockedby'] = User::whoIs( $wgUser->blockedBy() );
- $vals['blockreason'] = $wgUser->blockedFor();
+ if ( $user->isBlocked() ) {
+ $vals['blockedby'] = User::whoIs( $user->blockedBy() );
+ $vals['blockreason'] = $user->blockedFor();
}
}
- if ( isset( $this->prop['hasmsg'] ) && $wgUser->getNewtalk() ) {
+ if ( isset( $this->prop['hasmsg'] ) && $user->getNewtalk() ) {
$vals['messages'] = '';
}
if ( isset( $this->prop['groups'] ) ) {
- $autolist = ApiQueryUsers::getAutoGroups( $wgUser );
+ $autolist = ApiQueryUsers::getAutoGroups( $user );
- $vals['groups'] = array_merge( $autolist, $wgUser->getGroups() );
+ $vals['groups'] = array_merge( $autolist, $user->getGroups() );
$result->setIndexedTagName( $vals['groups'], 'g' ); // even if empty
}
if ( isset( $this->prop['implicitgroups'] ) ) {
- $vals['implicitgroups'] = ApiQueryUsers::getAutoGroups( $wgUser );
+ $vals['implicitgroups'] = ApiQueryUsers::getAutoGroups( $user );
$result->setIndexedTagName( $vals['implicitgroups'], 'g' ); // even if empty
}
if ( isset( $this->prop['rights'] ) ) {
// User::getRights() may return duplicate values, strip them
- $vals['rights'] = array_values( array_unique( $wgUser->getRights() ) );
+ $vals['rights'] = array_values( array_unique( $user->getRights() ) );
$result->setIndexedTagName( $vals['rights'], 'r' ); // even if empty
}
if ( isset( $this->prop['changeablegroups'] ) ) {
- $vals['changeablegroups'] = $wgUser->changeableGroups();
+ $vals['changeablegroups'] = $user->changeableGroups();
$result->setIndexedTagName( $vals['changeablegroups']['add'], 'g' );
$result->setIndexedTagName( $vals['changeablegroups']['remove'], 'g' );
$result->setIndexedTagName( $vals['changeablegroups']['add-self'], 'g' );
}
if ( isset( $this->prop['options'] ) ) {
- $vals['options'] = $wgUser->getOptions();
+ $vals['options'] = $user->getOptions();
}
if ( isset( $this->prop['preferencestoken'] ) &&
is_null( $this->getMain()->getRequest()->getVal( 'callback' ) )
) {
- $vals['preferencestoken'] = $wgUser->editToken( '', $this->getMain()->getRequest() );
+ $vals['preferencestoken'] = $user->editToken( '', $this->getMain()->getRequest() );
}
if ( isset( $this->prop['editcount'] ) ) {
- $vals['editcount'] = intval( $wgUser->getEditCount() );
+ $vals['editcount'] = intval( $user->getEditCount() );
}
if ( isset( $this->prop['ratelimits'] ) ) {
}
if ( isset( $this->prop['realname'] ) && !in_array( 'realname', $wgHiddenPrefs ) ) {
- $vals['realname'] = $wgUser->getRealName();
+ $vals['realname'] = $user->getRealName();
}
if ( isset( $this->prop['email'] ) ) {
- $vals['email'] = $wgUser->getEmail();
- $auth = $wgUser->getEmailAuthenticationTimestamp();
+ $vals['email'] = $user->getEmail();
+ $auth = $user->getEmailAuthenticationTimestamp();
if ( !is_null( $auth ) ) {
$vals['emailauthenticated'] = wfTimestamp( TS_ISO_8601, $auth );
}
}
if ( isset( $this->prop['registrationdate'] ) ) {
- $regDate = $wgUser->getRegistration();
+ $regDate = $user->getRegistration();
if ( $regDate !== false ) {
$vals['registrationdate'] = wfTimestamp( TS_ISO_8601, $regDate );
}
}
protected function getRateLimits() {
- global $wgUser, $wgRateLimits;
- if ( !$wgUser->isPingLimitable() ) {
+ global $wgRateLimits;
+ $user = $this->getUser();
+ if ( !$user->isPingLimitable() ) {
return array(); // No limits
}
// Find out which categories we belong to
$categories = array();
- if ( $wgUser->isAnon() ) {
+ if ( $user->isAnon() ) {
$categories[] = 'anon';
} else {
$categories[] = 'user';
}
- if ( $wgUser->isNewbie() ) {
+ if ( $user->isNewbie() ) {
$categories[] = 'ip';
$categories[] = 'subnet';
- if ( !$wgUser->isAnon() )
+ if ( !$user->isAnon() )
$categories[] = 'newbie';
}
- $categories = array_merge( $categories, $wgUser->getGroups() );
+ $categories = array_merge( $categories, $user->getGroups() );
// Now get the actual limits
$retval = array();
// Check permissions.
if ( isset( $show['patrolled'] ) || isset( $show['!patrolled'] ) ) {
- global $wgUser;
- if ( !$wgUser->useRCPatrol() && !$wgUser->useNPPatrol() ) {
+ $user = $this->getUser();
+ if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
$this->dieUsage( 'You need the patrol right to request the patrolled flag', 'permissiondenied' );
}
}
$params = $this->extractRequestParams();
// User and title already validated in call to getTokenSalt from Main
- $titleObj = $this->getTitle();
+ $titleObj = $this->getRbTitle();
$articleObj = new Article( $titleObj );
$summary = ( isset( $params['summary'] ) ? $params['summary'] : '' );
$details = array();
- $retval = $articleObj->doRollback( $this->getUser(), $summary, $params['token'], $params['markbot'], $details );
+ $retval = $articleObj->doRollback( $this->getRbUser(), $summary, $params['token'], $params['markbot'], $details );
if ( $retval ) {
// We don't care about multiple errors, just report one of them
}
public function getTokenSalt() {
- return array( $this->getTitle()->getPrefixedText(), $this->getUser() );
+ return array( $this->getRbTitle()->getPrefixedText(), $this->getRbUser() );
}
- private function getUser() {
+ private function getRbUser() {
if ( $this->mUser !== null ) {
return $this->mUser;
}
/**
* @return Title
*/
- private function getTitle() {
+ private function getRbTitle() {
if ( $this->mTitleObj !== null ) {
return $this->mTitleObj;
}
* Unblocks the specified user or provides the reason the unblock failed.
*/
public function execute() {
- global $wgUser;
+ $user = $this->getUser();
$params = $this->extractRequestParams();
if ( $params['gettoken'] ) {
- $res['unblocktoken'] = $wgUser->editToken( '', $this->getMain()->getRequest() );
+ $res['unblocktoken'] = $user->editToken( '', $this->getMain()->getRequest() );
$this->getResult()->addValue( null, $this->getModuleName(), $res );
return;
}
$this->dieUsageMsg( 'unblock-idanduser' );
}
- if ( !$wgUser->isAllowed( 'block' ) ) {
+ if ( !$user->isAllowed( 'block' ) ) {
$this->dieUsageMsg( 'cantunblock' );
}
# bug 15810: blocked admins should have limited access here
- if ( $wgUser->isBlocked() ) {
+ if ( $user->isBlocked() ) {
$status = SpecialBlock::checkUnblockSelf( $params['user'] );
if ( $status !== true ) {
$this->dieUsageMsg( $status );
}
public function execute() {
- global $wgUser;
$params = $this->extractRequestParams();
- if ( !$wgUser->isAllowed( 'undelete' ) ) {
+ if ( !$this->getUser()->isAllowed( 'undelete' ) ) {
$this->dieUsageMsg( 'permdenied-undelete' );
}
- if ( $wgUser->isBlocked() ) {
+ if ( $this->getUser()->isBlocked() ) {
$this->dieUsageMsg( 'blockedtext' );
}
if ( $retval[1] ) {
wfRunHooks( 'FileUndeleteComplete',
- array( $titleObj, array(), $wgUser, $params['reason'] ) );
+ array( $titleObj, array(), $this->getUser(), $params['reason'] ) );
}
$this->setWatch( $params['watchlist'], $titleObj );
}
public function execute() {
- global $wgUser;
-
// Check whether upload is enabled
if ( !UploadBase::isEnabled() ) {
$this->dieUsageMsg( 'uploaddisabled' );
}
+ $user = $this->getUser();
+
// Parameter handling
$this->mParams = $this->extractRequestParams();
$request = $this->getMain()->getRequest();
}
// First check permission to upload
- $this->checkPermissions( $wgUser );
+ $this->checkPermissions( $user );
// Fetch the file
$status = $this->mUpload->fetchFile();
// (This check is irrelevant if stashing is already requested, since the errors
// can always be fixed by changing the title)
if ( ! $this->mParams['stash'] ) {
- $permErrors = $this->mUpload->verifyTitlePermissions( $wgUser );
+ $permErrors = $this->mUpload->verifyTitlePermissions( $user );
if ( $permErrors !== true ) {
$this->dieRecoverableError( $permErrors[0], 'filename' );
}
$this->dieUsageMsg( 'invalid-file-key' );
}
- if( class_exists( 'RequestContext' ) ) {
- // context allows access to the current user without creating new $wgUser references
- $context = $this->createContext();
- $this->mUpload = new UploadFromStash( $context->getUser() );
- } else {
- // this is here to maintain 1.17 compatibility, so these changes can
- // be merged into production
- // remove this after we've moved to 1.18
- global $wgUser;
- $this->mUpload = new UploadFromStash( $wgUser );
- }
+ $this->mUpload = new UploadFromStash( $this->getUser() );
$this->mUpload->initialize( $this->mParams['filekey'], $this->mParams['filename'] );
* @return array
*/
protected function performUpload() {
- global $wgUser;
-
// Use comment as initial page text by default
if ( is_null( $this->mParams['text'] ) ) {
$this->mParams['text'] = $this->mParams['comment'];
// No errors, no warnings: do the upload
$status = $this->mUpload->performUpload( $this->mParams['comment'],
- $this->mParams['text'], $watch, $wgUser );
+ $this->mParams['text'], $watch, $this->getUser() );
if ( !$status->isGood() ) {
$error = $status->getErrorsArray();
public function execute() {
$params = $this->extractRequestParams();
- $user = $this->getUser();
+ $user = $this->getUrUser();
$form = new UserrightsPage;
$r['user'] = $user->getName();
/**
* @return User
*/
- private function getUser() {
+ private function getUrUser() {
if ( $this->mUser !== null ) {
return $this->mUser;
}
}
public function getTokenSalt() {
- return $this->getUser()->getName();
+ return $this->getUrUser()->getName();
}
public function getExamples() {
}
public function execute() {
- global $wgUser;
- if ( !$wgUser->isLoggedIn() ) {
+ $user = $this->getUser();
+ if ( !$user->isLoggedIn() ) {
$this->dieUsage( 'You must be logged-in to have a watchlist', 'notloggedin' );
}
if ( $params['unwatch'] ) {
$res['unwatched'] = '';
$res['message'] = wfMsgExt( 'removedwatchtext', array( 'parse' ), $title->getPrefixedText() );
- $success = UnwatchAction::doUnwatch( $title, $wgUser );
+ $success = UnwatchAction::doUnwatch( $title, $user );
} else {
$res['watched'] = '';
$res['message'] = wfMsgExt( 'addedwatchtext', array( 'parse' ), $title->getPrefixedText() );
- $success = WatchAction::doWatch( $title, $wgUser );
+ $success = WatchAction::doWatch( $title, $user );
}
if ( !$success ) {
$this->dieUsageMsg( 'hookaborted' );