Page MenuHomePhabricator

Exception thrown in action=parse when attempting to use the title parameter without setting the text parameter
Closed, ResolvedPublic

Description

Author: jpostlethwaite

Description:
When using the API sandbox, I tried to generate, with action=parse, title=Kanichar and all props selected:

https://en.wikipedia.org/w/api.php?action=parse&format=xml&title=Kanichar&prop=text%7Clanglinks%7Clanguageshtml%7Ccategories%7Ccategorieshtml%7Clinks%7Ctemplates%7Cimages%7Cexternallinks%7Csections%7Crevid%7Cdisplaytitle%7Cheaditems%7Cheadhtml%7Ciwlinks%7Cwikitext

An exception is thrown.


Version: unspecified
Severity: minor

Details

Reference
bz33865
TitleReferenceAuthorSource BranchDest Branch
phorge: Construct fully qualified names for milestone projectstoolforge-repos/wikibugs2!8bd808work/bd808/debugging-toolsmain
Customize query in GitLab

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 12:00 AM
bzimport set Reference to bz33865.
bzimport added a subscriber: Unknown Object (MLST).

jpostlethwaite wrote:

The exception:

internal_api_error_MWException

Exception Caught: Internal error in ApiResult::setElement: Bad parameter

jpostlethwaite wrote:

The stack trace:

#0 /usr/local/apache/common-local/php-1.18/includes/api/ApiBase.php(1255): wfDebugDieBacktrace('Internal error ...')
#1 /usr/local/apache/common-local/php-1.18/includes/api/ApiResult.php(149): ApiBase::dieDebug('ApiResult::setE...', 'Bad parameter')
#2 /usr/local/apache/common-local/php-1.18/includes/api/ApiResult.php(180): ApiResult::setElement(Array, '*', NULL)
#3 /usr/local/apache/common-local/php-1.18/includes/api/ApiParse.php(282): ApiResult::setContent(Array, NULL)
#4 /usr/local/apache/common-local/php-1.18/includes/api/ApiMain.php(692): ApiParse->execute()
#5 /usr/local/apache/common-local/php-1.18/includes/api/ApiMain.php(358): ApiMain->executeAction()
#6 /usr/local/apache/common-local/php-1.18/includes/api/ApiMain.php(342): ApiMain->executeActionWithErrorHandling()
#7 /usr/local/apache/common-local/php-1.18/api.php(115): ApiMain->execute()
#8 /usr/local/apache/common-local/live-1.5/api.php(3): require('/usr/local/apac...')
#9 {main}

jpostlethwaite wrote:

Narrowed down the request:

/w/api.php?action=parse&format=xml&title=Kanichar&prop=wikitext

This still generates the exception.

Replicable on trunk (exported article and dependant pages into my dev wiki)

<?xml version="1.0"?>
<api servedby="ubuntu64-web-esxi">

<error code="internal_api_error_MWException" info="Exception Caught: Internal error in ApiResult::setElement: Bad parameter" xml:space="preserve">

#0 /home/reedy/mediawiki/trunk/phase3/includes/api/ApiBase.php(1300): wfDebugDieBacktrace('Internal error ...')
#1 /home/reedy/mediawiki/trunk/phase3/includes/api/ApiResult.php(144): ApiBase::dieDebug('ApiResult::setE...', 'Bad parameter')
#2 /home/reedy/mediawiki/trunk/phase3/includes/api/ApiResult.php(175): ApiResult::setElement(Array, '*', NULL)
#3 /home/reedy/mediawiki/trunk/phase3/includes/api/ApiParse.php(278): ApiResult::setContent(Array, NULL)
#4 /home/reedy/mediawiki/trunk/phase3/includes/api/ApiMain.php(706): ApiParse->execute()
#5 /home/reedy/mediawiki/trunk/phase3/includes/api/ApiMain.php(361): ApiMain->executeAction()
#6 /home/reedy/mediawiki/trunk/phase3/includes/api/ApiMain.php(345): ApiMain->executeActionWithErrorHandling()
#7 /home/reedy/mediawiki/trunk/phase3/api.php(117): ApiMain->execute()
#8 {main}

</error>
</api>

wikitext is indeed the bad paramter, line 278 is the $result->setContent()

		if ( isset( $prop['wikitext'] ) ) {
			$result_array['wikitext'] = array();
			$result->setContent( $result_array['wikitext'], $this->text );
			if ( !is_null( $this->pstText ) ) {
				$result_array['psttext'] = array();
				$result->setContent( $result_array['psttext'], $this->pstText );
			}
		}

Happens on many pages, $this->text is null

Actually, it was broken in the very revision prop=wikitext was introduced, r81124.

(In reply to comment #7)

Actually, it was broken in the very revision prop=wikitext was introduced,
r81124.

Trololol. I have a fix, just not sure if it's the best

Actually, you shouldn't be using Title in this case

You want page

'title' => 'Title of page the text belongs to',
'page' => "Parse the content of this page. Cannot be used together with {$p}text and {$p}title",

http://en.wikipedia.org/w/api.php?action=parse&format=xmlfm&page=Kanichar&prop=wikitext

Title is so you can "create" a page, and use that as the title against arbitary text

If you do that properly, then

http://en.wikipedia.org/w/api.php?action=parse&format=xmlfm&title=FooBarLolBaz&prop=wikitext&text=[[Boo]]

Related URL: https://gerrit.wikimedia.org/r/63138 (Gerrit Change I03c1fbcb0bd31dea8bd84e164104f7ced0ace449)