From f6b5b8c89908164ababd729820bfe0155467081f Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Tue, 12 Aug 2014 19:45:55 -0700 Subject: [PATCH] includes/actions/: Use Config instead of globals Changed InfoAction::pageCounts to be non-static, so it's able to access $this to get the Config object. Also replaced instances of $wgScript with wfScript(). Change-Id: I4a6a3224e762f13640af04a73e2934b887dffedd --- includes/actions/CreditsAction.php | 21 ++++++++++----- includes/actions/HistoryAction.php | 19 ++++++------- includes/actions/InfoAction.php | 43 +++++++++++++++--------------- includes/actions/RawAction.php | 9 +++---- 4 files changed, 49 insertions(+), 43 deletions(-) diff --git a/includes/actions/CreditsAction.php b/includes/actions/CreditsAction.php index dd5195dd86..e064aab4e6 100644 --- a/includes/actions/CreditsAction.php +++ b/includes/actions/CreditsAction.php @@ -100,6 +100,17 @@ class CreditsAction extends FormlessAction { $this->userLink( $user ) )->params( $user->getName() )->escaped(); } + /** + * Whether we can display the user's real name (not a hidden pref) + * + * @since 1.24 + * @return bool + */ + protected function canShowRealUserName() { + $hiddenPrefs = $this->context->getConfig()->get( 'HiddenPrefs' ); + return !in_array( 'realname', $hiddenPrefs ); + } + /** * Get a list of contributors of $article * @param int $cnt Maximum list of contributors to show @@ -107,8 +118,6 @@ class CreditsAction extends FormlessAction { * @return string Html */ protected function getContributors( $cnt, $showIfMax ) { - global $wgHiddenPrefs; - $contributors = $this->page->getContributors(); $others_link = false; @@ -132,7 +141,7 @@ class CreditsAction extends FormlessAction { $cnt--; if ( $user->isLoggedIn() ) { $link = $this->link( $user ); - if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) { + if ( $this->canShowRealUserName() && $user->getRealName() ) { $real_names[] = $link; } else { $user_names[] = $link; @@ -192,8 +201,7 @@ class CreditsAction extends FormlessAction { * @return string Html */ protected function link( User $user ) { - global $wgHiddenPrefs; - if ( !in_array( 'realname', $wgHiddenPrefs ) && !$user->isAnon() ) { + if ( $this->canShowRealUserName() && !$user->isAnon() ) { $real = $user->getRealName(); } else { $real = false; @@ -216,8 +224,7 @@ class CreditsAction extends FormlessAction { if ( $user->isAnon() ) { return $this->msg( 'anonuser' )->rawParams( $link )->parse(); } else { - global $wgHiddenPrefs; - if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) { + if ( $this->canShowRealUserName() && $user->getRealName() ) { return $link; } else { return $this->msg( 'siteuser' )->rawParams( $link )->params( $user->getName() )->escaped(); diff --git a/includes/actions/HistoryAction.php b/includes/actions/HistoryAction.php index 4992313a70..63ba683938 100644 --- a/includes/actions/HistoryAction.php +++ b/includes/actions/HistoryAction.php @@ -92,8 +92,6 @@ class HistoryAction extends FormlessAction { * Print the history page for an article. */ function onView() { - global $wgScript, $wgUseFileCache; - $out = $this->getOutput(); $request = $this->getRequest(); @@ -109,7 +107,8 @@ class HistoryAction extends FormlessAction { $this->preCacheMessages(); # Fill in the file cache if not set already - if ( $wgUseFileCache && HTMLFileCache::useFileCache( $this->getContext() ) ) { + $useFileCache = $this->context->getConfig()->get( 'UseFileCache' ); + if ( $useFileCache && HTMLFileCache::useFileCache( $this->getContext() ) ) { $cache = HTMLFileCache::newFromTitle( $this->getTitle(), 'history' ); if ( !$cache->isCacheGood( /* Assume up to date */ ) ) { ob_start( array( &$cache, 'saveToFileCache' ) ); @@ -173,7 +172,7 @@ class HistoryAction extends FormlessAction { } // Add the general form - $action = htmlspecialchars( $wgScript ); + $action = htmlspecialchars( wfScript() ); $out->addHTML( "
" . Xml::fieldset( @@ -254,14 +253,14 @@ class HistoryAction extends FormlessAction { * @param string $type Feed type */ function feed( $type ) { - global $wgFeedClasses, $wgFeedLimit; if ( !FeedUtils::checkFeedOutput( $type ) ) { return; } $request = $this->getRequest(); + $feedClasses = $this->context->getConfig()->get( 'FeedClasses' ); /** @var RSSFeed|AtomFeed $feed */ - $feed = new $wgFeedClasses[$type]( + $feed = new $feedClasses[$type]( $this->getTitle()->getPrefixedText() . ' - ' . $this->msg( 'history-feed-title' )->inContentLanguage()->text(), $this->msg( 'history-feed-description' )->inContentLanguage()->text(), @@ -271,7 +270,10 @@ class HistoryAction extends FormlessAction { // Get a limit on number of feed entries. Provide a sane default // of 10 if none is defined (but limit to $wgFeedLimit max) $limit = $request->getInt( 'limit', 10 ); - $limit = min( max( $limit, 1 ), $wgFeedLimit ); + $limit = min( + max( $limit, 1 ), + $this->context->getConfig()->get( 'FeedLimit' ) + ); $items = $this->fetchRevisions( $limit, 0, self::DIR_NEXT ); @@ -462,13 +464,12 @@ class HistoryPager extends ReverseChronologicalPager { * @return string HTML output */ function getStartBody() { - global $wgScript; $this->lastRow = false; $this->counter = 1; $this->oldIdChecked = 0; $this->getOutput()->wrapWikiMsg( "
\n$1\n
", 'histlegend' ); - $s = Html::openElement( 'form', array( 'action' => $wgScript, + $s = Html::openElement( 'form', array( 'action' => wfScript(), 'id' => 'mw-history-compare' ) ) . "\n"; $s .= Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n"; $s .= Html::hidden( 'action', 'historysubmit' ) . "\n"; diff --git a/includes/actions/InfoAction.php b/includes/actions/InfoAction.php index c2c1ff5cd4..f932a40543 100644 --- a/includes/actions/InfoAction.php +++ b/includes/actions/InfoAction.php @@ -193,13 +193,13 @@ class InfoAction extends FormlessAction { * @return array */ protected function pageInfo() { - global $wgContLang, $wgRCMaxAge, $wgMemc, $wgMiserMode, - $wgUnwatchedPageThreshold, $wgPageInfoTransclusionLimit, $wgPageLanguageUseDB; + global $wgContLang, $wgMemc; $user = $this->getUser(); $lang = $this->getLanguage(); $title = $this->getTitle(); $id = $title->getArticleID(); + $config = $this->context->getConfig(); $memcKey = wfMemcKey( 'infoaction', sha1( $title->getPrefixedText() ), $this->page->getLatest() ); @@ -207,7 +207,7 @@ class InfoAction extends FormlessAction { $version = isset( $pageCounts['cacheversion'] ) ? $pageCounts['cacheversion'] : false; if ( $pageCounts === false || $version !== self::CACHE_VERSION ) { // Get page information that would be too "expensive" to retrieve by normal means - $pageCounts = self::pageCounts( $title ); + $pageCounts = $this->pageCounts( $title ); $pageCounts['cacheversion'] = self::CACHE_VERSION; $wgMemc->set( $memcKey, $pageCounts ); @@ -276,7 +276,7 @@ class InfoAction extends FormlessAction { // Language in which the page content is (supposed to be) written $pageLang = $title->getPageLanguage()->getCode(); - if ( $wgPageLanguageUseDB && $this->getTitle()->userCan( 'pagelang' ) ) { + if ( $config->get( 'PageLanguageUseDB' ) && $this->getTitle()->userCan( 'pagelang' ) ) { // Link to Special:PageLanguage with pre-filled page title if user has permissions $titleObj = SpecialPage::getTitleFor( 'PageLanguage', $title->getPrefixedText() ); $langDisp = Linker::link( @@ -321,19 +321,20 @@ class InfoAction extends FormlessAction { ); } + $unwatchedPageThreshold = $config->get( 'UnwatchedPageThreshold' ); if ( $user->isAllowed( 'unwatchedpages' ) || - ( $wgUnwatchedPageThreshold !== false && - $pageCounts['watchers'] >= $wgUnwatchedPageThreshold ) + ( $unwatchedPageThreshold !== false && + $pageCounts['watchers'] >= $unwatchedPageThreshold ) ) { // Number of page watchers $pageInfo['header-basic'][] = array( $this->msg( 'pageinfo-watchers' ), $lang->formatNum( $pageCounts['watchers'] ) ); - } elseif ( $wgUnwatchedPageThreshold !== false ) { + } elseif ( $unwatchedPageThreshold !== false ) { $pageInfo['header-basic'][] = array( $this->msg( 'pageinfo-watchers' ), - $this->msg( 'pageinfo-few-watchers' )->numParams( $wgUnwatchedPageThreshold ) + $this->msg( 'pageinfo-few-watchers' )->numParams( $unwatchedPageThreshold ) ); } @@ -521,7 +522,7 @@ class InfoAction extends FormlessAction { // Recent number of edits (within past 30 days) $pageInfo['header-edits'][] = array( - $this->msg( 'pageinfo-recent-edits', $lang->formatDuration( $wgRCMaxAge ) ), + $this->msg( 'pageinfo-recent-edits', $lang->formatDuration( $config->get( 'RCMaxAge' ) ) ), $lang->formatNum( $pageCounts['recent_edits'] ) ); @@ -555,9 +556,9 @@ class InfoAction extends FormlessAction { $pageCounts['transclusion']['from'] > 0 || $pageCounts['transclusion']['to'] > 0 ) { - $options = array( 'LIMIT' => $wgPageInfoTransclusionLimit ); + $options = array( 'LIMIT' => $config->get( 'PageInfoTransclusionLimit' ) ); $transcludedTemplates = $title->getTemplateLinksFrom( $options ); - if ( $wgMiserMode ) { + if ( $config->get( 'MiserMode' ) ) { $transcludedTargets = array(); } else { $transcludedTargets = $title->getTemplateLinksTo( $options ); @@ -602,7 +603,7 @@ class InfoAction extends FormlessAction { ); } - if ( !$wgMiserMode && $pageCounts['transclusion']['to'] > 0 ) { + if ( !$config->get( 'MiserMode' ) && $pageCounts['transclusion']['to'] > 0 ) { if ( $pageCounts['transclusion']['to'] > count( $transcludedTargets ) ) { $more = Linker::link( $whatLinksHere, @@ -635,16 +636,15 @@ class InfoAction extends FormlessAction { * @param Title $title Title to get counts for * @return array */ - protected static function pageCounts( Title $title ) { - global $wgRCMaxAge, $wgDisableCounters, $wgMiserMode; - + protected function pageCounts( Title $title ) { wfProfileIn( __METHOD__ ); $id = $title->getArticleID(); + $config = $this->context->getConfig(); $dbr = wfGetDB( DB_SLAVE ); $result = array(); - if ( !$wgDisableCounters ) { + if ( !$config->get( 'DisableCounters' ) ) { // Number of views $views = (int)$dbr->selectField( 'page', @@ -685,8 +685,8 @@ class InfoAction extends FormlessAction { ); $result['authors'] = $authors; - // "Recent" threshold defined by $wgRCMaxAge - $threshold = $dbr->timestamp( time() - $wgRCMaxAge ); + // "Recent" threshold defined by RCMaxAge setting + $threshold = $dbr->timestamp( time() - $config->get( 'RCMaxAge' ) ); // Recent number of edits $edits = (int)$dbr->selectField( @@ -740,7 +740,7 @@ class InfoAction extends FormlessAction { } // Counts for the number of transclusion links (to/from) - if ( $wgMiserMode ) { + if ( $config->get( 'MiserMode' ) ) { $result['transclusion']['to'] = 0; } else { $result['transclusion']['to'] = (int)$dbr->selectField( @@ -780,8 +780,6 @@ class InfoAction extends FormlessAction { * @return string Html */ protected function getContributors() { - global $wgHiddenPrefs; - $contributors = $this->page->getContributors(); $real_names = array(); $user_names = array(); @@ -794,9 +792,10 @@ class InfoAction extends FormlessAction { ? SpecialPage::getTitleFor( 'Contributions', $user->getName() ) : $user->getUserPage(); + $hiddenPrefs = $this->context->getConfig()->get( 'HiddenPrefs' ); if ( $user->getID() == 0 ) { $anon_ips[] = Linker::link( $page, htmlspecialchars( $user->getName() ) ); - } elseif ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) { + } elseif ( !in_array( 'realname', $hiddenPrefs ) && $user->getRealName() ) { $real_names[] = Linker::link( $page, htmlspecialchars( $user->getRealName() ) ); } else { $user_names[] = Linker::link( $page, htmlspecialchars( $user->getName() ) ); diff --git a/includes/actions/RawAction.php b/includes/actions/RawAction.php index 37e6e667e8..cd4e4ba107 100644 --- a/includes/actions/RawAction.php +++ b/includes/actions/RawAction.php @@ -48,10 +48,9 @@ class RawAction extends FormlessAction { } function onView() { - global $wgSquidMaxage, $wgForcedRawSMaxage; - $this->getOutput()->disable(); $request = $this->getRequest(); + $config = $this->context->getConfig(); if ( !$request->checkUrlExtension() ) { return; @@ -69,7 +68,7 @@ class RawAction extends FormlessAction { if ( $gen == 'css' || $gen == 'js' ) { $this->mGen = $gen; if ( $smaxage === null ) { - $smaxage = $wgSquidMaxage; + $smaxage = $config->get( 'SquidMaxage' ); } } else { $this->mGen = false; @@ -81,13 +80,13 @@ class RawAction extends FormlessAction { # Note: If using a canonical url for userpage css/js, we send an HTCP purge. if ( $smaxage === null ) { if ( $contentType == 'text/css' || $contentType == 'text/javascript' ) { - $smaxage = intval( $wgForcedRawSMaxage ); + $smaxage = intval( $config->get( 'ForcedRawSMaxage' ) ); } else { $smaxage = 0; } } - $maxage = $request->getInt( 'maxage', $wgSquidMaxage ); + $maxage = $request->getInt( 'maxage', $config->get( 'SquidMaxage' ) ); $response = $request->response(); -- 2.20.1