Make imagelinks work like templatelinks

Due to bug 17259 (which is fixed in a better way in Id44d566a),
imagelinks only records the redirect and not the actual image used when
an image redirect is referenced. This causes various problems, such as
cascading protection not working through image redirects.

It makes more sense for imagelinks to work like tempaltelinks, recording
both so that things like cascading protection don't have to care about
image redirects explicitly.

Comparing imagelinks to templatelinks also reveals a few places
(WikiPage::doDeleteUpdates, WikiPage::doCascadeProtectionUpdates) that
should be triggering a LinksUpdate if the image links changed.

Bug: 23002
Bug: 23542
Bug: 26503
Change-Id: I64fe7d25646cae2c8213211893c6f821f3504dbf
This commit is contained in:
Brad Jorsch 2014-01-04 14:26:26 -05:00 committed by Aaron Schulz
parent 09f84556bd
commit a2120b0bd0
5 changed files with 37 additions and 28 deletions

View file

@ -98,6 +98,8 @@ production.
messages have been updated and marked for review at translatewiki.net.
* (bug 14323) Redirect pages, when viewed with redirect=no, no longer hide the
remaining page content.
* (bug 23542) imagelinks now stores both the redirect and target (as
templatelinks does).
=== Web API changes in 1.23 ===
* (bug 54884) action=parse&prop=categories now indicates hidden and missing

View file

@ -2794,6 +2794,11 @@ class WikiPage implements Page, IDBAccessObject {
// Reparse any pages transcluding this page
LinksUpdate::queueRecursiveJobsForTable( $this->mTitle, 'templatelinks' );
// Reparse any pages including this image
if ( $this->mTitle->getNamespace() == NS_FILE ) {
LinksUpdate::queueRecursiveJobsForTable( $this->mTitle, 'imagelinks' );
}
// Clear caches
WikiPage::onArticleDelete( $this->mTitle );
@ -3262,17 +3267,17 @@ class WikiPage implements Page, IDBAccessObject {
return;
}
// templatelinks table may have become out of sync,
// templatelinks or imagelinks tables may have become out of sync,
// especially if using variable-based transclusions.
// For paranoia, check if things have changed and if
// so apply updates to the database. This will ensure
// that cascaded protections apply as soon as the changes
// are visible.
// Get templates from templatelinks
// Get templates from templatelinks and images from imagelinks
$id = $this->getId();
$tlTemplates = array();
$dbLinks = array();
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select( array( 'templatelinks' ),
@ -3282,21 +3287,35 @@ class WikiPage implements Page, IDBAccessObject {
);
foreach ( $res as $row ) {
$tlTemplates["{$row->tl_namespace}:{$row->tl_title}"] = true;
$dbLinks["{$row->tl_namespace}:{$row->tl_title}"] = true;
}
// Get templates from parser output.
$poTemplates = array();
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select( array( 'imagelinks' ),
array( 'il_to' ),
array( 'il_from' => $id ),
__METHOD__
);
foreach ( $res as $row ) {
$dbLinks[NS_FILE . ":{$row->il_to}"] = true;
}
// Get templates and images from parser output.
$poLinks = array();
foreach ( $parserOutput->getTemplates() as $ns => $templates ) {
foreach ( $templates as $dbk => $id ) {
$poTemplates["$ns:$dbk"] = true;
$poLinks["$ns:$dbk"] = true;
}
}
foreach ( $parserOutput->getImages() as $dbk => $id ) {
$poLinks[NS_FILE . ":$dbk"] = true;
}
// Get the diff
$templates_diff = array_diff_key( $poTemplates, $tlTemplates );
$links_diff = array_diff_key( $poLinks, $dbLinks );
if ( count( $templates_diff ) > 0 ) {
if ( count( $links_diff ) > 0 ) {
// Whee, link updates time.
// Note: we are only interested in links here. We don't need to get other DataUpdate items from the parser output.
$u = new LinksUpdate( $this->mTitle, $parserOutput, false );

View file

@ -233,11 +233,15 @@ class LinksUpdate extends SqlDataUpdate {
/**
* Queue recursive jobs for this page
*
* Which means do LinksUpdate on all templates
* that include the current page, using the job queue.
* Which means do LinksUpdate on all pages that include the current page,
* using the job queue.
*/
function queueRecursiveJobs() {
self::queueRecursiveJobsForTable( $this->mTitle, 'templatelinks' );
if ( $this->mTitle->getNamespace() == NS_FILE ) {
// Process imagelinks in case the title is or was a redirect
self::queueRecursiveJobsForTable( $this->mTitle, 'imagelinks' );
}
}
/**

View file

@ -1458,17 +1458,6 @@ class LocalFile extends File {
LinksUpdate::queueRecursiveJobsForTable( $this->getTitle(), 'imagelinks' );
}
# Invalidate cache for all pages that redirects on this page
$redirs = $this->getTitle()->getRedirectsHere();
foreach ( $redirs as $redir ) {
if ( !$reupload && $redir->getNamespace() === NS_FILE ) {
LinksUpdate::queueRecursiveJobsForTable( $redir, 'imagelinks' );
}
$update = new HTMLCacheUpdate( $redir, 'imagelinks' );
$update->doUpdate();
}
wfProfileOut( __METHOD__ );
return true;

View file

@ -3837,12 +3837,7 @@ class Parser {
if ( $file && !$title->equals( $file->getTitle() ) ) {
# Update fetched file title
$title = $file->getTitle();
if ( is_null( $file->getRedirectedTitle() ) ) {
# This file was not a redirect, but the title does not match.
# Register under the new name because otherwise the link will
# get lost.
$this->mOutput->addImage( $title->getDBkey(), $time, $sha1 );
}
$this->mOutput->addImage( $title->getDBkey(), $time, $sha1 );
}
return array( $file, $title );
}