MediaWiki  master
ApiHelp.php
Go to the documentation of this file.
1 <?php
23 use HtmlFormatter\HtmlFormatter;
28 
35 class ApiHelp extends ApiBase {
37  private $skinFactory;
38 
44  public function __construct(
45  ApiMain $main,
46  $action,
47  SkinFactory $skinFactory
48  ) {
49  parent::__construct( $main, $action );
50  $this->skinFactory = $skinFactory;
51  }
52 
53  public function execute() {
54  $params = $this->extractRequestParams();
55  $modules = [];
56 
57  foreach ( $params['modules'] as $path ) {
58  $modules[] = $this->getModuleFromPath( $path );
59  }
60 
61  // Get the help
62  $context = new DerivativeContext( $this->getMain()->getContext() );
63  $context->setSkin( $this->skinFactory->makeSkin( 'apioutput' ) );
64  $context->setLanguage( $this->getMain()->getLanguage() );
65  $context->setTitle( SpecialPage::getTitleFor( 'ApiHelp' ) );
66  $out = new OutputPage( $context );
67  $out->setRobotPolicy( 'noindex,nofollow' );
68  $out->setCopyrightUrl( 'https://www.mediawiki.org/wiki/Special:MyLanguage/Copyright' );
69  $out->disallowUserJs();
70  $context->setOutput( $out );
71 
72  self::getHelp( $context, $modules, $params );
73 
74  // Grab the output from the skin
75  ob_start();
76  $context->getOutput()->output();
77  $html = ob_get_clean();
78 
79  $result = $this->getResult();
80  if ( $params['wrap'] ) {
81  $data = [
82  'mime' => 'text/html',
83  'filename' => 'api-help.html',
84  'help' => $html,
85  ];
86  ApiResult::setSubelementsList( $data, 'help' );
87  $result->addValue( null, $this->getModuleName(), $data );
88  } else {
89  // Show any errors at the top of the HTML
90  $transform = [
91  'Types' => [ 'AssocAsObject' => true ],
92  'Strip' => 'all',
93  ];
94  $errors = array_filter( [
95  'errors' => $this->getResult()->getResultData( [ 'errors' ], $transform ),
96  'warnings' => $this->getResult()->getResultData( [ 'warnings' ], $transform ),
97  ] );
98  if ( $errors ) {
99  $json = FormatJson::encode( $errors, true, FormatJson::UTF8_OK );
100  // Escape any "--", some parsers might interpret that as end-of-comment.
101  // The above already escaped any "<" and ">".
102  $json = str_replace( '--', '-\u002D', $json );
103  $html = "<!-- API warnings and errors:\n$json\n-->\n$html";
104  }
105 
106  $result->reset();
107  $result->addValue( null, 'text', $html, ApiResult::NO_SIZE_CHECK );
108  $result->addValue( null, 'mime', 'text/html', ApiResult::NO_SIZE_CHECK );
109  $result->addValue( null, 'filename', 'api-help.html', ApiResult::NO_SIZE_CHECK );
110  }
111  }
112 
132  public static function getHelp( IContextSource $context, $modules, array $options ) {
133  if ( !is_array( $modules ) ) {
134  $modules = [ $modules ];
135  }
136 
137  $out = $context->getOutput();
138  $out->addModuleStyles( [
139  'mediawiki.hlist',
140  'mediawiki.apipretty',
141  ] );
142  $out->setPageTitle( $context->msg( 'api-help-title' ) );
143 
144  $services = MediaWikiServices::getInstance();
145  $cache = $services->getMainWANObjectCache();
146  $cacheKey = null;
147  if ( count( $modules ) == 1 && $modules[0] instanceof ApiMain &&
148  $options['recursivesubmodules'] &&
149  $context->getLanguage()->equals( $services->getContentLanguage() )
150  ) {
151  $cacheHelpTimeout = $context->getConfig()->get( MainConfigNames::APICacheHelpTimeout );
152  if ( $cacheHelpTimeout > 0 ) {
153  // Get help text from cache if present
154  $cacheKey = $cache->makeKey( 'apihelp', $modules[0]->getModulePath(),
155  (int)!empty( $options['toc'] ),
156  str_replace( ' ', '_', SpecialVersion::getVersion( 'nodb' ) ) );
157  $cached = $cache->get( $cacheKey );
158  if ( $cached ) {
159  $out->addHTML( $cached );
160  return;
161  }
162  }
163  }
164  if ( $out->getHTML() !== '' ) {
165  // Don't save to cache, there's someone else's content in the page
166  // already
167  $cacheKey = null;
168  }
169 
170  $options['recursivesubmodules'] = !empty( $options['recursivesubmodules'] );
171  $options['submodules'] = $options['recursivesubmodules'] || !empty( $options['submodules'] );
172 
173  // Prepend lead
174  if ( empty( $options['nolead'] ) ) {
175  $msg = $context->msg( 'api-help-lead' );
176  if ( !$msg->isDisabled() ) {
177  $out->addHTML( $msg->parseAsBlock() );
178  }
179  }
180 
181  $haveModules = [];
182  $html = self::getHelpInternal( $context, $modules, $options, $haveModules );
183  if ( !empty( $options['toc'] ) && $haveModules ) {
184  // @phan-suppress-next-line SecurityCheck-DoubleEscaped Triggered by Linker?
185  $out->addHTML( Linker::generateTOC( $haveModules, $context->getLanguage() ) );
186  }
187  $out->addHTML( $html );
188 
189  $helptitle = $options['helptitle'] ?? null;
190  $html = self::fixHelpLinks( $out->getHTML(), $helptitle, $haveModules );
191  $out->clearHTML();
192  $out->addHTML( $html );
193 
194  if ( $cacheKey !== null ) {
195  // @phan-suppress-next-line PhanPossiblyUndeclaredVariable $cacheHelpTimeout declared when $cacheKey is set
196  $cache->set( $cacheKey, $out->getHTML(), $cacheHelpTimeout );
197  }
198  }
199 
208  public static function fixHelpLinks( $html, $helptitle = null, $localModules = [] ) {
209  $formatter = new HtmlFormatter( $html );
210  $doc = $formatter->getDoc();
211  $xpath = new DOMXPath( $doc );
212  $nodes = $xpath->query( '//a[@href][not(contains(@class,\'apihelp-linktrail\'))]' );
214  foreach ( $nodes as $node ) {
215  $href = $node->getAttribute( 'href' );
216  do {
217  $old = $href;
218  $href = rawurldecode( $href );
219  } while ( $old !== $href );
220  if ( preg_match( '!Special:ApiHelp/([^&/|#]+)((?:#.*)?)!', $href, $m ) ) {
221  if ( isset( $localModules[$m[1]] ) ) {
222  $href = $m[2] === '' ? '#' . $m[1] : $m[2];
223  } elseif ( $helptitle !== null ) {
224  $href = Title::newFromText( str_replace( '$1', $m[1], $helptitle ) . $m[2] )
225  ->getFullURL();
226  } else {
227  $href = wfAppendQuery( wfScript( 'api' ), [
228  'action' => 'help',
229  'modules' => $m[1],
230  ] ) . $m[2];
231  }
232  $node->setAttribute( 'href', $href );
233  $node->removeAttribute( 'title' );
234  }
235  }
236 
237  return $formatter->getText();
238  }
239 
248  private static function wrap( Message $msg, $class, $tag = 'span' ) {
249  return Html::rawElement( $tag, [ 'class' => $class ],
250  $msg->parse()
251  );
252  }
253 
263  private static function getHelpInternal( IContextSource $context, array $modules,
264  array $options, &$haveModules
265  ) {
266  $out = '';
267 
268  $level = empty( $options['headerlevel'] ) ? 2 : $options['headerlevel'];
269  if ( empty( $options['tocnumber'] ) ) {
270  $tocnumber = [ 2 => 0 ];
271  } else {
272  $tocnumber = &$options['tocnumber'];
273  }
274 
275  foreach ( $modules as $module ) {
276  $paramValidator = $module->getMain()->getParamValidator();
277  $tocnumber[$level]++;
278  $path = $module->getModulePath();
279  $module->setContext( $context );
280  $help = [
281  'header' => '',
282  'flags' => '',
283  'description' => '',
284  'help-urls' => '',
285  'parameters' => '',
286  'examples' => '',
287  'submodules' => '',
288  ];
289 
290  if ( empty( $options['noheader'] ) || !empty( $options['toc'] ) ) {
291  $anchor = $path;
292  $i = 1;
293  while ( isset( $haveModules[$anchor] ) ) {
294  $anchor = $path . '|' . ++$i;
295  }
296 
297  if ( $module->isMain() ) {
298  $headerContent = $context->msg( 'api-help-main-header' )->parse();
299  $headerAttr = [
300  'class' => 'apihelp-header',
301  ];
302  } else {
303  $name = $module->getModuleName();
304  $headerContent = htmlspecialchars(
305  $module->getParent()->getModuleManager()->getModuleGroup( $name ) . "=$name"
306  );
307  if ( $module->getModulePrefix() !== '' ) {
308  $headerContent .= ' ' .
309  $context->msg( 'parentheses', $module->getModulePrefix() )->parse();
310  }
311  // Module names are always in English and not localized,
312  // so English language and direction must be set explicitly,
313  // otherwise parentheses will get broken in RTL wikis
314  $headerAttr = [
315  'class' => [ 'apihelp-header', 'apihelp-module-name' ],
316  'dir' => 'ltr',
317  'lang' => 'en',
318  ];
319  }
320 
321  $headerAttr['id'] = $anchor;
322 
323  $haveModules[$anchor] = [
324  'toclevel' => count( $tocnumber ),
325  'level' => $level,
326  'anchor' => $anchor,
327  'line' => $headerContent,
328  'number' => implode( '.', $tocnumber ),
329  'index' => false,
330  ];
331  if ( empty( $options['noheader'] ) ) {
332  $help['header'] .= Html::rawElement(
333  'h' . min( 6, $level ),
334  $headerAttr,
335  $headerContent
336  );
337  }
338  } else {
339  $haveModules[$path] = true;
340  }
341 
342  $links = [];
343  $any = false;
344  for ( $m = $module; $m !== null; $m = $m->getParent() ) {
345  $name = $m->getModuleName();
346  if ( $name === 'main_int' ) {
347  $name = 'main';
348  }
349 
350  if ( count( $modules ) === 1 && $m === $modules[0] &&
351  !( !empty( $options['submodules'] ) && $m->getModuleManager() )
352  ) {
353  $link = Html::element( 'b', [ 'dir' => 'ltr', 'lang' => 'en' ], $name );
354  } else {
355  $link = SpecialPage::getTitleFor( 'ApiHelp', $m->getModulePath() )->getLocalURL();
356  $link = Html::element( 'a',
357  [ 'href' => $link, 'class' => 'apihelp-linktrail', 'dir' => 'ltr', 'lang' => 'en' ],
358  $name
359  );
360  $any = true;
361  }
362  array_unshift( $links, $link );
363  }
364  if ( $any ) {
365  $help['header'] .= self::wrap(
366  $context->msg( 'parentheses' )
367  ->rawParams( $context->getLanguage()->pipeList( $links ) ),
368  'apihelp-linktrail', 'div'
369  );
370  }
371 
372  $flags = $module->getHelpFlags();
373  $help['flags'] .= Html::openElement( 'div',
374  [ 'class' => [ 'apihelp-block', 'apihelp-flags' ] ] );
375  $msg = $context->msg( 'api-help-flags' );
376  if ( !$msg->isDisabled() ) {
377  $help['flags'] .= self::wrap(
378  $msg->numParams( count( $flags ) ), 'apihelp-block-head', 'div'
379  );
380  }
381  $help['flags'] .= Html::openElement( 'ul' );
382  foreach ( $flags as $flag ) {
383  $help['flags'] .= Html::rawElement( 'li', [],
384  // The follow classes are used here:
385  // * apihelp-flag-generator
386  // * apihelp-flag-internal
387  // * apihelp-flag-mustbeposted
388  // * apihelp-flag-readrights
389  // * apihelp-flag-writerights
390  self::wrap( $context->msg( "api-help-flag-$flag" ), "apihelp-flag-$flag" )
391  );
392  }
393  $sourceInfo = $module->getModuleSourceInfo();
394  if ( $sourceInfo ) {
395  if ( isset( $sourceInfo['namemsg'] ) ) {
396  $extname = $context->msg( $sourceInfo['namemsg'] )->text();
397  } else {
398  // Probably English, so wrap it.
399  $extname = Html::element( 'span', [ 'dir' => 'ltr', 'lang' => 'en' ], $sourceInfo['name'] );
400  }
401  $help['flags'] .= Html::rawElement( 'li', [],
402  self::wrap(
403  $context->msg( 'api-help-source', $extname, $sourceInfo['name'] ),
404  'apihelp-source'
405  )
406  );
407 
408  $link = SpecialPage::getTitleFor( 'Version', 'License/' . $sourceInfo['name'] );
409  if ( isset( $sourceInfo['license-name'] ) ) {
410  $msg = $context->msg( 'api-help-license', $link,
411  Html::element( 'span', [ 'dir' => 'ltr', 'lang' => 'en' ], $sourceInfo['license-name'] )
412  );
413  } elseif ( ExtensionInfo::getLicenseFileNames( dirname( $sourceInfo['path'] ) ) ) {
414  $msg = $context->msg( 'api-help-license-noname', $link );
415  } else {
416  $msg = $context->msg( 'api-help-license-unknown' );
417  }
418  $help['flags'] .= Html::rawElement( 'li', [],
419  self::wrap( $msg, 'apihelp-license' )
420  );
421  } else {
422  $help['flags'] .= Html::rawElement( 'li', [],
423  self::wrap( $context->msg( 'api-help-source-unknown' ), 'apihelp-source' )
424  );
425  $help['flags'] .= Html::rawElement( 'li', [],
426  self::wrap( $context->msg( 'api-help-license-unknown' ), 'apihelp-license' )
427  );
428  }
429  $help['flags'] .= Html::closeElement( 'ul' );
430  $help['flags'] .= Html::closeElement( 'div' );
431 
432  foreach ( $module->getFinalDescription() as $msg ) {
433  $msg->setContext( $context );
434  $help['description'] .= $msg->parseAsBlock();
435  }
436 
437  $urls = $module->getHelpUrls();
438  if ( $urls ) {
439  if ( !is_array( $urls ) ) {
440  $urls = [ $urls ];
441  }
442  $help['help-urls'] .= Html::openElement( 'div',
443  [ 'class' => [ 'apihelp-block', 'apihelp-help-urls' ] ]
444  );
445  $msg = $context->msg( 'api-help-help-urls' );
446  if ( !$msg->isDisabled() ) {
447  $help['help-urls'] .= self::wrap(
448  $msg->numParams( count( $urls ) ), 'apihelp-block-head', 'div'
449  );
450  }
451  $help['help-urls'] .= Html::openElement( 'ul' );
452  foreach ( $urls as $url ) {
453  $help['help-urls'] .= Html::rawElement( 'li', [],
454  Html::element( 'a', [ 'href' => $url, 'dir' => 'ltr' ], $url )
455  );
456  }
457  $help['help-urls'] .= Html::closeElement( 'ul' );
458  $help['help-urls'] .= Html::closeElement( 'div' );
459  }
460 
461  $params = $module->getFinalParams( ApiBase::GET_VALUES_FOR_HELP );
462  $dynamicParams = $module->dynamicParameterDocumentation();
463  $groups = [];
464  if ( $params || $dynamicParams !== null ) {
465  $help['parameters'] .= Html::openElement( 'div',
466  [ 'class' => [ 'apihelp-block', 'apihelp-parameters' ] ]
467  );
468  $msg = $context->msg( 'api-help-parameters' );
469  if ( !$msg->isDisabled() ) {
470  $help['parameters'] .= self::wrap(
471  $msg->numParams( count( $params ) ), 'apihelp-block-head', 'div'
472  );
473  }
474  $help['parameters'] .= Html::openElement( 'dl' );
475 
476  $descriptions = $module->getFinalParamDescription();
477 
478  foreach ( $params as $name => $settings ) {
479  $settings = $paramValidator->normalizeSettings( $settings );
480 
481  if ( $settings[ParamValidator::PARAM_TYPE] === 'submodule' ) {
482  $groups[] = $name;
483  }
484 
485  $help['parameters'] .= Html::rawElement( 'dt', [],
486  Html::element( 'span', [ 'dir' => 'ltr', 'lang' => 'en' ], $module->encodeParamName( $name ) )
487  );
488 
489  // Add description
490  $description = [];
491  if ( isset( $descriptions[$name] ) ) {
492  foreach ( $descriptions[$name] as $msg ) {
493  $msg->setContext( $context );
494  $description[] = $msg->parseAsBlock();
495  }
496  }
497  if ( !array_filter( $description ) ) {
498  $description = [ self::wrap(
499  $context->msg( 'api-help-param-no-description' ),
500  'apihelp-empty'
501  ) ];
502  }
503 
504  // Add "deprecated" flag
505  if ( !empty( $settings[ParamValidator::PARAM_DEPRECATED] ) ) {
506  $help['parameters'] .= Html::openElement( 'dd',
507  [ 'class' => 'info' ] );
508  $help['parameters'] .= self::wrap(
509  $context->msg( 'api-help-param-deprecated' ),
510  'apihelp-deprecated', 'strong'
511  );
512  $help['parameters'] .= Html::closeElement( 'dd' );
513  }
514 
515  if ( $description ) {
516  $description = implode( '', $description );
517  $description = preg_replace( '!\s*</([oud]l)>\s*<\1>\s*!', "\n", $description );
518  $help['parameters'] .= Html::rawElement( 'dd',
519  [ 'class' => 'description' ], $description );
520  }
521 
522  // Add usage info
523  $info = [];
524  $paramHelp = $paramValidator->getHelpInfo( $module, $name, $settings, [] );
525 
526  unset( $paramHelp[ParamValidator::PARAM_DEPRECATED] );
527 
528  if ( isset( $paramHelp[ParamValidator::PARAM_REQUIRED] ) ) {
529  $paramHelp[ParamValidator::PARAM_REQUIRED]->setContext( $context );
530  $info[] = $paramHelp[ParamValidator::PARAM_REQUIRED];
531  unset( $paramHelp[ParamValidator::PARAM_REQUIRED] );
532  }
533 
534  // Custom info?
535  if ( !empty( $settings[ApiBase::PARAM_HELP_MSG_INFO] ) ) {
536  foreach ( $settings[ApiBase::PARAM_HELP_MSG_INFO] as $i ) {
537  $tag = array_shift( $i );
538  $info[] = $context->msg( "apihelp-{$path}-paraminfo-{$tag}" )
539  ->numParams( count( $i ) )
540  ->params( $context->getLanguage()->commaList( $i ) )
541  ->params( $module->getModulePrefix() )
542  ->parse();
543  }
544  }
545 
546  // Templated?
547  if ( !empty( $settings[ApiBase::PARAM_TEMPLATE_VARS] ) ) {
548  $vars = [];
549  $msg = 'api-help-param-templated-var-first';
550  foreach ( $settings[ApiBase::PARAM_TEMPLATE_VARS] as $k => $v ) {
551  $vars[] = $context->msg( $msg, $k, $module->encodeParamName( $v ) );
552  $msg = 'api-help-param-templated-var';
553  }
554  $info[] = $context->msg( 'api-help-param-templated' )
555  ->numParams( count( $vars ) )
556  ->params( Message::listParam( $vars ) )
557  ->parse();
558  }
559 
560  // Type documentation
561  foreach ( $paramHelp as $m ) {
562  $m->setContext( $context );
563  $info[] = $m;
564  }
565 
566  foreach ( $info as $i ) {
567  $help['parameters'] .= Html::rawElement( 'dd', [ 'class' => 'info' ], $i );
568  }
569  }
570 
571  if ( $dynamicParams !== null ) {
572  $dynamicParams = ApiBase::makeMessage( $dynamicParams, $context, [
573  $module->getModulePrefix(),
574  $module->getModuleName(),
575  $module->getModulePath()
576  ] );
577  $help['parameters'] .= Html::element( 'dt', [], '*' );
578  $help['parameters'] .= Html::rawElement( 'dd',
579  [ 'class' => 'description' ], $dynamicParams->parse() );
580  }
581 
582  $help['parameters'] .= Html::closeElement( 'dl' );
583  $help['parameters'] .= Html::closeElement( 'div' );
584  }
585 
586  $examples = $module->getExamplesMessages();
587  if ( $examples ) {
588  $help['examples'] .= Html::openElement( 'div',
589  [ 'class' => [ 'apihelp-block', 'apihelp-examples' ] ] );
590  $msg = $context->msg( 'api-help-examples' );
591  if ( !$msg->isDisabled() ) {
592  $help['examples'] .= self::wrap(
593  $msg->numParams( count( $examples ) ), 'apihelp-block-head', 'div'
594  );
595  }
596 
597  $help['examples'] .= Html::openElement( 'dl' );
598  foreach ( $examples as $qs => $msg ) {
599  $msg = ApiBase::makeMessage( $msg, $context, [
600  $module->getModulePrefix(),
601  $module->getModuleName(),
602  $module->getModulePath()
603  ] );
604 
605  $link = wfAppendQuery( wfScript( 'api' ), $qs );
606  $sandbox = SpecialPage::getTitleFor( 'ApiSandbox' )->getLocalURL() . '#' . $qs;
607  $help['examples'] .= Html::rawElement( 'dt', [], $msg->parse() );
608  $help['examples'] .= Html::rawElement( 'dd', [],
609  Html::element( 'a', [
610  'href' => $link,
611  'dir' => 'ltr',
612  'rel' => 'nofollow',
613  ], "api.php?$qs" ) . ' ' .
614  Html::rawElement( 'a', [ 'href' => $sandbox ],
615  $context->msg( 'api-help-open-in-apisandbox' )->parse() )
616  );
617  }
618  $help['examples'] .= Html::closeElement( 'dl' );
619  $help['examples'] .= Html::closeElement( 'div' );
620  }
621 
622  $subtocnumber = $tocnumber;
623  $subtocnumber[$level + 1] = 0;
624  $suboptions = [
625  'submodules' => $options['recursivesubmodules'],
626  'headerlevel' => $level + 1,
627  'tocnumber' => &$subtocnumber,
628  'noheader' => false,
629  ] + $options;
630 
631  // @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset False positive
632  if ( $options['submodules'] && $module->getModuleManager() ) {
633  $manager = $module->getModuleManager();
634  $submodules = [];
635  foreach ( $groups as $group ) {
636  $names = $manager->getNames( $group );
637  sort( $names );
638  foreach ( $names as $name ) {
639  $submodules[] = $manager->getModule( $name );
640  }
641  }
642  $help['submodules'] .= self::getHelpInternal(
643  $context,
644  $submodules,
645  $suboptions,
646  $haveModules
647  );
648  }
649 
650  $module->modifyHelp( $help, $suboptions, $haveModules );
651 
652  $module->getHookRunner()->onAPIHelpModifyOutput( $module, $help,
653  $suboptions, $haveModules );
654 
655  $out .= implode( "\n", $help );
656  }
657 
658  return $out;
659  }
660 
661  public function shouldCheckMaxlag() {
662  return false;
663  }
664 
665  public function isReadMode() {
666  return false;
667  }
668 
669  public function getCustomPrinter() {
670  $params = $this->extractRequestParams();
671  if ( $params['wrap'] ) {
672  return null;
673  }
674 
675  $main = $this->getMain();
676  $errorPrinter = $main->createPrinterByName( $main->getParameter( 'format' ) );
677  return new ApiFormatRaw( $main, $errorPrinter );
678  }
679 
680  public function getAllowedParams() {
681  return [
682  'modules' => [
683  ParamValidator::PARAM_DEFAULT => 'main',
684  ParamValidator::PARAM_ISMULTI => true,
685  ],
686  'submodules' => false,
687  'recursivesubmodules' => false,
688  'wrap' => false,
689  'toc' => false,
690  ];
691  }
692 
693  protected function getExamplesMessages() {
694  return [
695  'action=help'
696  => 'apihelp-help-example-main',
697  'action=help&modules=query&submodules=1'
698  => 'apihelp-help-example-submodules',
699  'action=help&recursivesubmodules=1'
700  => 'apihelp-help-example-recursive',
701  'action=help&modules=help'
702  => 'apihelp-help-example-help',
703  'action=help&modules=query+info|query+categorymembers'
704  => 'apihelp-help-example-query',
705  ];
706  }
707 
708  public function getHelpUrls() {
709  return [
710  'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Main_page',
711  'https://www.mediawiki.org/wiki/Special:MyLanguage/API:FAQ',
712  'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Quick_start_guide',
713  ];
714  }
715 }
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
$modules
This abstract class implements many basic API functions, and is the base of all API classes.
Definition: ApiBase.php:57
getModuleFromPath( $path)
Get a module from its module path.
Definition: ApiBase.php:592
static makeMessage( $msg, IContextSource $context, array $params=null)
Create a Message from a string or array.
Definition: ApiBase.php:1222
getMain()
Get the main module.
Definition: ApiBase.php:515
const PARAM_HELP_MSG_INFO
(array) Specify additional information tags for the parameter.
Definition: ApiBase.php:181
const PARAM_TEMPLATE_VARS
(array) Indicate that this is a templated parameter, and specify replacements.
Definition: ApiBase.php:215
getResult()
Get the result object.
Definition: ApiBase.php:630
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:766
getModulePath()
Get the path to this module.
Definition: ApiBase.php:574
const GET_VALUES_FOR_HELP
getAllowedParams() flag: When set, the result could take longer to generate, but should be more thoro...
Definition: ApiBase.php:235
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:499
Formatter that spits out anything you like with any desired MIME type.
Class to output help for an API module.
Definition: ApiHelp.php:35
isReadMode()
Indicates whether this module requires read rights.
Definition: ApiHelp.php:665
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiHelp.php:53
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiHelp.php:693
static fixHelpLinks( $html, $helptitle=null, $localModules=[])
Replace Special:ApiHelp links with links to api.php.
Definition: ApiHelp.php:208
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiHelp.php:680
getHelpUrls()
Return links to more detailed help pages about the module.
Definition: ApiHelp.php:708
static getHelp(IContextSource $context, $modules, array $options)
Generate help for the specified modules.
Definition: ApiHelp.php:132
shouldCheckMaxlag()
Indicates if this module needs maxlag to be checked.
Definition: ApiHelp.php:661
__construct(ApiMain $main, $action, SkinFactory $skinFactory)
Definition: ApiHelp.php:44
getCustomPrinter()
If the module may only be used with a certain format module, it should override this method to return...
Definition: ApiHelp.php:669
This is the main API class, used for both external and internal processing.
Definition: ApiMain.php:55
const NO_SIZE_CHECK
For addValue() and similar functions, do not check size while adding a value Don't use this unless yo...
Definition: ApiResult.php:58
static setSubelementsList(array &$arr, $names)
Causes the elements with the specified names to be output as subelements rather than attributes.
Definition: ApiResult.php:553
getContext()
Get the base IContextSource object.
An IContextSource implementation which will inherit context from another source but allow individual ...
const UTF8_OK
Skip escaping most characters above U+007F for readability and compactness.
Definition: FormatJson.php:34
static encode( $value, $pretty=false, $escaping=0)
Returns the JSON representation of a value.
Definition: FormatJson.php:96
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:236
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:214
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:256
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:320
static generateTOC( $tree, Language $lang=null)
Definition: Linker.php:1682
A class containing constants representing the names of configuration variables.
Service locator for MediaWiki core services.
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition: Message.php:142
static listParam(array $list, $type='text')
Definition: Message.php:1276
parse()
Fully parse the text from wikitext to HTML.
Definition: Message.php:1040
This is one of the Core classes and should be read at least once by any new developers.
Definition: OutputPage.php:56
Factory class to create Skin objects.
Definition: SkinFactory.php:31
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
static getVersion( $flags='', $lang=null)
Return a string of the MediaWiki version with Git revision if available.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:373
Service for formatting and validating API parameters.
Interface for objects which can provide a MediaWiki context on request.
getConfig()
Get the site configuration.
msg( $key,... $params)
This is the method for getting translated interface messages.
$cache
Definition: mcc.php:33
$help
Definition: mcc.php:32
return true
Definition: router.php:90