Pulling back r45388 "Don't needlessly shy from reuniting lost files with their descri...
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 7 Jan 2009 02:41:03 +0000 (02:41 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 7 Jan 2009 02:41:03 +0000 (02:41 +0000)
I'm staring at this code and my brain just ain't liking it. :) Can we maybe just make the logic cleaner?

maintenance/cleanupImages.php

index 0fe6244..00903f2 100644 (file)
@@ -114,23 +114,9 @@ class ImageCleanup extends TableCleanup {
                $db = wfGetDB( DB_MASTER );
                $version = 0;
                $final = $new;
-               $has_page = Title::makeTitle( NS_FILE, $orig )->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;
-                       }
+               while( $db->selectField( 'image', 'img_name', array( 'img_name' => $final ), __METHOD__ ) ||
+                       Title::makeTitle( NS_FILE, $final )->exists() ) {
                        $this->log( "Rename conflicts with '$final'..." );
                        $version++;
                        $final = $this->appendTitle( $new, "_$version" );