From b5fa13fde7a02add75a6b3841c9a459d8404fffc Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Mon, 19 Jul 2010 11:55:30 +0000 Subject: [PATCH] Add iw_api and iw_wikiid fields to the interwiki table, plus rudimentary support in Interwiki.php and Title.php . Code written by peter17 in the iwtransclusion branch. This revision is a partial merge of r68170, r68448, r69480, r69540 and r69541 --- includes/Interwiki.php | 31 ++++++++++++++++--- includes/Title.php | 13 ++++++++ includes/installer/Updaters.php | 4 ++- .../archives/patch-iw_api_and_wikiid.sql | 9 ++++++ maintenance/tables.sql | 6 ++++ 5 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 maintenance/archives/patch-iw_api_and_wikiid.sql diff --git a/includes/Interwiki.php b/includes/Interwiki.php index 3c71f6eece..45c9dbbe9a 100644 --- a/includes/Interwiki.php +++ b/includes/Interwiki.php @@ -15,11 +15,13 @@ class Interwiki { protected static $smCache = array(); const CACHE_LIMIT = 100; // 0 means unlimited, any other value is max number of entries. - protected $mPrefix, $mURL, $mLocal, $mTrans; + protected $mPrefix, $mURL, $mAPI, $mWikiID, $mLocal, $mTrans; - public function __construct( $prefix = null, $url = '', $local = 0, $trans = 0 ) { + public function __construct( $prefix = null, $url = '', $api = '', $wikiid = '', $local = 0, $trans = 0 ) { $this->mPrefix = $prefix; $this->mURL = $url; + $this->mAPI = $api; + $this->mWikiID = $wikiid; $this->mLocal = $local; $this->mTrans = $trans; } @@ -153,7 +155,7 @@ class Interwiki { __METHOD__ ) ); $iw = Interwiki::loadFromArray( $row ); if ( $iw ) { - $mc = array( 'iw_url' => $iw->mURL, 'iw_local' => $iw->mLocal, 'iw_trans' => $iw->mTrans ); + $mc = array( 'iw_url' => $iw->mURL, 'iw_api' => $iw->mAPI, 'iw_local' => $iw->mLocal, 'iw_trans' => $iw->mTrans ); $wgMemc->add( $key, $mc, $wgInterwikiExpiry ); return $iw; } @@ -168,9 +170,12 @@ class Interwiki { * @return Boolean: whether everything was there */ protected static function loadFromArray( $mc ) { - if( isset( $mc['iw_url'] ) && isset( $mc['iw_local'] ) && isset( $mc['iw_trans'] ) ) { + if( isset( $mc['iw_url'] ) && isset( $mc['iw_api'] ) && isset( $mc['iw_wikiid'] ) + && isset( $mc['iw_local'] ) && isset( $mc['iw_trans'] ) ) { $iw = new Interwiki(); $iw->mURL = $mc['iw_url']; + $iw->mAPI = $mc['iw_api']; + $iw->mWikiID = $mc['iw_wikiid']; $iw->mLocal = $mc['iw_local']; $iw->mTrans = $mc['iw_trans']; return $iw; @@ -192,6 +197,24 @@ class Interwiki { return $url; } + /** + * Get the API URL for this wiki + * + * @return String: the URL + */ + public function getAPI( ) { + return $this->mAPI; + } + + /** + * Get the DB name for this wiki + * + * @return String: the DB name + */ + public function getWikiID( ) { + return $this->mWikiID; + } + /** * Is this a local link from a sister project, or is * it something outside, like Google diff --git a/includes/Title.php b/includes/Title.php index 678b5deea1..1434491685 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -521,6 +521,19 @@ class Title { return Interwiki::fetch( $this->mInterwiki )->isTranscludable(); } + /** + * Returns the DB name of the distant wiki + * which owns the object. + * + * @return \type{\string} the DB name + */ + public function getTransWikiID() { + if ( $this->mInterwiki == '' ) + return false; + + return Interwiki::fetch( $this->mInterwiki )->getWikiID(); + } + /** * Escape a text fragment, say from a link, for a URL * diff --git a/includes/installer/Updaters.php b/includes/installer/Updaters.php index ea4d21a6fb..8db3ddd436 100644 --- a/includes/installer/Updaters.php +++ b/includes/installer/Updaters.php @@ -166,7 +166,8 @@ class MysqlUpdater implements Updaters { '1.17' => array( array( 'add_table', 'iwlinks', 'patch-iwlinks.sql' ), array( 'add_index', 'iwlinks', 'iwl_prefix_from_title', 'patch-rename-iwl_prefix.sql' ), - array( 'add_field', 'updatelog', 'ul_value', 'patch-ul_value.sql' ) + array( 'add_field', 'updatelog', 'ul_value', 'patch-ul_value.sql' ), + array( 'add_field', 'interwiki', 'iw_api', 'patch-iw_api_and_wikiid.sql' ), ), ); } @@ -206,6 +207,7 @@ class SqliteUpdater implements Updaters { array( 'add_table', 'iwlinks', 'patch-iwlinks.sql' ), array( 'add_index', 'iwlinks', 'iwl_prefix_from_title', 'patch-rename-iwl_prefix.sql' ), array( 'add_field', 'updatelog', 'ul_value', 'patch-ul_value.sql' ), + array( 'add_field', 'interwiki', 'iw_api', 'patch-iw_api_and_wikiid.sql' ), ), ); } diff --git a/maintenance/archives/patch-iw_api_and_wikiid.sql b/maintenance/archives/patch-iw_api_and_wikiid.sql new file mode 100644 index 0000000000..4384a715f5 --- /dev/null +++ b/maintenance/archives/patch-iw_api_and_wikiid.sql @@ -0,0 +1,9 @@ +-- +-- Add iw_api and iw_wikiid to interwiki table +-- + +ALTER TABLE /*_*/interwiki + ADD iw_api BLOB NOT NULL; +ALTER TABLE /*_*/interwiki + ADD iw_wikiid varchar(64) NOT NULL; + diff --git a/maintenance/tables.sql b/maintenance/tables.sql index 99ddb77d9f..d3a12bdfb0 100644 --- a/maintenance/tables.sql +++ b/maintenance/tables.sql @@ -1068,6 +1068,12 @@ CREATE TABLE /*_*/interwiki ( -- insertion. iw_url blob NOT NULL, + -- The URL of the file api.php + iw_api blob NOT NULL, + + -- The name of the database (for a connection to be established with wfGetLB( 'wikiid' )) + iw_wikiid varchar(64) NOT NULL, + -- A boolean value indicating whether the wiki is in this project -- (used, for example, to detect redirect loops) iw_local bool NOT NULL, -- 2.20.1