Merge "swap enhanced watchlist/RC arrow images for prettier ones"
[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 $page = $params['page'];
48 $pageid = $params['pageid'];
49 $oldid = $params['oldid'];
50
51 $model = $params['contentmodel'];
52 $format = $params['contentformat'];
53
54 if ( !is_null( $page ) && ( !is_null( $text ) || $title != 'API' ) ) {
55 $this->dieUsage( 'The page parameter cannot be used together with the text and title parameters', 'params' );
56 }
57
58 $prop = array_flip( $params['prop'] );
59
60 if ( isset( $params['section'] ) ) {
61 $this->section = $params['section'];
62 } else {
63 $this->section = false;
64 }
65
66 // The parser needs $wgTitle to be set, apparently the
67 // $title parameter in Parser::parse isn't enough *sigh*
68 // TODO: Does this still need $wgTitle?
69 global $wgParser, $wgTitle;
70
71 // Currently unnecessary, code to act as a safeguard against any change in current behavior of uselang
72 $oldLang = null;
73 if ( isset( $params['uselang'] ) && $params['uselang'] != $this->getContext()->getLanguage()->getCode() ) {
74 $oldLang = $this->getContext()->getLanguage(); // Backup language
75 $this->getContext()->setLanguage( Language::factory( $params['uselang'] ) );
76 }
77
78 $redirValues = null;
79
80 // Return result
81 $result = $this->getResult();
82
83 if ( !is_null( $oldid ) || !is_null( $pageid ) || !is_null( $page ) ) {
84 if ( !is_null( $oldid ) ) {
85 // Don't use the parser cache
86 $rev = Revision::newFromID( $oldid );
87 if ( !$rev ) {
88 $this->dieUsage( "There is no revision ID $oldid", 'missingrev' );
89 }
90 if ( !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
91 $this->dieUsage( "You don't have permission to view deleted revisions", 'permissiondenied' );
92 }
93
94 $titleObj = $rev->getTitle();
95 $wgTitle = $titleObj;
96 $pageObj = WikiPage::factory( $titleObj );
97 $popts = $pageObj->makeParserOptions( $this->getContext() );
98 $popts->enableLimitReport( !$params['disablepp'] );
99
100 // If for some reason the "oldid" is actually the current revision, it may be cached
101 if ( $rev->isCurrent() ) {
102 // May get from/save to parser cache
103 $p_result = $this->getParsedContent( $pageObj, $popts,
104 $pageid, isset( $prop['wikitext'] ) );
105 } else { // This is an old revision, so get the text differently
106 $this->content = $rev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
107
108 if ( $this->section !== false ) {
109 $this->content = $this->getSectionContent( $this->content, 'r' . $rev->getId() );
110 }
111
112 // Should we save old revision parses to the parser cache?
113 $p_result = $this->content->getParserOutput( $titleObj, $rev->getId(), $popts );
114 }
115 } else { // Not $oldid, but $pageid or $page
116 if ( $params['redirects'] ) {
117 $reqParams = array(
118 'action' => 'query',
119 'redirects' => '',
120 );
121 if ( !is_null ( $pageid ) ) {
122 $reqParams['pageids'] = $pageid;
123 } else { // $page
124 $reqParams['titles'] = $page;
125 }
126 $req = new FauxRequest( $reqParams );
127 $main = new ApiMain( $req );
128 $main->execute();
129 $data = $main->getResultData();
130 $redirValues = isset( $data['query']['redirects'] )
131 ? $data['query']['redirects']
132 : array();
133 $to = $page;
134 foreach ( (array)$redirValues as $r ) {
135 $to = $r['to'];
136 }
137 $pageParams = array( 'title' => $to );
138 } elseif ( !is_null( $pageid ) ) {
139 $pageParams = array( 'pageid' => $pageid );
140 } else { // $page
141 $pageParams = array( 'title' => $page );
142 }
143
144 $pageObj = $this->getTitleOrPageId( $pageParams, 'fromdb' );
145 $titleObj = $pageObj->getTitle();
146 if ( !$titleObj || !$titleObj->exists() ) {
147 $this->dieUsage( "The page you specified doesn't exist", 'missingtitle' );
148 }
149 $wgTitle = $titleObj;
150
151 if ( isset( $prop['revid'] ) ) {
152 $oldid = $pageObj->getLatest();
153 }
154
155 $popts = $pageObj->makeParserOptions( $this->getContext() );
156 $popts->enableLimitReport( !$params['disablepp'] );
157
158 // Potentially cached
159 $p_result = $this->getParsedContent( $pageObj, $popts, $pageid,
160 isset( $prop['wikitext'] ) );
161 }
162 } else { // Not $oldid, $pageid, $page. Hence based on $text
163 $titleObj = Title::newFromText( $title );
164 if ( !$titleObj || $titleObj->isExternal() ) {
165 $this->dieUsageMsg( array( 'invalidtitle', $title ) );
166 }
167 if ( !$titleObj->canExist() ) {
168 $this->dieUsage( "Namespace doesn't allow actual pages", 'pagecannotexist' );
169 }
170 $wgTitle = $titleObj;
171 $pageObj = WikiPage::factory( $titleObj );
172
173 $popts = $pageObj->makeParserOptions( $this->getContext() );
174 $popts->enableLimitReport( !$params['disablepp'] );
175
176 if ( is_null( $text ) ) {
177 $this->dieUsage( 'The text parameter should be passed with the title parameter. Should you be using the "page" parameter instead?', 'params' );
178 }
179
180 try {
181 $this->content = ContentHandler::makeContent( $text, $titleObj, $model, $format );
182 } catch ( MWContentSerializationException $ex ) {
183 $this->dieUsage( $ex->getMessage(), 'parseerror' );
184 }
185
186 if ( $this->section !== false ) {
187 $this->content = $this->getSectionContent( $this->content, $titleObj->getText() );
188 }
189
190 if ( $params['pst'] || $params['onlypst'] ) {
191 $this->pstContent = $this->content->preSaveTransform( $titleObj, $this->getUser(), $popts );
192 }
193 if ( $params['onlypst'] ) {
194 // Build a result and bail out
195 $result_array = array();
196 $result_array['text'] = array();
197 ApiResult::setContent( $result_array['text'], $this->pstContent->serialize( $format ) );
198 if ( isset( $prop['wikitext'] ) ) {
199 $result_array['wikitext'] = array();
200 ApiResult::setContent( $result_array['wikitext'], $this->content->serialize( $format ) );
201 }
202 $result->addValue( null, $this->getModuleName(), $result_array );
203 return;
204 }
205
206 // Not cached (save or load)
207 if ( $params['pst'] ) {
208 $p_result = $this->pstContent->getParserOutput( $titleObj, null, $popts );
209 } else {
210 $p_result = $this->content->getParserOutput( $titleObj, null, $popts );
211 }
212 }
213
214 $result_array = array();
215
216 $result_array['title'] = $titleObj->getPrefixedText();
217
218 if ( !is_null( $oldid ) ) {
219 $result_array['revid'] = intval( $oldid );
220 }
221
222 if ( $params['redirects'] && !is_null( $redirValues ) ) {
223 $result_array['redirects'] = $redirValues;
224 }
225
226 if ( isset( $prop['text'] ) ) {
227 $result_array['text'] = array();
228 ApiResult::setContent( $result_array['text'], $p_result->getText() );
229 }
230
231 if ( !is_null( $params['summary'] ) ) {
232 $result_array['parsedsummary'] = array();
233 ApiResult::setContent( $result_array['parsedsummary'], Linker::formatComment( $params['summary'], $titleObj ) );
234 }
235
236 if ( isset( $prop['langlinks'] ) || isset( $prop['languageshtml'] ) ) {
237 $langlinks = $p_result->getLanguageLinks();
238
239 if ( $params['effectivelanglinks'] ) {
240 // Link flags are ignored for now, but may in the future be
241 // included in the result.
242 $linkFlags = array();
243 wfRunHooks( 'LanguageLinks', array( $titleObj, &$langlinks, &$linkFlags ) );
244 }
245 } else {
246 $langlinks = false;
247 }
248
249 if ( isset( $prop['langlinks'] ) ) {
250 $result_array['langlinks'] = $this->formatLangLinks( $langlinks );
251 }
252 if ( isset( $prop['languageshtml'] ) ) {
253 $languagesHtml = $this->languagesHtml( $langlinks );
254
255 $result_array['languageshtml'] = array();
256 ApiResult::setContent( $result_array['languageshtml'], $languagesHtml );
257 }
258 if ( isset( $prop['categories'] ) ) {
259 $result_array['categories'] = $this->formatCategoryLinks( $p_result->getCategories() );
260 }
261 if ( isset( $prop['categorieshtml'] ) ) {
262 $categoriesHtml = $this->categoriesHtml( $p_result->getCategories() );
263 $result_array['categorieshtml'] = array();
264 ApiResult::setContent( $result_array['categorieshtml'], $categoriesHtml );
265 }
266 if ( isset( $prop['links'] ) ) {
267 $result_array['links'] = $this->formatLinks( $p_result->getLinks() );
268 }
269 if ( isset( $prop['templates'] ) ) {
270 $result_array['templates'] = $this->formatLinks( $p_result->getTemplates() );
271 }
272 if ( isset( $prop['images'] ) ) {
273 $result_array['images'] = array_keys( $p_result->getImages() );
274 }
275 if ( isset( $prop['externallinks'] ) ) {
276 $result_array['externallinks'] = array_keys( $p_result->getExternalLinks() );
277 }
278 if ( isset( $prop['sections'] ) ) {
279 $result_array['sections'] = $p_result->getSections();
280 }
281
282 if ( isset( $prop['displaytitle'] ) ) {
283 $result_array['displaytitle'] = $p_result->getDisplayTitle() ?
284 $p_result->getDisplayTitle() :
285 $titleObj->getPrefixedText();
286 }
287
288 if ( isset( $prop['headitems'] ) || isset( $prop['headhtml'] ) ) {
289 $context = $this->getContext();
290 $context->setTitle( $titleObj );
291 $context->getOutput()->addParserOutputNoText( $p_result );
292
293 if ( isset( $prop['headitems'] ) ) {
294 $headItems = $this->formatHeadItems( $p_result->getHeadItems() );
295
296 $css = $this->formatCss( $context->getOutput()->buildCssLinksArray() );
297
298 $scripts = array( $context->getOutput()->getHeadScripts() );
299
300 $result_array['headitems'] = array_merge( $headItems, $css, $scripts );
301 }
302
303 if ( isset( $prop['headhtml'] ) ) {
304 $result_array['headhtml'] = array();
305 ApiResult::setContent( $result_array['headhtml'], $context->getOutput()->headElement( $context->getSkin() ) );
306 }
307 }
308
309 if ( isset( $prop['iwlinks'] ) ) {
310 $result_array['iwlinks'] = $this->formatIWLinks( $p_result->getInterwikiLinks() );
311 }
312
313 if ( isset( $prop['wikitext'] ) ) {
314 $result_array['wikitext'] = array();
315 ApiResult::setContent( $result_array['wikitext'], $this->content->serialize( $format ) );
316 if ( !is_null( $this->pstContent ) ) {
317 $result_array['psttext'] = array();
318 ApiResult::setContent( $result_array['psttext'], $this->pstContent->serialize( $format ) );
319 }
320 }
321 if ( isset( $prop['properties'] ) ) {
322 $result_array['properties'] = $this->formatProperties( $p_result->getProperties() );
323 }
324
325 if ( $params['generatexml'] ) {
326 if ( $this->content->getModel() != CONTENT_MODEL_WIKITEXT ) {
327 $this->dieUsage( "generatexml is only supported for wikitext content", "notwikitext" );
328 }
329
330 $wgParser->startExternalParse( $titleObj, $popts, OT_PREPROCESS );
331 $dom = $wgParser->preprocessToDom( $this->content->getNativeData() );
332 if ( is_callable( array( $dom, 'saveXML' ) ) ) {
333 $xml = $dom->saveXML();
334 } else {
335 $xml = $dom->__toString();
336 }
337 $result_array['parsetree'] = array();
338 ApiResult::setContent( $result_array['parsetree'], $xml );
339 }
340
341 $result_mapping = array(
342 'redirects' => 'r',
343 'langlinks' => 'll',
344 'categories' => 'cl',
345 'links' => 'pl',
346 'templates' => 'tl',
347 'images' => 'img',
348 'externallinks' => 'el',
349 'iwlinks' => 'iw',
350 'sections' => 's',
351 'headitems' => 'hi',
352 'properties' => 'pp',
353 );
354 $this->setIndexedTagNames( $result_array, $result_mapping );
355 $result->addValue( null, $this->getModuleName(), $result_array );
356
357 if ( !is_null( $oldLang ) ) {
358 $this->getContext()->setLanguage( $oldLang ); // Reset language to $oldLang
359 }
360 }
361
362 /**
363 * @param $page WikiPage
364 * @param $popts ParserOptions
365 * @param $pageId Int
366 * @param $getWikitext Bool
367 * @return ParserOutput
368 */
369 private function getParsedContent( WikiPage $page, $popts, $pageId = null, $getWikitext = false ) {
370 $this->content = $page->getContent( Revision::RAW ); //XXX: really raw?
371
372 if ( $this->section !== false && $this->content !== null ) {
373 $this->content = $this->getSectionContent(
374 $this->content,
375 !is_null( $pageId ) ? 'page id ' . $pageId : $page->getTitle()->getText() );
376
377 // Not cached (save or load)
378 return $this->content->getParserOutput( $page->getTitle(), null, $popts );
379 } else {
380 // Try the parser cache first
381 // getParserOutput will save to Parser cache if able
382 $pout = $page->getParserOutput( $popts );
383 if ( !$pout ) {
384 $this->dieUsage( "There is no revision ID {$page->getLatest()}", 'missingrev' );
385 }
386 if ( $getWikitext ) {
387 $this->content = $page->getContent( Revision::RAW );
388 }
389 return $pout;
390 }
391 }
392
393 private function getSectionContent( Content $content, $what ) {
394 // Not cached (save or load)
395 $section = $content->getSection( $this->section );
396 if ( $section === false ) {
397 $this->dieUsage( "There is no section {$this->section} in " . $what, 'nosuchsection' );
398 }
399 if ( $section === null ) {
400 $this->dieUsage( "Sections are not supported by " . $what, 'nosuchsection' );
401 $section = false;
402 }
403 return $section;
404 }
405
406 private function formatLangLinks( $links ) {
407 $result = array();
408 foreach ( $links as $link ) {
409 $entry = array();
410 $bits = explode( ':', $link, 2 );
411 $title = Title::newFromText( $link );
412
413 $entry['lang'] = $bits[0];
414 if ( $title ) {
415 $entry['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
416 }
417 ApiResult::setContent( $entry, $bits[1] );
418 $result[] = $entry;
419 }
420 return $result;
421 }
422
423 private function formatCategoryLinks( $links ) {
424 $result = array();
425 foreach ( $links as $link => $sortkey ) {
426 $entry = array();
427 $entry['sortkey'] = $sortkey;
428 ApiResult::setContent( $entry, $link );
429 $result[] = $entry;
430 }
431 return $result;
432 }
433
434 private function categoriesHtml( $categories ) {
435 $context = $this->getContext();
436 $context->getOutput()->addCategoryLinks( $categories );
437 return $context->getSkin()->getCategories();
438 }
439
440 /**
441 * @deprecated since 1.18 No modern skin generates language links this way, please use language links
442 * data to generate your own HTML.
443 * @param $languages array
444 * @return string
445 */
446 private function languagesHtml( $languages ) {
447 wfDeprecated( __METHOD__, '1.18' );
448
449 global $wgContLang, $wgHideInterlanguageLinks;
450
451 if ( $wgHideInterlanguageLinks || count( $languages ) == 0 ) {
452 return '';
453 }
454
455 $s = htmlspecialchars( wfMessage( 'otherlanguages' )->text() . wfMessage( 'colon-separator' )->text() );
456
457 $langs = array();
458 foreach ( $languages as $l ) {
459 $nt = Title::newFromText( $l );
460 $text = Language::fetchLanguageName( $nt->getInterwiki() );
461
462 $langs[] = Html::element( 'a',
463 array( 'href' => $nt->getFullURL(), 'title' => $nt->getText(), 'class' => 'external' ),
464 $text == '' ? $l : $text );
465 }
466
467 $s .= implode( wfMessage( 'pipe-separator' )->escaped(), $langs );
468
469 if ( $wgContLang->isRTL() ) {
470 $s = Html::rawElement( 'span', array( 'dir' => 'LTR' ), $s );
471 }
472
473 return $s;
474 }
475
476 private function formatLinks( $links ) {
477 $result = array();
478 foreach ( $links as $ns => $nslinks ) {
479 foreach ( $nslinks as $title => $id ) {
480 $entry = array();
481 $entry['ns'] = $ns;
482 ApiResult::setContent( $entry, Title::makeTitle( $ns, $title )->getFullText() );
483 if ( $id != 0 ) {
484 $entry['exists'] = '';
485 }
486 $result[] = $entry;
487 }
488 }
489 return $result;
490 }
491
492 private function formatIWLinks( $iw ) {
493 $result = array();
494 foreach ( $iw as $prefix => $titles ) {
495 foreach ( array_keys( $titles ) as $title ) {
496 $entry = array();
497 $entry['prefix'] = $prefix;
498
499 $title = Title::newFromText( "{$prefix}:{$title}" );
500 if ( $title ) {
501 $entry['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
502 }
503
504 ApiResult::setContent( $entry, $title->getFullText() );
505 $result[] = $entry;
506 }
507 }
508 return $result;
509 }
510
511 private function formatHeadItems( $headItems ) {
512 $result = array();
513 foreach ( $headItems as $tag => $content ) {
514 $entry = array();
515 $entry['tag'] = $tag;
516 ApiResult::setContent( $entry, $content );
517 $result[] = $entry;
518 }
519 return $result;
520 }
521
522 private function formatProperties( $properties ) {
523 $result = array();
524 foreach ( $properties as $name => $value ) {
525 $entry = array();
526 $entry['name'] = $name;
527 ApiResult::setContent( $entry, $value );
528 $result[] = $entry;
529 }
530 return $result;
531 }
532
533 private function formatCss( $css ) {
534 $result = array();
535 foreach ( $css as $file => $link ) {
536 $entry = array();
537 $entry['file'] = $file;
538 ApiResult::setContent( $entry, $link );
539 $result[] = $entry;
540 }
541 return $result;
542 }
543
544 private function setIndexedTagNames( &$array, $mapping ) {
545 foreach ( $mapping as $key => $name ) {
546 if ( isset( $array[$key] ) ) {
547 $this->getResult()->setIndexedTagName( $array[$key], $name );
548 }
549 }
550 }
551
552 public function getAllowedParams() {
553 return array(
554 'title' => array(
555 ApiBase::PARAM_DFLT => 'API',
556 ),
557 'text' => null,
558 'summary' => null,
559 'page' => null,
560 'pageid' => array(
561 ApiBase::PARAM_TYPE => 'integer',
562 ),
563 'redirects' => false,
564 'oldid' => array(
565 ApiBase::PARAM_TYPE => 'integer',
566 ),
567 'prop' => array(
568 ApiBase::PARAM_DFLT => 'text|langlinks|categories|links|templates|images|externallinks|sections|revid|displaytitle|iwlinks|properties',
569 ApiBase::PARAM_ISMULTI => true,
570 ApiBase::PARAM_TYPE => array(
571 'text',
572 'langlinks',
573 'languageshtml',
574 'categories',
575 'categorieshtml',
576 'links',
577 'templates',
578 'images',
579 'externallinks',
580 'sections',
581 'revid',
582 'displaytitle',
583 'headitems',
584 'headhtml',
585 'iwlinks',
586 'wikitext',
587 'properties',
588 )
589 ),
590 'pst' => false,
591 'onlypst' => false,
592 'effectivelanglinks' => false,
593 'uselang' => null,
594 'section' => null,
595 'disablepp' => false,
596 'generatexml' => false,
597 'contentformat' => array(
598 ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(),
599 ),
600 'contentmodel' => array(
601 ApiBase::PARAM_TYPE => ContentHandler::getContentModels(),
602 )
603 );
604 }
605
606 public function getParamDescription() {
607 $p = $this->getModulePrefix();
608 return array(
609 'text' => 'Wikitext to parse',
610 'summary' => 'Summary to parse',
611 'redirects' => "If the {$p}page or the {$p}pageid parameter is set to a redirect, resolve it",
612 'title' => 'Title of page the text belongs to',
613 'page' => "Parse the content of this page. Cannot be used together with {$p}text and {$p}title",
614 'pageid' => "Parse the content of this page. Overrides {$p}page",
615 'oldid' => "Parse the content of this revision. Overrides {$p}page and {$p}pageid",
616 'prop' => array(
617 'Which pieces of information to get',
618 ' text - Gives the parsed text of the wikitext',
619 ' langlinks - Gives the language links in the parsed wikitext',
620 ' categories - Gives the categories in the parsed wikitext',
621 ' categorieshtml - Gives the HTML version of the categories',
622 ' languageshtml - Gives the HTML version of the language links',
623 ' links - Gives the internal links in the parsed wikitext',
624 ' templates - Gives the templates in the parsed wikitext',
625 ' images - Gives the images in the parsed wikitext',
626 ' externallinks - Gives the external links in the parsed wikitext',
627 ' sections - Gives the sections in the parsed wikitext',
628 ' revid - Adds the revision ID of the parsed page',
629 ' displaytitle - Adds the title of the parsed wikitext',
630 ' headitems - Gives items to put in the <head> of the page',
631 ' headhtml - Gives parsed <head> of the page',
632 ' iwlinks - Gives interwiki links in the parsed wikitext',
633 ' wikitext - Gives the original wikitext that was parsed',
634 ' properties - Gives various properties defined in the parsed wikitext',
635 ),
636 'effectivelanglinks' => array(
637 'Includes language links supplied by extensions',
638 '(for use with prop=langlinks|languageshtml)',
639 ),
640 'pst' => array(
641 'Do a pre-save transform on the input before parsing it',
642 'Ignored if page, pageid or oldid is used'
643 ),
644 'onlypst' => array(
645 'Do a pre-save transform (PST) on the input, but don\'t parse it',
646 'Returns the same wikitext, after a PST has been applied. Ignored if page, pageid or oldid is used'
647 ),
648 'uselang' => 'Which language to parse the request in',
649 'section' => 'Only retrieve the content of this section number',
650 'disablepp' => 'Disable the PP Report from the parser output',
651 'generatexml' => 'Generate XML parse tree (requires prop=wikitext)',
652 'contentformat' => 'Content serialization format used for the input text',
653 'contentmodel' => 'Content model of the new content',
654 );
655 }
656
657 public function getDescription() {
658 return array(
659 'Parses wikitext and returns parser output',
660 'See the various prop-Modules of action=query to get information from the current version of a page',
661 );
662 }
663
664 public function getPossibleErrors() {
665 return array_merge( parent::getPossibleErrors(), array(
666 array( 'code' => 'params', 'info' => 'The page parameter cannot be used together with the text and title parameters' ),
667 array( 'code' => 'params', 'info' => 'The text parameter should be passed with the title parameter. Should you be using the "page" parameter instead?' ),
668 array( 'code' => 'missingrev', 'info' => 'There is no revision ID oldid' ),
669 array( 'code' => 'permissiondenied', 'info' => 'You don\'t have permission to view deleted revisions' ),
670 array( 'code' => 'missingtitle', 'info' => 'The page you specified doesn\'t exist' ),
671 array( 'code' => 'nosuchsection', 'info' => 'There is no section sectionnumber in page' ),
672 array( 'nosuchpageid' ),
673 array( 'invalidtitle', 'title' ),
674 array( 'code' => 'parseerror', 'info' => 'Failed to parse the given text.' ),
675 array( 'code' => 'notwikitext', 'info' => 'The requested operation is only supported on wikitext content.' ),
676 array( 'code' => 'pagecannotexist', 'info' => "Namespace doesn't allow actual pages" ),
677 ) );
678 }
679
680 public function getExamples() {
681 return array(
682 'api.php?action=parse&text={{Project:Sandbox}}'
683 );
684 }
685
686 public function getHelpUrls() {
687 return 'https://www.mediawiki.org/wiki/API:Parsing_wikitext#parse';
688 }
689 }