specials: Avoid the use of global variables in Special:Version
[lhc/web/wiklou.git] / includes / specials / SpecialVersion.php
index 2ad0def..0c4959a 100644 (file)
@@ -23,6 +23,8 @@
  * @ingroup SpecialPage
  */
 
  * @ingroup SpecialPage
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * Give information about the version of MediaWiki, PHP, the DB and extensions
  *
 /**
  * Give information about the version of MediaWiki, PHP, the DB and extensions
  *
@@ -47,7 +49,9 @@ class SpecialVersion extends SpecialPage {
         * @param string|null $par
         */
        public function execute( $par ) {
         * @param string|null $par
         */
        public function execute( $par ) {
-               global $IP, $wgExtensionCredits;
+               global $IP;
+               $config = $this->getConfig();
+               $extensionCredits = $config->get( 'ExtensionCredits' );
 
                $this->setHeaders();
                $this->outputHeader();
 
                $this->setHeaders();
                $this->outputHeader();
@@ -60,7 +64,7 @@ class SpecialVersion extends SpecialPage {
                if ( isset( $parts[1] ) ) {
                        $extName = str_replace( '_', ' ', $parts[1] );
                        // Find it!
                if ( isset( $parts[1] ) ) {
                        $extName = str_replace( '_', ' ', $parts[1] );
                        // Find it!
-                       foreach ( $wgExtensionCredits as $group => $extensions ) {
+                       foreach ( $extensionCredits as $group => $extensions ) {
                                foreach ( $extensions as $ext ) {
                                        if ( isset( $ext['name'] ) && ( $ext['name'] === $extName ) ) {
                                                $extNode = &$ext;
                                foreach ( $extensions as $ext ) {
                                        if ( isset( $ext['name'] ) && ( $ext['name'] === $extName ) ) {
                                                $extNode = &$ext;
@@ -206,6 +210,7 @@ class SpecialVersion extends SpecialPage {
                        'Victor Vasiliev', 'Rotem Liss', 'Platonides', 'Antoine Musso',
                        'Timo Tijhof', 'Daniel Kinzler', 'Jeroen De Dauw', 'Brad Jorsch',
                        'Bartosz Dziewoński', 'Ed Sanders', 'Moriel Schottlender',
                        'Victor Vasiliev', 'Rotem Liss', 'Platonides', 'Antoine Musso',
                        'Timo Tijhof', 'Daniel Kinzler', 'Jeroen De Dauw', 'Brad Jorsch',
                        'Bartosz Dziewoński', 'Ed Sanders', 'Moriel Schottlender',
+                       'Kunal Mehta', 'James D. Forrester', 'Brian Wolff', 'Adam Shorland',
                        $othersLink, $translatorsLink
                ];
 
                        $othersLink, $translatorsLink
                ];
 
@@ -405,12 +410,13 @@ class SpecialVersion extends SpecialPage {
         * @return string Wikitext
         */
        public function getExtensionCredits() {
         * @return string Wikitext
         */
        public function getExtensionCredits() {
-               global $wgExtensionCredits;
+               $config = $this->getConfig();
+               $extensionCredits = $config->get( 'ExtensionCredits' );
 
                if (
 
                if (
-                       count( $wgExtensionCredits ) === 0 ||
+                       count( $extensionCredits ) === 0 ||
                        // Skins are displayed separately, see getSkinCredits()
                        // Skins are displayed separately, see getSkinCredits()
-                       ( count( $wgExtensionCredits ) === 1 && isset( $wgExtensionCredits['skin'] ) )
+                       ( count( $extensionCredits ) === 1 && isset( $extensionCredits['skin'] ) )
                ) {
                        return '';
                }
                ) {
                        return '';
                }
@@ -425,14 +431,14 @@ class SpecialVersion extends SpecialPage {
                        Xml::openElement( 'table', [ 'class' => 'wikitable plainlinks', 'id' => 'sv-ext' ] );
 
                // Make sure the 'other' type is set to an array.
                        Xml::openElement( 'table', [ 'class' => 'wikitable plainlinks', 'id' => 'sv-ext' ] );
 
                // Make sure the 'other' type is set to an array.
-               if ( !array_key_exists( 'other', $wgExtensionCredits ) ) {
-                       $wgExtensionCredits['other'] = [];
+               if ( !array_key_exists( 'other', $extensionCredits ) ) {
+                       $extensionCredits['other'] = [];
                }
 
                // Find all extensions that do not have a valid type and give them the type 'other'.
                }
 
                // Find all extensions that do not have a valid type and give them the type 'other'.
-               foreach ( $wgExtensionCredits as $type => $extensions ) {
+               foreach ( $extensionCredits as $type => $extensions ) {
                        if ( !array_key_exists( $type, $extensionTypes ) ) {
                        if ( !array_key_exists( $type, $extensionTypes ) ) {
-                               $wgExtensionCredits['other'] = array_merge( $wgExtensionCredits['other'], $extensions );
+                               $extensionCredits['other'] = array_merge( $extensionCredits['other'], $extensions );
                        }
                }
 
                        }
                }
 
@@ -554,9 +560,7 @@ class SpecialVersion extends SpecialPage {
         * @return string HTML output
         */
        protected function getParserTags() {
         * @return string HTML output
         */
        protected function getParserTags() {
-               global $wgParser;
-
-               $tags = $wgParser->getTags();
+               $tags = MediaWikiServices::getInstance()->getParser()->getTags();
 
                if ( count( $tags ) ) {
                        $out = Html::rawElement(
 
                if ( count( $tags ) ) {
                        $out = Html::rawElement(
@@ -598,9 +602,7 @@ class SpecialVersion extends SpecialPage {
         * @return string HTML output
         */
        protected function getParserFunctionHooks() {
         * @return string HTML output
         */
        protected function getParserFunctionHooks() {
-               global $wgParser;
-
-               $fhooks = $wgParser->getFunctionHooks();
+               $fhooks = MediaWikiServices::getInstance()->getParser()->getFunctionHooks();
                if ( count( $fhooks ) ) {
                        $out = Html::rawElement(
                                'h2',
                if ( count( $fhooks ) ) {
                        $out = Html::rawElement(
                                'h2',
@@ -634,16 +636,17 @@ class SpecialVersion extends SpecialPage {
         * @return string
         */
        protected function getExtensionCategory( $type, $message ) {
         * @return string
         */
        protected function getExtensionCategory( $type, $message ) {
-               global $wgExtensionCredits;
+               $config = $this->getConfig();
+               $extensionCredits = $config->get( 'ExtensionCredits' );
 
                $out = '';
 
 
                $out = '';
 
-               if ( array_key_exists( $type, $wgExtensionCredits ) && count( $wgExtensionCredits[$type] ) > 0 ) {
+               if ( array_key_exists( $type, $extensionCredits ) && count( $extensionCredits[$type] ) > 0 ) {
                        $out .= $this->openExtType( $message, 'credits-' . $type );
 
                        $out .= $this->openExtType( $message, 'credits-' . $type );
 
-                       usort( $wgExtensionCredits[$type], [ $this, 'compare' ] );
+                       usort( $extensionCredits[$type], [ $this, 'compare' ] );
 
 
-                       foreach ( $wgExtensionCredits[$type] as $extension ) {
+                       foreach ( $extensionCredits[$type] as $extension ) {
                                $out .= $this->getCreditsForExtension( $type, $extension );
                        }
                }
                                $out .= $this->getCreditsForExtension( $type, $extension );
                        }
                }
@@ -703,7 +706,7 @@ class SpecialVersion extends SpecialPage {
                                [ 'class' => 'mw-version-ext-name' ]
                        );
                } else {
                                [ 'class' => 'mw-version-ext-name' ]
                        );
                } else {
-                       $extensionNameLink = $extensionName;
+                       $extensionNameLink = htmlspecialchars( $extensionName );
                }
 
                // ... and the version information
                }
 
                // ... and the version information
@@ -883,9 +886,9 @@ class SpecialVersion extends SpecialPage {
                        $ret[] = Html::closeElement( 'table' );
 
                        return implode( "\n", $ret );
                        $ret[] = Html::closeElement( 'table' );
 
                        return implode( "\n", $ret );
-               } else {
-                       return '';
                }
                }
+
+               return '';
        }
 
        private function openExtType( $text = null, $name = null ) {
        }
 
        private function openExtType( $text = null, $name = null ) {
@@ -1133,10 +1136,11 @@ class SpecialVersion extends SpecialPage {
         * @return string Wikitext
         */
        public function getEntryPointInfo() {
         * @return string Wikitext
         */
        public function getEntryPointInfo() {
-               global $wgArticlePath, $wgScriptPath;
-               $scriptPath = $wgScriptPath ?: "/";
+               $config = $this->getConfig();
+               $scriptPath = $config->get( 'ScriptPath' ) ?: '/';
+
                $entryPoints = [
                $entryPoints = [
-                       'version-entrypoints-articlepath' => $wgArticlePath,
+                       'version-entrypoints-articlepath' => $config->get( 'ArticlePath' ),
                        'version-entrypoints-scriptpath' => $scriptPath,
                        'version-entrypoints-index-php' => wfScript( 'index' ),
                        'version-entrypoints-api-php' => wfScript( 'api' ),
                        'version-entrypoints-scriptpath' => $scriptPath,
                        'version-entrypoints-index-php' => wfScript( 'index' ),
                        'version-entrypoints-api-php' => wfScript( 'api' ),