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;
41 public function execute() {
42 // The data is hot but user-dependent, like page views, so we set vary cookies
43 $this->getMain()->setCacheMode( 'anon-public-user-private' );
46 $params = $this->extractRequestParams();
48 // No easy way to say that text & title are allowed together while the
49 // rest aren't, so just do it in two calls.
50 $this->requireMaxOneParameter( $params, 'page', 'pageid', 'oldid', 'text' );
51 $this->requireMaxOneParameter( $params, 'page', 'pageid', 'oldid', 'title' );
53 $text = $params['text'];
54 $title = $params['title'];
55 if ( $title === null ) {
56 $titleProvided = false;
57 // A title is needed for parsing, so arbitrarily choose one
60 $titleProvided = true;
63 $page = $params['page'];
64 $pageid = $params['pageid'];
65 $oldid = $params['oldid'];
67 $model = $params['contentmodel'];
68 $format = $params['contentformat'];
70 $prop = array_flip( $params['prop'] );
72 if ( isset( $params['section'] ) ) {
73 $this->section
= $params['section'];
74 if ( !preg_match( '/^((T-)?\d+|new)$/', $this->section
) ) {
75 $this->dieWithError( 'apierror-invalidsection' );
78 $this->section
= false;
81 // The parser needs $wgTitle to be set, apparently the
82 // $title parameter in Parser::parse isn't enough *sigh*
83 // TODO: Does this still need $wgTitle?
84 global $wgParser, $wgTitle;
89 $result = $this->getResult();
91 if ( !is_null( $oldid ) ||
!is_null( $pageid ) ||
!is_null( $page ) ) {
92 if ( $this->section
=== 'new' ) {
93 $this->dieWithError( 'apierror-invalidparammix-parse-new-section', 'invalidparammix' );
95 if ( !is_null( $oldid ) ) {
96 // Don't use the parser cache
97 $rev = Revision
::newFromId( $oldid );
99 $this->dieWithError( [ 'apierror-nosuchrevid', $oldid ] );
102 $this->checkTitleUserPermissions( $rev->getTitle(), 'read' );
103 if ( !$rev->userCan( Revision
::DELETED_TEXT
, $this->getUser() ) ) {
105 [ 'apierror-permissiondenied', $this->msg( 'action-deletedtext' ) ]
109 $titleObj = $rev->getTitle();
110 $wgTitle = $titleObj;
111 $pageObj = WikiPage
::factory( $titleObj );
112 list( $popts, $reset, $suppressCache ) = $this->makeParserOptions( $pageObj, $params );
114 // If for some reason the "oldid" is actually the current revision, it may be cached
115 // Deliberately comparing $pageObj->getLatest() with $rev->getId(), rather than
116 // checking $rev->isCurrent(), because $pageObj is what actually ends up being used,
117 // and if its ->getLatest() is outdated, $rev->isCurrent() won't tell us that.
118 if ( !$suppressCache && $rev->getId() == $pageObj->getLatest() ) {
119 // May get from/save to parser cache
120 $p_result = $this->getParsedContent( $pageObj, $popts,
121 $pageid, isset( $prop['wikitext'] ) );
122 } else { // This is an old revision, so get the text differently
123 $this->content
= $rev->getContent( Revision
::FOR_THIS_USER
, $this->getUser() );
125 if ( $this->section
!== false ) {
126 $this->content
= $this->getSectionContent(
127 $this->content
, $this->msg( 'revid', $rev->getId() )
131 // Should we save old revision parses to the parser cache?
132 $p_result = $this->content
->getParserOutput( $titleObj, $rev->getId(), $popts );
134 } else { // Not $oldid, but $pageid or $page
135 if ( $params['redirects'] ) {
139 if ( !is_null( $pageid ) ) {
140 $reqParams['pageids'] = $pageid;
142 $reqParams['titles'] = $page;
144 $req = new FauxRequest( $reqParams );
145 $main = new ApiMain( $req );
146 $pageSet = new ApiPageSet( $main );
148 $redirValues = $pageSet->getRedirectTitlesAsResult( $this->getResult() );
151 foreach ( $pageSet->getRedirectTitles() as $title ) {
152 $to = $title->getFullText();
154 $pageParams = [ 'title' => $to ];
155 } elseif ( !is_null( $pageid ) ) {
156 $pageParams = [ 'pageid' => $pageid ];
158 $pageParams = [ 'title' => $page ];
161 $pageObj = $this->getTitleOrPageId( $pageParams, 'fromdb' );
162 $titleObj = $pageObj->getTitle();
163 if ( !$titleObj ||
!$titleObj->exists() ) {
164 $this->dieWithError( 'apierror-missingtitle' );
167 $this->checkTitleUserPermissions( $titleObj, 'read' );
168 $wgTitle = $titleObj;
170 if ( isset( $prop['revid'] ) ) {
171 $oldid = $pageObj->getLatest();
174 list( $popts, $reset, $suppressCache ) = $this->makeParserOptions( $pageObj, $params );
176 // Don't pollute the parser cache when setting options that aren't
177 // in ParserOptions::optionsHash()
178 /// @todo: This should be handled closer to the actual cache instead of here, see T110269
179 $suppressCache = $suppressCache ||
180 $params['disablepp'] ||
181 $params['disablelimitreport'] ||
182 $params['preview'] ||
183 $params['sectionpreview'] ||
184 $params['disabletidy'];
186 if ( $suppressCache ) {
187 $this->content
= $this->getContent( $pageObj, $pageid );
188 $p_result = $this->content
->getParserOutput( $titleObj, null, $popts );
190 // Potentially cached
191 $p_result = $this->getParsedContent( $pageObj, $popts, $pageid,
192 isset( $prop['wikitext'] ) );
195 } else { // Not $oldid, $pageid, $page. Hence based on $text
196 $titleObj = Title
::newFromText( $title );
197 if ( !$titleObj ||
$titleObj->isExternal() ) {
198 $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $title ) ] );
200 $wgTitle = $titleObj;
201 if ( $titleObj->canExist() ) {
202 $pageObj = WikiPage
::factory( $titleObj );
204 // Do like MediaWiki::initializeArticle()
205 $article = Article
::newFromTitle( $titleObj, $this->getContext() );
206 $pageObj = $article->getPage();
209 list( $popts, $reset ) = $this->makeParserOptions( $pageObj, $params );
210 $textProvided = !is_null( $text );
212 if ( !$textProvided ) {
213 if ( $titleProvided && ( $prop ||
$params['generatexml'] ) ) {
214 $this->addWarning( 'apiwarn-parse-titlewithouttext' );
216 // Prevent warning from ContentHandler::makeContent()
220 // If we are parsing text, do not use the content model of the default
221 // API title, but default to wikitext to keep BC.
222 if ( $textProvided && !$titleProvided && is_null( $model ) ) {
223 $model = CONTENT_MODEL_WIKITEXT
;
224 $this->addWarning( [ 'apiwarn-parse-nocontentmodel', $model ] );
228 $this->content
= ContentHandler
::makeContent( $text, $titleObj, $model, $format );
229 } catch ( MWContentSerializationException
$ex ) {
230 $this->dieWithException( $ex, [
231 'wrap' => ApiMessage
::create( 'apierror-contentserializationexception', 'parseerror' )
235 if ( $this->section
!== false ) {
236 if ( $this->section
=== 'new' ) {
237 // Insert the section title above the content.
238 if ( !is_null( $params['sectiontitle'] ) && $params['sectiontitle'] !== '' ) {
239 $this->content
= $this->content
->addSectionHeader( $params['sectiontitle'] );
242 $this->content
= $this->getSectionContent( $this->content
, $titleObj->getPrefixedText() );
246 if ( $params['pst'] ||
$params['onlypst'] ) {
247 $this->pstContent
= $this->content
->preSaveTransform( $titleObj, $this->getUser(), $popts );
249 if ( $params['onlypst'] ) {
250 // Build a result and bail out
252 $result_array['text'] = $this->pstContent
->serialize( $format );
253 $result_array[ApiResult
::META_BC_SUBELEMENTS
][] = 'text';
254 if ( isset( $prop['wikitext'] ) ) {
255 $result_array['wikitext'] = $this->content
->serialize( $format );
256 $result_array[ApiResult
::META_BC_SUBELEMENTS
][] = 'wikitext';
258 if ( !is_null( $params['summary'] ) ||
259 ( !is_null( $params['sectiontitle'] ) && $this->section
=== 'new' )
261 $result_array['parsedsummary'] = $this->formatSummary( $titleObj, $params );
262 $result_array[ApiResult
::META_BC_SUBELEMENTS
][] = 'parsedsummary';
265 $result->addValue( null, $this->getModuleName(), $result_array );
270 // Not cached (save or load)
271 if ( $params['pst'] ) {
272 $p_result = $this->pstContent
->getParserOutput( $titleObj, null, $popts );
274 $p_result = $this->content
->getParserOutput( $titleObj, null, $popts );
280 $result_array['title'] = $titleObj->getPrefixedText();
281 $result_array['pageid'] = $pageid ?
: $pageObj->getId();
283 if ( $params['disabletoc'] ) {
284 $p_result->setTOCEnabled( false );
287 if ( isset( $params['useskin'] ) ) {
288 $factory = MediaWikiServices
::getInstance()->getSkinFactory();
289 $skin = $factory->makeSkin( Skin
::normalizeKey( $params['useskin'] ) );
295 if ( $skin ||
isset( $prop['headhtml'] ) ) {
296 // Enabling the skin via 'useskin' or 'headhtml' gets OutputPage and
297 // Skin involved, which (among others) applies these hooks:
298 // - ParserOutputHooks
299 // - Hook: LanguageLinks
300 // - Hook: OutputPageParserOutput
301 $context = new DerivativeContext( $this->getContext() );
302 $context->setTitle( $titleObj );
303 $context->setWikiPage( $pageObj );
306 // Use the skin specified by 'useskin'
307 $context->setSkin( $skin );
308 // Context clones the skin, refetch to stay in sync. (T166022)
309 $skin = $context->getSkin();
312 $outputPage = new OutputPage( $context );
313 $outputPage->addParserOutputMetadata( $p_result );
314 $context->setOutput( $outputPage );
317 if ( !is_null( $oldid ) ) {
318 $result_array['revid'] = intval( $oldid );
321 if ( $params['redirects'] && !is_null( $redirValues ) ) {
322 $result_array['redirects'] = $redirValues;
325 if ( isset( $prop['text'] ) ) {
326 $result_array['text'] = $p_result->getText();
327 $result_array[ApiResult
::META_BC_SUBELEMENTS
][] = 'text';
330 if ( !is_null( $params['summary'] ) ||
331 ( !is_null( $params['sectiontitle'] ) && $this->section
=== 'new' )
333 $result_array['parsedsummary'] = $this->formatSummary( $titleObj, $params );
334 $result_array[ApiResult
::META_BC_SUBELEMENTS
][] = 'parsedsummary';
337 if ( isset( $prop['langlinks'] ) ) {
339 $langlinks = $outputPage->getLanguageLinks();
341 $langlinks = $p_result->getLanguageLinks();
342 // The deprecated 'effectivelanglinks' option depredates OutputPage
343 // support via 'useskin'. If not already applied, then run just this
344 // one hook of OutputPage::addParserOutputMetadata here.
345 if ( $params['effectivelanglinks'] ) {
347 Hooks
::run( 'LanguageLinks', [ $titleObj, &$langlinks, &$linkFlags ] );
351 $result_array['langlinks'] = $this->formatLangLinks( $langlinks );
353 if ( isset( $prop['categories'] ) ) {
354 $result_array['categories'] = $this->formatCategoryLinks( $p_result->getCategories() );
356 if ( isset( $prop['categorieshtml'] ) ) {
357 $result_array['categorieshtml'] = $this->categoriesHtml( $p_result->getCategories() );
358 $result_array[ApiResult
::META_BC_SUBELEMENTS
][] = 'categorieshtml';
360 if ( isset( $prop['links'] ) ) {
361 $result_array['links'] = $this->formatLinks( $p_result->getLinks() );
363 if ( isset( $prop['templates'] ) ) {
364 $result_array['templates'] = $this->formatLinks( $p_result->getTemplates() );
366 if ( isset( $prop['images'] ) ) {
367 $result_array['images'] = array_keys( $p_result->getImages() );
369 if ( isset( $prop['externallinks'] ) ) {
370 $result_array['externallinks'] = array_keys( $p_result->getExternalLinks() );
372 if ( isset( $prop['sections'] ) ) {
373 $result_array['sections'] = $p_result->getSections();
375 if ( isset( $prop['parsewarnings'] ) ) {
376 $result_array['parsewarnings'] = $p_result->getWarnings();
379 if ( isset( $prop['displaytitle'] ) ) {
380 $result_array['displaytitle'] = $p_result->getDisplayTitle() ?
:
381 $titleObj->getPrefixedText();
384 if ( isset( $prop['headitems'] ) ) {
386 $result_array['headitems'] = $this->formatHeadItems( $outputPage->getHeadItemsArray() );
388 $result_array['headitems'] = $this->formatHeadItems( $p_result->getHeadItems() );
390 $this->addDeprecation( 'apiwarn-deprecation-parse-headitems', 'action=parse&prop=headitems' );
393 if ( isset( $prop['headhtml'] ) ) {
394 $result_array['headhtml'] = $outputPage->headElement( $context->getSkin() );
395 $result_array[ApiResult
::META_BC_SUBELEMENTS
][] = 'headhtml';
398 if ( isset( $prop['modules'] ) ) {
400 $result_array['modules'] = $outputPage->getModules();
401 $result_array['modulescripts'] = $outputPage->getModuleScripts();
402 $result_array['modulestyles'] = $outputPage->getModuleStyles();
404 $result_array['modules'] = array_values( array_unique( $p_result->getModules() ) );
405 $result_array['modulescripts'] = array_values( array_unique( $p_result->getModuleScripts() ) );
406 $result_array['modulestyles'] = array_values( array_unique( $p_result->getModuleStyles() ) );
410 if ( isset( $prop['jsconfigvars'] ) ) {
411 $jsconfigvars = $skin ?
$outputPage->getJsConfigVars() : $p_result->getJsConfigVars();
412 $result_array['jsconfigvars'] = ApiResult
::addMetadataToResultVars( $jsconfigvars );
415 if ( isset( $prop['encodedjsconfigvars'] ) ) {
416 $jsconfigvars = $skin ?
$outputPage->getJsConfigVars() : $p_result->getJsConfigVars();
417 $result_array['encodedjsconfigvars'] = FormatJson
::encode(
422 $result_array[ApiResult
::META_SUBELEMENTS
][] = 'encodedjsconfigvars';
425 if ( isset( $prop['modules'] ) &&
426 !isset( $prop['jsconfigvars'] ) && !isset( $prop['encodedjsconfigvars'] ) ) {
427 $this->addWarning( 'apiwarn-moduleswithoutvars' );
430 if ( isset( $prop['indicators'] ) ) {
432 $result_array['indicators'] = (array)$outputPage->getIndicators();
434 $result_array['indicators'] = (array)$p_result->getIndicators();
436 ApiResult
::setArrayType( $result_array['indicators'], 'BCkvp', 'name' );
439 if ( isset( $prop['iwlinks'] ) ) {
440 $result_array['iwlinks'] = $this->formatIWLinks( $p_result->getInterwikiLinks() );
443 if ( isset( $prop['wikitext'] ) ) {
444 $result_array['wikitext'] = $this->content
->serialize( $format );
445 $result_array[ApiResult
::META_BC_SUBELEMENTS
][] = 'wikitext';
446 if ( !is_null( $this->pstContent
) ) {
447 $result_array['psttext'] = $this->pstContent
->serialize( $format );
448 $result_array[ApiResult
::META_BC_SUBELEMENTS
][] = 'psttext';
451 if ( isset( $prop['properties'] ) ) {
452 $result_array['properties'] = (array)$p_result->getProperties();
453 ApiResult
::setArrayType( $result_array['properties'], 'BCkvp', 'name' );
456 if ( isset( $prop['limitreportdata'] ) ) {
457 $result_array['limitreportdata'] =
458 $this->formatLimitReportData( $p_result->getLimitReportData() );
460 if ( isset( $prop['limitreporthtml'] ) ) {
461 $result_array['limitreporthtml'] = EditPage
::getPreviewLimitReport( $p_result );
462 $result_array[ApiResult
::META_BC_SUBELEMENTS
][] = 'limitreporthtml';
465 if ( isset( $prop['parsetree'] ) ||
$params['generatexml'] ) {
466 if ( $this->content
->getModel() != CONTENT_MODEL_WIKITEXT
) {
467 $this->dieWithError( 'apierror-parsetree-notwikitext', 'notwikitext' );
470 $wgParser->startExternalParse( $titleObj, $popts, Parser
::OT_PREPROCESS
);
471 $dom = $wgParser->preprocessToDom( $this->content
->getNativeData() );
472 if ( is_callable( [ $dom, 'saveXML' ] ) ) {
473 $xml = $dom->saveXML();
475 $xml = $dom->__toString();
477 $result_array['parsetree'] = $xml;
478 $result_array[ApiResult
::META_BC_SUBELEMENTS
][] = 'parsetree';
484 'categories' => 'cl',
488 'externallinks' => 'el',
493 'indicators' => 'ind',
494 'modulescripts' => 'm',
495 'modulestyles' => 'm',
496 'properties' => 'pp',
497 'limitreportdata' => 'lr',
498 'parsewarnings' => 'pw'
500 $this->setIndexedTagNames( $result_array, $result_mapping );
501 $result->addValue( null, $this->getModuleName(), $result_array );
505 * Constructs a ParserOptions object
507 * @param WikiPage $pageObj
508 * @param array $params
510 * @return array [ ParserOptions, ScopedCallback, bool $suppressCache ]
512 protected function makeParserOptions( WikiPage
$pageObj, array $params ) {
513 $popts = $pageObj->makeParserOptions( $this->getContext() );
514 $popts->enableLimitReport( !$params['disablepp'] && !$params['disablelimitreport'] );
515 $popts->setIsPreview( $params['preview'] ||
$params['sectionpreview'] );
516 $popts->setIsSectionPreview( $params['sectionpreview'] );
517 $popts->setEditSection( !$params['disableeditsection'] );
518 if ( $params['disabletidy'] ) {
519 $popts->setTidy( false );
521 $popts->setWrapOutputClass(
522 $params['wrapoutputclass'] === '' ?
false : $params['wrapoutputclass']
526 $suppressCache = false;
527 Hooks
::run( 'ApiMakeParserOptions',
528 [ $popts, $pageObj->getTitle(), $params, $this, &$reset, &$suppressCache ] );
530 return [ $popts, $reset, $suppressCache ];
534 * @param WikiPage $page
535 * @param ParserOptions $popts
537 * @param bool $getWikitext
538 * @return ParserOutput
540 private function getParsedContent( WikiPage
$page, $popts, $pageId = null, $getWikitext = false ) {
541 $this->content
= $this->getContent( $page, $pageId );
543 if ( $this->section
!== false && $this->content
!== null ) {
544 // Not cached (save or load)
545 return $this->content
->getParserOutput( $page->getTitle(), null, $popts );
548 // Try the parser cache first
549 // getParserOutput will save to Parser cache if able
550 $pout = $page->getParserOutput( $popts );
552 $this->dieWithError( [ 'apierror-nosuchrevid', $page->getLatest() ] );
554 if ( $getWikitext ) {
555 $this->content
= $page->getContent( Revision
::RAW
);
562 * Get the content for the given page and the requested section.
564 * @param WikiPage $page
568 private function getContent( WikiPage
$page, $pageId = null ) {
569 $content = $page->getContent( Revision
::RAW
); // XXX: really raw?
571 if ( $this->section
!== false && $content !== null ) {
572 $content = $this->getSectionContent(
575 ?
$this->msg( 'pageid', $pageId )
576 : $page->getTitle()->getPrefixedText()
583 * Extract the requested section from the given Content
585 * @param Content $content
586 * @param string|Message $what Identifies the content in error messages, e.g. page title.
587 * @return Content|bool
589 private function getSectionContent( Content
$content, $what ) {
590 // Not cached (save or load)
591 $section = $content->getSection( $this->section
);
592 if ( $section === false ) {
593 $this->dieWithError( [ 'apierror-nosuchsection-what', $this->section
, $what ], 'nosuchsection' );
595 if ( $section === null ) {
596 $this->dieWithError( [ 'apierror-sectionsnotsupported-what', $what ], 'nosuchsection' );
604 * This mimicks the behavior of EditPage in formatting a summary
606 * @param Title $title of the page being parsed
607 * @param Array $params the API parameters of the request
608 * @return Content|bool
610 private function formatSummary( $title, $params ) {
612 $summary = !is_null( $params['summary'] ) ?
$params['summary'] : '';
613 $sectionTitle = !is_null( $params['sectiontitle'] ) ?
$params['sectiontitle'] : '';
615 if ( $this->section
=== 'new' && ( $sectionTitle === '' ||
$summary === '' ) ) {
616 if ( $sectionTitle !== '' ) {
617 $summary = $params['sectiontitle'];
619 if ( $summary !== '' ) {
620 $summary = wfMessage( 'newsectionsummary' )
621 ->rawParams( $wgParser->stripSectionName( $summary ) )
622 ->inContentLanguage()->text();
625 return Linker
::formatComment( $summary, $title, $this->section
=== 'new' );
628 private function formatLangLinks( $links ) {
630 foreach ( $links as $link ) {
632 $bits = explode( ':', $link, 2 );
633 $title = Title
::newFromText( $link );
635 $entry['lang'] = $bits[0];
637 $entry['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT
);
638 // localised language name in 'uselang' language
639 $entry['langname'] = Language
::fetchLanguageName(
640 $title->getInterwiki(),
641 $this->getLanguage()->getCode()
644 // native language name
645 $entry['autonym'] = Language
::fetchLanguageName( $title->getInterwiki() );
647 ApiResult
::setContentValue( $entry, 'title', $bits[1] );
654 private function formatCategoryLinks( $links ) {
661 // Fetch hiddencat property
663 $lb->setArray( [ NS_CATEGORY
=> $links ] );
664 $db = $this->getDB();
665 $res = $db->select( [ 'page', 'page_props' ],
666 [ 'page_title', 'pp_propname' ],
667 $lb->constructSet( 'page', $db ),
671 'LEFT JOIN', [ 'pp_propname' => 'hiddencat', 'pp_page = page_id' ]
675 foreach ( $res as $row ) {
676 $hiddencats[$row->page_title
] = isset( $row->pp_propname
);
679 $linkCache = LinkCache
::singleton();
681 foreach ( $links as $link => $sortkey ) {
683 $entry['sortkey'] = $sortkey;
684 // array keys will cast numeric category names to ints, so cast back to string
685 ApiResult
::setContentValue( $entry, 'category', (string)$link );
686 if ( !isset( $hiddencats[$link] ) ) {
687 $entry['missing'] = true;
689 // We already know the link doesn't exist in the database, so
690 // tell LinkCache that before calling $title->isKnown().
691 $title = Title
::makeTitle( NS_CATEGORY
, $link );
692 $linkCache->addBadLinkObj( $title );
693 if ( $title->isKnown() ) {
694 $entry['known'] = true;
696 } elseif ( $hiddencats[$link] ) {
697 $entry['hidden'] = true;
705 private function categoriesHtml( $categories ) {
706 $context = $this->getContext();
707 $context->getOutput()->addCategoryLinks( $categories );
709 return $context->getSkin()->getCategories();
712 private function formatLinks( $links ) {
714 foreach ( $links as $ns => $nslinks ) {
715 foreach ( $nslinks as $title => $id ) {
718 ApiResult
::setContentValue( $entry, 'title', Title
::makeTitle( $ns, $title )->getFullText() );
719 $entry['exists'] = $id != 0;
727 private function formatIWLinks( $iw ) {
729 foreach ( $iw as $prefix => $titles ) {
730 foreach ( array_keys( $titles ) as $title ) {
732 $entry['prefix'] = $prefix;
734 $title = Title
::newFromText( "{$prefix}:{$title}" );
736 $entry['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT
);
739 ApiResult
::setContentValue( $entry, 'title', $title->getFullText() );
747 private function formatHeadItems( $headItems ) {
749 foreach ( $headItems as $tag => $content ) {
751 $entry['tag'] = $tag;
752 ApiResult
::setContentValue( $entry, 'content', $content );
759 private function formatLimitReportData( $limitReportData ) {
762 foreach ( $limitReportData as $name => $value ) {
764 $entry['name'] = $name;
765 if ( !is_array( $value ) ) {
768 ApiResult
::setIndexedTagNameRecursive( $value, 'param' );
769 $entry = array_merge( $entry, $value );
776 private function setIndexedTagNames( &$array, $mapping ) {
777 foreach ( $mapping as $key => $name ) {
778 if ( isset( $array[$key] ) ) {
779 ApiResult
::setIndexedTagName( $array[$key], $name );
784 public function getAllowedParams() {
788 ApiBase
::PARAM_TYPE
=> 'text',
793 ApiBase
::PARAM_TYPE
=> 'integer',
795 'redirects' => false,
797 ApiBase
::PARAM_TYPE
=> 'integer',
800 ApiBase
::PARAM_DFLT
=> 'text|langlinks|categories|links|templates|' .
801 'images|externallinks|sections|revid|displaytitle|iwlinks|' .
802 'properties|parsewarnings',
803 ApiBase
::PARAM_ISMULTI
=> true,
804 ApiBase
::PARAM_TYPE
=> [
820 'encodedjsconfigvars',
830 ApiBase
::PARAM_HELP_MSG_PER_VALUE
=> [
831 'parsetree' => [ 'apihelp-parse-paramvalue-prop-parsetree', CONTENT_MODEL_WIKITEXT
],
834 'wrapoutputclass' => 'mw-parser-output',
837 'effectivelanglinks' => [
838 ApiBase
::PARAM_DFLT
=> false,
839 ApiBase
::PARAM_DEPRECATED
=> true,
843 ApiBase
::PARAM_TYPE
=> 'string',
846 ApiBase
::PARAM_DFLT
=> false,
847 ApiBase
::PARAM_DEPRECATED
=> true,
849 'disablelimitreport' => false,
850 'disableeditsection' => false,
851 'disabletidy' => false,
853 ApiBase
::PARAM_DFLT
=> false,
854 ApiBase
::PARAM_HELP_MSG
=> [
855 'apihelp-parse-param-generatexml', CONTENT_MODEL_WIKITEXT
857 ApiBase
::PARAM_DEPRECATED
=> true,
860 'sectionpreview' => false,
861 'disabletoc' => false,
863 ApiBase
::PARAM_TYPE
=> array_keys( Skin
::getAllowedSkins() ),
866 ApiBase
::PARAM_TYPE
=> ContentHandler
::getAllContentFormats(),
869 ApiBase
::PARAM_TYPE
=> ContentHandler
::getContentModels(),
874 protected function getExamplesMessages() {
876 'action=parse&page=Project:Sandbox'
877 => 'apihelp-parse-example-page',
878 'action=parse&text={{Project:Sandbox}}&contentmodel=wikitext'
879 => 'apihelp-parse-example-text',
880 'action=parse&text={{PAGENAME}}&title=Test'
881 => 'apihelp-parse-example-texttitle',
882 'action=parse&summary=Some+[[link]]&prop='
883 => 'apihelp-parse-example-summary',
887 public function getHelpUrls() {
888 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Parsing_wikitext#parse';