From: Tim Starling Date: Tue, 11 Apr 2006 14:56:04 +0000 (+0000) Subject: langlinks table X-Git-Tag: 1.31.0-rc.0~57530 X-Git-Url: http://git.cyclocoop.org//%27%40script%40/%27?a=commitdiff_plain;h=fb97cc3078ab3c3ef1c3ee77d773f693f929d943;p=lhc%2Fweb%2Fwiklou.git langlinks table --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index fa9d1e0358..3ae828a8c0 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 == diff --git a/includes/Article.php b/includes/Article.php index 4ede20f3ec..4676a4e667 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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' ); diff --git a/includes/LinksUpdate.php b/includes/LinksUpdate.php index 46dc1ca26c..bea37c1b3c 100644 --- a/includes/LinksUpdate.php +++ b/includes/LinksUpdate.php @@ -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; + } } ?> diff --git a/includes/Parser.php b/includes/Parser.php index 53f55d0919..58047db449 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -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 index 0000000000..0dd4d40570 --- /dev/null +++ b/maintenance/archives/patch-langlinks.sql @@ -0,0 +1,14 @@ +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; + diff --git a/maintenance/mysql5/tables.sql b/maintenance/mysql5/tables.sql index fcf41a3050..3a9a1b2c2b 100644 --- a/maintenance/mysql5/tables.sql +++ b/maintenance/mysql5/tables.sql @@ -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. diff --git a/maintenance/tables.sql b/maintenance/tables.sql index b206a8a54a..77ca26d17d 100644 --- a/maintenance/tables.sql +++ b/maintenance/tables.sql @@ -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. diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index 61fe17b236..ec16062e88 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -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(