3 * Created on Dec 01, 2007
5 * Copyright © 2007 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
25 use MediaWiki\MediaWikiServices
;
30 class ApiParse
extends ApiBase
{
32 /** @var string $section */
33 private $section = null;
35 /** @var Content $content */
36 private $content = null;
38 /** @var Content $pstContent */
39 private $pstContent = null;
42 private $contentIsDeleted = false, $contentIsSuppressed = false;
44 public function execute() {
45 // The data is hot but user-dependent, like page views, so we set vary cookies
46 $this->getMain()->setCacheMode( 'anon-public-user-private' );
49 $params = $this->extractRequestParams();
51 // No easy way to say that text and title or revid are allowed together
52 // while the rest aren't, so just do it in three calls.
53 $this->requireMaxOneParameter( $params, 'page', 'pageid', 'oldid', 'text' );
54 $this->requireMaxOneParameter( $params, 'page', 'pageid', 'oldid', 'title' );
55 $this->requireMaxOneParameter( $params, 'page', 'pageid', 'oldid', 'revid' );
57 $text = $params['text'];
58 $title = $params['title'];
59 if ( $title === null ) {
60 $titleProvided = false;
61 // A title is needed for parsing, so arbitrarily choose one
64 $titleProvided = true;
67 $page = $params['page'];
68 $pageid = $params['pageid'];
69 $oldid = $params['oldid'];
71 $model = $params['contentmodel'];
72 $format = $params['contentformat'];
74 $prop = array_flip( $params['prop'] );
76 if ( isset( $params['section'] ) ) {
77 $this->section
= $params['section'];
78 if ( !preg_match( '/^((T-)?\d+|new)$/', $this->section
) ) {
79 $this->dieWithError( 'apierror-invalidsection' );
82 $this->section
= false;
85 // The parser needs $wgTitle to be set, apparently the
86 // $title parameter in Parser::parse isn't enough *sigh*
87 // TODO: Does this still need $wgTitle?
88 global $wgParser, $wgTitle;
92 $needContent = isset( $prop['wikitext'] ) ||
93 isset( $prop['parsetree'] ) ||
$params['generatexml'];
96 $result = $this->getResult();
98 if ( !is_null( $oldid ) ||
!is_null( $pageid ) ||
!is_null( $page ) ) {
99 if ( $this->section
=== 'new' ) {
100 $this->dieWithError( 'apierror-invalidparammix-parse-new-section', 'invalidparammix' );
102 if ( !is_null( $oldid ) ) {
103 // Don't use the parser cache
104 $rev = Revision
::newFromId( $oldid );
106 $this->dieWithError( [ 'apierror-nosuchrevid', $oldid ] );
109 $this->checkTitleUserPermissions( $rev->getTitle(), 'read' );
110 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $this->getUser() ) ) {
112 [ 'apierror-permissiondenied', $this->msg( 'action-deletedtext' ) ]
116 $titleObj = $rev->getTitle();
117 $wgTitle = $titleObj;
118 $pageObj = WikiPage
::factory( $titleObj );
119 list( $popts, $reset, $suppressCache ) = $this->makeParserOptions( $pageObj, $params );
120 $p_result = $this->getParsedContent(
121 $pageObj, $popts, $suppressCache, $pageid, $rev, $needContent
123 } else { // Not $oldid, but $pageid or $page
124 if ( $params['redirects'] ) {
128 if ( !is_null( $pageid ) ) {
129 $reqParams['pageids'] = $pageid;
131 $reqParams['titles'] = $page;
133 $req = new FauxRequest( $reqParams );
134 $main = new ApiMain( $req );
135 $pageSet = new ApiPageSet( $main );
137 $redirValues = $pageSet->getRedirectTitlesAsResult( $this->getResult() );
140 foreach ( $pageSet->getRedirectTitles() as $title ) {
141 $to = $title->getFullText();
143 $pageParams = [ 'title' => $to ];
144 } elseif ( !is_null( $pageid ) ) {
145 $pageParams = [ 'pageid' => $pageid ];
147 $pageParams = [ 'title' => $page ];
150 $pageObj = $this->getTitleOrPageId( $pageParams, 'fromdb' );
151 $titleObj = $pageObj->getTitle();
152 if ( !$titleObj ||
!$titleObj->exists() ) {
153 $this->dieWithError( 'apierror-missingtitle' );
156 $this->checkTitleUserPermissions( $titleObj, 'read' );
157 $wgTitle = $titleObj;
159 if ( isset( $prop['revid'] ) ) {
160 $oldid = $pageObj->getLatest();
163 list( $popts, $reset, $suppressCache ) = $this->makeParserOptions( $pageObj, $params );
164 $p_result = $this->getParsedContent(
165 $pageObj, $popts, $suppressCache, $pageid, null, $needContent
168 } else { // Not $oldid, $pageid, $page. Hence based on $text
169 $titleObj = Title
::newFromText( $title );
170 if ( !$titleObj ||
$titleObj->isExternal() ) {
171 $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $title ) ] );
173 $revid = $params['revid'];
174 if ( $revid !== null ) {
175 $rev = Revision
::newFromId( $revid );
177 $this->dieWithError( [ 'apierror-nosuchrevid', $revid ] );
179 $pTitleObj = $titleObj;
180 $titleObj = $rev->getTitle();
181 if ( $titleProvided ) {
182 if ( !$titleObj->equals( $pTitleObj ) ) {
183 $this->addWarning( [ 'apierror-revwrongpage', $rev->getId(),
184 wfEscapeWikiText( $pTitleObj->getPrefixedText() ) ] );
187 // Consider the title derived from the revid as having
189 $titleProvided = true;
192 $wgTitle = $titleObj;
193 if ( $titleObj->canExist() ) {
194 $pageObj = WikiPage
::factory( $titleObj );
196 // Do like MediaWiki::initializeArticle()
197 $article = Article
::newFromTitle( $titleObj, $this->getContext() );
198 $pageObj = $article->getPage();
201 list( $popts, $reset ) = $this->makeParserOptions( $pageObj, $params );
202 $textProvided = !is_null( $text );
204 if ( !$textProvided ) {
205 if ( $titleProvided && ( $prop ||
$params['generatexml'] ) ) {
206 if ( $revid !== null ) {
207 $this->addWarning( 'apiwarn-parse-revidwithouttext' );
209 $this->addWarning( 'apiwarn-parse-titlewithouttext' );
212 // Prevent warning from ContentHandler::makeContent()
216 // If we are parsing text, do not use the content model of the default
217 // API title, but default to wikitext to keep BC.
218 if ( $textProvided && !$titleProvided && is_null( $model ) ) {
219 $model = CONTENT_MODEL_WIKITEXT
;
220 $this->addWarning( [ 'apiwarn-parse-nocontentmodel', $model ] );
224 $this->content
= ContentHandler
::makeContent( $text, $titleObj, $model, $format );
225 } catch ( MWContentSerializationException
$ex ) {
226 $this->dieWithException( $ex, [
227 'wrap' => ApiMessage
::create( 'apierror-contentserializationexception', 'parseerror' )
231 if ( $this->section
!== false ) {
232 if ( $this->section
=== 'new' ) {
233 // Insert the section title above the content.
234 if ( !is_null( $params['sectiontitle'] ) && $params['sectiontitle'] !== '' ) {
235 $this->content
= $this->content
->addSectionHeader( $params['sectiontitle'] );
238 $this->content
= $this->getSectionContent( $this->content
, $titleObj->getPrefixedText() );
242 if ( $params['pst'] ||
$params['onlypst'] ) {
243 $this->pstContent
= $this->content
->preSaveTransform( $titleObj, $this->getUser(), $popts );
245 if ( $params['onlypst'] ) {
246 // Build a result and bail out
248 if ( $this->contentIsDeleted
) {
249 $result_array['textdeleted'] = true;
251 if ( $this->contentIsSuppressed
) {
252 $result_array['textsuppressed'] = true;
254 $result_array['text'] = $this->pstContent
->serialize( $format );
255 $result_array[ApiResult
::META_BC_SUBELEMENTS
][] = 'text';
256 if ( isset( $prop['wikitext'] ) ) {
257 $result_array['wikitext'] = $this->content
->serialize( $format );
258 $result_array[ApiResult
::META_BC_SUBELEMENTS
][] = 'wikitext';
260 if ( !is_null( $params['summary'] ) ||
261 ( !is_null( $params['sectiontitle'] ) && $this->section
=== 'new' )
263 $result_array['parsedsummary'] = $this->formatSummary( $titleObj, $params );
264 $result_array[ApiResult
::META_BC_SUBELEMENTS
][] = 'parsedsummary';
267 $result->addValue( null, $this->getModuleName(), $result_array );
272 // Not cached (save or load)
273 if ( $params['pst'] ) {
274 $p_result = $this->pstContent
->getParserOutput( $titleObj, $revid, $popts );
276 $p_result = $this->content
->getParserOutput( $titleObj, $revid, $popts );
282 $result_array['title'] = $titleObj->getPrefixedText();
283 $result_array['pageid'] = $pageid ?
: $pageObj->getId();
284 if ( $this->contentIsDeleted
) {
285 $result_array['textdeleted'] = true;
287 if ( $this->contentIsSuppressed
) {
288 $result_array['textsuppressed'] = true;
291 if ( isset( $params['useskin'] ) ) {
292 $factory = MediaWikiServices
::getInstance()->getSkinFactory();
293 $skin = $factory->makeSkin( Skin
::normalizeKey( $params['useskin'] ) );
299 if ( $skin ||
isset( $prop['headhtml'] ) ||
isset( $prop['categorieshtml'] ) ) {
300 // Enabling the skin via 'useskin', 'headhtml', or 'categorieshtml'
301 // gets OutputPage and Skin involved, which (among others) applies
303 // - ParserOutputHooks
304 // - Hook: LanguageLinks
305 // - Hook: OutputPageParserOutput
306 // - Hook: OutputPageMakeCategoryLinks
307 $context = new DerivativeContext( $this->getContext() );
308 $context->setTitle( $titleObj );
309 $context->setWikiPage( $pageObj );
312 // Use the skin specified by 'useskin'
313 $context->setSkin( $skin );
314 // Context clones the skin, refetch to stay in sync. (T166022)
315 $skin = $context->getSkin();
317 // Make sure the context's skin refers to the context. Without this,
318 // $outputPage->getSkin()->getOutput() !== $outputPage which
319 // confuses some of the output.
320 $context->setSkin( $context->getSkin() );
323 $outputPage = new OutputPage( $context );
324 $outputPage->addParserOutputMetadata( $p_result );
325 $context->setOutput( $outputPage );
328 // Based on OutputPage::headElement()
329 $skin->setupSkinUserCss( $outputPage );
330 // Based on OutputPage::output()
331 foreach ( $skin->getDefaultModules() as $group ) {
332 $outputPage->addModules( $group );
337 if ( !is_null( $oldid ) ) {
338 $result_array['revid'] = intval( $oldid );
341 if ( $params['redirects'] && !is_null( $redirValues ) ) {
342 $result_array['redirects'] = $redirValues;
345 if ( isset( $prop['text'] ) ) {
346 $result_array['text'] = $p_result->getText( [
347 'allowTOC' => !$params['disabletoc'],
348 'enableSectionEditLinks' => !$params['disableeditsection'],
350 $result_array[ApiResult
::META_BC_SUBELEMENTS
][] = 'text';
353 if ( !is_null( $params['summary'] ) ||
354 ( !is_null( $params['sectiontitle'] ) && $this->section
=== 'new' )
356 $result_array['parsedsummary'] = $this->formatSummary( $titleObj, $params );
357 $result_array[ApiResult
::META_BC_SUBELEMENTS
][] = 'parsedsummary';
360 if ( isset( $prop['langlinks'] ) ) {
362 $langlinks = $outputPage->getLanguageLinks();
364 $langlinks = $p_result->getLanguageLinks();
365 // The deprecated 'effectivelanglinks' option depredates OutputPage
366 // support via 'useskin'. If not already applied, then run just this
367 // one hook of OutputPage::addParserOutputMetadata here.
368 if ( $params['effectivelanglinks'] ) {
370 Hooks
::run( 'LanguageLinks', [ $titleObj, &$langlinks, &$linkFlags ] );
374 $result_array['langlinks'] = $this->formatLangLinks( $langlinks );
376 if ( isset( $prop['categories'] ) ) {
377 $result_array['categories'] = $this->formatCategoryLinks( $p_result->getCategories() );
379 if ( isset( $prop['categorieshtml'] ) ) {
380 $result_array['categorieshtml'] = $outputPage->getSkin()->getCategories();
381 $result_array[ApiResult
::META_BC_SUBELEMENTS
][] = 'categorieshtml';
383 if ( isset( $prop['links'] ) ) {
384 $result_array['links'] = $this->formatLinks( $p_result->getLinks() );
386 if ( isset( $prop['templates'] ) ) {
387 $result_array['templates'] = $this->formatLinks( $p_result->getTemplates() );
389 if ( isset( $prop['images'] ) ) {
390 $result_array['images'] = array_keys( $p_result->getImages() );
392 if ( isset( $prop['externallinks'] ) ) {
393 $result_array['externallinks'] = array_keys( $p_result->getExternalLinks() );
395 if ( isset( $prop['sections'] ) ) {
396 $result_array['sections'] = $p_result->getSections();
398 if ( isset( $prop['parsewarnings'] ) ) {
399 $result_array['parsewarnings'] = $p_result->getWarnings();
402 if ( isset( $prop['displaytitle'] ) ) {
403 $result_array['displaytitle'] = $p_result->getDisplayTitle() ?
:
404 $titleObj->getPrefixedText();
407 if ( isset( $prop['headitems'] ) ) {
409 $result_array['headitems'] = $this->formatHeadItems( $outputPage->getHeadItemsArray() );
411 $result_array['headitems'] = $this->formatHeadItems( $p_result->getHeadItems() );
415 if ( isset( $prop['headhtml'] ) ) {
416 $result_array['headhtml'] = $outputPage->headElement( $context->getSkin() );
417 $result_array[ApiResult
::META_BC_SUBELEMENTS
][] = 'headhtml';
420 if ( isset( $prop['modules'] ) ) {
422 $result_array['modules'] = $outputPage->getModules();
423 $result_array['modulescripts'] = $outputPage->getModuleScripts();
424 $result_array['modulestyles'] = $outputPage->getModuleStyles();
426 $result_array['modules'] = array_values( array_unique( $p_result->getModules() ) );
427 $result_array['modulescripts'] = array_values( array_unique( $p_result->getModuleScripts() ) );
428 $result_array['modulestyles'] = array_values( array_unique( $p_result->getModuleStyles() ) );
432 if ( isset( $prop['jsconfigvars'] ) ) {
433 $jsconfigvars = $skin ?
$outputPage->getJsConfigVars() : $p_result->getJsConfigVars();
434 $result_array['jsconfigvars'] = ApiResult
::addMetadataToResultVars( $jsconfigvars );
437 if ( isset( $prop['encodedjsconfigvars'] ) ) {
438 $jsconfigvars = $skin ?
$outputPage->getJsConfigVars() : $p_result->getJsConfigVars();
439 $result_array['encodedjsconfigvars'] = FormatJson
::encode(
444 $result_array[ApiResult
::META_SUBELEMENTS
][] = 'encodedjsconfigvars';
447 if ( isset( $prop['modules'] ) &&
448 !isset( $prop['jsconfigvars'] ) && !isset( $prop['encodedjsconfigvars'] ) ) {
449 $this->addWarning( 'apiwarn-moduleswithoutvars' );
452 if ( isset( $prop['indicators'] ) ) {
454 $result_array['indicators'] = (array)$outputPage->getIndicators();
456 $result_array['indicators'] = (array)$p_result->getIndicators();
458 ApiResult
::setArrayType( $result_array['indicators'], 'BCkvp', 'name' );
461 if ( isset( $prop['iwlinks'] ) ) {
462 $result_array['iwlinks'] = $this->formatIWLinks( $p_result->getInterwikiLinks() );
465 if ( isset( $prop['wikitext'] ) ) {
466 $result_array['wikitext'] = $this->content
->serialize( $format );
467 $result_array[ApiResult
::META_BC_SUBELEMENTS
][] = 'wikitext';
468 if ( !is_null( $this->pstContent
) ) {
469 $result_array['psttext'] = $this->pstContent
->serialize( $format );
470 $result_array[ApiResult
::META_BC_SUBELEMENTS
][] = 'psttext';
473 if ( isset( $prop['properties'] ) ) {
474 $result_array['properties'] = (array)$p_result->getProperties();
475 ApiResult
::setArrayType( $result_array['properties'], 'BCkvp', 'name' );
478 if ( isset( $prop['limitreportdata'] ) ) {
479 $result_array['limitreportdata'] =
480 $this->formatLimitReportData( $p_result->getLimitReportData() );
482 if ( isset( $prop['limitreporthtml'] ) ) {
483 $result_array['limitreporthtml'] = EditPage
::getPreviewLimitReport( $p_result );
484 $result_array[ApiResult
::META_BC_SUBELEMENTS
][] = 'limitreporthtml';
487 if ( isset( $prop['parsetree'] ) ||
$params['generatexml'] ) {
488 if ( $this->content
->getModel() != CONTENT_MODEL_WIKITEXT
) {
489 $this->dieWithError( 'apierror-parsetree-notwikitext', 'notwikitext' );
492 $wgParser->startExternalParse( $titleObj, $popts, Parser
::OT_PREPROCESS
);
493 $dom = $wgParser->preprocessToDom( $this->content
->getNativeData() );
494 if ( is_callable( [ $dom, 'saveXML' ] ) ) {
495 $xml = $dom->saveXML();
497 $xml = $dom->__toString();
499 $result_array['parsetree'] = $xml;
500 $result_array[ApiResult
::META_BC_SUBELEMENTS
][] = 'parsetree';
506 'categories' => 'cl',
510 'externallinks' => 'el',
515 'indicators' => 'ind',
516 'modulescripts' => 'm',
517 'modulestyles' => 'm',
518 'properties' => 'pp',
519 'limitreportdata' => 'lr',
520 'parsewarnings' => 'pw'
522 $this->setIndexedTagNames( $result_array, $result_mapping );
523 $result->addValue( null, $this->getModuleName(), $result_array );
527 * Constructs a ParserOptions object
529 * @param WikiPage $pageObj
530 * @param array $params
532 * @return array [ ParserOptions, ScopedCallback, bool $suppressCache ]
534 protected function makeParserOptions( WikiPage
$pageObj, array $params ) {
535 $popts = $pageObj->makeParserOptions( $this->getContext() );
536 $popts->enableLimitReport( !$params['disablepp'] && !$params['disablelimitreport'] );
537 $popts->setIsPreview( $params['preview'] ||
$params['sectionpreview'] );
538 $popts->setIsSectionPreview( $params['sectionpreview'] );
539 $popts->setEditSection( !$params['disableeditsection'] );
540 if ( $params['disabletidy'] ) {
541 $popts->setTidy( false );
543 $popts->setWrapOutputClass(
544 $params['wrapoutputclass'] === '' ?
false : $params['wrapoutputclass']
548 $suppressCache = false;
549 Hooks
::run( 'ApiMakeParserOptions',
550 [ $popts, $pageObj->getTitle(), $params, $this, &$reset, &$suppressCache ] );
552 // Force cache suppression when $popts aren't cacheable.
553 $suppressCache = $suppressCache ||
!$popts->isSafeToCache();
555 return [ $popts, $reset, $suppressCache ];
559 * @param WikiPage $page
560 * @param ParserOptions $popts
561 * @param bool $suppressCache
563 * @param Revision|null $rev
564 * @param bool $getContent
565 * @return ParserOutput
567 private function getParsedContent(
568 WikiPage
$page, $popts, $suppressCache, $pageId, $rev, $getContent
570 $revId = $rev ?
$rev->getId() : null;
571 $isDeleted = $rev && $rev->isDeleted( Revision
::DELETED_TEXT
);
573 if ( $getContent ||
$this->section
!== false ||
$isDeleted ) {
575 $this->content
= $rev->getContent( Revision
::FOR_THIS_USER
, $this->getUser() );
576 if ( !$this->content
) {
577 $this->dieWithError( [ 'apierror-missingcontent-revid', $revId ] );
580 $this->content
= $page->getContent( Revision
::FOR_THIS_USER
, $this->getUser() );
581 if ( !$this->content
) {
582 $this->dieWithError( [ 'apierror-missingcontent-pageid', $pageId ] );
585 $this->contentIsDeleted
= $isDeleted;
586 $this->contentIsSuppressed
= $rev &&
587 $rev->isDeleted( Revision
::DELETED_TEXT | Revision
::DELETED_RESTRICTED
);
590 if ( $this->section
!== false ) {
591 $this->content
= $this->getSectionContent(
593 $pageId === null ?
$page->getTitle()->getPrefixedText() : $this->msg( 'pageid', $pageId )
595 return $this->content
->getParserOutput( $page->getTitle(), $revId, $popts );
599 // getParserOutput can't do revdeled revisions
600 $pout = $this->content
->getParserOutput( $page->getTitle(), $revId, $popts );
602 // getParserOutput will save to Parser cache if able
603 $pout = $page->getParserOutput( $popts, $revId, $suppressCache );
606 $this->dieWithError( [ 'apierror-nosuchrevid', $revId ?
: $page->getLatest() ] );
613 * Extract the requested section from the given Content
615 * @param Content $content
616 * @param string|Message $what Identifies the content in error messages, e.g. page title.
619 private function getSectionContent( Content
$content, $what ) {
620 // Not cached (save or load)
621 $section = $content->getSection( $this->section
);
622 if ( $section === false ) {
623 $this->dieWithError( [ 'apierror-nosuchsection-what', $this->section
, $what ], 'nosuchsection' );
625 if ( $section === null ) {
626 $this->dieWithError( [ 'apierror-sectionsnotsupported-what', $what ], 'nosuchsection' );
634 * This mimicks the behavior of EditPage in formatting a summary
636 * @param Title $title of the page being parsed
637 * @param Array $params the API parameters of the request
638 * @return Content|bool
640 private function formatSummary( $title, $params ) {
642 $summary = !is_null( $params['summary'] ) ?
$params['summary'] : '';
643 $sectionTitle = !is_null( $params['sectiontitle'] ) ?
$params['sectiontitle'] : '';
645 if ( $this->section
=== 'new' && ( $sectionTitle === '' ||
$summary === '' ) ) {
646 if ( $sectionTitle !== '' ) {
647 $summary = $params['sectiontitle'];
649 if ( $summary !== '' ) {
650 $summary = wfMessage( 'newsectionsummary' )
651 ->rawParams( $wgParser->stripSectionName( $summary ) )
652 ->inContentLanguage()->text();
655 return Linker
::formatComment( $summary, $title, $this->section
=== 'new' );
658 private function formatLangLinks( $links ) {
660 foreach ( $links as $link ) {
662 $bits = explode( ':', $link, 2 );
663 $title = Title
::newFromText( $link );
665 $entry['lang'] = $bits[0];
667 $entry['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT
);
668 // localised language name in 'uselang' language
669 $entry['langname'] = Language
::fetchLanguageName(
670 $title->getInterwiki(),
671 $this->getLanguage()->getCode()
674 // native language name
675 $entry['autonym'] = Language
::fetchLanguageName( $title->getInterwiki() );
677 ApiResult
::setContentValue( $entry, 'title', $bits[1] );
684 private function formatCategoryLinks( $links ) {
691 // Fetch hiddencat property
693 $lb->setArray( [ NS_CATEGORY
=> $links ] );
694 $db = $this->getDB();
695 $res = $db->select( [ 'page', 'page_props' ],
696 [ 'page_title', 'pp_propname' ],
697 $lb->constructSet( 'page', $db ),
701 'LEFT JOIN', [ 'pp_propname' => 'hiddencat', 'pp_page = page_id' ]
705 foreach ( $res as $row ) {
706 $hiddencats[$row->page_title
] = isset( $row->pp_propname
);
709 $linkCache = LinkCache
::singleton();
711 foreach ( $links as $link => $sortkey ) {
713 $entry['sortkey'] = $sortkey;
714 // array keys will cast numeric category names to ints, so cast back to string
715 ApiResult
::setContentValue( $entry, 'category', (string)$link );
716 if ( !isset( $hiddencats[$link] ) ) {
717 $entry['missing'] = true;
719 // We already know the link doesn't exist in the database, so
720 // tell LinkCache that before calling $title->isKnown().
721 $title = Title
::makeTitle( NS_CATEGORY
, $link );
722 $linkCache->addBadLinkObj( $title );
723 if ( $title->isKnown() ) {
724 $entry['known'] = true;
726 } elseif ( $hiddencats[$link] ) {
727 $entry['hidden'] = true;
735 private function formatLinks( $links ) {
737 foreach ( $links as $ns => $nslinks ) {
738 foreach ( $nslinks as $title => $id ) {
741 ApiResult
::setContentValue( $entry, 'title', Title
::makeTitle( $ns, $title )->getFullText() );
742 $entry['exists'] = $id != 0;
750 private function formatIWLinks( $iw ) {
752 foreach ( $iw as $prefix => $titles ) {
753 foreach ( array_keys( $titles ) as $title ) {
755 $entry['prefix'] = $prefix;
757 $title = Title
::newFromText( "{$prefix}:{$title}" );
759 $entry['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT
);
762 ApiResult
::setContentValue( $entry, 'title', $title->getFullText() );
770 private function formatHeadItems( $headItems ) {
772 foreach ( $headItems as $tag => $content ) {
774 $entry['tag'] = $tag;
775 ApiResult
::setContentValue( $entry, 'content', $content );
782 private function formatLimitReportData( $limitReportData ) {
785 foreach ( $limitReportData as $name => $value ) {
787 $entry['name'] = $name;
788 if ( !is_array( $value ) ) {
791 ApiResult
::setIndexedTagNameRecursive( $value, 'param' );
792 $entry = array_merge( $entry, $value );
799 private function setIndexedTagNames( &$array, $mapping ) {
800 foreach ( $mapping as $key => $name ) {
801 if ( isset( $array[$key] ) ) {
802 ApiResult
::setIndexedTagName( $array[$key], $name );
807 public function getAllowedParams() {
811 ApiBase
::PARAM_TYPE
=> 'text',
814 ApiBase
::PARAM_TYPE
=> 'integer',
819 ApiBase
::PARAM_TYPE
=> 'integer',
821 'redirects' => false,
823 ApiBase
::PARAM_TYPE
=> 'integer',
826 ApiBase
::PARAM_DFLT
=> 'text|langlinks|categories|links|templates|' .
827 'images|externallinks|sections|revid|displaytitle|iwlinks|' .
828 'properties|parsewarnings',
829 ApiBase
::PARAM_ISMULTI
=> true,
830 ApiBase
::PARAM_TYPE
=> [
845 'encodedjsconfigvars',
856 ApiBase
::PARAM_HELP_MSG_PER_VALUE
=> [
857 'parsetree' => [ 'apihelp-parse-paramvalue-prop-parsetree', CONTENT_MODEL_WIKITEXT
],
859 ApiBase
::PARAM_DEPRECATED_VALUES
=> [
860 'headitems' => 'apiwarn-deprecation-parse-headitems',
863 'wrapoutputclass' => 'mw-parser-output',
866 'effectivelanglinks' => [
867 ApiBase
::PARAM_DFLT
=> false,
868 ApiBase
::PARAM_DEPRECATED
=> true,
872 ApiBase
::PARAM_TYPE
=> 'string',
875 ApiBase
::PARAM_DFLT
=> false,
876 ApiBase
::PARAM_DEPRECATED
=> true,
878 'disablelimitreport' => false,
879 'disableeditsection' => false,
880 'disabletidy' => false,
882 ApiBase
::PARAM_DFLT
=> false,
883 ApiBase
::PARAM_HELP_MSG
=> [
884 'apihelp-parse-param-generatexml', CONTENT_MODEL_WIKITEXT
886 ApiBase
::PARAM_DEPRECATED
=> true,
889 'sectionpreview' => false,
890 'disabletoc' => false,
892 ApiBase
::PARAM_TYPE
=> array_keys( Skin
::getAllowedSkins() ),
895 ApiBase
::PARAM_TYPE
=> ContentHandler
::getAllContentFormats(),
898 ApiBase
::PARAM_TYPE
=> ContentHandler
::getContentModels(),
903 protected function getExamplesMessages() {
905 'action=parse&page=Project:Sandbox'
906 => 'apihelp-parse-example-page',
907 'action=parse&text={{Project:Sandbox}}&contentmodel=wikitext'
908 => 'apihelp-parse-example-text',
909 'action=parse&text={{PAGENAME}}&title=Test'
910 => 'apihelp-parse-example-texttitle',
911 'action=parse&summary=Some+[[link]]&prop='
912 => 'apihelp-parse-example-summary',
916 public function getHelpUrls() {
917 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Parsing_wikitext#parse';