34 parent::__construct(
'RestSandbox' );
51 return $this->moduleManager->hasApiSpecs();
59 private function getSpecUrl( array $apiSpecs,
string $apiId ): ?string {
60 if ( $apiId !==
'' ) {
61 $spec = $apiSpecs[$apiId] ??
null;
63 $spec = reset( $apiSpecs ) ?:
null;
70 return $this->urlUtils->expand( $spec[
'url'] );
76 $out = $this->getOutput();
77 $this->addHelpLink(
'Help:RestSandbox' );
79 $apiId = $this->getRequest()->getRawVal(
'api' ) ?? $subPage ??
'';
80 $apiSpecs = $this->moduleManager->getApiSpecs();
81 $specUrl = $this->getSpecUrl( $apiSpecs, $apiId );
83 $out->addJsConfigVars( [
87 $out->addModuleStyles( [
90 'mediawiki.special.restsandbox.styles'
94 $out->addHTML( Html::errorBox(
95 $out->msg(
'restsandbox-no-specs-configured' )->parse()
100 if ( $out->getLanguage()->getCode() !==
'en' ) {
101 $out->addHTML( Html::noticeBox( $out->msg(
'restsandbox-disclaimer' )->parse() ) );
104 $this->showForm( $apiSpecs, $apiId );
107 $out->addHTML( Html::errorBox(
108 $out->msg(
'restsandbox-no-such-api', $apiId )->parse()
114 'mediawiki.codex.messagebox.styles',
115 'mediawiki.special.restsandbox'
118 $out->addHTML( Html::openElement(
'div', [
'id' =>
'mw-restsandbox' ] ) );
121 $out->addHTML( Html::errorBox(
122 $out->msg(
'restsandbox-jsonly' )->parse(),
124 'mw-restsandbox-client-nojs'
128 $out->addElement(
'div', [
129 'id' =>
'mw-restsandbox-swagger-ui',
137 'class' =>
'skin-invert'
140 $out->addHTML( Html::closeElement(
'div' ) );
143 private function showForm( array $apiSpecs,
string $apiId ) {
146 foreach ( $apiSpecs as $key => $spec ) {
147 $apis[$spec[
'name']] = $key;
154 'default' => $this->msg(
'restsandbox-text' )->parseAsBlock()
159 'label-message' =>
'restsandbox-select-api',
166 'default' => $this->getPageTitle()->getPrefixedDBkey()
170 $action = $this->getPageTitle()->getLocalURL( [
'action' =>
'submit' ] );
172 $htmlForm = HTMLForm::factory(
'ooui', $formDescriptor, $this->getContext() );
173 $htmlForm->setAction( $action );
174 $htmlForm->setMethod(
'GET' );
175 $htmlForm->setId(
'mw-restsandbox-form' );
176 $htmlForm->prepareForm()->displayForm(
false );
if(!defined('MW_SETUP_CALLBACK'))
Parent class for all special pages.
getConfig()
Shortcut to get main config object.
getContentLanguage()
Shortcut to get content language.