[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/maintenance/ -> checkImages.php (source)

   1  <?php
   2  /**
   3   * Check images to see if they exist, are readable, etc.
   4   *
   5   * This program is free software; you can redistribute it and/or modify
   6   * it under the terms of the GNU General Public License as published by
   7   * the Free Software Foundation; either version 2 of the License, or
   8   * (at your option) any later version.
   9   *
  10   * This program is distributed in the hope that it will be useful,
  11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13   * GNU General Public License for more details.
  14   *
  15   * You should have received a copy of the GNU General Public License along
  16   * with this program; if not, write to the Free Software Foundation, Inc.,
  17   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18   * http://www.gnu.org/copyleft/gpl.html
  19   *
  20   * @file
  21   * @ingroup Maintenance
  22   */
  23  require_once  __DIR__ . '/Maintenance.php';
  24  
  25  /**
  26   * Maintenance script to check images to see if they exist, are readable, etc.
  27   *
  28   * @ingroup Maintenance
  29   */
  30  class CheckImages extends Maintenance {
  31  
  32  	public function __construct() {
  33          parent::__construct();
  34          $this->mDescription = "Check images to see if they exist, are readable, etc";
  35          $this->setBatchSize( 1000 );
  36      }
  37  
  38  	public function execute() {
  39          $start = '';
  40          $dbr = wfGetDB( DB_SLAVE );
  41  
  42          $numImages = 0;
  43          $numGood = 0;
  44  
  45          do {
  46              $res = $dbr->select( 'image', '*', array( 'img_name > ' . $dbr->addQuotes( $start ) ),
  47                  __METHOD__, array( 'LIMIT' => $this->mBatchSize ) );
  48              foreach ( $res as $row ) {
  49                  $numImages++;
  50                  $start = $row->img_name;
  51                  $file = RepoGroup::singleton()->getLocalRepo()->newFileFromRow( $row );
  52                  $path = $file->getPath();
  53                  if ( !$path ) {
  54                      $this->output( "{$row->img_name}: not locally accessible\n" );
  55                      continue;
  56                  }
  57                  wfSuppressWarnings();
  58                  $stat = stat( $file->getPath() );
  59                  wfRestoreWarnings();
  60                  if ( !$stat ) {
  61                      $this->output( "{$row->img_name}: missing\n" );
  62                      continue;
  63                  }
  64  
  65                  if ( $stat['mode'] & 040000 ) {
  66                      $this->output( "{$row->img_name}: is a directory\n" );
  67                      continue;
  68                  }
  69  
  70                  if ( $stat['size'] == 0 && $row->img_size != 0 ) {
  71                      $this->output( "{$row->img_name}: truncated, was {$row->img_size}\n" );
  72                      continue;
  73                  }
  74  
  75                  if ( $stat['size'] != $row->img_size ) {
  76                      $this->output( "{$row->img_name}: size mismatch DB={$row->img_size}, "
  77                          . "actual={$stat['size']}\n" );
  78                      continue;
  79                  }
  80  
  81                  $numGood++;
  82              }
  83          } while ( $res->numRows() );
  84  
  85          $this->output( "Good images: $numGood/$numImages\n" );
  86      }
  87  }
  88  
  89  $maintClass = "CheckImages";
  90  require_once RUN_MAINTENANCE_IF_MAIN;


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1