* Support redirects in image namespace
authorVictor Vasiliev <vasilievvv@users.mediawiki.org>
Wed, 16 Jan 2008 18:27:43 +0000 (18:27 +0000)
committerVictor Vasiliev <vasilievvv@users.mediawiki.org>
Wed, 16 Jan 2008 18:27:43 +0000 (18:27 +0000)
Now doesn't require schema change

RELEASE-NOTES
includes/Linker.php
includes/Wiki.php
includes/filerepo/FileRepo.php
includes/filerepo/LocalRepo.php
includes/filerepo/RepoGroup.php

index 1aa8f28..0d50a7c 100644 (file)
@@ -132,6 +132,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * Add APCOND_INGROUPS
 * Add DBA caching to installer 
 * (bug 18585) Added a bunch of parameters to the revertpage message
+* Support redirects in image namespace
 
 
 === Bug fixes in 1.12 ===
index e0dc1a7..678be8d 100644 (file)
@@ -723,6 +723,10 @@ class Linker {
                                $upload = SpecialPage::getTitleFor( 'Upload' );
                                if( $text == '' )
                                        $text = htmlspecialchars( $title->getPrefixedText() );
+                               $redir = RepoGroup::getLocalRepo()->checkRedirect( $title );
+                               if( $redir ) {  
+                                       return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
+                               } 
                                $q = 'wpDestFile=' . $title->getPartialUrl();
                                if( $query != '' )
                                        $q .= '&' . $query;
index e1a3c5f..2a60262 100644 (file)
@@ -220,6 +220,10 @@ class MediaWiki {
 
                switch( $title->getNamespace() ) {
                case NS_IMAGE:
+                       $file = wfFindFile( $title );
+                       if( $file && $file->getRedirected() ) {
+                               return new Article( $title );
+                       }
                        return new ImagePage( $title );
                case NS_CATEGORY:
                        return new CategoryPage( $title );
index cf6d65c..96bcd19 100644 (file)
@@ -90,6 +90,19 @@ abstract class FileRepo {
                if ( $img->exists() ) {
                        return $img;
                }
+
+               # Now try redirects
+               $redir = $this->checkRedirect( $title );
+               if( $redir ) {
+                       $img = $this->newFile( $redir );
+                       if( !$img ) {
+                               return false;
+                       }
+                       if( $img->exists() ) {
+                               $img->redirectedFrom( $title->getText() );
+                               return $img;
+                       }
+               }
        }
 
        /**
@@ -400,5 +413,15 @@ abstract class FileRepo {
         * STUB
         */
        function cleanupDeletedBatch( $storageKeys ) {}
+
+       /**
+        * Checks if there is a redirect named as $title
+        * STUB
+        *
+        * @param Title $title Title of image
+        */
+       function checkRedirect( $title ) {
+               return false;
+       }
 }
 
index 72f9e9a..021e679 100644 (file)
@@ -62,4 +62,46 @@ class LocalRepo extends FSRepo {
                }
                return $status;
        }
+
+       /**
+        * Function link Title::getArticleID().
+        * We can't say Title object, what database it should use, so we duplicate that function here.
+        */
+       function getArticleID( $title ) {
+               if( !$title instanceof Title ) {
+                       return 0;
+               }
+               $dbr = $this->getSlaveDB();
+               $id = $dbr->selectField(
+                       'page', // Table
+                       'page_id',      //Field
+                       array(  //Conditions
+                               'page_namespace' => $title->getNamespace(),
+                               'page_title' => $title->getDbKey(),
+                       ),
+                       __METHOD__      //Function name
+               );
+               return $id;
+       }
+
+       function checkRedirect( $title ) {
+               $id = $this->getArticleID( $title );
+               if( !$id ) {
+                       return false;
+               }
+               $dbr = $this->getSlaveDB();
+               $row = $dbr->selectRow(
+                       'redirect',
+                       array( 'rd_title', 'rd_namespace' ),
+                       array( 'rd_from' => $id ),
+                       __METHOD__
+               );
+               if( !$row ) {
+                       return false;
+               }
+               if( $row->rd_namespace != NS_IMAGE ) {
+                       return false;
+               }
+               return Title::makeTitle( $row->rd_namespace, $row->rd_title );
+       }
 }
index 4e9a8a6..e5e49d0 100644 (file)
@@ -76,6 +76,27 @@ class RepoGroup {
                return false;
        }
 
+       /**
+        * Interface for FileRepo::checkRedirect()
+        */
+       function checkRedirect( $title ) {
+               if ( !$this->reposInitialised ) {
+                       $this->initialiseRepos();
+               }
+
+               $redir = $this->localRepo->checkRedirect( $title );
+               if( $redir ) {
+                       return $redir;
+               }
+               foreach ( $this->foreignRepos as $repo ) {
+                       $redir = $repo->checkRedirect( $title );
+                       if ( $redir ) {
+                               return $redir;
+                       }
+               }
+               return false;
+       }
+
        /**
         * Get the repo instance with a given key.
         */