From: Brad Jorsch Date: Sat, 4 Jan 2014 19:26:26 +0000 (-0500) Subject: Make imagelinks work like templatelinks X-Git-Tag: 1.31.0-rc.0~17342 X-Git-Url: http://git.cyclocoop.org/%7B%7B%20url_for%28%27admin_vote_del%27%2C%20idvote=vote.voteid%29%20%7D%7D?a=commitdiff_plain;h=a2120b0bd0fed4dba09204f0bb2c4e477ac5b657;p=lhc%2Fweb%2Fwiklou.git 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 --- diff --git a/RELEASE-NOTES-1.23 b/RELEASE-NOTES-1.23 index 09cf8cf31a..13d9ff8b27 100644 --- a/RELEASE-NOTES-1.23 +++ b/RELEASE-NOTES-1.23 @@ -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 diff --git a/includes/WikiPage.php b/includes/WikiPage.php index 384a7c4050..8c035aa9b8 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -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; + } + + $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 from parser output. - $poTemplates = array(); + // 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 ); diff --git a/includes/deferred/LinksUpdate.php b/includes/deferred/LinksUpdate.php index 6e0cebff75..8c3b671195 100644 --- a/includes/deferred/LinksUpdate.php +++ b/includes/deferred/LinksUpdate.php @@ -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' ); + } } /** diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index 5206447c39..687c5498dd 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -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; diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 71cb863616..cdf5e98a0e 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -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 ); }