* Support images-redirects
authorVictor Vasiliev <vasilievvv@users.mediawiki.org>
Sat, 29 Dec 2007 09:32:22 +0000 (09:32 +0000)
committerVictor Vasiliev <vasilievvv@users.mediawiki.org>
Sat, 29 Dec 2007 09:32:22 +0000 (09:32 +0000)
Note: this revision requires schema change

RELEASE-NOTES
includes/Article.php
includes/filerepo/FileRepo.php
maintenance/archives/patch-image_reditects.sql [new file with mode: 0644]
maintenance/tables.sql
maintenance/updaters.inc

index 5e80096..704a9a1 100644 (file)
@@ -112,6 +112,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * Add HTML ID's mw-read-only-warning and mw-anon-edit-warning to warnings when
   editing to allow CSS styling.
 * Parser now returns list of sections
+* Support images-redirects
 
 === Bug fixes in 1.12 ===
 
index 9a7e85b..9cd73f6 100644 (file)
@@ -1098,6 +1098,28 @@ class Article {
                $isRedirect = !is_null($redirectTitle);
                if ($isRedirect || is_null($lastRevIsRedirect) || $lastRevIsRedirect !== $isRedirect) {
 
+                       $imageResult = true;    //Result of imageredirects handling
+                       file_put_contents( "C:\\err.txt", strval( $this->mTitle->getNamespace() == NS_IMAGE ) );
+                       if( $this->mTitle->getNamespace() == NS_IMAGE ) {
+                               wfProfileIn( __METHOD__ . "-img" );
+
+                               $exists = $redirectTitle ? RepoGroup::singleton()->findFile( $redirectTitle->getDBkey() ) !== false : false;
+                               if( $isRedirect && $redirectTitle->getNamespace() == NS_IMAGE && $exists ) {
+                                       $set = array( 
+                                               'ir_from' => $this->mTitle->getDBkey(),
+                                               'ir_to' => $redirectTitle->getDBkey(),
+                                       );
+                                       $dbw->replace( 'imageredirects', array( 'ir_from' ), $set, __METHOD__ );
+                                       $imageResult = $dbw->affectedRows() != 0;
+                               } else {
+                                       // Non-redirect or redirect to non-image
+                                       $where = array( 'ir_from' => $this->mTitle->getDBkey() );
+                                       $dbw->delete( 'imageredirects', $where, __METHOD__ );
+                               }
+
+                               wfProfileOut( __METHOD__ . "-img" );
+                       }
+
                        wfProfileIn( __METHOD__ );
 
                        if ($isRedirect) {
@@ -1117,7 +1139,7 @@ class Article {
                        }
 
                        wfProfileOut( __METHOD__ );
-                       return ( $dbw->affectedRows() != 0 );
+                       return ( $dbw->affectedRows() != 0 ) && $imageResult;
                }
 
                return true;
index cf6d65c..90d284f 100644 (file)
@@ -76,7 +76,14 @@ abstract class FileRepo {
         *
         * @param mixed $time 14-character timestamp, or false for the current version
         */
-       function findFile( $title, $time = false ) {
+       function findFile( $title, $time = false, $redirected = false ) {
+               if ( !($title instanceof Title) ) {
+                       $title = Title::makeTitleSafe( NS_IMAGE, $title );
+                       if ( !is_object( $title ) ) {
+                               return null;
+                       }
+               }
+       
                # First try the current version of the file to see if it precedes the timestamp
                $img = $this->newFile( $title );
                if ( !$img ) {
@@ -90,6 +97,13 @@ abstract class FileRepo {
                if ( $img->exists() ) {
                        return $img;
                }
+
+               #Try redirects
+               if( !$redirected ) {    // Prevent redirect loops
+                       $redir = $this->checkRedirects( $title->getDBkey() );
+                       if( $redir )
+                               return $this->findFile( $redir, $time, $title );
+               }
        }
 
        /**
@@ -400,5 +414,20 @@ abstract class FileRepo {
         * STUB
         */
        function cleanupDeletedBatch( $storageKeys ) {}
+       
+       /**
+        * Check for redirects.
+        */
+       function checkRedirects( $filename ) {
+               $dbr = $this->getSlaveDB();
+               $res = $dbr->selectRow(
+                       'imageredirects',
+                       array( 'ir_from', 'ir_to' ),
+                       array( 'ir_from' => $filename ),
+                       __METHOD__
+               );
+               if( !$res ) return false;
+               return $res->ir_to;
+       }
 }
 
diff --git a/maintenance/archives/patch-image_reditects.sql b/maintenance/archives/patch-image_reditects.sql
new file mode 100644 (file)
index 0000000..66c9b7f
--- /dev/null
@@ -0,0 +1,6 @@
+-- Image redirects. Only existent images are put in this table.
+CREATE TABLE /*$wgDBprefix*/imageredirects (
+       ir_from varchar(255) binary NOT NULL default '',
+       ir_to   varchar(255) binary NOT NULL default '',
+       PRIMARY KEY ir_from (ir_from)
+) /*$wgDBTableOptions*/;
\ No newline at end of file
index 6282f52..52b0ec5 100644 (file)
@@ -710,6 +710,17 @@ CREATE TABLE /*$wgDBprefix*/image (
 
 ) /*$wgDBTableOptions*/;
 
+--
+-- Image redirects. Only existent images are put in this table.
+--
+CREATE TABLE /*$wgDBprefix*/imageredirects (
+       -- Source image name
+       ir_from varchar(255) binary NOT NULL default '',
+       -- Destination image name
+       ir_to   varchar(255) binary NOT NULL default '',
+
+       PRIMARY KEY ir_from (ir_from)
+) /*$wgDBTableOptions*/;
 --
 -- Previous revisions of uploaded files.
 -- Awkwardly, image rows have to be moved into
index 9f7ce2a..4ec5735 100644 (file)
@@ -23,22 +23,23 @@ $wgRenamedTables = array(
 
 $wgNewTables = array(
 #            table          patch file (in maintenance/archives)
-       array( 'hitcounter',    'patch-hitcounter.sql' ),
-       array( 'querycache',    'patch-querycache.sql' ),
-       array( 'objectcache',   'patch-objectcache.sql' ),
-       array( 'categorylinks', 'patch-categorylinks.sql' ),
-       array( 'logging',       'patch-logging.sql' ),
-       array( 'user_newtalk',  'patch-usernewtalk2.sql' ),
-       array( 'transcache',    'patch-transcache.sql' ),
-       array( 'trackbacks',    'patch-trackbacks.sql' ),
-       array( 'externallinks', 'patch-externallinks.sql' ),
-       array( 'job',           'patch-job.sql' ),
-       array( 'langlinks',     'patch-langlinks.sql' ),
-       array( 'querycache_info', 'patch-querycacheinfo.sql' ),
-       array( 'filearchive',   'patch-filearchive.sql' ),
-       array( 'querycachetwo', 'patch-querycachetwo.sql' ),
-       array( 'redirect', 'patch-redirect.sql' ),
+       array( 'hitcounter',       'patch-hitcounter.sql' ),
+       array( 'querycache',       'patch-querycache.sql' ),
+       array( 'objectcache',      'patch-objectcache.sql' ),
+       array( 'categorylinks',    'patch-categorylinks.sql' ),
+       array( 'logging',          'patch-logging.sql' ),
+       array( 'user_newtalk',     'patch-usernewtalk2.sql' ),
+       array( 'transcache',       'patch-transcache.sql' ),
+       array( 'trackbacks',       'patch-trackbacks.sql' ),
+       array( 'externallinks',    'patch-externallinks.sql' ),
+       array( 'job',              'patch-job.sql' ),
+       array( 'langlinks',        'patch-langlinks.sql' ),
+       array( 'querycache_info',  'patch-querycacheinfo.sql' ),
+       array( 'filearchive',      'patch-filearchive.sql' ),
+       array( 'querycachetwo',    'patch-querycachetwo.sql' ),
+       array( 'redirect',         'patch-redirect.sql' ),
        array( 'protected_titles', 'patch-protected_titles.sql' ),
+       array( 'imageredirects',   'patch-image_reditects.sql' ),
 );
 
 $wgNewFields = array(