Put code to view redirect page in new method Article::viewRedirect in order to allow...
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Sun, 11 May 2008 19:49:08 +0000 (19:49 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Sun, 11 May 2008 19:49:08 +0000 (19:49 +0000)
includes/Article.php
includes/ImagePage.php

index 1558efd..cef4470 100644 (file)
@@ -860,18 +860,8 @@ class Article {
                        }
 
                        elseif ( $rt = Title::newFromRedirect( $text ) ) {
-                               # Display redirect
-                               $imageDir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
-                               $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
                                # Don't overwrite the subtitle if this was an old revision
-                               if( !$wasRedirected && $this->isCurrent() ) {
-                                       $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) );
-                               }
-                               $link = $sk->makeLinkObj( $rt, htmlspecialchars( $rt->getFullText() ) );
-
-                               $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT " />' .
-                                 '<span class="redirectText">'.$link.'</span>' );
-
+                               $this->viewRedirect( $rt, !$wasRedirected && $this->isCurrent() );
                                $parseout = $wgParser->parse($text, $this->mTitle, ParserOptions::newFromUser($wgUser));
                                $wgOut->addParserOutputNoText( $parseout );
                        } else if ( $pcache ) {
@@ -933,6 +923,27 @@ class Article {
                $this->viewUpdates();
                wfProfileOut( __METHOD__ );
        }
+       
+       protected function viewRedirect( $target, $overwriteSubtitle = true, $forceKnown = false ) {
+               global $wgParser, $wgOut, $wgContLang, $wgStylePath, $wgUser;
+               
+               # Display redirect
+               $imageDir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
+               $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
+               
+               if( $overwriteSubtitle ) {
+                       $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) );
+               }
+               $sk = $wgUser->getSkin();
+               if ( $forceKnown )
+                       $link = $sk->makeKnownLinkObj( $target, htmlspecialchars( $target->getFullText() ) );
+               else
+                       $link = $sk->makeLinkObj( $target, htmlspecialchars( $target->getFullText() ) );
+
+               $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT " />' .
+                       '<span class="redirectText">'.$link.'</span>' );
+               
+       }
 
        function addTrackbacks() {
                global $wgOut, $wgUser;
index 7579399..4dacae3 100644 (file)
@@ -44,8 +44,17 @@ class ImagePage extends Article {
        function view() {
                global $wgOut, $wgShowEXIF, $wgRequest, $wgUser;
 
-               if ( $this->img->getRedirected() )
-                       return Article::view();
+               if ( $this->img->getRedirected() ) {
+                       if ( $this->mTitle->getDBkey() == $this->img->getName() ) {
+                               return Article::view();
+                       } else {
+                               $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
+                               $this->viewRedirect( Title::makeTitle( NS_IMAGE, $this->img->getName() ),
+                                       /* $overwriteSubtitle */ true, /* $forceKnown */ true );
+                               $this->viewUpdates();
+                               return;
+                       }
+               }
 
                $diff = $wgRequest->getVal( 'diff' );
                $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );