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

Change subject: Cleanup handling of 'section' param
......................................................................

Cleanup handling of 'section' param

Provide a common function to parsing, and always pass
section to the target, instead of having the target
re-compute it itself.

Change-Id: If9fc24ffa51507cd969fa1b4dfc1519a0b50a572
---
M modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
M modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js
2 files changed, 25 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/02/326002/1

diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js 
b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
index 7ba7b2a..11ff2ef 100644
--- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
+++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
@@ -101,6 +101,18 @@
                }
        }
 
+       function parseSection( section ) {
+               var parsedSection = section;
+               // Section must be 'new' (not yet supported) or a number
+               if ( section !== 'new' ) {
+                       parsedSection = +section;
+                       if ( isNaN( parsedSection ) ) {
+                               parsedSection = null;
+                       }
+               }
+               return parsedSection;
+       }
+
        /**
         * Use deferreds to avoid loading and instantiating Target multiple 
times.
         *
@@ -108,7 +120,7 @@
         * @param {string} mode Target mode: 'visual' or 'source'
         * @return {jQuery.Promise}
         */
-       function getTarget( mode ) {
+       function getTarget( mode, section ) {
                if ( !targetPromise ) {
                        // The TargetLoader module is loaded in the bottom 
queue, so it should have been
                        // requested already but it might not have finished 
loading yet
@@ -165,7 +177,8 @@
                                } );
                }
 
-               targetPromise.then( function () {
+               targetPromise.then( function ( target ) {
+                       target.section = section;
                        // Enqueue the loading of deferred modules (that is, 
modules which provide
                        // functionality that is not needed for loading the 
editor).
                        setTimeout( function () {
@@ -263,7 +276,7 @@
                incrementLoadingProgress();
                active = true;
 
-               targetPromise = targetPromise || getTarget( mode );
+               targetPromise = targetPromise || getTarget( mode, section );
                targetPromise
                        .then( function ( target ) {
                                var activatePromise;
@@ -655,18 +668,18 @@
                                history.pushState( { tag: 'visualeditor' }, 
document.title, this.href );
                        }
 
-                       targetPromise = getTarget( mode );
                        if ( mode === 'visual' ) {
-                               targetPromise = targetPromise.then( function ( 
target ) {
+                               // Get section based on heading count (may 
differ from wikitext section count)
+                               targetPromise = getTarget( mode ).then( 
function ( target ) {
                                        target.saveEditSection( $( e.target 
).closest( 'h1, h2, h3, h4, h5, h6' ).get( 0 ) );
                                        return target;
                                } );
                        } else {
-                               section = +( new mw.Uri( e.target.href 
).query.section );
-                               targetPromise = targetPromise.then( function ( 
target ) {
-                                       target.section = section;
-                                       return target;
-                               } );
+                               // Use section from URL
+                               if ( section === undefined ) {
+                                       section = parseSection( new mw.Uri( 
e.target.href ).query.section );
+                               }
+                               targetPromise = getTarget( mode, section );
                        }
                        activateTarget( mode, section, targetPromise );
                }
@@ -800,7 +813,7 @@
 
        $( function () {
                var showWikitextWelcome = true,
-                       section = uri.query.section !== undefined ? 
uri.query.section : null,
+                       section = uri.query.section !== undefined ? 
parseSection( uri.query.section ) : null,
                        isLoggedIn = !mw.user.isAnon(),
                        prefSaysShowWelcome = isLoggedIn && 
!mw.user.options.get( 'visualeditor-hidebetawelcome' ),
                        urlSaysHideWelcome = 'hidewelcomedialog' in new mw.Uri( 
location.href ).query,
diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js 
b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js
index 280c138..e20c935 100644
--- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js
+++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js
@@ -52,7 +52,7 @@
        };
        this.scrollTop = null;
        this.currentUri = currentUri;
-       this.section = currentUri.query.section !== undefined ? 
+currentUri.query.section : null;
+       this.section = null;
        if ( $( '#wpSummary' ).length ) {
                this.initialEditSummary = $( '#wpSummary' ).val();
        } else {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If9fc24ffa51507cd969fa1b4dfc1519a0b50a572
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <esand...@wikimedia.org>

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

Reply via email to