Page MenuHomePhabricator

API import of pages with invalid characters in this wiki leads to Fatal Error
Closed, ResolvedPublic


When using the API to import pages and one of the pages has invalid characters in the page title, this will result in an Fatal Error, the API also won't return the result properly then.

Fatal error: Call to a member function getNamespace() on a non-object in '...\includes\api\ApiQueryBase.php' on line 297

Here the call stack trace:

# Time Memory Function Location
1 0.0006 366264 {main}( ) ..\api.php:0
2 0.2134 15054240 ApiMain->execute( ) ..\api.php:104
3 0.2134 15054272 ApiMain->executeActionWithErrorHandling( ) ..\ApiMain.php:323
4 0.2134 15095600 ApiMain->executeAction( ) ..\ApiMain.php:339
5 0.2515 16244760 ApiImport->execute( ) ..\ApiMain.php:657
6 0.2562 16731304 WikiImporter->doImport( ) ..\ApiImport.php:84
7 0.2564 16731448 WikiImporter->handlePage( ) ..\Import.php:370
8 0.2687 17866176 WikiImporter->pageOutCallback( ) ..\Import.php:507
9 0.2687 17867064 call_user_func_array ( ) ..\Import.php:246
10 0.2687 17867456 ApiImportReporter->reportPage( ) ..\Import.php:246
11 0.2700 18041056 ApiQueryBase::addTitleInfo( ) ..\ApiImport.php:177

I would say, this is due to the fact that the Title object was not created, contained null and was given to the next function anyway.

The special page import doesn't have this error, there, the title is validated properly.
I guess the problem lays within WikiImporter::handlePage() and/or WikiImporter::processTitle()
In another run I also got the notices:

Undefined variable: origTitle in WikiImporter::handlePage()
Undefined index: _title in WikiImporter::handlePage()

Version: 1.17.x
Severity: normal



Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:50 PM
bzimport added a project: MediaWiki-API.
bzimport set Reference to bz30975.
bzimport added a subscriber: Unknown Object (MLST).

Can you link to what query you were actually requesting?

Query contains post data, url:

POST data:
token: normal edit token
xml: '@importtest.xml'
summary: 'summary'

The XML file can be seen here:

It works if you remove the '|' from the 'title' tag.

Created attachment 9082
Import test data

Attaching import test to the bug in case the server disappears.


ImportReporter::reportPage has

if ( $title === null ) {

  1. Invalid or non-importable title; a notice is already displayed return;


The api extends ImportReporter with ApiImportReporter, but does not respect a null in $title in reportPage . The api is calling ApiQueryBase::addTitleInfo and that gives the reported fatal error.

When $title is null you have to set a info in the api result (something like invalid="" and the original title) and than returning.

a patch submitted with gerrit 6095