r55694 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55693‎ | r55694 | r55695 >
Date:13:58, 31 August 2009
Author:vyznev
Status:ok (Comments)
Tags:
Comment:
redo r45388 (hopefully) more cleanly (see also bug 16916: Unnecessary title disambiguation by cleanupImages.php)
Modified paths:
  • /trunk/phase3/maintenance/cleanupImages.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/cleanupImages.php
@@ -101,6 +101,14 @@
102102 return $this->repo->getRootDirectory() . '/' . $this->repo->getHashPath( $name ) . $name;
103103 }
104104
 105+ function imageExists( $name, $db ) {
 106+ return $db->selectField( 'image', '1', array( 'img_name' => $name ), __METHOD__ );
 107+ }
 108+
 109+ function pageExists( $name, $db ) {
 110+ return $db->selectField( 'page', '1', array( 'page_namespace' => NS_FILE, 'page_title' => $name ), __METHOD__ );
 111+ }
 112+
105113 private function pokeFile( $orig, $new ) {
106114 $path = $this->filePath( $orig );
107115 if( !file_exists( $path ) ) {
@@ -109,14 +117,24 @@
110118 }
111119
112120 $db = wfGetDB( DB_MASTER );
 121+
 122+ /*
 123+ * To prevent key collisions in the update() statements below,
 124+ * if the target title exists in the image table, or if both the
 125+ * original and target titles exist in the page table, append
 126+ * increasing version numbers until the target title exists in
 127+ * neither. (See also bug 16916.)
 128+ */
113129 $version = 0;
114130 $final = $new;
 131+ $conflict = ( $this->imageExists( $final, $db ) ||
 132+ ( $this->pageExists( $orig, $db ) && $this->pageExists( $final, $db ) ) );
115133
116 - while( $db->selectField( 'image', 'img_name', array( 'img_name' => $final ), __METHOD__ ) ||
117 - Title::makeTitle( NS_FILE, $final )->exists() ) {
 134+ while( $conflict ) {
118135 $this->output( "Rename conflicts with '$final'...\n" );
119136 $version++;
120137 $final = $this->appendTitle( $new, "_$version" );
 138+ $conflict = ( $this->imageExists( $final, $db ) || $this->pageExists( $final, $db ) );
121139 }
122140
123141 $finalPath = $this->filePath( $final );

Follow-up revisions

RevisionCommit summaryAuthorDate
r55695followup to r55694: forgot to mark the new functions privatevyznev14:01, 31 August 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r45388Don't needlessly shy from reuniting lost files with their description pages.vyznev02:36, 4 January 2009

Comments

#Comment by Happy-melon (talk | contribs)   18:46, 31 August 2009

This seems to have broken a parser test.

#Comment by Ilmari Karonen (talk | contribs)   21:56, 31 August 2009

I asked about that on IRC earlier. Apparently something is/was wrong with the system that runs the parser tests for CodeReview, causing spurious test failures to be reported. In any case, the test on question passes when I run it locally. (Indeed, it'd be quite surprised if this change could actually cause a test to fail, given that the parser tests don't cover the maintenance scripts.)

Status & tagging log