Page MenuHomePhabricator

Missing argument 5 for WikiImporter::finishImportPage() during xml dump import via API
Closed, ResolvedPublic

Description

Author: cnit

Description:
I develop an extension which uses API to export XML dump to remote wiki. In r75001 I get the following warning:

[Tue Oct 19 10:12:41 2010] [error] [client 10.1.1.119] PHP Warning: Missing argument 5 for WikiImporter::finishImportPage() in /var/www/wiki/phase3/includes/ImportXMLReader.php on line 182
[Tue Oct 19 10:12:41 2010] [error] [client 10.1.1.119] PHP Stack trace:
[Tue Oct 19 10:12:41 2010] [error] [client 10.1.1.119] PHP 1. {main}() /var/www/wiki/phase3/api.php:0
[Tue Oct 19 10:12:41 2010] [error] [client 10.1.1.119] PHP 2. ApiMain->execute() /var/www/wiki/phase3/api.php:116
[Tue Oct 19 10:12:41 2010] [error] [client 10.1.1.119] PHP 3. ApiMain->executeActionWithErrorHandling() /var/www/wiki/phase3/includes/api/ApiMain.php:322
[Tue Oct 19 10:12:41 2010] [error] [client 10.1.1.119] PHP 4. ApiMain->executeAction() /var/www/wiki/phase3/includes/api/ApiMain.php:338
[Tue Oct 19 10:12:41 2010] [error] [client 10.1.1.119] PHP 5. ApiImport->execute() /var/www/wiki/phase3/includes/api/ApiMain.php:656
[Tue Oct 19 10:12:41 2010] [error] [client 10.1.1.119] PHP 6. WikiImporter->doImport() /var/www/wiki/phase3/includes/api/ApiImport.php:88
[Tue Oct 19 10:12:41 2010] [error] [client 10.1.1.119] PHP 7. WikiImporter->handlePage() /var/www/wiki/phase3/includes/ImportXMLReader.php:333
[Tue Oct 19 10:12:41 2010] [error] [client 10.1.1.119] PHP 8. WikiImporter->pageOutCallback() /var/www/wiki/phase3/includes/ImportXMLReader.php:470
[Tue Oct 19 10:12:41 2010] [error] [client 10.1.1.119] PHP 9. call_user_func_array() /var/www/wiki/phase3/includes/ImportXMLReader.php:225
[Tue Oct 19 10:12:41 2010] [error] [client 10.1.1.119] PHP 10. ApiImportReporter->reportPage() /var/www/wiki/phase3/includes/ImportXMLReader.php:0
[Tue Oct 19 10:12:41 2010] [error] [client 10.1.1.119] PHP 11. ImportReporter->reportPage() /var/www/wiki/phase3/includes/api/ApiImport.php:192
[Tue Oct 19 10:12:41 2010] [error] [client 10.1.1.119] PHP 12. call_user_func_array() /var/www/wiki/phase3/includes/specials/SpecialImport.php:314
[Tue Oct 19 10:12:41 2010] [error] [client 10.1.1.119] PHP 13. WikiImporter->finishImportPage() /var/www/wiki/phase3/includes/specials/SpecialImport.php:0

I've incloded the xdebug stack trace, maybe it will help to easier spot the problem.

Also I get the following warning:
[Tue Oct 19 10:07:49 2010] [error] [client 10.1.1.119] PHP Warning: filemtime(): stat failed for /var/www/wiki/phase3/Array in /var/www/wiki/phase3/includes/ResourceLoaderModule.php on line 565, referer: http://phase3.wiki2.uniyar.ac.ru/index.php/%D0%9F%D1%80%D0%B0%D0%BA%D1%82%D0%B8%D1%87%D0%B5%D1%81%D0%BA%D0%B0%D1%8F_%D0%BF%D1%81%D0%B8%D1%85%D0%BE%D0%BB%D0%BE%D0%B3%D0%B8%D1%8F
[Tue Oct 19 10:07:49 2010] [error] [client 10.1.1.119] PHP Stack trace:, referer: http://phase3.wiki2.uniyar.ac.ru/index.php/%D0%9F%D1%80%D0%B0%D0%BA%D1%82%D0%B8%D1%87%D0%B5%D1%81%D0%BA%D0%B0%D1%8F_%D0%BF%D1%81%D0%B8%D1%85%D0%BE%D0%BB%D0%BE%D0%B3%D0%B8%D1%8F
[Tue Oct 19 10:07:49 2010] [error] [client 10.1.1.119] PHP 1. {main}() /var/www/wiki/phase3/load.php:0, referer: http://phase3.wiki2.uniyar.ac.ru/index.php/%D0%9F%D1%80%D0%B0%D0%BA%D1%82%D0%B8%D1%87%D0%B5%D1%81%D0%BA%D0%B0%D1%8F_%D0%BF%D1%81%D0%B8%D1%85%D0%BE%D0%BB%D0%BE%D0%B3%D0%B8%D1%8F
[Tue Oct 19 10:07:49 2010] [error] [client 10.1.1.119] PHP 2. ResourceLoader->respond() /var/www/wiki/phase3/load.php:49, referer: http://phase3.wiki2.uniyar.ac.ru/index.php/%D0%9F%D1%80%D0%B0%D0%BA%D1%82%D0%B8%D1%87%D0%B5%D1%81%D0%BA%D0%B0%D1%8F_%D0%BF%D1%81%D0%B8%D1%85%D0%BE%D0%BB%D0%BE%D0%B3%D0%B8%D1%8F
[Tue Oct 19 10:07:49 2010] [error] [client 10.1.1.119] PHP 3. ResourceLoaderFileModule->getModifiedTime() /var/www/wiki/phase3/includes/ResourceLoader.php:285, referer: http://phase3.wiki2.uniyar.ac.ru/index.php/%D0%9F%D1%80%D0%B0%D0%BA%D1%82%D0%B8%D1%87%D0%B5%D1%81%D0%BA%D0%B0%D1%8F_%D0%BF%D1%81%D0%B8%D1%85%D0%BE%D0%BB%D0%BE%D0%B3%D0%B8%D1%8F
[Tue Oct 19 10:07:49 2010] [error] [client 10.1.1.119] PHP 4. array_map() /var/www/wiki/phase3/includes/ResourceLoaderModule.php:565, referer: http://phase3.wiki2.uniyar.ac.ru/index.php/%D0%9F%D1%80%D0%B0%D0%BA%D1%82%D0%B8%D1%87%D0%B5%D1%81%D0%BA%D0%B0%D1%8F_%D0%BF%D1%81%D0%B8%D1%85%D0%BE%D0%BB%D0%BE%D0%B3%D0%B8%D1%8F

The first one is a hook, I guess that it's being called with not enough of arguments (probably).


Version: 1.17.x
Severity: minor

Details

Reference
bz25580

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:22 PM
bzimport set Reference to bz25580.

cnit wrote:

Oops.. Could you remote the http links to my testing wiki (phase3), please? I've posted in haste and forgot to conceal them.

I don't think we can easily.

As for the above, the second half is a Resource loader issue

Which hook are you calling?

cnit wrote:

I am not calling any hook remotely. I use that 1.17 wiki remotely via API action=import&xml&token:

static function importXML( $dstImportToken, $xmldata ) {

		if ( self::$directionToLocal ) {
			$json_result = new WikiSyncJSONresult( false );

// TODO: unfinished..

			return $json_result->getResult();
		} else {
			$APIparams = array(
				'action' => 'import',
				'format' => 'json',
				'token' => $dstImportToken,
			);
			list( $fname, $fp ) = self::tempnam_sfx( '', '.xml' );
			fwrite( $fp, $xmldata, strlen( $xmldata ) );
			fclose( $fp );
			$APIfiles = array(
				'xml'=>$fname
			);
			$jr = self::remoteAPIget( self::$remoteContextJSON, $APIparams, $APIfiles, false, true );
			return $jr;
		}

}

static function remoteAPIget() {

  1. get params
		$args = func_get_args();
		// by default will encode JSON result to string
		$encodeResult = count( $args ) < 4 || $args[3] !== false;
		// by default will NOT use 'multipart/form-data' encoding
		$useMultipart = count( $args ) > 4 && $args[4] === true;
		$json_result = new WikiSyncJSONresult( $encodeResult );
		if ( !WikiSyncSetup::initUser() ) {
			# not enough priviledges to run this method
			return $json_result->getResult( 'noaccess' );
		}
		# snoopy api_params are associative array
		$api_params = is_array( $args[1] ) ? $args[1] : json_decode( $args[1], true );
		$api_files = count( $args ) > 2 ? $args[2] : '';
		$snoopy = new WikiSnoopy();
		$snoopy->setContext( $args[0] );
		if ( $useMultipart ) {
			$snoopy->set_submit_multipart();
			$snoopy->httpmethod = "POST";
		} else {
			$snoopy->set_submit_normal();
			$snoopy->httpmethod = "GET";
		}
		$snoopy->submitToApi( $api_params, $api_files );
		# transport level error ?
		if ( $snoopy->error != '' ) {
			return $json_result->getResult( 'http', $snoopy->error );
		}
		$response = json_decode( $snoopy->results, true );
		# proxy returned html instead of json ?
		if ( $response === null ) {
			return $json_result->getResult( 'http' );
		}
		$json_result->append( $response ); // no HTTP error & valid AJAX
		if ( isset( $response['error'] ) ) {
			return $json_result->getResult( $response['error']['code'], $response['error']['info'] ); // API reported error
		}
		$json_result->setStatus( '1' ); // API success
		return $json_result->getResult();

}

XML seems to be remotely imported fine, but with warnings in error_log file.

Andrew, could this be related to your import rewrite?

cnit wrote:

Roan, after a brief observation, the first bug seems to be very simple:

includes/specials/SpecialImport.php

function reportPage( $title, $origTitle, $revisionCount, $successCount ) {

		global $wgOut, $wgUser, $wgLang, $wgContLang;
		
		$args = func_get_args();
		call_user_func_array( $this->mOriginalPageOutCallback, $args );

There is a call_user_func_array with $args, where $args is a four reportPage arguments, while the callback has been modified to include 5th parameter:

includes/ImportXMLReader.php

/**

  • Mostly for hook use
	 */

public function finishImportPage( $title, $origTitle, $revCount, $sRevCount, $pageInfo ) {

		$args = func_get_args();
		return wfRunHooks( 'AfterImportPage', $args );

}

which expects five parameters. Thus, the warning is produced. Either, the 5th parameter should be added to SpecialImport's reportPage; or the default value for finishImportPage should be provided.

cnit wrote:

Roan, it seems that ResourceLoader bug is quite simple, too. My 1.17 testing site uses Monobook skin, not Vector. and in
ResourceLoaderFileModule::getModifiedTime() there is a following line:

		$filesMtime = max( array_map( 'filemtime', array_map( array( __CLASS__, 'remapFilename' ), $files ) ) );

which produced a warning with bad consequences, because $files[] elements might be Array, not just strings:

$files=array(1) {

[0]=>
string(23) "skins/vector/screen.css"

}

$files=array(1) {

[0]=>
string(28) "skins/common/commonPrint.css"

}

$files=array(1) {

[0]=>
string(23) "skins/common/shared.css"

}

$files=array(2) {

[0]=>
string(23) "skins/monobook/main.css"
[1]=>
array(1) {
  ["media"]=>
  string(8) "handheld"
}

}

note that in last case resourceloadermodule $files[1] is array which indicates media type of stylesheet. One should not do direct array_map() on such arrays to expect valid string result. "Array" string is produced and of course it is not a valid file name so one could not filemtime() it.

(In reply to comment #6)

$files=array(2) {

[0]=>
string(23) "skins/monobook/main.css"
[1]=>
array(1) {
  ["media"]=>
  string(8) "handheld"
}

}

This one should no longer be there as of r75006.

cnit wrote:

Yes, ResourceLoader issue has disappeared. However, SpecialImport issue is still here:
[09-Nov-2010 20:43:13] PHP Warning: Missing argument 5 for WikiImporter::finishImportPage() in C:\www\phase3\includes\ImportXMLReader.php on line 182

[09-Nov-2010 20:43:13] PHP Warning: Missing argument 5 for WikiImporter::finishImportPage() in C:\www\phase3\includes\ImportXMLReader.php on line 182

[09-Nov-2010 20:43:13] PHP Warning: Missing argument 5 for WikiImporter::finishImportPage() in C:\www\phase3\includes\ImportXMLReader.php on line 182

[09-Nov-2010 20:43:14] PHP Warning: Missing argument 5 for WikiImporter::finishImportPage() in C:\www\phase3\includes\ImportXMLReader.php on line 182

[09-Nov-2010 20:43:15] PHP Warning: Missing argument 5 for WikiImporter::finishImportPage() in C:\www\phase3\includes\ImportXMLReader.php on line 182

[09-Nov-2010 20:43:15] PHP Warning: Missing argument 5 for WikiImporter::finishImportPage() in C:\www\phase3\includes\ImportXMLReader.php on line 182

Besides ImportReporter, also ApiImportReporter uses only four parameters while WikiImporter::finishImportPage() expects five parameters and not providing the default value for 5th parameter.

Sounds like this bug is very easy to fix. The question is, what is better - to provide the default value of 5th parameter in WikiImporter::finishImportPage(), or to modify calls to provide proper value of $pageInfo in ImportReporter and ApiImportReporter.

Should be fixed by r76420.

If not, let me know and I'll investigate in depth.

Thanks for the bug report!