Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/347609 )

Change subject: Add help button in player GUI
......................................................................

Add help button in player GUI

The button takes the user to a help page for Wikispeech. The page is
defined by the config variable `WikispeechHelpPage`, "Wikispeech_help"
by default. The button only appears if the variable is set.

Changed button tests to use stubs instead of spies, as the function
for the help button changes redirected the browser.

Bug: T151886
Change-Id: Iba29fcb7f8102bfa3f82ca62794ed6ea4cff5921
---
M Hooks.php
M extension.json
M modules/ext.wikispeech.css
M modules/ext.wikispeech.js
M tests/qunit/ext.wikispeech.test.js
5 files changed, 84 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/09/347609/1

diff --git a/Hooks.php b/Hooks.php
index 2fa1092..b5c0038 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -119,6 +119,9 @@
                global $wgWikispeechSkipBackRewindsThreshold;
                $vars['wgWikispeechSkipBackRewindsThreshold'] =
                        $wgWikispeechSkipBackRewindsThreshold;
+               global $wgWikispeechHelpPage;
+               $vars['wgWikispeechHelpPage'] =
+                       $wgWikispeechHelpPage;
                return true;
        }
 }
diff --git a/extension.json b/extension.json
index 8b1b9d1..499a0d1 100644
--- a/extension.json
+++ b/extension.json
@@ -102,6 +102,7 @@
                                "modifiers": [ "alt", "shift" ]
                        }
                },
-               "WikispeechSkipBackRewindsThreshold": 3.0
+               "WikispeechSkipBackRewindsThreshold": 3.0,
+               "WikispeechHelpPage": "Wikispeech_help"
        }
 }
diff --git a/modules/ext.wikispeech.css b/modules/ext.wikispeech.css
index 98d0148..c9777c0 100644
--- a/modules/ext.wikispeech.css
+++ b/modules/ext.wikispeech.css
@@ -32,6 +32,16 @@
        content: '\f050';
 }
 
+.ext-wikispeech-divider {
+       border-left: solid 1px rgb( 150, 150, 150 );
+       margin: 3px;
+}
+
+.ext-wikispeech-help:after {
+       font-family: 'Fontawesome';
+       content: '\f128';
+}
+
 .ext-wikispeech-control-panel {
        position: fixed;
        left: 0;
diff --git a/modules/ext.wikispeech.js b/modules/ext.wikispeech.js
index 62c9ae0..6849474 100644
--- a/modules/ext.wikispeech.js
+++ b/modules/ext.wikispeech.js
@@ -10,7 +10,9 @@
                 */
 
                this.addControlPanel = function () {
-                       $( '<div></div>' )
+                       var $controlPanel, helpPage;
+
+                       $controlPanel = $( '<div></div>' )
                                .attr( 'id', 'ext-wikispeech-control-panel' )
                                .addClass( 'ext-wikispeech-control-panel' )
                                .appendTo( '#content' );
@@ -40,6 +42,19 @@
                                'ext-wikispeech-skip-ahead-sentence',
                                self.skipAheadUtterance
                        );
+                       helpPage = mw.config.get( 'wgWikispeechHelpPage' );
+                       if ( helpPage ) {
+                               // Only add button for help page if it is 
specified in
+                               // the config.
+                               $( '<span></span>' )
+                                       .addClass( 'ext-wikispeech-divider' )
+                                       .appendTo( $controlPanel );
+                               self.addButton(
+                                       'ext-wikispeech-help-button',
+                                       'ext-wikispeech-help',
+                                       self.goToHelpPage
+                               );
+                       }
                };
 
                /**
@@ -599,6 +614,18 @@
                };
 
                /**
+                * Go to the help page.
+                *
+                * The name of the help page is specified by the config
+                * variable `WikispeechHelpPage`.
+                */
+
+               this.goToHelpPage = function () {
+                       window.location.pathname =
+                               '/wiki/' + mw.config.get( 
'wgWikispeechHelpPage' );
+               };
+
+               /**
                 * Register listeners for keyboard shortcuts.
                 */
 
diff --git a/tests/qunit/ext.wikispeech.test.js 
b/tests/qunit/ext.wikispeech.test.js
index e5fea89..64c653b 100644
--- a/tests/qunit/ext.wikispeech.test.js
+++ b/tests/qunit/ext.wikispeech.test.js
@@ -192,6 +192,34 @@
                );
        } );
 
+       QUnit.test( 'addControlPanel(): add help button if page is set', 
function ( assert ) {
+               assert.expect( 1 );
+               mw.config.set(
+                       'wgWikispeechHelpPage',
+                       'Help'
+               );
+               wikispeech.addControlPanel();
+
+               assert.strictEqual(
+                       $( '#ext-wikispeech-control-panel 
#ext-wikispeech-help-button' ).length,
+                       1
+               );
+       } );
+
+       QUnit.test( 'addControlPanel(): do not add help button if page is not 
set', function ( assert ) {
+               assert.expect( 1 );
+               mw.config.set(
+                       'wgWikispeechHelpPage',
+                       null
+               );
+               wikispeech.addControlPanel();
+
+               assert.strictEqual(
+                       $( '#ext-wikispeech-control-panel 
#ext-wikispeech-help-button' ).length,
+                       0
+               );
+       } );
+
        QUnit.test( 'Clicking play/stop button', function ( assert ) {
                testClickButton(
                        assert,
@@ -211,7 +239,7 @@
 
        function testClickButton( assert, functionName, buttonId ) {
                assert.expect( 1 );
-               sinon.spy( wikispeech, functionName );
+               sinon.stub( wikispeech, functionName );
                wikispeech.addControlPanel();
 
                $( buttonId ).click();
@@ -243,6 +271,18 @@
                );
        } );
 
+       QUnit.test( 'Clicking help button', function ( assert ) {
+               mw.config.set(
+                       'wgWikispeechHelpPage',
+                       'Help'
+               );
+               testClickButton(
+                       assert,
+                       'goToHelpPage',
+                       '#ext-wikispeech-help-button'
+               );
+       } );
+
        QUnit.test( 'playOrStop(): play', function ( assert ) {
                assert.expect( 1 );
                sinon.spy( wikispeech, 'play' );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iba29fcb7f8102bfa3f82ca62794ed6ea4cff5921
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikispeech
Gerrit-Branch: master
Gerrit-Owner: Sebastian Berlin (WMSE) <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to