From 628e3ce69c07f278c2b5b610482b7a37658bdd18 Mon Sep 17 00:00:00 2001 From: "This, that and the other" Date: Fri, 12 Aug 2016 11:17:02 +1000 Subject: [PATCH] Fix importation of weird file names in importTextFiles.php 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 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/maintenance/importTextFiles.php b/maintenance/importTextFiles.php index 5531ffc3af..2894653eb4 100644 --- a/maintenance/importTextFiles.php +++ b/maintenance/importTextFiles.php @@ -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 ) { -- 2.20.1