langlinks table
authorTim Starling <tstarling@users.mediawiki.org>
Tue, 11 Apr 2006 14:56:04 +0000 (14:56 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Tue, 11 Apr 2006 14:56:04 +0000 (14:56 +0000)
RELEASE-NOTES
includes/Article.php
includes/LinksUpdate.php
includes/Parser.php
maintenance/archives/patch-langlinks.sql [new file with mode: 0644]
maintenance/mysql5/tables.sql
maintenance/tables.sql
maintenance/updaters.inc

index fa9d1e0..3ae828a 100644 (file)
@@ -46,6 +46,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * Optional {{DISPLAYTITLE|title with markup}} magic word
   Deactivated by default, set "$wgAllowDisplayTitle = true" in LocalSettings.php to activate
 * Cleaned SpecialContributions a bit
+* Added a table to track interlanguage links
 
 == Compatibility ==
 
index 4ede20f..4676a4e 100644 (file)
@@ -2092,6 +2092,7 @@ class Article {
                $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
                $dbw->delete( 'templatelinks', array( 'tl_from' => $id ) );
                $dbw->delete( 'externallinks', array( 'el_from' => $id ) );
+               $dbw->delete( 'langlinks', array( 'll_from' => $id ) );
 
                # Log the deletion
                $log = new LogPage( 'delete' );
index 46dc1ca..bea37c1 100644 (file)
@@ -19,7 +19,8 @@ class LinksUpdate {
                $mImages,        # DB keys of the images used, in the array key only
                $mTemplates,     # Map of title strings to IDs for the template references, including broken ones
                $mExternals,     # URLs of external links, array key only
-               $mCategories,    # Map of category names to sort keys
+           $mCategories,    # Map of category names to sort keys
+           $mInterlangs,    # Map of language codes to titles
                $mDb,            # Database connection reference
                $mOptions,       # SELECT options to be used (array)
                $mRecursive;     # Whether to queue jobs for recursive updates
@@ -53,8 +54,19 @@ class LinksUpdate {
                $this->mTemplates = $parserOutput->getTemplates();
                $this->mExternals = $parserOutput->getExternalLinks();
                $this->mCategories = $parserOutput->getCategories();
-               $this->mRecursive = $recursive;
 
+               # Convert the format of the interlanguage links
+               # I didn't want to change it in the ParserOutput, because that array is passed all 
+               # the way back to the skin, so either a skin API break would be required, or an 
+               # inefficient back-conversion.
+               $ill = $parserOutput->getLanguageLinks();
+               $this->mInterlangs = array();
+               foreach ( $ill as $link ) {
+                       list( $key, $title ) = explode( ':', $link, 2 );
+                       $this->mInterlangs[$key] = $title;
+               }
+
+               $this->mRecursive = $recursive;
        }
 
        /**
@@ -90,7 +102,12 @@ class LinksUpdate {
                # External links
                $existing = $this->getExistingExternals();
                $this->incrTableUpdate( 'externallinks', 'el', $this->getExternalDeletions( $existing ),
-                       $this->getExternalInsertions( $existing ) );
+               $this->getExternalInsertions( $existing ) );
+
+           # Language links
+           $existing = $this->getExistingInterlangs();
+           $this->incrTableUpdate( 'langlinks', 'll', $this->getInterlangDeletions( $existing ),
+               $this->getInterlangInsertions( $existing ) );
 
                # Template links
                $existing = $this->getExistingTemplates();
@@ -104,7 +121,7 @@ class LinksUpdate {
                                require_once( 'JobQueue.php' );
                                Job::queueLinksJobs( $tlto );
                        }
-               }
+           }
 
                # Category links
                $existing = $this->getExistingCategories();
@@ -146,7 +163,8 @@ class LinksUpdate {
                $this->dumbTableUpdate( 'imagelinks',    $this->getImageInsertions(),    'il_from' );
                $this->dumbTableUpdate( 'categorylinks', $this->getCategoryInsertions(), 'cl_from' );
                $this->dumbTableUpdate( 'templatelinks', $this->getTemplateInsertions(), 'tl_from' );
-               $this->dumbTableUpdate( 'externallinks', $this->getExternalInsertions(), 'el_from' );
+           $this->dumbTableUpdate( 'externallinks', $this->getExternalInsertions(), 'el_from' );
+           $this->dumbTableUpdate( 'langlinks',     $this->getInterlangInsertions(), 'll_from' );
 
                # Update the cache of all the category pages and image description pages which were changed
                $this->invalidateCategories( $categoryUpdates );
@@ -217,8 +235,13 @@ class LinksUpdate {
                                $where = false;
                        }
                } else {
+                       if ( $table == 'langlinks' ) {
+                               $toField = 'll_lang';
+                       } else {
+                               $toField = $prefix . '_to';
+                       }
                        if ( count( $deletions ) ) {
-                               $where[] = "{$prefix}_to IN (" . $this->mDb->makeList( array_keys( $deletions ) ) . ')';
+                               $where[] = "$toField IN (" . $this->mDb->makeList( array_keys( $deletions ) ) . ')';
                        } else {
                                $where = false;
                        }
@@ -327,6 +350,24 @@ class LinksUpdate {
                return $arr;
        }
 
+       /**
+        * Get an array of interlanguage link insertions
+        * @param array $existing Array mapping existing language codes to titles        
+        * @access 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;
+       }
+
        /**
         * Given an array of existing links, returns those links which are not in $this
         * and thus should be deleted.
@@ -388,6 +429,15 @@ class LinksUpdate {
                return array_diff_assoc( $existing, $this->mCategories );
        }
 
+       /** 
+        * Given an array of existing interlanguage links, returns those links which are not
+        * in $this and thus should be deleted.
+        * @access private
+        */
+       function getInterlangDeletions( $existing ) {
+           return array_diff_assoc( $existing, $this->mInterlangs );
+       }
+
        /**
         * Get an array of existing links, as a 2-D array
         * @access private
@@ -473,5 +523,21 @@ class LinksUpdate {
                $this->mDb->freeResult( $res );
                return $arr;
        }
+
+       /**
+        * Get an array of existing interlanguage links, with the language code in the key and the 
+        * title in the value.
+        * @access private
+        */
+       function getExistingInterlangs() {
+               $fname = 'LinksUpdate::getExistingInterlangs';
+               $res = $this->mDb->select( 'langlinks', array( 'll_lang', 'll_title' ), 
+                       array( 'll_from' => $this->mId ), $fname, $this->mOptions );
+               $arr = array();
+               while ( $row = $this->mDb->fetchObject( $res ) ) {
+                       $arr[$row->ll_lang] = $row->ll_title;
+               }
+               return $arr;
+       }
 }
 ?>
index 53f55d0..58047db 100644 (file)
@@ -2637,10 +2637,10 @@ class Parser
                }               
 
                # Extensions
-               if ( !$found ) {
+               if ( !$found && substr( $part1, 0, 1 ) == '#' ) {
                        $colonPos = strpos( $part1, ':' );
                        if ( $colonPos !== false ) {
-                               $function = strtolower( substr( $part1, 0, $colonPos ) );
+                               $function = strtolower( substr( $part1, 1, $colonPos - 1 ) );
                                if ( isset( $this->mFunctionHooks[$function] ) ) {
                                        $funcArgs = array_merge( array( &$this, substr( $part1, $colonPos + 1 ) ), $args );
                                        $result = call_user_func_array( $this->mFunctionHooks[$function], $funcArgs );
@@ -4027,7 +4027,7 @@ class ParserOutput
        }
 
        function getText()                   { return $this->mText; }
-       function getLanguageLinks()          { return $this->mLanguageLinks; }
+       function &getLanguageLinks()          { return $this->mLanguageLinks; }
        function getCategoryLinks()          { return array_keys( $this->mCategories ); }
        function &getCategories()            { return $this->mCategories; }
        function getCacheTime()              { return $this->mCacheTime; }
@@ -4068,16 +4068,6 @@ class ParserOutput
                $this->mTemplates[$ns][$dbk] = $id;
        }
 
-       /**
-        * @deprecated
-        */
-       /*
-       function merge( $other ) {
-               $this->mLanguageLinks = array_merge( $this->mLanguageLinks, $other->mLanguageLinks );
-               $this->mCategories = array_merge( $this->mCategories, $this->mLanguageLinks );
-               $this->mContainsOldMagic = $this->mContainsOldMagic || $other->mContainsOldMagic;
-       }*/
-
        /**
         * Return true if this cached output object predates the global or
         * per-article cache invalidation timestamps, or if it comes from
@@ -4094,7 +4084,7 @@ class ParserOutput
                       $this->getCacheTime() <= $wgCacheEpoch ||
                       !isset( $this->mVersion ) ||
                       version_compare( $this->mVersion, MW_PARSER_VERSION, "lt" );
-       }
+    }
 }
 
 /**
diff --git a/maintenance/archives/patch-langlinks.sql b/maintenance/archives/patch-langlinks.sql
new file mode 100644 (file)
index 0000000..0dd4d40
--- /dev/null
@@ -0,0 +1,14 @@
+CREATE TABLE /*$wgDBprefix*/langlinks (\r
+  -- page_id of the referring page\r
+  ll_from int(8) unsigned NOT NULL default '0',\r
+  \r
+  -- Language code of the target\r
+  ll_lang varchar(10) binary NOT NULL default '',\r
+\r
+  -- Title of the target, including namespace\r
+  ll_title varchar(255) binary NOT NULL default '',\r
+\r
+  UNIQUE KEY (ll_from, ll_lang),\r
+  KEY (ll_lang, ll_title)\r
+) ENGINE=InnoDB;\r
+\r
index fcf41a3..3a9a1b2 100644 (file)
@@ -490,6 +490,23 @@ CREATE TABLE /*$wgDBprefix*/externallinks (
   KEY (el_index(60))
 ) TYPE=InnoDB, DEFAULT CHARSET=utf8;
 
+-- 
+-- Track interlanguage links
+--
+CREATE TABLE /*$wgDBprefix*/langlinks (
+  -- page_id of the referring page
+  ll_from int(8) unsigned NOT NULL default '0',
+  
+  -- Language code of the target
+  ll_lang varchar(10) binary NOT NULL default '',
+
+  -- Title of the target, including namespace
+  ll_title varchar(255) binary NOT NULL default '',
+
+  UNIQUE KEY (ll_from, ll_lang),
+  KEY (ll_lang, ll_title)
+) ENGINE=InnoDB, DEFAULT CHARSET=utf8;
+
 --
 -- Contains a single row with some aggregate info
 -- on the state of the site.
index b206a8a..77ca26d 100644 (file)
@@ -477,6 +477,23 @@ CREATE TABLE /*$wgDBprefix*/externallinks (
   KEY (el_index(60))
 ) TYPE=InnoDB;
 
+-- 
+-- Track interlanguage links
+--
+CREATE TABLE /*$wgDBprefix*/langlinks (
+  -- page_id of the referring page
+  ll_from int(8) unsigned NOT NULL default '0',
+  
+  -- Language code of the target
+  ll_lang varchar(10) binary NOT NULL default '',
+
+  -- Title of the target, including namespace
+  ll_title varchar(255) binary NOT NULL default '',
+
+  UNIQUE KEY (ll_from, ll_lang),
+  KEY (ll_lang, ll_title)
+) ENGINE=InnoDB;
+
 --
 -- Contains a single row with some aggregate info
 -- on the state of the site.
index 61fe17b..ec16062 100644 (file)
@@ -28,6 +28,7 @@ $wgNewTables = array(
        array( 'trackbacks',    'patch-trackbacks.sql' ),
        array( 'externallinks', 'patch-externallinks.sql' ),
        array( 'job',           'patch-job.sql' ),
+       array( 'langlinks',     'patch-langlinks.sql' ),
 );
 
 $wgNewFields = array(