Siebrand has uploaded a new change for review. https://gerrit.wikimedia.org/r/65330
Change subject: Reduce usage of globals ...................................................................... Reduce usage of globals Per https://www.facebook.com/brionv/posts/10151391376376852 and Tim's reply "In favour of RequestContext::getMain()->getUser() which may or may not be better, but it's where we're at with the current code base. At least it can be progressively migrated to $this->context->getUser() which really is nicer." Change-Id: Ib53b89e5d68ac5c41a0dd2d77a12035e7e1d74eb --- M docs/design.txt M includes/AjaxDispatcher.php M includes/AjaxResponse.php M includes/Article.php M includes/ChangesList.php M includes/EditPage.php M includes/FeedUtils.php M includes/FileDeleteForm.php M includes/Linker.php M includes/ProtectionForm.php 10 files changed, 181 insertions(+), 147 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/30/65330/1 diff --git a/docs/design.txt b/docs/design.txt index f95ef0f..def6670 100644 --- a/docs/design.txt +++ b/docs/design.txt @@ -47,7 +47,7 @@ override some of its functions. The User object contains a reference to a skin (according to that user's preference), and so rather than having a global skin object we just rely on the global User and get the skin with - $wgUser->getSkin(). + RequestContext::getMain()->getUser()->getSkin(). See also skin.txt. Language diff --git a/includes/AjaxDispatcher.php b/includes/AjaxDispatcher.php index e22fe20..fe9eac2 100644 --- a/includes/AjaxDispatcher.php +++ b/includes/AjaxDispatcher.php @@ -97,7 +97,7 @@ * request. */ function performAction() { - global $wgAjaxExportList, $wgUser; + global $wgAjaxExportList; if ( empty( $this->mode ) ) { return; @@ -114,7 +114,7 @@ "unknown function " . (string) $this->func_name ); } elseif ( !in_array( 'read', User::getGroupPermissions( array( '*' ) ), true ) - && !$wgUser->isAllowed( 'read' ) ) + && !RequestContext::getMain()->getUser()->isAllowed( 'read' ) ) { wfHttpError( 403, diff --git a/includes/AjaxResponse.php b/includes/AjaxResponse.php index d553652..6f0cfb2 100644 --- a/includes/AjaxResponse.php +++ b/includes/AjaxResponse.php @@ -211,8 +211,10 @@ * @return bool Returns true if the response code was set to 304 Not Modified. */ function checkLastModified( $timestamp ) { - global $wgCachePages, $wgCacheEpoch, $wgUser; + global $wgCachePages, $wgCacheEpoch; + $fname = 'AjaxResponse::checkLastModified'; + $user = RequestContext::getMain()->getUser(); if ( !$timestamp || $timestamp == '19700101000000' ) { wfDebug( "$fname: CACHE DISABLED, NO TIMESTAMP\n" ); @@ -224,13 +226,13 @@ return false; } - if ( $wgUser->getOption( 'nocache' ) ) { + if ( $user->getOption( 'nocache' ) ) { wfDebug( "$fname: USER DISABLED CACHE\n", false ); return false; } $timestamp = wfTimestamp( TS_MW, $timestamp ); - $lastmod = wfTimestamp( TS_RFC2822, max( $timestamp, $wgUser->getTouched(), $wgCacheEpoch ) ); + $lastmod = wfTimestamp( TS_RFC2822, max( $timestamp, $user->getTouched(), $wgCacheEpoch ) ); if ( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) { # IE sends sizes after the date like this: @@ -242,17 +244,17 @@ wfDebug( "$fname: -- client send If-Modified-Since: " . $modsince . "\n", false ); wfDebug( "$fname: -- we might send Last-Modified : $lastmod\n", false ); - if ( ( $ismodsince >= $timestamp ) && $wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) { + if ( ( $ismodsince >= $timestamp ) && $user->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) { ini_set( 'zlib.output_compression', 0 ); $this->setResponseCode( "304 Not Modified" ); $this->disable(); $this->mLastModified = $lastmod; - wfDebug( "$fname: CACHED client: $ismodsince ; user: {$wgUser->getTouched()} ; page: $timestamp ; site $wgCacheEpoch\n", false ); + wfDebug( "$fname: CACHED client: $ismodsince ; user: {$user->getTouched()} ; page: $timestamp ; site $wgCacheEpoch\n", false ); return true; } else { - wfDebug( "$fname: READY client: $ismodsince ; user: {$wgUser->getTouched()} ; page: $timestamp ; site $wgCacheEpoch\n", false ); + wfDebug( "$fname: READY client: $ismodsince ; user: {$user->getTouched()} ; page: $timestamp ; site $wgCacheEpoch\n", false ); $this->mLastModified = $lastmod; } } else { diff --git a/includes/Article.php b/includes/Article.php index dc57911..23261a7 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -51,7 +51,7 @@ protected $mPage; /** - * ParserOptions object for $wgUser articles + * ParserOptions object for RequestContext::getMain()->getUser() articles * @var ParserOptions $mParserOptions */ public $mParserOptions; diff --git a/includes/ChangesList.php b/includes/ChangesList.php index 1b6b396..2883345 100644 --- a/includes/ChangesList.php +++ b/includes/ChangesList.php @@ -467,8 +467,7 @@ * @return Boolean */ public static function usePatrol() { - global $wgUser; - return $wgUser->useRCPatrol(); + return RequestContext::getMain()->getUser()->useRCPatrol(); } /** @@ -502,7 +501,7 @@ * field of this revision, if it's marked as deleted. * @param $rc RCCacheEntry * @param $field Integer - * @param $user User object to check, or null to use $wgUser + * @param $user User object to check, or null to use RequestContext::getMain()->getUser() * @return Boolean */ public static function userCan( $rc, $field, User $user = null ) { diff --git a/includes/EditPage.php b/includes/EditPage.php index 27f4556..a37f8b1 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -335,7 +335,6 @@ * the newly-edited page. */ function edit() { - global $wgOut, $wgRequest, $wgUser; // Allow extensions to modify/prevent this form or submission if ( !wfRunHooks( 'AlternateEdit', array( $this ) ) ) { return; @@ -344,14 +343,16 @@ wfProfileIn( __METHOD__ ); wfDebug( __METHOD__ . ": enter\n" ); + $context = RequestContext::getMain(); + // If they used redlink=1 and the page exists, redirect to the main article - if ( $wgRequest->getBool( 'redlink' ) && $this->mTitle->exists() ) { - $wgOut->redirect( $this->mTitle->getFullURL() ); + if ( $context->getRequest()->getBool( 'redlink' ) && $this->mTitle->exists() ) { + $context->getOutput()->redirect( $this->mTitle->getFullURL() ); wfProfileOut( __METHOD__ ); return; } - $this->importFormData( $wgRequest ); + $this->importFormData( $context->getRequest() ); $this->firsttime = false; if ( $this->live ) { @@ -385,7 +386,7 @@ if ( $permErrors ) { wfDebug( __METHOD__ . ": User can't edit\n" ); // Auto-block user's IP if the account was "hard" blocked - $wgUser->spreadAnyEditBlock(); + $context->getUser()->spreadAnyEditBlock(); $this->displayPermissionsError( $permErrors ); @@ -447,12 +448,13 @@ * @return array */ protected function getEditPermissionErrors() { - global $wgUser; - $permErrors = $this->mTitle->getUserPermissionsErrors( 'edit', $wgUser ); + $user = RequestContext::getMain()->getUser(); + $permErrors = $this->mTitle->getUserPermissionsErrors( 'edit', $user ); + # Can this title be created? if ( !$this->mTitle->exists() ) { $permErrors = array_merge( $permErrors, - wfArrayDiff2( $this->mTitle->getUserPermissionsErrors( 'create', $wgUser ), $permErrors ) ); + wfArrayDiff2( $this->mTitle->getUserPermissionsErrors( 'create', $user ), $permErrors ) ); } # Ignore some permissions errors when a user is just previewing/viewing diffs $remove = array(); @@ -481,13 +483,13 @@ * @throws PermissionsError */ protected function displayPermissionsError( array $permErrors ) { - global $wgRequest, $wgOut; + $out = RequestContext::getMain()->getOutput(); - if ( $wgRequest->getBool( 'redlink' ) ) { + if ( RequestContext::getMain()->getRequest()->getBool( 'redlink' ) ) { // The edit page was reached via a red link. // Redirect to the article page and let them click the edit tab if // they really want a permission error. - $wgOut->redirect( $this->mTitle->getFullURL() ); + $out->redirect( $this->mTitle->getFullURL() ); return; } @@ -500,29 +502,29 @@ throw new PermissionsError( $action, $permErrors ); } - $wgOut->setRobotPolicy( 'noindex,nofollow' ); - $wgOut->setPageTitle( wfMessage( 'viewsource-title', $this->getContextTitle()->getPrefixedText() ) ); - $wgOut->addBacklinkSubtitle( $this->getContextTitle() ); - $wgOut->addWikiText( $wgOut->formatPermissionsErrorMessage( $permErrors, 'edit' ) ); - $wgOut->addHTML( "<hr />\n" ); + $out->setRobotPolicy( 'noindex,nofollow' ); + $out->setPageTitle( wfMessage( 'viewsource-title', $this->getContextTitle()->getPrefixedText() ) ); + $out->addBacklinkSubtitle( $this->getContextTitle() ); + $out->addWikiText( $out->formatPermissionsErrorMessage( $permErrors, 'edit' ) ); + $out->addHTML( "<hr />\n" ); # If the user made changes, preserve them when showing the markup # (This happens when a user is blocked during edit, for instance) if ( !$this->firsttime ) { $text = $this->textbox1; - $wgOut->addWikiMsg( 'viewyourtext' ); + $out->addWikiMsg( 'viewyourtext' ); } else { $text = $this->toEditText( $content ); - $wgOut->addWikiMsg( 'viewsourcetext' ); + $out->addWikiMsg( 'viewsourcetext' ); } $this->showTextbox( $text, 'wpTextbox1', array( 'readonly' ) ); - $wgOut->addHTML( Html::rawElement( 'div', array( 'class' => 'templatesUsed' ), + $out->addHTML( Html::rawElement( 'div', array( 'class' => 'templatesUsed' ), Linker::formatTemplates( $this->getTemplates() ) ) ); if ( $this->mTitle->exists() ) { - $wgOut->returnToMain( null, $this->mTitle ); + $out->returnToMain( null, $this->mTitle ); } } @@ -535,14 +537,13 @@ function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) { wfDeprecated( __METHOD__, '1.19' ); - global $wgRequest, $wgOut; - if ( $wgRequest->getBool( 'redlink' ) ) { + if ( RequestContext::getMain()->getRequest()->getBool( 'redlink' ) ) { // The edit page was reached via a red link. // Redirect to the article page and let them click the edit tab if // they really want a permission error. - $wgOut->redirect( $this->mTitle->getFullURL() ); + RequestContext::getMain()->getOutput()->redirect( $this->mTitle->getFullURL() ); } else { - $wgOut->readOnlyPage( $source, $protected, $reasons, $action ); + RequestContext::getMain()->getOutput()->readOnlyPage( $source, $protected, $reasons, $action ); } } @@ -552,17 +553,20 @@ * @return bool */ protected function previewOnOpen() { - global $wgRequest, $wgUser, $wgPreviewOnOpenNamespaces; - if ( $wgRequest->getVal( 'preview' ) == 'yes' ) { + global $wgPreviewOnOpenNamespaces; + + $request = RequestContext::getMain()->getRequest(); + + if ( $request->getVal( 'preview' ) == 'yes' ) { // Explicit override from request return true; - } elseif ( $wgRequest->getVal( 'preview' ) == 'no' ) { + } elseif ( $request->getVal( 'preview' ) == 'no' ) { // Explicit override from request return false; } elseif ( $this->section == 'new' ) { // Nothing *to* preview for new sections return false; - } elseif ( ( $wgRequest->getVal( 'preload' ) !== null || $this->mTitle->exists() ) && $wgUser->getOption( 'previewonfirst' ) ) { + } elseif ( ( $request->getVal( 'preload' ) !== null || $this->mTitle->exists() ) && RequestContext::getMain()->getUser()->getOption( 'previewonfirst' ) ) { // Standard preference behavior return true; } elseif ( !$this->mTitle->exists() && diff --git a/includes/FeedUtils.php b/includes/FeedUtils.php index 22cb52b..43c3cca 100644 --- a/includes/FeedUtils.php +++ b/includes/FeedUtils.php @@ -37,9 +37,11 @@ * @param string $key cache key of feed's content */ public static function checkPurge( $timekey, $key ) { - global $wgRequest, $wgUser, $messageMemc; - $purge = $wgRequest->getVal( 'action' ) === 'purge'; - if ( $purge && $wgUser->isAllowed( 'purge' ) ) { + global $messageMemc; + + $context = RequestContext::getMain(); + $purge = $context->getRequest()->getVal( 'action' ) === 'purge'; + if ( $purge && $context->getUser()->isAllowed( 'purge' ) ) { $messageMemc->delete( $timekey ); $messageMemc->delete( $key ); } @@ -52,15 +54,15 @@ * @return Boolean */ public static function checkFeedOutput( $type ) { - global $wgOut, $wgFeed, $wgFeedClasses; + global $wgFeed, $wgFeedClasses; if ( !$wgFeed ) { - $wgOut->addWikiMsg( 'feed-unavailable' ); + RequestContext::getMain()->getOutput()->addWikiMsg( 'feed-unavailable' ); return false; } if ( !isset( $wgFeedClasses[$type] ) ) { - $wgOut->addWikiMsg( 'feed-invalid' ); + RequestContext::getMain()->getOutput()->addWikiMsg( 'feed-invalid' ); return false; } diff --git a/includes/FileDeleteForm.php b/includes/FileDeleteForm.php index 9fc70eb..4ff723b 100644 --- a/includes/FileDeleteForm.php +++ b/includes/FileDeleteForm.php @@ -60,9 +60,14 @@ * pending authentication, confirmation, etc. */ public function execute() { - global $wgOut, $wgRequest, $wgUser, $wgUploadMaintenance; + global $wgUploadMaintenance; - $permissionErrors = $this->title->getUserPermissionsErrors( 'delete', $wgUser ); + $context = RequestContext::getMain(); + $out = $context->getOutput(); + $request = $context->getRequest(); + $user = $context->getUser(); + + $permissionErrors = $this->title->getUserPermissionsErrors( 'delete', $user ); if ( count( $permissionErrors ) ) { throw new PermissionsError( 'delete', $permissionErrors ); } @@ -77,25 +82,25 @@ $this->setHeaders(); - $this->oldimage = $wgRequest->getText( 'oldimage', false ); - $token = $wgRequest->getText( 'wpEditToken' ); + $this->oldimage = $request->getText( 'oldimage', false ); + $token = $request->getText( 'wpEditToken' ); # Flag to hide all contents of the archived revisions - $suppress = $wgRequest->getVal( 'wpSuppress' ) && $wgUser->isAllowed( 'suppressrevision' ); + $suppress = $request->getVal( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' ); if ( $this->oldimage ) { $this->oldfile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $this->title, $this->oldimage ); } if ( !self::haveDeletableFile( $this->file, $this->oldfile, $this->oldimage ) ) { - $wgOut->addHTML( $this->prepareMessage( 'filedelete-nofile' ) ); - $wgOut->addReturnTo( $this->title ); + $out->addHTML( $this->prepareMessage( 'filedelete-nofile' ) ); + $out->addReturnTo( $this->title ); return; } // Perform the deletion if appropriate - if ( $wgRequest->wasPosted() && $wgUser->matchEditToken( $token, $this->oldimage ) ) { - $deleteReasonList = $wgRequest->getText( 'wpDeleteReasonList' ); - $deleteReason = $wgRequest->getText( 'wpReason' ); + if ( $request->wasPosted() && $user->matchEditToken( $token, $this->oldimage ) ) { + $deleteReasonList = $request->getText( 'wpDeleteReasonList' ); + $deleteReason = $request->getText( 'wpReason' ); if ( $deleteReasonList == 'other' ) { $reason = $deleteReason; @@ -107,27 +112,28 @@ $reason = $deleteReasonList; } - $status = self::doDelete( $this->title, $this->file, $this->oldimage, $reason, $suppress, $wgUser ); + $status = self::doDelete( $this->title, $this->file, $this->oldimage, $reason, $suppress, $user ); if ( !$status->isGood() ) { - $wgOut->addHTML( '<h2>' . $this->prepareMessage( 'filedeleteerror-short' ) . "</h2>\n" ); - $wgOut->addWikiText( '<div class="error">' . $status->getWikiText( 'filedeleteerror-short', 'filedeleteerror-long' ) . '</div>' ); + $out->addHTML( '<h2>' . $this->prepareMessage( 'filedeleteerror-short' ) . "</h2>\n" ); + $out->addWikiText( '<div class="error">' . $status->getWikiText( 'filedeleteerror-short', 'filedeleteerror-long' ) . '</div>' ); } if ( $status->ok ) { - $wgOut->setPageTitle( wfMessage( 'actioncomplete' ) ); - $wgOut->addHTML( $this->prepareMessage( 'filedelete-success' ) ); + $out->setPageTitle( wfMessage( 'actioncomplete' ) ); + $out->addHTML( $this->prepareMessage( 'filedelete-success' ) ); // Return to the main page if we just deleted all versions of the // file, otherwise go back to the description page - $wgOut->addReturnTo( $this->oldimage ? $this->title : Title::newMainPage() ); + $out->addReturnTo( $this->oldimage ? $this->title : Title::newMainPage() ); - if ( $wgUser->isLoggedIn() && $wgRequest->getCheck( 'wpWatch' ) != $wgUser->isWatched( $this->title ) ) { - if ( $wgRequest->getCheck( 'wpWatch' ) ) { - WatchAction::doWatch( $this->title, $wgUser ); + if ( $user->isLoggedIn() && $request->getCheck( 'wpWatch' ) != $user->isWatched( $this->title ) ) { + if ( $request->getCheck( 'wpWatch' ) ) { + WatchAction::doWatch( $this->title, $user ); } else { - WatchAction::doUnwatch( $this->title, $wgUser ); + WatchAction::doUnwatch( $this->title, $user ); } } } + return; } @@ -149,8 +155,7 @@ */ public static function doDelete( &$title, &$file, &$oldimage, $reason, $suppress, User $user = null ) { if ( $user === null ) { - global $wgUser; - $user = $wgUser; + $user = RequestContext::getMain()->getUser(); } if ( $oldimage ) { @@ -211,9 +216,10 @@ * Show the confirmation form */ private function showForm() { - global $wgOut, $wgUser, $wgRequest; + $context = RequestContext::getMain(); + $user = $context->getUser(); - if ( $wgUser->isAllowed( 'suppressrevision' ) ) { + if ( $user->isAllowed( 'suppressrevision' ) ) { $suppress = "<tr id=\"wpDeleteSuppressRow\"> <td></td> <td class='mw-input'><strong>" . @@ -225,12 +231,12 @@ $suppress = ''; } - $checkWatch = $wgUser->getBoolOption( 'watchdeletion' ) || $wgUser->isWatched( $this->title ); + $checkWatch = $user->getBoolOption( 'watchdeletion' ) || $user->isWatched( $this->title ); $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getAction(), 'id' => 'mw-img-deleteconfirm' ) ) . Xml::openElement( 'fieldset' ) . Xml::element( 'legend', null, wfMessage( 'filedelete-legend' )->text() ) . - Html::hidden( 'wpEditToken', $wgUser->getEditToken( $this->oldimage ) ) . + Html::hidden( 'wpEditToken', $user->getEditToken( $this->oldimage ) ) . $this->prepareMessage( 'filedelete-intro' ) . Xml::openElement( 'table', array( 'id' => 'mw-img-deleteconfirm-table' ) ) . "<tr> @@ -253,12 +259,12 @@ Xml::label( wfMessage( 'filedelete-otherreason' )->text(), 'wpReason' ) . "</td> <td class='mw-input'>" . - Xml::input( 'wpReason', 60, $wgRequest->getText( 'wpReason' ), + Xml::input( 'wpReason', 60, $context->getRequest()->getText( 'wpReason' ), array( 'type' => 'text', 'maxlength' => '255', 'tabindex' => '2', 'id' => 'wpReason' ) ) . "</td> </tr> {$suppress}"; - if ( $wgUser->isLoggedIn() ) { + if ( $user->isLoggedIn() ) { $form .= " <tr> <td></td> @@ -280,7 +286,7 @@ Xml::closeElement( 'fieldset' ) . Xml::closeElement( 'form' ); - if ( $wgUser->isAllowed( 'editinterface' ) ) { + if ( $user->isAllowed( 'editinterface' ) ) { $title = Title::makeTitle( NS_MEDIAWIKI, 'Filedelete-reason-dropdown' ); $link = Linker::link( $title, @@ -291,17 +297,18 @@ $form .= '<p class="mw-filedelete-editreasons">' . $link . '</p>'; } - $wgOut->addHTML( $form ); + $context->getOutput()->addHTML( $form ); } /** * Show deletion log fragments pertaining to the current file */ private function showLogEntries() { - global $wgOut; + $out = RequestContext::getMain()->getOutput(); $deleteLogPage = new LogPage( 'delete' ); - $wgOut->addHTML( '<h2>' . $deleteLogPage->getName()->escaped() . "</h2>\n" ); - LogEventsList::showLogExtract( $wgOut, 'delete', $this->title ); + + $out->addHTML( '<h2>' . $deleteLogPage->getName()->escaped() . "</h2>\n" ); + LogEventsList::showLogExtract( $out, 'delete', $this->title ); } /** @@ -313,13 +320,13 @@ * @return String */ private function prepareMessage( $message ) { - global $wgLang; if ( $this->oldimage ) { + $lang = RequestContext::getMain()->getLanguage(); return wfMessage( "{$message}-old", # To ensure grep will find them: 'filedelete-intro-old', 'filedelete-nofile-old', 'filedelete-success-old' wfEscapeWikiText( $this->title->getText() ), - $wgLang->date( $this->getTimestamp(), true ), - $wgLang->time( $this->getTimestamp(), true ), + $lang->date( $this->getTimestamp(), true ), + $lang->time( $this->getTimestamp(), true ), wfExpandUrl( $this->file->getArchiveUrl( $this->oldimage ), PROTO_CURRENT ) )->parseAsBlock(); } else { return wfMessage( @@ -333,10 +340,11 @@ * Set headers, titles and other bits */ private function setHeaders() { - global $wgOut; - $wgOut->setPageTitle( wfMessage( 'filedelete', $this->title->getText() ) ); - $wgOut->setRobotPolicy( 'noindex,nofollow' ); - $wgOut->addBacklinkSubtitle( $this->title ); + $out = RequestContext::getMain()->getOutput(); + + $out->setPageTitle( wfMessage( 'filedelete', $this->title->getText() ) ); + $out->setRobotPolicy( 'noindex,nofollow' ); + $out->addBacklinkSubtitle( $this->title ); } /** diff --git a/includes/Linker.php b/includes/Linker.php index 3529d28..d35f5aa 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -319,7 +319,6 @@ */ private static function linkAttribs( $target, $attribs, $options ) { wfProfileIn( __METHOD__ ); - global $wgUser; $defaults = array(); if ( !in_array( 'noclasses', $options ) ) { @@ -336,7 +335,11 @@ } if ( !in_array( 'broken', $options ) ) { # Avoid useless calls to LinkCache (see r50387) - $colour = self::getLinkColour( $target, $wgUser->getStubThreshold() ); + $colour = self::getLinkColour( + $target, + RequestContext::getMain()->getUser()->getStubThreshold() + ); + if ( $colour !== '' ) { $classes[] = $colour; # mw-redirect or stub } @@ -344,6 +347,7 @@ if ( $classes != array() ) { $defaults['class'] = implode( ' ', $classes ); } + wfProfileOut( __METHOD__ . '-getClasses' ); } @@ -407,10 +411,9 @@ * @deprecated since 1.17 */ static function makeSizeLinkObj( $size, $nt, $text = '', $query = '', $trail = '', $prefix = '' ) { - global $wgUser; wfDeprecated( __METHOD__, '1.17' ); - $threshold = $wgUser->getStubThreshold(); + $threshold = RequestContext::getMain()->getUser()->getStubThreshold(); $colour = ( $size < $threshold ) ? 'stub' : ''; // @todo FIXME: Replace deprecated makeColouredLinkObj by link() return self::makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix ); @@ -1126,7 +1129,8 @@ public static function userToolLinks( $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits = null ) { - global $wgUser, $wgDisableAnonTalk, $wgLang; + global $wgDisableAnonTalk; + $talkable = !( $wgDisableAnonTalk && 0 == $userId ); $blockable = !( $flags & self::TOOL_LINKS_NOBLOCK ); $addEmailLink = $flags & self::TOOL_LINKS_EMAIL && $userId; @@ -1151,11 +1155,15 @@ $items[] = self::link( $contribsPage, wfMessage( 'contribslink' )->escaped(), $attribs ); } - if ( $blockable && $wgUser->isAllowed( 'block' ) ) { + + $context = RequestContext::getMain(); + $user = $context->getUser(); + + if ( $blockable && $user->isAllowed( 'block' ) ) { $items[] = self::blockLink( $userId, $userText ); } - if ( $addEmailLink && $wgUser->canSendEmail() ) { + if ( $addEmailLink && $user->canSendEmail() ) { $items[] = self::emailLink( $userId, $userText ); } @@ -1164,7 +1172,7 @@ if ( $items ) { return wfMessage( 'word-separator' )->plain() . '<span class="mw-usertoollinks">' - . wfMessage( 'parentheses' )->rawParams( $wgLang->pipeList( $items ) )->escaped() + . wfMessage( 'parentheses' )->rawParams( $context->getLanguage()->pipeList( $items ) )->escaped() . '</span>'; } else { return ''; diff --git a/includes/ProtectionForm.php b/includes/ProtectionForm.php index 6f444ee..a303d64 100644 --- a/includes/ProtectionForm.php +++ b/includes/ProtectionForm.php @@ -58,7 +58,6 @@ var $mExistingExpiry = array(); function __construct( Page $article ) { - global $wgUser; // Set instance variables. $this->mArticle = $article; $this->mTitle = $article->getTitle(); @@ -66,10 +65,15 @@ // Check if the form should be disabled. // If it is, the form will be available in read-only to show levels. - $this->mPermErrors = $this->mTitle->getUserPermissionsErrors( 'protect', $wgUser ); + $this->mPermErrors = $this->mTitle->getUserPermissionsErrors( + 'protect', + RequestContext::getMain()->getUser() + ); + if ( wfReadOnly() ) { $this->mPermErrors[] = array( 'readonlytext', wfReadOnlyReason() ); } + $this->disabled = $this->mPermErrors != array(); $this->disabledAttrib = $this->disabled ? array( 'disabled' => 'disabled' ) @@ -82,14 +86,15 @@ * Loads the current state of protection into the object. */ function loadData() { - global $wgRequest, $wgUser; global $wgRestrictionLevels; + $context = RequestContext::getMain(); + $request = $context->getRequest(); $this->mCascade = $this->mTitle->areRestrictionsCascading(); - $this->mReason = $wgRequest->getText( 'mwProtect-reason' ); - $this->mReasonSelection = $wgRequest->getText( 'wpProtectReasonSelection' ); - $this->mCascade = $wgRequest->getBool( 'mwProtect-cascade', $this->mCascade ); + $this->mReason = $request->getText( 'mwProtect-reason' ); + $this->mReasonSelection = $request->getText( 'wpProtectReasonSelection' ); + $this->mCascade = $request->getBool( 'mwProtect-cascade', $this->mCascade ); foreach ( $this->mApplicableTypes as $action ) { // @todo FIXME: This form currently requires individual selections, @@ -106,8 +111,8 @@ } $this->mExistingExpiry[$action] = $existingExpiry; - $requestExpiry = $wgRequest->getText( "mwProtect-expiry-$action" ); - $requestExpirySelection = $wgRequest->getVal( "wpProtectExpirySelection-$action" ); + $requestExpiry = $request->getText( "mwProtect-expiry-$action" ); + $requestExpirySelection = $request->getVal( "wpProtectExpirySelection-$action" ); if ( $requestExpiry ) { // Custom expiry takes precedence @@ -131,15 +136,15 @@ $this->mExpirySelection[$action] = 'infinite'; } - $val = $wgRequest->getVal( "mwProtect-level-$action" ); + $val = $request->getVal( "mwProtect-level-$action" ); if ( isset( $val ) && in_array( $val, $wgRestrictionLevels ) ) { // Prevent users from setting levels that they cannot later unset if ( $val == 'sysop' ) { // Special case, rewrite sysop to either protect and editprotected - if ( !$wgUser->isAllowedAny( 'protect', 'editprotected' ) ) { + if ( !$context->getUser()->isAllowedAny( 'protect', 'editprotected' ) ) { continue; } - } elseif ( !$wgUser->isAllowed( $val ) ) { + } elseif ( !$context->getUser()->isAllowed( $val ) ) { continue; } $this->mRestrictions[$action] = $val; @@ -182,16 +187,16 @@ * Main entry point for action=protect and action=unprotect */ function execute() { - global $wgRequest, $wgOut; - if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { throw new ErrorPageError( 'protect-badnamespace-title', 'protect-badnamespace-text' ); } - if ( $wgRequest->wasPosted() ) { + $context = RequestContext::getMain(); + + if ( $context->getRequest()->wasPosted() ) { if ( $this->save() ) { $q = $this->mArticle->isRedirect() ? 'redirect=no' : ''; - $wgOut->redirect( $this->mTitle->getFullURL( $q ) ); + $context->getOutput()->redirect( $this->mTitle->getFullURL( $q ) ); } } else { $this->show(); @@ -204,25 +209,25 @@ * @param string $err error message or null if there's no error */ function show( $err = null ) { - global $wgOut; + $out = RequestContext::getMain()->getOutput(); - $wgOut->setRobotPolicy( 'noindex,nofollow' ); - $wgOut->addBacklinkSubtitle( $this->mTitle ); + $out->setRobotPolicy( 'noindex,nofollow' ); + $out->addBacklinkSubtitle( $this->mTitle ); if ( is_array( $err ) ) { - $wgOut->wrapWikiMsg( "<p class='error'>\n$1\n</p>\n", $err ); + $out->wrapWikiMsg( "<p class='error'>\n$1\n</p>\n", $err ); } elseif ( is_string( $err ) ) { - $wgOut->addHTML( "<p class='error'>{$err}</p>\n" ); + $out->addHTML( "<p class='error'>{$err}</p>\n" ); } if ( $this->mTitle->getRestrictionTypes() === array() ) { // No restriction types available for the current title // this might happen if an extension alters the available types - $wgOut->setPageTitle( wfMessage( 'protect-norestrictiontypes-title', $this->mTitle->getPrefixedText() ) ); - $wgOut->addWikiText( wfMessage( 'protect-norestrictiontypes-text' )->text() ); + $out->setPageTitle( wfMessage( 'protect-norestrictiontypes-title', $this->mTitle->getPrefixedText() ) ); + $out->addWikiText( wfMessage( 'protect-norestrictiontypes-text' )->text() ); // Show the log in case protection was possible once - $this->showLogExtract( $wgOut ); + $this->showLogExtract( $out ); // return as there isn't anything else we can do return; } @@ -235,22 +240,22 @@ $titles .= '* [[:' . $title->getPrefixedText() . "]]\n"; } - $wgOut->wrapWikiMsg( "<div id=\"mw-protect-cascadeon\">\n$1\n" . $titles . "</div>", array( 'protect-cascadeon', count( $cascadeSources ) ) ); + $out->wrapWikiMsg( "<div id=\"mw-protect-cascadeon\">\n$1\n" . $titles . "</div>", array( 'protect-cascadeon', count( $cascadeSources ) ) ); } # Show an appropriate message if the user isn't allowed or able to change # the protection settings at this time if ( $this->disabled ) { - $wgOut->setPageTitle( wfMessage( 'protect-title-notallowed', $this->mTitle->getPrefixedText() ) ); - $wgOut->addWikiText( $wgOut->formatPermissionsErrorMessage( $this->mPermErrors, 'protect' ) ); + $out->setPageTitle( wfMessage( 'protect-title-notallowed', $this->mTitle->getPrefixedText() ) ); + $out->addWikiText( $out->formatPermissionsErrorMessage( $this->mPermErrors, 'protect' ) ); } else { - $wgOut->setPageTitle( wfMessage( 'protect-title', $this->mTitle->getPrefixedText() ) ); - $wgOut->addWikiMsg( 'protect-text', + $out->setPageTitle( wfMessage( 'protect-title', $this->mTitle->getPrefixedText() ) ); + $out->addWikiMsg( 'protect-text', wfEscapeWikiText( $this->mTitle->getPrefixedText() ) ); } - $wgOut->addHTML( $this->buildForm() ); - $this->showLogExtract( $wgOut ); + $out->addHTML( $this->buildForm() ); + $this->showLogExtract( $out ); } /** @@ -259,16 +264,18 @@ * @return Boolean: success */ function save() { - global $wgRequest, $wgUser, $wgOut; - # Permission check! if ( $this->disabled ) { $this->show(); return false; } - $token = $wgRequest->getVal( 'wpEditToken' ); - if ( !$wgUser->matchEditToken( $token, array( 'protect', $this->mTitle->getPrefixedDBkey() ) ) ) { + $context = RequestContext::getMain(); + $request = $context->getRequest(); + $token = $request->getVal( 'wpEditToken' ); + $user = $context->getUser(); + + if ( !$user->matchEditToken( $token, array( 'protect', $this->mTitle->getPrefixedDBkey() ) ) ) { $this->show( array( 'sessionfailure' ) ); return false; } @@ -300,16 +307,16 @@ # They shouldn't be able to do this anyway, but just to make sure, ensure that cascading restrictions aren't being applied # to a semi-protected page. $edit_restriction = isset( $this->mRestrictions['edit'] ) ? $this->mRestrictions['edit'] : ''; - $this->mCascade = $wgRequest->getBool( 'mwProtect-cascade' ); + $this->mCascade = $request->getBool( 'mwProtect-cascade' ); if ( $this->mCascade && ( $edit_restriction != 'protect' ) && !User::groupHasPermission( $edit_restriction, 'protect' ) ) { $this->mCascade = false; } - $status = $this->mArticle->doUpdateRestrictions( $this->mRestrictions, $expiry, $this->mCascade, $reasonstr, $wgUser ); + $status = $this->mArticle->doUpdateRestrictions( $this->mRestrictions, $expiry, $this->mCascade, $reasonstr, $user ); if ( !$status->isOK() ) { - $this->show( $wgOut->parseInline( $status->getWikiText() ) ); + $this->show( $context->getOutput()->parseInline( $status->getWikiText() ) ); return false; } @@ -330,11 +337,11 @@ return false; } - if ( $wgUser->isLoggedIn() && $wgRequest->getCheck( 'mwProtectWatch' ) != $wgUser->isWatched( $this->mTitle ) ) { - if ( $wgRequest->getCheck( 'mwProtectWatch' ) ) { - WatchAction::doWatch( $this->mTitle, $wgUser ); + if ( $user->isLoggedIn() && $request->getCheck( 'mwProtectWatch' ) != $user->isWatched( $this->mTitle ) ) { + if ( $request->getCheck( 'mwProtectWatch' ) ) { + WatchAction::doWatch( $this->mTitle, $user ); } else { - WatchAction::doUnwatch( $this->mTitle, $wgUser ); + WatchAction::doUnwatch( $this->mTitle, $user ); } } return true; @@ -346,8 +353,6 @@ * @return String: HTML form */ function buildForm() { - global $wgUser, $wgLang, $wgOut; - $mProtectreasonother = Xml::label( wfMessage( 'protectcomment' )->text(), 'wpProtectReasonSelection' @@ -357,9 +362,12 @@ 'mwProtect-reason' ); + $context = RequestContext::getMain(); $out = ''; + $output = $context->getOutput(); + if ( !$this->disabled ) { - $wgOut->addModules( 'mediawiki.legacy.protect' ); + $output->addModules( 'mediawiki.legacy.protect' ); $out .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->mTitle->getLocalURL( 'action=protect' ), 'id' => 'mw-Protect-Form', 'onsubmit' => 'ProtectionForm.enableUnchainedInputs(true)' ) ); @@ -399,9 +407,10 @@ $expiryFormOptions = ''; if ( $this->mExistingExpiry[$action] && $this->mExistingExpiry[$action] != 'infinity' ) { - $timestamp = $wgLang->timeanddate( $this->mExistingExpiry[$action], true ); - $d = $wgLang->date( $this->mExistingExpiry[$action], true ); - $t = $wgLang->time( $this->mExistingExpiry[$action], true ); + $lang = $context->getLanguage(); + $timestamp = $lang->timeanddate( $this->mExistingExpiry[$action], true ); + $d = $lang->date( $this->mExistingExpiry[$action], true ); + $t = $lang->time( $this->mExistingExpiry[$action], true ); $expiryFormOptions .= Xml::option( wfMessage( 'protect-existing-expiry', $timestamp, $d, $t )->text(), @@ -508,14 +517,16 @@ "</td> </tr>"; # Disallow watching is user is not logged in - if ( $wgUser->isLoggedIn() ) { + $user = $context->getUser(); + + if ( $user->isLoggedIn() ) { $out .= " <tr> <td></td> <td class='mw-input'>" . Xml::checkLabel( wfMessage( 'watchthis' )->text(), 'mwProtectWatch', 'mwProtectWatch', - $wgUser->isWatched( $this->mTitle ) || $wgUser->getOption( 'watchdefault' ) ) . + $user->isWatched( $this->mTitle ) || $user->getOption( 'watchdefault' ) ) . "</td> </tr>"; } @@ -533,7 +544,7 @@ } $out .= Xml::closeElement( 'fieldset' ); - if ( $wgUser->isAllowed( 'editinterface' ) ) { + if ( $user->isAllowed( 'editinterface' ) ) { $title = Title::makeTitle( NS_MEDIAWIKI, 'Protect-dropdown' ); $link = Linker::link( $title, @@ -545,9 +556,9 @@ } if ( !$this->disabled ) { - $out .= Html::hidden( 'wpEditToken', $wgUser->getEditToken( array( 'protect', $this->mTitle->getPrefixedDBkey() ) ) ); + $out .= Html::hidden( 'wpEditToken', $user->getEditToken( array( 'protect', $this->mTitle->getPrefixedDBkey() ) ) ); $out .= Xml::closeElement( 'form' ); - $wgOut->addScript( $this->buildCleanupScript() ); + $output->addScript( $this->buildCleanupScript() ); } return $out; -- To view, visit https://gerrit.wikimedia.org/r/65330 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib53b89e5d68ac5c41a0dd2d77a12035e7e1d74eb Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Siebrand <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
