X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=maintenance%2FcleanupImages.php;h=4e7b937dbf0cddcb3db6a5fa1b5a2eb426b3707c;hb=fcdf2518605954fe1bcf88598fc14bd95d525882;hp=267061009ac7ade2cd940fed36b81906b10bb6aa;hpb=27665d27ae0e545b341cc76940a9c78d8e0d21eb;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/cleanupImages.php b/maintenance/cleanupImages.php index 267061009a..4e7b937dbf 100644 --- a/maintenance/cleanupImages.php +++ b/maintenance/cleanupImages.php @@ -1,12 +1,12 @@ + * Copyright © 2005-2006 Brion Vibber * http://www.mediawiki.org/ * * This program is free software; you can redistribute it and/or modify @@ -29,8 +29,13 @@ * @ingroup Maintenance */ -require_once( dirname( __FILE__ ) . '/cleanupTable.inc' ); +require_once( __DIR__ . '/cleanupTable.inc' ); +/** + * Maintenance script to clean up broken, unparseable upload filenames. + * + * @ingroup Maintenance + */ class ImageCleanup extends TableCleanup { protected $defaultParams = array( 'table' => 'image', @@ -73,8 +78,9 @@ class ImageCleanup extends TableCleanup { if ( is_null( $title ) ) { $this->output( "page $source ($cleaned) is illegal.\n" ); $safe = $this->buildSafeTitle( $cleaned ); - if ( $safe === false ) + if ( $safe === false ) { return $this->progress( 0 ); + } $this->pokeFile( $source, $safe ); return $this->progress( 1 ); } @@ -86,7 +92,7 @@ class ImageCleanup extends TableCleanup { return $this->progress( 1 ); } - $this->progress( 0 ); + return $this->progress( 0 ); } /** @@ -123,7 +129,8 @@ class ImageCleanup extends TableCleanup { $path = $this->filePath( $orig ); if ( !file_exists( $path ) ) { $this->output( "missing file: $path\n" ); - return $this->killRow( $orig ); + $this->killRow( $orig ); + return; } $db = wfGetDB( DB_MASTER ); @@ -138,7 +145,7 @@ class ImageCleanup extends TableCleanup { $version = 0; $final = $new; $conflict = ( $this->imageExists( $final, $db ) || - ( $this->pageExists( $orig, $db ) && $this->pageExists( $final, $db ) ) ); + ( $this->pageExists( $orig, $db ) && $this->pageExists( $final, $db ) ) ); while ( $conflict ) { $this->output( "Rename conflicts with '$final'...\n" ); @@ -154,7 +161,7 @@ class ImageCleanup extends TableCleanup { } else { $this->output( "renaming $path to $finalPath\n" ); // @todo FIXME: Should this use File::move()? - $db->begin(); + $db->begin( __METHOD__ ); $db->update( 'image', array( 'img_name' => $final ), array( 'img_name' => $orig ), @@ -170,16 +177,16 @@ class ImageCleanup extends TableCleanup { $dir = dirname( $finalPath ); if ( !file_exists( $dir ) ) { if ( !wfMkdirParents( $dir, null, __METHOD__ ) ) { - $this->log( "RENAME FAILED, COULD NOT CREATE $dir" ); - $db->rollback(); + $this->output( "RENAME FAILED, COULD NOT CREATE $dir" ); + $db->rollback( __METHOD__ ); return; } } if ( rename( $path, $finalPath ) ) { - $db->commit(); + $db->commit( __METHOD__ ); } else { $this->error( "RENAME FAILED" ); - $db->rollback(); + $db->rollback( __METHOD__ ); } } } @@ -190,9 +197,8 @@ class ImageCleanup extends TableCleanup { } private function buildSafeTitle( $name ) { - global $wgLegalTitleChars; $x = preg_replace_callback( - "/([^$wgLegalTitleChars]|~)/", + '/([^' . Title::legalChars() . ']|~)/', array( $this, 'hexChar' ), $name );