includes/actions/: Use Config instead of globals
authorKunal Mehta <legoktm@gmail.com>
Wed, 13 Aug 2014 02:45:55 +0000 (19:45 -0700)
committerLegoktm <legoktm.wikipedia@gmail.com>
Wed, 13 Aug 2014 20:34:32 +0000 (20:34 +0000)
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
includes/actions/HistoryAction.php
includes/actions/InfoAction.php
includes/actions/RawAction.php

index dd5195d..e064aab 100644 (file)
@@ -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();
index 4992313..63ba683 100644 (file)
@@ -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(
                        "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" .
                        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( "<div class='mw-history-legend'>\n$1\n</div>", '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";
index c2c1ff5..f932a40 100644 (file)
@@ -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() ) );
index 37e6e66..cd4e4ba 100644 (file)
@@ -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();