3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
21 namespace MediaWiki\Specials
;
24 use MediaWiki\Api\ApiHelp
;
25 use MediaWiki\Api\ApiMain
;
26 use MediaWiki\Api\ApiUsageException
;
27 use MediaWiki\Html\Html
;
28 use MediaWiki\SpecialPage\UnlistedSpecialPage
;
29 use MediaWiki\Utils\UrlUtils
;
32 * Redirect to help pages served by api.php.
34 * For situations where linking to full api.php URLs is not wanted
35 * or not possible, e.g. in edit summaries.
37 * @ingroup SpecialPage
39 class SpecialApiHelp
extends UnlistedSpecialPage
{
41 private UrlUtils
$urlUtils;
44 * @param UrlUtils $urlUtils
46 public function __construct(
49 parent
::__construct( 'ApiHelp' );
50 $this->urlUtils
= $urlUtils;
53 public function execute( $par ) {
54 $this->getOutput()->addModuleStyles( 'mediawiki.codex.messagebox.styles' );
59 // These come from transclusions
60 $request = $this->getRequest();
64 'submodules' => $request->getCheck( 'submodules' ),
65 'recursivesubmodules' => $request->getCheck( 'recursivesubmodules' ),
66 'title' => $request->getVal( 'title', $this->getPageTitle( '$1' )->getPrefixedText() ),
69 // These are for linking from wikitext, since url parameters are a pain
72 if ( str_starts_with( $par, 'sub/' ) ) {
73 $par = substr( $par, 4 );
74 $options['submodules'] = 1;
78 if ( str_starts_with( $par, 'rsub/' ) ) {
79 $par = substr( $par, 5 );
80 $options['recursivesubmodules'] = 1;
87 if ( !isset( $moduleName ) ) {
88 throw new LogicException( 'Module name should have been found' );
91 if ( !$this->including() ) {
92 unset( $options['nolead'], $options['title'] );
93 $options['modules'] = $moduleName;
94 $link = wfAppendQuery( (string)$this->urlUtils
->expand( wfScript( 'api' ), PROTO_CURRENT
), $options );
95 $this->getOutput()->redirect( $link );
99 $main = new ApiMain( $this->getContext(), false );
101 $module = $main->getModuleFromPath( $moduleName );
102 } catch ( ApiUsageException
$ex ) {
103 $this->getOutput()->addHTML( Html
::errorBox(
104 $this->msg( 'apihelp-no-such-module', $moduleName )->inContentLanguage()->parse()
109 ApiHelp
::getHelp( $this->getContext(), $module, $options );
112 public function isIncludable() {
117 /** @deprecated class alias since 1.41 */
118 class_alias( SpecialApiHelp
::class, 'SpecialApiHelp' );