3 * Implements Special:ApiHelp
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup SpecialPage
25 * Special page to redirect to API help pages, for situations where linking to
26 * the api.php endpoint is not wanted.
28 * @ingroup SpecialPage
30 class SpecialApiHelp extends UnlistedSpecialPage {
31 public function __construct() {
32 parent::__construct( 'ApiHelp' );
35 public function execute( $par ) {
36 if ( empty( $par ) ) {
40 // These come from transclusions
41 $request = $this->getRequest();
45 'submodules' => $request->getCheck( 'submodules' ),
46 'recursivesubmodules' => $request->getCheck( 'recursivesubmodules' ),
47 'title' => $request->getVal( 'title', $this->getPageTitle( '$1' )->getPrefixedText() ),
50 // These are for linking from wikitext, since url parameters are a pain
53 if ( substr( $par, 0, 4 ) === 'sub/' ) {
54 $par = substr( $par, 4 );
55 $options['submodules'] = 1;
59 if ( substr( $par, 0, 5 ) === 'rsub/' ) {
60 $par = substr( $par, 5 );
61 $options['recursivesubmodules'] = 1;
69 if ( !$this->including() ) {
70 unset( $options['nolead'], $options['title'] );
71 $options['modules'] = $moduleName;
72 $link = wfAppendQuery( wfExpandUrl( wfScript( 'api' ), PROTO_CURRENT ), $options );
73 $this->getOutput()->redirect( $link );
77 $main = new ApiMain( $this->getContext(), false );
79 $module = $main->getModuleFromPath( $moduleName );
80 } catch ( ApiUsageException $ex ) {
81 $this->getOutput()->addHTML( Html::rawElement( 'span', [ 'class' => 'error' ],
82 $this->msg( 'apihelp-no-such-module', $moduleName )->inContentLanguage()->parse()
85 } catch ( UsageException $ex ) {
86 $this->getOutput()->addHTML( Html::rawElement( 'span', [ 'class' => 'error' ],
87 $this->msg( 'apihelp-no-such-module', $moduleName )->inContentLanguage()->parse()
92 ApiHelp::getHelp( $this->getContext(), $module, $options );
95 public function isIncludable() {