Spage has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/189921

Change subject: Api help examples add links to Special:ApiSandbox
......................................................................

Api help examples add links to Special:ApiSandbox

Takes advantage of doHash() in ApiSandbox's JavaScript.

Bug: T89229
Change-Id: Ie41995753f3dda49012acd3b427a74f6ef9a9c0c
---
M RELEASE-NOTES-1.25
M includes/api/ApiHelp.php
2 files changed, 19 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/21/189921/1

diff --git a/RELEASE-NOTES-1.25 b/RELEASE-NOTES-1.25
index 3b7eef3..864d984 100644
--- a/RELEASE-NOTES-1.25
+++ b/RELEASE-NOTES-1.25
@@ -94,6 +94,8 @@
   tags.
 * Added 'ChangeTagsListActive' hook, to separate the concepts of "defined" and
   "active" formerly conflated by the 'ListDefinedTags' hook.
+* (T89229) Api help examples will link to Special:ApiSandbox if
+  $wgApiHelpMakeSandboxLinks is true and the extension is loaded.
 
 ==== External libraries ====
 * MediaWiki now requires certain external libraries to be installed. In the 
past
diff --git a/includes/api/ApiHelp.php b/includes/api/ApiHelp.php
index dd05f45..2883984 100644
--- a/includes/api/ApiHelp.php
+++ b/includes/api/ApiHelp.php
@@ -563,6 +563,10 @@
 
                        $examples = $module->getExamplesMessages();
                        if ( $examples ) {
+                               global $wgApiHelpMakeSandboxLinks;
+                               $doApiSandbox = $wgApiHelpMakeSandboxLinks and 
class_exists( 'SpecialApiSandbox' );
+                               $apiSandbox = Title::makeTitle( NS_SPECIAL, 
'ApiSandbox' );
+
                                $help['examples'] .= Html::openElement( 'div',
                                        array( 'class' => 'apihelp-block 
apihelp-examples' ) );
                                $msg = $context->msg( 'api-help-examples' );
@@ -582,9 +586,19 @@
 
                                        $link = wfAppendQuery( wfScript( 'api' 
), $qs );
                                        $help['examples'] .= Html::rawElement( 
'dt', null, $msg->parse() );
-                                       $help['examples'] .= Html::rawElement( 
'dd', null,
-                                               Html::element( 'a', array( 
'href' => $link ), "api.php?$qs" )
-                                       );
+                                       $help['examples'] .= Html::openElement( 
'dd' );
+                                       $help['examples'] .= Html::element( 
'a', array( 'href' => $link ), "api.php?$qs" );
+                                       if ( $doApiSandbox ) {
+                                               $help['examples'] .= '<br>';
+                                               $help['examples'] .= 
Html::openElement( 'small' );
+                                               $help['examples'] .= 
Html::element( 'a',
+                                                       // xxx 
Title::setFragment( '#' . $qs ) turns e.g. #action=query
+                                                       // into 
#action.3Dquery, so instead append the query string as fragment.
+                                                       array( 'href' => 
$apiSandbox->getLinkUrl() . '#' . $qs ),
+                                                       "Load this example API 
request into Special:ApiSandbox" );
+                                               $help['examples'] .= 
Html::closeElement( 'small' );
+                                       }
+                                       $help['examples'] .= 
Html::closeElement( 'dd' );
                                }
                                $help['examples'] .= Html::closeElement( 'dl' );
                                $help['examples'] .= Html::closeElement( 'div' 
);

-- 
To view, visit https://gerrit.wikimedia.org/r/189921
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie41995753f3dda49012acd3b427a74f6ef9a9c0c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Spage <sp...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to