jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/370904 )

Change subject: Move JS config vars from page HTML into RL module
......................................................................


Move JS config vars from page HTML into RL module

Bug: T172458
Change-Id: I60bfab0028a21c3942508f5ad6377df9a285c7de
(cherry picked from commit 0f6d8818be27bdb534a7ebd037fd27a1e2ac63bf)
---
M CodeMirror.hooks.php
A ResourceLoaderCodeMirrorModule.php
M extension.json
M phpcs.xml
4 files changed, 113 insertions(+), 82 deletions(-)

Approvals:
  MaxSem: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/CodeMirror.hooks.php b/CodeMirror.hooks.php
index 1bd9c40..90c3eff 100644
--- a/CodeMirror.hooks.php
+++ b/CodeMirror.hooks.php
@@ -32,84 +32,6 @@
        }
 
        /**
-        * Returns an array of variables for CodeMirror to work (tags and so on)
-        *
-        * @global Parser $wgParser
-        * @global Language $wgContLang
-        * @staticvar array $config Cached version of configuration
-        * @return array
-        */
-       public static function getConfiguraton() {
-               global $wgParser, $wgContLang;
-               static $config = [];
-
-               // if we already created these variable array, return it
-               if ( !$config ) {
-                        // Use the content language, not the user language. 
(See T170130.)
-                       $lang = $wgContLang;
-                       $registry = ExtensionRegistry::getInstance();
-
-                       if ( !isset( $wgParser->mFunctionSynonyms ) ) {
-                               $wgParser->initialiseVariables();
-                               $wgParser->firstCallInit();
-                       }
-
-                       // initialize configuration
-                       $config = [
-                               'pluginModules' => $registry->getAttribute( 
'CodeMirrorPluginModules' ),
-                               'tagModes' => $registry->getAttribute( 
'CodeMirrorTagModes' ),
-                               'tags' => array_fill_keys( 
$wgParser->getTags(), true ),
-                               'doubleUnderscore' => [ [], [] ],
-                               'functionSynonyms' => 
$wgParser->mFunctionSynonyms,
-                               'urlProtocols' => $wgParser->mUrlProtocols,
-                               'linkTrailCharacters' =>  $lang->linkTrail(),
-                       ];
-
-                       $mw = $lang->getMagicWords();
-                       foreach ( MagicWord::getDoubleUnderscoreArray()->names 
as $name ) {
-                               if ( isset( $mw[$name] ) ) {
-                                       $caseSensitive = array_shift( 
$mw[$name] ) == 0 ? 0 : 1;
-                                       foreach ( $mw[$name] as $n ) {
-                                               $n = $caseSensitive ? $n : 
$lang->lc( $n );
-                                               
$config['doubleUnderscore'][$caseSensitive][$n] = $name;
-                                       }
-                               } else {
-                                       $config['doubleUnderscore'][0][] = 
$name;
-                               }
-                       }
-
-                       foreach ( MagicWord::getVariableIDs() as $name ) {
-                               if ( isset( $mw[$name] ) ) {
-                                       $caseSensitive = array_shift( 
$mw[$name] ) == 0 ? 0 : 1;
-                                       foreach ( $mw[$name] as $n ) {
-                                               $n = $caseSensitive ? $n : 
$lang->lc( $n );
-                                               
$config['functionSynonyms'][$caseSensitive][$n] = $name;
-                                       }
-                               }
-                       }
-
-               }
-
-               return $config;
-       }
-
-       /**
-        * MakeGlobalVariablesScript hook handler
-        *
-        * @see 
https://www.mediawiki.org/wiki/Manual:Hooks/MakeGlobalVariablesScript
-        *
-        * @param array $vars
-        * @param OutputPage $out
-        */
-       public static function onMakeGlobalVariablesScript( array &$vars, 
OutputPage $out ) {
-               $context = $out->getContext();
-               // add CodeMirror vars on edit pages, or if VE is installed
-               if ( self::isCodeMirrorEnabled( $context ) || class_exists( 
'VisualEditorHooks' ) ) {
-                       $vars['extCodeMirrorConfig'] = self::getConfiguraton();
-               }
-       }
-
-       /**
         * BeforePageDisplay hook handler
         *
         * @see https://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay
diff --git a/ResourceLoaderCodeMirrorModule.php 
b/ResourceLoaderCodeMirrorModule.php
new file mode 100644
index 0000000..457d5cd
--- /dev/null
+++ b/ResourceLoaderCodeMirrorModule.php
@@ -0,0 +1,109 @@
+<?php
+/**
+ * ResourceLoader ext.CodeMirror module
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * ResourceLoader module for ext.CodeMirror
+ */
+class ResourceLoaderCodeMirrorModule extends ResourceLoaderFileModule {
+       /**
+        * @inheritdoc
+        */
+       public function getScript( ResourceLoaderContext $context ) {
+               return ResourceLoader::makeConfigSetScript(
+                               [ 'extCodeMirrorConfig' => 
$this->getFrontendConfiguraton() ]
+                       )
+                          . "\n"
+                          . parent::getScript( $context );
+       }
+
+       /**
+        * @inheritdoc
+        */
+       public function supportsURLLoading() {
+               // This module does not support loading URLs, because it inserts
+               // JS config vars into the module by the getScript function.
+               return false;
+       }
+
+       /**
+        * @inheritdoc
+        */
+       public function enableModuleContentVersion() {
+               return true;
+       }
+
+       /**
+        * Returns an array of variables for CodeMirror to work (tags and so on)
+        *
+        * @global Parser $wgParser
+        * @global Language $wgContLang
+        * @return array
+        */
+       private function getFrontendConfiguraton() {
+               global $wgParser, $wgContLang;
+
+               // Use the content language, not the user language. (See 
T170130.)
+               $lang = $wgContLang;
+               $registry = ExtensionRegistry::getInstance();
+
+               if ( !isset( $wgParser->mFunctionSynonyms ) ) {
+                       $wgParser->initialiseVariables();
+                       $wgParser->firstCallInit();
+               }
+
+               // initialize configuration
+               $config = [
+                       'pluginModules' => $registry->getAttribute( 
'CodeMirrorPluginModules' ),
+                       'tagModes' => $registry->getAttribute( 
'CodeMirrorTagModes' ),
+                       'tags' => array_fill_keys( $wgParser->getTags(), true ),
+                       'doubleUnderscore' => [ [], [] ],
+                       'functionSynonyms' => $wgParser->mFunctionSynonyms,
+                       'urlProtocols' => $wgParser->mUrlProtocols,
+                       'linkTrailCharacters' => $lang->linkTrail(),
+               ];
+
+               $mw = $lang->getMagicWords();
+               foreach ( MagicWord::getDoubleUnderscoreArray()->names as $name 
) {
+                       if ( isset( $mw[$name] ) ) {
+                               $caseSensitive = array_shift( $mw[$name] ) == 0 
? 0 : 1;
+                               foreach ( $mw[$name] as $n ) {
+                                       $n = $caseSensitive ? $n : $lang->lc( 
$n );
+                                       
$config['doubleUnderscore'][$caseSensitive][$n] = $name;
+                               }
+                       } else {
+                               $config['doubleUnderscore'][0][] = $name;
+                       }
+               }
+
+               foreach ( MagicWord::getVariableIDs() as $name ) {
+                       if ( isset( $mw[$name] ) ) {
+                               $caseSensitive = array_shift( $mw[$name] ) == 0 
? 0 : 1;
+                               foreach ( $mw[$name] as $n ) {
+                                       $n = $caseSensitive ? $n : $lang->lc( 
$n );
+                                       
$config['functionSynonyms'][$caseSensitive][$n] = $name;
+                               }
+                       }
+               }
+
+               return $config;
+       }
+}
diff --git a/extension.json b/extension.json
index 8362113..15ab20e 100644
--- a/extension.json
+++ b/extension.json
@@ -18,13 +18,15 @@
                ]
        },
        "AutoloadClasses": {
-               "CodeMirrorHooks": "CodeMirror.hooks.php"
+               "CodeMirrorHooks": "CodeMirror.hooks.php",
+               "ResourceLoaderCodeMirrorModule": 
"ResourceLoaderCodeMirrorModule.php"
        },
        "ResourceModules": {
                "ext.CodeMirror.loader": {
                        "loaderScripts": "ext.CodeMirror.loader.js"
                },
                "ext.CodeMirror": {
+                       "class": "ResourceLoaderCodeMirrorModule",
                        "dependencies": [
                                "ext.CodeMirror.lib",
                                "ext.CodeMirror.mode.mediawiki",
@@ -144,9 +146,6 @@
                "remoteExtPath": "CodeMirror/resources"
        },
        "Hooks": {
-               "MakeGlobalVariablesScript": [
-                       "CodeMirrorHooks::onMakeGlobalVariablesScript"
-               ],
                "BeforePageDisplay": [
                        "CodeMirrorHooks::onBeforePageDisplay"
                ],
diff --git a/phpcs.xml b/phpcs.xml
index df8c2b5..b0b9e1c 100644
--- a/phpcs.xml
+++ b/phpcs.xml
@@ -4,6 +4,7 @@
                <exclude 
name="MediaWiki.Commenting.FunctionComment.MissingParamComment"/>
                <exclude 
name="MediaWiki.Commenting.FunctionComment.MissingParamTag"/>
                <exclude 
name="MediaWiki.Commenting.FunctionComment.ParamNameNoMatch"/>
+               <exclude 
name="MediaWiki.Commenting.FunctionComment.MissingReturn"/>
        </rule>
        <file>.</file>
        <arg name="extensions" value="php,php5,inc"/>

-- 
To view, visit https://gerrit.wikimedia.org/r/370904
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I60bfab0028a21c3942508f5ad6377df9a285c7de
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CodeMirror
Gerrit-Branch: wmf/1.30.0-wmf.12
Gerrit-Owner: MaxSem <maxsem.w...@gmail.com>
Gerrit-Reviewer: MaxSem <maxsem.w...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to