jenkins-bot has submitted this change and it was merged.
Change subject: Register NS_SCHEMA early if running on schema wiki
......................................................................
Register NS_SCHEMA early if running on schema wiki
The point at which $wgExtensionFunctions are executed is too late for
registering additional namespaces. Defering the registration of the namespace
until then can lead to unpredictable results, as documented in bug 45031. The
solution is to register the namespace early by binding the CanonicalNamespaces
hook handler at file scope and checking there if the wiki should activate the
extra namespace or not. Namespace permissions and content handlers can be
configured at unconditionally at file level since they do not require the
namespace to actually be created.
Bug: 45031
Change-Id: Ide5f0920632b758e769c0b6f32d8231eeaf7a1d4
---
M EventLogging.php
M includes/JsonSchemaHooks.php
2 files changed, 14 insertions(+), 27 deletions(-)
Approvals:
Yuvipanda: Looks good to me, approved
jenkins-bot: Verified
diff --git a/EventLogging.php b/EventLogging.php
index 23f1c4d..2e0741d 100644
--- a/EventLogging.php
+++ b/EventLogging.php
@@ -35,6 +35,17 @@
define( 'NS_SCHEMA', 470 );
define( 'NS_SCHEMA_TALK', 471 );
+$wgHooks[ 'CanonicalNamespaces' ][] = function ( &$namespaces ) {
+ global $wgDBname, $wgEventLoggingDBname;
+ if ( $wgEventLoggingDBname === $wgDBname ) {
+ $namespaces[ NS_SCHEMA ] = 'Schema';
+ $namespaces[ NS_SCHEMA_TALK ] = 'Schema_talk';
+ }
+};
+$wgContentHandlers[ 'JsonSchema' ] = 'JsonSchemaContentHandler';
+$wgNamespaceContentModels[ NS_SCHEMA ] = 'JsonSchema';
+$wgNamespaceProtection[ NS_SCHEMA ] = array( 'autoconfirmed' );
+
// Configuration
diff --git a/includes/JsonSchemaHooks.php b/includes/JsonSchemaHooks.php
index 89ce301..e9d8ad3 100644
--- a/includes/JsonSchemaHooks.php
+++ b/includes/JsonSchemaHooks.php
@@ -12,27 +12,20 @@
class JsonSchemaHooks {
/**
- * Registers hook and content handlers if the JSON Schema
- * namespace is enabled for this site.
+ * Registers API module and hooks which should only run if the JSON
+ * Schema namespace is enabled for this wiki.
* @return bool: Whether hooks and handler were registered.
*/
static function registerHandlers() {
- global $wgAPIModules, $wgHooks, $wgContentHandlers,
- $wgEventLoggingDBname, $wgDBname;
+ global $wgAPIModules, $wgHooks, $wgEventLoggingDBname,
$wgDBname;
if ( $wgEventLoggingDBname === $wgDBname ) {
- $wgContentHandlers[ 'JsonSchema' ] =
'JsonSchemaContentHandler';
-
$wgHooks[ 'BeforePageDisplay' ][] =
'JsonSchemaHooks::onBeforePageDisplay';
- $wgHooks[ 'CanonicalNamespaces' ][] =
'JsonSchemaHooks::onCanonicalNamespaces';
$wgHooks[ 'EditFilterMerged' ][] =
'JsonSchemaHooks::onEditFilterMerged';
$wgHooks[ 'CodeEditorGetPageLanguage' ][] =
'JsonSchemaHooks::onCodeEditorGetPageLanguage';
-
$wgAPIModules[ 'jsonschema' ] = 'ApiJsonSchema';
-
return true;
}
-
return false;
}
@@ -47,23 +40,6 @@
if ( $title->inNamespace( NS_SCHEMA ) ) {
$lang = 'json';
}
- return true;
- }
-
- /**
- * Registers Schema namespaces and assign edit rights.
- * @param array &$namespaces Mapping of numbers to namespace names.
- * @return bool
- */
- static function onCanonicalNamespaces( array &$namespaces ) {
- global $wgNamespaceContentModels, $wgNamespaceProtection;
-
- $namespaces[ NS_SCHEMA ] = 'Schema';
- $namespaces[ NS_SCHEMA_TALK ] = 'Schema_talk';
-
- $wgNamespaceProtection[ NS_SCHEMA ] = array( 'autoconfirmed' );
- $wgNamespaceContentModels[ NS_SCHEMA ] = 'JsonSchema';
-
return true;
}
--
To view, visit https://gerrit.wikimedia.org/r/76326
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ide5f0920632b758e769c0b6f32d8231eeaf7a1d4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/EventLogging
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: Spage <[email protected]>
Gerrit-Reviewer: Yuvipanda <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits