* @ingroup Maintenance
*/
+use MediaWiki\MediaWikiServices;
+
require_once __DIR__ . '/cleanupTable.inc';
/**
*
* @ingroup Maintenance
*/
-class ImageCleanup extends TableCleanup {
+class CleanupImages extends TableCleanup {
protected $defaultParams = [
'table' => 'image',
'conds' => [],
'callback' => 'processRow',
];
+ /** @var LocalRepo|null */
+ private $repo;
+
public function __construct() {
parent::__construct();
$this->addDescription( 'Script to clean up broken, unparseable upload filenames' );
}
protected function processRow( $row ) {
- global $wgContLang;
-
$source = $row->img_name;
if ( $source == '' ) {
// Ye olde empty rows. Just kill them.
// We also have some HTML entities there
$cleaned = Sanitizer::decodeCharReferences( $cleaned );
+ $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+
// Some are old latin-1
- $cleaned = $wgContLang->checkTitleEncoding( $cleaned );
+ $cleaned = $contLang->checkTitleEncoding( $cleaned );
// Many of remainder look like non-normalized unicode
- $cleaned = $wgContLang->normalize( $cleaned );
+ $cleaned = $contLang->normalize( $cleaned );
$title = Title::makeTitleSafe( NS_FILE, $cleaned );
}
}
+ /**
+ * @param string $name
+ * @return string
+ */
private function filePath( $name ) {
- if ( !isset( $this->repo ) ) {
+ if ( $this->repo === null ) {
$this->repo = RepoGroup::singleton()->getLocalRepo();
}
* if the target title exists in the image table, or if both the
* original and target titles exist in the page table, append
* increasing version numbers until the target title exists in
- * neither. (See also bug 16916.)
+ * neither. (See also T18916.)
*/
$version = 0;
$final = $new;
}
}
-$maintClass = "ImageCleanup";
+$maintClass = CleanupImages::class;
require_once RUN_MAINTENANCE_IF_MAIN;