jenkins-bot has submitted this change and it was merged.

Change subject: Add extension.json, empty PHP entry point
......................................................................


Add extension.json, empty PHP entry point

Conditionally register NS_CONFIG and NS_DATA

NS_DATA to be used in near future

Add NS_DATA namespace messages for completeness

Remove 'UnitTestList' hook

Bug: T88054
Bug: T142120
Bug: T142121
Change-Id: I394829630ea6fc8d71219c70ccffc6cecdee345b
---
M JsonConfig.namespaces.php
M JsonConfig.php
A extension.json
M includes/JCSingleton.php
4 files changed, 205 insertions(+), 166 deletions(-)

Approvals:
  Reedy: Looks good to me, but someone else must approve
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/JsonConfig.namespaces.php b/JsonConfig.namespaces.php
index f85e2c7..2d67e55 100644
--- a/JsonConfig.namespaces.php
+++ b/JsonConfig.namespaces.php
@@ -15,6 +15,8 @@
 $namespaceNames['en'] = array(
        482 => 'Config',
        483 => 'Config_talk',
+       486 => 'Data',
+       487 => 'Data_talk',
 );
 
 $namespaceNames['vi'] = array(
diff --git a/JsonConfig.php b/JsonConfig.php
index e52a323..854cdb6 100644
--- a/JsonConfig.php
+++ b/JsonConfig.php
@@ -11,167 +11,17 @@
  * @license GNU General Public Licence 2.0 or later
  */
 
-// Needs to be called within MediaWiki; not standalone
-if ( !defined( 'MEDIAWIKI' ) ) {
-       echo( "This is a MediaWiki extension and cannot run standalone.\n" );
-       die( -1 );
+if ( function_exists( 'wfLoadExtension' ) ) {
+       wfLoadExtension( 'JsonConfig' );
+       // Keep i18n globals so mergeMessageFileList.php doesn't break
+       $wgMessagesDirs['JsonConfig'] = __DIR__ . '/i18n';
+       $wgExtensionMessagesFiles['JsonConfigNamespaces'] = __DIR__ . 
'/JsonConfig.namespaces.php';
+       /* wfWarn(
+               'Deprecated PHP entry point used for JsonConfig extension. ' .
+               'Please use wfLoadExtension instead, ' .
+               'see https://www.mediawiki.org/wiki/Extension_registration for 
more details.'
+       ); */
+       return;
+} else {
+       die( 'This version of the JsonConfig extension requires MediaWiki 
1.25+' );
 }
-
-// Extension credits that will show up on Special:Version
-$wgExtensionCredits['other'][] = array(
-       'path' => __FILE__,
-       'name' => 'JsonConfig',
-       'version' => '1.1.0',
-       'author' => array( 'Yuri Astrakhan' ),
-       'descriptionmsg' => 'jsonconfig-desc',
-       'url' => 'https://www.mediawiki.org/wiki/Extension:JsonConfig',
-       'license-name' => 'GPL-2.0+',
-);
-
-define( 'NS_CONFIG', 482 );
-define( 'NS_CONFIG_TALK', 483 );
-define( 'NS_DATA', 486 );
-define( 'NS_DATA_TALK', 487 );
-
-$cwd = __DIR__ . DIRECTORY_SEPARATOR;
-$wgMessagesDirs['JsonConfig'] = $cwd . 'i18n';
-
-// @todo: this entry should be done only if $wgJsonConfigEnabled === true && 
namespace is actually used by config
-$wgExtensionMessagesFiles['JsonConfigNamespaces'] = $cwd . 
'JsonConfig.namespaces.php';
-
-$wgHooks['ScribuntoExternalLibraries'][] = 
'JsonConfig\JCLuaLibrary::onScribuntoExternalLibraries';
-
-$cwd .= 'includes' . DIRECTORY_SEPARATOR;
-foreach ( array(
-                       'JCApi',
-                       'JCCache',
-                       'JCContent',
-                       'JCContentHandler',
-                       'JCContentView',
-                       'JCDataContent',
-                       'JCDefaultContentView',
-                       'JCDefaultObjContentView',
-                       'JCLuaLibrary',
-                       'JCObjContent',
-                       'JCSingleton',
-                       'JCTabularContent',
-                       'JCTabularContentView',
-                       'JCTitle',
-                       'JCUtils',
-                       'JCValidators',
-                       'JCValue',
-               ) as $key => $class ) {
-       $wgAutoloadClasses['JsonConfig\\' . ( is_string( $key ) ? $key : $class 
)] = $cwd . $class . '.php';
-}
-
-/**
- * Use this prefix when parsing remote titles. This prefix + ':' will be 
prepended to title strings
- * in JCSingleton::parseTitle(), passed through the english TitleParser, and 
prefix removed.
- * "commons" seems to be a fairly safe bet, as it is auto-setup in Vagrant and 
in many wikis.
- * Make sure this prefix exists in the interwiki table, but not as a local 
interwiki:
- *   http://.../w/api.php?action=query&meta=siteinfo&siprop=interwikimap
- */
-$wgJsonConfigInterwikiPrefix = 'commons';
-
-/**
- * Each extension should add its configuration profiles as described in the doc
- * 
https://www.mediawiki.org/wiki/Requests_for_comment/Json_Config_pages_in_wiki
- * https://www.mediawiki.org/wiki/Extension:JsonConfig
- */
-$wgJsonConfigs = array();
-
-/**
- * Array of model ID => content class mappings
- * Each value could either be a string - a JCContent-derived class name
- * or an array:
- *    { 'content' => 'classname',  // derives from JCContent
- *      'view'    => 'classname' } // implements JCContentView
- */
-$wgJsonConfigModels = array();
-
-/**
- * Disable memcached caching (debugging)
- */
-$wgJsonConfigDisableCache = false;
-
-/**
- * Change this value whenever the entire JsonConfig cache needs to be 
invalidated
- */
-$wgJsonConfigCacheKeyPrefix = '1';
-
-/**
- * If true, enable Scribunto lua functions
- * TODO: make this true by default, after updating InitialSettings.php
- */
-$wgJsonConfigEnableLuaSupport = false;
-
-/**
- * Quick check if the current wiki will store any configurations.
- * Faster than doing a full parsing of the $wgJsonConfigs in the 
JCSingleton::init()
- * @return bool
- */
-function jsonConfigIsStorage() {
-       static $isStorage = null;
-       if ( $isStorage === null ) {
-               global $wgJsonConfigs;
-               $isStorage = false;
-               foreach ( $wgJsonConfigs as $jc ) {
-                       if ( ( !array_key_exists( 'isLocal', $jc ) || 
$jc['isLocal'] ) ||
-                            ( array_key_exists( 'store', $jc ) )
-                       ) {
-                               $isStorage = true;
-                               break;
-                       }
-               }
-       }
-
-       return $isStorage;
-}
-
-// Registers hooks and resources which are only required on the config-hosting 
wiki.
-$wgExtensionFunctions[] = function () {
-       global $wgAPIModules;
-       $wgAPIModules['jsonconfig'] = 'JsonConfig\JCApi';
-
-       // The rest of the function is storage-related only
-       if ( !jsonConfigIsStorage() ) {
-               return;
-       }
-
-       global $wgResourceModules, $wgHooks;
-       $wgResourceModules['ext.jsonConfig'] = array(
-               'localBasePath' => __DIR__,
-               'remoteExtPath' => 'JsonConfig',
-               'styles' => array( 'modules/JsonConfig.css' ),
-               'position' => 'top',
-       );
-
-       $prefix = 'JsonConfig\JCSingleton::on';
-       foreach ( array(
-                         'ContentHandlerDefaultModelFor',
-                         'ContentHandlerForModelID',
-                         'CodeEditorGetPageLanguage',
-                         'EditFilterMergedContent',
-                         'BeforePageDisplay',
-                         'MovePageIsValidMove',
-                         'AbortMove',
-                         'ArticleDeleteComplete',
-                         'ArticleUndelete',
-                         'PageContentSaveComplete',
-                         'TitleMoveComplete',
-                         'userCan',
-                     'UnitTestsList'
-                 ) as $hook ) {
-               $wgHooks[$hook][] = $prefix . $hook;
-       }
-};
-
-// MWNamespace::getCanonicalNamespaces() might be called before our own 
extension is initialized
-$wgHooks['CanonicalNamespaces'][] = function ( array &$namespaces ) {
-       if ( jsonConfigIsStorage() ) {
-               // Class loader will not be called until it gets here
-               \JsonConfig\JCSingleton::onCanonicalNamespaces( $namespaces );
-       }
-
-       return true;
-};
diff --git a/extension.json b/extension.json
new file mode 100644
index 0000000..43afcd2
--- /dev/null
+++ b/extension.json
@@ -0,0 +1,130 @@
+{
+       "name": "JsonConfig",
+       "version": "1.1.0",
+       "author": [
+               "Yuri Astrakhan"
+       ],
+       "url": "https://www.mediawiki.org/wiki/Extension:JsonConfig";,
+       "descriptionmsg": "jsonconfig-desc",
+       "type": "other",
+       "license-name": "GPL-2.0+",
+       "namespaces": [
+               {
+                       "id": 482,
+                       "constant": "NS_CONFIG",
+                       "name": "Config",
+                       "conditional": true
+               },
+               {
+                       "id": 483,
+                       "constant": "NS_CONFIG_TALK",
+                       "name": "Config_talk",
+                       "conditional": true
+               },
+               {
+                       "id": 486,
+                       "constant": "NS_DATA",
+                       "name": "Data",
+                       "conditional": true
+               },
+               {
+                       "id": 487,
+                       "constant": "NS_DATA_TALK",
+                       "name": "Data_talk",
+                       "conditional": true
+               }
+       ],
+       "MessagesDirs": {
+               "JsonConfig": [
+                       "i18n"
+               ]
+       },
+       "ExtensionMessagesFiles": {
+               "JsonConfigNamespaces": "JsonConfig.namespaces.php"
+       },
+       "AutoloadClasses": {
+               "JsonConfig\\JCApi": "includes/JCApi.php",
+               "JsonConfig\\JCCache": "includes/JCCache.php",
+               "JsonConfig\\JCContent": "includes/JCContent.php",
+               "JsonConfig\\JCContentHandler": "includes/JCContentHandler.php",
+               "JsonConfig\\JCContentView": "includes/JCContentView.php",
+               "JsonConfig\\JCDataContent": "includes/JCDataContent.php",
+               "JsonConfig\\JCDefaultContentView": 
"includes/JCDefaultContentView.php",
+               "JsonConfig\\JCDefaultObjContentView": 
"includes/JCDefaultObjContentView.php",
+               "JsonConfig\\JCLuaLibrary": "includes/JCLuaLibrary.php",
+               "JsonConfig\\JCObjContent": "includes/JCObjContent.php",
+               "JsonConfig\\JCSingleton": "includes/JCSingleton.php",
+               "JsonConfig\\JCTabularContent": "includes/JCTabularContent.php",
+               "JsonConfig\\JCTabularContentView": 
"includes/JCTabularContentView.php",
+               "JsonConfig\\JCTitle": "includes/JCTitle.php",
+               "JsonConfig\\JCUtils": "includes/JCUtils.php",
+               "JsonConfig\\JCValidators": "includes/JCValidators.php",
+               "JsonConfig\\JCValue": "includes/JCValue.php"
+       },
+       "APIModules": {
+               "jsonconfig": "JsonConfig\\JCApi"
+       },
+       "ResourceModules": {
+               "ext.jsonConfig": {
+                       "styles": "JsonConfig.css",
+                       "position": "top"
+               }
+       },
+       "ResourceFileModulePaths": {
+               "localBasePath": "modules",
+               "remoteExtPath": "JsonConfig/modules"
+       },
+       "Hooks": {
+               "CanonicalNamespaces": [
+                       "JsonConfig\\JCSingleton::onCanonicalNamespaces"
+               ],
+               "ScribuntoExternalLibraries": [
+                       "JsonConfig\\JCLuaLibrary::onScribuntoExternalLibraries"
+               ],
+               "ContentHandlerDefaultModelFor": [
+                       
"JsonConfig\\JCSingleton::onContentHandlerDefaultModelFor"
+               ],
+               "ContentHandlerForModelID": [
+                       "JsonConfig\\JCSingleton::onContentHandlerForModelID"
+               ],
+               "CodeEditorGetPageLanguage": [
+                       "JsonConfig\\JCSingleton::onCodeEditorGetPageLanguage"
+               ],
+               "EditFilterMergedContent": [
+                       "JsonConfig\\JCSingleton::onEditFilterMergedContent"
+               ],
+               "BeforePageDisplay": [
+                       "JsonConfig\\JCSingleton::onBeforePageDisplay"
+               ],
+               "MovePageIsValidMove": [
+                       "JsonConfig\\JCSingleton::onMovePageIsValidMove"
+               ],
+               "AbortMove": [
+                       "JsonConfig\\JCSingleton::onAbortMove"
+               ],
+               "ArticleDeleteComplete": [
+                       "JsonConfig\\JCSingleton::onArticleDeleteComplete"
+               ],
+               "ArticleUndelete": [
+                       "JsonConfig\\JCSingleton::onArticleUndelete"
+               ],
+               "PageContentSaveComplete": [
+                       "JsonConfig\\JCSingleton::onPageContentSaveComplete"
+               ],
+               "TitleMoveComplete": [
+                       "JsonConfig\\JCSingleton::onTitleMoveComplete"
+               ],
+               "userCan": [
+                       "JsonConfig\\JCSingleton::onuserCan"
+               ]
+       },
+       "config": {
+               "JsonConfigs": [],
+               "JsonConfigModels": [],
+               "JsonConfigDisableCache": false,
+               "JsonConfigCacheKeyPrefix": "1",
+               "JsonConfigEnableLuaSupport": false,
+               "JsonConfigInterwikiPrefix": "commons"
+       },
+       "manifest_version": 1
+}
diff --git a/includes/JCSingleton.php b/includes/JCSingleton.php
index cc18ebf..46181d0 100644
--- a/includes/JCSingleton.php
+++ b/includes/JCSingleton.php
@@ -516,6 +516,10 @@
         * @param array $namespaces
         */
        public static function onCanonicalNamespaces( array &$namespaces ) {
+               if ( !self::jsonConfigIsStorage() ) {
+                       return true;
+               }
+
                self::init();
                foreach ( self::$namespaces as $ns => $name ) {
                        if ( $name === false ) { // must be already declared
@@ -545,6 +549,10 @@
         * @return bool
         */
        public static function onContentHandlerDefaultModelFor( $title, 
&$modelId ) {
+               if ( !self::jsonConfigIsStorage() ) {
+                       return true;
+               }
+
                $jct = self::parseTitle( $title );
                if ( $jct ) {
                        $modelId = $jct->getConfig()->model;
@@ -560,6 +568,10 @@
         * @return bool
         */
        public static function onContentHandlerForModelID( $modelId, &$handler 
) {
+               if ( !self::jsonConfigIsStorage() ) {
+                       return true;
+               }
+
                self::init();
                global $wgJsonConfigModels;
                if ( array_key_exists( $modelId, $wgJsonConfigModels ) ) {
@@ -578,6 +590,10 @@
         * @return bool
         */
        static function onCodeEditorGetPageLanguage( $title, &$lang ) {
+               if ( !self::jsonConfigIsStorage() ) {
+                       return true;
+               }
+
                // todo/fixme? We should probably add 'json' lang to only those 
pages that pass parseTitle()
                $handler = ContentHandler::getForModelID( 
$title->getContentModel() );
                if ( $handler->getDefaultFormat() === CONTENT_FORMAT_JSON || 
self::parseTitle( $title ) ) {
@@ -599,6 +615,10 @@
         */
        static function onEditFilterMergedContent( /** @noinspection 
PhpUnusedParameterInspection */
                $context, $content, $status, $summary, $user, $minoredit ) {
+               if ( !self::jsonConfigIsStorage() ) {
+                       return true;
+               }
+
                if ( is_a( $content, 'JsonConfig\JCContent' ) ) {
                        $status->merge( $content->getStatus() );
                        if ( !$status->isGood() ) {
@@ -615,6 +635,10 @@
         * @return bool
         */
        static function onBeforePageDisplay( /** @noinspection 
PhpUnusedParameterInspection */ &$out, &$skin ) {
+               if ( !self::jsonConfigIsStorage() ) {
+                       return true;
+               }
+
                $title = $out->getTitle();
                // todo/fixme? We should probably add ext.jsonConfig style to 
only those pages that pass parseTitle()
                $handler = ContentHandler::getForModelID( 
$title->getContentModel() );
@@ -627,6 +651,10 @@
        }
 
        public static function onMovePageIsValidMove( Title $oldTitle, Title 
$newTitle, Status $status ) {
+               if ( !self::jsonConfigIsStorage() ) {
+                       return true;
+               }
+
                $jctOld = self::parseTitle( $oldTitle );
                if ( $jctOld ) {
                        $jctNew = self::parseTitle( $newTitle );
@@ -644,6 +672,10 @@
        }
 
        public static function onAbortMove( /** @noinspection 
PhpUnusedParameterInspection */ Title $title, Title $newTitle, $wgUser, &$err, 
$reason ) {
+               if ( !self::jsonConfigIsStorage() ) {
+                       return true;
+               }
+
                $status = new \Status();
                self::onMovePageIsValidMove( $title, $newTitle, $status );
                if ( !$status->isOK() ) {
@@ -682,6 +714,10 @@
         * @return bool
         */
        public static function onuserCan( /** @noinspection 
PhpUnusedParameterInspection */ &$title, &$user, $action, &$result = null ) {
+               if ( !self::jsonConfigIsStorage() ) {
+                       return true;
+               }
+
                if ( $action === 'create' && self::parseTitle( $title ) === 
null ) {
                        // prohibit creation of the pages for the namespace 
that we handle,
                        // if the title is not matching declared rules
@@ -697,6 +733,10 @@
         * @return bool
         */
        private static function onArticleChangeComplete( $value, $content = 
null ) {
+               if ( !self::jsonConfigIsStorage() ) {
+                       return true;
+               }
+
                if ( $value && ( !$content || is_a( $content, 
'JsonConfig\JCContent' ) ) ) {
 
                        if ( method_exists( $value, 'getTitle' ) ) {
@@ -728,8 +768,25 @@
                return true;
        }
 
-       public static function onUnitTestsList( &$files ) {
-               $files = array_merge( $files, glob( __DIR__ . 
'/../tests/phpunit/*Test.php' ) );
-               return true;
+       /**
+        * Quick check if the current wiki will store any configurations.
+        * Faster than doing a full parsing of the $wgJsonConfigs in the 
JCSingleton::init()
+        * @return bool
+        */
+       private static function jsonConfigIsStorage() {
+               static $isStorage = null;
+               if ( $isStorage === null ) {
+                       global $wgJsonConfigs;
+                       $isStorage = false;
+                       foreach ( $wgJsonConfigs as $jc ) {
+                               if ( ( !array_key_exists( 'isLocal', $jc ) || 
$jc['isLocal'] ) ||
+                                        ( array_key_exists( 'store', $jc ) )
+                               ) {
+                                       $isStorage = true;
+                                       break;
+                               }
+                       }
+               }
+               return $isStorage;
        }
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I394829630ea6fc8d71219c70ccffc6cecdee345b
Gerrit-PatchSet: 19
Gerrit-Project: mediawiki/extensions/JsonConfig
Gerrit-Branch: master
Gerrit-Owner: Paladox <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Paladox <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: Spage <[email protected]>
Gerrit-Reviewer: Yurik <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to