[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
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 // Currently unnecessary, code to act as a safeguard against any change 83 // in current behavior of uselang 84 $oldLang = null; 85 if ( isset( $params['uselang'] ) 86 && $params['uselang'] != $this->getContext()->getLanguage()->getCode() 87 ) { 88 $oldLang = $this->getContext()->getLanguage(); // Backup language 89 $this->getContext()->setLanguage( Language::factory( $params['uselang'] ) ); 90 } 91 92 $redirValues = null; 93 94 // Return result 95 $result = $this->getResult(); 96 97 if ( !is_null( $oldid ) || !is_null( $pageid ) || !is_null( $page ) ) { 98 if ( !is_null( $oldid ) ) { 99 // Don't use the parser cache 100 $rev = Revision::newFromID( $oldid ); 101 if ( !$rev ) { 102 $this->dieUsage( "There is no revision ID $oldid", 'missingrev' ); 103 } 104 if ( !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) { 105 $this->dieUsage( "You don't have permission to view deleted revisions", 'permissiondenied' ); 106 } 107 108 $titleObj = $rev->getTitle(); 109 $wgTitle = $titleObj; 110 $pageObj = WikiPage::factory( $titleObj ); 111 $popts = $this->makeParserOptions( $pageObj, $params ); 112 113 // If for some reason the "oldid" is actually the current revision, it may be cached 114 if ( $rev->isCurrent() ) { 115 // May get from/save to parser cache 116 $p_result = $this->getParsedContent( $pageObj, $popts, 117 $pageid, isset( $prop['wikitext'] ) ); 118 } else { // This is an old revision, so get the text differently 119 $this->content = $rev->getContent( Revision::FOR_THIS_USER, $this->getUser() ); 120 121 if ( $this->section !== false ) { 122 $this->content = $this->getSectionContent( $this->content, 'r' . $rev->getId() ); 123 } 124 125 // Should we save old revision parses to the parser cache? 126 $p_result = $this->content->getParserOutput( $titleObj, $rev->getId(), $popts ); 127 } 128 } else { // Not $oldid, but $pageid or $page 129 if ( $params['redirects'] ) { 130 $reqParams = array( 131 'action' => 'query', 132 'redirects' => '', 133 ); 134 if ( !is_null( $pageid ) ) { 135 $reqParams['pageids'] = $pageid; 136 } else { // $page 137 $reqParams['titles'] = $page; 138 } 139 $req = new FauxRequest( $reqParams ); 140 $main = new ApiMain( $req ); 141 $main->execute(); 142 $data = $main->getResultData(); 143 $redirValues = isset( $data['query']['redirects'] ) 144 ? $data['query']['redirects'] 145 : array(); 146 $to = $page; 147 foreach ( (array)$redirValues as $r ) { 148 $to = $r['to']; 149 } 150 $pageParams = array( 'title' => $to ); 151 } elseif ( !is_null( $pageid ) ) { 152 $pageParams = array( 'pageid' => $pageid ); 153 } else { // $page 154 $pageParams = array( 'title' => $page ); 155 } 156 157 $pageObj = $this->getTitleOrPageId( $pageParams, 'fromdb' ); 158 $titleObj = $pageObj->getTitle(); 159 if ( !$titleObj || !$titleObj->exists() ) { 160 $this->dieUsage( "The page you specified doesn't exist", 'missingtitle' ); 161 } 162 $wgTitle = $titleObj; 163 164 if ( isset( $prop['revid'] ) ) { 165 $oldid = $pageObj->getLatest(); 166 } 167 168 $popts = $this->makeParserOptions( $pageObj, $params ); 169 170 // Potentially cached 171 $p_result = $this->getParsedContent( $pageObj, $popts, $pageid, 172 isset( $prop['wikitext'] ) ); 173 } 174 } else { // Not $oldid, $pageid, $page. Hence based on $text 175 $titleObj = Title::newFromText( $title ); 176 if ( !$titleObj || $titleObj->isExternal() ) { 177 $this->dieUsageMsg( array( 'invalidtitle', $title ) ); 178 } 179 $wgTitle = $titleObj; 180 if ( $titleObj->canExist() ) { 181 $pageObj = WikiPage::factory( $titleObj ); 182 } else { 183 // Do like MediaWiki::initializeArticle() 184 $article = Article::newFromTitle( $titleObj, $this->getContext() ); 185 $pageObj = $article->getPage(); 186 } 187 188 $popts = $this->makeParserOptions( $pageObj, $params ); 189 $textProvided = !is_null( $text ); 190 191 if ( !$textProvided ) { 192 if ( $titleProvided && ( $prop || $params['generatexml'] ) ) { 193 $this->setWarning( 194 "'title' used without 'text', and parsed page properties were requested " . 195 "(did you mean to use 'page' instead of 'title'?)" 196 ); 197 } 198 // Prevent warning from ContentHandler::makeContent() 199 $text = ''; 200 } 201 202 // If we are parsing text, do not use the content model of the default 203 // API title, but default to wikitext to keep BC. 204 if ( $textProvided && !$titleProvided && is_null( $model ) ) { 205 $model = CONTENT_MODEL_WIKITEXT; 206 $this->setWarning( "No 'title' or 'contentmodel' was given, assuming $model." ); 207 } 208 209 try { 210 $this->content = ContentHandler::makeContent( $text, $titleObj, $model, $format ); 211 } catch ( MWContentSerializationException $ex ) { 212 $this->dieUsage( $ex->getMessage(), 'parseerror' ); 213 } 214 215 if ( $this->section !== false ) { 216 $this->content = $this->getSectionContent( $this->content, $titleObj->getPrefixedText() ); 217 } 218 219 if ( $params['pst'] || $params['onlypst'] ) { 220 $this->pstContent = $this->content->preSaveTransform( $titleObj, $this->getUser(), $popts ); 221 } 222 if ( $params['onlypst'] ) { 223 // Build a result and bail out 224 $result_array = array(); 225 $result_array['text'] = array(); 226 ApiResult::setContent( $result_array['text'], $this->pstContent->serialize( $format ) ); 227 if ( isset( $prop['wikitext'] ) ) { 228 $result_array['wikitext'] = array(); 229 ApiResult::setContent( $result_array['wikitext'], $this->content->serialize( $format ) ); 230 } 231 $result->addValue( null, $this->getModuleName(), $result_array ); 232 233 return; 234 } 235 236 // Not cached (save or load) 237 if ( $params['pst'] ) { 238 $p_result = $this->pstContent->getParserOutput( $titleObj, null, $popts ); 239 } else { 240 $p_result = $this->content->getParserOutput( $titleObj, null, $popts ); 241 } 242 } 243 244 $result_array = array(); 245 246 $result_array['title'] = $titleObj->getPrefixedText(); 247 248 if ( !is_null( $oldid ) ) { 249 $result_array['revid'] = intval( $oldid ); 250 } 251 252 if ( $params['redirects'] && !is_null( $redirValues ) ) { 253 $result_array['redirects'] = $redirValues; 254 } 255 256 if ( $params['disabletoc'] ) { 257 $p_result->setTOCEnabled( false ); 258 } 259 260 if ( isset( $prop['text'] ) ) { 261 $result_array['text'] = array(); 262 ApiResult::setContent( $result_array['text'], $p_result->getText() ); 263 } 264 265 if ( !is_null( $params['summary'] ) ) { 266 $result_array['parsedsummary'] = array(); 267 ApiResult::setContent( 268 $result_array['parsedsummary'], 269 Linker::formatComment( $params['summary'], $titleObj ) 270 ); 271 } 272 273 if ( isset( $prop['langlinks'] ) ) { 274 $langlinks = $p_result->getLanguageLinks(); 275 276 if ( $params['effectivelanglinks'] ) { 277 // Link flags are ignored for now, but may in the future be 278 // included in the result. 279 $linkFlags = array(); 280 wfRunHooks( 'LanguageLinks', array( $titleObj, &$langlinks, &$linkFlags ) ); 281 } 282 } else { 283 $langlinks = false; 284 } 285 286 if ( isset( $prop['langlinks'] ) ) { 287 $result_array['langlinks'] = $this->formatLangLinks( $langlinks ); 288 } 289 if ( isset( $prop['categories'] ) ) { 290 $result_array['categories'] = $this->formatCategoryLinks( $p_result->getCategories() ); 291 } 292 if ( isset( $prop['categorieshtml'] ) ) { 293 $categoriesHtml = $this->categoriesHtml( $p_result->getCategories() ); 294 $result_array['categorieshtml'] = array(); 295 ApiResult::setContent( $result_array['categorieshtml'], $categoriesHtml ); 296 } 297 if ( isset( $prop['links'] ) ) { 298 $result_array['links'] = $this->formatLinks( $p_result->getLinks() ); 299 } 300 if ( isset( $prop['templates'] ) ) { 301 $result_array['templates'] = $this->formatLinks( $p_result->getTemplates() ); 302 } 303 if ( isset( $prop['images'] ) ) { 304 $result_array['images'] = array_keys( $p_result->getImages() ); 305 } 306 if ( isset( $prop['externallinks'] ) ) { 307 $result_array['externallinks'] = array_keys( $p_result->getExternalLinks() ); 308 } 309 if ( isset( $prop['sections'] ) ) { 310 $result_array['sections'] = $p_result->getSections(); 311 } 312 313 if ( isset( $prop['displaytitle'] ) ) { 314 $result_array['displaytitle'] = $p_result->getDisplayTitle() ? 315 $p_result->getDisplayTitle() : 316 $titleObj->getPrefixedText(); 317 } 318 319 if ( isset( $prop['headitems'] ) || isset( $prop['headhtml'] ) ) { 320 $context = $this->getContext(); 321 $context->setTitle( $titleObj ); 322 $context->getOutput()->addParserOutputMetadata( $p_result ); 323 324 if ( isset( $prop['headitems'] ) ) { 325 $headItems = $this->formatHeadItems( $p_result->getHeadItems() ); 326 327 $css = $this->formatCss( $context->getOutput()->buildCssLinksArray() ); 328 329 $scripts = array( $context->getOutput()->getHeadScripts() ); 330 331 $result_array['headitems'] = array_merge( $headItems, $css, $scripts ); 332 } 333 334 if ( isset( $prop['headhtml'] ) ) { 335 $result_array['headhtml'] = array(); 336 ApiResult::setContent( 337 $result_array['headhtml'], 338 $context->getOutput()->headElement( $context->getSkin() ) 339 ); 340 } 341 } 342 343 if ( isset( $prop['modules'] ) ) { 344 $result_array['modules'] = array_values( array_unique( $p_result->getModules() ) ); 345 $result_array['modulescripts'] = array_values( array_unique( $p_result->getModuleScripts() ) ); 346 $result_array['modulestyles'] = array_values( array_unique( $p_result->getModuleStyles() ) ); 347 $result_array['modulemessages'] = array_values( array_unique( $p_result->getModuleMessages() ) ); 348 } 349 350 if ( isset( $prop['iwlinks'] ) ) { 351 $result_array['iwlinks'] = $this->formatIWLinks( $p_result->getInterwikiLinks() ); 352 } 353 354 if ( isset( $prop['wikitext'] ) ) { 355 $result_array['wikitext'] = array(); 356 ApiResult::setContent( $result_array['wikitext'], $this->content->serialize( $format ) ); 357 if ( !is_null( $this->pstContent ) ) { 358 $result_array['psttext'] = array(); 359 ApiResult::setContent( $result_array['psttext'], $this->pstContent->serialize( $format ) ); 360 } 361 } 362 if ( isset( $prop['properties'] ) ) { 363 $result_array['properties'] = $this->formatProperties( $p_result->getProperties() ); 364 } 365 366 if ( isset( $prop['limitreportdata'] ) ) { 367 $result_array['limitreportdata'] = 368 $this->formatLimitReportData( $p_result->getLimitReportData() ); 369 } 370 if ( isset( $prop['limitreporthtml'] ) ) { 371 $limitreportHtml = EditPage::getPreviewLimitReport( $p_result ); 372 $result_array['limitreporthtml'] = array(); 373 ApiResult::setContent( $result_array['limitreporthtml'], $limitreportHtml ); 374 } 375 376 if ( $params['generatexml'] ) { 377 if ( $this->content->getModel() != CONTENT_MODEL_WIKITEXT ) { 378 $this->dieUsage( "generatexml is only supported for wikitext content", "notwikitext" ); 379 } 380 381 $wgParser->startExternalParse( $titleObj, $popts, OT_PREPROCESS ); 382 $dom = $wgParser->preprocessToDom( $this->content->getNativeData() ); 383 if ( is_callable( array( $dom, 'saveXML' ) ) ) { 384 $xml = $dom->saveXML(); 385 } else { 386 $xml = $dom->__toString(); 387 } 388 $result_array['parsetree'] = array(); 389 ApiResult::setContent( $result_array['parsetree'], $xml ); 390 } 391 392 $result_mapping = array( 393 'redirects' => 'r', 394 'langlinks' => 'll', 395 'categories' => 'cl', 396 'links' => 'pl', 397 'templates' => 'tl', 398 'images' => 'img', 399 'externallinks' => 'el', 400 'iwlinks' => 'iw', 401 'sections' => 's', 402 'headitems' => 'hi', 403 'modules' => 'm', 404 'modulescripts' => 'm', 405 'modulestyles' => 'm', 406 'modulemessages' => 'm', 407 'properties' => 'pp', 408 'limitreportdata' => 'lr', 409 ); 410 $this->setIndexedTagNames( $result_array, $result_mapping ); 411 $result->addValue( null, $this->getModuleName(), $result_array ); 412 413 if ( !is_null( $oldLang ) ) { 414 $this->getContext()->setLanguage( $oldLang ); // Reset language to $oldLang 415 } 416 } 417 418 /** 419 * Constructs a ParserOptions object 420 * 421 * @param WikiPage $pageObj 422 * @param array $params 423 * 424 * @return ParserOptions 425 */ 426 protected function makeParserOptions( WikiPage $pageObj, array $params ) { 427 wfProfileIn( __METHOD__ ); 428 429 $popts = $pageObj->makeParserOptions( $this->getContext() ); 430 $popts->enableLimitReport( !$params['disablepp'] ); 431 $popts->setIsPreview( $params['preview'] || $params['sectionpreview'] ); 432 $popts->setIsSectionPreview( $params['sectionpreview'] ); 433 $popts->setEditSection( !$params['disableeditsection'] ); 434 435 wfProfileOut( __METHOD__ ); 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 user language (maybe set by uselang=) 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 'iwlinks', 698 'wikitext', 699 'properties', 700 'limitreportdata', 701 'limitreporthtml', 702 ) 703 ), 704 'pst' => false, 705 'onlypst' => false, 706 'effectivelanglinks' => false, 707 'uselang' => null, 708 'section' => null, 709 'disablepp' => false, 710 'disableeditsection' => false, 711 'generatexml' => false, 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 getParamDescription() { 725 $p = $this->getModulePrefix(); 726 $wikitext = CONTENT_MODEL_WIKITEXT; 727 728 return array( 729 'text' => "Text to parse. Use {$p}title or {$p}contentmodel to control the content model", 730 'summary' => 'Summary to parse', 731 'redirects' => "If the {$p}page or the {$p}pageid parameter is set to a redirect, resolve it", 732 'title' => "Title of page the text belongs to. " . 733 "If omitted, {$p}contentmodel must be specified, and \"API\" will be used as the title", 734 'page' => "Parse the content of this page. Cannot be used together with {$p}text and {$p}title", 735 'pageid' => "Parse the content of this page. Overrides {$p}page", 736 'oldid' => "Parse the content of this revision. Overrides {$p}page and {$p}pageid", 737 'prop' => array( 738 'Which pieces of information to get', 739 ' text - Gives the parsed text of the wikitext', 740 ' langlinks - Gives the language links in the parsed wikitext', 741 ' categories - Gives the categories in the parsed wikitext', 742 ' categorieshtml - Gives the HTML version of the categories', 743 ' links - Gives the internal links in the parsed wikitext', 744 ' templates - Gives the templates in the parsed wikitext', 745 ' images - Gives the images in the parsed wikitext', 746 ' externallinks - Gives the external links in the parsed wikitext', 747 ' sections - Gives the sections in the parsed wikitext', 748 ' revid - Adds the revision ID of the parsed page', 749 ' displaytitle - Adds the title of the parsed wikitext', 750 ' headitems - Gives items to put in the <head> of the page', 751 ' headhtml - Gives parsed <head> of the page', 752 ' modules - Gives the ResourceLoader modules used on the page', 753 ' iwlinks - Gives interwiki links in the parsed wikitext', 754 ' wikitext - Gives the original wikitext that was parsed', 755 ' properties - Gives various properties defined in the parsed wikitext', 756 ' limitreportdata - Gives the limit report in a structured way.', 757 " Gives no data, when {$p}disablepp is set.", 758 ' limitreporthtml - Gives the HTML version of the limit report.', 759 " Gives no data, when {$p}disablepp is set.", 760 ), 761 'effectivelanglinks' => array( 762 'Includes language links supplied by extensions', 763 '(for use with prop=langlinks)', 764 ), 765 'pst' => array( 766 'Do a pre-save transform on the input before parsing it', 767 "Only valid when used with {$p}text", 768 ), 769 'onlypst' => array( 770 'Do a pre-save transform (PST) on the input, but don\'t parse it', 771 'Returns the same wikitext, after a PST has been applied.', 772 "Only valid when used with {$p}text", 773 ), 774 'uselang' => 'Which language to parse the request in', 775 'section' => 'Only retrieve the content of this section number', 776 'disablepp' => 'Disable the PP Report from the parser output', 777 'disableeditsection' => 'Disable edit section links from the parser output', 778 'generatexml' => "Generate XML parse tree (requires contentmodel=$wikitext)", 779 'preview' => 'Parse in preview mode', 780 'sectionpreview' => 'Parse in section preview mode (enables preview mode too)', 781 'disabletoc' => 'Disable table of contents in output', 782 'contentformat' => array( 783 'Content serialization format used for the input text', 784 "Only valid when used with {$p}text", 785 ), 786 'contentmodel' => array( 787 "Content model of the input text. If omitted, $p}title must be specified, " . 788 "and default will be the model of the specified $p}title", 789 "Only valid when used with {$p}text", 790 ), 791 ); 792 } 793 794 public function getDescription() { 795 $p = $this->getModulePrefix(); 796 797 return array( 798 'Parses content and returns parser output.', 799 'See the various prop-Modules of action=query to get information from the current' . 800 'version of a page.', 801 'There are several ways to specify the text to parse:', 802 "1) Specify a page or revision, using {$p}page, {$p}pageid, or {$p}oldid.", 803 "2) Specify content explicitly, using {$p}text, {$p}title, and {$p}contentmodel.", 804 "3) Specify only a summary to parse. {$p}prop should be given an empty value.", 805 ); 806 } 807 808 public function getExamples() { 809 return array( 810 'api.php?action=parse&page=Project:Sandbox' => 'Parse a page', 811 'api.php?action=parse&text={{Project:Sandbox}}&contentmodel=wikitext' => 'Parse wikitext', 812 'api.php?action=parse&text={{PAGENAME}}&title=Test' 813 => 'Parse wikitext, specifying the page title', 814 'api.php?action=parse&summary=Some+[[link]]&prop=' => 'Parse a summary', 815 ); 816 } 817 818 public function getHelpUrls() { 819 return 'https://www.mediawiki.org/wiki/API:Parsing_wikitext#parse'; 820 } 821 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |