summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'GentooToolbox')
-rw-r--r--GentooToolbox/GentooToolbox.php46
-rw-r--r--GentooToolbox/properties/TranslationProperties.body.php54
-rw-r--r--GentooToolbox/properties/TranslationProperties.i18n.php14
3 files changed, 114 insertions, 0 deletions
diff --git a/GentooToolbox/GentooToolbox.php b/GentooToolbox/GentooToolbox.php
new file mode 100644
index 00000000..a5da0537
--- /dev/null
+++ b/GentooToolbox/GentooToolbox.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * GentooToolbox
+ *
+ * @ingroup Extensions
+ * @author Alex Legler <a3li@gentoo.org>
+ * @version 1.0
+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
+ */
+
+if (!defined('MEDIAWIKI')) {
+ echo "This is an extension to the MediaWiki package and cannot be run standalone.\n";
+ die(-1);
+}
+
+if (!defined('SMW_VERSION')) {
+ echo "Semantic MediaWiki not found.\n";
+ die(-1);
+}
+
+define('GTBX_VERSION', '0.0.1');
+
+$wgExtensionCredits['semantic'][] = array(
+ 'path' => __FILE__,
+ 'name' => 'Gentoo Toolbox: Translation properties',
+ 'version' => GTBX_VERSION,
+ 'author' => 'Alex Legler',
+ 'url' => 'https://wiki.gentoo.org/',
+);
+
+$wgExtensionCredits['other'][] = array(
+ 'path' => __FILE__,
+ 'name' => 'Gentoo Toolbox',
+ 'version' => GTBX_VERSION,
+ 'author' => 'Alex Legler',
+ 'url' => 'https://wiki.gentoo.org/',
+);
+
+$dir = dirname(__FILE__) . '/';
+
+// Translation Properties
+$wgExtensionMessagesFiles['GTBX_TranslationProperties'] = $dir . '/properties/TranslationProperties.i18n.php';
+$wgAutoloadClasses['GTBXTranslationProperties'] = $dir . '/properties/TranslationProperties.body.php';
+
+$wgHooks['smwInitProperties'][] = 'GTBXTranslationProperties::setupProperties';
+$wgHooks['SMWStore::updateDataBefore'][] = 'GTBXTranslationProperties::updateDataBefore';
diff --git a/GentooToolbox/properties/TranslationProperties.body.php b/GentooToolbox/properties/TranslationProperties.body.php
new file mode 100644
index 00000000..517059f3
--- /dev/null
+++ b/GentooToolbox/properties/TranslationProperties.body.php
@@ -0,0 +1,54 @@
+<?php
+/**
+ * GentooToolbox
+ *
+ * @ingroup Extensions
+ * @author Alex Legler <a3li@gentoo.org>
+ * @version 1.0
+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
+ */
+
+class GTBXTranslationProperties {
+
+ public static function setupProperties() {
+ SMWDIProperty::registerProperty('___LANG', '_str', wfMsgForContent('gtbx-prop-lang'));
+ SMWDIProperty::registerPropertyAlias('___LANG', 'Language');
+
+ SMWDIProperty::registerProperty('___TRANS', '_boo', wfMsgForContent('gtbx-prop-trans'));
+ SMWDIProperty::registerPropertyAlias('___TRANS', 'Is Translation Page');
+
+ return true;
+ }
+
+ public function updateDataBefore($store, $data) {
+ $subject = $data->getSubject();
+ $title = Title::makeTitle($subject->getNamespace(), $subject->getDBKey());
+ $wikipage = WikiPage::factory($title);
+
+ if (is_null($title) || is_null($wikipage)) {
+ return true;
+ }
+
+ // Property 1: Is translation page
+ $property = new SMWDIProperty('___TRANS');
+ $is_translation_page = !(TranslatablePage::isTranslationPage($title) === false);
+ $data_item = new SMWDIBoolean($is_translation_page);
+
+ $data->addPropertyObjectValue($property, $data_item);
+
+ // Property 2: Language?
+ $property = new SMWDIProperty('___LANG');
+ global $wgLanguageCode;
+ $language_code = $wgLanguageCode;
+
+ if ($is_translation_page) {
+ list( , $code ) = TranslateUtils::figureMessage( $title->getText() );
+ $language_code = $code;
+ }
+
+ $data_item = new SMWDIString($language_code);
+
+ $data->addPropertyObjectValue($property, $data_item);
+
+ }
+}
diff --git a/GentooToolbox/properties/TranslationProperties.i18n.php b/GentooToolbox/properties/TranslationProperties.i18n.php
new file mode 100644
index 00000000..ae8a4dfb
--- /dev/null
+++ b/GentooToolbox/properties/TranslationProperties.i18n.php
@@ -0,0 +1,14 @@
+<?php
+/**
+ * GentooToolbox
+ *
+ * @ingroup Extensions
+ * @author Alex Legler <a3li@gentoo.org>
+ * @version 1.0
+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
+ */
+
+$messages['en'] = array(
+ 'gtbx-prop-lang' => 'Language',
+ 'gtbx-prop-trans' => 'Is Translation Page',
+);