Index: trunk/extensions/LocalisationUpdate/LocalisationUpdate.php |
— | — | @@ -21,6 +21,18 @@ |
22 | 22 | |
23 | 23 | $wgLocalisationUpdateRetryAttempts = 5; |
24 | 24 | |
| 25 | +/** |
| 26 | + * If you want to share LocalisationUpdate info between multiple wikis, |
| 27 | + * you can have them reference a central copy of the tables in a given |
| 28 | + * database. Must be accessible via the main database connection. |
| 29 | + * |
| 30 | + * Note that if your wikis have different extensions enabled, you may |
| 31 | + * wish to pass the --all option to LocalisationUpdate/update.php so it |
| 32 | + * pulls updates for all extensions present in the source tree instead |
| 33 | + * of just the ones you have enabled on the wiki you run it from. |
| 34 | + */ |
| 35 | +$wgLocalisationUpdateDatabase = false; |
| 36 | + |
25 | 37 | // Info about me! |
26 | 38 | $wgExtensionCredits['other'][] = array( |
27 | 39 | 'path' => __FILE__, |
Index: trunk/extensions/LocalisationUpdate/LocalisationUpdate.class.php |
— | — | @@ -20,7 +20,7 @@ |
21 | 21 | |
22 | 22 | // Get the message from the database |
23 | 23 | $conds = array( 'lo_key' => $lckey, 'lo_language' => $langcode ); |
24 | | - $result = $db->selectField( 'localisation', 'lo_value', $conds, __METHOD__ ); // Check if the database has any updated message |
| 24 | + $result = $db->selectField( self::table( 'localisation' ), 'lo_value', $conds, __METHOD__ ); // Check if the database has any updated message |
25 | 25 | if ( $result === false ) { // If no results found, exit here |
26 | 26 | return true; |
27 | 27 | } |
— | — | @@ -35,7 +35,7 @@ |
36 | 36 | $dbr = wfGetDB ( DB_SLAVE ); |
37 | 37 | |
38 | 38 | // Get the messages from the database |
39 | | - $res = $dbr->select( 'localisation', |
| 39 | + $res = $dbr->select( self::table( 'localisation' ), |
40 | 40 | array( 'lo_key', 'lo_value' ), |
41 | 41 | array( 'lo_language' => $langcode ), |
42 | 42 | __METHOD__ ); |
— | — | @@ -279,7 +279,7 @@ |
280 | 280 | // Add the messages we got with our previous update(s) to the local array (as we already got these as well) |
281 | 281 | $fields = array( 'lo_key', 'lo_value' ); |
282 | 282 | $conds = array( 'lo_language' => $langcode ); |
283 | | - $result = $db->select( 'localisation', $fields, $conds, __METHOD__ ); |
| 283 | + $result = $db->select( self::table( 'localisation' ), $fields, $conds, __METHOD__ ); |
284 | 284 | foreach ( $result as $r ) { |
285 | 285 | $compare_messages[$r->lo_key] = $r->lo_value; |
286 | 286 | } |
— | — | @@ -316,7 +316,7 @@ |
317 | 317 | $db = wfGetDB( DB_MASTER ); |
318 | 318 | |
319 | 319 | $hashConds = array( 'lfh_file' => $file, 'lfh_hash' => $hash ); |
320 | | - $result = $db->select( 'localisation_file_hash', '*', $hashConds, __METHOD__ ); |
| 320 | + $result = $db->select( self::table( 'localisation_file_hash' ), '*', $hashConds, __METHOD__ ); |
321 | 321 | if ( $db->numRows( $result ) == 0 ) { |
322 | 322 | return true; |
323 | 323 | } else { |
— | — | @@ -329,7 +329,7 @@ |
330 | 330 | // Double query sucks but we wanna make sure we don't update |
331 | 331 | // the timestamp when the hash hasn't changed |
332 | 332 | if ( self::checkHash( $file, $hash ) ) |
333 | | - $db->replace( 'localisation_file_hash', array( 'lfh_file' ), array( |
| 333 | + $db->replace( self::table( 'localisation_file_hash' ), array( 'lfh_file' ), array( |
334 | 334 | 'lfh_file' => $file, |
335 | 335 | 'lfh_hash' => $hash, |
336 | 336 | 'lfh_timestamp' => $db->timestamp( wfTimestamp() ) |
— | — | @@ -358,7 +358,7 @@ |
359 | 359 | 'lo_language' => $langcode, |
360 | 360 | 'lo_key' => $key |
361 | 361 | ); |
362 | | - $db->replace( 'localisation', |
| 362 | + $db->replace( self::table( 'localisation' ), |
363 | 363 | array( 'PRIMARY' ), $values, |
364 | 364 | __METHOD__ ); |
365 | 365 | |
— | — | @@ -479,7 +479,7 @@ |
480 | 480 | // Add the already known messages to the array so we will only find new changes |
481 | 481 | $fields = array( 'lo_key', 'lo_value' ); |
482 | 482 | $conds = array( 'lo_language' => $language ); |
483 | | - $result = $db->select( 'localisation', $fields, $conds, __METHOD__ ); |
| 483 | + $result = $db->select( self::table( 'localisation' ), $fields, $conds, __METHOD__ ); |
484 | 484 | foreach ( $result as $r ) { |
485 | 485 | $compare_messages[$r->lo_key] = $r->lo_value; |
486 | 486 | } |
— | — | @@ -544,6 +544,15 @@ |
545 | 545 | return false; |
546 | 546 | } |
547 | 547 | } |
| 548 | + |
| 549 | + public static function table( $table ) { |
| 550 | + global $wgLocalisationUpdateDatabase; |
| 551 | + if( $wgLocalisationUpdateDatabase ) { |
| 552 | + return "$wgLocalisationUpdateDatabase.$table"; |
| 553 | + } else { |
| 554 | + return $table; |
| 555 | + } |
| 556 | + } |
548 | 557 | } |
549 | 558 | |
550 | 559 | class LUDependency extends CacheDependency { |
— | — | @@ -561,7 +570,9 @@ |
562 | 571 | function getTimestamp() { |
563 | 572 | $dbr = wfGetDB( DB_SLAVE ); |
564 | 573 | return $dbr->selectField( |
565 | | - 'localisation_file_hash', 'MAX(lfh_timestamp)', '', |
| 574 | + LocalisationUpdate::table( 'localisation_file_hash' ), |
| 575 | + 'MAX(lfh_timestamp)', |
| 576 | + '', |
566 | 577 | __METHOD__ ); |
567 | 578 | } |
568 | 579 | |