| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Specials; |
| 22 |
|
| 23 |
use MediaWiki\Api\ApiHelp; |
| 24 |
use MediaWiki\Api\ApiMain; |
| 25 |
use MediaWiki\Api\ApiUsageException; |
| 26 |
use MediaWiki\Html\Html; |
| 27 |
use MediaWiki\SpecialPage\UnlistedSpecialPage; |
| 28 |
use MediaWiki\Utils\UrlUtils; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
class SpecialApiHelp extends UnlistedSpecialPage { |
| 39 |
|
| 40 |
private UrlUtils $urlUtils; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public function __construct( |
| 46 |
UrlUtils $urlUtils |
| 47 |
) { |
| 48 |
parent::__construct( 'ApiHelp' ); |
| 49 |
$this->urlUtils = $urlUtils; |
| 50 |
} |
| 51 |
|
| 52 |
public function execute( $par ) { |
| 53 |
if ( !$par ) { |
| 54 |
$par = 'main'; |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
$request = $this->getRequest(); |
| 59 |
$options = [ |
| 60 |
'action' => 'help', |
| 61 |
'nolead' => true, |
| 62 |
'submodules' => $request->getCheck( 'submodules' ), |
| 63 |
'recursivesubmodules' => $request->getCheck( 'recursivesubmodules' ), |
| 64 |
'title' => $request->getVal( 'title', $this->getPageTitle( '$1' )->getPrefixedText() ), |
| 65 |
]; |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
while ( true ) { |
| 70 |
if ( str_starts_with( $par, 'sub/' ) ) { |
| 71 |
$par = substr( $par, 4 ); |
| 72 |
$options['submodules'] = 1; |
| 73 |
continue; |
| 74 |
} |
| 75 |
|
| 76 |
if ( str_starts_with( $par, 'rsub/' ) ) { |
| 77 |
$par = substr( $par, 5 ); |
| 78 |
$options['recursivesubmodules'] = 1; |
| 79 |
continue; |
| 80 |
} |
| 81 |
|
| 82 |
$moduleName = $par; |
| 83 |
break; |
| 84 |
} |
| 85 |
|
| 86 |
if ( !$this->including() ) { |
| 87 |
unset( $options['nolead'], $options['title'] ); |
| 88 |
|
| 89 |
$options['modules'] = $moduleName; |
| 90 |
$link = wfAppendQuery( (string)$this->urlUtils->expand( wfScript( 'api' ), PROTO_CURRENT ), $options ); |
| 91 |
$this->getOutput()->redirect( $link ); |
| 92 |
return; |
| 93 |
} |
| 94 |
|
| 95 |
$main = new ApiMain( $this->getContext(), false ); |
| 96 |
try { |
| 97 |
|
| 98 |
$module = $main->getModuleFromPath( $moduleName ); |
| 99 |
} catch ( ApiUsageException $ex ) { |
| 100 |
$this->getOutput()->addHTML( Html::rawElement( 'span', [ 'class' => 'error' ], |
| 101 |
|
| 102 |
$this->msg( 'apihelp-no-such-module', $moduleName )->inContentLanguage()->parse() |
| 103 |
) ); |
| 104 |
return; |
| 105 |
} |
| 106 |
|
| 107 |
ApiHelp::getHelp( $this->getContext(), $module, $options ); |
| 108 |
} |
| 109 |
|
| 110 |
public function isIncludable() { |
| 111 |
return true; |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
class_alias( SpecialApiHelp::class, 'SpecialApiHelp' ); |