$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'];
$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' );
}
$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'?)"
$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 ) {
private function formatCategoryLinks( $links ) {
$result = array();
+
+ if ( !$links ) {
+ return $result;
+ }
+
+ // Fetch hiddencat property
+ $lb = new LinkBatch;
+ $lb->setArray( array( NS_CATEGORY => $links ) );
+ $db = $this->getDB();
+ $res = $db->select( array( 'page', 'page_props' ),
+ array( 'page_title', 'pp_propname' ),
+ $lb->constructSet( 'page', $db ),
+ __METHOD__,
+ array(),
+ array( 'page_props' => array(
+ 'LEFT JOIN', array( 'pp_propname' => 'hiddencat', 'pp_page = page_id' )
+ ) )
+ );
+ $hiddencats = array();
+ foreach ( $res as $row ) {
+ $hiddencats[$row->page_title] = isset( $row->pp_propname );
+ }
+
foreach ( $links as $link => $sortkey ) {
$entry = array();
$entry['sortkey'] = $sortkey;
ApiResult::setContent( $entry, $link );
+ if ( !isset( $hiddencats[$link] ) ) {
+ $entry['missing'] = '';
+ } elseif ( $hiddencats[$link] ) {
+ $entry['hidden'] = '';
+ }
$result[] = $entry;
}
+
return $result;
}
public function getAllowedParams() {
return array(
- 'title' => array(
- ApiBase::PARAM_DFLT => 'API',
- ),
+ 'title' => null,
'text' => null,
'summary' => null,
'page' => null,
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",
),
'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.",
);
}