Merge "Maintenance script to check LESS files for validity"
[lhc/web/wiklou.git] / includes / api / ApiParse.php
index ac6913e..a369994 100644 (file)
@@ -44,6 +44,14 @@ class ApiParse extends ApiBase {
                $params = $this->extractRequestParams();
                $text = $params['text'];
                $title = $params['title'];
+               if ( $title === null ) {
+                       $titleProvided = false;
+                       // A title is needed for parsing, so arbitrarily choose one
+                       $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,13 @@ 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( "No 'title' or 'contentmodel' was given, assuming $model." );
+                       }
+
                        try {
                                $this->content = ContentHandler::makeContent( $text, $titleObj, $model, $format );
                        } catch ( MWContentSerializationException $ex ) {
@@ -575,9 +590,7 @@ class ApiParse extends ApiBase {
 
        public function getAllowedParams() {
                return array(
-                       'title' => array(
-                               ApiBase::PARAM_DFLT => 'API',
-                       ),
+                       'title' => null,
                        'text' => null,
                        'summary' => null,
                        'page' => null,
@@ -631,11 +644,13 @@ class ApiParse extends ApiBase {
 
        public function getParamDescription() {
                $p = $this->getModulePrefix();
+               $wikitext = CONTENT_MODEL_WIKITEXT;
                return array(
-                       'text' => 'Wikitext to parse',
+                       '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',
+                       'title' => "Title of page the text belongs to. " .
+                               "If omitted, \"API\" is used as the title with content model $wikitext",
                        '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",
@@ -665,27 +680,40 @@ class ApiParse extends ApiBase {
                        ),
                        'pst' => array(
                                'Do a pre-save transform on the input before parsing it',
-                               'Ignored if page, pageid or oldid is used'
+                               "Only valid when used with {$p}text",
                        ),
                        'onlypst' => array(
                                'Do a pre-save transform (PST) on the input, but don\'t parse it',
-                               'Returns the same wikitext, after a PST has been applied. Ignored if page, pageid or oldid is used'
+                               'Returns the same wikitext, after a PST has been applied.',
+                               "Only valid when used with {$p}text",
                        ),
                        'uselang' => 'Which language to parse the request in',
                        'section' => 'Only retrieve the content of this section number',
                        'disablepp' => 'Disable the PP Report from the parser output',
-                       'generatexml' => 'Generate XML parse tree (requires prop=wikitext)',
+                       'generatexml' => "Generate XML parse tree (requires contentmodel=$wikitext)",
                        'preview' => 'Parse in preview mode',
                        'sectionpreview' => 'Parse in section preview mode (enables preview mode too)',
-                       'contentformat' => 'Content serialization format used for the input text',
-                       'contentmodel' => 'Content model of the new content',
+                       '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",
+                               "Only valid when used with {$p}text",
+                       ),
                );
        }
 
        public function getDescription() {
+               $p = $this->getModulePrefix();
                return array(
-                       'Parses wikitext and returns parser output',
+                       'Parses content and returns parser output',
                        'See the various prop-Modules of action=query to get information from the current version of a page',
+                       'There are several ways to specify the text to parse:',
+                       "1) Specify a page or revision, using {$p}page, {$p}pageid, or {$p}oldid.",
+                       "2) Specify content explicitly, using {$p}text, {$p}title, and {$p}contentmodel.",
+                       "3) Specify only a summary to parse. {$p}prop should be given an empty value.",
                );
        }