Index: trunk/phase3/maintenance/cleanupImages.php |
— | — | @@ -114,9 +114,23 @@ |
115 | 115 | $db = wfGetDB( DB_MASTER ); |
116 | 116 | $version = 0; |
117 | 117 | $final = $new; |
| 118 | + $has_page = Title::makeTitle( NS_FILE, $orig )->exists(); |
118 | 119 | |
119 | | - while( $db->selectField( 'image', 'img_name', array( 'img_name' => $final ), __METHOD__ ) || |
120 | | - Title::makeTitle( NS_FILE, $final )->exists() ) { |
| 120 | + while( true ) { |
| 121 | + $test = $db->selectField( 'image', 'img_name', array( 'img_name' => $final ), __METHOD__ ); |
| 122 | + $conflict = ( $test !== false ); |
| 123 | + |
| 124 | + if( !$conflict && ( $has_page || $version > 0 ) ) { |
| 125 | + // If the file has a description page, don't try to move it to a |
| 126 | + // title that already has one. But if we have a misnamed file |
| 127 | + // with no corresponding page, and there just happens to exist a |
| 128 | + // page with no file at the corrected title, it's probably not a |
| 129 | + // coincidence and we shouldn't shy from reuniting them. |
| 130 | + $conflict = Title::makeTitle( NS_FILE, $final )->exists(); |
| 131 | + } |
| 132 | + if( !$conflict ) { |
| 133 | + break; |
| 134 | + } |
121 | 135 | $this->log( "Rename conflicts with '$final'..." ); |
122 | 136 | $version++; |
123 | 137 | $final = $this->appendTitle( $new, "_$version" ); |