From 41acfbfcfb0d0f5c85ba1e6062a12e47afd20075 Mon Sep 17 00:00:00 2001 From: Ilmari Karonen Date: Sun, 4 Jan 2009 02:36:03 +0000 Subject: [PATCH] Don't needlessly shy from reuniting lost files with their description pages. --- maintenance/cleanupImages.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/maintenance/cleanupImages.php b/maintenance/cleanupImages.php index 00903f2222..0fe62440a5 100644 --- a/maintenance/cleanupImages.php +++ b/maintenance/cleanupImages.php @@ -114,9 +114,23 @@ class ImageCleanup extends TableCleanup { $db = wfGetDB( DB_MASTER ); $version = 0; $final = $new; + $has_page = Title::makeTitle( NS_FILE, $orig )->exists(); - while( $db->selectField( 'image', 'img_name', array( 'img_name' => $final ), __METHOD__ ) || - Title::makeTitle( NS_FILE, $final )->exists() ) { + while( true ) { + $test = $db->selectField( 'image', 'img_name', array( 'img_name' => $final ), __METHOD__ ); + $conflict = ( $test !== false ); + + if( !$conflict && ( $has_page || $version > 0 ) ) { + // If the file has a description page, don't try to move it to a + // title that already has one. But if we have a misnamed file + // with no corresponding page, and there just happens to exist a + // page with no file at the corrected title, it's probably not a + // coincidence and we shouldn't shy from reuniting them. + $conflict = Title::makeTitle( NS_FILE, $final )->exists(); + } + if( !$conflict ) { + break; + } $this->log( "Rename conflicts with '$final'..." ); $version++; $final = $this->appendTitle( $new, "_$version" ); -- 2.20.1