Index: trunk/extensions/LocalisationUpdate/LocalisationUpdate.php |
— | — | @@ -33,6 +33,7 @@ |
34 | 34 | ); |
35 | 35 | |
36 | 36 | // Use the right hook |
| 37 | +$wgHooks['MessageNotInMwNs'][] = 'LocalisationUpdate::FindUpdatedMessages'; // MW <= 1.15 |
37 | 38 | $wgHooks['LocalisationCacheRecache'][] = 'LocalisationUpdate::onRecache'; // MW 1.16+ |
38 | 39 | |
39 | 40 | $dir = dirname( __FILE__ ) . '/'; |
Index: trunk/extensions/LocalisationUpdate/LocalisationUpdate.class.php |
— | — | @@ -1,6 +1,34 @@ |
2 | 2 | <?php |
3 | 3 | class LocalisationUpdate { |
4 | 4 | // DB Search funtion |
| 5 | + // MW <= 1.15 |
| 6 | + public static function FindUpdatedMessage( &$message, $lckey, $langcode, $isFullKey ) { |
| 7 | + // Define a cache |
| 8 | + static $cache = array(); |
| 9 | + $db = wfGetDB ( DB_SLAVE ); |
| 10 | + |
| 11 | + // If the key also contains the language code remove the language code from the key |
| 12 | + if ( $isFullKey ) { |
| 13 | + $lckey = preg_replace( "/\/" . $langcode . "/", "", $lckey ); |
| 14 | + } |
| 15 | + |
| 16 | + // If message is in the cache, don't get an update! |
| 17 | + if ( array_key_exists( $lckey . "/" . $langcode, $cache ) ) { |
| 18 | + $message = $cache[$lckey . "/" . $langcode]; |
| 19 | + |
| 20 | + // Get the message from the database |
| 21 | + $conds = array( 'lo_key' => $lckey, 'lo_language' => $langcode ); |
| 22 | + $result = $db->selectField( 'localisation', 'lo_value', $conds, __METHOD__ ); // Check if the database has any updated message |
| 23 | + if ( $result === false ) { // If no results found, exit here |
| 24 | + return true; |
| 25 | + } |
| 26 | + |
| 27 | + $message = $result; |
| 28 | + $cache[$lckey . "/" . $langcode] = $result; // Update the cache |
| 29 | + return true; |
| 30 | + } |
| 31 | + |
| 32 | + // MW 1.16+ |
5 | 33 | public static function onRecache( $lc, $langcode, &$cache ) { |
6 | 34 | $dbr = wfGetDB ( DB_SLAVE ); |
7 | 35 | |