Merge "Remove unused variable in ProfilerMwprof"
[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 $result->addValue( null, $this->getModuleName(), $result_array );
222
223 return;
224 }
225
226 // Not cached (save or load)
227 if ( $params['pst'] ) {
228 $p_result = $this->pstContent->getParserOutput( $titleObj, null, $popts );
229 } else {
230 $p_result = $this->content->getParserOutput( $titleObj, null, $popts );
231 }
232 }
233
234 $result_array = array();
235
236 $result_array['title'] = $titleObj->getPrefixedText();
237
238 if ( !is_null( $oldid ) ) {
239 $result_array['revid'] = intval( $oldid );
240 }
241
242 if ( $params['redirects'] && !is_null( $redirValues ) ) {
243 $result_array['redirects'] = $redirValues;
244 }
245
246 if ( $params['disabletoc'] ) {
247 $p_result->setTOCEnabled( false );
248 }
249
250 if ( isset( $prop['text'] ) ) {
251 $result_array['text'] = array();
252 ApiResult::setContent( $result_array['text'], $p_result->getText() );
253 }
254
255 if ( !is_null( $params['summary'] ) ) {
256 $result_array['parsedsummary'] = array();
257 ApiResult::setContent(
258 $result_array['parsedsummary'],
259 Linker::formatComment( $params['summary'], $titleObj )
260 );
261 }
262
263 if ( isset( $prop['langlinks'] ) ) {
264 $langlinks = $p_result->getLanguageLinks();
265
266 if ( $params['effectivelanglinks'] ) {
267 // Link flags are ignored for now, but may in the future be
268 // included in the result.
269 $linkFlags = array();
270 wfRunHooks( 'LanguageLinks', array( $titleObj, &$langlinks, &$linkFlags ) );
271 }
272 } else {
273 $langlinks = false;
274 }
275
276 if ( isset( $prop['langlinks'] ) ) {
277 $result_array['langlinks'] = $this->formatLangLinks( $langlinks );
278 }
279 if ( isset( $prop['categories'] ) ) {
280 $result_array['categories'] = $this->formatCategoryLinks( $p_result->getCategories() );
281 }
282 if ( isset( $prop['categorieshtml'] ) ) {
283 $categoriesHtml = $this->categoriesHtml( $p_result->getCategories() );
284 $result_array['categorieshtml'] = array();
285 ApiResult::setContent( $result_array['categorieshtml'], $categoriesHtml );
286 }
287 if ( isset( $prop['links'] ) ) {
288 $result_array['links'] = $this->formatLinks( $p_result->getLinks() );
289 }
290 if ( isset( $prop['templates'] ) ) {
291 $result_array['templates'] = $this->formatLinks( $p_result->getTemplates() );
292 }
293 if ( isset( $prop['images'] ) ) {
294 $result_array['images'] = array_keys( $p_result->getImages() );
295 }
296 if ( isset( $prop['externallinks'] ) ) {
297 $result_array['externallinks'] = array_keys( $p_result->getExternalLinks() );
298 }
299 if ( isset( $prop['sections'] ) ) {
300 $result_array['sections'] = $p_result->getSections();
301 }
302
303 if ( isset( $prop['displaytitle'] ) ) {
304 $result_array['displaytitle'] = $p_result->getDisplayTitle() ?
305 $p_result->getDisplayTitle() :
306 $titleObj->getPrefixedText();
307 }
308
309 if ( isset( $prop['headitems'] ) || isset( $prop['headhtml'] ) ) {
310 $context = $this->getContext();
311 $context->setTitle( $titleObj );
312 $context->getOutput()->addParserOutputMetadata( $p_result );
313
314 if ( isset( $prop['headitems'] ) ) {
315 $headItems = $this->formatHeadItems( $p_result->getHeadItems() );
316
317 $css = $this->formatCss( $context->getOutput()->buildCssLinksArray() );
318
319 $scripts = array( $context->getOutput()->getHeadScripts() );
320
321 $result_array['headitems'] = array_merge( $headItems, $css, $scripts );
322 }
323
324 if ( isset( $prop['headhtml'] ) ) {
325 $result_array['headhtml'] = array();
326 ApiResult::setContent(
327 $result_array['headhtml'],
328 $context->getOutput()->headElement( $context->getSkin() )
329 );
330 }
331 }
332
333 if ( isset( $prop['modules'] ) ) {
334 $result_array['modules'] = array_values( array_unique( $p_result->getModules() ) );
335 $result_array['modulescripts'] = array_values( array_unique( $p_result->getModuleScripts() ) );
336 $result_array['modulestyles'] = array_values( array_unique( $p_result->getModuleStyles() ) );
337 $result_array['modulemessages'] = array_values( array_unique( $p_result->getModuleMessages() ) );
338 }
339
340 if ( isset( $prop['indicators'] ) ) {
341 foreach ( $p_result->getIndicators() as $name => $content ) {
342 $indicator = array( 'name' => $name );
343 ApiResult::setContent( $indicator, $content );
344 $result_array['indicators'][] = $indicator;
345 }
346 }
347
348 if ( isset( $prop['iwlinks'] ) ) {
349 $result_array['iwlinks'] = $this->formatIWLinks( $p_result->getInterwikiLinks() );
350 }
351
352 if ( isset( $prop['wikitext'] ) ) {
353 $result_array['wikitext'] = array();
354 ApiResult::setContent( $result_array['wikitext'], $this->content->serialize( $format ) );
355 if ( !is_null( $this->pstContent ) ) {
356 $result_array['psttext'] = array();
357 ApiResult::setContent( $result_array['psttext'], $this->pstContent->serialize( $format ) );
358 }
359 }
360 if ( isset( $prop['properties'] ) ) {
361 $result_array['properties'] = $this->formatProperties( $p_result->getProperties() );
362 }
363
364 if ( isset( $prop['limitreportdata'] ) ) {
365 $result_array['limitreportdata'] =
366 $this->formatLimitReportData( $p_result->getLimitReportData() );
367 }
368 if ( isset( $prop['limitreporthtml'] ) ) {
369 $limitreportHtml = EditPage::getPreviewLimitReport( $p_result );
370 $result_array['limitreporthtml'] = array();
371 ApiResult::setContent( $result_array['limitreporthtml'], $limitreportHtml );
372 }
373
374 if ( $params['generatexml'] ) {
375 if ( $this->content->getModel() != CONTENT_MODEL_WIKITEXT ) {
376 $this->dieUsage( "generatexml is only supported for wikitext content", "notwikitext" );
377 }
378
379 $wgParser->startExternalParse( $titleObj, $popts, OT_PREPROCESS );
380 $dom = $wgParser->preprocessToDom( $this->content->getNativeData() );
381 if ( is_callable( array( $dom, 'saveXML' ) ) ) {
382 $xml = $dom->saveXML();
383 } else {
384 $xml = $dom->__toString();
385 }
386 $result_array['parsetree'] = array();
387 ApiResult::setContent( $result_array['parsetree'], $xml );
388 }
389
390 $result_mapping = array(
391 'redirects' => 'r',
392 'langlinks' => 'll',
393 'categories' => 'cl',
394 'links' => 'pl',
395 'templates' => 'tl',
396 'images' => 'img',
397 'externallinks' => 'el',
398 'iwlinks' => 'iw',
399 'sections' => 's',
400 'headitems' => 'hi',
401 'modules' => 'm',
402 'indicators' => 'ind',
403 'modulescripts' => 'm',
404 'modulestyles' => 'm',
405 'modulemessages' => 'm',
406 'properties' => 'pp',
407 'limitreportdata' => 'lr',
408 );
409 $this->setIndexedTagNames( $result_array, $result_mapping );
410 $result->addValue( null, $this->getModuleName(), $result_array );
411 }
412
413 /**
414 * Constructs a ParserOptions object
415 *
416 * @param WikiPage $pageObj
417 * @param array $params
418 *
419 * @return ParserOptions
420 */
421 protected function makeParserOptions( WikiPage $pageObj, array $params ) {
422 wfProfileIn( __METHOD__ );
423
424 $popts = $pageObj->makeParserOptions( $this->getContext() );
425 $popts->enableLimitReport( !$params['disablepp'] );
426 $popts->setIsPreview( $params['preview'] || $params['sectionpreview'] );
427 $popts->setIsSectionPreview( $params['sectionpreview'] );
428 $popts->setEditSection( !$params['disableeditsection'] );
429
430 wfProfileOut( __METHOD__ );
431
432 return $popts;
433 }
434
435 /**
436 * @param WikiPage $page
437 * @param ParserOptions $popts
438 * @param int $pageId
439 * @param bool $getWikitext
440 * @return ParserOutput
441 */
442 private function getParsedContent( WikiPage $page, $popts, $pageId = null, $getWikitext = false ) {
443 $this->content = $page->getContent( Revision::RAW ); //XXX: really raw?
444
445 if ( $this->section !== false && $this->content !== null ) {
446 $this->content = $this->getSectionContent(
447 $this->content,
448 !is_null( $pageId ) ? 'page id ' . $pageId : $page->getTitle()->getPrefixedText()
449 );
450
451 // Not cached (save or load)
452 return $this->content->getParserOutput( $page->getTitle(), null, $popts );
453 }
454
455 // Try the parser cache first
456 // getParserOutput will save to Parser cache if able
457 $pout = $page->getParserOutput( $popts );
458 if ( !$pout ) {
459 $this->dieUsage( "There is no revision ID {$page->getLatest()}", 'missingrev' );
460 }
461 if ( $getWikitext ) {
462 $this->content = $page->getContent( Revision::RAW );
463 }
464
465 return $pout;
466 }
467
468 /**
469 * @param Content $content
470 * @param string $what Identifies the content in error messages, e.g. page title.
471 * @return Content|bool
472 */
473 private function getSectionContent( Content $content, $what ) {
474 // Not cached (save or load)
475 $section = $content->getSection( $this->section );
476 if ( $section === false ) {
477 $this->dieUsage( "There is no section {$this->section} in " . $what, 'nosuchsection' );
478 }
479 if ( $section === null ) {
480 $this->dieUsage( "Sections are not supported by " . $what, 'nosuchsection' );
481 $section = false;
482 }
483
484 return $section;
485 }
486
487 private function formatLangLinks( $links ) {
488 $result = array();
489 foreach ( $links as $link ) {
490 $entry = array();
491 $bits = explode( ':', $link, 2 );
492 $title = Title::newFromText( $link );
493
494 $entry['lang'] = $bits[0];
495 if ( $title ) {
496 $entry['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
497 // localised language name in 'uselang' language
498 $entry['langname'] = Language::fetchLanguageName(
499 $title->getInterwiki(),
500 $this->getLanguage()->getCode()
501 );
502
503 // native language name
504 $entry['autonym'] = Language::fetchLanguageName( $title->getInterwiki() );
505 }
506 ApiResult::setContent( $entry, $bits[1] );
507 $result[] = $entry;
508 }
509
510 return $result;
511 }
512
513 private function formatCategoryLinks( $links ) {
514 $result = array();
515
516 if ( !$links ) {
517 return $result;
518 }
519
520 // Fetch hiddencat property
521 $lb = new LinkBatch;
522 $lb->setArray( array( NS_CATEGORY => $links ) );
523 $db = $this->getDB();
524 $res = $db->select( array( 'page', 'page_props' ),
525 array( 'page_title', 'pp_propname' ),
526 $lb->constructSet( 'page', $db ),
527 __METHOD__,
528 array(),
529 array( 'page_props' => array(
530 'LEFT JOIN', array( 'pp_propname' => 'hiddencat', 'pp_page = page_id' )
531 ) )
532 );
533 $hiddencats = array();
534 foreach ( $res as $row ) {
535 $hiddencats[$row->page_title] = isset( $row->pp_propname );
536 }
537
538 foreach ( $links as $link => $sortkey ) {
539 $entry = array();
540 $entry['sortkey'] = $sortkey;
541 ApiResult::setContent( $entry, $link );
542 if ( !isset( $hiddencats[$link] ) ) {
543 $entry['missing'] = '';
544 } elseif ( $hiddencats[$link] ) {
545 $entry['hidden'] = '';
546 }
547 $result[] = $entry;
548 }
549
550 return $result;
551 }
552
553 private function categoriesHtml( $categories ) {
554 $context = $this->getContext();
555 $context->getOutput()->addCategoryLinks( $categories );
556
557 return $context->getSkin()->getCategories();
558 }
559
560 private function formatLinks( $links ) {
561 $result = array();
562 foreach ( $links as $ns => $nslinks ) {
563 foreach ( $nslinks as $title => $id ) {
564 $entry = array();
565 $entry['ns'] = $ns;
566 ApiResult::setContent( $entry, Title::makeTitle( $ns, $title )->getFullText() );
567 if ( $id != 0 ) {
568 $entry['exists'] = '';
569 }
570 $result[] = $entry;
571 }
572 }
573
574 return $result;
575 }
576
577 private function formatIWLinks( $iw ) {
578 $result = array();
579 foreach ( $iw as $prefix => $titles ) {
580 foreach ( array_keys( $titles ) as $title ) {
581 $entry = array();
582 $entry['prefix'] = $prefix;
583
584 $title = Title::newFromText( "{$prefix}:{$title}" );
585 if ( $title ) {
586 $entry['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
587 }
588
589 ApiResult::setContent( $entry, $title->getFullText() );
590 $result[] = $entry;
591 }
592 }
593
594 return $result;
595 }
596
597 private function formatHeadItems( $headItems ) {
598 $result = array();
599 foreach ( $headItems as $tag => $content ) {
600 $entry = array();
601 $entry['tag'] = $tag;
602 ApiResult::setContent( $entry, $content );
603 $result[] = $entry;
604 }
605
606 return $result;
607 }
608
609 private function formatProperties( $properties ) {
610 $result = array();
611 foreach ( $properties as $name => $value ) {
612 $entry = array();
613 $entry['name'] = $name;
614 ApiResult::setContent( $entry, $value );
615 $result[] = $entry;
616 }
617
618 return $result;
619 }
620
621 private function formatCss( $css ) {
622 $result = array();
623 foreach ( $css as $file => $link ) {
624 $entry = array();
625 $entry['file'] = $file;
626 ApiResult::setContent( $entry, $link );
627 $result[] = $entry;
628 }
629
630 return $result;
631 }
632
633 private function formatLimitReportData( $limitReportData ) {
634 $result = array();
635 $apiResult = $this->getResult();
636
637 foreach ( $limitReportData as $name => $value ) {
638 $entry = array();
639 $entry['name'] = $name;
640 if ( !is_array( $value ) ) {
641 $value = array( $value );
642 }
643 $apiResult->setIndexedTagName( $value, 'param' );
644 $apiResult->setIndexedTagName_recursive( $value, 'param' );
645 $entry = array_merge( $entry, $value );
646 $result[] = $entry;
647 }
648
649 return $result;
650 }
651
652 private function setIndexedTagNames( &$array, $mapping ) {
653 foreach ( $mapping as $key => $name ) {
654 if ( isset( $array[$key] ) ) {
655 $this->getResult()->setIndexedTagName( $array[$key], $name );
656 }
657 }
658 }
659
660 public function getAllowedParams() {
661 return array(
662 'title' => null,
663 'text' => null,
664 'summary' => null,
665 'page' => null,
666 'pageid' => array(
667 ApiBase::PARAM_TYPE => 'integer',
668 ),
669 'redirects' => false,
670 'oldid' => array(
671 ApiBase::PARAM_TYPE => 'integer',
672 ),
673 'prop' => array(
674 ApiBase::PARAM_DFLT => 'text|langlinks|categories|links|templates|' .
675 'images|externallinks|sections|revid|displaytitle|iwlinks|properties',
676 ApiBase::PARAM_ISMULTI => true,
677 ApiBase::PARAM_TYPE => array(
678 'text',
679 'langlinks',
680 'categories',
681 'categorieshtml',
682 'links',
683 'templates',
684 'images',
685 'externallinks',
686 'sections',
687 'revid',
688 'displaytitle',
689 'headitems',
690 'headhtml',
691 'modules',
692 'indicators',
693 'iwlinks',
694 'wikitext',
695 'properties',
696 'limitreportdata',
697 'limitreporthtml',
698 )
699 ),
700 'pst' => false,
701 'onlypst' => false,
702 'effectivelanglinks' => false,
703 'section' => null,
704 'disablepp' => false,
705 'disableeditsection' => false,
706 'generatexml' => array(
707 ApiBase::PARAM_DFLT => false,
708 ApiBase::PARAM_HELP_MSG => array(
709 'apihelp-parse-param-generatexml', CONTENT_MODEL_WIKITEXT
710 ),
711 ),
712 'preview' => false,
713 'sectionpreview' => false,
714 'disabletoc' => false,
715 'contentformat' => array(
716 ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(),
717 ),
718 'contentmodel' => array(
719 ApiBase::PARAM_TYPE => ContentHandler::getContentModels(),
720 )
721 );
722 }
723
724 public function getExamplesMessages() {
725 return array(
726 'action=parse&page=Project:Sandbox'
727 => 'apihelp-parse-example-page',
728 'action=parse&text={{Project:Sandbox}}&contentmodel=wikitext'
729 => 'apihelp-parse-example-text',
730 'action=parse&text={{PAGENAME}}&title=Test'
731 => 'apihelp-parse-example-texttitle',
732 'action=parse&summary=Some+[[link]]&prop='
733 => 'apihelp-parse-example-summary',
734 );
735 }
736
737 public function getHelpUrls() {
738 return 'https://www.mediawiki.org/wiki/API:Parsing_wikitext#parse';
739 }
740 }