Mattflaschen has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/357443 )

Change subject: Handle Help:Guided tour/guider not existing, not being able to 
launch
......................................................................

Handle Help:Guided tour/guider not existing, not being able to launch

test tries to exercise all the main features, including the ability to
get the content of a tour step from a page.

However, not all wikis have this feature set up.  Rather than needing
to do a maintenance script to populate this and have wikis maintain it,
we can just skip this step if it's not present.

Similarly, the 'firstedit' tour only works on articles.  So if they're
not currently on an article, just don't demonstrate launching another
tour.

Bug: T153000
Change-Id: I089a481f7bc13263ebca8f50828b66a5d26e5c65
(cherry picked from commit b413ce11c5e3766d36386a0ec6ee6308e955fe4b)
---
M GuidedTourHooks.php
M modules/ext.guidedTour.lib/ext.guidedTour.lib.main.js
M modules/tours/onshow.js
M modules/tours/test.js
4 files changed, 92 insertions(+), 60 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GuidedTour 
refs/changes/43/357443/1

diff --git a/GuidedTourHooks.php b/GuidedTourHooks.php
index f92c4fa..db36de5 100644
--- a/GuidedTourHooks.php
+++ b/GuidedTourHooks.php
@@ -18,12 +18,17 @@
        const TOUR_PARAM = 'tour';
 
        /*
-          XXX (mattflaschen, 2012-01-02):
+          XXX (mattflaschen, 2013-01-02):
 
           wgGuidedTourHelpGuiderUrl is a hack pending forcontent messages:
           https://bugzilla.wikimedia.org/show_bug.cgi?id=25349
        */
        /**
+        * Adds the page name of a GuidedTour local documentation page,
+        * to demonstrate showing tour content from pages.
+        *
+        * If the page does not exist, it will not be set.
+        *
         * Add static config vars to startup module that will be exposed via 
mw.config.
         *
         * No value added here can depend on the page name, user, or other 
request-specific
@@ -33,8 +38,15 @@
         * @return bool
         */
        public static function onResourceLoaderGetConfigVars( &$vars ) {
-               $vars['wgGuidedTourHelpGuiderUrl'] =
-                       wfMessage( 'guidedtour-help-guider-url' 
)->inContentLanguage()->plain();
+               $pageName = wfMessage( 'guidedtour-help-guider-url' )
+                       ->inContentLanguage()->plain();
+
+               $pageTitle = Title::newFromText( $pageName );
+
+               if ( $pageTitle !== null && $pageTitle->exists() ) {
+                       $vars['wgGuidedTourHelpGuiderUrl'] = $pageName;
+               }
+
 
                return true;
        }
diff --git a/modules/ext.guidedTour.lib/ext.guidedTour.lib.main.js 
b/modules/ext.guidedTour.lib/ext.guidedTour.lib.main.js
index 38cf5d0..22aedbe 100644
--- a/modules/ext.guidedTour.lib/ext.guidedTour.lib.main.js
+++ b/modules/ext.guidedTour.lib/ext.guidedTour.lib.main.js
@@ -314,7 +314,7 @@
                        internal.loadTour( tourName ).done( function () {
                                var tour = internal.definedTours[tourName];
 
-                               if ( gt.shouldShowTour( {
+                               if ( tour && gt.shouldShowTour( {
                                        tourName: tourName,
                                        userState: getUserState(),
                                        pageName: mw.config.get( 'wgPageName' ),
diff --git a/modules/tours/onshow.js b/modules/tours/onshow.js
index d91162a..e846c8c 100644
--- a/modules/tours/onshow.js
+++ b/modules/tours/onshow.js
@@ -3,10 +3,9 @@
  * when they are.
  */
 ( function ( window, document, $, mw, gt ) {
-
        // XXX (mattflaschen, 2012-01-02): See GuidedTourHooks.php
        var pageName = mw.config.get( 'wgGuidedTourHelpGuiderUrl' ),
-               tour;
+               tour, firstStepButtons, firstStep;
 
        tour = new gt.TourBuilder( {
                /*
@@ -19,7 +18,12 @@
                name: 'onshow'
        } );
 
-       tour.firstStep( {
+       // If there is no page, this is also the last step.
+       firstStepButtons = ( pageName === null ) ?
+               [ { action: 'end' } ] :
+               [];
+
+       firstStep = tour.firstStep( {
                name: 'descriptionwikitext',
                titlemsg: 'guidedtour-tour-test-mediawiki-parse',
                // This deliberately does not use descriptionmsg in order to 
demonstrate
@@ -32,29 +36,33 @@
                position: {
                        fallback: 'bottomRight',
                        monobook: 'right'
-               }
-       } )
-       .next( 'descriptionpage' );
+               },
+               buttons: firstStepButtons
+       } );
 
-       tour.step( {
-               /*
-                * Test out mediawiki description pages
-                */
-               name: 'descriptionpage',
-               titlemsg: 'guidedtour-tour-test-description-page',
-               description: pageName,
+       if ( pageName !== null ) {
+               firstStep.next( 'descriptionpage' );
 
-               overlay: true,
-               onShow: gt.getPageAsDescription,
+               tour.step( {
+                       /*
+                        * Test out mediawiki description pages
+                        */
+                       name: 'descriptionpage',
+                       titlemsg: 'guidedtour-tour-test-description-page',
+                       description: pageName,
 
-               buttons: [ {
-                       action: 'wikiLink',
-                       page: pageName,
-                       namemsg: 'guidedtour-tour-test-go-description-page',
-                       type: 'progressive'
-               }, {
-                       action: 'end'
-               } ]
-       } )
-       .back( 'descriptionwikitext' );
+                       overlay: true,
+                       onShow: gt.getPageAsDescription,
+
+                       buttons: [ {
+                               action: 'wikiLink',
+                               page: pageName,
+                               namemsg: 
'guidedtour-tour-test-go-description-page',
+                               type: 'progressive'
+                       }, {
+                               action: 'end'
+                       } ]
+               } )
+               .back( 'descriptionwikitext' );
+       }
 } ( window, document, jQuery, mediaWiki, mediaWiki.guidedTour ) );
diff --git a/modules/tours/test.js b/modules/tours/test.js
index f6da108..d5cec09 100644
--- a/modules/tours/test.js
+++ b/modules/tours/test.js
@@ -2,10 +2,14 @@
  * Guided Tour to test guided tour features.
  */
 ( function ( window, document, $, mw, gt ) {
-
        // XXX (mattflaschen, 2012-01-02): See GuidedTourHooks.php
-       var pageName = mw.config.get( 'wgGuidedTourHelpGuiderUrl' ),
-               tour;
+       var tour, launchTourButtons,
+               pageName = mw.config.get( 'wgGuidedTourHelpGuiderUrl' );
+
+       // Should match shouldShowForPage from firstedit.js
+       function shouldShowFirstEdit() {
+               return ( mw.config.get( 'wgCanonicalNamespace' ) === '' && 
mw.config.get( 'wgIsProbablyEditable' ) );
+       }
 
        tour = new gt.TourBuilder( {
                /*
@@ -54,28 +58,44 @@
                        monobook: 'right'
                }
        } )
-       .next( 'descriptionpage' )
+       .next( pageName ? 'descriptionpage' : 'launchtour' )
        .back( 'callout' );
 
-       tour.step( {
-               /*
-                * Test out mediawiki description pages
-                */
-               name: 'descriptionpage',
-               titlemsg: 'guidedtour-tour-test-description-page',
-               description: new mw.Title( pageName ),
+       if ( pageName ) {
+               tour.step( {
+                       /*
+                        * Test out mediawiki description pages
+                        */
+                       name: 'descriptionpage',
+                       titlemsg: 'guidedtour-tour-test-description-page',
+                       description: new mw.Title( pageName ),
 
-               overlay: true,
+                       overlay: true,
 
-               buttons: [ {
-                       action: 'wikiLink',
-                       page: pageName,
-                       namemsg: 'guidedtour-tour-test-go-description-page',
-                       type: 'progressive'
-               } ]
-       } )
-       .next( 'launchtour' )
-       .back( 'descriptionwikitext' );
+                       buttons: [ {
+                               action: 'wikiLink',
+                               page: pageName,
+                               namemsg: 
'guidedtour-tour-test-go-description-page',
+                               type: 'progressive'
+                       } ]
+               } )
+               .next( 'launchtour' )
+               .back( 'descriptionwikitext' );
+       }
+
+       launchTourButtons = [ {
+               action: 'end'
+       } ];
+
+       if ( shouldShowFirstEdit() ) {
+               launchTourButtons.unshift( {
+                       namemsg: 'guidedtour-tour-test-launch-editing',
+                       onclick: function() {
+                               gt.endTour();
+                               gt.launchTour( 'firstedit' );
+                       }
+               } );
+       }
 
        /*
         * Test out tour launching
@@ -88,15 +108,7 @@
                // attachment
                overlay: true,
 
-               buttons: [ {
-                       namemsg: 'guidedtour-tour-test-launch-editing',
-                       onclick: function() {
-                               gt.endTour();
-                               gt.launchTour( 'firstedit' );
-                       }
-               }, {
-                       action: 'end'
-               } ]
+               buttons: launchTourButtons
        })
-       .back( 'descriptionpage' );
+       .back( pageName ? 'descriptionpage' : 'descriptionwikitext' );
 } ( window, document, jQuery, mediaWiki, mediaWiki.guidedTour ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I089a481f7bc13263ebca8f50828b66a5d26e5c65
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/GuidedTour
Gerrit-Branch: REL1_28
Gerrit-Owner: Mattflaschen <[email protected]>

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

Reply via email to