(bug 23002) Imagelinks table not updated after imagemove. The actual bug was inconsis...
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Sat, 14 May 2011 12:20:45 +0000 (12:20 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Sat, 14 May 2011 12:20:45 +0000 (12:20 +0000)
* 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.

includes/ImagePage.php
includes/parser/Parser.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php

index 6d4aedf..54c676c 100644 (file)
@@ -140,7 +140,6 @@ class ImagePage extends Article {
                $this->imageDupes();
                # TODO! FIXME! For some freaky reason, we can't redirect to foreign images.
                # Yet we return metadata about the target. Definitely an issue in the FileRepo
-               $this->imageRedirects();
                $this->imageLinks();
                
                # Allow extensions to add something after the image links
@@ -660,21 +659,45 @@ EOT
                }
        }
 
-       protected function imageLinks() {
-               global $wgUser, $wgOut, $wgLang;
-
-               $limit = 100;
-
+       protected function queryImageLinks( $target, $limit ) {
                $dbr = wfGetDB( DB_SLAVE );
 
-               $res = $dbr->select(
+               return $dbr->select(
                        array( 'imagelinks', 'page' ),
-                       array( 'page_namespace', 'page_title' ),
-                       array( 'il_to' => $this->mTitle->getDBkey(), 'il_from = page_id' ),
+                       array( 'page_namespace', 'page_title', 'page_is_redirect', 'il_to' ),
+                       array( 'il_to' => $target, 'il_from = page_id' ),
                        __METHOD__,
                        array( 'LIMIT' => $limit + 1 )
-               );
-               $count = $dbr->numRows( $res );
+               );              
+       }
+       
+       protected function imageLinks() {
+               global $wgUser, $wgOut, $wgLang;
+
+               $limit = 100;
+               
+               $res = $this->queryImageLinks( $this->mTitle->getDbKey(), $limit + 1);
+               $rows = array();
+               $redirects = array();
+               foreach ( $res as $row ) {
+                       if ( $row->page_is_redirect ) {
+                               $redirects[$row->page_title] = array();
+                       }
+                       $rows[] = $row;
+               }
+               $count = count( $rows );
+               
+               $hasMore = $count > $limit;
+               if ( !$hasMore && count( $redirects ) ) {
+                       $res = $this->queryImageLinks( array_keys( $redirects ), 
+                               $limit - count( $rows ) + 1 );
+                       foreach ( $res as $row ) {
+                               $redirects[$row->il_to][] = $row;
+                               $count++;
+                       }
+                       $hasMore = ( $res->numRows() + count( $rows ) ) > $limit;
+               }
+
                if ( $count == 0 ) {
                        $wgOut->wrapWikiMsg(
                                Html::rawElement( 'div',
@@ -685,7 +708,7 @@ EOT
                }
                
                $wgOut->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" );
-               if ( $count <= $limit - 1 ) {
+               if ( !$hasMore ) {
                        $wgOut->addWikiMsg( 'linkstoimage', $count );
                } else {
                        // More links than the limit. Add a link to [[Special:Whatlinkshere]]
@@ -701,25 +724,44 @@ EOT
                );
                $sk = $wgUser->getSkin();
                $count = 0;
-               $elements = array();
-               foreach ( $res as $s ) {
-                       $count++;
-                       if ( $count <= $limit ) {
-                               // We have not yet reached the extra one that tells us there is more to fetch
-                               $elements[] =  $s;
-                       }
-               }
 
                // Sort the list by namespace:title
-               usort( $elements, array( $this, 'compare' ) );
+               usort( $rows, array( $this, 'compare' ) );
 
                // Create links for every element
-               foreach( $elements as $element ) {    
+               $currentCount = 0;
+               foreach( $rows as $element ) {
+                       $currentCount++;
+                       if ( $currentCount > $limit ) {
+                               break;
+                       }
+                           
                        $link = $sk->linkKnown( Title::makeTitle( $element->page_namespace, $element->page_title ) );
+                       if ( !isset( $redirects[$element->page_title] ) ) {
+                               $liContents = $link;
+                       } else {
+                               $ul = "<ul class='mw-imagepage-redirectstofile'>\n";
+                               foreach ( $redirects[$element->page_title] as $row ) {
+                                       $currentCount++;
+                                       if ( $currentCount > $limit ) {
+                                               break;
+                                       }
+                                       
+                                       $link2 = $sk->linkKnown( Title::makeTitle( $row->page_namespace, $row->page_title ) );
+                                       $ul .= Html::rawElement(
+                                               'li',
+                                               array( 'id' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ),
+                                               $link2
+                                               ) . "\n";
+                               }
+                               $ul .= '</ul>';
+                               $liContents = wfMessage( 'linkstoimage-redirect' )->rawParams( 
+                                       $link, $ul )->parse();
+                       }
                        $wgOut->addHTML( Html::rawElement(
                                        'li',
                                        array( 'id' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ),
-                                       $link
+                                       $liContents
                                ) . "\n"
                        );
 
@@ -733,34 +775,6 @@ EOT
                }
                $wgOut->addHTML( Html::closeElement( 'div' ) . "\n" );
        }
-       
-       protected function imageRedirects() {
-               global $wgUser, $wgOut, $wgLang;
-
-               $redirects = $this->getTitle()->getRedirectsHere( NS_FILE );
-               if ( count( $redirects ) == 0 ) {
-                       return;
-               }
-
-               $wgOut->addHTML( "<div id='mw-imagepage-section-redirectstofile'>\n" );
-               $wgOut->addWikiMsg( 'redirectstofile',
-                       $wgLang->formatNum( count( $redirects ) )
-               );
-               $wgOut->addHTML( "<ul class='mw-imagepage-redirectstofile'>\n" );
-
-               $sk = $wgUser->getSkin();
-               foreach ( $redirects as $title ) {
-                       $link = $sk->link(
-                               $title,
-                               null,
-                               array(),
-                               array( 'redirect' => 'no' ),
-                               array( 'known', 'noclasses' )
-                       );
-                       $wgOut->addHTML( "<li>{$link}</li>\n" );
-               }
-               $wgOut->addHTML( "</ul></div>\n" );
-       }
 
        protected function imageDupes() {
                global $wgOut, $wgUser, $wgLang;
index e1cafa7..1f780fb 100644 (file)
@@ -3508,8 +3508,6 @@ class Parser {
                # Register the file as a dependency...
                $this->mOutput->addImage( $title->getDBkey(), $time, $sha1 );
                if ( $file && !$title->equals( $file->getTitle() ) ) {
-                       # We fetched a rev from a different title; register it too...
-                       $this->mOutput->addImage( $file->getTitle()->getDBkey(), $time, $sha1 );
                        # Update fetched file title 
                        $title = $file->getTitle();
                }
index 098211e..751a0ab 100644 (file)
@@ -2333,7 +2333,7 @@ The following list shows the {{PLURAL:$1|first page link|first $1 page links}} t
 A [[Special:WhatLinksHere/$2|full list]] is available.',
 'nolinkstoimage'                    => 'There are no pages that link to this file.',
 'morelinkstoimage'                  => 'View [[Special:WhatLinksHere/$1|more links]] to this file.',
-'redirectstofile'                   => 'The following {{PLURAL:$1|file redirects|$1 files redirect}} to this file:',
+'linkstoimage-redirect'                                => '$1 (file redirect) $2',
 'duplicatesoffile'                  => 'The following {{PLURAL:$1|file is a duplicate|$1 files are duplicates}} of this file ([[Special:FileDuplicateSearch/$2|more details]]):',
 'sharedupload'                      => 'This file is from $1 and may be used by other projects.',
 'sharedupload-desc-there'           => 'This file is from $1 and may be used by other projects.
index 5b43b06..4e20402 100644 (file)
@@ -1901,8 +1901,10 @@ Example: [[:Image:Addon-icn.png]]',
 
 * $1: limit. At the moment hardcoded at 100
 * $2: filename',
+'linkstoimage-redirect'                                => 'Item in the "the following pages link to this file" section on a file page if the item is a redirect.
+* $1: an HTML link to the file
+* $2: the list of files that link to the redirect (may be empty)',
 'nolinkstoimage'                    => 'Displayed on image description pages, see for exampe [[:Image:Tournesol.png#filelinks]].',
-'redirectstofile'                   => 'Used on file description pages after the list of pages which used this file',
 'duplicatesoffile'                  => 'Shown on file description pages when a file is duplicated
 
 * $1: Number of identical files