# External links
$existing = $this->getExistingExternals();
$this->incrTableUpdate( 'externallinks', 'el', $this->getExternalDeletions( $existing ),
- $this->getExternalInsertions( $existing ) );
+ $this->getExternalInsertions( $existing ) );
# Language links
$existing = $this->getExistingInterlangs();
$this->getTemplateInsertions( $existing ) );
# Distant template links
- global $wgGlobalDB;
- if ( $wgGlobalDB ) {
+ global $wgGlobalDatabase;
+ if ( $wgGlobalDatabase ) {
$existing = $this->getDistantExistingTemplates();
$this->incrSharedTableUpdate( 'globaltemplatelinks', 'gtl',
$this->getDistantTemplateDeletions( $existing ),
foreach ( $batches as $batch ) {
list( $start, $end ) = $batch;
$params = array(
+ 'table' => 'templatelinks',
'start' => $start,
'end' => $end,
);
if ( $where ) {
$this->mDb->delete( $table, $where, __METHOD__ );
}
+ if ( isset( $insertions['globaltemplatelinks'] ) ) {
+ $this->mDb->insert( 'globaltemplatelinks', $insertions['globaltemplatelinks'], __METHOD__, 'IGNORE' );
+ unset( $insertions['globaltemplatelinks'] );
+ }
+ if ( isset( $insertions['globalnamespaces'] ) ) {
+ $this->mDb->insert( 'globalnamespaces', $insertions['globalnamespaces'], __METHOD__, 'IGNORE' );
+ unset( $insertions['globalnamespaces'] );
+ }
+ if ( isset( $insertions['globalinterwiki'] ) ) {
+ $this->mDb->insert( 'globalinterwiki', $insertions['globalinterwiki'], __METHOD__, 'IGNORE' );
+ unset( $insertions['globalinterwiki'] );
+ }
if ( count( $insertions ) ) {
- if ( isset( $insertions['globaltemplatelinks'] ) ) {
- $this->mDb->insert( 'globaltemplatelinks', $insertions['globaltemplatelinks'], __METHOD__, 'IGNORE' );
- }
- if ( isset( $insertions['globalnamespaces'] ) ) {
- $this->mDb->insert( 'globalnamespaces', $insertions['globalnamespaces'], __METHOD__, 'IGNORE' );
- }
- if ( isset( $insertions['globalinterwiki'] ) ) {
- $this->mDb->insert( 'globalinterwiki', $insertions['globalinterwiki'], __METHOD__, 'IGNORE' );
- }
+ $this->mDb->insert( $table, $insertions, __METHOD__, 'IGNORE' );
}
}
* @private
*/
function incrSharedTableUpdate( $table, $prefix, $deletions, $insertions ) {
+ global $wgGlobalDatabase;
- global $wgWikiID;
- global $wgGlobalDB;
-
- if ( $wgGlobalDB ) {
- $dbw = wfGetDB( DB_MASTER, array(), $wgGlobalDB );
- $where = array( "{$prefix}_from_wiki" => $wgWikiID,
+ if ( $wgGlobalDatabase ) {
+ $dbw = wfGetDB( DB_MASTER, array(), $wgGlobalDatabase );
+ $where = array( "{$prefix}_from_wiki" => wfWikiID(),
"{$prefix}_from_page" => $this->mId
);
$baseKey = "{$prefix}_to_wiki";
* @private
*/
function getDistantTemplateInsertions( $existing = array() ) {
- global $wgWikiID;
$arr = array();
- foreach( $this->mDistantTemplates as $wikiid => $templatesToNS ) {
+ foreach( $this->mDistantTemplates as $prefix => $templatesToNS ) {
foreach( $templatesToNS as $ns => $dbkeys ) {
- $diffs = isset( $existing[$wikiid] ) && isset( $existing[$wikiid][$ns] )
- ? array_diff_key( $dbkeys, $existing[$wikiid][$ns] )
+ $diffs = isset( $existing[$prefix] ) && isset( $existing[$prefix][$ns] )
+ ? array_diff_key( $dbkeys, $existing[$prefix][$ns] )
: $dbkeys;
- $interwiki = Interwiki::fetch( $wikiid );
+ $interwiki = Interwiki::fetch( $prefix );
$wikiid = $interwiki->getWikiID();
foreach ( $diffs as $dbk => $id ) {
$arr['globaltemplatelinks'][] = array(
- 'gtl_from_wiki' => $wgWikiID,
+ 'gtl_from_wiki' => wfWikiID(),
'gtl_from_page' => $this->mId,
'gtl_from_namespace' => $this->mTitle->getNamespace(),
'gtl_from_title' => $this->mTitle->getText(),
);
$arr['globalinterwiki'][] = array(
'giw_wikiid' => $wikiid,
- 'giw_prefix' => $prefix, // FIXME: $prefix ix undefined
+ 'giw_prefix' => $prefix,
);
$arr['globalnamespaces'][] = array(
'gn_wiki' => wfWikiID( ),
* @private
*/
function getInterlangInsertions( $existing = array() ) {
- $diffs = array_diff_assoc( $this->mInterlangs, $existing );
- $arr = array();
- foreach( $diffs as $lang => $title ) {
- $arr[] = array(
- 'll_from' => $this->mId,
- 'll_lang' => $lang,
- 'll_title' => $title
- );
- }
- return $arr;
+ $diffs = array_diff_assoc( $this->mInterlangs, $existing );
+ $arr = array();
+ foreach( $diffs as $lang => $title ) {
+ $arr[] = array(
+ 'll_from' => $this->mId,
+ 'll_lang' => $lang,
+ 'll_title' => $title
+ );
+ }
+ return $arr;
}
/**
* @private
*/
function getInterlangDeletions( $existing ) {
- return array_diff_assoc( $existing, $this->mInterlangs );
+ return array_diff_assoc( $existing, $this->mInterlangs );
}
/**
* @private
*/
function getDistantExistingTemplates() {
- global $wgWikiID;
- global $wgGlobalDB;
+ global $wgGlobalDatabase;
$arr = array();
- if ( $wgGlobalDB ) {
- $dbr = wfGetDB( DB_SLAVE, array(), $wgGlobalDB );
- $res = $dbr->select( 'globaltemplatelinks', array( 'gtl_to_wiki', 'gtl_to_namespace', 'gtl_to_title' ),
- array( 'gtl_from_wiki' => $wgWikiID, 'gtl_from_page' => $this->mId ), __METHOD__, $this->mOptions );
- while ( $row = $dbr->fetchObject( $res ) ) {
+ if ( $wgGlobalDatabase ) {
+ $dbr = wfGetDB( DB_SLAVE, array(), $wgGlobalDatabase );
+ $res = $dbr->select(
+ 'globaltemplatelinks',
+ array( 'gtl_to_wiki', 'gtl_to_namespace', 'gtl_to_title' ),
+ array( 'gtl_from_wiki' => wfWikiID(), 'gtl_from_page' => $this->mId ),
+ __METHOD__,
+ $this->mOptions
+ );
+ foreach ( $res as $row ) {
if ( !isset( $arr[$row->gtl_to_wiki] ) ) {
$arr[$row->gtl_to_wiki] = array();
}
}
$arr[$row->gtl_to_wiki][$row->gtl_to_namespace][$row->gtl_to_title] = 1;
}
- $dbr->freeResult( $res );
}
return $arr;
}