(bug 33928) make diff title page more relevant
[lhc/web/wiklou.git] / maintenance / rebuildImages.php
index 8fbeb1c..fe3b35c 100644 (file)
  *
  * @file
  * @author Brion Vibber <brion at pobox.com>
- * @ingroup maintenance
+ * @ingroup Maintenance
  */
 
 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
 
 class ImageBuilder extends Maintenance {
+
+       /**
+        * @var DatabaseBase
+        */
+       protected $dbw;
+
        function __construct() {
                parent::__construct();
 
+               global $wgUpdateCompatibleMetadata;
+               //make sure to update old, but compatible img_metadata fields.
+               $wgUpdateCompatibleMetadata = true;
+
                $this->mDescription = 'Script to update image metadata records';
 
                $this->addOption( 'missing', 'Check for files without associated database record' );
@@ -57,6 +67,9 @@ class ImageBuilder extends Maintenance {
                }
        }
 
+       /**
+        * @return FileRepo
+        */
        function getRepo() {
                if ( !isset( $this->repo ) ) {
                        $this->repo = RepoGroup::singleton()->getLocalRepo();
@@ -135,8 +148,7 @@ class ImageBuilder extends Maintenance {
        }
 
        function buildOldImage() {
-               $this->buildTable( 'oldimage', 'oi_archive_name',
-                       array( $this, 'oldimageCallback' ) );
+               $this->buildTable( 'oldimage', 'oi_archive_name', array( $this, 'oldimageCallback' ) );
        }
 
        function oldimageCallback( $row, $copy ) {
@@ -151,42 +163,33 @@ class ImageBuilder extends Maintenance {
        }
 
        function crawlMissing() {
-               $repo = RepoGroup::singleton()->getLocalRepo();
-               $repo->enumFilesInFS( array( $this, 'checkMissingImage' ) );
+               $this->getRepo()->enumFiles( array( $this, 'checkMissingImage' ) );
        }
 
        function checkMissingImage( $fullpath ) {
                $filename = wfBaseName( $fullpath );
-               if ( is_dir( $fullpath ) ) {
-                       return;
-               }
-               if ( is_link( $fullpath ) ) {
-                       $this->output( "skipping symlink at $fullpath\n" );
-                       return;
-               }
                $row = $this->dbw->selectRow( 'image',
                        array( 'img_name' ),
                        array( 'img_name' => $filename ),
                        __METHOD__ );
 
-               if ( $row ) {
-                       // already known, move on
-                       return;
-               } else {
+               if ( !$row ) { // file not registered
                        $this->addMissingImage( $filename, $fullpath );
                }
        }
 
        function addMissingImage( $filename, $fullpath ) {
-               $timestamp = $this->dbw->timestamp( filemtime( $fullpath ) );
-
                global $wgContLang;
+
+               $timestamp = $this->dbw->timestamp( $this->getRepo()->getFileTimestamp( $fullpath ) );
+
                $altname = $wgContLang->checkTitleEncoding( $filename );
                if ( $altname != $filename ) {
                        if ( $this->dryrun ) {
                                $filename = $altname;
                                $this->output( "Estimating transcoding... $altname\n" );
                        } else {
+                               # @FIXME: create renameFile()
                                $filename = $this->renameFile( $filename );
                        }
                }
@@ -209,4 +212,4 @@ class ImageBuilder extends Maintenance {
 }
 
 $maintClass = 'ImageBuilder';
-require( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );