r88054 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88053‎ | r88054 | r88055 >
Date:12:20, 14 May 2011
Author:btongminh
Status:resolved (Comments)
Tags:
Comment:
(bug 23002) Imagelinks table not updated after imagemove. The actual bug was inconsistent behaviour between imagelinks and pagelinks for redirects.
* Parser now only adds the redirect source to imagelinks, like it does in pagelinks
* ImagePage now shows the file redirects in-line with the normal "The following pages link to this file:"
** Added message linkstoimage-redirect
** Removed the separate file redirects section and removed associated message redirectstofile
** ImagePage::imageLinks will first fetch image links to the file, determine which are redirects, and if there are fewer links than the limit, fetch the redirect target links.
Modified paths:
  • /trunk/phase3/includes/ImagePage.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesQqq.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -3508,8 +3508,6 @@
35093509 # Register the file as a dependency...
35103510 $this->mOutput->addImage( $title->getDBkey(), $time, $sha1 );
35113511 if ( $file && !$title->equals( $file->getTitle() ) ) {
3512 - # We fetched a rev from a different title; register it too...
3513 - $this->mOutput->addImage( $file->getTitle()->getDBkey(), $time, $sha1 );
35143512 # Update fetched file title
35153513 $title = $file->getTitle();
35163514 }
Index: trunk/phase3/includes/ImagePage.php
@@ -140,7 +140,6 @@
141141 $this->imageDupes();
142142 # TODO! FIXME! For some freaky reason, we can't redirect to foreign images.
143143 # Yet we return metadata about the target. Definitely an issue in the FileRepo
144 - $this->imageRedirects();
145144 $this->imageLinks();
146145
147146 # Allow extensions to add something after the image links
@@ -660,21 +659,45 @@
661660 }
662661 }
663662
 663+ protected function queryImageLinks( $target, $limit ) {
 664+ $dbr = wfGetDB( DB_SLAVE );
 665+
 666+ return $dbr->select(
 667+ array( 'imagelinks', 'page' ),
 668+ array( 'page_namespace', 'page_title', 'page_is_redirect', 'il_to' ),
 669+ array( 'il_to' => $target, 'il_from = page_id' ),
 670+ __METHOD__,
 671+ array( 'LIMIT' => $limit + 1 )
 672+ );
 673+ }
 674+
664675 protected function imageLinks() {
665676 global $wgUser, $wgOut, $wgLang;
666677
667678 $limit = 100;
 679+
 680+ $res = $this->queryImageLinks( $this->mTitle->getDbKey(), $limit + 1);
 681+ $rows = array();
 682+ $redirects = array();
 683+ foreach ( $res as $row ) {
 684+ if ( $row->page_is_redirect ) {
 685+ $redirects[$row->page_title] = array();
 686+ }
 687+ $rows[] = $row;
 688+ }
 689+ $count = count( $rows );
 690+
 691+ $hasMore = $count > $limit;
 692+ if ( !$hasMore && count( $redirects ) ) {
 693+ $res = $this->queryImageLinks( array_keys( $redirects ),
 694+ $limit - count( $rows ) + 1 );
 695+ foreach ( $res as $row ) {
 696+ $redirects[$row->il_to][] = $row;
 697+ $count++;
 698+ }
 699+ $hasMore = ( $res->numRows() + count( $rows ) ) > $limit;
 700+ }
668701
669 - $dbr = wfGetDB( DB_SLAVE );
670 -
671 - $res = $dbr->select(
672 - array( 'imagelinks', 'page' ),
673 - array( 'page_namespace', 'page_title' ),
674 - array( 'il_to' => $this->mTitle->getDBkey(), 'il_from = page_id' ),
675 - __METHOD__,
676 - array( 'LIMIT' => $limit + 1 )
677 - );
678 - $count = $dbr->numRows( $res );
679702 if ( $count == 0 ) {
680703 $wgOut->wrapWikiMsg(
681704 Html::rawElement( 'div',
@@ -685,7 +708,7 @@
686709 }
687710
688711 $wgOut->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" );
689 - if ( $count <= $limit - 1 ) {
 712+ if ( !$hasMore ) {
690713 $wgOut->addWikiMsg( 'linkstoimage', $count );
691714 } else {
692715 // More links than the limit. Add a link to [[Special:Whatlinkshere]]
@@ -701,25 +724,44 @@
702725 );
703726 $sk = $wgUser->getSkin();
704727 $count = 0;
705 - $elements = array();
706 - foreach ( $res as $s ) {
707 - $count++;
708 - if ( $count <= $limit ) {
709 - // We have not yet reached the extra one that tells us there is more to fetch
710 - $elements[] = $s;
711 - }
712 - }
713728
714729 // Sort the list by namespace:title
715 - usort( $elements, array( $this, 'compare' ) );
 730+ usort( $rows, array( $this, 'compare' ) );
716731
717732 // Create links for every element
718 - foreach( $elements as $element ) {
 733+ $currentCount = 0;
 734+ foreach( $rows as $element ) {
 735+ $currentCount++;
 736+ if ( $currentCount > $limit ) {
 737+ break;
 738+ }
 739+
719740 $link = $sk->linkKnown( Title::makeTitle( $element->page_namespace, $element->page_title ) );
 741+ if ( !isset( $redirects[$element->page_title] ) ) {
 742+ $liContents = $link;
 743+ } else {
 744+ $ul = "<ul class='mw-imagepage-redirectstofile'>\n";
 745+ foreach ( $redirects[$element->page_title] as $row ) {
 746+ $currentCount++;
 747+ if ( $currentCount > $limit ) {
 748+ break;
 749+ }
 750+
 751+ $link2 = $sk->linkKnown( Title::makeTitle( $row->page_namespace, $row->page_title ) );
 752+ $ul .= Html::rawElement(
 753+ 'li',
 754+ array( 'id' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ),
 755+ $link2
 756+ ) . "\n";
 757+ }
 758+ $ul .= '</ul>';
 759+ $liContents = wfMessage( 'linkstoimage-redirect' )->rawParams(
 760+ $link, $ul )->parse();
 761+ }
720762 $wgOut->addHTML( Html::rawElement(
721763 'li',
722764 array( 'id' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ),
723 - $link
 765+ $liContents
724766 ) . "\n"
725767 );
726768
@@ -733,35 +775,7 @@
734776 }
735777 $wgOut->addHTML( Html::closeElement( 'div' ) . "\n" );
736778 }
737 -
738 - protected function imageRedirects() {
739 - global $wgUser, $wgOut, $wgLang;
740779
741 - $redirects = $this->getTitle()->getRedirectsHere( NS_FILE );
742 - if ( count( $redirects ) == 0 ) {
743 - return;
744 - }
745 -
746 - $wgOut->addHTML( "<div id='mw-imagepage-section-redirectstofile'>\n" );
747 - $wgOut->addWikiMsg( 'redirectstofile',
748 - $wgLang->formatNum( count( $redirects ) )
749 - );
750 - $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
751 -
752 - $sk = $wgUser->getSkin();
753 - foreach ( $redirects as $title ) {
754 - $link = $sk->link(
755 - $title,
756 - null,
757 - array(),
758 - array( 'redirect' => 'no' ),
759 - array( 'known', 'noclasses' )
760 - );
761 - $wgOut->addHTML( "<li>{$link}</li>\n" );
762 - }
763 - $wgOut->addHTML( "</ul></div>\n" );
764 - }
765 -
766780 protected function imageDupes() {
767781 global $wgOut, $wgUser, $wgLang;
768782
Index: trunk/phase3/languages/messages/MessagesQqq.php
@@ -1901,8 +1901,10 @@
19021902
19031903 * $1: limit. At the moment hardcoded at 100
19041904 * $2: filename',
 1905+'linkstoimage-redirect' => 'Item in the "the following pages link to this file" section on a file page if the item is a redirect.
 1906+* $1: an HTML link to the file
 1907+* $2: the list of files that link to the redirect (may be empty)',
19051908 'nolinkstoimage' => 'Displayed on image description pages, see for exampe [[:Image:Tournesol.png#filelinks]].',
1906 -'redirectstofile' => 'Used on file description pages after the list of pages which used this file',
19071909 'duplicatesoffile' => 'Shown on file description pages when a file is duplicated
19081910
19091911 * $1: Number of identical files
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2333,7 +2333,7 @@
23342334 A [[Special:WhatLinksHere/$2|full list]] is available.',
23352335 'nolinkstoimage' => 'There are no pages that link to this file.',
23362336 'morelinkstoimage' => 'View [[Special:WhatLinksHere/$1|more links]] to this file.',
2337 -'redirectstofile' => 'The following {{PLURAL:$1|file redirects|$1 files redirect}} to this file:',
 2337+'linkstoimage-redirect' => '$1 (file redirect) $2',
23382338 'duplicatesoffile' => 'The following {{PLURAL:$1|file is a duplicate|$1 files are duplicates}} of this file ([[Special:FileDuplicateSearch/$2|more details]]):',
23392339 'sharedupload' => 'This file is from $1 and may be used by other projects.',
23402340 'sharedupload-desc-there' => 'This file is from $1 and may be used by other projects.

Follow-up revisions

RevisionCommit summaryAuthorDate
r88071Follow-up r88054: Update messages.incbtongminh13:12, 14 May 2011
r88082RELEASE-NOTES for r88054btongminh14:08, 14 May 2011
r91785Follow-up r88054: register the file if a hook changed the target file.btongminh10:31, 9 July 2011

Comments

#Comment by Siebrand (talk | contribs)   13:09, 14 May 2011

Please update maintenance/language/messages.inc. Old key needs to be removed, new needs to be added.

#Comment by Bryan (talk | contribs)   13:14, 14 May 2011
#Comment by Siebrand (talk | contribs)   01:22, 15 May 2011

Thank you, Bryan.

#Comment by Aaron Schulz (talk | contribs)   06:15, 22 June 2011

This still could use better handling for the $sha1 case (where the file has a different title than $title).

#Comment by Bryan (talk | contribs)   20:42, 29 June 2011

Can you clarify this comment? I have absolutely zarroo idea what you are talking about.

#Comment by Aaron Schulz (talk | contribs)   20:43, 29 June 2011

If a hook causes $sha1 to be filled, the file selected may have a different title than $title. No dependency on the true title will be added, so if it changes the cache won't update the page using the file.

#Comment by Bryan (talk | contribs)   20:44, 7 July 2011

I'm confused. Which hook? Can you point me to the file and the hook name?

#Comment by Aaron Schulz (talk | contribs)   19:09, 8 July 2011

BeforeParserFetchFileAndTitle in Parser.php.

#Comment by Bryan (talk | contribs)   10:35, 9 July 2011

Status & tagging log