Merge "SpecialResetTokens: Use Config instead of globals"
authorAddshore <addshorewiki@gmail.com>
Mon, 4 Aug 2014 10:16:46 +0000 (10:16 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 4 Aug 2014 10:16:46 +0000 (10:16 +0000)
includes/User.php
includes/parser/CoreParserFunctions.php
includes/specials/SpecialJavaScriptTest.php
includes/specials/SpecialMovepage.php
includes/specials/SpecialNewpages.php
includes/specials/SpecialPasswordReset.php
includes/specials/SpecialProtectedpages.php
tests/phpunit/phpunit.php

index a21119a..7edd93e 100644 (file)
@@ -181,8 +181,16 @@ class User implements IDBAccessObject {
 
        public $mRealName;
 
+       /**
+        * @todo Make this actually private
+        * @private
+        */
        public $mPassword;
 
+       /**
+        * @todo Make this actually private
+        * @private
+        */
        public $mNewpassword;
 
        public $mNewpassTime;
@@ -2247,6 +2255,26 @@ class User implements IDBAccessObject {
                return $this->mTouched;
        }
 
+       /**
+        * @return Password
+        * @since 1.24
+        */
+       public function getPassword() {
+               $this->loadPasswords();
+
+               return $this->mPassword;
+       }
+
+       /**
+        * @return Password
+        * @since 1.24
+        */
+       public function getTemporaryPassword() {
+               $this->loadPasswords();
+
+               return $this->mNewpassword;
+       }
+
        /**
         * Set the password and reset the random token.
         * Calls through to authentication plugin if necessary;
index faff0e7..84e7fe2 100644 (file)
@@ -33,7 +33,7 @@ class CoreParserFunctions {
        static function register( $parser ) {
                global $wgAllowDisplayTitle, $wgAllowSlowParserFunctions;
 
-               # Syntax for arguments (see self::setFunctionHook):
+               # Syntax for arguments (see Parser::setFunctionHook):
                #  "name for lookup in localized magic words array",
                #  function callback,
                #  optional SFH_NO_HASH to omit the hash from calls (e.g. {{int:...}}
index a67d3c0..0efebb3 100644 (file)
@@ -134,16 +134,15 @@ class SpecialJavaScriptTest extends SpecialPage {
         * Initialize the page for QUnit.
         */
        private function initQUnitTesting() {
-               global $wgJavaScriptTestConfig;
-
                $out = $this->getOutput();
+               $testConfig = $this->getConfig()->get( 'JavaScriptTestConfig' );
 
                $out->addModules( 'test.mediawiki.qunit.testrunner' );
                $qunitTestModules = $out->getResourceLoader()->getTestModuleNames( 'qunit' );
                $out->addModules( $qunitTestModules );
 
                $summary = $this->msg( 'javascripttest-qunit-intro' )
-                       ->params( $wgJavaScriptTestConfig['qunit']['documentation'] )
+                       ->params( $testConfig['qunit']['documentation'] )
                        ->parseAsBlock();
                $header = $this->msg( 'javascripttest-qunit-heading' )->escaped();
                $userDir = $this->getLanguage()->getDir();
@@ -169,7 +168,7 @@ HTML;
                // $wgJavaScriptTestConfig in DefaultSettings.php
                $out->addJsConfigVars(
                        'QUnitTestSwarmInjectJSPath',
-                       $wgJavaScriptTestConfig['qunit']['testswarm-injectjs']
+                       $testConfig['qunit']['testswarm-injectjs']
                );
        }
 
index ee144d6..ec9593f 100644 (file)
@@ -131,7 +131,7 @@ class MovePageForm extends UnlistedSpecialPage {
         *    parameters, like the second argument to OutputPage::wrapWikiMsg().
         */
        function showForm( $err ) {
-               global $wgContLang, $wgFixDoubleRedirects, $wgMaximumMovedPages;
+               global $wgContLang;
 
                $this->getSkin()->setRelevantTitle( $this->oldTitle );
 
@@ -190,7 +190,7 @@ class MovePageForm extends UnlistedSpecialPage {
                                );
                        }
 
-                       $out->addWikiMsg( $wgFixDoubleRedirects ?
+                       $out->addWikiMsg( $this->getConfig()->get( 'FixDoubleRedirects' ) ?
                                'movepagetext' :
                                'movepagetext-noredirectfixer'
                        );
@@ -221,7 +221,7 @@ class MovePageForm extends UnlistedSpecialPage {
                                || ( $oldTitleTalkSubpages && $canMoveSubpage ) );
 
                $dbr = wfGetDB( DB_SLAVE );
-               if ( $wgFixDoubleRedirects ) {
+               if ( $this->getConfig()->get( 'FixDoubleRedirects' ) ) {
                        $hasRedirects = $dbr->selectField( 'redirect', '1',
                                array(
                                        'rd_namespace' => $this->oldTitle->getNamespace(),
@@ -419,6 +419,7 @@ class MovePageForm extends UnlistedSpecialPage {
                }
 
                if ( $canMoveSubpage ) {
+                       $maximumMovedPages = $this->getConfig()->get( 'MaximumMovedPages' );
                        $out->addHTML( "
                                <tr>
                                        <td></td>
@@ -435,7 +436,7 @@ class MovePageForm extends UnlistedSpecialPage {
                                                        ( $this->oldTitle->hasSubpages()
                                                                ? 'move-subpages'
                                                                : 'move-talk-subpages' )
-                                               )->numParams( $wgMaximumMovedPages )->params( $wgMaximumMovedPages )->parse()
+                                               )->numParams( $maximumMovedPages )->params( $maximumMovedPages )->parse()
                                        ) .
                                        "</td>
                                </tr>"
@@ -480,8 +481,6 @@ class MovePageForm extends UnlistedSpecialPage {
        }
 
        function doSubmit() {
-               global $wgMaximumMovedPages, $wgFixDoubleRedirects;
-
                $user = $this->getUser();
 
                if ( $user->pingLimiter( 'move' ) ) {
@@ -557,7 +556,7 @@ class MovePageForm extends UnlistedSpecialPage {
                        return;
                }
 
-               if ( $wgFixDoubleRedirects && $this->fixRedirects ) {
+               if ( $this->getConfig()->get( 'FixDoubleRedirects' ) && $this->fixRedirects ) {
                        DoubleRedirectJob::fixRedirects( 'move', $ot, $nt );
                }
 
@@ -713,9 +712,10 @@ class MovePageForm extends UnlistedSpecialPage {
                                                ->rawParams( $oldLink, $newLink )->escaped();
                                        ++$count;
 
-                                       if ( $count >= $wgMaximumMovedPages ) {
+                                       $maximumMovedPages = $this->getConfig()->get( 'MaximumMovedPages' );
+                                       if ( $count >= $maximumMovedPages ) {
                                                $extraOutput[] = $this->msg( 'movepage-max-pages' )
-                                                       ->numParams( $wgMaximumMovedPages )->escaped();
+                                                       ->numParams( $maximumMovedPages )->escaped();
                                                break;
                                        }
                                } else {
index 1ec7006..fbb2d73 100644 (file)
@@ -199,8 +199,6 @@ class SpecialNewpages extends IncludableSpecialPage {
        }
 
        protected function form() {
-               global $wgScript;
-
                // Consume values
                $this->opts->consumeValue( 'offset' ); // don't carry offset, DWIW
                $namespace = $this->opts->consumeValue( 'namespace' );
@@ -224,7 +222,7 @@ class SpecialNewpages extends IncludableSpecialPage {
                        list( $tagFilterLabel, $tagFilterSelector ) = $tagFilter;
                }
 
-               $form = Xml::openElement( 'form', array( 'action' => $wgScript ) ) .
+               $form = Xml::openElement( 'form', array( 'action' => wfScript() ) ) .
                        Html::hidden( 'title', $this->getPageTitle()->getPrefixedDBkey() ) .
                        Xml::fieldset( $this->msg( 'newpages' )->text() ) .
                        Xml::openElement( 'table', array( 'id' => 'mw-newpages-table' ) ) .
@@ -405,21 +403,20 @@ class SpecialNewpages extends IncludableSpecialPage {
         * @param string $type
         */
        protected function feed( $type ) {
-               global $wgFeed, $wgFeedClasses, $wgFeedLimit;
-
-               if ( !$wgFeed ) {
+               if ( !$this->getConfig()->get( 'Feed' ) ) {
                        $this->getOutput()->addWikiMsg( 'feed-unavailable' );
 
                        return;
                }
 
-               if ( !isset( $wgFeedClasses[$type] ) ) {
+               $feedClasses = $this->getConfig()->get( 'FeedClasses' );
+               if ( !isset( $feedClasses[$type] ) ) {
                        $this->getOutput()->addWikiMsg( 'feed-invalid' );
 
                        return;
                }
 
-               $feed = new $wgFeedClasses[$type](
+               $feed = new $feedClasses[$type](
                        $this->feedTitle(),
                        $this->msg( 'tagline' )->text(),
                        $this->getPageTitle()->getFullURL()
@@ -427,7 +424,7 @@ class SpecialNewpages extends IncludableSpecialPage {
 
                $pager = new NewPagesPager( $this, $this->opts );
                $limit = $this->opts->getValue( 'limit' );
-               $pager->mLimit = min( $limit, $wgFeedLimit );
+               $pager->mLimit = min( $limit, $this->getConfig()->get( 'FeedLimit' ) );
 
                $feed->outHeader();
                if ( $pager->getNumRows() > 0 ) {
@@ -439,10 +436,11 @@ class SpecialNewpages extends IncludableSpecialPage {
        }
 
        protected function feedTitle() {
-               global $wgLanguageCode, $wgSitename;
                $desc = $this->getDescription();
+               $code = $this->getConfig()->get( 'LanguageCode' );
+               $sitename = $this->getConfig()->get( 'Sitename' );
 
-               return "$wgSitename - $desc [$wgLanguageCode]";
+               return "$sitename - $desc [$code]";
        }
 
        protected function feedItem( $row ) {
index c60b347..3061c85 100644 (file)
@@ -62,9 +62,10 @@ class SpecialPasswordReset extends FormSpecialPage {
        }
 
        protected function getFormFields() {
-               global $wgPasswordResetRoutes, $wgAuth;
+               global $wgAuth;
+               $resetRoutes = $this->getConfig()->get( 'PasswordResetRoutes' );
                $a = array();
-               if ( isset( $wgPasswordResetRoutes['username'] ) && $wgPasswordResetRoutes['username'] ) {
+               if ( isset( $resetRoutes['username'] ) && $resetRoutes['username'] ) {
                        $a['Username'] = array(
                                'type' => 'text',
                                'label-message' => 'passwordreset-username',
@@ -75,14 +76,14 @@ class SpecialPasswordReset extends FormSpecialPage {
                        }
                }
 
-               if ( isset( $wgPasswordResetRoutes['email'] ) && $wgPasswordResetRoutes['email'] ) {
+               if ( isset( $resetRoutes['email'] ) && $resetRoutes['email'] ) {
                        $a['Email'] = array(
                                'type' => 'email',
                                'label-message' => 'passwordreset-email',
                        );
                }
 
-               if ( isset( $wgPasswordResetRoutes['domain'] ) && $wgPasswordResetRoutes['domain'] ) {
+               if ( isset( $resetRoutes['domain'] ) && $resetRoutes['domain'] ) {
                        $domains = $wgAuth->domainList();
                        $a['Domain'] = array(
                                'type' => 'select',
@@ -103,7 +104,7 @@ class SpecialPasswordReset extends FormSpecialPage {
        }
 
        public function alterForm( HTMLForm $form ) {
-               global $wgPasswordResetRoutes;
+               $resetRoutes = $this->getConfig()->get( 'PasswordResetRoutes' );
 
                $form->setDisplayFormat( 'vform' );
                // Turn the old-school line around the form off.
@@ -115,13 +116,13 @@ class SpecialPasswordReset extends FormSpecialPage {
                $form->addHiddenFields( $this->getRequest()->getValues( 'returnto', 'returntoquery' ) );
 
                $i = 0;
-               if ( isset( $wgPasswordResetRoutes['username'] ) && $wgPasswordResetRoutes['username'] ) {
+               if ( isset( $resetRoutes['username'] ) && $resetRoutes['username'] ) {
                        $i++;
                }
-               if ( isset( $wgPasswordResetRoutes['email'] ) && $wgPasswordResetRoutes['email'] ) {
+               if ( isset( $resetRoutes['email'] ) && $resetRoutes['email'] ) {
                        $i++;
                }
-               if ( isset( $wgPasswordResetRoutes['domain'] ) && $wgPasswordResetRoutes['domain'] ) {
+               if ( isset( $resetRoutes['domain'] ) && $resetRoutes['domain'] ) {
                        $i++;
                }
 
@@ -222,19 +223,16 @@ class SpecialPasswordReset extends FormSpecialPage {
                // Check against password throttle
                foreach ( $users as $user ) {
                        if ( $user->isPasswordReminderThrottled() ) {
-                               global $wgPasswordReminderResendTime;
 
                                # Round the time in hours to 3 d.p., in case someone is specifying
                                # minutes or seconds.
                                return array( array(
                                        'throttled-mailpassword',
-                                       round( $wgPasswordReminderResendTime, 3 )
+                                       round( $this->getConfig()->get( 'PasswordReminderResendTime' ), 3 )
                                ) );
                        }
                }
 
-               global $wgNewPasswordExpiry;
-
                // All the users will have the same email address
                if ( $firstUser->getEmail() == '' ) {
                        // This won't be reachable from the email route, so safe to expose the username
@@ -273,7 +271,7 @@ class SpecialPasswordReset extends FormSpecialPage {
                        $passwordBlock,
                        count( $passwords ),
                        '<' . Title::newMainPage()->getCanonicalURL() . '>',
-                       round( $wgNewPasswordExpiry / 86400 )
+                       round( $this->getConfig()->get( 'NewPasswordExpiry' ) / 86400 )
                );
 
                $title = $this->msg( 'passwordreset-emailtitle' );
@@ -320,11 +318,12 @@ class SpecialPasswordReset extends FormSpecialPage {
        }
 
        protected function canChangePassword( User $user ) {
-               global $wgPasswordResetRoutes, $wgEnableEmail, $wgAuth;
+               global $wgAuth;
+               $resetRoutes = $this->getConfig()->get( 'PasswordResetRoutes' );
 
                // Maybe password resets are disabled, or there are no allowable routes
-               if ( !is_array( $wgPasswordResetRoutes ) ||
-                       !in_array( true, array_values( $wgPasswordResetRoutes ) )
+               if ( !is_array( $resetRoutes ) ||
+                       !in_array( true, array_values( $resetRoutes ) )
                ) {
                        return 'passwordreset-disabled';
                }
@@ -335,7 +334,7 @@ class SpecialPasswordReset extends FormSpecialPage {
                }
 
                // Maybe email features have been disabled
-               if ( !$wgEnableEmail ) {
+               if ( !$this->getConfig()->get( 'EnableEmail' ) ) {
                        return 'passwordreset-emaildisabled';
                }
 
index 7554e37..b64b029 100644 (file)
@@ -103,11 +103,9 @@ class SpecialProtectedpages extends SpecialPage {
        protected function showOptions( $namespace, $type = 'edit', $level, $sizetype,
                $size, $indefOnly, $cascadeOnly, $noRedirect
        ) {
-               global $wgScript;
-
                $title = $this->getPageTitle();
 
-               return Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
+               return Xml::openElement( 'form', array( 'method' => 'get', 'action' => wfScript() ) ) .
                        Xml::openElement( 'fieldset' ) .
                        Xml::element( 'legend', array(), $this->msg( 'protectedpages' )->text() ) .
                        Html::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" .
@@ -252,14 +250,12 @@ class SpecialProtectedpages extends SpecialPage {
         * @return string Formatted HTML
         */
        protected 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 ) {
                        // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
                        if ( $type != '' && $type != '*' ) {
                                $text = $this->msg( "restriction-level-$type" )->text();
index 7dd932f..63313cf 100755 (executable)
@@ -198,36 +198,36 @@ class PHPUnitMaintClass extends Maintenance {
 $maintClass = 'PHPUnitMaintClass';
 require RUN_MAINTENANCE_IF_MAIN;
 
-$pharFile = stream_resolve_include_path( 'phpunit.phar' );
-$isValidPhar = Phar::isValidPharFilename( $pharFile );
-
-if ( !$isValidPhar && !class_exists( 'PHPUnit_Runner_Version' ) ) {
-       // try loading phpunit via PEAR
-       require_once 'PHPUnit/Runner/Version.php';
-}
-
 // Prevent segfault when we have lots of unit tests (bug 62623)
-if ( version_compare( PHP_VERSION, '5.4.0', '<' )
-       && version_compare( PHP_VERSION, '5.3.0', '>=' )
-) {
+if ( version_compare( PHP_VERSION, '5.4.0', '<' ) ) {
        register_shutdown_function( function () {
                gc_collect_cycles();
                gc_disable();
        } );
 }
 
-if ( $isValidPhar ) {
-       require $pharFile;
-} else {
-       if ( PHPUnit_Runner_Version::id() !== '@package_version@'
-           && version_compare( PHPUnit_Runner_Version::id(), '3.7.0', '<' )
-       ) {
-           die( 'PHPUnit 3.7.0 or later required, you have ' . PHPUnit_Runner_Version::id() . ".\n" );
-       }
 
-       if ( !class_exists( 'PHPUnit_TextUI_Command' ) ) {
-           require_once 'PHPUnit/Autoload.php';
+$ok = false;
+
+foreach( array(
+       stream_resolve_include_path( 'phpunit.phar' ),
+       'PHPUnit/Runner/Version.php',
+       'PHPUnit/Autoload.php'
+) as $includePath ) {
+       @include_once( $includePath );
+       if ( class_exists( 'PHPUnit_TextUI_Command' ) ) {
+               $ok = true;
+               break;
        }
+}
+
+if ( !$ok ) {
+       die( "Couldn't find a usable PHPUnit.\n" );
+}
 
-       PHPUnit_TextUI_Command::main();
+$puVersion = PHPUnit_Runner_Version::id();
+if ( $puVersion !== '@package_version@' && version_compare( $puVersion, '3.7.0', '<' ) ) {
+       die( "PHPUnit 3.7.0 or later required; you have {$puVersion}.\n" );
 }
+
+PHPUnit_TextUI_Command::main();