Index: trunk/extensions/Interlanguage/Interlanguage.i18n.php |
— | — | @@ -12,6 +12,7 @@ |
13 | 13 | |
14 | 14 | $messages['en'] = array( |
15 | 15 | 'interlanguage-desc' => 'Grabs interlanguage links from another wiki', |
| 16 | + 'interlanguage-pagelinksexplanation' => 'Pages with interlanguage links:', |
16 | 17 | ); |
17 | 18 | |
18 | 19 | /** Message documentation (Message documentation) |
Index: trunk/extensions/Interlanguage/Interlanguage.php |
— | — | @@ -1,206 +1,338 @@ |
2 | 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
20 | | -# |
21 | | -# For more information see |
22 | | -# http://www.mediawiki.org/wiki/Extension:Interlanguage |
| 3 | +/** |
| 4 | + * MediaWiki Interlanguage extension v1.3 |
| 5 | + * |
| 6 | + * Copyright © 2008-2010 Nikola Smolenski <smolensk@eunet.rs> and others |
| 7 | + * @version 1.3 |
| 8 | + * |
| 9 | + * This program is free software; you can redistribute it and/or modify |
| 10 | + * it under the terms of the GNU General Public License as published by |
| 11 | + * the Free Software Foundation; either version 2 of the License, or |
| 12 | + * (at your option) any later version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public License |
| 20 | + * along with this program; if not, write to the Free Software |
| 21 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 22 | + * |
| 23 | + * For more information, |
| 24 | + * @see http://www.mediawiki.org/wiki/Extension:Interlanguage |
| 25 | + */ |
23 | 26 | |
24 | 27 | $wgExtensionFunctions[]="wfInterlanguageExtension"; |
25 | 28 | $wgExtensionCredits['parserhook'][] = array( |
26 | | - 'path' => __FILE__, |
27 | | - 'name' => 'Interlanguage', |
28 | | - 'author' => 'Nikola Smolenski', |
29 | | - 'url' => 'http://www.mediawiki.org/wiki/Extension:Interlanguage', |
30 | | - 'version' => '1.2', |
31 | | - 'descriptionmsg' => 'interlanguage-desc', |
| 29 | + 'path' => __FILE__, |
| 30 | + 'name' => 'Interlanguage', |
| 31 | + 'author' => 'Nikola Smolenski', |
| 32 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:Interlanguage', |
| 33 | + 'version' => '1.3', |
| 34 | + 'descriptionmsg' => 'interlanguage-desc', |
32 | 35 | ); |
| 36 | +$wgExtensionMessagesFiles['Interlanguage'] = dirname(__FILE__) . '/Interlanguage.i18n.php'; |
| 37 | +$wgExtensionMessagesFiles['InterlanguageMagic'] = dirname(__FILE__) . '/Interlanguage.i18n.magic.php'; |
33 | 38 | |
34 | 39 | function wfInterlanguageExtension() { |
35 | | - global $wgParser; |
36 | | - $wgParser->setFunctionHook( 'interlanguage', 'InterlanguageExtension', SFH_NO_HASH ); |
| 40 | + global $wgParser, $wgHooks, $wgInterlanguageExtension; |
| 41 | + |
| 42 | + $wgInterlanguageExtension = new InterlanguageExtension(); |
| 43 | + $wgHooks['LanguageGetMagic'][] = array( &$wgInterlanguageExtension, 'onLanguageGetMagic' ); |
| 44 | + $wgHooks['EditPage::showEditForm:fields'][] = array( &$wgInterlanguageExtension, 'pageLinks' ); |
| 45 | + $wgHooks['ArticleSaveComplete'][] = $wgInterlanguageExtension; |
| 46 | + $wgParser->setFunctionHook( 'interlanguage', array( &$wgInterlanguageExtension, 'interlanguage' ), SFH_NO_HASH ); |
37 | 47 | } |
38 | 48 | |
39 | | -function InterlanguageExtension( &$parser, $param) { |
40 | | - global $wgInterlanguageExtensionApiUrl, $wgInterlanguageExtensionSort, |
41 | | - $wgInterlanguageExtensionPrefix, $wgInterlanguageExtensionInterwiki, |
42 | | - $wgLanguageCode, $wgTitle, $wgMemc; |
| 49 | +class InterlanguageExtension { |
| 50 | + var $pageLinks = array(); |
43 | 51 | |
44 | | - if(isset($wgInterlanguageExtensionPrefix)) { |
45 | | - $param = "$wgInterlanguageExtensionPrefix$param"; |
| 52 | + function onLanguageGetMagic( &$magicWords, $langCode ) { |
| 53 | + $magicWords['interlanguage'] = array(0, 'interlanguage'); |
| 54 | + return true; |
46 | 55 | } |
47 | 56 | |
48 | | - $url = $wgInterlanguageExtensionApiUrl . "?action=query&prop=langlinks&" . |
49 | | - "lllimit=500&format=php&redirects&titles=" . strtr( $param, ' ', '_' ); |
50 | | - $key = wfMemcKey( 'Interlanguage', md5( $url ) ); |
51 | | - $res = $wgMemc->get( $key ); |
| 57 | + /** |
| 58 | + * The meat of the extension, the function that handles {{interlanguage:}} magic. |
| 59 | + * |
| 60 | + * @param $parser - standard Parser object. |
| 61 | + * @param $param - parameter passed to {{interlanguage:}}. |
| 62 | + */ |
| 63 | + function interlanguage( &$parser, $param ) { |
| 64 | + global $wgInterlanguageExtensionApiUrl, $wgInterlanguageExtensionSort, |
| 65 | + $wgInterlanguageExtensionPrefix, $wgInterlanguageExtensionInterwiki, |
| 66 | + $wgLanguageCode, $wgTitle, $wgMemc; |
| 67 | + |
| 68 | + if(isset($wgInterlanguageExtensionPrefix)) { |
| 69 | + $param = "$wgInterlanguageExtensionPrefix$param"; |
| 70 | + } |
52 | 71 | |
53 | | - if ( !$res ) { |
54 | | - # be sure to set $res back to bool false, we do a strict compare below |
55 | | - $res = false; |
56 | | - $a = Http::get( $url ); |
57 | | - $a = @unserialize( $a ); |
58 | | - if(isset($a['query']['pages']) && is_array($a['query']['pages'])) { |
59 | | - $a = array_shift($a['query']['pages']); |
| 72 | + //This will later be used by pageLinks() and onArticleSave() |
| 73 | + $this->pageLinks[$param] = true; |
60 | 74 | |
61 | | - if(isset($a['missing'])) { |
62 | | - // There is no such article on the central wiki |
63 | | - $linker = new Linker(); |
64 | | - $res=array( $linker->makeBrokenLink( $wgInterlanguageExtensionInterwiki . strtr($param,'_',' ') ), 'noparse' => true, 'isHTML' => true); |
| 75 | + $url = $wgInterlanguageExtensionApiUrl . "?action=query&prop=langlinks&" . |
| 76 | + "lllimit=500&format=php&redirects&titles=" . urlencode(strtr( $param, ' ', '_' )); |
| 77 | + $key = wfMemcKey( 'Interlanguage', md5( $param ) ); |
| 78 | + $res = $wgMemc->get( $key ); |
65 | 79 | |
66 | | - } else { |
67 | | - if(isset($a['langlinks'])) { |
68 | | - $a = $a['langlinks']; |
69 | | - if(is_array($a)) { |
70 | | - $res = true; |
| 80 | + if ( !$res ) { |
| 81 | + // be sure to set $res back to bool false, we do a strict compare below |
| 82 | + $res = false; |
| 83 | + $a = Http::get( $url ); |
| 84 | + $a = @unserialize( $a ); |
| 85 | + if(isset($a['query']['pages']) && is_array($a['query']['pages'])) { |
| 86 | + $a = array_shift($a['query']['pages']); |
| 87 | + |
| 88 | + if(isset($a['missing'])) { |
| 89 | + // There is no such article on the central wiki |
| 90 | + $linker = new Linker(); |
| 91 | + $res=array( $linker->makeBrokenLink( $wgInterlanguageExtensionInterwiki . strtr($param,'_',' ') ), 'noparse' => true, 'isHTML' => true); |
| 92 | + } else { |
| 93 | + if(isset($a['langlinks'])) { |
| 94 | + $a = $a['langlinks']; |
| 95 | + if(is_array($a)) { |
| 96 | + $res = true; |
| 97 | + } |
| 98 | + } else { |
| 99 | + // There are no links in the central wiki article |
| 100 | + $res = ''; |
71 | 101 | } |
72 | | - } else { |
73 | | - // There are no links in the central wiki article |
74 | | - $res = ''; |
75 | 102 | } |
76 | 103 | } |
77 | 104 | } |
78 | | - } |
| 105 | + |
| 106 | + if($res === false) { |
| 107 | + // An API error has occured; preserve the links that are in the article |
| 108 | + $dbr = wfGetDB( DB_SLAVE ); |
| 109 | + $res = $dbr->select( 'langlinks', array( 'll_lang', 'll_title' ), array( 'll_from' => $wgTitle->mArticleID), __FUNCTION__); |
| 110 | + $a = array(); |
| 111 | + while ( $row = $dbr->fetchObject( $res ) ) { |
| 112 | + $a[] = array( 'lang' => $row->ll_lang, '*' => $row->ll_title ); |
| 113 | + } |
| 114 | + $dbr->freeResult( $res ); |
| 115 | + $res = true; |
| 116 | + } |
| 117 | + |
| 118 | + if($res === true) { |
| 119 | + // Sort links |
| 120 | + switch($wgInterlanguageExtensionSort) { |
| 121 | + case 'code': |
| 122 | + usort($a, 'InterlanguageExtension::compareCode'); |
| 123 | + break; |
| 124 | + case 'alphabetic': |
| 125 | + usort($a, 'InterlanguageExtension::compareAlphabetic'); |
| 126 | + break; |
| 127 | + case 'alphabetic_revised': |
| 128 | + usort($a, 'InterlanguageExtension::compareAlphabeticRevised'); |
| 129 | + break; |
| 130 | + } |
| 131 | + |
| 132 | + // Convert links to wikitext |
| 133 | + $res = ''; |
| 134 | + foreach($a as $v) { |
| 135 | + if($v['lang'] != $wgLanguageCode) { |
| 136 | + $res .= "[[".$v['lang'].':'.$v['*']."]]"; |
| 137 | + } |
| 138 | + } |
| 139 | + } |
79 | 140 | |
80 | | - if($res === false) { |
81 | | - // An API error has occured; preserve the links that are in the article |
82 | | - $dbr = wfGetDB( DB_SLAVE ); |
83 | | - $res = $dbr->select( 'langlinks', array( 'll_lang', 'll_title' ), array( 'll_from' => $wgTitle->mArticleID), __FUNCTION__); |
84 | | - $a = array(); |
85 | | - while ( $row = $dbr->fetchObject( $res ) ) { |
86 | | - $a[] = array( 'lang' => $row->ll_lang, '*' => $row->ll_title ); |
87 | | - } |
88 | | - $dbr->freeResult( $res ); |
89 | | - $res = true; |
| 141 | + // cache the final result so we can skip all of this |
| 142 | + $wgMemc->set( $key, $res, time() + 3600 ); |
| 143 | + return $res; |
90 | 144 | } |
91 | 145 | |
92 | | - if($res === true) { |
93 | | - // Sort links |
94 | | - switch($wgInterlanguageExtensionSort) { |
95 | | - case 'code': |
96 | | - usort($a, 'InterlanguageExtensionCompareCode'); |
97 | | - break; |
98 | | - case 'alphabetic': |
99 | | - usort($a, 'InterlanguageExtensionCompareAlphabetic'); |
100 | | - break; |
101 | | - case 'alphabetic_revised': |
102 | | - usort($a, 'InterlanguageExtensionCompareAlphabeticRevised'); |
103 | | - break; |
| 146 | + /** |
| 147 | + * Displays a list of links to pages on the central wiki below the edit box. |
| 148 | + * |
| 149 | + * @param $editPage - standard EditPage object. |
| 150 | + */ |
| 151 | + function pageLinks( $editPage ) { |
| 152 | + global $wgInterlanguageExtensionInterwiki, $wgMessageCache, $wgTitle; |
| 153 | + |
| 154 | + if( count( $this->pageLinks )) { |
| 155 | + $pagelinks = $this->pageLinks; |
| 156 | + } else { |
| 157 | + $pagelinks = $this->loadPageLinks( $wgTitle->mArticleID ); |
104 | 158 | } |
105 | 159 | |
106 | | - // Convert links to wikitext |
107 | | - $res = ''; |
108 | | - foreach($a as $v) { |
109 | | - if($v['lang'] != $wgLanguageCode) { |
110 | | - $res .= "[[".$v['lang'].':'.$v['*']."]]"; |
| 160 | + if( count( $pagelinks ) ) { |
| 161 | + $linker = new Linker(); $pagelinktexts = array(); |
| 162 | + foreach( $pagelinks as $page => $dummy ) { |
| 163 | + $title = Title::newFromText( $wgInterlanguageExtensionInterwiki . strtr($page,'_',' ') ); |
| 164 | + $link = $linker->link( $title ); |
| 165 | + if( strlen( $link ) ) { |
| 166 | + $pagelinktexts[] = $link; |
| 167 | + } |
111 | 168 | } |
| 169 | + |
| 170 | + $wgMessageCache->loadAllMessages(); //Why? |
| 171 | + $ple = wfMsg( 'interlanguage-pagelinksexplanation' ); |
| 172 | + |
| 173 | + $res = <<<THEEND |
| 174 | +<div class='interlanguageExtensionEditLinks'> |
| 175 | +<div class="mw-interlanguageExtensionEditLinksExplanation"><p>$ple</p></div> |
| 176 | +<ul> |
| 177 | +THEEND; |
| 178 | + foreach($pagelinktexts as $link) { |
| 179 | + $res .= "<li>$link</li>\n"; |
| 180 | + } |
| 181 | + $res .= <<<THEEND |
| 182 | +</ul> |
| 183 | +</div> |
| 184 | +THEEND; |
| 185 | + |
| 186 | + $editPage->editFormTextBottom = $res; |
112 | 187 | } |
| 188 | + |
| 189 | + return true; |
113 | 190 | } |
114 | | - # cache the final result so we can skip all of this |
115 | | - $wgMemc->set( $key, $res, time() + 3600 ); |
116 | | - return $res; |
117 | | -} |
118 | 191 | |
119 | | -function InterlanguageExtensionCompareCode($a, $b) { |
120 | | - return strcmp($a['lang'], $b['lang']); |
121 | | -} |
| 192 | + /** |
| 193 | + * Saves names of pages on the central wiki which are linked to from the saved page |
| 194 | + * by {{interlanguage:}} magic. |
| 195 | + * |
| 196 | + * @param $article - standard Article object. |
| 197 | + */ |
| 198 | + function onArticleSaveComplete( &$article ) { |
| 199 | + $articleid = $article->mTitle->mArticleID; |
| 200 | + $pagelinks = $this->loadPageLinks( $articleid ); |
| 201 | + $dbr = wfGetDB( DB_MASTER ); |
122 | 202 | |
123 | | -function InterlanguageExtensionCompareAlphabetic($a, $b) { |
124 | | - global $wgInterlanguageExtensionSortPrepend; |
125 | | -//http://meta.wikimedia.org/w/index.php?title=Interwiki_sorting_order&oldid=1156923#By_order_of_alphabet.2C_based_on_local_language |
126 | | - static $order = array( |
127 | | - 'aa', 'af', 'ak', 'als', 'am', 'ang', 'ab', 'ar', 'an', 'arc', |
128 | | - 'roa-rup', 'frp', 'as', 'ast', 'gn', 'av', 'ay', 'az', 'bm', 'bn', |
129 | | - 'zh-min-nan', 'map-bms', 'ba', 'be', 'be-x-old', 'bh', 'bcl', 'bi', |
130 | | - 'bar', 'bo', 'bs', 'br', 'bg', 'bxr', 'ca', 'cv', 'ceb', 'cs', 'ch', |
131 | | - 'ny', 'sn', 'tum', 'cho', 'co', 'za', 'cy', 'da', 'pdc', 'de', 'dv', |
132 | | - 'nv', 'dsb', 'dz', 'mh', 'et', 'el', 'eml', 'en', 'myv', 'es', 'eo', |
133 | | - 'ext', 'eu', 'ee', 'fa', 'fo', 'fr', 'fy', 'ff', 'fur', 'ga', 'gv', |
134 | | - 'gd', 'gl', 'gan', 'ki', 'glk', 'gu', 'got', 'zh-classical', 'hak', |
135 | | - 'xal', 'ko', 'ha', 'haw', 'hy', 'hi', 'ho', 'hsb', 'hr', 'io', 'ig', |
136 | | - 'ilo', 'bpy', 'id', 'ia', 'ie', 'iu', 'ik', 'os', 'xh', 'zu', 'is', |
137 | | - 'it', 'he', 'jv', 'kl', 'pam', 'kn', 'kr', 'ka', 'ks', 'csb', 'kk', |
138 | | - 'kw', 'rw', 'ky', 'rn', 'sw', 'kv', 'kg', 'ht', 'kj', 'ku', 'lad', |
139 | | - 'lbe', 'lo', 'la', 'lv', 'lb', 'lt', 'lij', 'li', 'ln', 'jbo', 'lg', |
140 | | - 'lmo', 'hu', 'mk', 'mg', 'ml', 'mt', 'mi', 'mr', 'mzn', 'ms', 'cdo', |
141 | | - 'mdf', 'mo', 'mn', 'mus', 'my', 'nah', 'na', 'fj', 'nl', 'nds-nl', |
142 | | - 'cr', 'ne', 'new', 'ja', 'nap', 'ce', 'pih', 'no', 'nn', 'nrm', |
143 | | - 'nov', 'oc', 'or', 'om', 'ng', 'hz', 'ug', 'uz', 'pa', 'pi', 'pag', |
144 | | - 'pap', 'ps', 'km', 'pms', 'nds', 'pl', 'pt', 'kaa', 'crh', 'ty', |
145 | | - 'ksh', 'ro', 'rmy', 'rm', 'qu', 'ru', 'sah', 'se', 'sm', 'sa', 'sg', |
146 | | - 'sc', 'sco', 'stq', 'st', 'tn', 'sq', 'scn', 'si', 'simple', 'sd', |
147 | | - 'ss', 'sk', 'cu', 'sl', 'szl', 'so', 'sr', 'sh', 'su', 'fi', 'sv', |
148 | | - 'tl', 'ta', 'kab', 'roa-tara', 'tt', 'te', 'tet', 'th', 'vi', 'ti', |
149 | | - 'tg', 'tpi', 'to', 'chr', 'chy', 've', 'tr', 'tk', 'tw', 'udm', |
150 | | - 'bug', 'uk', 'ur', 'vec', 'vo', 'fiu-vro', 'wa', 'vls', 'war', 'wo', |
151 | | - 'wuu', 'ts', 'ii', 'yi', 'yo', 'zh-yue', 'cbk-zam', 'diq', 'zea', |
152 | | - 'bat-smg', 'zh' |
153 | | - ); |
| 203 | + if( count( array_diff_key( $pagelinks, $this->pageLinks ) ) || count( array_diff_key( $this->pageLinks, $pagelinks ) ) ) { |
| 204 | + if( count( $pagelinks ) ) { |
| 205 | + $dbr->delete( 'page_props', array( 'pp_page' => $articleid, 'pp_propname' => 'interlanguage_pages' ), __FUNCTION__); |
| 206 | + } |
| 207 | + if( count( $this->pageLinks ) ) { |
| 208 | + $dbr->insert( 'page_props', array( 'pp_page' => $articleid, 'pp_propname' => 'interlanguage_pages', 'pp_value' => @serialize( $this->pageLinks ) ), __FUNCTION__); |
| 209 | + } |
| 210 | + } |
154 | 211 | |
155 | | - if(isset($wgInterlanguageExtensionSortPrepend) && is_array($wgInterlanguageExtensionSortPrepend)) { |
156 | | - $order = array_merge($wgInterlanguageExtensionSortPrepend, $order); |
157 | | - unset($wgInterlanguageExtensionSortPrepend); |
| 212 | + return true; |
158 | 213 | } |
159 | 214 | |
160 | | - $a=array_search($a['lang'], $order); |
161 | | - $b=array_search($b['lang'], $order); |
| 215 | + /** |
| 216 | + * Returns an array of names of pages on the central wiki which are linked to from a page |
| 217 | + * on this wiki by {{interlanguage:}} magic. Pagenames are array keys. |
| 218 | + * |
| 219 | + * @param $articleid - ID of the article whose links should be returned. |
| 220 | + * @returns The array. If there are no pages linked, an empty array is returned. |
| 221 | + */ |
| 222 | + function loadPageLinks( $articleid ) { |
| 223 | + $dbr = wfGetDB( DB_SLAVE ); |
| 224 | + $res = $dbr->select( 'page_props', 'pp_value', array( 'pp_page' => $articleid, 'pp_propname' => 'interlanguage_pages' ), __FUNCTION__); |
| 225 | + $pagelinks = array(); |
| 226 | + if ( $row = $dbr->fetchObject( $res ) ) { |
| 227 | + $pagelinks = @unserialize( $row->pp_value ); |
| 228 | + } |
| 229 | + $dbr->freeResult( $res ); |
| 230 | + return $pagelinks; |
| 231 | + } |
162 | 232 | |
163 | | - return ($a>$b)?1:(($a<$b)?-1:0); |
164 | | -} |
| 233 | + /** |
| 234 | + * Compare two interlanguage links by order of alphabet, based on language code. |
| 235 | + */ |
| 236 | + static function compareCode($a, $b) { |
| 237 | + return strcmp($a['lang'], $b['lang']); |
| 238 | + } |
165 | 239 | |
166 | | -function InterlanguageExtensionCompareAlphabeticRevised($a, $b) { |
167 | | - global $wgInterlanguageExtensionSortPrepend; |
168 | | -//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 |
169 | | - static $order = array( |
170 | | - 'aa', 'af', 'ak', 'als', 'am', 'ang', 'ab', |
171 | | - 'ar', 'an', 'arc', 'roa-rup', 'frp', 'as', 'ast', 'gn', 'av', 'ay', |
172 | | - 'az', 'id', 'ms', 'bm', 'bn', 'zh-min-nan', 'map-bms', 'jv', 'su', |
173 | | - 'ba', 'be', 'be-x-old', 'bh', 'bcl', 'bi', 'bar', 'bo', 'bs', 'br', |
174 | | - 'bug', 'bg', 'bxr', 'ca', 'ceb', 'cv', 'cs', 'ch', 'cbk-zam', 'ny', |
175 | | - 'sn', 'tum', 'cho', 'co', 'za', 'cy', 'da', 'pdc', 'de', 'dv', 'nv', |
176 | | - 'dsb', 'dz', 'mh', 'et', 'na', 'el', 'eml', 'en', 'myv', 'es', 'eo', |
177 | | - 'ext', 'eu', 'ee', 'to', 'fa', 'fo', 'fr', 'fy', 'ff', 'fur', 'ga', |
178 | | - 'gv', 'sm', 'gd', 'gl', 'gan', 'ki', 'glk', 'gu', 'got', 'hak', |
179 | | - 'ko', 'ha', 'haw', 'hy', 'hi', 'ho', 'hsb', 'hr', 'io', 'ig', 'ilo', |
| 240 | + /** |
| 241 | + * Compare two interlanguage links by order of alphabet, based on local language. |
| 242 | + * |
| 243 | + * List from http://meta.wikimedia.org/w/index.php?title=Interwiki_sorting_order&oldid=2022604#By_order_of_alphabet.2C_based_on_local_language |
| 244 | + */ |
| 245 | + static function compareAlphabetic($a, $b) { |
| 246 | + global $wgInterlanguageExtensionSortPrepend; |
| 247 | + // |
| 248 | + static $order = array( |
| 249 | + 'ace', 'af', 'ak', 'als', 'am', 'ang', 'ab', 'ar', 'an', 'arc', |
| 250 | + 'roa-rup', 'frp', 'as', 'ast', 'gn', 'av', 'ay', 'az', 'bm', 'bn', |
| 251 | + 'zh-min-nan', 'nan', 'map-bms', 'ba', 'be', 'be-x-old', 'bh', 'bcl', |
| 252 | + 'bi', 'bar', 'bo', 'bs', 'br', 'bg', 'bxr', 'ca', 'cv', 'ceb', 'cs', |
| 253 | + 'ch', 'cbk-zam', 'ny', 'sn', 'tum', 'cho', 'co', 'cy', 'da', 'dk', |
| 254 | + 'pdc', 'de', 'dv', 'nv', 'dsb', 'dz', 'mh', 'et', 'el', 'eml', 'en', |
| 255 | + 'myv', 'es', 'eo', 'ext', 'eu', 'ee', 'fa', 'hif', 'fo', 'fr', 'fy', |
| 256 | + 'ff', 'fur', 'ga', 'gv', 'gd', 'gl', 'gan', 'ki', 'glk', 'gu', |
| 257 | + 'got', 'hak', 'xal', 'ko', 'ha', 'haw', 'hy', 'hi', 'ho', 'hsb', |
| 258 | + 'hr', 'io', 'ig', 'ilo', 'bpy', 'id', 'ia', 'ie', 'iu', 'ik', 'os', |
| 259 | + 'xh', 'zu', 'is', 'it', 'he', 'jv', 'kl', 'kn', 'kr', 'pam', 'krc', |
| 260 | + 'ka', 'ks', 'csb', 'kk', 'kw', 'rw', 'ky', 'rn', 'sw', 'kv', 'kg', |
| 261 | + 'ht', 'ku', 'kj', 'lad', 'lbe', 'lo', 'la', 'lv', 'lb', 'lt', 'lij', |
| 262 | + 'li', 'ln', 'jbo', 'lg', 'lmo', 'hu', 'mk', 'mg', 'ml', 'mt', 'mi', |
| 263 | + 'mr', 'arz', 'mzn', 'ms', 'cdo', 'mwl', 'mdf', 'mo', 'mn', 'mus', |
| 264 | + 'my', 'nah', 'na', 'fj', 'nl', 'nds-nl', 'cr', 'ne', 'new', 'ja', |
| 265 | + 'nap', 'ce', 'pih', 'no', 'nb', 'nn', 'nrm', 'nov', 'ii', 'oc', |
| 266 | + 'mhr', 'or', 'om', 'ng', 'hz', 'uz', 'pa', 'pi', 'pag', 'pnb', |
| 267 | + 'pap', 'ps', 'km', 'pcd', 'pms', 'tpi', 'nds', 'pl', 'tokipona', |
| 268 | + 'tp', 'pnt', 'pt', 'aa', 'kaa', 'crh', 'ty', 'ksh', 'ro', 'rmy', |
| 269 | + 'rm', 'qu', 'ru', 'sah', 'se', 'sm', 'sa', 'sg', 'sc', 'sco', 'stq', |
| 270 | + 'st', 'tn', 'sq', 'scn', 'si', 'simple', 'sd', 'ss', 'sk', 'cu', |
| 271 | + 'sl', 'szl', 'so', 'ckb', 'srn', 'sr', 'sh', 'su', 'fi', 'sv', 'tl', |
| 272 | + 'ta', 'kab', 'roa-tara', 'tt', 'te', 'tet', 'th', 'ti', 'tg', 'to', |
| 273 | + 'chr', 'chy', 've', 'tr', 'tk', 'tw', 'udm', 'bug', 'uk', 'ur', |
| 274 | + 'ug', 'za', 'vec', 'vi', 'vo', 'fiu-vro', 'wa', 'zh-classical', |
| 275 | + 'vls', 'war', 'wo', 'wuu', 'ts', 'yi', 'yo', 'zh-yue', 'diq', 'zea', |
| 276 | + 'bat-smg', 'zh', 'zh-tw', 'zh-cn', |
| 277 | + ); |
| 278 | + |
| 279 | + if(isset($wgInterlanguageExtensionSortPrepend) && is_array($wgInterlanguageExtensionSortPrepend)) { |
| 280 | + $order = array_merge($wgInterlanguageExtensionSortPrepend, $order); |
| 281 | + unset($wgInterlanguageExtensionSortPrepend); |
| 282 | + } |
| 283 | + |
| 284 | + $a=array_search($a['lang'], $order); |
| 285 | + $b=array_search($b['lang'], $order); |
| 286 | + |
| 287 | + return ($a>$b)?1:(($a<$b)?-1:0); |
| 288 | + } |
| 289 | + |
| 290 | + /** |
| 291 | + * Compare two interlanguage links by order of alphabet, based on local language (by first |
| 292 | + * word). |
| 293 | + * |
| 294 | + * List from http://meta.wikimedia.org/w/index.php?title=Interwiki_sorting_order&oldid=2022604#By_order_of_alphabet.2C_based_on_local_language_.28by_first_word.29 |
| 295 | + */ |
| 296 | + static function compareAlphabeticRevised($a, $b) { |
| 297 | + global $wgInterlanguageExtensionSortPrepend; |
| 298 | + static $order = array( |
| 299 | + 'ace', 'af', 'ak', 'als', 'am', 'ang', 'ab', 'ar', 'an', 'arc', |
| 300 | + 'roa-rup', 'frp', 'as', 'ast', 'gn', 'av', 'ay', 'az', 'id', 'ms', |
| 301 | + 'bm', 'bn', 'zh-min-nan', 'nan', 'map-bms', 'jv', 'su', 'ba', 'be', |
| 302 | + 'be-x-old', 'bh', 'bcl', 'bi', 'bar', 'bo', 'bs', 'br', 'bug', 'bg', |
| 303 | + 'bxr', 'ca', 'ceb', 'cv', 'cs', 'ch', 'cbk-zam', 'ny', 'sn', 'tum', |
| 304 | + 'cho', 'co', 'cy', 'da', 'dk', 'pdc', 'de', 'dv', 'nv', 'dsb', 'na', |
| 305 | + 'dz', 'mh', 'et', 'el', 'eml', 'en', 'myv', 'es', 'eo', 'ext', 'eu', |
| 306 | + 'ee', 'fa', 'hif', 'fo', 'fr', 'fy', 'ff', 'fur', 'ga', 'gv', 'sm', |
| 307 | + 'gd', 'gl', 'gan', 'ki', 'glk', 'gu', 'got', 'hak', 'xal', 'ko', |
| 308 | + 'ha', 'haw', 'hy', 'hi', 'ho', 'hsb', 'hr', 'io', 'ig', 'ilo', |
180 | 309 | 'bpy', 'ia', 'ie', 'iu', 'ik', 'os', 'xh', 'zu', 'is', 'it', 'he', |
181 | | - 'kl', 'xal', 'kn', 'kr', 'pam', 'ka', 'ks', 'csb', 'kk', 'kw', 'rw', |
182 | | - 'ky', 'rn', 'sw', 'kv', 'kg', 'ht', 'ku', 'kj', 'lad', 'lbe', 'lo', |
183 | | - 'la', 'lv', 'lb', 'lt', 'lij', 'li', 'ln', 'jbo', 'lg', 'lmo', 'hu', |
184 | | - 'mk', 'mg', 'ml', 'mt', 'zh-classical', 'mi', 'mr', 'mzn', 'cdo', |
185 | | - 'mdf', 'mo', 'mn', 'mus', 'my', 'nah', 'fj', 'nl', 'nds-nl', 'cr', |
186 | | - 'ne', 'new', 'ja', 'nap', 'ce', 'pih', 'no', 'nn', 'nrm', 'nov', |
187 | | - 'oc', 'or', 'om', 'ng', 'hz', 'uz', 'pa', 'pi', 'pag', 'pap', 'ps', |
188 | | - 'km', 'pms', 'nds', 'pl', 'pt', 'kaa', 'crh', 'ty', 'ksh', 'ro', |
189 | | - 'rmy', 'rm', 'qu', 'ru', 'se', 'sa', 'sg', 'sc', 'sah', 'sco', |
190 | | - 'stq', 'st', 'tn', 'sq', 'scn', 'si', 'simple', 'sd', 'ss', 'sk', |
191 | | - 'sl', 'cu', 'szl', 'so', 'sr', 'sh', 'fi', 'sv', 'tl', 'ta', 'kab', |
192 | | - 'roa-tara', 'tt', 'te', 'tet', 'th', 'vi', 'ti', 'tg', 'tpi', 'chr', |
193 | | - 'chy', 've', 'tr', 'tk', 'tw', 'udm', 'uk', 'ur', 'ug', 'vec', 'vo', |
194 | | - 'fiu-vro', 'wa', 'vls', 'war', 'wo', 'wuu', 'ts', 'ii', 'yi', 'yo', |
195 | | - 'zh-yue', 'diq', 'zea', 'bat-smg', 'zh', 'zh-tw', 'zh-cn', |
196 | | - ); |
197 | | - |
198 | | - if(isset($wgInterlanguageExtensionSortPrepend) && is_array($wgInterlanguageExtensionSortPrepend)) { |
199 | | - $order = array_merge($wgInterlanguageExtensionSortPrepend, $order); |
200 | | - unset($wgInterlanguageExtensionSortPrepend); |
| 310 | + 'kl', 'kn', 'kr', 'pam', 'ka', 'ks', 'csb', 'kk', 'kw', 'rw', 'ky', |
| 311 | + 'rn', 'sw', 'kv', 'kg', 'ht', 'ku', 'kj', 'lad', 'lbe', 'lo', 'la', |
| 312 | + 'lv', 'to', 'lb', 'lt', 'lij', 'li', 'ln', 'jbo', 'lg', 'lmo', 'hu', |
| 313 | + 'mk', 'mg', 'ml', 'krc', 'mt', 'mi', 'mr', 'arz', 'mzn', 'cdo', |
| 314 | + 'mwl', 'mdf', 'mo', 'mn', 'mus', 'my', 'nah', 'fj', 'nl', 'nds-nl', |
| 315 | + 'cr', 'ne', 'new', 'ja', 'nap', 'ce', 'pih', 'no', 'nb', 'nn', |
| 316 | + 'nrm', 'nov', 'ii', 'oc', 'mhr', 'or', 'om', 'ng', 'hz', 'uz', 'pa', |
| 317 | + 'pi', 'pag', 'pnb', 'pap', 'ps', 'km', 'pcd', 'pms', 'nds', 'pl', |
| 318 | + 'pnt', 'pt', 'aa', 'kaa', 'crh', 'ty', 'ksh', 'ro', 'rmy', 'rm', |
| 319 | + 'qu', 'ru', 'sah', 'se', 'sa', 'sg', 'sc', 'sco', 'stq', 'st', 'tn', |
| 320 | + 'sq', 'scn', 'si', 'simple', 'sd', 'ss', 'sk', 'sl', 'cu', 'szl', |
| 321 | + 'so', 'ckb', 'srn', 'sr', 'sh', 'fi', 'sv', 'tl', 'ta', 'kab', |
| 322 | + 'roa-tara', 'tt', 'te', 'tet', 'th', 'vi', 'ti', 'tg', 'tpi', |
| 323 | + 'tokipona', 'tp', 'chr', 'chy', 've', 'tr', 'tk', 'tw', 'udm', 'uk', |
| 324 | + 'ur', 'ug', 'za', 'vec', 'vo', 'fiu-vro', 'wa', 'zh-classical', |
| 325 | + 'vls', 'war', 'wo', 'wuu', 'ts', 'yi', 'yo', 'zh-yue', 'diq', 'zea', |
| 326 | + 'bat-smg', 'zh', 'zh-tw', 'zh-cn', |
| 327 | + ); |
| 328 | + |
| 329 | + if(isset($wgInterlanguageExtensionSortPrepend) && is_array($wgInterlanguageExtensionSortPrepend)) { |
| 330 | + $order = array_merge($wgInterlanguageExtensionSortPrepend, $order); |
| 331 | + unset($wgInterlanguageExtensionSortPrepend); |
| 332 | + } |
| 333 | + |
| 334 | + $a=array_search($a['lang'], $order); |
| 335 | + $b=array_search($b['lang'], $order); |
| 336 | + |
| 337 | + return ($a>$b)?1:(($a<$b)?-1:0); |
201 | 338 | } |
202 | | - |
203 | | - $a=array_search($a['lang'], $order); |
204 | | - $b=array_search($b['lang'], $order); |
205 | | - |
206 | | - return ($a>$b)?1:(($a<$b)?-1:0); |
207 | 339 | } |