MediaWiki
REL1_24
|
00001 <?php 00028 class ApiParse extends ApiBase { 00029 00031 private $section = null; 00032 00034 private $content = null; 00035 00037 private $pstContent = null; 00038 00039 public function execute() { 00040 // The data is hot but user-dependent, like page views, so we set vary cookies 00041 $this->getMain()->setCacheMode( 'anon-public-user-private' ); 00042 00043 // Get parameters 00044 $params = $this->extractRequestParams(); 00045 $text = $params['text']; 00046 $title = $params['title']; 00047 if ( $title === null ) { 00048 $titleProvided = false; 00049 // A title is needed for parsing, so arbitrarily choose one 00050 $title = 'API'; 00051 } else { 00052 $titleProvided = true; 00053 } 00054 00055 $page = $params['page']; 00056 $pageid = $params['pageid']; 00057 $oldid = $params['oldid']; 00058 00059 $model = $params['contentmodel']; 00060 $format = $params['contentformat']; 00061 00062 if ( !is_null( $page ) && ( !is_null( $text ) || $titleProvided ) ) { 00063 $this->dieUsage( 00064 'The page parameter cannot be used together with the text and title parameters', 00065 'params' 00066 ); 00067 } 00068 00069 $prop = array_flip( $params['prop'] ); 00070 00071 if ( isset( $params['section'] ) ) { 00072 $this->section = $params['section']; 00073 } else { 00074 $this->section = false; 00075 } 00076 00077 // The parser needs $wgTitle to be set, apparently the 00078 // $title parameter in Parser::parse isn't enough *sigh* 00079 // TODO: Does this still need $wgTitle? 00080 global $wgParser, $wgTitle; 00081 00082 // Currently unnecessary, code to act as a safeguard against any change 00083 // in current behavior of uselang 00084 $oldLang = null; 00085 if ( isset( $params['uselang'] ) 00086 && $params['uselang'] != $this->getContext()->getLanguage()->getCode() 00087 ) { 00088 $oldLang = $this->getContext()->getLanguage(); // Backup language 00089 $this->getContext()->setLanguage( Language::factory( $params['uselang'] ) ); 00090 } 00091 00092 $redirValues = null; 00093 00094 // Return result 00095 $result = $this->getResult(); 00096 00097 if ( !is_null( $oldid ) || !is_null( $pageid ) || !is_null( $page ) ) { 00098 if ( !is_null( $oldid ) ) { 00099 // Don't use the parser cache 00100 $rev = Revision::newFromID( $oldid ); 00101 if ( !$rev ) { 00102 $this->dieUsage( "There is no revision ID $oldid", 'missingrev' ); 00103 } 00104 if ( !$rev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) { 00105 $this->dieUsage( "You don't have permission to view deleted revisions", 'permissiondenied' ); 00106 } 00107 00108 $titleObj = $rev->getTitle(); 00109 $wgTitle = $titleObj; 00110 $pageObj = WikiPage::factory( $titleObj ); 00111 $popts = $this->makeParserOptions( $pageObj, $params ); 00112 00113 // If for some reason the "oldid" is actually the current revision, it may be cached 00114 if ( $rev->isCurrent() ) { 00115 // May get from/save to parser cache 00116 $p_result = $this->getParsedContent( $pageObj, $popts, 00117 $pageid, isset( $prop['wikitext'] ) ); 00118 } else { // This is an old revision, so get the text differently 00119 $this->content = $rev->getContent( Revision::FOR_THIS_USER, $this->getUser() ); 00120 00121 if ( $this->section !== false ) { 00122 $this->content = $this->getSectionContent( $this->content, 'r' . $rev->getId() ); 00123 } 00124 00125 // Should we save old revision parses to the parser cache? 00126 $p_result = $this->content->getParserOutput( $titleObj, $rev->getId(), $popts ); 00127 } 00128 } else { // Not $oldid, but $pageid or $page 00129 if ( $params['redirects'] ) { 00130 $reqParams = array( 00131 'action' => 'query', 00132 'redirects' => '', 00133 ); 00134 if ( !is_null( $pageid ) ) { 00135 $reqParams['pageids'] = $pageid; 00136 } else { // $page 00137 $reqParams['titles'] = $page; 00138 } 00139 $req = new FauxRequest( $reqParams ); 00140 $main = new ApiMain( $req ); 00141 $main->execute(); 00142 $data = $main->getResultData(); 00143 $redirValues = isset( $data['query']['redirects'] ) 00144 ? $data['query']['redirects'] 00145 : array(); 00146 $to = $page; 00147 foreach ( (array)$redirValues as $r ) { 00148 $to = $r['to']; 00149 } 00150 $pageParams = array( 'title' => $to ); 00151 } elseif ( !is_null( $pageid ) ) { 00152 $pageParams = array( 'pageid' => $pageid ); 00153 } else { // $page 00154 $pageParams = array( 'title' => $page ); 00155 } 00156 00157 $pageObj = $this->getTitleOrPageId( $pageParams, 'fromdb' ); 00158 $titleObj = $pageObj->getTitle(); 00159 if ( !$titleObj || !$titleObj->exists() ) { 00160 $this->dieUsage( "The page you specified doesn't exist", 'missingtitle' ); 00161 } 00162 $wgTitle = $titleObj; 00163 00164 if ( isset( $prop['revid'] ) ) { 00165 $oldid = $pageObj->getLatest(); 00166 } 00167 00168 $popts = $this->makeParserOptions( $pageObj, $params ); 00169 00170 // Potentially cached 00171 $p_result = $this->getParsedContent( $pageObj, $popts, $pageid, 00172 isset( $prop['wikitext'] ) ); 00173 } 00174 } else { // Not $oldid, $pageid, $page. Hence based on $text 00175 $titleObj = Title::newFromText( $title ); 00176 if ( !$titleObj || $titleObj->isExternal() ) { 00177 $this->dieUsageMsg( array( 'invalidtitle', $title ) ); 00178 } 00179 $wgTitle = $titleObj; 00180 if ( $titleObj->canExist() ) { 00181 $pageObj = WikiPage::factory( $titleObj ); 00182 } else { 00183 // Do like MediaWiki::initializeArticle() 00184 $article = Article::newFromTitle( $titleObj, $this->getContext() ); 00185 $pageObj = $article->getPage(); 00186 } 00187 00188 $popts = $this->makeParserOptions( $pageObj, $params ); 00189 $textProvided = !is_null( $text ); 00190 00191 if ( !$textProvided ) { 00192 if ( $titleProvided && ( $prop || $params['generatexml'] ) ) { 00193 $this->setWarning( 00194 "'title' used without 'text', and parsed page properties were requested " . 00195 "(did you mean to use 'page' instead of 'title'?)" 00196 ); 00197 } 00198 // Prevent warning from ContentHandler::makeContent() 00199 $text = ''; 00200 } 00201 00202 // If we are parsing text, do not use the content model of the default 00203 // API title, but default to wikitext to keep BC. 00204 if ( $textProvided && !$titleProvided && is_null( $model ) ) { 00205 $model = CONTENT_MODEL_WIKITEXT; 00206 $this->setWarning( "No 'title' or 'contentmodel' was given, assuming $model." ); 00207 } 00208 00209 try { 00210 $this->content = ContentHandler::makeContent( $text, $titleObj, $model, $format ); 00211 } catch ( MWContentSerializationException $ex ) { 00212 $this->dieUsage( $ex->getMessage(), 'parseerror' ); 00213 } 00214 00215 if ( $this->section !== false ) { 00216 $this->content = $this->getSectionContent( $this->content, $titleObj->getPrefixedText() ); 00217 } 00218 00219 if ( $params['pst'] || $params['onlypst'] ) { 00220 $this->pstContent = $this->content->preSaveTransform( $titleObj, $this->getUser(), $popts ); 00221 } 00222 if ( $params['onlypst'] ) { 00223 // Build a result and bail out 00224 $result_array = array(); 00225 $result_array['text'] = array(); 00226 ApiResult::setContent( $result_array['text'], $this->pstContent->serialize( $format ) ); 00227 if ( isset( $prop['wikitext'] ) ) { 00228 $result_array['wikitext'] = array(); 00229 ApiResult::setContent( $result_array['wikitext'], $this->content->serialize( $format ) ); 00230 } 00231 $result->addValue( null, $this->getModuleName(), $result_array ); 00232 00233 return; 00234 } 00235 00236 // Not cached (save or load) 00237 if ( $params['pst'] ) { 00238 $p_result = $this->pstContent->getParserOutput( $titleObj, null, $popts ); 00239 } else { 00240 $p_result = $this->content->getParserOutput( $titleObj, null, $popts ); 00241 } 00242 } 00243 00244 $result_array = array(); 00245 00246 $result_array['title'] = $titleObj->getPrefixedText(); 00247 00248 if ( !is_null( $oldid ) ) { 00249 $result_array['revid'] = intval( $oldid ); 00250 } 00251 00252 if ( $params['redirects'] && !is_null( $redirValues ) ) { 00253 $result_array['redirects'] = $redirValues; 00254 } 00255 00256 if ( $params['disabletoc'] ) { 00257 $p_result->setTOCEnabled( false ); 00258 } 00259 00260 if ( isset( $prop['text'] ) ) { 00261 $result_array['text'] = array(); 00262 ApiResult::setContent( $result_array['text'], $p_result->getText() ); 00263 } 00264 00265 if ( !is_null( $params['summary'] ) ) { 00266 $result_array['parsedsummary'] = array(); 00267 ApiResult::setContent( 00268 $result_array['parsedsummary'], 00269 Linker::formatComment( $params['summary'], $titleObj ) 00270 ); 00271 } 00272 00273 if ( isset( $prop['langlinks'] ) ) { 00274 $langlinks = $p_result->getLanguageLinks(); 00275 00276 if ( $params['effectivelanglinks'] ) { 00277 // Link flags are ignored for now, but may in the future be 00278 // included in the result. 00279 $linkFlags = array(); 00280 wfRunHooks( 'LanguageLinks', array( $titleObj, &$langlinks, &$linkFlags ) ); 00281 } 00282 } else { 00283 $langlinks = false; 00284 } 00285 00286 if ( isset( $prop['langlinks'] ) ) { 00287 $result_array['langlinks'] = $this->formatLangLinks( $langlinks ); 00288 } 00289 if ( isset( $prop['categories'] ) ) { 00290 $result_array['categories'] = $this->formatCategoryLinks( $p_result->getCategories() ); 00291 } 00292 if ( isset( $prop['categorieshtml'] ) ) { 00293 $categoriesHtml = $this->categoriesHtml( $p_result->getCategories() ); 00294 $result_array['categorieshtml'] = array(); 00295 ApiResult::setContent( $result_array['categorieshtml'], $categoriesHtml ); 00296 } 00297 if ( isset( $prop['links'] ) ) { 00298 $result_array['links'] = $this->formatLinks( $p_result->getLinks() ); 00299 } 00300 if ( isset( $prop['templates'] ) ) { 00301 $result_array['templates'] = $this->formatLinks( $p_result->getTemplates() ); 00302 } 00303 if ( isset( $prop['images'] ) ) { 00304 $result_array['images'] = array_keys( $p_result->getImages() ); 00305 } 00306 if ( isset( $prop['externallinks'] ) ) { 00307 $result_array['externallinks'] = array_keys( $p_result->getExternalLinks() ); 00308 } 00309 if ( isset( $prop['sections'] ) ) { 00310 $result_array['sections'] = $p_result->getSections(); 00311 } 00312 00313 if ( isset( $prop['displaytitle'] ) ) { 00314 $result_array['displaytitle'] = $p_result->getDisplayTitle() ? 00315 $p_result->getDisplayTitle() : 00316 $titleObj->getPrefixedText(); 00317 } 00318 00319 if ( isset( $prop['headitems'] ) || isset( $prop['headhtml'] ) ) { 00320 $context = $this->getContext(); 00321 $context->setTitle( $titleObj ); 00322 $context->getOutput()->addParserOutputMetadata( $p_result ); 00323 00324 if ( isset( $prop['headitems'] ) ) { 00325 $headItems = $this->formatHeadItems( $p_result->getHeadItems() ); 00326 00327 $css = $this->formatCss( $context->getOutput()->buildCssLinksArray() ); 00328 00329 $scripts = array( $context->getOutput()->getHeadScripts() ); 00330 00331 $result_array['headitems'] = array_merge( $headItems, $css, $scripts ); 00332 } 00333 00334 if ( isset( $prop['headhtml'] ) ) { 00335 $result_array['headhtml'] = array(); 00336 ApiResult::setContent( 00337 $result_array['headhtml'], 00338 $context->getOutput()->headElement( $context->getSkin() ) 00339 ); 00340 } 00341 } 00342 00343 if ( isset( $prop['modules'] ) ) { 00344 $result_array['modules'] = array_values( array_unique( $p_result->getModules() ) ); 00345 $result_array['modulescripts'] = array_values( array_unique( $p_result->getModuleScripts() ) ); 00346 $result_array['modulestyles'] = array_values( array_unique( $p_result->getModuleStyles() ) ); 00347 $result_array['modulemessages'] = array_values( array_unique( $p_result->getModuleMessages() ) ); 00348 } 00349 00350 if ( isset( $prop['iwlinks'] ) ) { 00351 $result_array['iwlinks'] = $this->formatIWLinks( $p_result->getInterwikiLinks() ); 00352 } 00353 00354 if ( isset( $prop['wikitext'] ) ) { 00355 $result_array['wikitext'] = array(); 00356 ApiResult::setContent( $result_array['wikitext'], $this->content->serialize( $format ) ); 00357 if ( !is_null( $this->pstContent ) ) { 00358 $result_array['psttext'] = array(); 00359 ApiResult::setContent( $result_array['psttext'], $this->pstContent->serialize( $format ) ); 00360 } 00361 } 00362 if ( isset( $prop['properties'] ) ) { 00363 $result_array['properties'] = $this->formatProperties( $p_result->getProperties() ); 00364 } 00365 00366 if ( isset( $prop['limitreportdata'] ) ) { 00367 $result_array['limitreportdata'] = 00368 $this->formatLimitReportData( $p_result->getLimitReportData() ); 00369 } 00370 if ( isset( $prop['limitreporthtml'] ) ) { 00371 $limitreportHtml = EditPage::getPreviewLimitReport( $p_result ); 00372 $result_array['limitreporthtml'] = array(); 00373 ApiResult::setContent( $result_array['limitreporthtml'], $limitreportHtml ); 00374 } 00375 00376 if ( $params['generatexml'] ) { 00377 if ( $this->content->getModel() != CONTENT_MODEL_WIKITEXT ) { 00378 $this->dieUsage( "generatexml is only supported for wikitext content", "notwikitext" ); 00379 } 00380 00381 $wgParser->startExternalParse( $titleObj, $popts, OT_PREPROCESS ); 00382 $dom = $wgParser->preprocessToDom( $this->content->getNativeData() ); 00383 if ( is_callable( array( $dom, 'saveXML' ) ) ) { 00384 $xml = $dom->saveXML(); 00385 } else { 00386 $xml = $dom->__toString(); 00387 } 00388 $result_array['parsetree'] = array(); 00389 ApiResult::setContent( $result_array['parsetree'], $xml ); 00390 } 00391 00392 $result_mapping = array( 00393 'redirects' => 'r', 00394 'langlinks' => 'll', 00395 'categories' => 'cl', 00396 'links' => 'pl', 00397 'templates' => 'tl', 00398 'images' => 'img', 00399 'externallinks' => 'el', 00400 'iwlinks' => 'iw', 00401 'sections' => 's', 00402 'headitems' => 'hi', 00403 'modules' => 'm', 00404 'modulescripts' => 'm', 00405 'modulestyles' => 'm', 00406 'modulemessages' => 'm', 00407 'properties' => 'pp', 00408 'limitreportdata' => 'lr', 00409 ); 00410 $this->setIndexedTagNames( $result_array, $result_mapping ); 00411 $result->addValue( null, $this->getModuleName(), $result_array ); 00412 00413 if ( !is_null( $oldLang ) ) { 00414 $this->getContext()->setLanguage( $oldLang ); // Reset language to $oldLang 00415 } 00416 } 00417 00426 protected function makeParserOptions( WikiPage $pageObj, array $params ) { 00427 wfProfileIn( __METHOD__ ); 00428 00429 $popts = $pageObj->makeParserOptions( $this->getContext() ); 00430 $popts->enableLimitReport( !$params['disablepp'] ); 00431 $popts->setIsPreview( $params['preview'] || $params['sectionpreview'] ); 00432 $popts->setIsSectionPreview( $params['sectionpreview'] ); 00433 $popts->setEditSection( !$params['disableeditsection'] ); 00434 00435 wfProfileOut( __METHOD__ ); 00436 00437 return $popts; 00438 } 00439 00447 private function getParsedContent( WikiPage $page, $popts, $pageId = null, $getWikitext = false ) { 00448 $this->content = $page->getContent( Revision::RAW ); //XXX: really raw? 00449 00450 if ( $this->section !== false && $this->content !== null ) { 00451 $this->content = $this->getSectionContent( 00452 $this->content, 00453 !is_null( $pageId ) ? 'page id ' . $pageId : $page->getTitle()->getPrefixedText() 00454 ); 00455 00456 // Not cached (save or load) 00457 return $this->content->getParserOutput( $page->getTitle(), null, $popts ); 00458 } 00459 00460 // Try the parser cache first 00461 // getParserOutput will save to Parser cache if able 00462 $pout = $page->getParserOutput( $popts ); 00463 if ( !$pout ) { 00464 $this->dieUsage( "There is no revision ID {$page->getLatest()}", 'missingrev' ); 00465 } 00466 if ( $getWikitext ) { 00467 $this->content = $page->getContent( Revision::RAW ); 00468 } 00469 00470 return $pout; 00471 } 00472 00478 private function getSectionContent( Content $content, $what ) { 00479 // Not cached (save or load) 00480 $section = $content->getSection( $this->section ); 00481 if ( $section === false ) { 00482 $this->dieUsage( "There is no section {$this->section} in " . $what, 'nosuchsection' ); 00483 } 00484 if ( $section === null ) { 00485 $this->dieUsage( "Sections are not supported by " . $what, 'nosuchsection' ); 00486 $section = false; 00487 } 00488 00489 return $section; 00490 } 00491 00492 private function formatLangLinks( $links ) { 00493 $result = array(); 00494 foreach ( $links as $link ) { 00495 $entry = array(); 00496 $bits = explode( ':', $link, 2 ); 00497 $title = Title::newFromText( $link ); 00498 00499 $entry['lang'] = $bits[0]; 00500 if ( $title ) { 00501 $entry['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT ); 00502 // localised language name in user language (maybe set by uselang=) 00503 $entry['langname'] = Language::fetchLanguageName( 00504 $title->getInterwiki(), 00505 $this->getLanguage()->getCode() 00506 ); 00507 00508 // native language name 00509 $entry['autonym'] = Language::fetchLanguageName( $title->getInterwiki() ); 00510 } 00511 ApiResult::setContent( $entry, $bits[1] ); 00512 $result[] = $entry; 00513 } 00514 00515 return $result; 00516 } 00517 00518 private function formatCategoryLinks( $links ) { 00519 $result = array(); 00520 00521 if ( !$links ) { 00522 return $result; 00523 } 00524 00525 // Fetch hiddencat property 00526 $lb = new LinkBatch; 00527 $lb->setArray( array( NS_CATEGORY => $links ) ); 00528 $db = $this->getDB(); 00529 $res = $db->select( array( 'page', 'page_props' ), 00530 array( 'page_title', 'pp_propname' ), 00531 $lb->constructSet( 'page', $db ), 00532 __METHOD__, 00533 array(), 00534 array( 'page_props' => array( 00535 'LEFT JOIN', array( 'pp_propname' => 'hiddencat', 'pp_page = page_id' ) 00536 ) ) 00537 ); 00538 $hiddencats = array(); 00539 foreach ( $res as $row ) { 00540 $hiddencats[$row->page_title] = isset( $row->pp_propname ); 00541 } 00542 00543 foreach ( $links as $link => $sortkey ) { 00544 $entry = array(); 00545 $entry['sortkey'] = $sortkey; 00546 ApiResult::setContent( $entry, $link ); 00547 if ( !isset( $hiddencats[$link] ) ) { 00548 $entry['missing'] = ''; 00549 } elseif ( $hiddencats[$link] ) { 00550 $entry['hidden'] = ''; 00551 } 00552 $result[] = $entry; 00553 } 00554 00555 return $result; 00556 } 00557 00558 private function categoriesHtml( $categories ) { 00559 $context = $this->getContext(); 00560 $context->getOutput()->addCategoryLinks( $categories ); 00561 00562 return $context->getSkin()->getCategories(); 00563 } 00564 00565 private function formatLinks( $links ) { 00566 $result = array(); 00567 foreach ( $links as $ns => $nslinks ) { 00568 foreach ( $nslinks as $title => $id ) { 00569 $entry = array(); 00570 $entry['ns'] = $ns; 00571 ApiResult::setContent( $entry, Title::makeTitle( $ns, $title )->getFullText() ); 00572 if ( $id != 0 ) { 00573 $entry['exists'] = ''; 00574 } 00575 $result[] = $entry; 00576 } 00577 } 00578 00579 return $result; 00580 } 00581 00582 private function formatIWLinks( $iw ) { 00583 $result = array(); 00584 foreach ( $iw as $prefix => $titles ) { 00585 foreach ( array_keys( $titles ) as $title ) { 00586 $entry = array(); 00587 $entry['prefix'] = $prefix; 00588 00589 $title = Title::newFromText( "{$prefix}:{$title}" ); 00590 if ( $title ) { 00591 $entry['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT ); 00592 } 00593 00594 ApiResult::setContent( $entry, $title->getFullText() ); 00595 $result[] = $entry; 00596 } 00597 } 00598 00599 return $result; 00600 } 00601 00602 private function formatHeadItems( $headItems ) { 00603 $result = array(); 00604 foreach ( $headItems as $tag => $content ) { 00605 $entry = array(); 00606 $entry['tag'] = $tag; 00607 ApiResult::setContent( $entry, $content ); 00608 $result[] = $entry; 00609 } 00610 00611 return $result; 00612 } 00613 00614 private function formatProperties( $properties ) { 00615 $result = array(); 00616 foreach ( $properties as $name => $value ) { 00617 $entry = array(); 00618 $entry['name'] = $name; 00619 ApiResult::setContent( $entry, $value ); 00620 $result[] = $entry; 00621 } 00622 00623 return $result; 00624 } 00625 00626 private function formatCss( $css ) { 00627 $result = array(); 00628 foreach ( $css as $file => $link ) { 00629 $entry = array(); 00630 $entry['file'] = $file; 00631 ApiResult::setContent( $entry, $link ); 00632 $result[] = $entry; 00633 } 00634 00635 return $result; 00636 } 00637 00638 private function formatLimitReportData( $limitReportData ) { 00639 $result = array(); 00640 $apiResult = $this->getResult(); 00641 00642 foreach ( $limitReportData as $name => $value ) { 00643 $entry = array(); 00644 $entry['name'] = $name; 00645 if ( !is_array( $value ) ) { 00646 $value = array( $value ); 00647 } 00648 $apiResult->setIndexedTagName( $value, 'param' ); 00649 $apiResult->setIndexedTagName_recursive( $value, 'param' ); 00650 $entry = array_merge( $entry, $value ); 00651 $result[] = $entry; 00652 } 00653 00654 return $result; 00655 } 00656 00657 private function setIndexedTagNames( &$array, $mapping ) { 00658 foreach ( $mapping as $key => $name ) { 00659 if ( isset( $array[$key] ) ) { 00660 $this->getResult()->setIndexedTagName( $array[$key], $name ); 00661 } 00662 } 00663 } 00664 00665 public function getAllowedParams() { 00666 return array( 00667 'title' => null, 00668 'text' => null, 00669 'summary' => null, 00670 'page' => null, 00671 'pageid' => array( 00672 ApiBase::PARAM_TYPE => 'integer', 00673 ), 00674 'redirects' => false, 00675 'oldid' => array( 00676 ApiBase::PARAM_TYPE => 'integer', 00677 ), 00678 'prop' => array( 00679 ApiBase::PARAM_DFLT => 'text|langlinks|categories|links|templates|' . 00680 'images|externallinks|sections|revid|displaytitle|iwlinks|properties', 00681 ApiBase::PARAM_ISMULTI => true, 00682 ApiBase::PARAM_TYPE => array( 00683 'text', 00684 'langlinks', 00685 'categories', 00686 'categorieshtml', 00687 'links', 00688 'templates', 00689 'images', 00690 'externallinks', 00691 'sections', 00692 'revid', 00693 'displaytitle', 00694 'headitems', 00695 'headhtml', 00696 'modules', 00697 'iwlinks', 00698 'wikitext', 00699 'properties', 00700 'limitreportdata', 00701 'limitreporthtml', 00702 ) 00703 ), 00704 'pst' => false, 00705 'onlypst' => false, 00706 'effectivelanglinks' => false, 00707 'uselang' => null, 00708 'section' => null, 00709 'disablepp' => false, 00710 'disableeditsection' => false, 00711 'generatexml' => false, 00712 'preview' => false, 00713 'sectionpreview' => false, 00714 'disabletoc' => false, 00715 'contentformat' => array( 00716 ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(), 00717 ), 00718 'contentmodel' => array( 00719 ApiBase::PARAM_TYPE => ContentHandler::getContentModels(), 00720 ) 00721 ); 00722 } 00723 00724 public function getParamDescription() { 00725 $p = $this->getModulePrefix(); 00726 $wikitext = CONTENT_MODEL_WIKITEXT; 00727 00728 return array( 00729 'text' => "Text to parse. Use {$p}title or {$p}contentmodel to control the content model", 00730 'summary' => 'Summary to parse', 00731 'redirects' => "If the {$p}page or the {$p}pageid parameter is set to a redirect, resolve it", 00732 'title' => "Title of page the text belongs to. " . 00733 "If omitted, {$p}contentmodel must be specified, and \"API\" will be used as the title", 00734 'page' => "Parse the content of this page. Cannot be used together with {$p}text and {$p}title", 00735 'pageid' => "Parse the content of this page. Overrides {$p}page", 00736 'oldid' => "Parse the content of this revision. Overrides {$p}page and {$p}pageid", 00737 'prop' => array( 00738 'Which pieces of information to get', 00739 ' text - Gives the parsed text of the wikitext', 00740 ' langlinks - Gives the language links in the parsed wikitext', 00741 ' categories - Gives the categories in the parsed wikitext', 00742 ' categorieshtml - Gives the HTML version of the categories', 00743 ' links - Gives the internal links in the parsed wikitext', 00744 ' templates - Gives the templates in the parsed wikitext', 00745 ' images - Gives the images in the parsed wikitext', 00746 ' externallinks - Gives the external links in the parsed wikitext', 00747 ' sections - Gives the sections in the parsed wikitext', 00748 ' revid - Adds the revision ID of the parsed page', 00749 ' displaytitle - Adds the title of the parsed wikitext', 00750 ' headitems - Gives items to put in the <head> of the page', 00751 ' headhtml - Gives parsed <head> of the page', 00752 ' modules - Gives the ResourceLoader modules used on the page', 00753 ' iwlinks - Gives interwiki links in the parsed wikitext', 00754 ' wikitext - Gives the original wikitext that was parsed', 00755 ' properties - Gives various properties defined in the parsed wikitext', 00756 ' limitreportdata - Gives the limit report in a structured way.', 00757 " Gives no data, when {$p}disablepp is set.", 00758 ' limitreporthtml - Gives the HTML version of the limit report.', 00759 " Gives no data, when {$p}disablepp is set.", 00760 ), 00761 'effectivelanglinks' => array( 00762 'Includes language links supplied by extensions', 00763 '(for use with prop=langlinks)', 00764 ), 00765 'pst' => array( 00766 'Do a pre-save transform on the input before parsing it', 00767 "Only valid when used with {$p}text", 00768 ), 00769 'onlypst' => array( 00770 'Do a pre-save transform (PST) on the input, but don\'t parse it', 00771 'Returns the same wikitext, after a PST has been applied.', 00772 "Only valid when used with {$p}text", 00773 ), 00774 'uselang' => 'Which language to parse the request in', 00775 'section' => 'Only retrieve the content of this section number', 00776 'disablepp' => 'Disable the PP Report from the parser output', 00777 'disableeditsection' => 'Disable edit section links from the parser output', 00778 'generatexml' => "Generate XML parse tree (requires contentmodel=$wikitext)", 00779 'preview' => 'Parse in preview mode', 00780 'sectionpreview' => 'Parse in section preview mode (enables preview mode too)', 00781 'disabletoc' => 'Disable table of contents in output', 00782 'contentformat' => array( 00783 'Content serialization format used for the input text', 00784 "Only valid when used with {$p}text", 00785 ), 00786 'contentmodel' => array( 00787 "Content model of the input text. If omitted, ${p}title must be specified, " . 00788 "and default will be the model of the specified ${p}title", 00789 "Only valid when used with {$p}text", 00790 ), 00791 ); 00792 } 00793 00794 public function getDescription() { 00795 $p = $this->getModulePrefix(); 00796 00797 return array( 00798 'Parses content and returns parser output.', 00799 'See the various prop-Modules of action=query to get information from the current' . 00800 'version of a page.', 00801 'There are several ways to specify the text to parse:', 00802 "1) Specify a page or revision, using {$p}page, {$p}pageid, or {$p}oldid.", 00803 "2) Specify content explicitly, using {$p}text, {$p}title, and {$p}contentmodel.", 00804 "3) Specify only a summary to parse. {$p}prop should be given an empty value.", 00805 ); 00806 } 00807 00808 public function getExamples() { 00809 return array( 00810 'api.php?action=parse&page=Project:Sandbox' => 'Parse a page', 00811 'api.php?action=parse&text={{Project:Sandbox}}&contentmodel=wikitext' => 'Parse wikitext', 00812 'api.php?action=parse&text={{PAGENAME}}&title=Test' 00813 => 'Parse wikitext, specifying the page title', 00814 'api.php?action=parse&summary=Some+[[link]]&prop=' => 'Parse a summary', 00815 ); 00816 } 00817 00818 public function getHelpUrls() { 00819 return 'https://www.mediawiki.org/wiki/API:Parsing_wikitext#parse'; 00820 } 00821 }