r70764 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70763‎ | r70764 | r70765 >
Date:14:46, 9 August 2010
Author:peter17
Status:resolved (Comments)
Tags:
Comment:
Fix remarks about r70576; display the distant templates below the edit textarea
Modified paths:
  • /branches/iwtransclusion/phase3/includes/Article.php (modified) (history)
  • /branches/iwtransclusion/phase3/includes/EditPage.php (modified) (history)
  • /branches/iwtransclusion/phase3/includes/Linker.php (modified) (history)
  • /branches/iwtransclusion/phase3/includes/LinksUpdate.php (modified) (history)
  • /branches/iwtransclusion/phase3/includes/OutputPage.php (modified) (history)
  • /branches/iwtransclusion/phase3/includes/Title.php (modified) (history)
  • /branches/iwtransclusion/phase3/includes/db/Database.php (modified) (history)
  • /branches/iwtransclusion/phase3/includes/parser/Parser.php (modified) (history)
  • /branches/iwtransclusion/phase3/includes/parser/ParserOutput.php (modified) (history)
  • /branches/iwtransclusion/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /branches/iwtransclusion/phase3/maintenance/archives/patch-globaltemplatelinks.sql (modified) (history)
  • /branches/iwtransclusion/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: branches/iwtransclusion/phase3/maintenance/archives/patch-globaltemplatelinks.sql
@@ -17,15 +17,19 @@
1818 -- Needed for display purposes
1919 gtl_from_title varchar(255) binary NOT NULL,
2020
21 - -- The wiki ID of the wiki that hosts the transcluded page
22 - gtl_to_wiki varchar(64) NOT NULL,
 21+ -- The interwiki prefix of the wiki that hosts the transcluded page
 22+ gtl_to_prefix varchar(32) NOT NULL,
2323
2424 -- The namespace of the transcluded page on that wiki
2525 gtl_to_namespace int NOT NULL,
2626
 27+ -- The namespace name of transcluded page
 28+ -- Needed for display purposes, since the local namespace ID doesn't necessarily match a distant one
 29+ gtl_to_namespacetext varchar(255) NOT NULL,
 30+
2731 -- The title of the transcluded page on that wiki
2832 gtl_to_title varchar(255) binary NOT NULL
2933 ) /*$wgDBTableOptions*/;
3034
31 -CREATE UNIQUE INDEX /*i*/gtl_to_from ON /*_*/globaltemplatelinks (gtl_to_wiki, gtl_to_namespace, gtl_to_title, gtl_from_wiki, gtl_from_page);
32 -CREATE UNIQUE INDEX /*i*/gtl_from_to ON /*_*/globaltemplatelinks (gtl_from_wiki, gtl_from_page, gtl_to_wiki, gtl_to_namespace, gtl_to_title);
 35+CREATE UNIQUE INDEX /*i*/gtl_to_from ON /*_*/globaltemplatelinks (gtl_to_prefix, gtl_to_namespace, gtl_to_title, gtl_from_wiki, gtl_from_page);
 36+CREATE UNIQUE INDEX /*i*/gtl_from_to ON /*_*/globaltemplatelinks (gtl_from_wiki, gtl_from_page, gtl_to_prefix, gtl_to_namespace, gtl_to_title);
Index: branches/iwtransclusion/phase3/maintenance/language/messages.inc
@@ -586,6 +586,9 @@
587587 'templatesused',
588588 'templatesusedpreview',
589589 'templatesusedsection',
 590+ 'distanttemplatesused',
 591+ 'distanttemplatesusedpreview',
 592+ 'distanttemplatesusedsection',
590593 'template-protected',
591594 'template-semiprotected',
592595 'hiddencategories',
Index: branches/iwtransclusion/phase3/includes/Article.php
@@ -3172,7 +3172,7 @@
31733173 * @return boolean true if successful
31743174 */
31753175 public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true ) {
3176 - global $wgDeferredUpdateList, $wgUseTrackbacks, $wgGlobalDB, $wgWikiID;
 3176+ global $wgDeferredUpdateList, $wgUseTrackbacks, $wgEnableInterwikiTemplatesTracking, $wgGlobalDatabase;
31773177
31783178 wfDebug( __METHOD__ . "\n" );
31793179
@@ -3271,11 +3271,11 @@
32723272 $dbw->delete( 'langlinks', array( 'll_from' => $id ) );
32733273 $dbw->delete( 'redirect', array( 'rd_from' => $id ) );
32743274
3275 - if ( $wgGlobalDB ) {
3276 - $dbw2 = wfGetDB( DB_MASTER, array(), $wgGlobalDB );
 3275+ if ( $wgEnableInterwikiTemplatesTracking && $wgGlobalDatabase ) {
 3276+ $dbw2 = wfGetDB( DB_MASTER, array(), $wgGlobalDatabase );
32773277 $dbw2->delete( 'globaltemplatelinks',
3278 - array( 'gtl_from_wiki' => $wgWikiID,
3279 - 'gtl_from_page' => $id )
 3278+ array( 'gtl_from_wiki' => wfWikiID( ),
 3279+ 'gtl_from_page' => $id )
32803280 );
32813281 }
32823282 }
@@ -4312,6 +4312,42 @@
43134313 }
43144314
43154315 /**
 4316+ * Return a list of distant templates used by this article.
 4317+ * Uses the globaltemplatelinks table
 4318+ *
 4319+ * @return Array of Title objects
 4320+ */
 4321+ public function getUsedDistantTemplates() {
 4322+ global $wgGlobalDatabase;
 4323+
 4324+ $result = array();
 4325+
 4326+ if ( $wgGlobalDatabase ) {
 4327+ $id = $this->mTitle->getArticleID();
 4328+
 4329+ if ( $id == 0 ) {
 4330+ return array();
 4331+ }
 4332+
 4333+ $dbr = wfGetDB( DB_SLAVE, array(), $wgGlobalDatabase );
 4334+ $res = $dbr->select( array( 'globaltemplatelinks' ),
 4335+ array( 'gtl_to_prefix', 'gtl_to_namespace', 'gtl_to_title' ),
 4336+ array( 'gtl_from_wiki' => wfWikiID( ), 'gtl_from_page' => $id ),
 4337+ __METHOD__ );
 4338+
 4339+ if ( $res !== false ) {
 4340+ foreach ( $res as $row ) {
 4341+ $result[] = Title::makeTitle( $row->gtl_to_namespace, $row->gtl_to_title, null, $row->gtl_to_prefix );
 4342+ }
 4343+ }
 4344+
 4345+ $dbr->freeResult( $res );
 4346+ }
 4347+
 4348+ return $result;
 4349+ }
 4350+
 4351+ /**
43164352 * Returns a list of hidden categories this page is a member of.
43174353 * Uses the page_props and categorylinks tables.
43184354 *
Index: branches/iwtransclusion/phase3/includes/parser/Parser.php
@@ -2959,7 +2959,7 @@
29602960 * @private
29612961 */
29622962 function braceSubstitution( $piece, $frame ) {
2963 - global $wgContLang, $wgNonincludableNamespaces;
 2963+ global $wgContLang, $wgNonincludableNamespaces, $wgEnableInterwikiTranscluding, $wgEnableInterwikiTemplatesTracking;
29642964 wfProfileIn( __METHOD__ );
29652965 wfProfileIn( __METHOD__.'-setup' );
29662966
@@ -3172,12 +3172,15 @@
31733173 $text = "[[:$titleText]]";
31743174 $found = true;
31753175 }
3176 - } elseif ( $title->isTrans() ) {
 3176+ } elseif ( $wgEnableInterwikiTranscluding && $title->isTrans() ) {
31773177 // TODO: Work by Peter17 in progress
31783178
31793179 $text = Interwiki::interwikiTransclude( $title );
3180 - $this->registerDistantTemplate( $title );
31813180
 3181+ if ( $wgEnableInterwikiTemplatesTracking ) {
 3182+ $this->registerDistantTemplate( $title );
 3183+ }
 3184+
31823185 if ( $text !== false ) {
31833186 # Preprocess it like a template
31843187 $text = $this->preprocessToDom( $text, self::PTD_FOR_INCLUSION );
@@ -3329,8 +3332,7 @@
33303333 * Register a distant template as used
33313334 */
33323335 function registerDistantTemplate( $title ) {
3333 - $templateCb = array( 'Parser', 'distantTemplateCallback' );
3334 - $stuff = call_user_func( $templateCb, $title, $this );
 3336+ $stuff = Parser::distantTemplateCallback( $title, $this );
33353337 $text = $stuff['text'];
33363338 $finalTitle = isset( $stuff['finalTitle'] ) ? $stuff['finalTitle'] : $title;
33373339 if ( isset( $stuff['deps'] ) ) {
Index: branches/iwtransclusion/phase3/includes/parser/ParserOutput.php
@@ -209,21 +209,27 @@
210210 }
211211
212212 function addDistantTemplate( $title, $page_id, $rev_id ) {
213 - $wikiid = $title->getTransWikiID();
214 - if ( $wikiid !=='' ) {
 213+ $prefix = $title->getInterwiki();
 214+ if ( $prefix !=='' ) {
215215 $ns = $title->getNamespace();
216216 $dbk = $title->getDBkey();
217 - if ( !isset( $this->mDistantTemplates[$wikiid] ) ) {
218 - $this->mDistantTemplates[$wikiid] = array();
 217+
 218+ if ( !isset( $this->mDistantTemplates[$prefix] ) ) {
 219+ $this->mDistantTemplates[$prefix] = array();
219220 }
220 - if ( !isset( $this->mDistantTemplates[$wikiid][$ns] ) ) {
221 - $this->mDistantTemplates[$wikiid][$ns] = array();
 221+ if ( !isset( $this->mDistantTemplates[$prefix][$ns] ) ) {
 222+ $this->mDistantTemplates[$prefix][$ns] = array();
222223 }
223 - $this->mDistantTemplates[$wikiid][$ns][$dbk] = $page_id;
224 - if ( !isset( $this->mDistantTemplateIds[$wikiid][$ns] ) ) {
225 - $this->mDistantTemplateIds[$wikiid][$ns] = array();
 224+ $this->mDistantTemplates[$prefix][$ns][$dbk] = $page_id;
 225+
 226+ // For versioning
 227+ if ( !isset( $this->mDistantTemplateIds[$prefix] ) ) {
 228+ $this->mDistantTemplateIds[$prefix] = array();
226229 }
227 - $this->mDistantTemplateIds[$wikiid][$ns][$dbk] = $rev_id; // For versioning
 230+ if ( !isset( $this->mDistantTemplateIds[$prefix][$ns] ) ) {
 231+ $this->mDistantTemplateIds[$prefix][$ns] = array();
 232+ }
 233+ $this->mDistantTemplateIds[$prefix][$ns][$dbk] = $rev_id;
228234 }
229235 }
230236
Index: branches/iwtransclusion/phase3/includes/Linker.php
@@ -1575,6 +1575,48 @@
15761576 }
15771577
15781578 /**
 1579+ * Returns HTML for the "templates used on this page" list.
 1580+ *
 1581+ * @param $templates Array of templates from Article::getUsedTemplate
 1582+ * or similar
 1583+ * @param $preview Boolean: whether this is for a preview
 1584+ * @param $section Boolean: whether this is for a section edit
 1585+ * @return String: HTML output
 1586+ */
 1587+ public function formatDistantTemplates( $templates, $preview = false, $section = false ) {
 1588+ wfProfileIn( __METHOD__ );
 1589+
 1590+ $outText = '';
 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+
 1599+ # Construct the HTML
 1600+ $outText = '<div class="mw-templatesUsedExplanation">';
 1601+ if ( $preview ) {
 1602+ $outText .= wfMsgExt( 'distanttemplatesusedpreview', array( 'parse' ), count( $templates ) );
 1603+ } elseif ( $section ) {
 1604+ $outText .= wfMsgExt( 'distanttemplatesusedsection', array( 'parse' ), count( $templates ) );
 1605+ } else {
 1606+ $outText .= wfMsgExt( 'distanttemplatesused', array( 'parse' ), count( $templates ) );
 1607+ }
 1608+ $outText .= "</div><ul>\n";
 1609+
 1610+ usort( $templates, array( 'Title', 'compare' ) );
 1611+ foreach ( $templates as $titleObj ) {
 1612+ $outText .= '<li>' . $this->link( $titleObj ) . '</li>';
 1613+ }
 1614+ $outText .= '</ul>';
 1615+ }
 1616+ wfProfileOut( __METHOD__ );
 1617+ return $outText;
 1618+ }
 1619+
 1620+ /**
15791621 * Returns HTML for the "hidden categories on this page" list.
15801622 *
15811623 * @param $hiddencats Array of hidden categories from Article::getHiddenCategories
Index: branches/iwtransclusion/phase3/includes/db/Database.php
@@ -1287,7 +1287,7 @@
12881288 * The keys on each level may be either integers or strings.
12891289 *
12901290 * @param $data Array: organized as 3-d array(baseKeyVal => array(middleKeyVal => array(subKeyVal => <ignored>, ...), ...), ...)
1291 - * @param $baseKey String: field name to match the base-level keys to (eg 'gtl_to_wikiid')
 1291+ * @param $baseKey String: field name to match the base-level keys to (eg 'gtl_to_prefix')
12921292 * @param $middleKey String: field name to match the middle-level keys to (eg 'gtl_to_namespace')
12931293 * @param $subKey String: field name to match the sub-level keys to (eg 'gtl_to_title')
12941294 * @return Mixed: string SQL fragment, or false if no items in array.
@@ -1297,9 +1297,12 @@
12981298 foreach ( $data as $base => $subdata ) {
12991299 foreach ( $subdata as $middle => $sub ) {
13001300 if ( count( $sub ) ) {
1301 - $conds[] = $this->makeList(
1302 - array( $baseKey => $base, $middleKey => $middle, $subKey => array_keys( $sub ) ),
1303 - LIST_AND);
 1301+ $conds[] = $this->makeList(
 1302+ array( $baseKey => $base,
 1303+ $middleKey => $middle,
 1304+ $subKey => array_keys( $sub ) ),
 1305+ LIST_AND
 1306+ );
13041307 }
13051308 }
13061309 }
Index: branches/iwtransclusion/phase3/includes/EditPage.php
@@ -1189,7 +1189,7 @@
11901190 * near the top, for captchas and the like.
11911191 */
11921192 function showEditForm( $formCallback=null ) {
1193 - global $wgOut, $wgUser, $wgTitle;
 1193+ global $wgOut, $wgUser, $wgTitle, $wgEnableInterwikiTranscluding, $wgEnableInterwikiTemplatesTracking;
11941194
11951195 # If $wgTitle is null, that means we're in API mode.
11961196 # Some hook probably called this function without checking
@@ -1241,6 +1241,9 @@
12421242
12431243 $templates = $this->getTemplates();
12441244 $formattedtemplates = $sk->formatTemplates( $templates, $this->preview, $this->section != '');
 1245+
 1246+ $distantTemplates = $this->getDistantTemplates();
 1247+ $formattedDistantTemplates = $sk->formatDistantTemplates( $distantTemplates, $this->preview, $this->section != '' );
12451248
12461249 $hiddencats = $this->mArticle->getHiddenCategories();
12471250 $formattedhiddencats = $sk->formatHiddenCategories( $hiddencats );
@@ -1331,6 +1334,21 @@
13321335 <div class='templatesUsed'>
13331336 {$formattedtemplates}
13341337 </div>
 1338+HTML
 1339+);
 1340+
 1341+ if ( $wgEnableInterwikiTranscluding && $wgEnableInterwikiTemplatesTracking ) {
 1342+ $wgOut->addHTML( <<<HTML
 1343+{$this->editFormTextAfterTools}
 1344+<div class='distantTemplatesUsed'>
 1345+{$formattedDistantTemplates}
 1346+</div>
 1347+HTML
 1348+);
 1349+ }
 1350+
 1351+ $wgOut->addHTML( <<<HTML
 1352+{$this->editFormTextAfterTools}
13351353 <div class='hiddencats'>
13361354 {$formattedhiddencats}
13371355 </div>
@@ -1949,6 +1967,28 @@
19501968 return $this->mArticle->getUsedTemplates();
19511969 }
19521970 }
 1971+
 1972+ function getDistantTemplates() {
 1973+ global $wgEnableInterwikiTemplatesTracking;
 1974+ if ( !$wgEnableInterwikiTemplatesTracking ) {
 1975+ return array( );
 1976+ }
 1977+ if ( $this->preview || $this->section != '' ) {
 1978+ $templates = array();
 1979+ if ( !isset( $this->mParserOutput ) ) return $templates;
 1980+ $templatesList = $this->mParserOutput->getDistantTemplates();
 1981+ foreach( $templatesList as $prefix => $templatesbyns ) {
 1982+ foreach( $templatesbyns as $ns => $template ) {
 1983+ foreach( array_keys( $template ) as $dbk ) {
 1984+ $templates[] = Title::makeTitle( $ns, $dbk, null, $prefix );
 1985+ }
 1986+ }
 1987+ }
 1988+ return $templates;
 1989+ } else {
 1990+ return $this->mArticle->getUsedDistantTemplates();
 1991+ }
 1992+ }
19531993
19541994 /**
19551995 * Call the stock "user is blocked" page
Index: branches/iwtransclusion/phase3/includes/OutputPage.php
@@ -1895,7 +1895,7 @@
18961896 * @param $action String: action that was denied or null if unknown
18971897 */
18981898 public function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
1899 - global $wgUser;
 1899+ global $wgUser, $wgEnableInterwikiTranscluding, $wgEnableInterwikiTemplatesTracking;
19001900 $skin = $wgUser->getSkin();
19011901
19021902 $this->setRobotPolicy( 'noindex,nofollow' );
@@ -1945,6 +1945,12 @@
19461946 {$skin->formatTemplates( $article->getUsedTemplates() )}
19471947 </div>
19481948 " );
 1949+ if ( $wgEnableInterwikiTranscluding && $wgEnableInterwikiTemplatesTracking ) {
 1950+ $this->addHTML( "<div class='distantTemplatesUsed'>
 1951+{$skin->formatDistantTemplates( $article->getUsedDistantTemplates( ) )}
 1952+</div>
 1953+" );
 1954+ }
19491955 }
19501956
19511957 # If the title doesn't exist, it's fairly pointless to print a return
Index: branches/iwtransclusion/phase3/includes/LinksUpdate.php
@@ -128,8 +128,8 @@
129129 $this->getTemplateInsertions( $existing ) );
130130
131131 # Distant template links
132 - global $wgGlobalDB;
133 - if ( $wgGlobalDB ) {
 132+ global $wgEnableInterwikiTemplatesTracking, $wgGlobalDatabase;
 133+ if ( $wgEnableInterwikiTemplatesTracking && $wgGlobalDatabase ) {
134134 $existing = $this->getDistantExistingTemplates();
135135 $this->incrSharedTableUpdate( 'globaltemplatelinks', 'gtl',
136136 $this->getDistantTemplateDeletions( $existing ),
@@ -358,16 +358,14 @@
359359 * @private
360360 */
361361 function incrSharedTableUpdate( $table, $prefix, $deletions, $insertions ) {
362 -
363 - global $wgWikiID;
364 - global $wgGlobalDB;
 362+ global $wgEnableInterwikiTemplatesTracking, $wgGlobalDatabase;
365363
366 - if ( $wgGlobalDB ) {
367 - $dbw = wfGetDB( DB_MASTER, array(), $wgGlobalDB );
368 - $where = array( "{$prefix}_from_wiki" => $wgWikiID,
 364+ if ( $wgEnableInterwikiTemplatesTracking && $wgGlobalDatabase ) {
 365+ $dbw = wfGetDB( DB_MASTER, array(), $wgGlobalDatabase );
 366+ $where = array( "{$prefix}_from_wiki" => wfWikiID( ),
369367 "{$prefix}_from_page" => $this->mId
370368 );
371 - $baseKey = "{$prefix}_to_wiki";
 369+ $baseKey = "{$prefix}_to_prefix";
372370 $middleKey = "{$prefix}_to_namespace";
373371
374372 $clause = $dbw->makeWhereFrom3d( $deletions, $baseKey, $middleKey, "{$prefix}_to_title" );
@@ -432,18 +430,18 @@
433431 * @private
434432 */
435433 function getDistantTemplateInsertions( $existing = array() ) {
436 - global $wgWikiID;
 434+
437435 $arr = array();
438 - foreach( $this->mDistantTemplates as $wikiid => $templatesToNS ) {
 436+ foreach( $this->mDistantTemplates as $prefix => $templatesToNS ) {
439437 foreach( $templatesToNS as $ns => $dbkeys ) {
440 - $diffs = isset( $existing[$wikiid] ) && isset( $existing[$wikiid][$ns] ) ? array_diff_key( $dbkeys, $existing[$wikiid][$ns] ) : $dbkeys;
 438+ $diffs = isset( $existing[$prefix] ) && isset( $existing[$prefix][$ns] ) ? array_diff_key( $dbkeys, $existing[$prefix][$ns] ) : $dbkeys;
441439 foreach ( $diffs as $dbk => $id ) {
442440 $arr[] = array(
443 - 'gtl_from_wiki' => $wgWikiID,
 441+ 'gtl_from_wiki' => wfWikiID( ),
444442 'gtl_from_page' => $this->mId,
445443 'gtl_from_namespace' => $this->mTitle->getNsText(),
446444 'gtl_from_title' => $this->mTitle->getText(),
447 - 'gtl_to_wiki' => $wikiid,
 445+ 'gtl_to_prefix' => $prefix,
448446 'gtl_to_namespace' => $ns,
449447 'gtl_to_title' => $dbk
450448 );
@@ -641,17 +639,17 @@
642640 */
643641 function getDistantTemplateDeletions( $existing ) {
644642 $del = array();
645 - foreach ( $existing as $wikiid => $templatesForNS ) {
646 - if ( isset( $this->mDistantTemplates[$wikiid] ) ) {
647 - $del[$wikiid] = array_diff_key( $existing[$wikiid], $this->mDistantTemplates[$wikiid] );
 643+ foreach ( $existing as $prefix => $templatesForNS ) {
 644+ if ( isset( $this->mDistantTemplates[$prefix] ) ) {
 645+ $del[$prefix] = array_diff_key( $existing[$prefix], $this->mDistantTemplates[$prefix] );
648646 } else {
649 - $del[$wikiid] = $existing[$wikiid];
 647+ $del[$prefix] = $existing[$prefix];
650648 }
651649 foreach ( $templatesForNS as $ns => $dbkeys ) {
652 - if ( isset( $this->mDistantTemplates[$wikiid][$ns] ) ) {
653 - $del[$wikiid][$ns] = array_diff_key( $existing[$wikiid][$ns], $this->mDistantTemplates[$wikiid][$ns] );
 650+ if ( isset( $this->mDistantTemplates[$prefix][$ns] ) ) {
 651+ $del[$prefix][$ns] = array_diff_key( $existing[$prefix][$ns], $this->mDistantTemplates[$prefix][$ns] );
654652 } else {
655 - $del[$wikiid][$ns] = $existing[$wikiid][$ns];
 653+ $del[$prefix][$ns] = $existing[$prefix][$ns];
656654 }
657655 }
658656 }
@@ -760,24 +758,22 @@
761759 * @private
762760 */
763761 function getDistantExistingTemplates() {
764 - global $wgWikiID;
765 - global $wgGlobalDB;
 762+ global $wgEnableInterwikiTemplatesTracking, $wgGlobalDatabase;
766763
767764 $arr = array();
768 - if ( $wgGlobalDB ) {
769 - $dbr = wfGetDB( DB_SLAVE, array(), $wgGlobalDB );
770 - $res = $dbr->select( 'globaltemplatelinks', array( 'gtl_to_wiki', 'gtl_to_namespace', 'gtl_to_title' ),
771 - array( 'gtl_from_wiki' => $wgWikiID, 'gtl_from_page' => $this->mId ), __METHOD__, $this->mOptions );
772 - while ( $row = $dbr->fetchObject( $res ) ) {
773 - if ( !isset( $arr[$row->gtl_to_wiki] ) ) {
774 - $arr[$row->gtl_to_wiki] = array();
 765+ if ( $wgGlobalDatabase ) {
 766+ $dbr = wfGetDB( DB_SLAVE, array(), $wgGlobalDatabase );
 767+ $res = $dbr->select( 'globaltemplatelinks', array( 'gtl_to_prefix', 'gtl_to_namespace', 'gtl_to_title' ),
 768+ array( 'gtl_from_wiki' => wfWikiID( ), 'gtl_from_page' => $this->mId ), __METHOD__, $this->mOptions );
 769+ foreach ( $res as $row ) {
 770+ if ( !isset( $arr[$row->gtl_to_prefix] ) ) {
 771+ $arr[$row->gtl_to_prefix] = array();
775772 }
776 - if ( !isset( $arr[$row->gtl_to_wiki][$row->gtl_to_namespace] ) ) {
777 - $arr[$row->gtl_to_wiki][$row->gtl_to_namespace] = array();
 773+ if ( !isset( $arr[$row->gtl_to_prefix][$row->gtl_to_namespace] ) ) {
 774+ $arr[$row->gtl_to_prefix][$row->gtl_to_namespace] = array();
778775 }
779 - $arr[$row->gtl_to_wiki][$row->gtl_to_namespace][$row->gtl_to_title] = 1;
 776+ $arr[$row->gtl_to_prefix][$row->gtl_to_namespace][$row->gtl_to_title] = 1;
780777 }
781 - $dbr->freeResult( $res );
782778 }
783779 return $arr;
784780 }
Index: branches/iwtransclusion/phase3/includes/Title.php
@@ -3057,7 +3057,7 @@
30583058 * @return \type{\mixed} true on success, getUserPermissionsErrors()-like array on failure
30593059 */
30603060 public function moveTo( &$nt, $auth = true, $reason = '', $createRedirect = true ) {
3061 - global $wgContLang, $wgGlobalDB, $wgWikiID;
 3061+ global $wgContLang, $wgEnableInterwikiTemplatesTracking, $wgGlobalDatabase;
30623062
30633063 $err = $this->isValidMoveOperation( $nt, $auth, $reason );
30643064 if ( is_array( $err ) ) {
@@ -3106,8 +3106,8 @@
31073107 array( 'cl_from' => $pageid ),
31083108 __METHOD__ );
31093109
3110 - if ( $wgGlobalDB ) {
3111 - $dbw2 = wfGetDB( DB_MASTER, array(), $wgGlobalDB );
 3110+ if ( $wgEnableInterwikiTemplatesTracking && $wgGlobalDatabase ) {
 3111+ $dbw2 = wfGetDB( DB_MASTER, array(), $wgGlobalDatabase );
31123112 $dbw2->update( 'globaltemplatelinks',
31133113 array( 'gtl_from_namespace' => $nt->getNsText(),
31143114 'gtl_from_title' => $nt->getText() ),
@@ -3207,7 +3207,7 @@
32083208 * Ignored if the user doesn't have the suppressredirect right
32093209 */
32103210 private function moveOverExistingRedirect( &$nt, $reason = '', $createRedirect = true ) {
3211 - global $wgUseSquid, $wgUser, $wgContLang, $wgWikiID, $wgGlobalDB;
 3211+ global $wgUseSquid, $wgUser, $wgContLang, $wgEnableInterwikiTemplatesTracking, $wgGlobalDatabase;
32123212
32133213 $comment = wfMsgForContent( '1movedto2_redir', $this->getPrefixedText(), $nt->getPrefixedText() );
32143214
@@ -3247,10 +3247,10 @@
32483248 $dbw->delete( 'langlinks', array( 'll_from' => $newid ), __METHOD__ );
32493249 $dbw->delete( 'redirect', array( 'rd_from' => $newid ), __METHOD__ );
32503250
3251 - if ( $wgGlobalDB ) {
3252 - $dbw2 = wfGetDB( DB_MASTER, array(), $wgGlobalDB );
 3251+ if ( $wgEnableInterwikiTemplatesTracking && $wgGlobalDatabase ) {
 3252+ $dbw2 = wfGetDB( DB_MASTER, array(), $wgGlobalDatabase );
32533253 $dbw2->delete( 'globaltemplatelinks',
3254 - array( 'gtl_from_wiki' => $wgWikiID,
 3254+ array( 'gtl_from_wiki' => wfWikiID( ),
32553255 'gtl_from_page' => $newid ),
32563256 __METHOD__ );
32573257 }
Index: branches/iwtransclusion/phase3/languages/messages/MessagesEn.php
@@ -1350,6 +1350,9 @@
13511351 'templatesused' => '{{PLURAL:$1|Template|Templates}} used on this page:',
13521352 'templatesusedpreview' => '{{PLURAL:$1|Template|Templates}} used in this preview:',
13531353 'templatesusedsection' => '{{PLURAL:$1|Template|Templates}} used in this section:',
 1354+'distanttemplatesused' => 'Distant {{PLURAL:$1|template|templates}} used on this page:',
 1355+'distanttemplatesusedpreview' => 'Distant {{PLURAL:$1|template|templates}} used in this preview:',
 1356+'distanttemplatesusedsection' => 'Distant {{PLURAL:$1|template|templates}} used in this section:',
13541357 'template-protected' => '(protected)',
13551358 'template-semiprotected' => '(semi-protected)',
13561359 'hiddencategories' => 'This page is a member of {{PLURAL:$1|1 hidden category|$1 hidden categories}}:',

Follow-up revisions

RevisionCommit summaryAuthorDate
r70802Fix remarks about r70764; invalidate the cache of the distant pages when the ...peter1709:11, 10 August 2010
r87108Merge r70764reedy00:40, 29 April 2011
r92990Merge r87108, Merge r70764reedy17:38, 24 July 2011
r92993Merge r87108, which merged r70764reedy18:15, 24 July 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r70576This will register the links to distant templates in the globaltemplatelinks ...peter1716:01, 6 August 2010

Comments

#Comment by Catrope (talk | contribs)   15:47, 9 August 2010
   -- The namespace of the transcluded page on that wiki
   gtl_to_namespace int NOT NULL,
 
+  -- The namespace name of transcluded page
+  -- Needed for display purposes, since the local namespace ID doesn't necessarily match a distant one
+  gtl_to_namespacetext varchar(255) NOT NULL,

So now this table has a namespace ID and name for the to_ part, but only a namespace name for the from_ part. That's not very consistent.

+			$res = $dbr->select( array( 'globaltemplatelinks' ),

Just using $dbr->select( 'globaltemplatelinks', ... will work too.

+			$dbr->freeResult( $res );

Not needed. There was a crusade against these in trunk just yesterday, see r70686.

+			# Do a batch existence check
+			$batch = new LinkBatch;
+			foreach( $templates as $title ) {
+				$batch->addObj( $title );
+			}
+			$batch->execute();

This won't work the way you expect and is useless. LinkBatch expects to only be fed local titles, so has no code to deal with interwiki titles at all. The intention of this code in normal usage (with local titles) is to run all existence checks at once and cache them so Linker::link() doesn't hit the database for each individual title, but existence checks are skipped for interwiki titles anyway.

+{$this->editFormTextAfterTools}

You shouldn't add this twice.

#Comment by Catrope (talk | contribs)   18:58, 9 August 2010

Also, the globals need to be added to DefaultSettings.php and documented.

Status & tagging log