Paladox has uploaded a new change for review.
https://gerrit.wikimedia.org/r/262711
Change subject: Add extension.json, empty PHP entry point
......................................................................
Add extension.json, empty PHP entry point
Bug: T88054
Change-Id: I394829630ea6fc8d71219c70ccffc6cecdee345b
---
A JsonConfig.hooks.php
M JsonConfig.php
A extension.json
3 files changed, 140 insertions(+), 138 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/JsonConfig
refs/changes/11/262711/1
diff --git a/JsonConfig.hooks.php b/JsonConfig.hooks.php
new file mode 100644
index 0000000..082fc19
--- /dev/null
+++ b/JsonConfig.hooks.php
@@ -0,0 +1,78 @@
+<?php
+
+class JsonConfigHooks {
+
+ public static function onExtensionRegistration() {
+ define( 'NS_CONFIG', 482 );
+ define( 'NS_CONFIG_TALK', 483 );
+ }
+
+ public static function onExtensionFunctions() {
+ global $wgAPIModules, $wgResourceModules, $wgHooks;
+ $wgAPIModules['jsonconfig'] = 'JsonConfig\JCApi';
+
+ // The rest of the function is storage-related only
+ if ( !jsonConfigIsStorage() ) {
+ return;
+ }
+
+ $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;
+ }
+ }
+
+ /**
+ * 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;
+ }
+
+ public static function onCanonicalNamespaces( array &$namespaces ) {
+ if ( jsonConfigIsStorage() ) {
+ // Class loader will not be called until it gets here
+ \JsonConfig\JCSingleton::onCanonicalNamespaces(
$namespaces );
+ }
+
+ return true;
+ }
+
+}
diff --git a/JsonConfig.php b/JsonConfig.php
index b6f1974..854cdb6 100644
--- a/JsonConfig.php
+++ b/JsonConfig.php
@@ -11,142 +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' => '0.1.0',
- 'author' => array( 'Yuri Astrakhan' ),
- 'descriptionmsg' => 'jsonconfig-desc',
- 'url' => 'https://www.mediawiki.org/wiki/Extension:JsonConfig',
-);
-
-define( 'NS_CONFIG', 482 );
-define( 'NS_CONFIG_TALK', 483 );
-
-$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';
-
-$cwd .= 'includes' . DIRECTORY_SEPARATOR;
-foreach ( array(
- 'JCApi',
- 'JCCache',
- 'JCContent',
- 'JCContentHandler',
- 'JCContentView',
- 'JCDefaultContentView',
- 'JCDefaultObjContentView',
- 'JCObjContent',
- 'JCSingleton',
- 'JCUtils',
- 'JCValidators',
- 'JCValue',
- ) as $key => $class ) {
- $wgAutoloadClasses['JsonConfig\\' . ( is_string( $key ) ? $key : $class
)] = $cwd . $class . '.php';
-}
-
-/**
- * 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';
-
-/**
- * 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..7c7f080
--- /dev/null
+++ b/extension.json
@@ -0,0 +1,49 @@
+{
+ "name": "JsonConfig",
+ "version": "0.1.0",
+ "author": [
+ "Yuri Astrakhan"
+ ],
+ "url": "https://www.mediawiki.org/wiki/Extension:JsonConfig",
+ "descriptionmsg": "jsonconfig-desc",
+ "type": "other",
+ "callback": "JsonConfigHooks::onExtensionRegistration",
+ "ExtensionFunctions": [
+ "JsonConfigHooks::onExtensionFunctions"
+ ],
+ "MessagesDirs": {
+ "JsonConfig": [
+ "i18n"
+ ]
+ },
+ "ExtensionMessagesFiles": {
+ "JsonConfigNamespaces": "JsonConfig.namespaces.php"
+ },
+ "AutoloadClasses": {
+ "JsonConfigHooks": "JsonConfig.hooks.php",
+ "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\\JCDefaultContentView":
"includes\\JCDefaultContentView.php",
+ "JsonConfig\\JCDefaultObjContentView":
"includes\\JCDefaultObjContentView.php",
+ "JsonConfig\\JCObjContent": "includes\\JCObjContent.php",
+ "JsonConfig\\JCSingleton": "includes\\JCSingleton.php",
+ "JsonConfig\\JCUtils": "includes\\JCUtils.php",
+ "JsonConfig\\JCValidators": "includes\\JCValidators.php",
+ "JsonConfig\\JCValue": "includes\\JCValue.php"
+ },
+ "Hooks": {
+ "CanonicalNamespaces": [
+ "JsonConfigHooks::onCanonicalNamespaces"
+ ]
+ },
+ "config": {
+ "JsonConfigs": [],
+ "JsonConfigModels": [],
+ "JsonConfigDisableCache": false,
+ "JsonConfigCacheKeyPrefix": "1"
+ },
+ "manifest_version": 1
+}
--
To view, visit https://gerrit.wikimedia.org/r/262711
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I394829630ea6fc8d71219c70ccffc6cecdee345b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/JsonConfig
Gerrit-Branch: master
Gerrit-Owner: Paladox <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits