r102818 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102817‎ | r102818 | r102819 >
Date:22:14, 11 November 2011
Author:aaron
Status:ok
Tags:lamecommitsummary 
Comment:
FU r102073:
* (bug 32367) Fixed SpecialMovePage to not call wfLocalFile() on a non file title and expect an actual File back. Previously "worked" due to an old file title checking loophole (File objects with non File: titles).
* Use File::normalizeTitle() in some more functions that were still doing their own incomplete normalization.
* Updated FileRepo::newFile() docs to reflect that it can return null; wfLocalFile() docs already mentioned this.
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/filerepo/FileRepo.php (modified) (history)
  • /trunk/phase3/includes/filerepo/RepoGroup.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialMovepage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -3258,7 +3258,7 @@
32593259 * Returns a valid placeholder object if the file does not exist.
32603260 *
32613261 * @param $title Title or String
3262 - * @return File, or null if passed an invalid Title
 3262+ * @return File|null A File, or null if passed an invalid Title
32633263 */
32643264 function wfLocalFile( $title ) {
32653265 return RepoGroup::singleton()->getLocalRepo()->newFile( $title );
Index: trunk/phase3/includes/filerepo/FileRepo.php
@@ -71,14 +71,12 @@
7272 * current file. Repositories not supporting version control
7373 * should return false if this parameter is set.
7474 *
75 - * @return File
 75+ * @return File|null A File, or null if passed an invalid Title
7676 */
7777 function newFile( $title, $time = false ) {
78 - if ( !( $title instanceof Title ) ) {
79 - $title = Title::makeTitleSafe( NS_FILE, $title );
80 - if ( !is_object( $title ) ) {
81 - return null;
82 - }
 78+ $title = File::normalizeTitle( $title );
 79+ if ( !$title ) {
 80+ return null;
8381 }
8482 if ( $time ) {
8583 if ( $this->oldFileFactory ) {
@@ -111,13 +109,11 @@
112110 * @return File|false
113111 */
114112 function findFile( $title, $options = array() ) {
115 - $time = isset( $options['time'] ) ? $options['time'] : false;
116 - if ( !($title instanceof Title) ) {
117 - $title = Title::makeTitleSafe( NS_FILE, $title );
118 - if ( !is_object( $title ) ) {
119 - return false;
120 - }
 113+ $title = File::normalizeTitle( $title );
 114+ if ( !$title ) {
 115+ return false;
121116 }
 117+ $time = isset( $options['time'] ) ? $options['time'] : false;
122118 # First try the current version of the file to see if it precedes the timestamp
123119 $img = $this->newFile( $title );
124120 if ( !$img ) {
Index: trunk/phase3/includes/filerepo/RepoGroup.php
@@ -172,10 +172,10 @@
173173 if ( !is_array( $item ) ) {
174174 $item = array( 'title' => $item );
175175 }
176 - if ( !( $item['title'] instanceof Title ) )
177 - $item['title'] = Title::makeTitleSafe( NS_FILE, $item['title'] );
178 - if ( $item['title'] )
 176+ $item['title'] = File::normalizeTitle( $item['title'] );
 177+ if ( $item['title'] ) {
179178 $items[$item['title']->getDBkey()] = $item;
 179+ }
180180 }
181181
182182 $images = $this->localRepo->findFiles( $items );
Index: trunk/phase3/includes/specials/SpecialMovepage.php
@@ -376,9 +376,11 @@
377377 $reason = wfMessage( 'delete_and_move_reason', $ot )->inContentLanguage()->text();
378378
379379 // Delete an associated image if there is
380 - $file = wfLocalFile( $nt );
381 - if( $file->exists() ) {
382 - $file->delete( $reason, false );
 380+ if ( $nt->getNamespace() == NS_FILE ) {
 381+ $file = wfLocalFile( $nt );
 382+ if ( $file->exists() ) {
 383+ $file->delete( $reason, false );
 384+ }
383385 }
384386
385387 $error = ''; // passed by ref

Sign-offs

UserFlagDate
Bryaninspected09:41, 12 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r102073* Added File::normalizeTitle() function and used it to consolidate file title...aaron23:49, 4 November 2011

Status & tagging log