langlinks table
This commit is contained in:
parent
9622c428fa
commit
fb97cc3078
8 changed files with 127 additions and 20 deletions
|
|
@ -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 ==
|
||||
|
||||
|
|
|
|||
|
|
@ -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' );
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -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" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
14
maintenance/archives/patch-langlinks.sql
Normal file
14
maintenance/archives/patch-langlinks.sql
Normal file
|
|
@ -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;
|
||||
|
||||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in a new issue