From d64452ffe1a6027f67e2e98ae800bb97cb070222 Mon Sep 17 00:00:00 2001 From: Ilmari Karonen Date: Fri, 21 Nov 2008 04:54:47 +0000 Subject: [PATCH] Clean up image titles with HTML entities (made invalid in r28968). Also misc. improvements: fail gracefully if buildSafeTitle() fails, move description page and old image revisions too. --- maintenance/cleanupImages.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/maintenance/cleanupImages.php b/maintenance/cleanupImages.php index 79ff54e84f..df765d816f 100644 --- a/maintenance/cleanupImages.php +++ b/maintenance/cleanupImages.php @@ -54,6 +54,9 @@ class ImageCleanup extends TableCleanup { // About half of old bad image names have percent-codes $cleaned = rawurldecode( $cleaned ); + + // We also have some HTML entities there + $cleaned = Sanitizer::decodeCharReferences( $cleaned ); // Some are old latin-1 $cleaned = $wgContLang->checkTitleEncoding( $cleaned ); @@ -66,6 +69,8 @@ class ImageCleanup extends TableCleanup { if( is_null( $title ) ) { $this->log( "page $source ($cleaned) is illegal." ); $safe = $this->buildSafeTitle( $cleaned ); + if( $safe === false ) + return $this->progress( 0 ); $this->pokeFile( $source, $safe ); return $this->progress( 1 ); } @@ -110,8 +115,8 @@ class ImageCleanup extends TableCleanup { $version = 0; $final = $new; - while( $db->selectField( 'image', 'img_name', - array( 'img_name' => $final ), __METHOD__ ) ) { + while( $db->selectField( 'image', 'img_name', array( 'img_name' => $final ), __METHOD__ ) || + Title::makeTitle( NS_IMAGE, $final )->exists() ) { $this->log( "Rename conflicts with '$final'..." ); $version++; $final = $this->appendTitle( $new, "_$version" ); @@ -123,11 +128,20 @@ class ImageCleanup extends TableCleanup { $this->log( "DRY RUN: would rename $path to $finalPath" ); } else { $this->log( "renaming $path to $finalPath" ); + // XXX: should this use File::move()? FIXME? $db->begin(); $db->update( 'image', array( 'img_name' => $final ), array( 'img_name' => $orig ), __METHOD__ ); + $db->update( 'oldimage', + array( 'oi_name' => $final ), + array( 'oi_name' => $orig ), + __METHOD__ ); + $db->update( 'page', + array( 'page_title' => $final ), + array( 'page_title' => $orig, 'page_namespace' => NS_IMAGE ), + __METHOD__ ); $dir = dirname( $finalPath ); if( !file_exists( $dir ) ) { if( !mkdir( $dir, 0777, true ) ) { -- 2.20.1