Index: branches/iwtransclusion/phase3v3/includes/Linker.php |
— | — | @@ -1659,12 +1659,6 @@ |
1660 | 1660 | |
1661 | 1661 | $outText = ''; |
1662 | 1662 | if ( count( $templates ) > 0 ) { |
1663 | | - # Do a batch existence check |
1664 | | - $batch = new LinkBatch; |
1665 | | - foreach( $templates as $title ) { |
1666 | | - $batch->addObj( $title ); |
1667 | | - } |
1668 | | - $batch->execute(); |
1669 | 1663 | |
1670 | 1664 | # Construct the HTML |
1671 | 1665 | $outText = '<div class="mw-templatesUsedExplanation">'; |
Index: branches/iwtransclusion/phase3v3/includes/interwiki/Interwiki.php |
— | — | @@ -9,6 +9,7 @@ |
10 | 10 | * All information is loaded on creation when called by Interwiki::fetch( $prefix ). |
11 | 11 | * All work is done on slave, because this should *never* change (except during |
12 | 12 | * schema updates etc, which aren't wiki-related) |
| 13 | + * This class also contains the functions that allow interwiki templates transclusion. |
13 | 14 | */ |
14 | 15 | class Interwiki { |
15 | 16 | |
Property changes on: branches/iwtransclusion/phase3v3/includes/interwiki/Interwiki.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
16 | 17 | Merged /branches/iwtransclusion/phase3/includes/interwiki/Interwiki.php:r70802 |
17 | 18 | Merged /branches/iwtransclusion/phase3v2/includes/interwiki/Interwiki.php:r87109 |
Index: branches/iwtransclusion/phase3v3/includes/BacklinkCache.php |
— | — | @@ -175,6 +175,27 @@ |
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
| 179 | + * Get the distant backtemplatelinks for the table globaltemplatelinks. Cached in process memory only. |
| 180 | + * @param $table String |
| 181 | + * @param $startId Integer or false |
| 182 | + * @param $endId Integer or false |
| 183 | + * @return TitleArray |
| 184 | + */ |
| 185 | + public function getDistantTemplateLinks( ) { |
| 186 | + global $wgGlobalDatabase, $wgLocalInterwiki; |
| 187 | + |
| 188 | + $dbr = $dbr = wfGetDB( DB_SLAVE, array(), $wgGlobalDatabase ); |
| 189 | + $res = $dbr->select( |
| 190 | + array( 'globaltemplatelinks' ), |
| 191 | + array( 'gtl_from_wiki', 'gtl_from_page' ), |
| 192 | + array( 'gtl_to_prefix' => $wgLocalInterwiki, 'gtl_to_title' => $this->title->getDBkey( ) ), |
| 193 | + __METHOD__, |
| 194 | + 'GROUP BY gtl_from_wiki' |
| 195 | + ); |
| 196 | + return $res; |
| 197 | + } |
| 198 | + |
| 199 | + /** |
179 | 200 | * Get the field name prefix for a given table |
180 | 201 | * @param $table String |
181 | 202 | */ |
— | — | @@ -185,6 +206,7 @@ |
186 | 207 | 'categorylinks' => 'cl', |
187 | 208 | 'templatelinks' => 'tl', |
188 | 209 | 'redirect' => 'rd', |
| 210 | + 'globaltemplatelinks' => 'gtl', |
189 | 211 | ); |
190 | 212 | |
191 | 213 | if ( isset( $prefixes[$table] ) ) { |
Index: branches/iwtransclusion/phase3v3/includes/cache/HTMLCacheUpdate.php |
— | — | @@ -51,6 +51,16 @@ |
52 | 52 | return; |
53 | 53 | } |
54 | 54 | |
| 55 | + if ( $this->mTable === 'globaltemplatelinks' ) { |
| 56 | + global $wgEnableInterwikiTemplatesTracking; |
| 57 | + |
| 58 | + if ( $wgEnableInterwikiTemplatesTracking ) { |
| 59 | + $distantPageArray = $this->mCache->getDistantTemplateLinks( 'globaltemplatelinks' ); |
| 60 | + $this->invalidateDistantTitles( $distantPageArray ); |
| 61 | + } |
| 62 | + return; |
| 63 | + } |
| 64 | + |
55 | 65 | # Get an estimate of the number of rows from the BacklinkCache |
56 | 66 | $numRows = $this->mCache->getNumLinks( $this->mTable ); |
57 | 67 | if ( $numRows > $this->mRowsPerJob * 2 ) { |
— | — | @@ -68,6 +78,7 @@ |
69 | 79 | $this->invalidateTitles( $titleArray ); |
70 | 80 | } |
71 | 81 | } |
| 82 | + wfRunHooks( 'HTMLCacheUpdate::doUpdate', array($this->mTitle) ); |
72 | 83 | } |
73 | 84 | |
74 | 85 | /** |
— | — | @@ -197,7 +208,35 @@ |
198 | 209 | } |
199 | 210 | } |
200 | 211 | } |
201 | | - |
| 212 | + |
| 213 | + /** |
| 214 | + * Invalidate an array of distant pages, given the wiki ID and page ID of those pages |
| 215 | + */ |
| 216 | + protected function invalidateDistantTitles( $distantPageArray ) { |
| 217 | + global $wgUseFileCache, $wgUseSquid, $wgLocalInterwiki; |
| 218 | + |
| 219 | + $pagesByWiki = array(); |
| 220 | + foreach ( $distantPageArray as $row ) { |
| 221 | + $wikiid = $row->gtl_from_wiki; |
| 222 | + if( !isset( $pagesByWiki[$wikiid] ) ) { |
| 223 | + $pagesByWiki[$wikiid] = array(); |
| 224 | + } |
| 225 | + $pagesByWiki[$wikiid][] = $row->gtl_from_page; |
| 226 | + } |
| 227 | + |
| 228 | + foreach ( $pagesByWiki as $wikiid => $pages ) { |
| 229 | + $dbw = wfGetDB( DB_MASTER, array( ), $wikiid ); |
| 230 | + $timestamp = $dbw->timestamp(); |
| 231 | + $batches = array_chunk( $pages, $this->mRowsPerQuery ); |
| 232 | + foreach ( $batches as $batch ) { |
| 233 | + $dbw->update( 'page', |
| 234 | + array( 'page_touched' => $timestamp ), |
| 235 | + array( 'page_id IN (' . $dbw->makeList( $batch ) . ')' ), |
| 236 | + __METHOD__ |
| 237 | + ); |
| 238 | + } |
| 239 | + } |
| 240 | + } |
202 | 241 | } |
203 | 242 | |
204 | 243 | /** |
Index: branches/iwtransclusion/phase3v3/includes/WikiPage.php |
— | — | @@ -2254,6 +2254,10 @@ |
2255 | 2255 | |
2256 | 2256 | // Invalidate caches of articles which include this page |
2257 | 2257 | $wgDeferredUpdateList[] = new HTMLCacheUpdate( $title, 'templatelinks' ); |
| 2258 | + |
| 2259 | + // Invalidate caches of distant articles which transclude this page |
| 2260 | + $wgDeferredUpdateList[] = new HTMLCacheUpdate( $title, 'globaltemplatelinks' ); |
| 2261 | + wfDoUpdates(); |
2258 | 2262 | |
2259 | 2263 | // Invalidate the caches of all pages which redirect here |
2260 | 2264 | $wgDeferredUpdateList[] = new HTMLCacheUpdate( $title, 'redirect' ); |
— | — | @@ -2315,7 +2319,7 @@ |
2316 | 2320 | } |
2317 | 2321 | |
2318 | 2322 | $dbr = wfGetDB( DB_SLAVE, array(), $wgGlobalDatabase ); |
2319 | | - $res = $dbr->select( array( 'globaltemplatelinks' ), |
| 2323 | + $res = $dbr->select( 'globaltemplatelinks', |
2320 | 2324 | array( 'gtl_to_prefix', 'gtl_to_namespace', 'gtl_to_title' ), |
2321 | 2325 | array( 'gtl_from_wiki' => wfWikiID( ), 'gtl_from_page' => $id ), |
2322 | 2326 | __METHOD__ ); |
— | — | @@ -2325,8 +2329,6 @@ |
2326 | 2330 | $result[] = Title::makeTitle( $row->gtl_to_namespace, $row->gtl_to_title, null, $row->gtl_to_prefix ); |
2327 | 2331 | } |
2328 | 2332 | } |
2329 | | - |
2330 | | - $dbr->freeResult( $res ); |
2331 | 2333 | } |
2332 | 2334 | |
2333 | 2335 | return $result; |
Index: branches/iwtransclusion/phase3v3/includes/DefaultSettings.php |
— | — | @@ -2943,13 +2943,35 @@ |
2944 | 2944 | $wgPreprocessorCacheThreshold = 1000; |
2945 | 2945 | |
2946 | 2946 | /** |
2947 | | - * Enable interwiki transcluding. Only when iw_trans=1. |
| 2947 | + * Enable interwiki transcluding. Only when iw_trans=1 in the interwiki table. |
| 2948 | + * If the interwiki prefix is associated with a wiki ID in the interwiki table, |
| 2949 | + * then the distant templates will be retrieved in the distant DB. If there is |
| 2950 | + * no wiki ID but a API URL for that prefix, the distant templates will be |
| 2951 | + * retrieved using the API and cached in memcached. |
2948 | 2952 | */ |
2949 | | -$wgEnableScaryTranscluding = false; |
| 2953 | +$wgEnableInterwikiTranscluding = false; |
2950 | 2954 | |
2951 | 2955 | /** |
2952 | | - * Expiry time for interwiki transclusion |
| 2956 | + * If $wgEnableInterwikiTranscluding is set to true and if an interwiki prefix |
| 2957 | + * is associated with a wiki ID, then, this option should be set to true to |
| 2958 | + * enable the cache invalidation of the distant pages when the local templates |
| 2959 | + * are edited and also to display the list of the distant templates used by |
| 2960 | + * the local pages. Enabling this requires to set up a global shared database |
| 2961 | + * (see next option $wgGlobalDatabase). |
2953 | 2962 | */ |
| 2963 | +$wgEnableInterwikiTemplatesTracking = false; |
| 2964 | + |
| 2965 | +/** |
| 2966 | + * If $wgEnableInterwikiTemplatesTracking is set to true, this option should |
| 2967 | + * contain the wiki ID of the database that hosts the globaltemplatelinks table. |
| 2968 | + */ |
| 2969 | +$wgGlobalDatabase = ''; |
| 2970 | + |
| 2971 | +/** |
| 2972 | + * If $wgEnableInterwikiTranscluding is set to true and if an interwiki |
| 2973 | + * prefix is associated with an API URL and no wiki ID, this will be |
| 2974 | + * the expiry time for the transcluded templates cached in memcached. |
| 2975 | + */ |
2954 | 2976 | $wgTranscludeCacheExpiry = 3600; |
2955 | 2977 | |
2956 | 2978 | /** @} */ # end of parser settings } |