Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 41 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| SpecialApiHelp | |
0.00% |
0 / 40 |
|
0.00% |
0 / 3 |
110 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 38 |
|
0.00% |
0 / 1 |
72 | |||
| isIncludable | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\Specials; |
| 8 | |
| 9 | use LogicException; |
| 10 | use MediaWiki\Api\ApiHelp; |
| 11 | use MediaWiki\Api\ApiMain; |
| 12 | use MediaWiki\Api\ApiUsageException; |
| 13 | use MediaWiki\Html\Html; |
| 14 | use MediaWiki\SpecialPage\UnlistedSpecialPage; |
| 15 | use MediaWiki\Utils\UrlUtils; |
| 16 | |
| 17 | /** |
| 18 | * Redirect to help pages served by api.php. |
| 19 | * |
| 20 | * For situations where linking to full api.php URLs is not wanted |
| 21 | * or not possible, e.g. in edit summaries. |
| 22 | * |
| 23 | * @ingroup SpecialPage |
| 24 | */ |
| 25 | class SpecialApiHelp extends UnlistedSpecialPage { |
| 26 | |
| 27 | public function __construct( |
| 28 | private readonly UrlUtils $urlUtils |
| 29 | ) { |
| 30 | parent::__construct( 'ApiHelp' ); |
| 31 | } |
| 32 | |
| 33 | /** @inheritDoc */ |
| 34 | public function execute( $par ) { |
| 35 | $this->getOutput()->addModuleStyles( 'mediawiki.codex.messagebox.styles' ); |
| 36 | if ( !$par ) { |
| 37 | $par = 'main'; |
| 38 | } |
| 39 | |
| 40 | // These come from transclusions |
| 41 | $request = $this->getRequest(); |
| 42 | $options = [ |
| 43 | 'action' => 'help', |
| 44 | 'nolead' => true, |
| 45 | 'submodules' => $request->getCheck( 'submodules' ), |
| 46 | 'recursivesubmodules' => $request->getCheck( 'recursivesubmodules' ), |
| 47 | 'title' => $request->getVal( 'title', $this->getPageTitle( '$1' )->getPrefixedText() ), |
| 48 | ]; |
| 49 | |
| 50 | // These are for linking from wikitext, since url parameters are a pain |
| 51 | // to do. |
| 52 | while ( true ) { |
| 53 | if ( str_starts_with( $par, 'sub/' ) ) { |
| 54 | $par = substr( $par, 4 ); |
| 55 | $options['submodules'] = 1; |
| 56 | continue; |
| 57 | } |
| 58 | |
| 59 | if ( str_starts_with( $par, 'rsub/' ) ) { |
| 60 | $par = substr( $par, 5 ); |
| 61 | $options['recursivesubmodules'] = 1; |
| 62 | continue; |
| 63 | } |
| 64 | |
| 65 | $moduleName = $par; |
| 66 | break; |
| 67 | } |
| 68 | if ( !isset( $moduleName ) ) { |
| 69 | throw new LogicException( 'Module name should have been found' ); |
| 70 | } |
| 71 | |
| 72 | if ( !$this->including() ) { |
| 73 | unset( $options['nolead'], $options['title'] ); |
| 74 | $options['modules'] = $moduleName; |
| 75 | $link = wfAppendQuery( (string)$this->urlUtils->expand( wfScript( 'api' ), PROTO_CURRENT ), $options ); |
| 76 | $this->getOutput()->redirect( $link ); |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | $main = new ApiMain( $this->getContext(), false ); |
| 81 | try { |
| 82 | $module = $main->getModuleFromPath( $moduleName ); |
| 83 | } catch ( ApiUsageException ) { |
| 84 | $this->getOutput()->addHTML( Html::errorBox( |
| 85 | $this->msg( 'apihelp-no-such-module', $moduleName )->inContentLanguage()->parse() |
| 86 | ) ); |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | ApiHelp::getHelp( $this->getContext(), $module, $options ); |
| 91 | } |
| 92 | |
| 93 | /** @inheritDoc */ |
| 94 | public function isIncludable() { |
| 95 | return true; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | /** @deprecated class alias since 1.41 */ |
| 100 | class_alias( SpecialApiHelp::class, 'SpecialApiHelp' ); |