API: Return parsedsummary on onlypst
[lhc/web/wiklou.git] / includes / api / ApiParse.php
1 <?php
2 /**
3 * Created on Dec 01, 2007
4 *
5 * Copyright © 2007 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
6 *
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.
11 *
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.
16 *
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
21 *
22 * @file
23 */
24
25 /**
26 * @ingroup API
27 */
28 class ApiParse extends ApiBase {
29
30 /** @var string $section */
31 private $section = null;
32
33 /** @var Content $content */
34 private $content = null;
35
36 /** @var Content $pstContent */
37 private $pstContent = null;
38
39 public function execute() {
40 // The data is hot but user-dependent, like page views, so we set vary cookies
41 $this->getMain()->setCacheMode( 'anon-public-user-private' );
42
43 // Get parameters
44 $params = $this->extractRequestParams();
45 $text = $params['text'];
46 $title = $params['title'];
47 if ( $title === null ) {
48 $titleProvided = false;
49 // A title is needed for parsing, so arbitrarily choose one
50 $title = 'API';
51 } else {
52 $titleProvided = true;
53 }
54
55 $page = $params['page'];
56 $pageid = $params['pageid'];
57 $oldid = $params['oldid'];
58
59 $model = $params['contentmodel'];
60 $format = $params['contentformat'];
61
62 if ( !is_null( $page ) && ( !is_null( $text ) || $titleProvided ) ) {
63 $this->dieUsage(
64 'The page parameter cannot be used together with the text and title parameters',
65 'params'
66 );
67 }
68
69 $prop = array_flip( $params['prop'] );
70
71 if ( isset( $params['section'] ) ) {
72 $this->section = $params['section'];
73 } else {
74 $this->section = false;
75 }
76
77 // The parser needs $wgTitle to be set, apparently the
78 // $title parameter in Parser::parse isn't enough *sigh*
79 // TODO: Does this still need $wgTitle?
80 global $wgParser, $wgTitle;
81
82 $redirValues = null;
83
84 // Return result
85 $result = $this->getResult();
86
87 if ( !is_null( $oldid ) || !is_null( $pageid ) || !is_null( $page ) ) {
88 if ( !is_null( $oldid ) ) {
89 // Don't use the parser cache
90 $rev = Revision::newFromId( $oldid );
91 if ( !$rev ) {
92 $this->dieUsage( "There is no revision ID $oldid", 'missingrev' );
93 }
94 if ( !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
95 $this->dieUsage( "You don't have permission to view deleted revisions", 'permissiondenied' );
96 }
97
98 $titleObj = $rev->getTitle();
99 $wgTitle = $titleObj;
100 $pageObj = WikiPage::factory( $titleObj );
101 $popts = $this->makeParserOptions( $pageObj, $params );
102
103 // If for some reason the "oldid" is actually the current revision, it may be cached
104 if ( $rev->isCurrent() ) {
105 // May get from/save to parser cache
106 $p_result = $this->getParsedContent( $pageObj, $popts,
107 $pageid, isset( $prop['wikitext'] ) );
108 } else { // This is an old revision, so get the text differently
109 $this->content = $rev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
110
111 if ( $this->section !== false ) {
112 $this->content = $this->getSectionContent( $this->content, 'r' . $rev->getId() );
113 }
114
115 // Should we save old revision parses to the parser cache?
116 $p_result = $this->content->getParserOutput( $titleObj, $rev->getId(), $popts );
117 }
118 } else { // Not $oldid, but $pageid or $page
119 if ( $params['redirects'] ) {
120 $reqParams = array(
121 'action' => 'query',
122 'redirects' => '',
123 );
124 if ( !is_null( $pageid ) ) {
125 $reqParams['pageids'] = $pageid;
126 } else { // $page
127 $reqParams['titles'] = $page;
128 }
129 $req = new FauxRequest( $reqParams );
130 $main = new ApiMain( $req );
131 $main->execute();
132 $data = $main->getResultData();
133 $redirValues = isset( $data['query']['redirects'] )
134 ? $data['query']['redirects']
135 : array();
136 $to = $page;
137 foreach ( (array)$redirValues as $r ) {
138 $to = $r['to'];
139 }
140 $pageParams = array( 'title' => $to );
141 } elseif ( !is_null( $pageid ) ) {
142 $pageParams = array( 'pageid' => $pageid );
143 } else { // $page
144 $pageParams = array( 'title' => $page );
145 }
146
147 $pageObj = $this->getTitleOrPageId( $pageParams, 'fromdb' );
148 $titleObj = $pageObj->getTitle();
149 if ( !$titleObj || !$titleObj->exists() ) {
150 $this->dieUsage( "The page you specified doesn't exist", 'missingtitle' );
151 }
152 $wgTitle = $titleObj;
153
154 if ( isset( $prop['revid'] ) ) {
155 $oldid = $pageObj->getLatest();
156 }
157
158 $popts = $this->makeParserOptions( $pageObj, $params );
159
160 // Potentially cached
161 $p_result = $this->getParsedContent( $pageObj, $popts, $pageid,
162 isset( $prop['wikitext'] ) );
163 }
164 } else { // Not $oldid, $pageid, $page. Hence based on $text
165 $titleObj = Title::newFromText( $title );
166 if ( !$titleObj || $titleObj->isExternal() ) {
167 $this->dieUsageMsg( array( 'invalidtitle', $title ) );
168 }
169 $wgTitle = $titleObj;
170 if ( $titleObj->canExist() ) {
171 $pageObj = WikiPage::factory( $titleObj );
172 } else {
173 // Do like MediaWiki::initializeArticle()
174 $article = Article::newFromTitle( $titleObj, $this->getContext() );
175 $pageObj = $article->getPage();
176 }
177
178 $popts = $this->makeParserOptions( $pageObj, $params );
179 $textProvided = !is_null( $text );
180
181 if ( !$textProvided ) {
182 if ( $titleProvided && ( $prop || $params['generatexml'] ) ) {
183 $this->setWarning(
184 "'title' used without 'text', and parsed page properties were requested " .
185 "(did you mean to use 'page' instead of 'title'?)"
186 );
187 }
188 // Prevent warning from ContentHandler::makeContent()
189 $text = '';
190 }
191
192 // If we are parsing text, do not use the content model of the default
193 // API title, but default to wikitext to keep BC.
194 if ( $textProvided && !$titleProvided && is_null( $model ) ) {
195 $model = CONTENT_MODEL_WIKITEXT;
196 $this->setWarning( "No 'title' or 'contentmodel' was given, assuming $model." );
197 }
198
199 try {
200 $this->content = ContentHandler::makeContent( $text, $titleObj, $model, $format );
201 } catch ( MWContentSerializationException $ex ) {
202 $this->dieUsage( $ex->getMessage(), 'parseerror' );
203 }
204
205 if ( $this->section !== false ) {
206 $this->content = $this->getSectionContent( $this->content, $titleObj->getPrefixedText() );
207 }
208
209 if ( $params['pst'] || $params['onlypst'] ) {
210 $this->pstContent = $this->content->preSaveTransform( $titleObj, $this->getUser(), $popts );
211 }
212 if ( $params['onlypst'] ) {
213 // Build a result and bail out
214 $result_array = array();
215 $result_array['text'] = array();
216 ApiResult::setContent( $result_array['text'], $this->pstContent->serialize( $format ) );
217 if ( isset( $prop['wikitext'] ) ) {
218 $result_array['wikitext'] = array();
219 ApiResult::setContent( $result_array['wikitext'], $this->content->serialize( $format ) );
220 }
221 if ( !is_null( $params['summary'] ) ) {
222 $result_array['parsedsummary'] = array();
223 ApiResult::setContent(
224 $result_array['parsedsummary'],
225 Linker::formatComment( $params['summary'], $titleObj )
226 );
227 }
228
229 $result->addValue( null, $this->getModuleName(), $result_array );
230
231 return;
232 }
233
234 // Not cached (save or load)
235 if ( $params['pst'] ) {
236 $p_result = $this->pstContent->getParserOutput( $titleObj, null, $popts );
237 } else {
238 $p_result = $this->content->getParserOutput( $titleObj, null, $popts );
239 }
240 }
241
242 $result_array = array();
243
244 $result_array['title'] = $titleObj->getPrefixedText();
245
246 if ( !is_null( $oldid ) ) {
247 $result_array['revid'] = intval( $oldid );
248 }
249
250 if ( $params['redirects'] && !is_null( $redirValues ) ) {
251 $result_array['redirects'] = $redirValues;
252 }
253
254 if ( $params['disabletoc'] ) {
255 $p_result->setTOCEnabled( false );
256 }
257
258 if ( isset( $prop['text'] ) ) {
259 $result_array['text'] = array();
260 ApiResult::setContent( $result_array['text'], $p_result->getText() );
261 }
262
263 if ( !is_null( $params['summary'] ) ) {
264 $result_array['parsedsummary'] = array();
265 ApiResult::setContent(
266 $result_array['parsedsummary'],
267 Linker::formatComment( $params['summary'], $titleObj )
268 );
269 }
270
271 if ( isset( $prop['langlinks'] ) ) {
272 $langlinks = $p_result->getLanguageLinks();
273
274 if ( $params['effectivelanglinks'] ) {
275 // Link flags are ignored for now, but may in the future be
276 // included in the result.
277 $linkFlags = array();
278 Hooks::run( 'LanguageLinks', array( $titleObj, &$langlinks, &$linkFlags ) );
279 }
280 } else {
281 $langlinks = false;
282 }
283
284 if ( isset( $prop['langlinks'] ) ) {
285 $result_array['langlinks'] = $this->formatLangLinks( $langlinks );
286 }
287 if ( isset( $prop['categories'] ) ) {
288 $result_array['categories'] = $this->formatCategoryLinks( $p_result->getCategories() );
289 }
290 if ( isset( $prop['categorieshtml'] ) ) {
291 $categoriesHtml = $this->categoriesHtml( $p_result->getCategories() );
292 $result_array['categorieshtml'] = array();
293 ApiResult::setContent( $result_array['categorieshtml'], $categoriesHtml );
294 }
295 if ( isset( $prop['links'] ) ) {
296 $result_array['links'] = $this->formatLinks( $p_result->getLinks() );
297 }
298 if ( isset( $prop['templates'] ) ) {
299 $result_array['templates'] = $this->formatLinks( $p_result->getTemplates() );
300 }
301 if ( isset( $prop['images'] ) ) {
302 $result_array['images'] = array_keys( $p_result->getImages() );
303 }
304 if ( isset( $prop['externallinks'] ) ) {
305 $result_array['externallinks'] = array_keys( $p_result->getExternalLinks() );
306 }
307 if ( isset( $prop['sections'] ) ) {
308 $result_array['sections'] = $p_result->getSections();
309 }
310
311 if ( isset( $prop['displaytitle'] ) ) {
312 $result_array['displaytitle'] = $p_result->getDisplayTitle() ?
313 $p_result->getDisplayTitle() :
314 $titleObj->getPrefixedText();
315 }
316
317 if ( isset( $prop['headitems'] ) || isset( $prop['headhtml'] ) ) {
318 $context = $this->getContext();
319 $context->setTitle( $titleObj );
320 $context->getOutput()->addParserOutputMetadata( $p_result );
321
322 if ( isset( $prop['headitems'] ) ) {
323 $headItems = $this->formatHeadItems( $p_result->getHeadItems() );
324
325 $css = $this->formatCss( $context->getOutput()->buildCssLinksArray() );
326
327 $scripts = array( $context->getOutput()->getHeadScripts() );
328
329 $result_array['headitems'] = array_merge( $headItems, $css, $scripts );
330 }
331
332 if ( isset( $prop['headhtml'] ) ) {
333 $result_array['headhtml'] = array();
334 ApiResult::setContent(
335 $result_array['headhtml'],
336 $context->getOutput()->headElement( $context->getSkin() )
337 );
338 }
339 }
340
341 if ( isset( $prop['modules'] ) ) {
342 $result_array['modules'] = array_values( array_unique( $p_result->getModules() ) );
343 $result_array['modulescripts'] = array_values( array_unique( $p_result->getModuleScripts() ) );
344 $result_array['modulestyles'] = array_values( array_unique( $p_result->getModuleStyles() ) );
345 $result_array['modulemessages'] = array_values( array_unique( $p_result->getModuleMessages() ) );
346 }
347
348 if ( isset( $prop['indicators'] ) ) {
349 foreach ( $p_result->getIndicators() as $name => $content ) {
350 $indicator = array( 'name' => $name );
351 ApiResult::setContent( $indicator, $content );
352 $result_array['indicators'][] = $indicator;
353 }
354 }
355
356 if ( isset( $prop['iwlinks'] ) ) {
357 $result_array['iwlinks'] = $this->formatIWLinks( $p_result->getInterwikiLinks() );
358 }
359
360 if ( isset( $prop['wikitext'] ) ) {
361 $result_array['wikitext'] = array();
362 ApiResult::setContent( $result_array['wikitext'], $this->content->serialize( $format ) );
363 if ( !is_null( $this->pstContent ) ) {
364 $result_array['psttext'] = array();
365 ApiResult::setContent( $result_array['psttext'], $this->pstContent->serialize( $format ) );
366 }
367 }
368 if ( isset( $prop['properties'] ) ) {
369 $result_array['properties'] = $this->formatProperties( $p_result->getProperties() );
370 }
371
372 if ( isset( $prop['limitreportdata'] ) ) {
373 $result_array['limitreportdata'] =
374 $this->formatLimitReportData( $p_result->getLimitReportData() );
375 }
376 if ( isset( $prop['limitreporthtml'] ) ) {
377 $limitreportHtml = EditPage::getPreviewLimitReport( $p_result );
378 $result_array['limitreporthtml'] = array();
379 ApiResult::setContent( $result_array['limitreporthtml'], $limitreportHtml );
380 }
381
382 if ( $params['generatexml'] ) {
383 if ( $this->content->getModel() != CONTENT_MODEL_WIKITEXT ) {
384 $this->dieUsage( "generatexml is only supported for wikitext content", "notwikitext" );
385 }
386
387 $wgParser->startExternalParse( $titleObj, $popts, Parser::OT_PREPROCESS );
388 $dom = $wgParser->preprocessToDom( $this->content->getNativeData() );
389 if ( is_callable( array( $dom, 'saveXML' ) ) ) {
390 $xml = $dom->saveXML();
391 } else {
392 $xml = $dom->__toString();
393 }
394 $result_array['parsetree'] = array();
395 ApiResult::setContent( $result_array['parsetree'], $xml );
396 }
397
398 $result_mapping = array(
399 'redirects' => 'r',
400 'langlinks' => 'll',
401 'categories' => 'cl',
402 'links' => 'pl',
403 'templates' => 'tl',
404 'images' => 'img',
405 'externallinks' => 'el',
406 'iwlinks' => 'iw',
407 'sections' => 's',
408 'headitems' => 'hi',
409 'modules' => 'm',
410 'indicators' => 'ind',
411 'modulescripts' => 'm',
412 'modulestyles' => 'm',
413 'modulemessages' => 'm',
414 'properties' => 'pp',
415 'limitreportdata' => 'lr',
416 );
417 $this->setIndexedTagNames( $result_array, $result_mapping );
418 $result->addValue( null, $this->getModuleName(), $result_array );
419 }
420
421 /**
422 * Constructs a ParserOptions object
423 *
424 * @param WikiPage $pageObj
425 * @param array $params
426 *
427 * @return ParserOptions
428 */
429 protected function makeParserOptions( WikiPage $pageObj, array $params ) {
430
431 $popts = $pageObj->makeParserOptions( $this->getContext() );
432 $popts->enableLimitReport( !$params['disablepp'] );
433 $popts->setIsPreview( $params['preview'] || $params['sectionpreview'] );
434 $popts->setIsSectionPreview( $params['sectionpreview'] );
435 $popts->setEditSection( !$params['disableeditsection'] );
436
437 return $popts;
438 }
439
440 /**
441 * @param WikiPage $page
442 * @param ParserOptions $popts
443 * @param int $pageId
444 * @param bool $getWikitext
445 * @return ParserOutput
446 */
447 private function getParsedContent( WikiPage $page, $popts, $pageId = null, $getWikitext = false ) {
448 $this->content = $page->getContent( Revision::RAW ); //XXX: really raw?
449
450 if ( $this->section !== false && $this->content !== null ) {
451 $this->content = $this->getSectionContent(
452 $this->content,
453 !is_null( $pageId ) ? 'page id ' . $pageId : $page->getTitle()->getPrefixedText()
454 );
455
456 // Not cached (save or load)
457 return $this->content->getParserOutput( $page->getTitle(), null, $popts );
458 }
459
460 // Try the parser cache first
461 // getParserOutput will save to Parser cache if able
462 $pout = $page->getParserOutput( $popts );
463 if ( !$pout ) {
464 $this->dieUsage( "There is no revision ID {$page->getLatest()}", 'missingrev' );
465 }
466 if ( $getWikitext ) {
467 $this->content = $page->getContent( Revision::RAW );
468 }
469
470 return $pout;
471 }
472
473 /**
474 * @param Content $content
475 * @param string $what Identifies the content in error messages, e.g. page title.
476 * @return Content|bool
477 */
478 private function getSectionContent( Content $content, $what ) {
479 // Not cached (save or load)
480 $section = $content->getSection( $this->section );
481 if ( $section === false ) {
482 $this->dieUsage( "There is no section {$this->section} in " . $what, 'nosuchsection' );
483 }
484 if ( $section === null ) {
485 $this->dieUsage( "Sections are not supported by " . $what, 'nosuchsection' );
486 $section = false;
487 }
488
489 return $section;
490 }
491
492 private function formatLangLinks( $links ) {
493 $result = array();
494 foreach ( $links as $link ) {
495 $entry = array();
496 $bits = explode( ':', $link, 2 );
497 $title = Title::newFromText( $link );
498
499 $entry['lang'] = $bits[0];
500 if ( $title ) {
501 $entry['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
502 // localised language name in 'uselang' language
503 $entry['langname'] = Language::fetchLanguageName(
504 $title->getInterwiki(),
505 $this->getLanguage()->getCode()
506 );
507
508 // native language name
509 $entry['autonym'] = Language::fetchLanguageName( $title->getInterwiki() );
510 }
511 ApiResult::setContent( $entry, $bits[1] );
512 $result[] = $entry;
513 }
514
515 return $result;
516 }
517
518 private function formatCategoryLinks( $links ) {
519 $result = array();
520
521 if ( !$links ) {
522 return $result;
523 }
524
525 // Fetch hiddencat property
526 $lb = new LinkBatch;
527 $lb->setArray( array( NS_CATEGORY => $links ) );
528 $db = $this->getDB();
529 $res = $db->select( array( 'page', 'page_props' ),
530 array( 'page_title', 'pp_propname' ),
531 $lb->constructSet( 'page', $db ),
532 __METHOD__,
533 array(),
534 array( 'page_props' => array(
535 'LEFT JOIN', array( 'pp_propname' => 'hiddencat', 'pp_page = page_id' )
536 ) )
537 );
538 $hiddencats = array();
539 foreach ( $res as $row ) {
540 $hiddencats[$row->page_title] = isset( $row->pp_propname );
541 }
542
543 foreach ( $links as $link => $sortkey ) {
544 $entry = array();
545 $entry['sortkey'] = $sortkey;
546 ApiResult::setContent( $entry, $link );
547 if ( !isset( $hiddencats[$link] ) ) {
548 $entry['missing'] = '';
549 } elseif ( $hiddencats[$link] ) {
550 $entry['hidden'] = '';
551 }
552 $result[] = $entry;
553 }
554
555 return $result;
556 }
557
558 private function categoriesHtml( $categories ) {
559 $context = $this->getContext();
560 $context->getOutput()->addCategoryLinks( $categories );
561
562 return $context->getSkin()->getCategories();
563 }
564
565 private function formatLinks( $links ) {
566 $result = array();
567 foreach ( $links as $ns => $nslinks ) {
568 foreach ( $nslinks as $title => $id ) {
569 $entry = array();
570 $entry['ns'] = $ns;
571 ApiResult::setContent( $entry, Title::makeTitle( $ns, $title )->getFullText() );
572 if ( $id != 0 ) {
573 $entry['exists'] = '';
574 }
575 $result[] = $entry;
576 }
577 }
578
579 return $result;
580 }
581
582 private function formatIWLinks( $iw ) {
583 $result = array();
584 foreach ( $iw as $prefix => $titles ) {
585 foreach ( array_keys( $titles ) as $title ) {
586 $entry = array();
587 $entry['prefix'] = $prefix;
588
589 $title = Title::newFromText( "{$prefix}:{$title}" );
590 if ( $title ) {
591 $entry['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
592 }
593
594 ApiResult::setContent( $entry, $title->getFullText() );
595 $result[] = $entry;
596 }
597 }
598
599 return $result;
600 }
601
602 private function formatHeadItems( $headItems ) {
603 $result = array();
604 foreach ( $headItems as $tag => $content ) {
605 $entry = array();
606 $entry['tag'] = $tag;
607 ApiResult::setContent( $entry, $content );
608 $result[] = $entry;
609 }
610
611 return $result;
612 }
613
614 private function formatProperties( $properties ) {
615 $result = array();
616 foreach ( $properties as $name => $value ) {
617 $entry = array();
618 $entry['name'] = $name;
619 ApiResult::setContent( $entry, $value );
620 $result[] = $entry;
621 }
622
623 return $result;
624 }
625
626 private function formatCss( $css ) {
627 $result = array();
628 foreach ( $css as $file => $link ) {
629 $entry = array();
630 $entry['file'] = $file;
631 ApiResult::setContent( $entry, $link );
632 $result[] = $entry;
633 }
634
635 return $result;
636 }
637
638 private function formatLimitReportData( $limitReportData ) {
639 $result = array();
640 $apiResult = $this->getResult();
641
642 foreach ( $limitReportData as $name => $value ) {
643 $entry = array();
644 $entry['name'] = $name;
645 if ( !is_array( $value ) ) {
646 $value = array( $value );
647 }
648 $apiResult->setIndexedTagName( $value, 'param' );
649 $apiResult->setIndexedTagName_recursive( $value, 'param' );
650 $entry = array_merge( $entry, $value );
651 $result[] = $entry;
652 }
653
654 return $result;
655 }
656
657 private function setIndexedTagNames( &$array, $mapping ) {
658 foreach ( $mapping as $key => $name ) {
659 if ( isset( $array[$key] ) ) {
660 $this->getResult()->setIndexedTagName( $array[$key], $name );
661 }
662 }
663 }
664
665 public function getAllowedParams() {
666 return array(
667 'title' => null,
668 'text' => null,
669 'summary' => null,
670 'page' => null,
671 'pageid' => array(
672 ApiBase::PARAM_TYPE => 'integer',
673 ),
674 'redirects' => false,
675 'oldid' => array(
676 ApiBase::PARAM_TYPE => 'integer',
677 ),
678 'prop' => array(
679 ApiBase::PARAM_DFLT => 'text|langlinks|categories|links|templates|' .
680 'images|externallinks|sections|revid|displaytitle|iwlinks|properties',
681 ApiBase::PARAM_ISMULTI => true,
682 ApiBase::PARAM_TYPE => array(
683 'text',
684 'langlinks',
685 'categories',
686 'categorieshtml',
687 'links',
688 'templates',
689 'images',
690 'externallinks',
691 'sections',
692 'revid',
693 'displaytitle',
694 'headitems',
695 'headhtml',
696 'modules',
697 'indicators',
698 'iwlinks',
699 'wikitext',
700 'properties',
701 'limitreportdata',
702 'limitreporthtml',
703 )
704 ),
705 'pst' => false,
706 'onlypst' => false,
707 'effectivelanglinks' => false,
708 'section' => null,
709 'disablepp' => false,
710 'disableeditsection' => false,
711 'generatexml' => array(
712 ApiBase::PARAM_DFLT => false,
713 ApiBase::PARAM_HELP_MSG => array(
714 'apihelp-parse-param-generatexml', CONTENT_MODEL_WIKITEXT
715 ),
716 ),
717 'preview' => false,
718 'sectionpreview' => false,
719 'disabletoc' => false,
720 'contentformat' => array(
721 ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(),
722 ),
723 'contentmodel' => array(
724 ApiBase::PARAM_TYPE => ContentHandler::getContentModels(),
725 )
726 );
727 }
728
729 protected function getExamplesMessages() {
730 return array(
731 'action=parse&page=Project:Sandbox'
732 => 'apihelp-parse-example-page',
733 'action=parse&text={{Project:Sandbox}}&contentmodel=wikitext'
734 => 'apihelp-parse-example-text',
735 'action=parse&text={{PAGENAME}}&title=Test'
736 => 'apihelp-parse-example-texttitle',
737 'action=parse&summary=Some+[[link]]&prop='
738 => 'apihelp-parse-example-summary',
739 );
740 }
741
742 public function getHelpUrls() {
743 return 'https://www.mediawiki.org/wiki/API:Parsing_wikitext#parse';
744 }
745 }