jenkins-bot has submitted this change and it was merged.
Change subject: Initial commit of code
......................................................................
Initial commit of code
Change-Id: I1dcafde55b9d84ddd0acd88c824433c569d58a66
---
A CommonMessages.body.php
A CommonMessages.php
A export/.gitignore
A export/README
A exportMessages.php
A i18n/en.json
A i18n/qqq.json
7 files changed, 168 insertions(+), 0 deletions(-)
Approvals:
Legoktm: Looks good to me, approved
Siebrand: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/CommonMessages.body.php b/CommonMessages.body.php
new file mode 100644
index 0000000..06d5ca6
--- /dev/null
+++ b/CommonMessages.body.php
@@ -0,0 +1,44 @@
+<?php
+
+class CommonMessages {
+
+ /** @var array $keys */
+ protected $keys;
+
+ public static function singleton() {
+ static $self = null;
+ if ( !$self ) {
+ $self = new self;
+ }
+ return $self;
+ }
+
+ public function transformKey( $key ) {
+ global $wgCommonMessagesPrefix;
+ return $wgCommonMessagesPrefix . '-' . $key;
+ }
+
+ /**
+ * @param string $key non-transformed key
+ * @return bool
+ */
+ public function isKeyRegistered( $key ) {
+ if ( $this->keys === null ) {
+ // Load the JSON file.
+ wfSuppressWarnings();
+ $file = file_get_contents( __DIR__ . '/export/en.json'
);
+ wfRestoreWarnings();
+ if ( !$file ) {
+ $this->keys = array();
+ return false;
+ }
+ $json = FormatJson::decode( $file, true );
+ if ( !$json ) {
+ $this->keys = array();
+ return false;
+ }
+ $this->keys = array_keys( $json );
+ }
+ return in_array( $this->transformKey( $key ), $this->keys );
+ }
+}
\ No newline at end of file
diff --git a/CommonMessages.php b/CommonMessages.php
new file mode 100644
index 0000000..af29d70
--- /dev/null
+++ b/CommonMessages.php
@@ -0,0 +1,60 @@
+<?php
+
+/**
+ * CommonMessages extension
+ *
+ * Allows a wikifarm to have custom
+ * message overrides easilly
+ * Mainly designed for ShoutWiki's setup,
+ * but can be used for any farm.
+ *
+ * @requires MediaWiki 1.23
+ * @license WTFPL
+ * @author Kunal Mehta <[email protected]>
+ */
+
+if ( !defined( 'MEDIAWIKI' ) ) {
+ exit();
+}
+
+$wgExtensionCredits['other'][] = array(
+ 'path' => __FILE__,
+ 'name' => 'CommonMessages',
+ 'author' => 'Kunal Mehta',
+ 'descriptionmsg' => 'commonmessages-desc',
+ 'version' => '0.0.1',
+);
+
+/**
+ * Prefix of messages when exporting.
+ * Must be configured.
+ */
+$wgCommonMessagesPrefix = '';
+
+/**
+ * Directory of where to export messages to
+ * and where to read from
+ * Must already exist
+ */
+$wgCommonMessagesExportDir = __DIR__ . '/export';
+
+$wgExtensionFunctions[] = function() {
+ global $wgCommonMessagesExportDir;
+ if ( file_exists( $wgCommonMessagesExportDir . '/en.json' ) ) {
+ // If an export has happened, load it
+ $wgMessagesDirs['CommonMessagesExport'] =
$wgCommonMessagesExportDir;
+ }
+};
+
+
+$wgMessagesDirs['CommonMessages'] = __DIR__ . '/i18n';
+$wgAutoloadClasses['CommonMessages'] = __DIR__ . '/CommonMessages.body.php';
+
+$wgHooks['MessageCache::get'][] = function( &$key ) {
+ $commons = CommonMessages::singleton();
+ if ( $commons->isKeyRegistered( $key ) ) {
+ $key = $commons->transformKey( $key );
+ }
+
+ return true;
+};
diff --git a/export/.gitignore b/export/.gitignore
new file mode 100644
index 0000000..a6c57f5
--- /dev/null
+++ b/export/.gitignore
@@ -0,0 +1 @@
+*.json
diff --git a/export/README b/export/README
new file mode 100644
index 0000000..f60e76e
--- /dev/null
+++ b/export/README
@@ -0,0 +1 @@
+This directory will be filled after using the exportMessages.php script.
diff --git a/exportMessages.php b/exportMessages.php
new file mode 100644
index 0000000..68d40d2
--- /dev/null
+++ b/exportMessages.php
@@ -0,0 +1,46 @@
+<?php
+
+$IP = getenv( 'MW_INSTALL_PATH' );
+if ( $IP === false ) {
+ $IP = __DIR__ . '/../..';
+}
+
+// Require base maintenance class
+require_once( "$IP/maintenance/Maintenance.php" );
+
+class ExportMessages extends Maintenance {
+
+ public function execute() {
+ global $wgCommonMessagesExportDir;
+ $commons = CommonMessages::singleton();
+ $dbr = wfGetDB( DB_SLAVE );
+ // @todo Can we make this less memory intensive?
+ $rows = $dbr->select(
+ 'page',
+ array( 'page_namespace', 'page_title', 'page_id',
'page_latest' ),
+ array( 'page_namespace' => NS_MEDIAWIKI ),
+ __METHOD__
+ );
+ $messages = array();
+ foreach( $rows as $row ) {
+ $title = Title::newFromRow( $row );
+ $exp = explode( '/', $title->getPrefixedText() );
+ $lang = $exp[1];
+ if ( !Language::isValidCode( $lang ) ) {
+ wfDebugLog( 'MessageCommons', 'Found invalid
page: ' . $title->getFullText() );
+ continue;
+ }
+ $key = $commons->transformKey( strtolower(
$title->getPrefixedText() ) );
+ $messages[$lang][$key]
+ = Revision::newFromTitle( $title )->getContent(
Revision::RAW )->getNativeData();
+ }
+ // Now export.
+ foreach ( $messages as $lang => $data ) {
+ $json = FormatJson::encode( $data, true );
+ file_put_contents(
"$wgCommonMessagesExportDir/$lang.json", $json );
+ }
+ }
+}
+
+$maintClass = 'ExportMessages';
+require_once( RUN_MAINTENANCE_IF_MAIN );
diff --git a/i18n/en.json b/i18n/en.json
new file mode 100644
index 0000000..15553c8
--- /dev/null
+++ b/i18n/en.json
@@ -0,0 +1,8 @@
+{
+ "@metadata": {
+ "authors": [
+ "Kunal Mehta"
+ ]
+ },
+ "commonmessages-desc": "Allows a wikifarm to override messages from
another wiki"
+}
diff --git a/i18n/qqq.json b/i18n/qqq.json
new file mode 100644
index 0000000..1646a03
--- /dev/null
+++ b/i18n/qqq.json
@@ -0,0 +1,8 @@
+{
+ "@metadata": {
+ "authors": [
+ "Kunal Mehta"
+ ]
+ },
+ "commonmessages-desc":
"{{desc|name=CommonMessages|url=https://www.mediawiki.org/wiki/Extension:CommonMessages}}"
+}
--
To view, visit https://gerrit.wikimedia.org/r/115390
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1dcafde55b9d84ddd0acd88c824433c569d58a66
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/CommonMessages
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: Jack Phoenix <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits