r44441 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44440‎ | r44441 | r44442 >
Date:01:23, 11 December 2008
Author:demon
Status:deferred
Tags:
Comment:
Add Interlanguage extension (http://www.mediawiki.org/wiki/Extension:Interlanguage) to source control because Nikola asked me nicely :)
Modified paths:
  • /trunk/extensions/Interlanguage (added) (history)
  • /trunk/extensions/Interlanguage/Interlanguage.i18n.php (added) (history)
  • /trunk/extensions/Interlanguage/Interlanguage.php (added) (history)

Diff [purge]

Index: trunk/extensions/Interlanguage/Interlanguage.i18n.php
@@ -0,0 +1,12 @@
 2+<?php
 3+/**
 4+ * Internationalisation file for Interlanguage extension.
 5+ *
 6+ * @addtogroup Extensions
 7+ */
 8+
 9+$messages = array();
 10+
 11+$messages['en'] = array(
 12+ 'interlanguage-desc' => 'Grabs interlanguage links from another wiki',
 13+);
Index: trunk/extensions/Interlanguage/Interlanguage.php
@@ -0,0 +1,209 @@
 2+<?php
 3+# MediaWiki Interlanguage extension v1.1
 4+#
 5+# Copyright � 2008 Nikola Smolenski <smolensk@eunet.yu>
 6+#
 7+# This program is free software; you can redistribute it and/or modify
 8+# it under the terms of the GNU General Public License as published by
 9+# the Free Software Foundation; either version 2 of the License, or
 10+# (at your option) any later version.
 11+#
 12+# This program is distributed in the hope that it will be useful,
 13+# but WITHOUT ANY WARRANTY; without even the implied warranty of
 14+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 15+# GNU General Public License for more details.
 16+#
 17+# You should have received a copy of the GNU General Public License
 18+# along with this program; if not, write to the Free Software
 19+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 20+#
 21+# For more information see
 22+# http://www.mediawiki.org/wiki/Extension:Interlanguage
 23+
 24+$wgExtensionFunctions[]="wfInterlanguageExtension";
 25+$wgHooks['LanguageGetMagic'][] = 'wfInterlanguageExtensionMagic';
 26+$wgExtensionCredits['parserhook'][] = array(
 27+ 'name' => 'Interlanguage',
 28+ 'author' => 'Nikola Smolenski',
 29+ 'url' => 'http://www.mediawiki.org/wiki/Extension:Interlanguage',
 30+ 'version' => '1.1',//preg_replace('/^.* (\d\d\d\d-\d\d-\d\d) .*$/', '\1', '$LastChangedDate$'), #just the date of the last change
 31+ 'description' => 'Grabs interlanguage links from another wiki',
 32+ 'descriptionmsg' => 'interlanguage-desc',
 33+);
 34+
 35+function wfInterlanguageExtension() {
 36+ global $wgParser;
 37+ $wgParser->setFunctionHook( 'interlanguage', 'InterlanguageExtension', SFH_NO_HASH );
 38+}
 39+
 40+function wfInterlanguageExtensionMagic( &$magicWords, $langCode ) {
 41+ $magicWords['interlanguage'] = array(0, 'interlanguage');
 42+ return true;
 43+}
 44+
 45+function InterlanguageExtension( &$parser, $param) {
 46+ global
 47+ $wgInterlanguageExtensionApiUrl,
 48+ $wgInterlanguageExtensionSort,
 49+ $wgInterlanguageExtensionPrefix,
 50+ $wgInterlanguageExtensionInterwiki,
 51+ $wgLanguageCode,
 52+ $wgTitle;
 53+
 54+ if(isset($wgInterlanguageExtensionPrefix)) {
 55+ $param = "$wgInterlanguageExtensionPrefix$param";
 56+ }
 57+
 58+ $res = false;
 59+ if($a = Http::get("$wgInterlanguageExtensionApiUrl?action=query&prop=langlinks&lllimit=500&format=php&redirects&titles=".strtr($param,' ','_'))) {
 60+
 61+ $a = @unserialize($a);
 62+ if(isset($a['query']['pages']) && is_array($a['query']['pages'])) {
 63+ $a = array_shift($a['query']['pages']);
 64+
 65+ if(isset($a['missing'])) {
 66+ // There is no such article on the central wiki
 67+ $linker = new Linker();
 68+ $res=array( $linker->makeBrokenLink( $wgInterlanguageExtensionInterwiki . strtr($param,'_',' ') ), 'noparse' => true, 'isHTML' => true);
 69+
 70+ } else {
 71+ if(isset($a['langlinks'])) {
 72+ $a = $a['langlinks'];
 73+ if(is_array($a)) {
 74+ $res = true;
 75+ }
 76+ } else {
 77+ // There are no links in the central wiki article
 78+ $res = '';
 79+ }
 80+ }
 81+ }
 82+ }
 83+
 84+ if($res === false) {
 85+ // An API error has occured; preserve the links that are in the article
 86+ $dbr = wfGetDB( DB_SLAVE );
 87+ $res = $dbr->select( 'langlinks', array( 'll_lang', 'll_title' ), array( 'll_from' => $wgTitle->mArticleID), __FUNCTION__);
 88+ $a = array();
 89+ while ( $row = $dbr->fetchObject( $res ) ) {
 90+ $a[] = array( 'lang' => $row->ll_lang, '*' => $row->ll_title );
 91+ }
 92+ $dbr->freeResult( $res );
 93+ $res = true;
 94+ }
 95+
 96+ if($res === true) {
 97+ // Sort links
 98+ switch($wgInterlanguageExtensionSort) {
 99+ case 'code':
 100+ usort($a, 'InterlanguageExtensionCompareCode');
 101+ break;
 102+ case 'alphabetic':
 103+ usort($a, 'InterlanguageExtensionCompareAlphabetic');
 104+ break;
 105+ case 'alphabetic_revised':
 106+ usort($a, 'InterlanguageExtensionCompareAlphabeticRevised');
 107+ break;
 108+ }
 109+
 110+ // Convert links to wikitext
 111+ $res = '';
 112+ foreach($a as $v) {
 113+ if($v['lang'] != $wgLanguageCode) {
 114+ $res .= "[[".$v['lang'].':'.$v['*']."]]";
 115+ }
 116+ }
 117+ }
 118+
 119+ return $res;
 120+}
 121+
 122+function InterlanguageExtensionCompareCode($a, $b) {
 123+ return strcmp($a['lang'], $b['lang']);
 124+}
 125+
 126+function InterlanguageExtensionCompareAlphabetic($a, $b) {
 127+ global $wgInterlanguageExtensionSortPrepend;
 128+//http://meta.wikimedia.org/w/index.php?title=Interwiki_sorting_order&oldid=1156923#By_order_of_alphabet.2C_based_on_local_language
 129+ static $order = array(
 130+ 'aa', 'af', 'ak', 'als', 'am', 'ang', 'ab', 'ar', 'an', 'arc',
 131+ 'roa-rup', 'frp', 'as', 'ast', 'gn', 'av', 'ay', 'az', 'bm', 'bn',
 132+ 'zh-min-nan', 'map-bms', 'ba', 'be', 'be-x-old', 'bh', 'bcl', 'bi',
 133+ 'bar', 'bo', 'bs', 'br', 'bg', 'bxr', 'ca', 'cv', 'ceb', 'cs', 'ch',
 134+ 'ny', 'sn', 'tum', 'cho', 'co', 'za', 'cy', 'da', 'pdc', 'de', 'dv',
 135+ 'nv', 'dsb', 'dz', 'mh', 'et', 'el', 'eml', 'en', 'myv', 'es', 'eo',
 136+ 'ext', 'eu', 'ee', 'fa', 'fo', 'fr', 'fy', 'ff', 'fur', 'ga', 'gv',
 137+ 'gd', 'gl', 'gan', 'ki', 'glk', 'gu', 'got', 'zh-classical', 'hak',
 138+ 'xal', 'ko', 'ha', 'haw', 'hy', 'hi', 'ho', 'hsb', 'hr', 'io', 'ig',
 139+ 'ilo', 'bpy', 'id', 'ia', 'ie', 'iu', 'ik', 'os', 'xh', 'zu', 'is',
 140+ 'it', 'he', 'jv', 'kl', 'pam', 'kn', 'kr', 'ka', 'ks', 'csb', 'kk',
 141+ 'kw', 'rw', 'ky', 'rn', 'sw', 'kv', 'kg', 'ht', 'kj', 'ku', 'lad',
 142+ 'lbe', 'lo', 'la', 'lv', 'lb', 'lt', 'lij', 'li', 'ln', 'jbo', 'lg',
 143+ 'lmo', 'hu', 'mk', 'mg', 'ml', 'mt', 'mi', 'mr', 'mzn', 'ms', 'cdo',
 144+ 'mdf', 'mo', 'mn', 'mus', 'my', 'nah', 'na', 'fj', 'nl', 'nds-nl',
 145+ 'cr', 'ne', 'new', 'ja', 'nap', 'ce', 'pih', 'no', 'nn', 'nrm',
 146+ 'nov', 'oc', 'or', 'om', 'ng', 'hz', 'ug', 'uz', 'pa', 'pi', 'pag',
 147+ 'pap', 'ps', 'km', 'pms', 'nds', 'pl', 'pt', 'kaa', 'crh', 'ty',
 148+ 'ksh', 'ro', 'rmy', 'rm', 'qu', 'ru', 'sah', 'se', 'sm', 'sa', 'sg',
 149+ 'sc', 'sco', 'stq', 'st', 'tn', 'sq', 'scn', 'si', 'simple', 'sd',
 150+ 'ss', 'sk', 'cu', 'sl', 'szl', 'so', 'sr', 'sh', 'su', 'fi', 'sv',
 151+ 'tl', 'ta', 'kab', 'roa-tara', 'tt', 'te', 'tet', 'th', 'vi', 'ti',
 152+ 'tg', 'tpi', 'to', 'chr', 'chy', 've', 'tr', 'tk', 'tw', 'udm',
 153+ 'bug', 'uk', 'ur', 'vec', 'vo', 'fiu-vro', 'wa', 'vls', 'war', 'wo',
 154+ 'wuu', 'ts', 'ii', 'yi', 'yo', 'zh-yue', 'cbk-zam', 'diq', 'zea',
 155+ 'bat-smg', 'zh'
 156+ );
 157+
 158+ if(isset($wgInterlanguageExtensionSortPrepend) && is_array($wgInterlanguageExtensionSortPrepend)) {
 159+ $order = array_merge($wgInterlanguageExtensionSortPrepend, $order);
 160+ unset($wgInterlanguageExtensionSortPrepend);
 161+ }
 162+
 163+ $a=array_search($a['lang'], $order);
 164+ $b=array_search($b['lang'], $order);
 165+
 166+ return ($a>$b)?1:(($a<$b)?-1:0);
 167+}
 168+
 169+function InterlanguageExtensionCompareAlphabeticRevised($a, $b) {
 170+ global $wgInterlanguageExtensionSortPrepend;
 171+//From http://meta.wikimedia.org/w/index.php?title=Interwiki_sorting_order&oldid=1156923#By_order_of_alphabet.2C_based_on_local_language_.28by_first_word.29
 172+ static $order = array(
 173+ 'aa', 'af', 'ak', 'als', 'am', 'ang', 'ab',
 174+ 'ar', 'an', 'arc', 'roa-rup', 'frp', 'as', 'ast', 'gn', 'av', 'ay',
 175+ 'az', 'id', 'ms', 'bm', 'bn', 'zh-min-nan', 'map-bms', 'jv', 'su',
 176+ 'ba', 'be', 'be-x-old', 'bh', 'bcl', 'bi', 'bar', 'bo', 'bs', 'br',
 177+ 'bug', 'bg', 'bxr', 'ca', 'ceb', 'cv', 'cs', 'ch', 'cbk-zam', 'ny',
 178+ 'sn', 'tum', 'cho', 'co', 'za', 'cy', 'da', 'pdc', 'de', 'dv', 'nv',
 179+ 'dsb', 'dz', 'mh', 'et', 'na', 'el', 'eml', 'en', 'myv', 'es', 'eo',
 180+ 'ext', 'eu', 'ee', 'to', 'fa', 'fo', 'fr', 'fy', 'ff', 'fur', 'ga',
 181+ 'gv', 'sm', 'gd', 'gl', 'gan', 'ki', 'glk', 'gu', 'got', 'hak',
 182+ 'ko', 'ha', 'haw', 'hy', 'hi', 'ho', 'hsb', 'hr', 'io', 'ig', 'ilo',
 183+ 'bpy', 'ia', 'ie', 'iu', 'ik', 'os', 'xh', 'zu', 'is', 'it', 'he',
 184+ 'kl', 'xal', 'kn', 'kr', 'pam', 'ka', 'ks', 'csb', 'kk', 'kw', 'rw',
 185+ 'ky', 'rn', 'sw', 'kv', 'kg', 'ht', 'ku', 'kj', 'lad', 'lbe', 'lo',
 186+ 'la', 'lv', 'lb', 'lt', 'lij', 'li', 'ln', 'jbo', 'lg', 'lmo', 'hu',
 187+ 'mk', 'mg', 'ml', 'mt', 'zh-classical', 'mi', 'mr', 'mzn', 'cdo',
 188+ 'mdf', 'mo', 'mn', 'mus', 'my', 'nah', 'fj', 'nl', 'nds-nl', 'cr',
 189+ 'ne', 'new', 'ja', 'nap', 'ce', 'pih', 'no', 'nn', 'nrm', 'nov',
 190+ 'oc', 'or', 'om', 'ng', 'hz', 'uz', 'pa', 'pi', 'pag', 'pap', 'ps',
 191+ 'km', 'pms', 'nds', 'pl', 'pt', 'kaa', 'crh', 'ty', 'ksh', 'ro',
 192+ 'rmy', 'rm', 'qu', 'ru', 'se', 'sa', 'sg', 'sc', 'sah', 'sco',
 193+ 'stq', 'st', 'tn', 'sq', 'scn', 'si', 'simple', 'sd', 'ss', 'sk',
 194+ 'sl', 'cu', 'szl', 'so', 'sr', 'sh', 'fi', 'sv', 'tl', 'ta', 'kab',
 195+ 'roa-tara', 'tt', 'te', 'tet', 'th', 'vi', 'ti', 'tg', 'tpi', 'chr',
 196+ 'chy', 've', 'tr', 'tk', 'tw', 'udm', 'uk', 'ur', 'ug', 'vec', 'vo',
 197+ 'fiu-vro', 'wa', 'vls', 'war', 'wo', 'wuu', 'ts', 'ii', 'yi', 'yo',
 198+ 'zh-yue', 'diq', 'zea', 'bat-smg', 'zh', 'zh-tw', 'zh-cn',
 199+ );
 200+
 201+ if(isset($wgInterlanguageExtensionSortPrepend) && is_array($wgInterlanguageExtensionSortPrepend)) {
 202+ $order = array_merge($wgInterlanguageExtensionSortPrepend, $order);
 203+ unset($wgInterlanguageExtensionSortPrepend);
 204+ }
 205+
 206+ $a=array_search($a['lang'], $order);
 207+ $b=array_search($b['lang'], $order);
 208+
 209+ return ($a>$b)?1:(($a<$b)?-1:0);
 210+}

Status & tagging log