Fix importation of weird file names in importTextFiles.php
authorThis, that and the other <at.light@live.com.au>
Fri, 12 Aug 2016 01:17:02 +0000 (11:17 +1000)
committerSam Wilson <sam@samwilson.id.au>
Wed, 21 Sep 2016 04:32:22 +0000 (12:32 +0800)
When importing a file whose name contains a #, the script would call
e.g. Title::newFromText( '#foo' ), which succeeds (because titles
are allowed to contain fragments) but causes problems when trying
to create the revision.

Also avoid fatals on actual invalid titles.

Bug: T142675
Change-Id: I6b4c8fd8dd09db14c0704c74137e112b292c964a

maintenance/importTextFiles.php

index 5531ffc..2894653 100644 (file)
@@ -103,16 +103,16 @@ class ImportTextFiles extends Maintenance {
                        $timestamp = $useTimestamp ? wfTimestamp( TS_UNIX, filemtime( $file ) ) : wfTimestampNow();
 
                        $title = Title::newFromText( $pageName );
-                       $exists = $title->exists();
-                       $oldRevID = $title->getLatestRevID();
-                       $oldRev = $oldRevID ? Revision::newFromId( $oldRevID ) : null;
-
-                       if ( !$title ) {
+                       // Have to check for # manually, since it gets interpreted as a fragment
+                       if ( !$title || $title->hasFragment() ) {
                                $this->error( "Invalid title $pageName. Skipping.\n" );
                                $skipCount++;
                                continue;
                        }
 
+                       $exists = $title->exists();
+                       $oldRevID = $title->getLatestRevID();
+                       $oldRev = $oldRevID ? Revision::newFromId( $oldRevID ) : null;
                        $actualTitle = $title->getPrefixedText();
 
                        if ( $exists ) {