X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiParse.php;h=9963edad1c1c2b7f1a842ba104d2eb878bdc3027;hb=f554d1871c7daa5d3cd8f10326bd610dcc126caa;hp=88904c0c73ddd7b2b5bffd3a678dee79eacadd06;hpb=da42257e35682db692accabee6864e40a272243d;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 88904c0c73..9963edad1c 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -176,15 +176,19 @@ class ApiParse extends ApiBase { if ( !$titleObj || $titleObj->isExternal() ) { $this->dieUsageMsg( array( 'invalidtitle', $title ) ); } - if ( !$titleObj->canExist() ) { - $this->dieUsage( "Namespace doesn't allow actual pages", 'pagecannotexist' ); - } $wgTitle = $titleObj; - $pageObj = WikiPage::factory( $titleObj ); + if ( $titleObj->canExist() ) { + $pageObj = WikiPage::factory( $titleObj ); + } else { + // Do like MediaWiki::initializeArticle() + $article = Article::newFromTitle( $titleObj, $this->getContext() ); + $pageObj = $article->getPage(); + } $popts = $this->makeParserOptions( $pageObj, $params ); + $textProvided = !is_null( $text ); - if ( is_null( $text ) ) { + if ( !$textProvided ) { if ( $titleProvided && ( $prop || $params['generatexml'] ) ) { $this->setWarning( "'title' used without 'text', and parsed page properties were requested " . @@ -197,7 +201,7 @@ class ApiParse extends ApiBase { // 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 ) ) { + if ( $textProvided && !$titleProvided && is_null( $model ) ) { $model = CONTENT_MODEL_WIKITEXT; $this->setWarning( "No 'title' or 'contentmodel' was given, assuming $model." ); } @@ -249,6 +253,10 @@ class ApiParse extends ApiBase { $result_array['redirects'] = $redirValues; } + if ( $params['disabletoc'] ) { + $p_result->setTOCEnabled( false ); + } + if ( isset( $prop['text'] ) ) { $result_array['text'] = array(); ApiResult::setContent( $result_array['text'], $p_result->getText() ); @@ -691,6 +699,7 @@ class ApiParse extends ApiBase { 'generatexml' => false, 'preview' => false, 'sectionpreview' => false, + 'disabletoc' => false, 'contentformat' => array( ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(), ), @@ -702,14 +711,13 @@ class ApiParse extends ApiBase { public function getParamDescription() { $p = $this->getModulePrefix(); - $wikitext = CONTENT_MODEL_WIKITEXT; return array( 'text' => "Text to parse. Use {$p}title or {$p}contentmodel to control the content model", 'summary' => 'Summary to parse', 'redirects' => "If the {$p}page or the {$p}pageid parameter is set to a redirect, resolve it", 'title' => "Title of page the text belongs to. " . - "If omitted, \"API\" is used as the title with content model $wikitext", + "If omitted, {$p}contentmodel must be specified, and \"API\" will be used as the title", 'page' => "Parse the content of this page. Cannot be used together with {$p}text and {$p}title", 'pageid' => "Parse the content of this page. Overrides {$p}page", 'oldid' => "Parse the content of this revision. Overrides {$p}page and {$p}pageid", @@ -753,13 +761,14 @@ class ApiParse extends ApiBase { 'generatexml' => "Generate XML parse tree (requires contentmodel=$wikitext)", 'preview' => 'Parse in preview mode', 'sectionpreview' => 'Parse in section preview mode (enables preview mode too)', + 'disabletoc' => 'Disable table of contents in output', 'contentformat' => array( 'Content serialization format used for the input text', "Only valid when used with {$p}text", ), 'contentmodel' => array( - "Content model of the input text. Default is the model of the " . - "specified ${p}title, or $wikitext if ${p}title is not specified", + "Content model of the input text. If omitted, ${p}title must be specified, " . + "and default will be the model of the specified ${p}title", "Only valid when used with {$p}text", ), ); @@ -799,14 +808,13 @@ class ApiParse extends ApiBase { 'code' => 'notwikitext', 'info' => 'The requested operation is only supported on wikitext content.' ), - array( 'code' => 'pagecannotexist', 'info' => "Namespace doesn't allow actual pages" ), ) ); } public function getExamples() { return array( 'api.php?action=parse&page=Project:Sandbox' => 'Parse a page', - 'api.php?action=parse&text={{Project:Sandbox}}' => 'Parse wikitext', + 'api.php?action=parse&text={{Project:Sandbox}}&contentmodel=wikitext' => 'Parse wikitext', 'api.php?action=parse&text={{PAGENAME}}&title=Test' => 'Parse wikitext, specifying the page title', 'api.php?action=parse&summary=Some+[[link]]&prop=' => 'Parse a summary',