ItSpiderman has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/336252 )

Change subject: Fix for missing archive images after file move
......................................................................

Fix for missing archive images after file move

When a file is moved to a different namespace, all arhived versions
of this file become unavailable. This was caused by the fact that
the archive file names were written with namespace and colon in them.
This would also cause problems on Windows systems.

For current version of a file NSFileRepo passes new file URL stripped
of namespace prefix, but in case of archived files, file name is used
and it was not stripped. Also when file name would eventually got
stipped, timestamp part of file name would be removed as well,
leading again to broken file path.

Change-Id: I9a48ee0e21e8ba3eb01de7a9b7e5e590d29f43a9
---
M includes/filerepo/file/NSLocalFile.php
1 file changed, 71 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/NSFileRepo 
refs/changes/52/336252/1

diff --git a/includes/filerepo/file/NSLocalFile.php 
b/includes/filerepo/file/NSLocalFile.php
index d2b1222..7491433 100644
--- a/includes/filerepo/file/NSLocalFile.php
+++ b/includes/filerepo/file/NSLocalFile.php
@@ -176,8 +176,20 @@
         * @return string
         */
        public static function getFileNameStripped($suffix) {
-               $bits = explode( ':', $suffix );
-               return $bits[ count( $bits ) -1 ];
+               $iNsEndPos = strpos( $suffix, ":");
+               if( $iNsEndPos ){
+                   $sRes = '';
+                   $iTsEndPos = strpos( $suffix, "!" );
+
+                   if( $iTsEndPos ) {
+                       $sRes = substr( $suffix, 0, $iTsEndPos +1 );
+                   }
+                   $sRes .= substr( $suffix,  $iNsEndPos +1, strlen( $suffix ) 
-1 );
+
+                   return $sRes;
+               } else {
+                   return $suffix;
+               }
        }
 
        /**
@@ -347,4 +359,61 @@
                $this->newRel = $this->newHash . 
NSLocalFile::getFileNameStripped( $this->newName );
                $this->db = $file->getRepo()->getMasterDb();
        }
+
+       /**
+        * Add the old versions of the image to the batch
+        * @return array List of archive names from old versions
+        */
+       function addOlds() {
+/* This is the part that changed from LocalFile */
+               $newName = $this->getFileNameStripped( $this->newName );
+/* End of changes */
+               $archiveBase = 'archive';
+               $this->olds = array();
+               $this->oldCount = 0;
+               $archiveNames = array();
+
+               $result = $this->db->select( 'oldimage',
+                       array( 'oi_archive_name', 'oi_deleted' ),
+                       array( 'oi_name' => $this->oldName ),
+                       __METHOD__
+               );
+
+               foreach ( $result as $row ) {
+                       $archiveNames[] = $row->oi_archive_name;
+                       $oldName = $row->oi_archive_name;
+                       $bits = explode( '!', $oldName, 2 );
+
+                       if ( count( $bits ) != 2 ) {
+                               wfDebug( "Old file name missing !: '$oldName' 
\n" );
+                               continue;
+                       }
+
+                       list( $timestamp, $filename ) = $bits;
+
+                       if ( $this->oldName != $filename ) {
+                               wfDebug( "Old file name doesn't match: 
'$oldName' \n" );
+                               continue;
+                       }
+
+                       $this->oldCount++;
+
+                       // Do we want to add those to oldCount?
+                       if ( $row->oi_deleted & File::DELETED_FILE ) {
+                               continue;
+                       }
+/* This is the part that changed from LocalFile */
+                       $this->olds[] = array(
+                               "{$archiveBase}/{$this->oldHash}{$oldName}",
+                               
"{$archiveBase}/{$this->newHash}{$timestamp}!{$newName}"
+                       );
+/* End of changes */
+               }
+
+               return $archiveNames;
+       }
+
+       function getFileNameStripped( $suffix ) {
+               return(NSLocalFile::getFileNameStripped($suffix));
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/336252
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9a48ee0e21e8ba3eb01de7a9b7e5e590d29f43a9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/NSFileRepo
Gerrit-Branch: REL1_27
Gerrit-Owner: ItSpiderman <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to