MediaWiki  master
ApiParse.php
Go to the documentation of this file.
1 <?php
34 
38 class ApiParse extends ApiBase {
39 
41  private $section = null;
42 
44  private $content = null;
45 
47  private $pstContent = null;
48 
50  private $contentIsDeleted = false, $contentIsSuppressed = false;
51 
53  private $revisionLookup;
54 
56  private $skinFactory;
57 
60 
63 
65  private $linkCache;
66 
69 
71  private $parser;
72 
75 
78 
81 
84 
100  public function __construct(
101  ApiMain $main,
102  $action,
109  Parser $parser,
114  ) {
115  parent::__construct( $main, $action );
116  $this->revisionLookup = $revisionLookup;
117  $this->skinFactory = $skinFactory;
118  $this->languageNameUtils = $languageNameUtils;
119  $this->linkBatchFactory = $linkBatchFactory;
120  $this->linkCache = $linkCache;
121  $this->contentHandlerFactory = $contentHandlerFactory;
122  $this->parser = $parser;
123  $this->wikiPageFactory = $wikiPageFactory;
124  $this->contentRenderer = $contentRenderer;
125  $this->contentTransformer = $contentTransformer;
126  $this->commentFormatter = $commentFormatter;
127  }
128 
129  private function getPoolKey(): string {
130  $poolKey = WikiMap::getCurrentWikiDbDomain() . ':ApiParse:';
131  if ( !$this->getUser()->isRegistered() ) {
132  $poolKey .= 'a:' . $this->getUser()->getName();
133  } else {
134  $poolKey .= 'u:' . $this->getUser()->getId();
135  }
136  return $poolKey;
137  }
138 
139  private function getContentParserOutput(
141  PageReference $page,
142  $revId,
143  ParserOptions $popts
144  ) {
145  $worker = new PoolCounterWorkViaCallback( 'ApiParser', $this->getPoolKey(),
146  [
147  'doWork' => function () use ( $content, $page, $revId, $popts ) {
148  return $this->contentRenderer->getParserOutput( $content, $page, $revId, $popts );
149  },
150  'error' => function () {
151  $this->dieWithError( 'apierror-concurrency-limit' );
152  },
153  ]
154  );
155  return $worker->execute();
156  }
157 
158  private function getPageParserOutput(
159  WikiPage $page,
160  $revId,
161  ParserOptions $popts,
162  bool $suppressCache
163  ) {
164  $worker = new PoolCounterWorkViaCallback( 'ApiParser', $this->getPoolKey(),
165  [
166  'doWork' => static function () use ( $page, $revId, $popts, $suppressCache ) {
167  return $page->getParserOutput( $popts, $revId, $suppressCache );
168  },
169  'error' => function () {
170  $this->dieWithError( 'apierror-concurrency-limit' );
171  },
172  ]
173  );
174  return $worker->execute();
175  }
176 
177  public function execute() {
178  // The data is hot but user-dependent, like page views, so we set vary cookies
179  $this->getMain()->setCacheMode( 'anon-public-user-private' );
180 
181  // Get parameters
182  $params = $this->extractRequestParams();
183 
184  // No easy way to say that text and title or revid are allowed together
185  // while the rest aren't, so just do it in three calls.
186  $this->requireMaxOneParameter( $params, 'page', 'pageid', 'oldid', 'text' );
187  $this->requireMaxOneParameter( $params, 'page', 'pageid', 'oldid', 'title' );
188  $this->requireMaxOneParameter( $params, 'page', 'pageid', 'oldid', 'revid' );
189 
190  $text = $params['text'];
191  $title = $params['title'];
192  if ( $title === null ) {
193  $titleProvided = false;
194  // A title is needed for parsing, so arbitrarily choose one
195  $title = 'API';
196  } else {
197  $titleProvided = true;
198  }
199 
200  $page = $params['page'];
201  $pageid = $params['pageid'];
202  $oldid = $params['oldid'];
203 
204  $model = $params['contentmodel'];
205  $format = $params['contentformat'];
206 
207  $prop = array_fill_keys( $params['prop'], true );
208 
209  if ( isset( $params['section'] ) ) {
210  $this->section = $params['section'];
211  if ( !preg_match( '/^((T-)?\d+|new)$/', $this->section ) ) {
212  $this->dieWithError( 'apierror-invalidsection' );
213  }
214  } else {
215  $this->section = false;
216  }
217 
218  // The parser needs $wgTitle to be set, apparently the
219  // $title parameter in Parser::parse isn't enough *sigh*
220  // TODO: Does this still need $wgTitle?
221  global $wgTitle;
222 
223  $redirValues = null;
224 
225  $needContent = isset( $prop['wikitext'] ) ||
226  isset( $prop['parsetree'] ) || $params['generatexml'];
227 
228  // Return result
229  $result = $this->getResult();
230 
231  if ( $oldid !== null || $pageid !== null || $page !== null ) {
232  if ( $this->section === 'new' ) {
233  $this->dieWithError( 'apierror-invalidparammix-parse-new-section', 'invalidparammix' );
234  }
235  if ( $oldid !== null ) {
236  // Don't use the parser cache
237  $rev = $this->revisionLookup->getRevisionById( $oldid );
238  if ( !$rev ) {
239  $this->dieWithError( [ 'apierror-nosuchrevid', $oldid ] );
240  }
241 
242  $this->checkTitleUserPermissions( $rev->getPage(), 'read' );
243 
244  if ( !$rev->userCan( RevisionRecord::DELETED_TEXT, $this->getAuthority() ) ) {
245  $this->dieWithError(
246  [ 'apierror-permissiondenied', $this->msg( 'action-deletedtext' ) ]
247  );
248  }
249 
250  $revLinkTarget = $rev->getPageAsLinkTarget();
251  $titleObj = Title::newFromLinkTarget( $revLinkTarget );
252  $wgTitle = $titleObj;
253  $pageObj = $this->wikiPageFactory->newFromTitle( $titleObj );
254  list( $popts, $reset, $suppressCache ) = $this->makeParserOptions( $pageObj, $params );
255  $p_result = $this->getParsedContent(
256  $pageObj, $popts, $suppressCache, $pageid, $rev, $needContent
257  );
258  } else { // Not $oldid, but $pageid or $page
259  if ( $params['redirects'] ) {
260  $reqParams = [
261  'redirects' => '',
262  ];
263  $pageParams = [];
264  if ( $pageid !== null ) {
265  $reqParams['pageids'] = $pageid;
266  $pageParams['pageid'] = $pageid;
267  } else { // $page
268  $reqParams['titles'] = $page;
269  $pageParams['title'] = $page;
270  }
271  $req = new FauxRequest( $reqParams );
272  $main = new ApiMain( $req );
273  $pageSet = new ApiPageSet( $main );
274  $pageSet->execute();
275  $redirValues = $pageSet->getRedirectTitlesAsResult( $this->getResult() );
276 
277  foreach ( $pageSet->getRedirectTitles() as $title ) {
278  $pageParams = [ 'title' => $title->getFullText() ];
279  }
280  } elseif ( $pageid !== null ) {
281  $pageParams = [ 'pageid' => $pageid ];
282  } else { // $page
283  $pageParams = [ 'title' => $page ];
284  }
285 
286  $pageObj = $this->getTitleOrPageId( $pageParams, 'fromdb' );
287  $titleObj = $pageObj->getTitle();
288  if ( !$titleObj->exists() ) {
289  $this->dieWithError( 'apierror-missingtitle' );
290  }
291 
292  $this->checkTitleUserPermissions( $titleObj, 'read' );
293  $wgTitle = $titleObj;
294 
295  if ( isset( $prop['revid'] ) ) {
296  $oldid = $pageObj->getLatest();
297  }
298 
299  list( $popts, $reset, $suppressCache ) = $this->makeParserOptions( $pageObj, $params );
300  $p_result = $this->getParsedContent(
301  $pageObj, $popts, $suppressCache, $pageid, null, $needContent
302  );
303  }
304  } else { // Not $oldid, $pageid, $page. Hence based on $text
305  $titleObj = Title::newFromText( $title );
306  if ( !$titleObj || $titleObj->isExternal() ) {
307  $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $title ) ] );
308  }
309  $revid = $params['revid'];
310  if ( $revid !== null ) {
311  $rev = $this->revisionLookup->getRevisionById( $revid );
312  if ( !$rev ) {
313  $this->dieWithError( [ 'apierror-nosuchrevid', $revid ] );
314  }
315  $pTitleObj = $titleObj;
316  $titleObj = Title::newFromLinkTarget( $rev->getPageAsLinkTarget() );
317  if ( $titleProvided ) {
318  if ( !$titleObj->equals( $pTitleObj ) ) {
319  $this->addWarning( [ 'apierror-revwrongpage', $rev->getId(),
320  wfEscapeWikiText( $pTitleObj->getPrefixedText() ) ] );
321  }
322  } else {
323  // Consider the title derived from the revid as having
324  // been provided.
325  $titleProvided = true;
326  }
327  }
328  $wgTitle = $titleObj;
329  if ( $titleObj->canExist() ) {
330  $pageObj = $this->wikiPageFactory->newFromTitle( $titleObj );
331  list( $popts, $reset ) = $this->makeParserOptions( $pageObj, $params );
332  } else { // A special page, presumably
333  // XXX: Why is this needed at all? Can't we just fail?
334  $pageObj = null;
335  $popts = ParserOptions::newCanonical( $this->getContext() );
336  list( $popts, $reset ) = $this->tweakParserOptions( $popts, $titleObj, $params );
337  }
338 
339  $textProvided = $text !== null;
340 
341  if ( !$textProvided ) {
342  if ( $titleProvided && ( $prop || $params['generatexml'] ) ) {
343  if ( $revid !== null ) {
344  $this->addWarning( 'apiwarn-parse-revidwithouttext' );
345  } else {
346  $this->addWarning( 'apiwarn-parse-titlewithouttext' );
347  }
348  }
349  // Prevent warning from ContentHandler::makeContent()
350  $text = '';
351  }
352 
353  // If we are parsing text, do not use the content model of the default
354  // API title, but default to wikitext to keep BC.
355  if ( $textProvided && !$titleProvided && $model === null ) {
356  $model = CONTENT_MODEL_WIKITEXT;
357  $this->addWarning( [ 'apiwarn-parse-nocontentmodel', $model ] );
358  }
359 
360  try {
361  $this->content = ContentHandler::makeContent( $text, $titleObj, $model, $format );
362  } catch ( MWContentSerializationException $ex ) {
363  $this->dieWithException( $ex, [
364  'wrap' => ApiMessage::create( 'apierror-contentserializationexception', 'parseerror' )
365  ] );
366  }
367 
368  if ( $this->section !== false ) {
369  if ( $this->section === 'new' ) {
370  // Insert the section title above the content.
371  if ( $params['sectiontitle'] !== null && $params['sectiontitle'] !== '' ) {
372  $this->content = $this->content->addSectionHeader( $params['sectiontitle'] );
373  }
374  } else {
375  $this->content = $this->getSectionContent( $this->content, $titleObj->getPrefixedText() );
376  }
377  }
378 
379  if ( $params['pst'] || $params['onlypst'] ) {
380  $this->pstContent = $this->contentTransformer->preSaveTransform(
381  $this->content,
382  $titleObj,
383  $this->getUser(),
384  $popts
385  );
386  }
387  if ( $params['onlypst'] ) {
388  // Build a result and bail out
389  $result_array = [];
390  $result_array['text'] = $this->pstContent->serialize( $format );
391  $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'text';
392  if ( isset( $prop['wikitext'] ) ) {
393  $result_array['wikitext'] = $this->content->serialize( $format );
394  $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'wikitext';
395  }
396  if ( $params['summary'] !== null ||
397  ( $params['sectiontitle'] !== null && $this->section === 'new' )
398  ) {
399  $result_array['parsedsummary'] = $this->formatSummary( $titleObj, $params );
400  $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'parsedsummary';
401  }
402 
403  $result->addValue( null, $this->getModuleName(), $result_array );
404 
405  return;
406  }
407 
408  // Not cached (save or load)
409  if ( $params['pst'] ) {
410  $p_result = $this->getContentParserOutput( $this->pstContent, $titleObj, $revid, $popts );
411  } else {
412  $p_result = $this->getContentParserOutput( $this->content, $titleObj, $revid, $popts );
413  }
414  }
415 
416  $result_array = [];
417 
418  $result_array['title'] = $titleObj->getPrefixedText();
419  $result_array['pageid'] = $pageid ?: $titleObj->getArticleID();
420  if ( $this->contentIsDeleted ) {
421  $result_array['textdeleted'] = true;
422  }
423  if ( $this->contentIsSuppressed ) {
424  $result_array['textsuppressed'] = true;
425  }
426 
427  if ( isset( $params['useskin'] ) ) {
428  $skin = $this->skinFactory->makeSkin( Skin::normalizeKey( $params['useskin'] ) );
429  } else {
430  $skin = null;
431  }
432 
433  $outputPage = null;
434  $context = null;
435  if ( $skin || isset( $prop['subtitle'] ) || isset( $prop['headhtml'] ) || isset( $prop['categorieshtml'] ) ) {
436  // Enabling the skin via 'useskin', 'subtitle', 'headhtml', or 'categorieshtml'
437  // gets OutputPage and Skin involved, which (among others) applies
438  // these hooks:
439  // - ParserOutputHooks
440  // - Hook: LanguageLinks
441  // - Hook: SkinSubPageSubtitle
442  // - Hook: OutputPageParserOutput
443  // - Hook: OutputPageMakeCategoryLinks
444  // - Hook: OutputPageBeforeHTML
445  $context = new DerivativeContext( $this->getContext() );
446  $context->setTitle( $titleObj );
447 
448  if ( $pageObj ) {
449  $context->setWikiPage( $pageObj );
450  }
451  // Some hooks only apply to pages when action=view, which this API
452  // call is simulating.
453  $context->setRequest( new FauxRequest( [ 'action' => 'view' ] ) );
454 
455  if ( $skin ) {
456  // Use the skin specified by 'useskin'
457  $context->setSkin( $skin );
458  // Context clones the skin, refetch to stay in sync. (T166022)
459  $skin = $context->getSkin();
460  } else {
461  // Make sure the context's skin refers to the context. Without this,
462  // $outputPage->getSkin()->getOutput() !== $outputPage which
463  // confuses some of the output.
464  $context->setSkin( $context->getSkin() );
465  }
466 
467  $outputPage = new OutputPage( $context );
468  // Required for subtitle to appear
469  $outputPage->setArticleFlag( true );
470 
471  $outputPage->addParserOutputMetadata( $p_result );
472  if ( $this->content ) {
473  $outputPage->addContentOverride( $titleObj, $this->content );
474  }
475  $context->setOutput( $outputPage );
476 
477  if ( $skin ) {
478  // Based on OutputPage::output()
479  $outputPage->loadSkinModules( $skin );
480  }
481 
482  $this->getHookRunner()->onApiParseMakeOutputPage( $this, $outputPage );
483  }
484 
485  if ( $oldid !== null ) {
486  $result_array['revid'] = (int)$oldid;
487  }
488 
489  if ( $params['redirects'] && $redirValues !== null ) {
490  $result_array['redirects'] = $redirValues;
491  }
492 
493  if ( isset( $prop['text'] ) ) {
494  $skin = $context ? $context->getSkin() : null;
495  $skinOptions = $skin ? $skin->getOptions() : [
496  'toc' => true,
497  ];
498  $result_array['text'] = $p_result->getText( [
499  'allowTOC' => !$params['disabletoc'],
500  'injectTOC' => $skinOptions['toc'],
501  'enableSectionEditLinks' => !$params['disableeditsection'],
502  'wrapperDivClass' => $params['wrapoutputclass'],
503  'deduplicateStyles' => !$params['disablestylededuplication'],
504  'skin' => $skin,
505  'includeDebugInfo' => !$params['disablepp'] && !$params['disablelimitreport']
506  ] );
507  $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'text';
508  if ( $context ) {
509  $this->getHookRunner()->onOutputPageBeforeHTML( $context->getOutput(), $result_array['text'] );
510  }
511  }
512 
513  if ( $params['summary'] !== null ||
514  ( $params['sectiontitle'] !== null && $this->section === 'new' )
515  ) {
516  $result_array['parsedsummary'] = $this->formatSummary( $titleObj, $params );
517  $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'parsedsummary';
518  }
519 
520  if ( isset( $prop['langlinks'] ) ) {
521  if ( $skin ) {
522  $langlinks = $outputPage->getLanguageLinks();
523  } else {
524  $langlinks = $p_result->getLanguageLinks();
525  // The deprecated 'effectivelanglinks' option depredates OutputPage
526  // support via 'useskin'. If not already applied, then run just this
527  // one hook of OutputPage::addParserOutputMetadata here.
528  if ( $params['effectivelanglinks'] ) {
529  $linkFlags = [];
530  $this->getHookRunner()->onLanguageLinks( $titleObj, $langlinks, $linkFlags );
531  }
532  }
533 
534  $result_array['langlinks'] = $this->formatLangLinks( $langlinks );
535  }
536  if ( isset( $prop['categories'] ) ) {
537  $result_array['categories'] = $this->formatCategoryLinks( $p_result->getCategories() );
538  }
539  if ( isset( $prop['categorieshtml'] ) ) {
540  $result_array['categorieshtml'] = $outputPage->getSkin()->getCategories();
541  $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'categorieshtml';
542  }
543  if ( isset( $prop['links'] ) ) {
544  $result_array['links'] = $this->formatLinks( $p_result->getLinks() );
545  }
546  if ( isset( $prop['templates'] ) ) {
547  $result_array['templates'] = $this->formatLinks( $p_result->getTemplates() );
548  }
549  if ( isset( $prop['images'] ) ) {
550  $result_array['images'] = array_keys( $p_result->getImages() );
551  }
552  if ( isset( $prop['externallinks'] ) ) {
553  $result_array['externallinks'] = array_keys( $p_result->getExternalLinks() );
554  }
555  if ( isset( $prop['sections'] ) ) {
556  $result_array['sections'] = $p_result->getSections();
557  }
558  if ( isset( $prop['parsewarnings'] ) ) {
559  $result_array['parsewarnings'] = $p_result->getWarnings();
560  }
561  if ( isset( $prop['parsewarningshtml'] ) ) {
562  $warnings = $p_result->getWarnings();
563  $warningsHtml = array_map( static function ( $warning ) {
564  return ( new RawMessage( '$1', [ $warning ] ) )->parse();
565  }, $warnings );
566  $result_array['parsewarningshtml'] = $warningsHtml;
567  }
568 
569  if ( isset( $prop['displaytitle'] ) ) {
570  $result_array['displaytitle'] = $p_result->getDisplayTitle() !== false
571  ? $p_result->getDisplayTitle()
572  : htmlspecialchars( $titleObj->getPrefixedText(), ENT_NOQUOTES );
573  }
574 
575  if ( isset( $prop['subtitle'] ) ) {
576  $result_array['subtitle'] = $context->getSkin()->prepareSubtitle();
577  }
578 
579  if ( isset( $prop['headitems'] ) ) {
580  if ( $skin ) {
581  $result_array['headitems'] = $this->formatHeadItems( $outputPage->getHeadItemsArray() );
582  } else {
583  $result_array['headitems'] = $this->formatHeadItems( $p_result->getHeadItems() );
584  }
585  }
586 
587  if ( isset( $prop['headhtml'] ) ) {
588  $result_array['headhtml'] = $outputPage->headElement( $context->getSkin() );
589  $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'headhtml';
590  }
591 
592  if ( isset( $prop['modules'] ) ) {
593  if ( $skin ) {
594  $result_array['modules'] = $outputPage->getModules();
595  // Deprecated since 1.32 (T188689)
596  $result_array['modulescripts'] = [];
597  $result_array['modulestyles'] = $outputPage->getModuleStyles();
598  } else {
599  $result_array['modules'] = array_values( array_unique( $p_result->getModules() ) );
600  // Deprecated since 1.32 (T188689)
601  $result_array['modulescripts'] = [];
602  $result_array['modulestyles'] = array_values( array_unique( $p_result->getModuleStyles() ) );
603  }
604  }
605 
606  if ( isset( $prop['jsconfigvars'] ) ) {
607  $jsconfigvars = $skin ? $outputPage->getJsConfigVars() : $p_result->getJsConfigVars();
608  $result_array['jsconfigvars'] = ApiResult::addMetadataToResultVars( $jsconfigvars );
609  }
610 
611  if ( isset( $prop['encodedjsconfigvars'] ) ) {
612  $jsconfigvars = $skin ? $outputPage->getJsConfigVars() : $p_result->getJsConfigVars();
613  $result_array['encodedjsconfigvars'] = FormatJson::encode(
614  $jsconfigvars,
615  false,
617  );
618  $result_array[ApiResult::META_SUBELEMENTS][] = 'encodedjsconfigvars';
619  }
620 
621  if ( isset( $prop['modules'] ) &&
622  !isset( $prop['jsconfigvars'] ) && !isset( $prop['encodedjsconfigvars'] ) ) {
623  $this->addWarning( 'apiwarn-moduleswithoutvars' );
624  }
625 
626  if ( isset( $prop['indicators'] ) ) {
627  if ( $skin ) {
628  $result_array['indicators'] = (array)$outputPage->getIndicators();
629  } else {
630  $result_array['indicators'] = (array)$p_result->getIndicators();
631  }
632  ApiResult::setArrayType( $result_array['indicators'], 'BCkvp', 'name' );
633  }
634 
635  if ( isset( $prop['iwlinks'] ) ) {
636  $result_array['iwlinks'] = $this->formatIWLinks( $p_result->getInterwikiLinks() );
637  }
638 
639  if ( isset( $prop['wikitext'] ) ) {
640  $result_array['wikitext'] = $this->content->serialize( $format );
641  $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'wikitext';
642  // @phan-suppress-next-line PhanImpossibleTypeComparison
643  if ( $this->pstContent !== null ) {
644  $result_array['psttext'] = $this->pstContent->serialize( $format );
645  $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'psttext';
646  }
647  }
648  if ( isset( $prop['properties'] ) ) {
649  $result_array['properties'] = $p_result->getPageProperties();
650  ApiResult::setArrayType( $result_array['properties'], 'BCkvp', 'name' );
651  }
652 
653  if ( isset( $prop['limitreportdata'] ) ) {
654  $result_array['limitreportdata'] =
655  $this->formatLimitReportData( $p_result->getLimitReportData() );
656  }
657  if ( isset( $prop['limitreporthtml'] ) ) {
658  $result_array['limitreporthtml'] = EditPage::getPreviewLimitReport( $p_result );
659  $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'limitreporthtml';
660  }
661 
662  if ( isset( $prop['parsetree'] ) || $params['generatexml'] ) {
663  if ( $this->content->getModel() != CONTENT_MODEL_WIKITEXT ) {
664  $this->dieWithError( 'apierror-parsetree-notwikitext', 'notwikitext' );
665  }
666 
667  $this->parser->startExternalParse( $titleObj, $popts, Parser::OT_PREPROCESS );
668  // @phan-suppress-next-line PhanUndeclaredMethod
669  $xml = $this->parser->preprocessToDom( $this->content->getText() )->__toString();
670  $result_array['parsetree'] = $xml;
671  $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'parsetree';
672  }
673 
674  $result_mapping = [
675  'redirects' => 'r',
676  'langlinks' => 'll',
677  'categories' => 'cl',
678  'links' => 'pl',
679  'templates' => 'tl',
680  'images' => 'img',
681  'externallinks' => 'el',
682  'iwlinks' => 'iw',
683  'sections' => 's',
684  'headitems' => 'hi',
685  'modules' => 'm',
686  'indicators' => 'ind',
687  'modulescripts' => 'm',
688  'modulestyles' => 'm',
689  'properties' => 'pp',
690  'limitreportdata' => 'lr',
691  'parsewarnings' => 'pw',
692  'parsewarningshtml' => 'pw',
693  ];
694  $this->setIndexedTagNames( $result_array, $result_mapping );
695  $result->addValue( null, $this->getModuleName(), $result_array );
696  }
697 
706  private function makeParserOptions( WikiPage $pageObj, array $params ) {
707  $popts = $pageObj->makeParserOptions( $this->getContext() );
708  return $this->tweakParserOptions( $popts, $pageObj->getTitle(), $params );
709  }
710 
720  private function tweakParserOptions( ParserOptions $popts, Title $title, array $params ) {
721  $popts->setIsPreview( $params['preview'] || $params['sectionpreview'] );
722  $popts->setIsSectionPreview( $params['sectionpreview'] );
723 
724  if ( $params['wrapoutputclass'] !== '' ) {
725  $popts->setWrapOutputClass( $params['wrapoutputclass'] );
726  }
727 
728  $reset = null;
729  $suppressCache = false;
730  $this->getHookRunner()->onApiMakeParserOptions( $popts, $title,
731  $params, $this, $reset, $suppressCache );
732 
733  return [ $popts, $reset, $suppressCache ];
734  }
735 
745  private function getParsedContent(
746  WikiPage $page, $popts, $suppressCache, $pageId, $rev, $getContent
747  ) {
748  $revId = $rev ? $rev->getId() : null;
749  $isDeleted = $rev && $rev->isDeleted( RevisionRecord::DELETED_TEXT );
750 
751  if ( $getContent || $this->section !== false || $isDeleted ) {
752  if ( $rev ) {
753  $this->content = $rev->getContent(
754  SlotRecord::MAIN, RevisionRecord::FOR_THIS_USER, $this->getUser()
755  );
756  if ( !$this->content ) {
757  $this->dieWithError( [ 'apierror-missingcontent-revid', $revId ] );
758  }
759  } else {
760  $this->content = $page->getContent( RevisionRecord::FOR_THIS_USER, $this->getUser() );
761  if ( !$this->content ) {
762  $this->dieWithError( [ 'apierror-missingcontent-pageid', $page->getId() ] );
763  }
764  }
765  $this->contentIsDeleted = $isDeleted;
766  $this->contentIsSuppressed = $rev &&
767  $rev->isDeleted( RevisionRecord::DELETED_TEXT | RevisionRecord::DELETED_RESTRICTED );
768  }
769 
770  if ( $this->section !== false ) {
771  $this->content = $this->getSectionContent(
772  $this->content,
773  $pageId === null ? $page->getTitle()->getPrefixedText() : $this->msg( 'pageid', $pageId )
774  );
775  return $this->getContentParserOutput( $this->content, $page->getTitle(), $revId, $popts );
776  }
777 
778  if ( $isDeleted ) {
779  // getParserOutput can't do revdeled revisions
780 
781  $pout = $this->getContentParserOutput( $this->content, $page->getTitle(), $revId, $popts );
782  } else {
783  // getParserOutput will save to Parser cache if able
784  $pout = $this->getPageParserOutput( $page, $revId, $popts, $suppressCache );
785  }
786  if ( !$pout ) {
787  // @codeCoverageIgnoreStart
788  $this->dieWithError( [ 'apierror-nosuchrevid', $revId ?: $page->getLatest() ] );
789  // @codeCoverageIgnoreEnd
790  }
791 
792  return $pout;
793  }
794 
802  private function getSectionContent( Content $content, $what ) {
803  // Not cached (save or load)
804  $section = $content->getSection( $this->section );
805  if ( $section === false ) {
806  $this->dieWithError( [ 'apierror-nosuchsection-what', $this->section, $what ], 'nosuchsection' );
807  }
808  if ( $section === null ) {
809  $this->dieWithError( [ 'apierror-sectionsnotsupported-what', $what ], 'nosuchsection' );
810  }
811 
812  return $section;
813  }
814 
822  private function formatSummary( $title, $params ) {
823  $summary = $params['summary'] ?? '';
824  $sectionTitle = $params['sectiontitle'] ?? '';
825 
826  if ( $this->section === 'new' && ( $sectionTitle === '' || $summary === '' ) ) {
827  if ( $sectionTitle !== '' ) {
828  $summary = $params['sectiontitle'];
829  }
830  if ( $summary !== '' ) {
831  $summary = wfMessage( 'newsectionsummary' )
832  ->rawParams( $this->parser->stripSectionName( $summary ) )
833  ->inContentLanguage()->text();
834  }
835  }
836  return $this->commentFormatter->format( $summary, $title, $this->section === 'new' );
837  }
838 
839  private function formatLangLinks( $links ) {
840  $result = [];
841  foreach ( $links as $link ) {
842  $entry = [];
843  $bits = explode( ':', $link, 2 );
844  $title = Title::newFromText( $link );
845 
846  $entry['lang'] = $bits[0];
847  if ( $title ) {
848  $entry['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
849  // localised language name in 'uselang' language
850  $entry['langname'] = $this->languageNameUtils->getLanguageName(
851  $title->getInterwiki(),
852  $this->getLanguage()->getCode()
853  );
854 
855  // native language name
856  $entry['autonym'] = $this->languageNameUtils->getLanguageName( $title->getInterwiki() );
857  }
858  ApiResult::setContentValue( $entry, 'title', $bits[1] );
859  $result[] = $entry;
860  }
861 
862  return $result;
863  }
864 
865  private function formatCategoryLinks( $links ) {
866  $result = [];
867 
868  if ( !$links ) {
869  return $result;
870  }
871 
872  // Fetch hiddencat property
873  $lb = $this->linkBatchFactory->newLinkBatch();
874  $lb->setArray( [ NS_CATEGORY => $links ] );
875  $db = $this->getDB();
876  $res = $db->select( [ 'page', 'page_props' ],
877  [ 'page_title', 'pp_propname' ],
878  $lb->constructSet( 'page', $db ),
879  __METHOD__,
880  [],
881  [ 'page_props' => [
882  'LEFT JOIN', [ 'pp_propname' => 'hiddencat', 'pp_page = page_id' ]
883  ] ]
884  );
885  $hiddencats = [];
886  foreach ( $res as $row ) {
887  $hiddencats[$row->page_title] = isset( $row->pp_propname );
888  }
889 
890  foreach ( $links as $link => $sortkey ) {
891  $entry = [];
892  $entry['sortkey'] = $sortkey;
893  // array keys will cast numeric category names to ints, so cast back to string
894  ApiResult::setContentValue( $entry, 'category', (string)$link );
895  if ( !isset( $hiddencats[$link] ) ) {
896  $entry['missing'] = true;
897 
898  // We already know the link doesn't exist in the database, so
899  // tell LinkCache that before calling $title->isKnown().
900  $title = Title::makeTitle( NS_CATEGORY, $link );
901  $this->linkCache->addBadLinkObj( $title );
902  if ( $title->isKnown() ) {
903  $entry['known'] = true;
904  }
905  } elseif ( $hiddencats[$link] ) {
906  $entry['hidden'] = true;
907  }
908  $result[] = $entry;
909  }
910 
911  return $result;
912  }
913 
914  private function formatLinks( $links ) {
915  $result = [];
916  foreach ( $links as $ns => $nslinks ) {
917  foreach ( $nslinks as $title => $id ) {
918  $entry = [];
919  $entry['ns'] = $ns;
920  ApiResult::setContentValue( $entry, 'title', Title::makeTitle( $ns, $title )->getFullText() );
921  $entry['exists'] = $id != 0;
922  $result[] = $entry;
923  }
924  }
925 
926  return $result;
927  }
928 
929  private function formatIWLinks( $iw ) {
930  $result = [];
931  foreach ( $iw as $prefix => $titles ) {
932  foreach ( array_keys( $titles ) as $title ) {
933  $entry = [];
934  $entry['prefix'] = $prefix;
935 
936  $title = Title::newFromText( "{$prefix}:{$title}" );
937  if ( $title ) {
938  $entry['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
939  }
940 
941  ApiResult::setContentValue( $entry, 'title', $title->getFullText() );
942  $result[] = $entry;
943  }
944  }
945 
946  return $result;
947  }
948 
949  private function formatHeadItems( $headItems ) {
950  $result = [];
951  foreach ( $headItems as $tag => $content ) {
952  $entry = [];
953  $entry['tag'] = $tag;
954  ApiResult::setContentValue( $entry, 'content', $content );
955  $result[] = $entry;
956  }
957 
958  return $result;
959  }
960 
961  private function formatLimitReportData( $limitReportData ) {
962  $result = [];
963 
964  foreach ( $limitReportData as $name => $value ) {
965  $entry = [];
966  $entry['name'] = $name;
967  if ( !is_array( $value ) ) {
968  $value = [ $value ];
969  }
970  ApiResult::setIndexedTagNameRecursive( $value, 'param' );
971  $entry = array_merge( $entry, $value );
972  $result[] = $entry;
973  }
974 
975  return $result;
976  }
977 
978  private function setIndexedTagNames( &$array, $mapping ) {
979  foreach ( $mapping as $key => $name ) {
980  if ( isset( $array[$key] ) ) {
981  ApiResult::setIndexedTagName( $array[$key], $name );
982  }
983  }
984  }
985 
986  public function getAllowedParams() {
987  return [
988  'title' => null,
989  'text' => [
990  ApiBase::PARAM_TYPE => 'text',
991  ],
992  'revid' => [
993  ApiBase::PARAM_TYPE => 'integer',
994  ],
995  'summary' => null,
996  'page' => null,
997  'pageid' => [
998  ApiBase::PARAM_TYPE => 'integer',
999  ],
1000  'redirects' => false,
1001  'oldid' => [
1002  ApiBase::PARAM_TYPE => 'integer',
1003  ],
1004  'prop' => [
1005  ApiBase::PARAM_DFLT => 'text|langlinks|categories|links|templates|' .
1006  'images|externallinks|sections|revid|displaytitle|iwlinks|' .
1007  'properties|parsewarnings',
1008  ApiBase::PARAM_ISMULTI => true,
1009  ApiBase::PARAM_TYPE => [
1010  'text',
1011  'langlinks',
1012  'categories',
1013  'categorieshtml',
1014  'links',
1015  'templates',
1016  'images',
1017  'externallinks',
1018  'sections',
1019  'revid',
1020  'displaytitle',
1021  'subtitle',
1022  'headhtml',
1023  'modules',
1024  'jsconfigvars',
1025  'encodedjsconfigvars',
1026  'indicators',
1027  'iwlinks',
1028  'wikitext',
1029  'properties',
1030  'limitreportdata',
1031  'limitreporthtml',
1032  'parsetree',
1033  'parsewarnings',
1034  'parsewarningshtml',
1035  'headitems',
1036  ],
1038  'parsetree' => [ 'apihelp-parse-paramvalue-prop-parsetree', CONTENT_MODEL_WIKITEXT ],
1039  ],
1041  'headitems' => 'apiwarn-deprecation-parse-headitems',
1042  ],
1043  ],
1044  'wrapoutputclass' => 'mw-parser-output',
1045  'pst' => false,
1046  'onlypst' => false,
1047  'effectivelanglinks' => [
1048  ApiBase::PARAM_DFLT => false,
1049  ApiBase::PARAM_DEPRECATED => true,
1050  ],
1051  'section' => null,
1052  'sectiontitle' => [
1053  ApiBase::PARAM_TYPE => 'string',
1054  ],
1055  'disablepp' => [
1056  ApiBase::PARAM_DFLT => false,
1057  ApiBase::PARAM_DEPRECATED => true,
1058  ],
1059  'disablelimitreport' => false,
1060  'disableeditsection' => false,
1061  'disablestylededuplication' => false,
1062  'generatexml' => [
1063  ApiBase::PARAM_DFLT => false,
1065  'apihelp-parse-param-generatexml', CONTENT_MODEL_WIKITEXT
1066  ],
1067  ApiBase::PARAM_DEPRECATED => true,
1068  ],
1069  'preview' => false,
1070  'sectionpreview' => false,
1071  'disabletoc' => false,
1072  'useskin' => [
1073  // T237856; We use all installed skins here to allow hidden (but usable) skins
1074  // to continue working correctly with some features such as Live Preview
1075  ApiBase::PARAM_TYPE => array_keys( $this->skinFactory->getInstalledSkins() ),
1076  ],
1077  'contentformat' => [
1078  ApiBase::PARAM_TYPE => $this->contentHandlerFactory->getAllContentFormats(),
1079  ],
1080  'contentmodel' => [
1081  ApiBase::PARAM_TYPE => $this->contentHandlerFactory->getContentModels(),
1082  ],
1083  ];
1084  }
1085 
1086  protected function getExamplesMessages() {
1087  return [
1088  'action=parse&page=Project:Sandbox'
1089  => 'apihelp-parse-example-page',
1090  'action=parse&text={{Project:Sandbox}}&contentmodel=wikitext'
1091  => 'apihelp-parse-example-text',
1092  'action=parse&text={{PAGENAME}}&title=Test'
1093  => 'apihelp-parse-example-texttitle',
1094  'action=parse&summary=Some+[[link]]&prop='
1095  => 'apihelp-parse-example-summary',
1096  ];
1097  }
1098 
1099  public function getHelpUrls() {
1100  return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Parsing_wikitext#parse';
1101  }
1102 }
ApiBase\checkTitleUserPermissions
checkTitleUserPermissions( $pageIdentity, $actions, array $options=[])
Helper function for permission-denied errors.
Definition: ApiBase.php:1571
ParserOptions
Set options of the Parser.
Definition: ParserOptions.php:45
ApiMain
This is the main API class, used for both external and internal processing.
Definition: ApiMain.php:49
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:39
LinkCache
Cache for article titles (prefixed DB keys) and ids linked from one source.
Definition: LinkCache.php:41
ApiParse\formatIWLinks
formatIWLinks( $iw)
Definition: ApiParse.php:929
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: FauxRequest.php:36
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:377
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:47
ApiParse\getParsedContent
getParsedContent(WikiPage $page, $popts, $suppressCache, $pageId, $rev, $getContent)
Definition: ApiParse.php:745
MediaWiki\Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:47
ApiBase\addWarning
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
Definition: ApiBase.php:1354
WikiMap\getCurrentWikiDbDomain
static getCurrentWikiDbDomain()
Definition: WikiMap.php:293
IContextSource\getSkin
getSkin()
ApiParse\formatLangLinks
formatLangLinks( $links)
Definition: ApiParse.php:839
ApiBase\dieWithError
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition: ApiBase.php:1436
ApiBase\PARAM_HELP_MSG
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition: ApiBase.php:162
ApiParse\tweakParserOptions
tweakParserOptions(ParserOptions $popts, Title $title, array $params)
Tweaks a ParserOptions object.
Definition: ApiParse.php:720
ApiResult\META_BC_SUBELEMENTS
const META_BC_SUBELEMENTS
Key for the 'BC subelements' metadata item.
Definition: ApiResult.php:143
ApiBase\getTitleOrPageId
getTitleOrPageId( $params, $load=false)
Get a WikiPage object from a title or pageid param, if possible.
Definition: ApiBase.php:1033
ApiBase\PARAM_TYPE
const PARAM_TYPE
Definition: ApiBase.php:81
ApiParse\formatLinks
formatLinks( $links)
Definition: ApiParse.php:914
ParserOptions\setIsPreview
setIsPreview( $x)
Parsing the page for a "preview" operation?
Definition: ParserOptions.php:622
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:628
ParserOptions\setIsSectionPreview
setIsSectionPreview( $x)
Parsing the page for a "preview" operation on a single section?
Definition: ParserOptions.php:639
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:63
WikiPage\makeParserOptions
makeParserOptions( $context)
Get parser options suitable for rendering the primary article wikitext.
Definition: WikiPage.php:2011
ParserOptions\setWrapOutputClass
setWrapOutputClass( $className)
CSS class to use to wrap output from Parser::parse()
Definition: ParserOptions.php:827
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1167
ApiBase\getDB
getDB()
Gets a default replica DB connection object.
Definition: ApiBase.php:651
ApiParse\$pstContent
Content null $pstContent
Definition: ApiParse.php:47
PoolCounterWorkViaCallback
Convenience class for dealing with PoolCounters using callbacks.
Definition: PoolCounterWorkViaCallback.php:31
ApiParse\$contentIsDeleted
bool $contentIsDeleted
Definition: ApiParse.php:50
$res
$res
Definition: testCompression.php:57
ContextSource\getUser
getUser()
Definition: ContextSource.php:136
MediaWiki\CommentFormatter\CommentFormatter
This is the main service interface for converting single-line comments from various DB comment fields...
Definition: CommentFormatter.php:16
ApiBase\PARAM_DEPRECATED_VALUES
const PARAM_DEPRECATED_VALUES
Definition: ApiBase.php:129
Page\PageReference
Interface for objects (potentially) representing a page that can be viewable and linked to on a wiki.
Definition: PageReference.php:49
FormatJson\ALL_OK
const ALL_OK
Skip escaping as many characters as reasonably possible.
Definition: FormatJson.php:55
MediaWiki\Revision\RevisionLookup
Service for looking up page revisions.
Definition: RevisionLookup.php:38
ApiPageSet
This class contains a list of pages that the client has requested.
Definition: ApiPageSet.php:45
ApiParse\$parser
Parser $parser
Definition: ApiParse.php:71
ApiBase
This abstract class implements many basic API functions, and is the base of all API classes.
Definition: ApiBase.php:55
MediaWiki\Languages\LanguageNameUtils
A service that provides utilities to do with language names and codes.
Definition: LanguageNameUtils.php:43
ApiParse\getPageParserOutput
getPageParserOutput(WikiPage $page, $revId, ParserOptions $popts, bool $suppressCache)
Definition: ApiParse.php:158
ApiResult\setContentValue
static setContentValue(array &$arr, $name, $value, $flags=0)
Add an output value to the array by name and mark as META_CONTENT.
Definition: ApiResult.php:466
ApiBase\PARAM_DEPRECATED
const PARAM_DEPRECATED
Definition: ApiBase.php:101
DerivativeContext
An IContextSource implementation which will inherit context from another source but allow individual ...
Definition: DerivativeContext.php:32
ApiParse
Definition: ApiParse.php:38
FormatJson\encode
static encode( $value, $pretty=false, $escaping=0)
Returns the JSON representation of a value.
Definition: FormatJson.php:96
ApiResult\setArrayType
static setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
Definition: ApiResult.php:715
ApiParse\getHelpUrls
getHelpUrls()
Return links to more detailed help pages about the module.
Definition: ApiParse.php:1099
ApiParse\__construct
__construct(ApiMain $main, $action, RevisionLookup $revisionLookup, SkinFactory $skinFactory, LanguageNameUtils $languageNameUtils, LinkBatchFactory $linkBatchFactory, LinkCache $linkCache, IContentHandlerFactory $contentHandlerFactory, Parser $parser, WikiPageFactory $wikiPageFactory, ContentRenderer $contentRenderer, ContentTransformer $contentTransformer, CommentFormatter $commentFormatter)
Definition: ApiParse.php:100
Content\getSection
getSection( $sectionId)
Returns the section with the given ID.
ApiResult\addMetadataToResultVars
static addMetadataToResultVars( $vars, $forceHash=true)
Add the correct metadata to an array of vars we want to export through the API.
Definition: ApiResult.php:1139
Skin\normalizeKey
static normalizeKey( $key)
Normalize a skin preference value to a form that can be loaded.
Definition: Skin.php:209
ApiParse\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiParse.php:986
PoolCounterWork\execute
execute( $skipcache=false)
Get the result of the work (whatever it is), or the result of the error() function.
Definition: PoolCounterWork.php:127
ApiResult\META_SUBELEMENTS
const META_SUBELEMENTS
Key for the 'subelements' metadata item.
Definition: ApiResult.php:78
ApiParse\formatLimitReportData
formatLimitReportData( $limitReportData)
Definition: ApiParse.php:961
MediaWiki\Cache\LinkBatchFactory
Definition: LinkBatchFactory.php:39
EditPage\getPreviewLimitReport
static getPreviewLimitReport(ParserOutput $output=null)
Get the Limit report for page previews.
Definition: EditPage.php:3832
WikiPage\getTitle
getTitle()
Get the title object of the article.
Definition: WikiPage.php:314
MWContentSerializationException
Exception representing a failure to serialize or unserialize a content object.
Definition: MWContentSerializationException.php:8
ApiParse\$contentHandlerFactory
IContentHandlerFactory $contentHandlerFactory
Definition: ApiParse.php:68
MediaWiki\Content\Transform\ContentTransformer
A service to transform content.
Definition: ContentTransformer.php:15
Page\WikiPageFactory
Definition: WikiPageFactory.php:19
ApiBase\extractRequestParams
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:764
ParserOptions\newCanonical
static newCanonical( $context, $userLang=null)
Creates a "canonical" ParserOptions object.
Definition: ParserOptions.php:1089
$title
$title
Definition: testCompression.php:38
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:648
ApiParse\$linkBatchFactory
LinkBatchFactory $linkBatchFactory
Definition: ApiParse.php:62
ApiMessage\create
static create( $msg, $code=null, array $data=null)
Create an IApiMessage for the message.
Definition: ApiMessage.php:43
MediaWiki\Content\Renderer\ContentRenderer
A service to render content.
Definition: ContentRenderer.php:15
ApiParse\formatSummary
formatSummary( $title, $params)
This mimics the behavior of EditPage in formatting a summary.
Definition: ApiParse.php:822
OutputPage
This is one of the Core classes and should be read at least once by any new developers.
Definition: OutputPage.php:50
ContentHandler\makeContent
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
Definition: ContentHandler.php:149
$wgTitle
$wgTitle
Definition: Setup.php:879
PROTO_CURRENT
const PROTO_CURRENT
Definition: Defines.php:195
ApiParse\formatCategoryLinks
formatCategoryLinks( $links)
Definition: ApiParse.php:865
ContextSource\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:197
WikiPage\getId
getId( $wikiId=self::LOCAL)
Definition: WikiPage.php:587
ApiResult\setIndexedTagName
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Definition: ApiResult.php:603
ApiParse\$revisionLookup
RevisionLookup $revisionLookup
Definition: ApiParse.php:53
WikiPage\getContent
getContent( $audience=RevisionRecord::FOR_PUBLIC, Authority $performer=null)
Get the content of the current revision.
Definition: WikiPage.php:840
ApiBase\requireMaxOneParameter
requireMaxOneParameter( $params,... $required)
Die if more than one of a certain set of parameters is set and not false.
Definition: ApiBase.php:936
MediaWiki\Content\IContentHandlerFactory
Definition: IContentHandlerFactory.php:10
SkinFactory
Factory class to create Skin objects.
Definition: SkinFactory.php:31
ApiParse\setIndexedTagNames
setIndexedTagNames(&$array, $mapping)
Definition: ApiParse.php:978
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1440
ApiParse\getContentParserOutput
getContentParserOutput(Content $content, PageReference $page, $revId, ParserOptions $popts)
Definition: ApiParse.php:139
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:208
Parser
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
Definition: Parser.php:91
Title\newFromLinkTarget
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Definition: Title.php:289
Parser\OT_PREPROCESS
const OT_PREPROCESS
Definition: Parser.php:126
Content
Base interface for content objects.
Definition: Content.php:35
ApiParse\$section
string false null $section
Definition: ApiParse.php:41
Title
Represents a title within MediaWiki.
Definition: Title.php:47
ApiParse\$languageNameUtils
LanguageNameUtils $languageNameUtils
Definition: ApiParse.php:59
ApiParse\getPoolKey
getPoolKey()
Definition: ApiParse.php:129
ApiBase\PARAM_DFLT
const PARAM_DFLT
Definition: ApiBase.php:73
ApiParse\$contentRenderer
ContentRenderer $contentRenderer
Definition: ApiParse.php:83
ApiParse\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiParse.php:1086
ApiParse\$commentFormatter
CommentFormatter $commentFormatter
Definition: ApiParse.php:80
ApiBase\dieWithException
dieWithException(Throwable $exception, array $options=[])
Abort execution with an error derived from a throwable.
Definition: ApiBase.php:1449
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:497
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
Definition: ApiBase.php:77
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:78
ApiParse\getSectionContent
getSectionContent(Content $content, $what)
Extract the requested section from the given Content.
Definition: ApiParse.php:802
WikiPage\getLatest
getLatest( $wikiId=self::LOCAL)
Get the page_latest field.
Definition: WikiPage.php:755
ApiParse\$wikiPageFactory
WikiPageFactory $wikiPageFactory
Definition: ApiParse.php:74
ApiBase\getMain
getMain()
Get the main module.
Definition: ApiBase.php:513
ApiParse\$content
Content null $content
Definition: ApiParse.php:44
ApiParse\$linkCache
LinkCache $linkCache
Definition: ApiParse.php:65
ApiParse\formatHeadItems
formatHeadItems( $headItems)
Definition: ApiParse.php:949
RawMessage
Variant of the Message class.
Definition: RawMessage.php:35
ApiResult\setIndexedTagNameRecursive
static setIndexedTagNameRecursive(array &$arr, $tag)
Set indexed tag name on $arr and all subarrays.
Definition: ApiResult.php:628
ApiBase\PARAM_HELP_MSG_PER_VALUE
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
Definition: ApiBase.php:195
ApiBase\getHookRunner
getHookRunner()
Get an ApiHookRunner for running core API hooks.
Definition: ApiBase.php:710
ApiParse\makeParserOptions
makeParserOptions(WikiPage $pageObj, array $params)
Constructs a ParserOptions object.
Definition: ApiParse.php:706
IContextSource\getOutput
getOutput()
ApiParse\$contentTransformer
ContentTransformer $contentTransformer
Definition: ApiParse.php:77
ApiParse\$skinFactory
SkinFactory $skinFactory
Definition: ApiParse.php:56
WikiPage\getParserOutput
getParserOutput(?ParserOptions $parserOptions=null, $oldid=null, $noCache=false)
Get a ParserOutput for the given ParserOptions and revision ID.
Definition: WikiPage.php:1284
MediaWiki\Revision\SlotRecord
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:40
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:474
ApiParse\$contentIsSuppressed
bool $contentIsSuppressed
Definition: ApiParse.php:50
ApiParse\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiParse.php:177