Add iw_api and iw_wikiid fields to the interwiki table, plus rudimentary support...
authorRoan Kattouw <catrope@users.mediawiki.org>
Mon, 19 Jul 2010 11:55:30 +0000 (11:55 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Mon, 19 Jul 2010 11:55:30 +0000 (11:55 +0000)
includes/Interwiki.php
includes/Title.php
includes/installer/Updaters.php
maintenance/archives/patch-iw_api_and_wikiid.sql [new file with mode: 0644]
maintenance/tables.sql

index 3c71f6e..45c9dbb 100644 (file)
@@ -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
index 678b5de..1434491 100644 (file)
@@ -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
         *
index ea4d21a..8db3ddd 100644 (file)
@@ -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 (file)
index 0000000..4384a71
--- /dev/null
@@ -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;
+
index 99ddb77..d3a12bd 100644 (file)
@@ -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,