* Add new flag FIND_IGNORE_REDIRECT to wfFindFile and functions it depends on
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Thu, 8 May 2008 20:15:09 +0000 (20:15 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Thu, 8 May 2008 20:15:09 +0000 (20:15 +0000)
* Follow redirects on image pages if the redirect is actually an image redirect
* Add comments to the check for redirect code in MediaWiki::initializeArticle so that I actually understand what it does

includes/GlobalFunctions.php
includes/Wiki.php
includes/filerepo/FileRepo.php
includes/filerepo/RepoGroup.php

index 07cfdf6..e84e82c 100644 (file)
@@ -2425,10 +2425,11 @@ function &wfGetLBFactory() {
  * @param mixed $time Requested time for an archived image, or false for the
  *                    current version. An image object will be returned which
  *                    was created at the specified time.
+ * @param mixed $flags FileRepo::FIND_ flags
  * @return File, or false if the file does not exist
  */
-function wfFindFile( $title, $time = false ) {
-       return RepoGroup::singleton()->findFile( $title, $time );
+function wfFindFile( $title, $time = false, $flags = 0 ) {
+       return RepoGroup::singleton()->findFile( $title, $time, $flags );
 }
 
 /**
index 8930902..8f9368a 100644 (file)
@@ -277,11 +277,17 @@ class MediaWiki {
 
                $action = $this->getVal( 'action' );
                $article = self::articleFromTitle( $title );
-
+               
+               wfDebug("Article: ".$title->getPrefixedText()."\n");
+               
                // Namespace might change when using redirects
-               if( ( $action == 'view' || $action == 'render' ) && !$request->getVal( 'oldid' ) &&
-                                               $request->getVal( 'redirect' ) != 'no' &&
-                                               !( $title->getNamespace() == NS_IMAGE && wfFindFile( $title->getText() ) ) ) {
+               // Check for redirects ...
+               if( ( $action == 'view' || $action == 'render' )        // ... for actions that show content
+                                       && !$request->getVal( 'oldid' ) &&                      // ... and are not old revisions
+                                       $request->getVal( 'redirect' ) != 'no' &&       // ... unless explicitly told not to
+                                       // ... and the article is not an image page with associated file
+                                       !( $title->getNamespace() == NS_IMAGE && wfFindFile( $title->getText(), false,
+                                                       FileRepo::FIND_IGNORE_REDIRECT ) ) ) { // ... unless it is really an image redirect
 
                        $dbr = wfGetDB( DB_SLAVE );
                        $article->loadPageData( $article->pageDataFromTitle( $dbr, $title ) );
index 2fd1749..b7559e8 100644 (file)
@@ -7,6 +7,7 @@
 abstract class FileRepo {
        const DELETE_SOURCE = 1;
        const FIND_PRIVATE = 1;
+       const FIND_IGNORE_REDIRECT = 2;
        const OVERWRITE = 2;
        const OVERWRITE_SAME = 4;
 
@@ -104,8 +105,10 @@ abstract class FileRepo {
                                }
                        }
                }
+                               
                # Now try redirects
-               $redir = $this->checkRedirect( $title );
+               if ( $flags & FileRepo::FIND_IGNORE_REDIRECT ) return false;
+               $redir = $this->checkRedirect( $title );                
                if( $redir && $redir->getNamespace() == NS_IMAGE) {
                        $img = $this->newFile( $redir );
                        if( !$img ) {
index 39e5688..477265e 100644 (file)
@@ -56,19 +56,20 @@ class RepoGroup {
         * @param mixed $title Title object or string
         * @param mixed $time The 14-char timestamp the file should have
         *                    been uploaded, or false for the current version
+        * @param mixed $flags FileRepo::FIND_ flags
         * @return File object or false if it is not found
         */
-       function findFile( $title, $time = false ) {
+       function findFile( $title, $time = false, $flags = 0 ) {
                if ( !$this->reposInitialised ) {
                        $this->initialiseRepos();
                }
 
-               $image = $this->localRepo->findFile( $title, $time );
+               $image = $this->localRepo->findFile( $title, $time, $flags );
                if ( $image ) {
                        return $image;
                }
                foreach ( $this->foreignRepos as $repo ) {
-                       $image = $repo->findFile( $title, $time );
+                       $image = $repo->findFile( $title, $time, $flags );
                        if ( $image ) {
                                return $image;
                        }