From 1104392eba1b7701582054fed11d353868614d62 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Niklas=20Laxstr=C3=B6m?= Date: Wed, 19 Jun 2013 10:21:19 +0000 Subject: [PATCH] Restore API action=parse&text=foo functionality on wikidata.org Bug: 48201 Change-Id: Ie4f7324c2a10700e52dadc4facd6b4fe6c76cf48 --- includes/api/ApiParse.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index ac6913eb46..89928fe389 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -44,6 +44,14 @@ class ApiParse extends ApiBase { $params = $this->extractRequestParams(); $text = $params['text']; $title = $params['title']; + if ( $title === '' ) { + $titleProvided = false; + // This is the old default value + $title = 'API'; + } else { + $titleProvided = true; + } + $page = $params['page']; $pageid = $params['pageid']; $oldid = $params['oldid']; @@ -51,7 +59,7 @@ class ApiParse extends ApiBase { $model = $params['contentmodel']; $format = $params['contentformat']; - if ( !is_null( $page ) && ( !is_null( $text ) || $title != 'API' ) ) { + if ( !is_null( $page ) && ( !is_null( $text ) || $titleProvided ) ) { $this->dieUsage( 'The page parameter cannot be used together with the text and title parameters', 'params' ); } @@ -171,7 +179,7 @@ class ApiParse extends ApiBase { $popts = $this->makeParserOptions( $pageObj, $params ); if ( is_null( $text ) ) { - if ( $title !== 'API' && ( $prop || $params['generatexml'] ) ) { + if ( $titleProvided && ( $prop || $params['generatexml'] ) ) { $this->setWarning( "'title' used without 'text', and parsed page properties were requested " . "(did you mean to use 'page' instead of 'title'?)" @@ -181,6 +189,16 @@ class ApiParse extends ApiBase { $text = ''; } + // If we are parsing text, do not use the content model of the default + // API title, but default to wikitext to keep BC. + if ( !$titleProvided && is_null( $model ) ) { + $model = CONTENT_MODEL_WIKITEXT; + $this->setWarning( + "Please set content model with contentmodel parameter. " . + "Assuming it is $model." + ); + } + try { $this->content = ContentHandler::makeContent( $text, $titleObj, $model, $format ); } catch ( MWContentSerializationException $ex ) { @@ -576,7 +594,7 @@ class ApiParse extends ApiBase { public function getAllowedParams() { return array( 'title' => array( - ApiBase::PARAM_DFLT => 'API', + ApiBase::PARAM_DFLT => '', ), 'text' => null, 'summary' => null, -- 2.20.1