Index: branches/RL2/extensions/Gadgets/Gadgets.php |
— | — | @@ -44,16 +44,18 @@ |
45 | 45 | * 'dbUser' => 'username', // User name for the foreign wiki's database |
46 | 46 | * 'dbPassword' => 'password', // Password for the foreign wiki's database |
47 | 47 | * 'dbName' => 'mediawikiwiki', // Name of the foreign wiki's database |
48 | | - * // TODO: Make this the default? |
| 48 | + * // TODO: Make this the default? |
49 | 49 | * 'dbFlags' => ( $wgDebugDumpSql ? DBO_DEBUG : 0 ) | DBO_DEFAULT // Use this value unless you know what you're doing |
50 | 50 | * 'tablePrefix' => 'mw_', // Table prefix for the foreign wiki's database, or '' if no prefix |
51 | | - * 'hasSharedCache' => true, // Whether the foreign wiki's cache is accessible through $wgMemc |
| 51 | + * 'hasSharedCache' => true, // Whether the foreign wiki's cache is accessible through $wgMemc |
| 52 | + * 'cacheTimeout' => 600, // Expiry for locally cached data, in seconds (optional; default is 600) |
52 | 53 | * ); |
53 | 54 | * |
54 | 55 | * For foreign API-based gadget repositories, use: |
55 | 56 | * $wgGadgetRepositories[] = array( |
56 | 57 | * 'class' => 'ForeignAPIGadgetRepo', |
57 | 58 | * 'source' => 'mediawikiwiki', |
| 59 | + * 'cacheTimeout' => 600, // Expiry for locally cached data, in seconds (optional; default is 600) |
58 | 60 | * ); |
59 | 61 | */ |
60 | 62 | $wgGadgetRepositories = array(); |
— | — | @@ -66,18 +68,6 @@ |
67 | 69 | */ |
68 | 70 | $wgGadgetEnableSharing = true; |
69 | 71 | |
70 | | -/** |
71 | | - * For how long gadget metadata obtained from a foreign wiki should be cached locally. |
72 | | - * Defaults to 600 seconds (10 minutes). If set to zero, data will be cached FOREVER. |
73 | | - * |
74 | | - * If you have a gadget repository (see $wgGadgetRepositories) with 'class' => 'ForeignAPIGadgetRepo', |
75 | | - * or a gadget repository with 'class' => 'ForeignDBGadgetRepo' and 'hasSharedCache' => false, |
76 | | - * this value controls how long it will take before changes to gadgets on the foreign wiki |
77 | | - * will show up on your wiki. For local gadgets and for foreign repositories with 'hasSharedCache' => true, |
78 | | - * changes will show up immediately. |
79 | | - */ |
80 | | -$wgGadgetsForeignCacheTimeout = 600; |
81 | | - |
82 | 72 | /*** Setup ***/ |
83 | 73 | |
84 | 74 | define( 'NS_GADGET', 2300 ); |
Index: branches/RL2/extensions/Gadgets/backend/ForeignDBGadgetRepo.php |
— | — | @@ -2,7 +2,7 @@ |
3 | 3 | /** |
4 | 4 | * Gadget repository that gets its gadgets from a foreign database. |
5 | 5 | * |
6 | | - * Options (all of these are MANDATORY): |
| 6 | + * Options (all of these are MANDATORY except cacheTimeout): |
7 | 7 | * 'source': Name of the source these gadgets are loaded from, as defined in ResourceLoader |
8 | 8 | * 'dbType': Database type, see DatabaseBase::factory() |
9 | 9 | * 'dbServer': Database host |
— | — | @@ -12,11 +12,13 @@ |
13 | 13 | * 'dbFlags': Bitmap of the DBO_* flags. Recommended value is ( $wgDebugDumpSql ? DBO_DEBUG : 0 ) | DBO_DEFAULT |
14 | 14 | * 'tablePrefix': Table prefix |
15 | 15 | * 'hasSharedCache': Whether the foreign wiki's cache is accessible through $wgMemc |
| 16 | + * 'cacheTimeout': Expiry for locally cached data, in seconds (optional; default is 600) |
16 | 17 | */ |
17 | 18 | class ForeignDBGadgetRepo extends LocalGadgetRepo { |
18 | 19 | protected $db = null; |
19 | 20 | |
20 | | - protected $source, $dbServer, $dbUser, $dbPassword, $dbName, $dbFlags, $tablePrefix, $hasSharedCache; |
| 21 | + protected $source, $dbServer, $dbUser, $dbPassword, $dbName, $dbFlags, $tablePrefix, $hasSharedCache, |
| 22 | + $cacheTimeout = 600; |
21 | 23 | |
22 | 24 | /** |
23 | 25 | * Constructor. |
— | — | @@ -30,6 +32,10 @@ |
31 | 33 | foreach ( $optionKeys as $optionKey ) { |
32 | 34 | $this->{$optionKey} = $options[$optionKey]; |
33 | 35 | } |
| 36 | + |
| 37 | + if ( isset( $options['cacheTimeout'] ) ) { |
| 38 | + $this->cacheTimeout = $options['cacheTimeout']; |
| 39 | + } |
34 | 40 | } |
35 | 41 | |
36 | 42 | public function isWriteable() { |
— | — | @@ -92,14 +98,13 @@ |
93 | 99 | } |
94 | 100 | |
95 | 101 | protected function getCacheExpiry( $id ) { |
96 | | - global $wgGadgetsForeignCacheTimeout; |
97 | 102 | if ( $this->hasSharedCache ) { |
98 | 103 | // We're using the other wiki's local cache, and |
99 | 104 | // the other wiki will be handling invalidation. |
100 | 105 | // So cache forever. |
101 | 106 | return 0; |
102 | 107 | } else { |
103 | | - return $wgGadgetsForeignCacheTimeout; |
| 108 | + return $this->cacheTimeout; |
104 | 109 | } |
105 | 110 | } |
106 | 111 | |
Index: branches/RL2/extensions/Gadgets/backend/ForeignAPIGadgetRepo.php |
— | — | @@ -4,6 +4,7 @@ |
5 | 5 | * |
6 | 6 | * Options (all of these are MANDATORY): |
7 | 7 | * 'source': Name of the source these gadgets are loaded from, as defined in ResourceLoader |
| 8 | + * 'cacheTimeout': Expiry for locally cached data, in seconds (optional; default is 600) |
8 | 9 | */ |
9 | 10 | class ForeignAPIGadgetRepo extends CachedGadgetRepo { |
10 | 11 | /** |
— | — | @@ -13,7 +14,7 @@ |
14 | 15 | */ |
15 | 16 | const VERSION = '1.0'; |
16 | 17 | |
17 | | - protected $source, $apiURL; |
| 18 | + protected $source, $apiURL, $cacheTimeout = 600; |
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Constructor. |
— | — | @@ -25,6 +26,9 @@ |
26 | 27 | |
27 | 28 | $this->source = $options['source']; |
28 | 29 | $this->apiURL = $wgResourceLoaderSources[$this->source]['apiScript']; |
| 30 | + if ( isset( $options['cacheTimeout'] ) ) { |
| 31 | + $this->cacheTimeout = $options['cacheTimeout']; |
| 32 | + } |
29 | 33 | } |
30 | 34 | |
31 | 35 | /*** Protected methods inherited from CachedGadgetRepo ***/ |
— | — | @@ -62,8 +66,7 @@ |
63 | 67 | } |
64 | 68 | |
65 | 69 | protected function getCacheExpiry( $id ) { |
66 | | - global $wgGadgetsForeignCacheTimeout; |
67 | | - return $wgGadgetsForeignCacheTimeout; |
| 70 | + return $this->cacheTimeout; |
68 | 71 | } |
69 | 72 | |
70 | 73 | /*** Protected methods ***/ |