Page MenuHomePhabricator

Import.php caused a Catchable fatal error: Argument 1 passed to WikiPage::factory
Closed, ResolvedPublic

Description

MediaWiki 1.26.0
PHP 5.6.8 (apache2handler)
MySQL 5.6.24

An attempt to import [0] failed with:

Catchable fatal error: Argument 1 passed to WikiPage::factory() must be an instance of Title, null given, called in ...\mw-26-00\includes\Import.php on line 313 and defined in ...\mw-26-00\includes\page\WikiPage.php on line 105

The import of [0] did not fail for any previous release.

[0] https://gist.github.com/mwjames/2f83d3d775cbcc42b4ed

Event Timeline

mwjames raised the priority of this task from to Needs Triage.
mwjames updated the task description. (Show Details)
mwjames subscribed.

Works for me on REL_1.26 from git:

$ php maintenance/importDump.php --dry-run < mwjamesdump.xml
Done!
You might want to run rebuildrecentchanges.php to regenerate RecentChanges

Admittedly that was a dry run, but that seems unlikely to affect this bug.

I suspect there is some effect created by an extension. Can you narrow it down to a single page in the dump and/or extension causing the issue? Probably one of the Property pages and a Wikibase extension, I'd be inclined to guess.

Probably one of the Property pages and a Wikibase extension, I'd be inclined to guess.

Sorry, to me Property suggests Wikibase, but I guess it's SMW in your case.

Also which import options were you using? Paste the command line if by command line.

Turning on Xdebug reports:

3	0.9202	2743176	MediaWiki->main( )	..\MediaWiki.php:476
4	1.1621	3166096	MediaWiki->performRequest( )	..\MediaWiki.php:682
5	1.2004	3263184	SpecialPageFactory::executePath( )	..\MediaWiki.php:249
6	1.2118	3300160	SpecialPage->run( )	..\SpecialPageFactory.php:553
7	1.2119	3300328	SpecialImport->execute( )	..\SpecialPage.php:384
8	1.6635	4171472	SpecialImport->doImport( )	..\SpecialImport.php:96
9	1.7125	4300008	WikiImporter->doImport( )	..\SpecialImport.php:205
10	4.2488	4992848	WikiImporter->handlePage( )	..\Import.php:567
11	4.2560	4994896	WikiImporter->pageCallback( )	..\Import.php:737
12	4.2560	4994928	call_user_func:{...\mw-26-00\includes\Import.php:446} ( )	..\Import.php:446
13	4.2560	4994944	WikiImporter->beforeImportPage( )	..\Import.php:446
14	4.2560	4994976	WikiPage::factory( )	..\Import.php:314

userCan hook is activated and returns for one imported article a false hence $title = $titleAndForeignTitle[0]; containing a NULL instead of an actual title object and ultimately $page = WikiPage::factory( $title ); is throwing up.

But WikiImporter::processTitle has a check for null, so I'm having a hard time working out why the null is getting through, and why I want to be able to reproduce it locally. Could you answer my questions above? Which extension is causing the problem?

... why the null is getting through, and why I want to be able to reproduce it locally

If you add something like below (PS: This is to make this case reproducible in connection with the provided XML content), you should be able to encounter mentioned fatal (via Special:Import).

\Hooks::register( 'userCan', function ( &$title, &$user, $action, &$result ) {

	if ( $action === 'edit' && $title->getText() == 'Lorem ipsum' ) {
		$result = false;
		return false;
	}

	return true;
} );

Could you answer my questions above?

?

Right, thanks, I can reproduce on REL1_26. It appears to be fixed on master.

I'll investigate.

Could you answer my questions above?

?

No need to now :) Thanks for the nice testcase.

This was fixed in https://gerrit.wikimedia.org/r/#/c/236784.

Here's a patch for 1.26, it's based on 1.26.2 but should apply to all 1.26.x release so far:

I'll see if we can get it into 1.26.3.

Change 263202 had a related patch set uploaded (by TTO):
Fix exception in Import, when import of a revision fails

https://gerrit.wikimedia.org/r/263202

Change 263205 had a related patch set uploaded (by TTO):
Fix exception in Import, when import of a revision fails

https://gerrit.wikimedia.org/r/263205

Change 263202 merged by jenkins-bot:
Fix exception in Import, when import of a revision fails

https://gerrit.wikimedia.org/r/263202

TTO claimed this task.

You can apply the patch in my comment above, or wait for the next maintenance release of your favourite MW version.

Change 263205 merged by jenkins-bot:
Fix exception in Import, when import of a revision fails

https://gerrit.wikimedia.org/r/263205