Merge "(bug 47070) check content model namespace on import."
[lhc/web/wiklou.git] / includes / api / ApiParse.php
index 88904c0..464fde6 100644 (file)
@@ -176,11 +176,14 @@ 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 );
 
@@ -249,6 +252,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 +698,7 @@ class ApiParse extends ApiBase {
                        'generatexml' => false,
                        'preview' => false,
                        'sectionpreview' => false,
+                       'disabletoc' => false,
                        'contentformat' => array(
                                ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(),
                        ),
@@ -753,6 +761,7 @@ 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",
@@ -799,7 +808,6 @@ 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" ),
                ) );
        }