FU r102073:
authorAaron Schulz <aaron@users.mediawiki.org>
Fri, 11 Nov 2011 22:14:21 +0000 (22:14 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Fri, 11 Nov 2011 22:14:21 +0000 (22:14 +0000)
* (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
includes/filerepo/FileRepo.php
includes/filerepo/RepoGroup.php
includes/specials/SpecialMovepage.php

index 0913fa2..17e13ec 100644 (file)
@@ -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 );
index d39b8f9..bff2296 100644 (file)
@@ -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 ) {
index 1e65380..a2ddadc 100644 (file)
@@ -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 );
index 540d7be..f7eddcc 100644 (file)
@@ -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