Merge "SpecialWhatlinkshere: Use Config instead of globals"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 6 Aug 2014 23:39:02 +0000 (23:39 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 6 Aug 2014 23:39:02 +0000 (23:39 +0000)
includes/api/ApiQueryAllUsers.php
includes/api/ApiUndelete.php
includes/specials/SpecialActiveusers.php
includes/specials/SpecialProtectedtitles.php
includes/specials/SpecialStatistics.php
includes/specials/SpecialTrackingCategories.php
includes/specials/SpecialUndelete.php
includes/specials/SpecialWantedpages.php
maintenance/undelete.php
resources/src/mediawiki/mediawiki.notification.js

index d0980e6..b27f6c2 100644 (file)
@@ -46,10 +46,11 @@ class ApiQueryAllUsers extends ApiQueryBase {
 
        public function execute() {
                $params = $this->extractRequestParams();
+               $activeUserDays = $this->getConfig()->get( 'ActiveUserDays' );
 
                if ( $params['activeusers'] ) {
                        // Update active user cache
-                       SpecialActiveUsers::mergeActiveUsers( 600 );
+                       SpecialActiveUsers::mergeActiveUsers( 600, $activeUserDays );
                }
 
                $db = $this->getDB();
@@ -161,7 +162,7 @@ class ApiQueryAllUsers extends ApiQueryBase {
                }
 
                if ( $params['activeusers'] ) {
-                       $activeUserSeconds = $this->getConfig()->get( 'ActiveUserDays' ) * 86400;
+                       $activeUserSeconds = $activeUserDays * 86400;
 
                        // Filter query to only include users in the active users cache
                        $this->addTables( 'querycachetwo' );
index 7d6a7e4..3492972 100644 (file)
@@ -56,7 +56,7 @@ class ApiUndelete extends ApiBase {
                        $params['timestamps'][$i] = wfTimestamp( TS_MW, $ts );
                }
 
-               $pa = new PageArchive( $titleObj );
+               $pa = new PageArchive( $titleObj, $this->getConfig() );
                $retval = $pa->undelete(
                        ( isset( $params['timestamps'] ) ? $params['timestamps'] : array() ),
                        $params['reason'],
index 6db9e5f..572eacc 100644 (file)
@@ -52,11 +52,9 @@ class ActiveUsersPager extends UsersPager {
         * @param string $par Parameter passed to the page
         */
        function __construct( IContextSource $context = null, $group = null, $par = null ) {
-               global $wgActiveUserDays;
-
                parent::__construct( $context );
 
-               $this->RCMaxAge = $wgActiveUserDays;
+               $this->RCMaxAge = $this->getConfig()->get( 'ActiveUserDays' );
                $un = $this->getRequest()->getText( 'username', $par );
                $this->requestedUser = '';
                if ( $un != '' ) {
@@ -192,13 +190,11 @@ class ActiveUsersPager extends UsersPager {
        }
 
        function getPageHeader() {
-               global $wgScript;
-
                $self = $this->getTitle();
                $limit = $this->mLimit ? Html::hidden( 'limit', $this->mLimit ) : '';
 
                # Form tag
-               $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
+               $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => wfScript() ) );
                $out .= Xml::fieldset( $this->msg( 'activeusers' )->text() ) . "\n";
                $out .= Html::hidden( 'title', $self->getPrefixedDBkey() ) . $limit . "\n";
 
@@ -247,17 +243,17 @@ class SpecialActiveUsers extends SpecialPage {
         * @param string $par Parameter passed to the page or null
         */
        public function execute( $par ) {
-               global $wgActiveUserDays;
+               $days = $this->getConfig()->get( 'ActiveUserDays' );
 
                $this->setHeaders();
                $this->outputHeader();
 
                $out = $this->getOutput();
                $out->wrapWikiMsg( "<div class='mw-activeusers-intro'>\n$1\n</div>",
-                       array( 'activeusers-intro', $this->getLanguage()->formatNum( $wgActiveUserDays ) ) );
+                       array( 'activeusers-intro', $this->getLanguage()->formatNum( $days ) ) );
 
                // Occasionally merge in new updates
-               $seconds = min( self::mergeActiveUsers( 600 ), $wgActiveUserDays * 86400 );
+               $seconds = min( self::mergeActiveUsers( 600, $days ), $days * 86400 );
                // Mention the level of staleness
                $out->addWikiMsg( 'cachedspecial-viewing-cached-ttl',
                        $this->getLanguage()->formatDuration( $seconds ) );
@@ -284,12 +280,11 @@ class SpecialActiveUsers extends SpecialPage {
        }
 
        /**
-        * @param intr $period Seconds (do updates no more often than this)
+        * @param int $period Seconds (do updates no more often than this)
+        * @param int $days How many days user must be idle before he is considered inactive
         * @return int How many seconds old the cache is
         */
-       public static function mergeActiveUsers( $period ) {
-               global $wgActiveUserDays;
-
+       public static function mergeActiveUsers( $period, $days ) {
                $dbr = wfGetDB( DB_SLAVE );
                $cTime = $dbr->selectField( 'querycache_info',
                        'qci_timestamp',
@@ -300,16 +295,16 @@ class SpecialActiveUsers extends SpecialPage {
                        if ( !$cTime || ( time() - wfTimestamp( TS_UNIX, $cTime ) ) > $period ) {
                                $dbw = wfGetDB( DB_MASTER );
                                if ( $dbw->estimateRowCount( 'recentchanges' ) <= 10000 ) {
-                                       $window = $wgActiveUserDays * 86400; // small wiki
+                                       $window = $days * 86400; // small wiki
                                } else {
                                        $window = $period * 2;
                                }
-                               $cTime = self::doQueryCacheUpdate( $dbw, $window ) ?: $cTime;
+                               $cTime = self::doQueryCacheUpdate( $dbw, $days, $window ) ?: $cTime;
                        }
                }
 
                return ( time() -
-                       ( $cTime ? wfTimestamp( TS_UNIX, $cTime ) : $wgActiveUserDays * 86400 ) );
+                       ( $cTime ? wfTimestamp( TS_UNIX, $cTime ) : $days * 86400 ) );
        }
 
        /**
@@ -319,19 +314,18 @@ class SpecialActiveUsers extends SpecialPage {
        public static function cacheUpdate( DatabaseBase $dbw ) {
                global $wgActiveUserDays;
 
-               self::doQueryCacheUpdate( $dbw, $wgActiveUserDays * 86400 );
+               self::doQueryCacheUpdate( $dbw, $wgActiveUserDays, $wgActiveUserDays * 86400 );
        }
 
        /**
         * Update the query cache as needed
         *
         * @param DatabaseBase $dbw
+        * @param int $days How many days user must be idle before he is considered inactive
         * @param int $window Maximum time range of new data to scan (in seconds)
         * @return int|bool UNIX timestamp the cache is now up-to-date as of (false on error)
         */
-       protected static function doQueryCacheUpdate( DatabaseBase $dbw, $window ) {
-               global $wgActiveUserDays;
-
+       protected static function doQueryCacheUpdate( DatabaseBase $dbw, $days, $window ) {
                $lockKey = wfWikiID() . '-activeusers';
                if ( !$dbw->lock( $lockKey, __METHOD__, 1 ) ) {
                        return false; // exclusive update (avoids duplicate entries)
@@ -347,7 +341,7 @@ class SpecialActiveUsers extends SpecialPage {
                // Pick the date range to fetch from. This is normally from the last
                // update to till the present time, but has a limited window for sanity.
                // If the window is limited, multiple runs are need to fully populate it.
-               $sTimestamp = max( $cTimeUnix, $now - $wgActiveUserDays * 86400 );
+               $sTimestamp = max( $cTimeUnix, $now - $days * 86400 );
                $eTimestamp = min( $sTimestamp + $window, $now );
 
                // Get all the users active since the last update
@@ -376,7 +370,7 @@ class SpecialActiveUsers extends SpecialPage {
                $dbw->delete( 'querycachetwo',
                        array(
                                'qcc_type' => 'activeusers',
-                               'qcc_value < ' . $dbw->addQuotes( $now - $wgActiveUserDays * 86400 ) // TS_UNIX
+                               'qcc_value < ' . $dbw->addQuotes( $now - $days * 86400 ) // TS_UNIX
                        ),
                        __METHOD__
                );
index cb6ec3c..b84540c 100644 (file)
@@ -50,7 +50,7 @@ class SpecialProtectedtitles extends SpecialPage {
                $size = $request->getIntOrNull( 'size' );
                $NS = $request->getIntOrNull( 'namespace' );
 
-               $pager = new ProtectedTitlesPager( $this, array(), $type, $level, $NS, $sizetype, $size );
+               $pager = new ProtectedTitlesPager( $this->getContext(), array(), $type, $level, $NS, $sizetype, $size );
 
                $this->getOutput()->addHTML( $this->showOptions( $NS, $type, $level ) );
 
@@ -133,8 +133,7 @@ class SpecialProtectedtitles extends SpecialPage {
         * @private
         */
        function showOptions( $namespace, $type = 'edit', $level ) {
-               global $wgScript;
-               $action = htmlspecialchars( $wgScript );
+               $action = htmlspecialchars( wfScript() );
                $title = $this->getPageTitle();
                $special = htmlspecialchars( $title->getPrefixedDBkey() );
 
@@ -175,14 +174,12 @@ class SpecialProtectedtitles extends SpecialPage {
         * @private
         */
        function getLevelMenu( $pr_level ) {
-               global $wgRestrictionLevels;
-
                // Temporary array
                $m = array( $this->msg( 'restriction-level-all' )->text() => 0 );
                $options = array();
 
                // First pass to load the log names
-               foreach ( $wgRestrictionLevels as $type ) {
+               foreach ( $this->getConfig()->get( 'RestrictionLevels' ) as $type ) {
                        if ( $type != '' && $type != '*' ) {
                                // Messages: restriction-level-sysop, restriction-level-autoconfirmed
                                $text = $this->msg( "restriction-level-$type" )->text();
index 371e5ea..67c96a7 100644 (file)
@@ -36,7 +36,10 @@ class SpecialStatistics extends SpecialPage {
        }
 
        public function execute( $par ) {
-               global $wgMemc, $wgDisableCounters, $wgMiserMode;
+               global $wgMemc;
+
+               $disableCounters = $this->getConfig()->get( 'DisableCounters' );
+               $miserMode = $this->getConfig()->get( 'MiserMode' );
 
                $this->setHeaders();
                $this->getOutput()->addModuleStyles( 'mediawiki.special' );
@@ -52,12 +55,12 @@ class SpecialStatistics extends SpecialPage {
 
                # Staticic - views
                $viewsStats = '';
-               if ( !$wgDisableCounters ) {
+               if ( !$disableCounters ) {
                        $viewsStats = $this->getViewsStats();
                }
 
                # Set active user count
-               if ( !$wgMiserMode ) {
+               if ( !$miserMode ) {
                        $key = wfMemcKey( 'sitestats', 'activeusers-updated' );
                        // Re-calculate the count if the last tally is old...
                        if ( !$wgMemc->get( $key ) ) {
@@ -83,7 +86,7 @@ class SpecialStatistics extends SpecialPage {
                $text .= $viewsStats;
 
                # Statistic - popular pages
-               if ( !$wgDisableCounters && !$wgMiserMode ) {
+               if ( !$disableCounters && !$miserMode ) {
                        $text .= $this->getMostViewedPages();
                }
 
@@ -170,8 +173,6 @@ class SpecialStatistics extends SpecialPage {
        }
 
        private function getUserStats() {
-               global $wgActiveUserDays;
-
                return Xml::openElement( 'tr' ) .
                        Xml::tags( 'th', array( 'colspan' => '2' ), $this->msg( 'statistics-header-users' )->parse() ) .
                        Xml::closeElement( 'tr' ) .
@@ -187,16 +188,15 @@ class SpecialStatistics extends SpecialPage {
                                $this->getLanguage()->formatNum( $this->activeUsers ),
                                array( 'class' => 'mw-statistics-users-active' ),
                                'statistics-users-active-desc',
-                               $this->getLanguage()->formatNum( $wgActiveUserDays )
+                               $this->getLanguage()->formatNum( $this->getConfig()->get( 'ActiveUserDays' ) )
                        );
        }
 
        private function getGroupStats() {
-               global $wgGroupPermissions, $wgImplicitGroups;
                $text = '';
-               foreach ( $wgGroupPermissions as $group => $permissions ) {
+               foreach ( $this->getConfig()->get( 'GroupPermissions' ) as $group => $permissions ) {
                        # Skip generic * and implicit groups
-                       if ( in_array( $group, $wgImplicitGroups ) || $group == '*' ) {
+                       if ( in_array( $group, $this->getConfig()->get( 'ImplicitGroups' ) ) || $group == '*' ) {
                                continue;
                        }
                        $groupname = htmlspecialchars( $group );
index 73bdbd6..5e5588c 100644 (file)
@@ -37,9 +37,6 @@ class SpecialTrackingCategories extends SpecialPage {
        }
 
        function execute( $par ) {
-               // Global array containing names of tracking categories
-               global $wgTrackingCategories;
-
                $this->setHeaders();
                $this->outputHeader();
                $this->getOutput()->allowClickjacking();
@@ -59,7 +56,7 @@ class SpecialTrackingCategories extends SpecialPage {
                        </tr></thead>"
                );
 
-               foreach ( $wgTrackingCategories as $catMsg ) {
+               foreach ( $this->getConfig()->get( 'TrackingCategories' ) as $catMsg ) {
                        /*
                         * Check if the tracking category varies by namespace
                         * Otherwise only pages in the current namespace will be displayed
index 25f520e..8acf8a2 100644 (file)
@@ -36,11 +36,19 @@ class PageArchive {
        /** @var Status */
        protected $revisionStatus;
 
-       function __construct( $title ) {
+       /** @var Config */
+       protected $config;
+
+       function __construct( $title, Config $config = null ) {
                if ( is_null( $title ) ) {
                        throw new MWException( __METHOD__ . ' given a null title.' );
                }
                $this->title = $title;
+               if ( $config === null ) {
+                       wfDebug( __METHOD__ . ' did not have a Config object passed to it' );
+                       $config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' );
+               }
+               $this->config = $config;
        }
 
        /**
@@ -115,8 +123,6 @@ class PageArchive {
         * @return ResultWrapper
         */
        function listRevisions() {
-               global $wgContentHandlerUseDB;
-
                $dbr = wfGetDB( DB_SLAVE );
 
                $tables = array( 'archive' );
@@ -126,7 +132,7 @@ class PageArchive {
                        'ar_comment', 'ar_len', 'ar_deleted', 'ar_rev_id', 'ar_sha1',
                );
 
-               if ( $wgContentHandlerUseDB ) {
+               if ( $this->config->get( 'ContentHandlerUseDB' ) ) {
                        $fields[] = 'ar_content_format';
                        $fields[] = 'ar_content_model';
                }
@@ -190,8 +196,6 @@ class PageArchive {
         * @return Revision|null
         */
        function getRevision( $timestamp ) {
-               global $wgContentHandlerUseDB;
-
                $dbr = wfGetDB( DB_SLAVE );
 
                $fields = array(
@@ -209,7 +213,7 @@ class PageArchive {
                        'ar_sha1',
                );
 
-               if ( $wgContentHandlerUseDB ) {
+               if ( $this->config->get( 'ContentHandlerUseDB' ) ) {
                        $fields[] = 'ar_content_format';
                        $fields[] = 'ar_content_model';
                }
@@ -442,8 +446,6 @@ class PageArchive {
         * @return Status Status object containing the number of revisions restored on success
         */
        private function undeleteRevisions( $timestamps, $unsuppress = false, $comment = '' ) {
-               global $wgContentHandlerUseDB;
-
                if ( wfReadOnly() ) {
                        throw new ReadOnlyError();
                }
@@ -516,7 +518,7 @@ class PageArchive {
                        'ar_sha1'
                );
 
-               if ( $wgContentHandlerUseDB ) {
+               if ( $this->config->get( 'ContentHandlerUseDB' ) ) {
                        $fields[] = 'ar_content_format';
                        $fields[] = 'ar_content_model';
                }
@@ -806,12 +808,10 @@ class SpecialUndelete extends SpecialPage {
        }
 
        function showSearchForm() {
-               global $wgScript;
-
                $out = $this->getOutput();
                $out->setPageTitle( $this->msg( 'undelete-search-title' ) );
                $out->addHTML(
-                       Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
+                       Xml::openElement( 'form', array( 'method' => 'get', 'action' => wfScript() ) ) .
                                Xml::fieldset( $this->msg( 'undelete-search-box' )->text() ) .
                                Html::hidden( 'title', $this->getPageTitle()->getPrefixedDBkey() ) .
                                Html::rawElement(
@@ -891,7 +891,7 @@ class SpecialUndelete extends SpecialPage {
                        return;
                }
 
-               $archive = new PageArchive( $this->mTargetObj );
+               $archive = new PageArchive( $this->mTargetObj, $this->getConfig() );
                if ( !wfRunHooks( 'UndeleteForm::showRevision', array( &$archive, $this->mTargetObj ) ) ) {
                        return;
                }
@@ -1198,7 +1198,7 @@ class SpecialUndelete extends SpecialPage {
                        array( 'undeletepagetitle', wfEscapeWikiText( $this->mTargetObj->getPrefixedText() ) )
                );
 
-               $archive = new PageArchive( $this->mTargetObj );
+               $archive = new PageArchive( $this->mTargetObj, $this->getConfig() );
                wfRunHooks( 'UndeleteForm::showHistory', array( &$archive, $this->mTargetObj ) );
                /*
                $text = $archive->getLastRevisionText();
@@ -1610,9 +1610,7 @@ class SpecialUndelete extends SpecialPage {
        }
 
        function undelete() {
-               global $wgUploadMaintenance;
-
-               if ( $wgUploadMaintenance && $this->mTargetObj->getNamespace() == NS_FILE ) {
+               if ( $this->getConfig()->get( 'UploadMaintenance' ) && $this->mTargetObj->getNamespace() == NS_FILE ) {
                        throw new ErrorPageError( 'undelete-error', 'filedelete-maintenance' );
                }
 
@@ -1621,7 +1619,7 @@ class SpecialUndelete extends SpecialPage {
                }
 
                $out = $this->getOutput();
-               $archive = new PageArchive( $this->mTargetObj );
+               $archive = new PageArchive( $this->mTargetObj, $this->getConfig() );
                wfRunHooks( 'UndeleteForm::undelete', array( &$archive, $this->mTargetObj ) );
                $ok = $archive->undelete(
                        $this->mTargetTimestamp,
index c54d9f4..38f1808 100644 (file)
@@ -54,8 +54,7 @@ class WantedPagesPage extends WantedQueryPage {
        }
 
        function getQueryInfo() {
-               global $wgWantedPagesThreshold;
-               $count = $wgWantedPagesThreshold - 1;
+               $count = $this->getConfig()->get( 'WantedPagesThreshold' ) - 1;
                $query = array(
                        'tables' => array(
                                'pagelinks',
index c890c69..adebd27 100644 (file)
@@ -47,7 +47,7 @@ class Undelete extends Maintenance {
                if ( !$wgUser ) {
                        $this->error( "Invalid username", true );
                }
-               $archive = new PageArchive( $title );
+               $archive = new PageArchive( $title, RequestContext::getMain()->getConfig() );
                $this->output( "Undeleting " . $title->getPrefixedDBkey() . '...' );
                $archive->undelete( array(), $reason );
                $this->output( "done\n" );
index b5fd69c..79ec310 100644 (file)
                /**
                 * Display a notification message to the user.
                 *
-                * @param {HTMLElement|jQuery|mw.Message|string} message
+                * @param {HTMLElement|HTMLElement[]|jQuery|mw.Message|string} message
                 * @param {Object} options The options to use for the notification.
                 *  See #defaults for details.
                 * @return {mw.Notification} Notification object