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;
43 public function __construct(
46 parent
::__construct( 'ApiHelp' );
47 $this->urlUtils
= $urlUtils;
50 public function execute( $par ) {
51 $this->getOutput()->addModuleStyles( 'mediawiki.codex.messagebox.styles' );
56 // These come from transclusions
57 $request = $this->getRequest();
61 'submodules' => $request->getCheck( 'submodules' ),
62 'recursivesubmodules' => $request->getCheck( 'recursivesubmodules' ),
63 'title' => $request->getVal( 'title', $this->getPageTitle( '$1' )->getPrefixedText() ),
66 // These are for linking from wikitext, since url parameters are a pain
69 if ( str_starts_with( $par, 'sub/' ) ) {
70 $par = substr( $par, 4 );
71 $options['submodules'] = 1;
75 if ( str_starts_with( $par, 'rsub/' ) ) {
76 $par = substr( $par, 5 );
77 $options['recursivesubmodules'] = 1;
84 if ( !isset( $moduleName ) ) {
85 throw new LogicException( 'Module name should have been found' );
88 if ( !$this->including() ) {
89 unset( $options['nolead'], $options['title'] );
90 $options['modules'] = $moduleName;
91 $link = wfAppendQuery( (string)$this->urlUtils
->expand( wfScript( 'api' ), PROTO_CURRENT
), $options );
92 $this->getOutput()->redirect( $link );
96 $main = new ApiMain( $this->getContext(), false );
98 $module = $main->getModuleFromPath( $moduleName );
99 } catch ( ApiUsageException
$ex ) {
100 $this->getOutput()->addHTML( Html
::errorBox(
101 $this->msg( 'apihelp-no-such-module', $moduleName )->inContentLanguage()->parse()
106 ApiHelp
::getHelp( $this->getContext(), $module, $options );
109 public function isIncludable() {
114 /** @deprecated class alias since 1.41 */
115 class_alias( SpecialApiHelp
::class, 'SpecialApiHelp' );