From 607171cb917ee5ec7cf9f84acf979f4db97f81e6 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 11 Nov 2011 22:14:21 +0000 Subject: [PATCH] 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. --- includes/GlobalFunctions.php | 2 +- includes/filerepo/FileRepo.php | 20 ++++++++------------ includes/filerepo/RepoGroup.php | 6 +++--- includes/specials/SpecialMovepage.php | 8 +++++--- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 0913fa2391..17e13ec172 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -3258,7 +3258,7 @@ function wfFindFile( $title, $options = array() ) { * Returns a valid placeholder object if the file does not exist. * * @param $title Title or String - * @return File, or null if passed an invalid Title + * @return File|null A File, or null if passed an invalid Title */ function wfLocalFile( $title ) { return RepoGroup::singleton()->getLocalRepo()->newFile( $title ); diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index d39b8f9196..bff229625d 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -71,14 +71,12 @@ abstract class FileRepo { * current file. Repositories not supporting version control * should return false if this parameter is set. * - * @return File + * @return File|null A File, or null if passed an invalid Title */ function newFile( $title, $time = false ) { - if ( !( $title instanceof Title ) ) { - $title = Title::makeTitleSafe( NS_FILE, $title ); - if ( !is_object( $title ) ) { - return null; - } + $title = File::normalizeTitle( $title ); + if ( !$title ) { + return null; } if ( $time ) { if ( $this->oldFileFactory ) { @@ -111,13 +109,11 @@ abstract class FileRepo { * @return File|false */ function findFile( $title, $options = array() ) { - $time = isset( $options['time'] ) ? $options['time'] : false; - if ( !($title instanceof Title) ) { - $title = Title::makeTitleSafe( NS_FILE, $title ); - if ( !is_object( $title ) ) { - return false; - } + $title = File::normalizeTitle( $title ); + if ( !$title ) { + return false; } + $time = isset( $options['time'] ) ? $options['time'] : false; # First try the current version of the file to see if it precedes the timestamp $img = $this->newFile( $title ); if ( !$img ) { diff --git a/includes/filerepo/RepoGroup.php b/includes/filerepo/RepoGroup.php index 1e6538035e..a2ddadc7b1 100644 --- a/includes/filerepo/RepoGroup.php +++ b/includes/filerepo/RepoGroup.php @@ -172,10 +172,10 @@ class RepoGroup { if ( !is_array( $item ) ) { $item = array( 'title' => $item ); } - if ( !( $item['title'] instanceof Title ) ) - $item['title'] = Title::makeTitleSafe( NS_FILE, $item['title'] ); - if ( $item['title'] ) + $item['title'] = File::normalizeTitle( $item['title'] ); + if ( $item['title'] ) { $items[$item['title']->getDBkey()] = $item; + } } $images = $this->localRepo->findFiles( $items ); diff --git a/includes/specials/SpecialMovepage.php b/includes/specials/SpecialMovepage.php index 540d7bed17..f7eddcc138 100644 --- a/includes/specials/SpecialMovepage.php +++ b/includes/specials/SpecialMovepage.php @@ -376,9 +376,11 @@ class MovePageForm extends UnlistedSpecialPage { $reason = wfMessage( 'delete_and_move_reason', $ot )->inContentLanguage()->text(); // Delete an associated image if there is - $file = wfLocalFile( $nt ); - if( $file->exists() ) { - $file->delete( $reason, false ); + if ( $nt->getNamespace() == NS_FILE ) { + $file = wfLocalFile( $nt ); + if ( $file->exists() ) { + $file->delete( $reason, false ); + } } $error = ''; // passed by ref -- 2.20.1