jenkins-bot has submitted this change and it was merged.
Change subject: Ensure namespace is passed when history code loaded
......................................................................
Ensure namespace is passed when history code loaded
Note you can still lazy load from search via a talk page so
URL should be rewritten correctly
Also ensure that the page doesn't get re-rendered with a talk
icon after talk page is edited.
Address a FIXME in process
Bug: 55594
Change-Id: Ib140dcff8bc6252abb3a7106554c86d50ff68b2b
---
M javascripts/common/Page.js
M javascripts/common/history-alpha.js
M tests/javascripts/common/test_Page.js
3 files changed, 53 insertions(+), 5 deletions(-)
Approvals:
Kaldari: Looks good to me, approved
jenkins-bot: Verified
diff --git a/javascripts/common/Page.js b/javascripts/common/Page.js
index 8bd1635..5b49a98 100644
--- a/javascripts/common/Page.js
+++ b/javascripts/common/Page.js
@@ -41,6 +41,8 @@
render: function( options ) {
var pageTitle = options.title, self = this,
$el = this.$el, _super = self._super;
+ // prevent talk icon being re-rendered after an edit to
a talk page
+ options.isTalkPage = self.isTalkPage();
// FIXME: this is horrible, because it makes preRender
run _during_ render...
if ( !options.sections ) {
@@ -74,9 +76,20 @@
}
},
- // FIXME: [ajax page loading] Note this will not work when we
ajax load namespaces other than main which we currently do not do.
+ getNamespaceId: function() {
+ var args = this.options.title.split( ':' ), nsId;
+ if ( args[1] ) {
+ nsId = mw.config.get( 'wgNamespaceIds' )[
args[0].toLowerCase().replace( ' ', '_' ) ] || 0;
+ } else {
+ nsId = 0;
+ }
+ return nsId;
+ },
+
isTalkPage: function() {
- return M.inNamespace( 'talk' );
+ var ns = this.getNamespaceId();
+ // all talk pages are odd numbers (except the case of
special pages)
+ return ns > 0 && ns % 2 === 1;
},
preRender: function( options ) {
diff --git a/javascripts/common/history-alpha.js
b/javascripts/common/history-alpha.js
index 9676c88..fb87b7d 100644
--- a/javascripts/common/history-alpha.js
+++ b/javascripts/common/history-alpha.js
@@ -23,7 +23,8 @@
// do not run more than once
function init() {
- var title = mw.config.get( 'wgTitle' ),
+ // use wgPageName to ensure we keep the namespace prefix
+ var title = mw.config.get( 'wgPageName' ),
currentUrl = mw.util.wikiGetlink( title, M.query );
// initial history state does not contain title
// run before binding to avoid nasty surprises
diff --git a/tests/javascripts/common/test_Page.js
b/tests/javascripts/common/test_Page.js
index 9c0dee4..8645662 100644
--- a/tests/javascripts/common/test_Page.js
+++ b/tests/javascripts/common/test_Page.js
@@ -1,4 +1,4 @@
-( function( M ) {
+( function( M, $ ) {
var Page = M.require( 'Page' );
QUnit.module( 'MobileFrontend Page' );
@@ -10,4 +10,38 @@
assert.strictEqual( p2.isMainPage(), false, 'check not marked
as main page' );
} );
-}( mw.mobileFrontend ) );
+ QUnit.test( '#getNamespaceId', 8, function( assert ) {
+ var testCases = [
+ [ 'Main Page', 0 ],
+ [ 'San Francisco', 0 ],
+ [ 'San Francisco: Talk:2', 0 ],
+ [ 'San Francisco: The Sequel', 0 ],
+ [ 'Talk:Foo', 1 ],
+ [ 'Project:Bar', 4 ],
+ [ 'User talk:Jon', 3 ],
+ [ 'Special:Nearby', -1 ]
+ ];
+ $.each( testCases, function( i, tc ) {
+ var p = new Page( { title: tc[0] } );
+ assert.strictEqual( p.getNamespaceId(), tc[1], 'Check
namespace is as expected' );
+ } );
+ } );
+
+ QUnit.test( '#isTalkPage', 8, function( assert ) {
+ var testCases = [
+ [ 'Main Page', false ],
+ [ 'San Francisco', false ],
+ [ 'San Francisco: Talk:2', false ],
+ [ 'San Francisco: The Sequel', false ],
+ [ 'Talk:Foo', true ],
+ [ 'Project talk:Bar', true ],
+ [ 'User talk:Jon', true ],
+ [ 'Special:Nearby', false ]
+ ];
+ $.each( testCases, function( i, tc ) {
+ var p = new Page( { title: tc[0] } );
+ assert.strictEqual( p.isTalkPage(), tc[1], 'Check test
is as expected' );
+ } );
+ } );
+
+}( mw.mobileFrontend, jQuery ) );
--
To view, visit https://gerrit.wikimedia.org/r/90072
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib140dcff8bc6252abb3a7106554c86d50ff68b2b
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: JGonera <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Kaldari <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits