Index: branches/iwtransclusion/phase3/includes/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 | |
Index: branches/iwtransclusion/phase3/includes/Article.php |
— | — | @@ -4158,6 +4158,10 @@ |
4159 | 4159 | |
4160 | 4160 | // Invalidate caches of articles which include this page |
4161 | 4161 | $wgDeferredUpdateList[] = new HTMLCacheUpdate( $title, 'templatelinks' ); |
| 4162 | + |
| 4163 | + // Invalidate caches of distant articles which transclude this page |
| 4164 | + $wgDeferredUpdateList[] = new HTMLCacheUpdate( $title, 'globaltemplatelinks' ); |
| 4165 | + wfDoUpdates(); |
4162 | 4166 | |
4163 | 4167 | // Invalidate the caches of all pages which redirect here |
4164 | 4168 | $wgDeferredUpdateList[] = new HTMLCacheUpdate( $title, 'redirect' ); |
— | — | @@ -4330,7 +4334,7 @@ |
4331 | 4335 | } |
4332 | 4336 | |
4333 | 4337 | $dbr = wfGetDB( DB_SLAVE, array(), $wgGlobalDatabase ); |
4334 | | - $res = $dbr->select( array( 'globaltemplatelinks' ), |
| 4338 | + $res = $dbr->select( 'globaltemplatelinks', |
4335 | 4339 | array( 'gtl_to_prefix', 'gtl_to_namespace', 'gtl_to_title' ), |
4336 | 4340 | array( 'gtl_from_wiki' => wfWikiID( ), 'gtl_from_page' => $id ), |
4337 | 4341 | __METHOD__ ); |
— | — | @@ -4340,10 +4344,8 @@ |
4341 | 4345 | $result[] = Title::makeTitle( $row->gtl_to_namespace, $row->gtl_to_title, null, $row->gtl_to_prefix ); |
4342 | 4346 | } |
4343 | 4347 | } |
4344 | | - |
4345 | | - $dbr->freeResult( $res ); |
4346 | 4348 | } |
4347 | | - |
| 4349 | + |
4348 | 4350 | return $result; |
4349 | 4351 | } |
4350 | 4352 | |
Index: branches/iwtransclusion/phase3/includes/Linker.php |
— | — | @@ -1588,12 +1588,6 @@ |
1589 | 1589 | |
1590 | 1590 | $outText = ''; |
1591 | 1591 | if ( count( $templates ) > 0 ) { |
1592 | | - # Do a batch existence check |
1593 | | - $batch = new LinkBatch; |
1594 | | - foreach( $templates as $title ) { |
1595 | | - $batch->addObj( $title ); |
1596 | | - } |
1597 | | - $batch->execute(); |
1598 | 1592 | |
1599 | 1593 | # Construct the HTML |
1600 | 1594 | $outText = '<div class="mw-templatesUsedExplanation">'; |
Index: branches/iwtransclusion/phase3/includes/BacklinkCache.php |
— | — | @@ -108,6 +108,27 @@ |
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
| 112 | + * Get the distant backtemplatelinks for the table globaltemplatelinks. Cached in process memory only. |
| 113 | + * @param $table String |
| 114 | + * @param $startId Integer or false |
| 115 | + * @param $endId Integer or false |
| 116 | + * @return TitleArray |
| 117 | + */ |
| 118 | + public function getDistantTemplateLinks( ) { |
| 119 | + global $wgGlobalDatabase, $wgLocalInterwiki; |
| 120 | + |
| 121 | + $dbr = $dbr = wfGetDB( DB_SLAVE, array(), $wgGlobalDatabase ); |
| 122 | + $res = $dbr->select( |
| 123 | + array( 'globaltemplatelinks' ), |
| 124 | + array( 'gtl_from_wiki', 'gtl_from_page' ), |
| 125 | + array( 'gtl_to_prefix' => $wgLocalInterwiki, 'gtl_to_title' => $this->title->getDBkey( ) ), |
| 126 | + __METHOD__, |
| 127 | + 'GROUP BY gtl_from_wiki' |
| 128 | + ); |
| 129 | + return $res; |
| 130 | + } |
| 131 | + |
| 132 | + /** |
112 | 133 | * Get the field name prefix for a given table |
113 | 134 | */ |
114 | 135 | protected function getPrefix( $table ) { |
— | — | @@ -117,6 +138,7 @@ |
118 | 139 | 'categorylinks' => 'cl', |
119 | 140 | 'templatelinks' => 'tl', |
120 | 141 | 'redirect' => 'rd', |
| 142 | + 'globaltemplatelinks' => 'gtl', |
121 | 143 | ); |
122 | 144 | |
123 | 145 | if ( isset( $prefixes[$table] ) ) { |
Index: branches/iwtransclusion/phase3/includes/HTMLCacheUpdate.php |
— | — | @@ -46,6 +46,16 @@ |
47 | 47 | return; |
48 | 48 | } |
49 | 49 | |
| 50 | + if ( $this->mTable === 'globaltemplatelinks' ) { |
| 51 | + global $wgEnableInterwikiTemplatesTracking; |
| 52 | + |
| 53 | + if ( $wgEnableInterwikiTemplatesTracking ) { |
| 54 | + $distantPageArray = $this->mCache->getDistantTemplateLinks( 'globaltemplatelinks' ); |
| 55 | + $this->invalidateDistantTitles( $distantPageArray ); |
| 56 | + } |
| 57 | + return; |
| 58 | + } |
| 59 | + |
50 | 60 | # Get an estimate of the number of rows from the BacklinkCache |
51 | 61 | $numRows = $this->mCache->getNumLinks( $this->mTable ); |
52 | 62 | if ( $numRows > $this->mRowsPerJob * 2 ) { |
— | — | @@ -63,6 +73,7 @@ |
64 | 74 | $this->invalidateTitles( $titleArray ); |
65 | 75 | } |
66 | 76 | } |
| 77 | + |
67 | 78 | wfRunHooks( 'HTMLCacheUpdate::doUpdate', array($this->mTitle) ); |
68 | 79 | } |
69 | 80 | |
— | — | @@ -200,7 +211,35 @@ |
201 | 212 | } |
202 | 213 | } |
203 | 214 | } |
204 | | - |
| 215 | + |
| 216 | + /** |
| 217 | + * Invalidate an array of distant pages, given the wiki ID and page ID of those pages |
| 218 | + */ |
| 219 | + protected function invalidateDistantTitles( $distantPageArray ) { |
| 220 | + global $wgUseFileCache, $wgUseSquid, $wgLocalInterwiki; |
| 221 | + |
| 222 | + $pagesByWiki = array(); |
| 223 | + foreach ( $distantPageArray as $row ) { |
| 224 | + $wikiid = $row->gtl_from_wiki; |
| 225 | + if( !isset( $pagesByWiki[$wikiid] ) ) { |
| 226 | + $pagesByWiki[$wikiid] = array(); |
| 227 | + } |
| 228 | + $pagesByWiki[$wikiid][] = $row->gtl_from_page; |
| 229 | + } |
| 230 | + |
| 231 | + foreach ( $pagesByWiki as $wikiid => $pages ) { |
| 232 | + $dbw = wfGetDB( DB_MASTER, array( ), $wikiid ); |
| 233 | + $timestamp = $dbw->timestamp(); |
| 234 | + $batches = array_chunk( $pages, $this->mRowsPerQuery ); |
| 235 | + foreach ( $batches as $batch ) { |
| 236 | + $dbw->update( 'page', |
| 237 | + array( 'page_touched' => $timestamp ), |
| 238 | + array( 'page_id IN (' . $dbw->makeList( $batch ) . ')' ), |
| 239 | + __METHOD__ |
| 240 | + ); |
| 241 | + } |
| 242 | + } |
| 243 | + } |
205 | 244 | } |
206 | 245 | |
207 | 246 | /** |
Index: branches/iwtransclusion/phase3/includes/DefaultSettings.php |
— | — | @@ -2687,13 +2687,35 @@ |
2688 | 2688 | $wgPreprocessorCacheThreshold = 1000; |
2689 | 2689 | |
2690 | 2690 | /** |
2691 | | - * Enable interwiki transcluding. Only when iw_trans=1. |
| 2691 | + * Enable interwiki transcluding. Only when iw_trans=1 in the interwiki table. |
| 2692 | + * If the interwiki prefix is associated with a wiki ID in the interwiki table, |
| 2693 | + * then the distant templates will be retrieved in the distant DB. If there is |
| 2694 | + * no wiki ID but a API URL for that prefix, the distant templates will be |
| 2695 | + * retrieved using the API and cached in memcached. |
2692 | 2696 | */ |
2693 | | -$wgEnableScaryTranscluding = false; |
| 2697 | +$wgEnableInterwikiTranscluding = false; |
2694 | 2698 | |
2695 | 2699 | /** |
2696 | | - * Expiry time for interwiki transclusion |
| 2700 | + * If $wgEnableInterwikiTranscluding is set to true and if an interwiki prefix |
| 2701 | + * is associated with a wiki ID, then, this option should be set to true to |
| 2702 | + * enable the cache invalidation of the distant pages when the local templates |
| 2703 | + * are edited and also to display the list of the distant templates used by |
| 2704 | + * the local pages. Enabling this requires to set up a global shared database |
| 2705 | + * (see next option $wgGlobalDatabase). |
2697 | 2706 | */ |
| 2707 | +$wgEnableInterwikiTemplatesTracking = false; |
| 2708 | + |
| 2709 | +/** |
| 2710 | + * If $wgEnableInterwikiTemplatesTracking is set to true, this option should |
| 2711 | + * contain the wiki ID of the database that hosts the globaltemplatelinks table. |
| 2712 | + */ |
| 2713 | +$wgGlobalDatabase = ''; |
| 2714 | + |
| 2715 | +/** |
| 2716 | + * If $wgEnableInterwikiTranscluding is set to true and if an interwiki |
| 2717 | + * prefix is associated with an API URL and no wiki ID, this will be |
| 2718 | + * the expiry time for the transcluded templates cached in memcached. |
| 2719 | + */ |
2698 | 2720 | $wgTranscludeCacheExpiry = 3600; |
2699 | 2721 | |
2700 | 2722 | /** @} */ # end of parser settings } |