jenkins-bot has submitted this change and it was merged.
Change subject: Register NS_ZERO early if running on configuration wiki
......................................................................
Register NS_ZERO early if running on configuration 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: I2fb2bcaa2108dd40a5374505ee5a9d8845e6e1d8
---
M ZeroRatedMobileAccess.php
M includes/ConfigPageHooks.php
2 files changed, 23 insertions(+), 28 deletions(-)
Approvals:
Yurik: Looks good to me, approved
jenkins-bot: Verified
diff --git a/ZeroRatedMobileAccess.php b/ZeroRatedMobileAccess.php
index 208877f..bc9b8fa 100644
--- a/ZeroRatedMobileAccess.php
+++ b/ZeroRatedMobileAccess.php
@@ -89,16 +89,34 @@
$wgHooks['MinervaPreRender'][] = $ns .
'PageRenderingHooks::onMinervaPreRender';
$wgHooks['GetMobileNotice'][] = $ns . 'PageRenderingHooks::onGetMobileNotice';
-// Registers hook and content handlers for JSON Zero config pages iff
-// running on the MediaWiki instance housing the zero configs (i.e. meta).
-// Use function to avoid loading ConfigPageHooks class in most wikis
+define( 'NS_ZERO', 480 );
+define( 'NS_ZERO_TALK', 481 );
+
+// Only register NS_ZERO if running on the MediaWiki instance which
+// houses the Zero configs (i.e., meta).
+$wgHooks['CanonicalNamespaces'][] = function( array &$namespaces ) {
+ global $wgZeroRatedMobileAccessEnableZeroConfigPages;
+ if ( $wgZeroRatedMobileAccessEnableZeroConfigPages === true ) {
+ $namespaces[NS_ZERO] = 'Zero';
+ $namespaces[NS_ZERO_TALK] = 'Zero_talk';
+ }
+ return true;
+};
+
+// Only users with the 'zero-edit' right may edit NS_ZERO pages.
+// Wikimedia's CommonSettings.php assigns this right to a 'zeroadmin' group.
+$wgNamespaceProtection[NS_ZERO] = array( 'zero-edit' );
+
+// Zero configuration pages use a special, JSON-based content model.
+$wgNamespaceContentModels[NS_ZERO] = 'JsonZeroConfig';
+$wgContentHandlers['JsonZeroConfig'] =
'Extensions\ZeroRatedMobileAccess\ZeroConfigContentHandler';
+
+// Registers hooks which are only required on the configuration wiki.
$wgExtensionFunctions[] = function() {
global $wgHooks, $wgContentHandlers,
$wgZeroRatedMobileAccessEnableZeroConfigPages;
if ( $wgZeroRatedMobileAccessEnableZeroConfigPages === true ) {
$hook = 'Extensions\ZeroRatedMobileAccess\ConfigPageHooks::';
-
- $wgContentHandlers['JsonZeroConfig'] =
'Extensions\ZeroRatedMobileAccess\ZeroConfigContentHandler';
$wgHooks['BeforePageDisplay'][] = $hook . 'onBeforePageDisplay';
$wgHooks['CanonicalNamespaces'][] = $hook .
'onCanonicalNamespaces';
diff --git a/includes/ConfigPageHooks.php b/includes/ConfigPageHooks.php
index 249a133..116272c 100644
--- a/includes/ConfigPageHooks.php
+++ b/includes/ConfigPageHooks.php
@@ -2,9 +2,6 @@
namespace Extensions\ZeroRatedMobileAccess;
-// Namespaces
-define( 'NS_ZERO', 480 );
-define( 'NS_ZERO_TALK', 481 );
/**
* Configuration page hook handlers for ZeroRatedMobileAccess extension.
@@ -25,26 +22,6 @@
if ( $title->inNamespace( NS_ZERO ) ) {
$lang = 'json';
}
- return true;
- }
-
- /**
- * Registers Zero namespaces and assign edit rights.
- * @param array &$namespaces Mapping of numbers to namespace names.
- * @return bool
- */
- static function onCanonicalNamespaces( array &$namespaces ) {
- global $wgNamespaceContentModels, $wgNamespaceProtection,
$wgGroupPermissions;
-
- $namespaces[NS_ZERO] = 'Zero';
- $namespaces[NS_ZERO_TALK] = 'Zero_talk';
-
- $wgNamespaceContentModels[NS_ZERO] = 'JsonZeroConfig';
-
- // Restrict Zero-namespace to be editable only by the special
"zeroadmin" group
- $wgNamespaceProtection[NS_ZERO] = array( 'zero-edit' );
- $wgGroupPermissions['zeroadmin']['zero-edit'] = true;
-
return true;
}
--
To view, visit https://gerrit.wikimedia.org/r/76325
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I2fb2bcaa2108dd40a5374505ee5a9d8845e6e1d8
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/ZeroRatedMobileAccess
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
Gerrit-Reviewer: Dr0ptp4kt <[email protected]>
Gerrit-Reviewer: Ori.livneh <[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