Index: trunk/extensions/Interlanguage/Interlanguage.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php
|
3 | 3 | # MediaWiki Interlanguage extension v1.1
|
4 | 4 | #
|
5 | | -# Copyright � 2008 Nikola Smolenski <smolensk@eunet.yu>
|
| 5 | +# Copyright © 2008 Nikola Smolenski <smolensk@eunet.yu>
|
6 | 6 | #
|
7 | 7 | # This program is free software; you can redistribute it and/or modify
|
8 | 8 | # it under the terms of the GNU General Public License as published by
|
— | — | @@ -42,22 +42,24 @@ |
43 | 43 | }
|
44 | 44 |
|
45 | 45 | function InterlanguageExtension( &$parser, $param) {
|
46 | | - global
|
47 | | - $wgInterlanguageExtensionApiUrl,
|
48 | | - $wgInterlanguageExtensionSort,
|
49 | | - $wgInterlanguageExtensionPrefix,
|
50 | | - $wgInterlanguageExtensionInterwiki,
|
51 | | - $wgLanguageCode,
|
52 | | - $wgTitle;
|
| 46 | + global $wgInterlanguageExtensionApiUrl, $wgInterlanguageExtensionSort,
|
| 47 | + $wgInterlanguageExtensionPrefix, $wgInterlanguageExtensionInterwiki,
|
| 48 | + $wgLanguageCode, $wgTitle, $wgMemc;
|
53 | 49 |
|
54 | 50 | if(isset($wgInterlanguageExtensionPrefix)) {
|
55 | 51 | $param = "$wgInterlanguageExtensionPrefix$param";
|
56 | 52 | }
|
57 | 53 |
|
58 | | - $res = false;
|
59 | | - if($a = Http::get("$wgInterlanguageExtensionApiUrl?action=query&prop=langlinks&lllimit=500&format=php&redirects&titles=".strtr($param,' ','_'))) {
|
| 54 | + $url = $wgInterlanguageExtensionApiUrl . "?action=query&prop=langlinks&" .
|
| 55 | + "lllimit=500&format=php&redirects&titles=" . strtr( $param, ' ', '_' );
|
| 56 | + $key = wfMemc( 'Interlanguage', md5( $url ) );
|
| 57 | + $res = $wgMemc->get( $key );
|
60 | 58 |
|
61 | | - $a = @unserialize($a);
|
| 59 | + if ( !$res ) {
|
| 60 | + # be sure to set $res back to bool false, we do a strict compare below
|
| 61 | + $res = false;
|
| 62 | + $a = Http::get( $url );
|
| 63 | + $a = @unserialize( $a );
|
62 | 64 | if(isset($a['query']['pages']) && is_array($a['query']['pages'])) {
|
63 | 65 | $a = array_shift($a['query']['pages']);
|
64 | 66 |
|
— | — | @@ -114,7 +116,8 @@ |
115 | 117 | }
|
116 | 118 | }
|
117 | 119 | }
|
118 | | -
|
| 120 | + # cache the final result so we can skip all of this
|
| 121 | + $wgMemc->set( $key, $res, time() + 3600 );
|
119 | 122 | return $res;
|
120 | 123 | }
|
121 | 124 |
|