Index: tags/extensions/ExternalData/REL_0_7/ExternalData.i18n.php |
— | — | @@ -0,0 +1,316 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Internationalization file for the External Data extension |
| 5 | + * |
| 6 | + * @addtogroup Extensions |
| 7 | +*/ |
| 8 | + |
| 9 | +$messages = array(); |
| 10 | + |
| 11 | +/** English |
| 12 | + * @author Yaron Koren |
| 13 | + */ |
| 14 | +$messages['en'] = array( |
| 15 | + // user messages |
| 16 | + 'getdata' => 'Get data', |
| 17 | + 'externaldata-desc' => 'Allows for retrieving data in CSV, JSON and XML formats from both external URLs and local wiki pages', |
| 18 | +); |
| 19 | + |
| 20 | +/** Message documentation (Message documentation) |
| 21 | + * @author Dead3y3 |
| 22 | + */ |
| 23 | +$messages['qqq'] = array( |
| 24 | + 'externaldata-desc' => 'Description of Mediawiki extension External Data', |
| 25 | +); |
| 26 | + |
| 27 | +/** Arabic (العربية) |
| 28 | + * @author Meno25 |
| 29 | + */ |
| 30 | +$messages['ar'] = array( |
| 31 | + 'getdata' => 'الحصول على البيانات', |
| 32 | + 'externaldata-desc' => 'يسمح باسترجاع البيانات بصيغة CSV، JSON و XML من مسارات خارجية وصفحات الويكي المحلية', |
| 33 | +); |
| 34 | + |
| 35 | +/** Egyptian Spoken Arabic (مصرى) |
| 36 | + * @author Meno25 |
| 37 | + */ |
| 38 | +$messages['arz'] = array( |
| 39 | + 'getdata' => 'الحصول على البيانات', |
| 40 | + 'externaldata-desc' => 'يسمح باسترجاع البيانات بصيغة CSV، JSON و XML من مسارات خارجية وصفحات الويكى المحلية', |
| 41 | +); |
| 42 | + |
| 43 | +/** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца)) |
| 44 | + * @author EugeneZelenko |
| 45 | + * @author Jim-by |
| 46 | + */ |
| 47 | +$messages['be-tarask'] = array( |
| 48 | + 'getdata' => 'Атрымаць зьвесткі', |
| 49 | + 'externaldata-desc' => 'Дазваляе атрымліваць зьвесткі ў фарматах CSV, JSON і XML з вонкавых крыніц і лякальных старонак вікі', |
| 50 | +); |
| 51 | + |
| 52 | +/** Bosnian (Bosanski) |
| 53 | + * @author CERminator |
| 54 | + */ |
| 55 | +$messages['bs'] = array( |
| 56 | + 'getdata' => 'Uzmi podatke', |
| 57 | + 'externaldata-desc' => 'Omogućuje za preuzimanje podataka u formatima CSV, JSON i XML za vanjske URLove i lokalnu wiki', |
| 58 | +); |
| 59 | + |
| 60 | +/** Catalan (Català) |
| 61 | + * @author Solde |
| 62 | + */ |
| 63 | +$messages['ca'] = array( |
| 64 | + 'getdata' => 'Obtenir dades', |
| 65 | +); |
| 66 | + |
| 67 | +/** German (Deutsch) |
| 68 | + * @author Purodha |
| 69 | + * @author Umherirrender |
| 70 | + */ |
| 71 | +$messages['de'] = array( |
| 72 | + 'getdata' => 'Daten holen', |
| 73 | + 'externaldata-desc' => 'Erlaubt das Einfügen von Daten der Formate CSV, JSON und XML sowohl von externer URL als auch von lokalen Wikiseite', |
| 74 | +); |
| 75 | + |
| 76 | +/** Lower Sorbian (Dolnoserbski) |
| 77 | + * @author Michawiki |
| 78 | + */ |
| 79 | +$messages['dsb'] = array( |
| 80 | + 'getdata' => 'Daty wobstaraś', |
| 81 | + 'externaldata-desc' => 'Zmóžnja wótwołanje datow w formatach CSV, JSON a XML ako z eksternych URL tak teke lokalnych wikijowych bokow', |
| 82 | +); |
| 83 | + |
| 84 | +/** Greek (Ελληνικά) |
| 85 | + * @author Dead3y3 |
| 86 | + */ |
| 87 | +$messages['el'] = array( |
| 88 | + 'getdata' => 'Πάρε δεδομένα', |
| 89 | + 'externaldata-desc' => 'Επιτρέπει την ανάκτηση δεδομένων σε μορφές CSV, JSON και XML και για εξωτερικά URLs και για σελίδες του τοπικού wiki', |
| 90 | +); |
| 91 | + |
| 92 | +/** Spanish (Español) |
| 93 | + * @author Crazymadlover |
| 94 | + * @author Sanbec |
| 95 | + */ |
| 96 | +$messages['es'] = array( |
| 97 | + 'getdata' => 'Obtener datos', |
| 98 | + 'externaldata-desc' => 'Permite la recuperación de datos en formatos CSV, JSON y XML a partir de URL externos y de páginas wiki locales', |
| 99 | +); |
| 100 | + |
| 101 | +/** French (Français) |
| 102 | + * @author Crochet.david |
| 103 | + * @author IAlex |
| 104 | + */ |
| 105 | +$messages['fr'] = array( |
| 106 | + 'getdata' => 'Obtenir des données', |
| 107 | + 'externaldata-desc' => 'Permet de récupérer des données en CSV, JSON et XML depuis des URL externes et des pages du wiki', |
| 108 | +); |
| 109 | + |
| 110 | +/** Galician (Galego) |
| 111 | + * @author Toliño |
| 112 | + */ |
| 113 | +$messages['gl'] = array( |
| 114 | + 'getdata' => 'Obter os datos', |
| 115 | + 'externaldata-desc' => 'Permite a recuperación de datos en formatos CSV, JSON e XML a partir dos enderezos URL externos e mais das páxinas wiki locais', |
| 116 | +); |
| 117 | + |
| 118 | +/** Swiss German (Alemannisch) |
| 119 | + * @author Als-Holder |
| 120 | + */ |
| 121 | +$messages['gsw'] = array( |
| 122 | + 'getdata' => 'Date hole', |
| 123 | + 'externaldata-desc' => 'Erlaubt Daten abzruefe im CSV, JSON un XML Format vu extärne URL un lokale Wikisyte', |
| 124 | +); |
| 125 | + |
| 126 | +/** Gujarati (ગુજરાતી) |
| 127 | + * @author Ashok modhvadia |
| 128 | + */ |
| 129 | +$messages['gu'] = array( |
| 130 | + 'getdata' => 'માહિતી પ્રાપ્ત કરો', |
| 131 | + 'externaldata-desc' => 'બાહ્ય કડીઓ અને સ્થાનિક વિકિ પાનાઓ પરથી CSV, JSON અને XML શૈલીમાં માહિતીની પુન:પ્રાપ્તિની છુટ', |
| 132 | +); |
| 133 | + |
| 134 | +/** Hebrew (עברית) |
| 135 | + * @author Rotemliss |
| 136 | + * @author YaronSh |
| 137 | + */ |
| 138 | +$messages['he'] = array( |
| 139 | + 'getdata' => 'קבלת נתונים', |
| 140 | + 'externaldata-desc' => 'אפשרות לקבלת נתונים בפורמטים: CSV, JSON ו־XML, גם מכתובות חיצוניות וגם מדפי ויקי מקומיים', |
| 141 | +); |
| 142 | + |
| 143 | +/** Upper Sorbian (Hornjoserbsce) |
| 144 | + * @author Michawiki |
| 145 | + */ |
| 146 | +$messages['hsb'] = array( |
| 147 | + 'getdata' => 'Daty wobstarać', |
| 148 | + 'externaldata-desc' => 'Zmóžnja wotwołanje datow we formatach CSV, JSON a XML z eksternych URL kaž tež lokalnych wikijowych stronow', |
| 149 | +); |
| 150 | + |
| 151 | +/** Interlingua (Interlingua) |
| 152 | + * @author McDutchie |
| 153 | + */ |
| 154 | +$messages['ia'] = array( |
| 155 | + 'getdata' => 'Obtener datos', |
| 156 | + 'externaldata-desc' => 'Permitte recuperar datos in le formatos CSV, JSON e XML, e ab adresses URL externe e ab paginas wiki local', |
| 157 | +); |
| 158 | + |
| 159 | +/** Italian (Italiano) |
| 160 | + * @author Pietrodn |
| 161 | + */ |
| 162 | +$messages['it'] = array( |
| 163 | + 'getdata' => 'Ottieni dati', |
| 164 | + 'externaldata-desc' => 'Consente di recuperare dati nei formati CSV, XML e JSON sia da URL esterni sia da pagine wiki locali', |
| 165 | +); |
| 166 | + |
| 167 | +/** Japanese (日本語) |
| 168 | + * @author Fryed-peach |
| 169 | + */ |
| 170 | +$messages['ja'] = array( |
| 171 | + 'getdata' => 'データ取得', |
| 172 | + 'externaldata-desc' => '外部URLやローカルのウィキページから、CSV・JSON・XML形式のデータを取得できるようにする', |
| 173 | +); |
| 174 | + |
| 175 | +/** Ripoarisch (Ripoarisch) |
| 176 | + * @author Purodha |
| 177 | + */ |
| 178 | +$messages['ksh'] = array( |
| 179 | + 'getdata' => 'Date holle!', |
| 180 | + 'externaldata-desc' => 'Äloup, Date em <i lang="en">CSV</i> Fomaat, em <i lang="en">JSON</i> Fomaat, un em <i lang="en">XML</i> Fomaat fun <i lang="en">URLs</i> un vun Wiki-Sigge ze holle.', |
| 181 | +); |
| 182 | + |
| 183 | +/** Luxembourgish (Lëtzebuergesch) |
| 184 | + * @author Robby |
| 185 | + */ |
| 186 | +$messages['lb'] = array( |
| 187 | + 'getdata' => 'Donnéeë kréien', |
| 188 | + 'externaldata-desc' => 'Erlaabt et Donnéeën an de Formater CSV, JSON an XML vun externen URLen a lokale Wiki-Säiten ze verschaffen', |
| 189 | +); |
| 190 | + |
| 191 | +/** Dutch (Nederlands) |
| 192 | + * @author Siebrand |
| 193 | + */ |
| 194 | +$messages['nl'] = array( |
| 195 | + 'getdata' => 'Gegevens ophalen', |
| 196 | + 'externaldata-desc' => "Maakt het mogelijk gegevens in CSV, JSON en XML op te halen van zowel externe URL's als lokale wikipagina's", |
| 197 | +); |
| 198 | + |
| 199 | +/** Norwegian Nynorsk (Norsk (nynorsk)) |
| 200 | + * @author Gunnernett |
| 201 | + */ |
| 202 | +$messages['nn'] = array( |
| 203 | + 'getdata' => 'Hent data', |
| 204 | + 'externaldata-desc' => 'Gjev høve til å lasta inn data i formata CSV, JSON og XML frå både eksterne nettadresser og lokale wikisider', |
| 205 | +); |
| 206 | + |
| 207 | +/** Norwegian (bokmål) (Norsk (bokmål)) |
| 208 | + * @author Nghtwlkr |
| 209 | + */ |
| 210 | +$messages['no'] = array( |
| 211 | + 'getdata' => 'Hent data', |
| 212 | + 'externaldata-desc' => 'Gir mulighet til å hente data i formatene CSV, JSON og XML fra både eksterne nettadresser og lokale wikisider', |
| 213 | +); |
| 214 | + |
| 215 | +/** Occitan (Occitan) |
| 216 | + * @author Cedric31 |
| 217 | + */ |
| 218 | +$messages['oc'] = array( |
| 219 | + 'getdata' => 'Obténer de donadas', |
| 220 | + 'externaldata-desc' => "Permet de recuperar de donadas en CSV, JSON e XML dempuèi d'URL extèrnas e de paginas del wiki", |
| 221 | +); |
| 222 | + |
| 223 | +/** Polish (Polski) |
| 224 | + * @author Leinad |
| 225 | + */ |
| 226 | +$messages['pl'] = array( |
| 227 | + 'getdata' => 'Pobierz dane', |
| 228 | + 'externaldata-desc' => 'Umożliwia pobieranie danych w formatach CSV, JSON lub XML zarówno z zewnętrznych adresów URL jak i lokalnych stron wiki', |
| 229 | +); |
| 230 | + |
| 231 | +/** Portuguese (Português) |
| 232 | + * @author Waldir |
| 233 | + */ |
| 234 | +$messages['pt'] = array( |
| 235 | + 'getdata' => 'Obter dados', |
| 236 | + 'externaldata-desc' => 'Permite a obtenção de dados em CSV, JSON e XML tanto a partir de URLs externos como de páginas wiki locais', |
| 237 | +); |
| 238 | + |
| 239 | +/** Brazilian Portuguese (Português do Brasil) |
| 240 | + * @author Eduardo.mps |
| 241 | + */ |
| 242 | +$messages['pt-br'] = array( |
| 243 | + 'getdata' => 'Obter dados', |
| 244 | + 'externaldata-desc' => 'Permite a obtenção de dados em CSV, JSON e XML tanto a partir de URLs externos como de páginas wiki locais', |
| 245 | +); |
| 246 | + |
| 247 | +/** Tarandíne (Tarandíne) |
| 248 | + * @author Joetaras |
| 249 | + */ |
| 250 | +$messages['roa-tara'] = array( |
| 251 | + 'getdata' => 'Pigghie le date', |
| 252 | + 'externaldata-desc' => "Permette de repigghià le data jndr'à le formate CSV, JSON e XML da URL fore a Uicchipèdie e da pàggene locale de Uicchipèdie", |
| 253 | +); |
| 254 | + |
| 255 | +/** Russian (Русский) |
| 256 | + * @author Ferrer |
| 257 | + * @author Александр Сигачёв |
| 258 | + */ |
| 259 | +$messages['ru'] = array( |
| 260 | + 'getdata' => 'Получить данные', |
| 261 | + 'externaldata-desc' => 'Позволяет получение данных в форматах CSV, JSON и XML, как с внешних адресов, так и с локальных вики-страниц.', |
| 262 | +); |
| 263 | + |
| 264 | +/** Slovak (Slovenčina) |
| 265 | + * @author Helix84 |
| 266 | + */ |
| 267 | +$messages['sk'] = array( |
| 268 | + 'getdata' => 'Získať dáta', |
| 269 | + 'externaldata-desc' => 'Umožňuje získavanie údajov vo formátoch CSV, JSON a XML z externých URL aj z lokálnych wiki stránok', |
| 270 | +); |
| 271 | + |
| 272 | +/** Serbian Cyrillic ekavian (ћирилица) |
| 273 | + * @author Михајло Анђелковић |
| 274 | + */ |
| 275 | +$messages['sr-ec'] = array( |
| 276 | + 'getdata' => 'Преузми податке', |
| 277 | + 'externaldata-desc' => 'Омогућава преузимање података у CSV, JSON и XML форматима, како преко спољашњих веза, тако и са локалних вики-страна', |
| 278 | +); |
| 279 | + |
| 280 | +/** Swedish (Svenska) |
| 281 | + * @author Najami |
| 282 | + */ |
| 283 | +$messages['sv'] = array( |
| 284 | + 'getdata' => 'Hämta data', |
| 285 | + 'externaldata-desc' => 'Tillåter att hämta data i formaten CSV, JSON och XML från både externa URL:er och lokala wikisidor', |
| 286 | +); |
| 287 | + |
| 288 | +/** Tagalog (Tagalog) |
| 289 | + * @author AnakngAraw |
| 290 | + */ |
| 291 | +$messages['tl'] = array( |
| 292 | + 'getdata' => 'Kunin ang dato', |
| 293 | + 'externaldata-desc' => 'Nagpapahintulot sa muling pagkuha ng datong nasa mga anyong CSV, JSON at XML na kapwa mula sa panlabas na mga URL at pampook na mga pahina ng wiki', |
| 294 | +); |
| 295 | + |
| 296 | +/** Turkish (Türkçe) |
| 297 | + * @author Karduelis |
| 298 | + */ |
| 299 | +$messages['tr'] = array( |
| 300 | + 'getdata' => 'Veri al', |
| 301 | +); |
| 302 | + |
| 303 | +/** Veps (Vepsan kel') |
| 304 | + * @author Игорь Бродский |
| 305 | + */ |
| 306 | +$messages['vep'] = array( |
| 307 | + 'getdata' => 'Sada andmused', |
| 308 | +); |
| 309 | + |
| 310 | +/** Vietnamese (Tiếng Việt) |
| 311 | + * @author Vinhtantran |
| 312 | + */ |
| 313 | +$messages['vi'] = array( |
| 314 | + 'getdata' => 'Lấy dữ liệu', |
| 315 | + 'externaldata-desc' => 'Cho phép truy xuất dữ liệu theo định dạng CSV, JSON và XML từ cả URL bên ngoài lẫn các trang wiki bên trong', |
| 316 | +); |
| 317 | + |
Property changes on: tags/extensions/ExternalData/REL_0_7/ExternalData.i18n.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 318 | + native |
Index: tags/extensions/ExternalData/REL_0_7/ExternalData.php |
— | — | @@ -0,0 +1,70 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Initialization file for the External Data extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup ExternalData |
| 8 | + * @author Yaron Koren |
| 9 | + */ |
| 10 | + |
| 11 | +if (!defined('MEDIAWIKI')) die(); |
| 12 | + |
| 13 | +$wgExtensionCredits['parserhook'][]= array( |
| 14 | + 'path' => __FILE__, |
| 15 | + 'name' => 'External Data', |
| 16 | + 'version' => '0.7', |
| 17 | + 'author' => array( 'Yaron Koren', 'Michael Dale', 'David Macdonald' ), |
| 18 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:External_Data', |
| 19 | + 'description' => 'Allows for retrieving data in CSV, JSON and XML formats from both external URLs and local wiki pages', |
| 20 | + 'descriptionmsg' => 'externaldata-desc', |
| 21 | +); |
| 22 | +$edgIP = $IP . '/extensions/ExternalData'; |
| 23 | + |
| 24 | +$wgExtensionFunctions[] = 'edgParserFunctions'; |
| 25 | +$wgExtensionMessagesFiles['ExternalData'] = $edgIP . '/ExternalData.i18n.php'; |
| 26 | +$wgHooks['LanguageGetMagic'][] = 'edgLanguageGetMagic'; |
| 27 | + |
| 28 | +// register all special pages and other classes |
| 29 | +$wgAutoloadClasses['EDUtils'] = $edgIP . '/ED_Utils.php'; |
| 30 | +$wgAutoloadClasses['EDParserFunctions'] = $edgIP . '/ED_ParserFunctions.php'; |
| 31 | +$wgSpecialPages['GetData'] = 'EDGetData'; |
| 32 | +$wgAutoloadClasses['EDGetData'] = $edgIP . '/ED_GetData.php'; |
| 33 | +$wgSpecialPageGroups['GetData'] = 'pagetools'; |
| 34 | + |
| 35 | +$edgValues = array(); |
| 36 | +$edgStringReplacements = array(); |
| 37 | +$edgCacheTable = null; |
| 38 | + |
| 39 | +function edgParserFunctions() { |
| 40 | + global $wgHooks, $wgParser; |
| 41 | + if( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) { |
| 42 | + $wgHooks['ParserFirstCallInit'][] = 'edgRegisterParser'; |
| 43 | + } else { |
| 44 | + if ( class_exists( 'StubObject' ) && !StubObject::isRealObject( $wgParser ) ) { |
| 45 | + $wgParser->_unstub(); |
| 46 | + } |
| 47 | + edgRegisterParser( $wgParser ); |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +function edgRegisterParser(&$parser) { |
| 52 | + $parser->setFunctionHook( 'get_external_data', array('EDParserFunctions','doGetExternalData') ); |
| 53 | + $parser->setFunctionHook( 'get_ldap_data', array('EDParserFunctions','doGetLDAPData') ); |
| 54 | + $parser->setFunctionHook( 'get_db_data', array('EDParserFunctions','doGetDBData') ); |
| 55 | + $parser->setFunctionHook( 'external_value', array('EDParserFunctions','doExternalValue') ); |
| 56 | + $parser->setFunctionHook( 'for_external_table', array('EDParserFunctions','doForExternalTable') ); |
| 57 | + |
| 58 | + return true; // always return true, in order not to stop MW's hook processing! |
| 59 | +} |
| 60 | + |
| 61 | +function edgLanguageGetMagic( &$magicWords, $langCode = "en" ) { |
| 62 | + switch ( $langCode ) { |
| 63 | + default: |
| 64 | + $magicWords['get_external_data'] = array ( 0, 'get_external_data' ); |
| 65 | + $magicWords['get_ldap_data'] = array ( 0, 'get_ldap_data' ); |
| 66 | + $magicWords['get_db_data'] = array ( 0, 'get_db_data' ); |
| 67 | + $magicWords['external_value'] = array ( 0, 'external_value' ); |
| 68 | + $magicWords['for_external_table'] = array ( 0, 'for_external_table' ); |
| 69 | + } |
| 70 | + return true; |
| 71 | +} |
Property changes on: tags/extensions/ExternalData/REL_0_7/ExternalData.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 72 | + native |
Index: tags/extensions/ExternalData/REL_0_7/ED_ParserFunctions.php |
— | — | @@ -0,0 +1,220 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Class for handling the parser functions for External Data |
| 5 | + */ |
| 6 | + |
| 7 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 8 | + die( 'This file is a MediaWiki extension; it is not a valid entry point' ); |
| 9 | +} |
| 10 | + |
| 11 | +class EDParserFunctions { |
| 12 | + |
| 13 | + /** |
| 14 | + * Render the #get_external_data parser function |
| 15 | + */ |
| 16 | + static function doGetExternalData( &$parser ) { |
| 17 | + global $wgTitle, $edgCurPageName, $edgValues; |
| 18 | + |
| 19 | + // if we're handling multiple pages, reset $edgValues |
| 20 | + // when we move from one page to another |
| 21 | + $cur_page_name = $wgTitle->getText(); |
| 22 | + if (! isset($edgCurPageName) || $edgCurPageName != $cur_page_name) { |
| 23 | + $edgValues = array(); |
| 24 | + $edgCurPageName = $cur_page_name; |
| 25 | + } |
| 26 | + |
| 27 | + $params = func_get_args(); |
| 28 | + array_shift( $params ); // we already know the $parser ... |
| 29 | + $url = array_shift( $params ); |
| 30 | + |
| 31 | + $url_contents = EDUtils::fetchURL( $url ); |
| 32 | + |
| 33 | + $format = strtolower( array_shift( $params ) ); // make case-insensitive |
| 34 | + $external_values = array(); |
| 35 | + if ( $format == 'xml' ) { |
| 36 | + $external_values = EDUtils::getXMLData( $url_contents ); |
| 37 | + } elseif ( $format == 'csv' ) { |
| 38 | + $external_values = EDUtils::getCSVData( $url_contents, false ); |
| 39 | + } elseif ( $format == 'csv with header' ) { |
| 40 | + $external_values = EDUtils::getCSVData( $url_contents, true ); |
| 41 | + } elseif ( $format == 'json' ) { |
| 42 | + $external_values = EDUtils::getJSONData( $url_contents ); |
| 43 | + } |
| 44 | + // get set of filters and set of mappings, determining each |
| 45 | + // one by whether there's a double or single equals sign, |
| 46 | + // respectively |
| 47 | + $filters = array(); |
| 48 | + $mappings = array(); |
| 49 | + foreach ( $params as $param ) { |
| 50 | + if ( strpos( $param, '==' ) ) { |
| 51 | + list( $external_var, $value ) = explode( '==', $param ); |
| 52 | + $filters[$external_var] = $value; |
| 53 | + } else { |
| 54 | + list( $local_var, $external_var ) = explode( '=', $param ); |
| 55 | + // set to all lowercase to avoid casing issues |
| 56 | + $external_var = strtolower( $external_var ); |
| 57 | + $mappings[$local_var] = $external_var; |
| 58 | + } |
| 59 | + } |
| 60 | + foreach ( $filters as $filter_var => $filter_value ) { |
| 61 | + // find the entry of $external_values that matches |
| 62 | + // the filter variable; if none exists, just ignore |
| 63 | + // the filter |
| 64 | + if ( array_key_exists( $filter_var, $external_values ) ) { |
| 65 | + if ( is_array( $external_values[$filter_var] ) ) { |
| 66 | + $column_values = $external_values[$filter_var]; |
| 67 | + foreach ( $column_values as $i => $single_value ) { |
| 68 | + // if a value doesn't match |
| 69 | + // the filter value, remove |
| 70 | + // the value from this row for |
| 71 | + // all columns |
| 72 | + if ( $single_value != $filter_value ) { |
| 73 | + foreach ( $external_values as $external_var => $external_value ) { |
| 74 | + unset( $external_values[$external_var][$i] ); |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + } else { |
| 79 | + // if we have only one row of values, |
| 80 | + // and the filter doesn't match, just |
| 81 | + // keep the results array blank and |
| 82 | + // return |
| 83 | + if ( $external_values[$filter_var] != $filter_value ) { |
| 84 | + return; |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + // for each external variable name specified in the function |
| 90 | + // call, get its value or values (if any exist), and attach it |
| 91 | + // or them to the local variable name |
| 92 | + foreach ( $mappings as $local_var => $external_var ) { |
| 93 | + if ( array_key_exists( $external_var, $external_values ) ) { |
| 94 | + if ( is_array( $external_values[$external_var] ) ) |
| 95 | + // array_values() restores regular |
| 96 | + // 1, 2, 3 indexes to array, after unset() |
| 97 | + // in filtering may have removed some |
| 98 | + $edgValues[$local_var] = array_values( $external_values[$external_var] ); |
| 99 | + else |
| 100 | + $edgValues[$local_var][] = $external_values[$external_var]; |
| 101 | + } |
| 102 | + } |
| 103 | + return; |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Render the #get_ldap_data parser function |
| 108 | + */ |
| 109 | + static function doGetLDAPData( &$parser ) { |
| 110 | + global $wgTitle, $edgCurPageName, $edgValues; |
| 111 | + |
| 112 | + // if we're handling multiple pages, reset $edgValues |
| 113 | + // when we move from one page to another |
| 114 | + $cur_page_name = $wgTitle->getText(); |
| 115 | + if (! isset($edgCurPageName) || $edgCurPageName != $cur_page_name) { |
| 116 | + $edgValues = array(); |
| 117 | + $edgCurPageName = $cur_page_name; |
| 118 | + } |
| 119 | + |
| 120 | + $params = func_get_args(); |
| 121 | + array_shift( $params ); // we already know the $parser ... |
| 122 | + $args = EDUtils::parseParams($params); // parse params into name-value pairs |
| 123 | + $mappings = EDUtils::parseMappings($args['data']); // parse the data arg into mappings |
| 124 | + |
| 125 | + $external_values = EDUtils::getLDAPData( $args['filter'], $args['domain'], array_values($mappings) ); |
| 126 | + |
| 127 | + // Build $edgValues |
| 128 | + foreach ( $mappings as $local_var => $external_var ) { |
| 129 | + $edgValues[$local_var][] = $external_values[0][$external_var][0]; |
| 130 | + } |
| 131 | + return; |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * Render the #get_db_data parser function |
| 136 | + */ |
| 137 | + static function doGetDBData( &$parser ) { |
| 138 | + global $wgTitle, $edgCurPageName, $edgValues; |
| 139 | + |
| 140 | + // if we're handling multiple pages, reset $edgValues |
| 141 | + // when we move from one page to another |
| 142 | + $cur_page_name = $wgTitle->getText(); |
| 143 | + if (! isset($edgCurPageName) || $edgCurPageName != $cur_page_name) { |
| 144 | + $edgValues = array(); |
| 145 | + $edgCurPageName = $cur_page_name; |
| 146 | + } |
| 147 | + |
| 148 | + $params = func_get_args(); |
| 149 | + array_shift( $params ); // we already know the $parser ... |
| 150 | + $args = EDUtils::parseParams($params); // parse params into name-value pairs |
| 151 | + $mappings = EDUtils::parseMappings($args['data']); // parse the data arg into mappings |
| 152 | + |
| 153 | + $external_values = EDUtils::getDBData( $args['server'], $args['from'], $args['where'], array_values($mappings) ); |
| 154 | + // handle error cases |
| 155 | + if (is_null($external_values)) |
| 156 | + return; |
| 157 | + |
| 158 | + // Build $edgValues |
| 159 | + foreach ( $mappings as $local_var => $external_var ) { |
| 160 | + if ( array_key_exists( $external_var, $external_values ) ) { |
| 161 | + foreach ($external_values[$external_var] as $value) { |
| 162 | + $edgValues[$local_var][] = $value; |
| 163 | + } |
| 164 | + } |
| 165 | + } |
| 166 | + return; |
| 167 | + } |
| 168 | + |
| 169 | + /** |
| 170 | + * Get the specified index of the array for the specified local |
| 171 | + * variable retrieved by #get_external_data |
| 172 | + */ |
| 173 | + static function getIndexedValue( $var, $i ) { |
| 174 | + global $edgValues; |
| 175 | + if ( array_key_exists( $var, $edgValues ) && count( $edgValues[$var] > $i ) ) |
| 176 | + return $edgValues[$var][$i]; |
| 177 | + else |
| 178 | + return ''; |
| 179 | + } |
| 180 | + |
| 181 | + /** |
| 182 | + * Render the #external_value parser function |
| 183 | + */ |
| 184 | + static function doExternalValue( &$parser, $local_var = '' ) { |
| 185 | + global $edgValues; |
| 186 | + if ( ! array_key_exists( $local_var, $edgValues ) ) |
| 187 | + return ''; |
| 188 | + elseif ( is_array( $edgValues[$local_var] ) ) |
| 189 | + return $edgValues[$local_var][0]; |
| 190 | + else |
| 191 | + return $edgValues[$local_var]; |
| 192 | + } |
| 193 | + |
| 194 | + /** |
| 195 | + * Render the #for_external_table parser function |
| 196 | + */ |
| 197 | + static function doForExternalTable( &$parser, $expression = '' ) { |
| 198 | + global $edgValues; |
| 199 | + |
| 200 | + // get the variables used in this expression, get the number |
| 201 | + // of values for each, and loop through |
| 202 | + $matches = array(); |
| 203 | + preg_match_all( '/{{{([^}]*)}}}/', $expression, $matches ); |
| 204 | + $variables = $matches[1]; |
| 205 | + $num_loops = 0; |
| 206 | + foreach ($variables as $variable) { |
| 207 | + if ( array_key_exists( $variable, $edgValues ) ) { |
| 208 | + $num_loops = max( $num_loops, count( $edgValues[$variable] ) ); |
| 209 | + } |
| 210 | + } |
| 211 | + $text = ""; |
| 212 | + for ($i = 0; $i < $num_loops; $i++) { |
| 213 | + $cur_expression = $expression; |
| 214 | + foreach ($variables as $variable) { |
| 215 | + $cur_expression = str_replace( '{{{' . $variable . '}}}', self::getIndexedValue( $variable , $i ), $cur_expression ); |
| 216 | + } |
| 217 | + $text .= $cur_expression; |
| 218 | + } |
| 219 | + return $text; |
| 220 | + } |
| 221 | +} |
Property changes on: tags/extensions/ExternalData/REL_0_7/ED_ParserFunctions.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 222 | + native |
Index: tags/extensions/ExternalData/REL_0_7/ED_GetData.php |
— | — | @@ -0,0 +1,71 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * A special page for retrieving selected rows of any wiki page that contains |
| 5 | + * data in CSV format |
| 6 | + */ |
| 7 | + |
| 8 | +if (!defined('MEDIAWIKI')) die(); |
| 9 | + |
| 10 | +class EDGetData extends SpecialPage { |
| 11 | + |
| 12 | + /** |
| 13 | + * Constructor |
| 14 | + */ |
| 15 | + function EDGetData() { |
| 16 | + SpecialPage::SpecialPage( 'GetData' ); |
| 17 | + wfLoadExtensionMessages( 'ExternalData' ); |
| 18 | + } |
| 19 | + |
| 20 | + function execute($query) { |
| 21 | + global $wgRequest, $wgOut; |
| 22 | + $wgOut->disable(); |
| 23 | + |
| 24 | + $this->setHeaders(); |
| 25 | + $page_name = $query; |
| 26 | + $title = Title::newFromText( $page_name ); |
| 27 | + if( is_null( $title ) ) |
| 28 | + return; |
| 29 | + if( ! $title->userCanRead() ) |
| 30 | + return; |
| 31 | + $article = new Article( $title ); |
| 32 | + $page_text = $article->fetchContent(); |
| 33 | + // Remove <noinclude> sections and <includeonly> tags from text |
| 34 | + $page_text = StringUtils::delimiterReplace('<noinclude>', '</noinclude>', '', $page_text); |
| 35 | + $page_text = strtr($page_text, array('<includeonly>' => '', '</includeonly>' => '')); |
| 36 | + $orig_lines = split( "\n", $page_text ); |
| 37 | + // ignore lines that are either blank or start with a semicolon |
| 38 | + $page_lines = array(); |
| 39 | + foreach ( $orig_lines as $i => $line ) |
| 40 | + if ( $line != '' && $line[0] != ';' ) |
| 41 | + $page_lines[] = $line; |
| 42 | + $headers = EDUtils::getValuesFromCSVLine( $page_lines[0] ); |
| 43 | + $queried_headers = array(); |
| 44 | + foreach( $wgRequest->getValues() as $key => $value ) { |
| 45 | + foreach( $headers as $header_index => $header_value ) { |
| 46 | + $header_value = str_replace( ' ', '_', $header_value ); |
| 47 | + if( $key == $header_value ) { |
| 48 | + $queried_headers[$header_index] = $value; |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | + // include header in output |
| 53 | + $text = $page_lines[0]; |
| 54 | + foreach( $page_lines as $i => $line) { |
| 55 | + if ($i == 0) continue; |
| 56 | + $row_values = EDUtils::getValuesFromCSVLine( $line ); |
| 57 | + $found_match = true; |
| 58 | + foreach( $queried_headers as $i => $query_value ) { |
| 59 | + $single_value = str_replace( ' ', '_', $row_values[$i] ); |
| 60 | + if ( $single_value != $query_value ) { |
| 61 | + $found_match = false; |
| 62 | + } |
| 63 | + } |
| 64 | + if( $found_match ) { |
| 65 | + if ($text != '') $text .= "\n"; |
| 66 | + $text .= $line; |
| 67 | + } |
| 68 | + } |
| 69 | + print $text; |
| 70 | + } |
| 71 | + |
| 72 | +} |
Property changes on: tags/extensions/ExternalData/REL_0_7/ED_GetData.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 73 | + native |
Index: tags/extensions/ExternalData/REL_0_7/ExternalData.sql |
— | — | @@ -0,0 +1,9 @@ |
| 2 | +CREATE TABLE IF NOT EXISTS `ed_url_cache` ( |
| 3 | + `id` int(10) unsigned NOT NULL auto_increment, |
| 4 | + `url` varchar(255) NOT NULL, |
| 5 | + `post_vars` text, |
| 6 | + `req_time` int(11) NOT NULL, |
| 7 | + `result` longtext character set utf8 collate utf8_unicode_ci, |
| 8 | + UNIQUE KEY `id` (`id`), |
| 9 | + KEY `url` (`url`) |
| 10 | +) ENGINE=MyISAM DEFAULT CHARSET=latin1; |
\ No newline at end of file |
Property changes on: tags/extensions/ExternalData/REL_0_7/ExternalData.sql |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 11 | + native |
Index: tags/extensions/ExternalData/REL_0_7/README |
— | — | @@ -0,0 +1,72 @@ |
| 2 | +External Data extension |
| 3 | + |
| 4 | + Version 0.7 |
| 5 | + Yaron Koren, Michael Dale and David Macdonald |
| 6 | + |
| 7 | +This is free software licensed under the GNU General Public License. Please |
| 8 | +see http://www.gnu.org/copyleft/gpl.html for further details, including the |
| 9 | +full text and terms of the license. |
| 10 | + |
| 11 | +== Overview == |
| 12 | + |
| 13 | +External Data is an extension to MediaWiki that allows for retrieving data |
| 14 | +from various sources: external URLs and local wiki pages (in CSV, JSON and |
| 15 | +XML formats), database tables, and LDAP servers |
| 16 | + |
| 17 | +The extension defines five parser functions - #get_external_data, |
| 18 | +#get_db_data, #get_ldap_data, #external_value and #for_external_table: |
| 19 | + |
| 20 | +#get_external_data retrieves the data from a URL that holds XML, CSV or |
| 21 | +JSON, and assigns it to local variables or arrays. |
| 22 | + |
| 23 | +#get_db_data retrieves data from a database, using a SQL query, and assigns |
| 24 | +it to local variables or arrays. |
| 25 | + |
| 26 | +#get_ldap_data retrieves data from an LDAP server and assigns it to |
| 27 | +local variables. |
| 28 | + |
| 29 | +#external_value displays the value of any retrieved variable, or the |
| 30 | +first value if it's an array. |
| 31 | + |
| 32 | +#for_external_table applies processing onto multiple rows retrieved by |
| 33 | +#get_external_data. |
| 34 | + |
| 35 | +In addition, the extension defines a new special page, 'GetData', that |
| 36 | +exports selected rows from a wiki page that holds CSV data, in a format that |
| 37 | +is readable by #get_external_data. |
| 38 | + |
| 39 | +For more information, see the extension homepage at: |
| 40 | +http://www.mediawiki.org/wiki/Extension:External_Data |
| 41 | + |
| 42 | +== Requirements == |
| 43 | + |
| 44 | +This version of the External Data extension requires MediaWiki 1.8 or higher. |
| 45 | + |
| 46 | +== Installation == |
| 47 | + |
| 48 | +To install the extension, place the entire 'ExternalData' directory |
| 49 | +within your MediaWiki 'extensions' directory, then add the following |
| 50 | +line to your 'LocalSettings.php' file: |
| 51 | + |
| 52 | + require_once( "$IP/extensions/ExternalData/ExternalData.php" ); |
| 53 | + |
| 54 | +To cache the data from the URLs being accessed, you can call the contents |
| 55 | +of ExternalData.sql in your database, then add the following to |
| 56 | +LocalSettings.php: |
| 57 | + |
| 58 | + $edgCacheTable = 'ed_url_cache'; |
| 59 | + |
| 60 | +You can also set for string replacements to be done on the URLs you call, |
| 61 | +for instance to hide API keys: |
| 62 | + |
| 63 | + $edgStringReplacements['MY_API_KEY'] = 'abcd1324'; |
| 64 | + |
| 65 | +Finally, to use the database or LDAP retrieval capabilities, you need to |
| 66 | +set connection settings as well - see the online documentation for more |
| 67 | +information. |
| 68 | + |
| 69 | +== Contact == |
| 70 | + |
| 71 | +Comments, questions, suggestions and bug reports are welcome, and can |
| 72 | +be placed on the Talk page for the extension, or sent to Yaron at |
| 73 | +yaron57@gmail.com. |
Property changes on: tags/extensions/ExternalData/REL_0_7/README |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 74 | + native |
Index: tags/extensions/ExternalData/REL_0_7/ED_Utils.php |
— | — | @@ -0,0 +1,315 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Utility functions for External Data |
| 5 | + */ |
| 6 | + |
| 7 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 8 | + die( 'This file is a MediaWiki extension; it is not a valid entry point' ); |
| 9 | +} |
| 10 | + |
| 11 | +class EDUtils { |
| 12 | + // how many times to try an HTTP request |
| 13 | + private static $http_number_of_tries=3; |
| 14 | + |
| 15 | + // XML-handling functions based on code found at |
| 16 | + // http://us.php.net/xml_set_element_handler |
| 17 | + static function startElement( $parser, $name, $attrs ) { |
| 18 | + global $edgCurrentXMLTag, $edgXMLValues; |
| 19 | + // set to all lowercase to avoid casing issues |
| 20 | + $edgCurrentXMLTag = strtolower( $name ); |
| 21 | + foreach( $attrs as $attr => $value ) { |
| 22 | + $attr = strtolower( $attr ); |
| 23 | + if ( array_key_exists( $attr, $edgXMLValues ) ) |
| 24 | + $edgXMLValues[$attr][] = $value; |
| 25 | + else |
| 26 | + $edgXMLValues[$attr] = array( $value ); |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + static function endElement( $parser, $name ) { |
| 31 | + global $edgCurrentXMLTag; |
| 32 | + $edgCurrentXMLTag = ""; |
| 33 | + } |
| 34 | + |
| 35 | + static function getContent ( $parser, $content ) { |
| 36 | + global $edgCurrentXMLTag, $edgXMLValues; |
| 37 | + if ( array_key_exists( $edgCurrentXMLTag, $edgXMLValues ) ) |
| 38 | + $edgXMLValues[$edgCurrentXMLTag][] = $content; |
| 39 | + else |
| 40 | + $edgXMLValues[$edgCurrentXMLTag] = array( $content ); |
| 41 | + } |
| 42 | + |
| 43 | + static function parseParams( $params ) { |
| 44 | + $args = Array(); |
| 45 | + foreach ($params as $param) { |
| 46 | + $param = preg_replace ( "/\s\s+/" , " " , $param ); //whitespace |
| 47 | + list($name, $value) = split("=", $param, 2); |
| 48 | + $args[$name] = $value; |
| 49 | + } |
| 50 | + return $args; |
| 51 | + } |
| 52 | + |
| 53 | + // This function parses the data argument |
| 54 | + static function parseMappings( $dataArg ) { |
| 55 | + $dataArg = preg_replace ( "/\s\s+/" , " " , $dataArg ); //whitespace |
| 56 | + $rawMappings = split(",", $dataArg); |
| 57 | + $mappings = Array(); |
| 58 | + foreach ($rawMappings as $rawMapping) { |
| 59 | + $vals = split("=", $rawMapping, 2); |
| 60 | + if (count($vals) == 2) { |
| 61 | + $intValue = trim($vals[0]); |
| 62 | + $extValue = trim($vals[1]); |
| 63 | + $mappings[$intValue] = $extValue; |
| 64 | + } |
| 65 | + } |
| 66 | + return $mappings; |
| 67 | + } |
| 68 | + |
| 69 | + static function getLDAPData ($filter, $domain, $params) { |
| 70 | + global $edgLDAPServer; |
| 71 | + global $edgLDAPUser; |
| 72 | + global $edgLDAPPass; |
| 73 | + |
| 74 | + $ds = EDUtils::connectLDAP($edgLDAPServer[$domain], $edgLDAPUser[$domain], $edgLDAPPass[$domain]); |
| 75 | + $results = EDUtils::searchLDAP($ds, $domain, $filter, $params); |
| 76 | + |
| 77 | + return $results; |
| 78 | + } |
| 79 | + |
| 80 | + static function connectLDAP($server, $username, $password) { |
| 81 | + $ds = ldap_connect($server); |
| 82 | + if ($ds) { |
| 83 | + // these options for Active Directory only? |
| 84 | + ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION,3); |
| 85 | + ldap_set_option($ds, LDAP_OPT_REFERRALS, 0); |
| 86 | + |
| 87 | + if ($username) { |
| 88 | + $r = ldap_bind($ds, $username, $password); |
| 89 | + } else { |
| 90 | + # no username, so do anonymous bind |
| 91 | + $r = ldap_bind($ds); |
| 92 | + } |
| 93 | + |
| 94 | + # should check the result of the bind here |
| 95 | + return $ds; |
| 96 | + } else { |
| 97 | + echo "Unable to connect to $server\n"; |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + static function searchLDAP($ds, $domain, $filter, $attributes) { |
| 102 | + global $edgLDAPBaseDN; |
| 103 | + |
| 104 | + $sr = ldap_search($ds, $edgLDAPBaseDN[$domain], $filter, $attributes); |
| 105 | + $results = ldap_get_entries($ds, $sr); |
| 106 | + return $results; |
| 107 | + } |
| 108 | + |
| 109 | + static function getDBData ($server_id, $from, $where, $columns) { |
| 110 | + global $edgDBServerType; |
| 111 | + global $edgDBServer; |
| 112 | + global $edgDBName; |
| 113 | + global $edgDBUser; |
| 114 | + global $edgDBPass; |
| 115 | + |
| 116 | + if ((! array_key_exists($server_id, $edgDBServerType)) || |
| 117 | + (! array_key_exists($server_id, $edgDBServer)) || |
| 118 | + (! array_key_exists($server_id, $edgDBName)) || |
| 119 | + (! array_key_exists($server_id, $edgDBUser)) || |
| 120 | + (! array_key_exists($server_id, $edgDBPass))) { |
| 121 | + echo "<p>ERROR: Incomplete information for this server ID.</p>\n"; |
| 122 | + return; |
| 123 | + } |
| 124 | + |
| 125 | + |
| 126 | + $db_type = $edgDBServerType[$server_id]; |
| 127 | + $db_server = $edgDBServer[$server_id]; |
| 128 | + $db_name = $edgDBName[$server_id]; |
| 129 | + $db_username = $edgDBUser[$server_id]; |
| 130 | + $db_password = $edgDBPass[$server_id]; |
| 131 | + |
| 132 | + if ($db_type == "mysql") { |
| 133 | + $db = new Database($db_server, $db_username, $db_password, $db_name); |
| 134 | + } elseif ($db_type == "postgres") { |
| 135 | + $db = new DatabasePostgres($db_server, $db_username, $db_password, $db_name); |
| 136 | + } elseif ($db_type == "mssql") { |
| 137 | + $db = new DatabaseMssql($db_server, $db_username, $db_password, $db_name); |
| 138 | + } else { |
| 139 | + echo "<p>ERROR: Unknown database type.</p>\n"; |
| 140 | + return; |
| 141 | + } |
| 142 | + if (! $db->isOpen()) { |
| 143 | + echo "<p>ERROR: Could not connect to database.</p>\n"; |
| 144 | + return; |
| 145 | + } |
| 146 | + |
| 147 | + if (count($columns) == 0) { |
| 148 | + echo "<p>ERROR: No return values specified.</p>\n"; |
| 149 | + return; |
| 150 | + } |
| 151 | + |
| 152 | + $rows = EDUtils::searchDB($db, $from, $where, $columns); |
| 153 | + $db->close(); |
| 154 | + |
| 155 | + $values = Array(); |
| 156 | + foreach ($rows as $row) { |
| 157 | + foreach ($columns as $column) { |
| 158 | + $values[$column][] = $row[$column]; |
| 159 | + } |
| 160 | + } |
| 161 | + |
| 162 | + return $values; |
| 163 | + } |
| 164 | + |
| 165 | + static function searchDB ($db, $from, $where, $columns) { |
| 166 | + $sql = "SELECT " . implode(",", $columns) . " "; |
| 167 | + $sql .= "FROM " . $from . " "; |
| 168 | + $sql .= "WHERE " . $where; |
| 169 | + |
| 170 | + $result = $db->query($sql); |
| 171 | + if (!$result) { |
| 172 | + echo "Invalid query."; |
| 173 | + return false; |
| 174 | + } else { |
| 175 | + $rows = Array(); |
| 176 | + while ($row = $db->fetchRow($result)) { |
| 177 | + $rows[] = $row; |
| 178 | + } |
| 179 | + return $rows; |
| 180 | + } |
| 181 | + } |
| 182 | + |
| 183 | + static function getXMLData ( $xml ) { |
| 184 | + global $edgXMLValues; |
| 185 | + $edgXMLValues = array(); |
| 186 | + |
| 187 | + $xml_parser = xml_parser_create(); |
| 188 | + xml_set_element_handler( $xml_parser, array( 'EDUtils', 'startElement' ), array( 'EDUtils', 'endElement' ) ); |
| 189 | + xml_set_character_data_handler( $xml_parser, array( 'EDUtils', 'getContent' ) ); |
| 190 | + if (!xml_parse($xml_parser, $xml, true)) { |
| 191 | + echo(sprintf("XML error: %s at line %d", |
| 192 | + xml_error_string(xml_get_error_code($xml_parser)), |
| 193 | + xml_get_current_line_number($xml_parser))); |
| 194 | + } |
| 195 | + xml_parser_free( $xml_parser ); |
| 196 | + return $edgXMLValues; |
| 197 | + } |
| 198 | + |
| 199 | + static function getValuesFromCSVLine( $csv_line ) { |
| 200 | + // regular expression copied from http://us.php.net/fgetcsv |
| 201 | + $vals = preg_split( '/,(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/', $csv_line ); |
| 202 | + $vals2 = array(); |
| 203 | + foreach( $vals as $val ) |
| 204 | + $vals2[] = trim( $val, '"' ); |
| 205 | + return $vals2; |
| 206 | + } |
| 207 | + |
| 208 | + static function getCSVData( $csv, $has_header ) { |
| 209 | + // from http://us.php.net/manual/en/function.str-getcsv.php#88311 |
| 210 | + // str_getcsv() is a function that was only added in PHP 5.3.0, |
| 211 | + // so use the much older fgetcsv() if it's not there |
| 212 | + if (function_exists('str_getcsv')) { |
| 213 | + $table = str_getcsv( $csv ); |
| 214 | + } else { |
| 215 | + $fiveMBs = 5 * 1024 * 1024; |
| 216 | + $fp = fopen("php://temp/maxmemory:$fiveMBs", 'r+'); |
| 217 | + fputs( $fp, $csv ); |
| 218 | + rewind( $fp ); |
| 219 | + $table = array(); |
| 220 | + while ($line = fgetcsv( $fp )) { |
| 221 | + array_push( $table, $line ); |
| 222 | + } |
| 223 | + fclose($fp); |
| 224 | + } |
| 225 | + // now "flip" the data, turning it into a column-by-column |
| 226 | + // array, instead of row-by-row |
| 227 | + if ( $has_header ) { |
| 228 | + $header_vals = array_shift( $table ); |
| 229 | + } |
| 230 | + $values = array(); |
| 231 | + foreach( $table as $line ) { |
| 232 | + foreach( $line as $i => $row_val ) { |
| 233 | + if ($has_header) { |
| 234 | + $column = strtolower( $header_vals[$i] ); |
| 235 | + } else { |
| 236 | + // start with an index of 1 instead of 0 |
| 237 | + $column = $i + 1; |
| 238 | + } |
| 239 | + if( array_key_exists( $column, $values ) ) |
| 240 | + $values[$column][] = $row_val; |
| 241 | + else |
| 242 | + $values[$column] = array( $row_val ); |
| 243 | + } |
| 244 | + } |
| 245 | + return $values; |
| 246 | + } |
| 247 | + |
| 248 | + /** |
| 249 | + * Recursive function for use by getJSONData() |
| 250 | + */ |
| 251 | + static function parseTree( $tree, &$retrieved_values ) { |
| 252 | + foreach ($tree as $key => $val) { |
| 253 | + if (is_array( $val )) { |
| 254 | + self::parseTree( $val, $retrieved_values ); |
| 255 | + } else { |
| 256 | + if( array_key_exists( $key, $retrieved_values ) ) |
| 257 | + $retrieved_values[$key][] = $val; |
| 258 | + else |
| 259 | + $retrieved_values[$key] = array( $val ); |
| 260 | + } |
| 261 | + } |
| 262 | + } |
| 263 | + |
| 264 | + static function getJSONData( $json ) { |
| 265 | + // escape if json_decode() isn't supported |
| 266 | + if ( ! function_exists( 'json_decode' ) ) { |
| 267 | + echo( "Error: json_decode() is not supported in this version of PHP" ); |
| 268 | + return array(); |
| 269 | + } |
| 270 | + $json_tree = json_decode($json, true); |
| 271 | + $values = array(); |
| 272 | + if ( is_array( $json_tree ) ) { |
| 273 | + self::parseTree( $json_tree, $values ); |
| 274 | + } |
| 275 | + return $values; |
| 276 | + } |
| 277 | + |
| 278 | + static function fetchURL( $url, $post_vars = array(), $get_fresh=false, $try_count=1 ) { |
| 279 | + $dbr = wfGetDB( DB_SLAVE ); |
| 280 | + global $edgStringReplacements, $edgCacheTable; |
| 281 | + |
| 282 | + // do any special variable replacements in the URLs, for |
| 283 | + // secret API keys and the like |
| 284 | + foreach ( $edgStringReplacements as $key => $value ) { |
| 285 | + $url = str_replace( $key, $value, $url ); |
| 286 | + } |
| 287 | + |
| 288 | + if( !isset( $edgCacheTable ) || is_null( $edgCacheTable ) ) |
| 289 | + return Http::get( $url ); |
| 290 | + |
| 291 | + // check the cache (only the first 254 chars of the url) |
| 292 | + $res = $dbr->select( $edgCacheTable, '*', array( 'url' => substr($url,0,254) ), 'EDUtils::fetchURL' ); |
| 293 | + // @@todo check date |
| 294 | + if ( $res->numRows() == 0 || $get_fresh) { |
| 295 | + $page = Http::get( $url ); |
| 296 | + if ( $page === false ) { |
| 297 | + sleep( 1 ); |
| 298 | + if( $try_count >= self::$http_number_of_tries ){ |
| 299 | + echo "could not get URL after " . self::$http_number_of_tries . " tries.\n\n"; |
| 300 | + return ''; |
| 301 | + } |
| 302 | + $try_count++; |
| 303 | + return self::fetchURL( $url, $post_vars, $get_fresh, $try_count ); |
| 304 | + } |
| 305 | + if ( $page != '' ) { |
| 306 | + $dbw = wfGetDB( DB_MASTER ); |
| 307 | + // insert contents into the cache table |
| 308 | + $dbw->insert( $edgCacheTable, array( 'url' => substr($url,0,254), 'result' => $page, 'req_time' => time() ) ); |
| 309 | + return $page; |
| 310 | + } |
| 311 | + } else { |
| 312 | + $row = $dbr->fetchObject( $res ); |
| 313 | + return $row->result; |
| 314 | + } |
| 315 | + } |
| 316 | +} |
Property changes on: tags/extensions/ExternalData/REL_0_7/ED_Utils.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 317 | + native |