Show pages that redirect to this image on ImagePage
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Thu, 8 May 2008 21:53:39 +0000 (21:53 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Thu, 8 May 2008 21:53:39 +0000 (21:53 +0000)
includes/ImagePage.php
languages/messages/MessagesEn.php

index 887f2dc..bbc1745 100644 (file)
@@ -91,6 +91,7 @@ class ImagePage extends Article {
                $this->closeShowImage();
                $this->imageHistory();
                $this->imageLinks();
+               if ( $this->img->isLocal() ) $this->imageRedirects();
 
                if ( $showmeta ) {
                        global $wgStylePath, $wgStyleVersion;
@@ -540,6 +541,40 @@ EOT
                }
                $wgOut->addHTML( "</ul>\n" );
        }
+       
+       function imageRedirects() 
+       {
+               global $wgUser, $wgOut;
+               
+               $dbr = wfGetDB( DB_SLAVE );
+               $res = $dbr->select(
+                       array( 'redirect', 'page' ),
+                       array( 'page_title' ),
+                       array(
+                               'rd_namespace' => NS_IMAGE,
+                               'rd_title' => $this->mTitle->getDBkey(),
+                               'page_namespace' => NS_IMAGE,
+                               'rd_from = page_id'
+                       )
+               );
+               
+
+               if ( 0 == $dbr->numRows( $res ) ) 
+                       return;
+
+               $wgOut->addHTML( '<p>' . wfMsg( 'redirectstofile' ) .  "</p>\n<ul>" );
+
+               $sk = $wgUser->getSkin();
+               while ( $row = $dbr->fetchObject( $res ) ) {
+                       $name = Title::makeTitle( NS_IMAGE, $row->page_title );
+                       $link = $sk->makeKnownLinkObj( $name, "" );
+                       wfDebug("Image redirect: {$row->page_title}\n");
+                       $wgOut->addHTML( "<li>{$link}</li>\n" );
+               }
+               $wgOut->addHTML( "</ul>\n" );
+               
+               $res->free();
+       }
 
        /**
         * Delete the file, or an earlier version of it
index d11dcd9..8198f81 100644 (file)
@@ -1710,6 +1710,7 @@ A click on a column header changes the sorting.',
 'imagelinks'                     => 'Links',
 'linkstoimage'                   => 'The following pages link to this file:',
 'nolinkstoimage'                 => 'There are no pages that link to this file.',
+'redirectstofile'                => 'The following files redirect to this file:',
 'sharedupload'                   => 'This file is a shared upload and may be used by other projects.',
 'shareduploadwiki'               => 'Please see the $1 for further information.',
 'shareduploadwiki-desc'          => 'The description on its $1 there is shown below.',