2017-07-12 15:12:40 +00:00
|
|
|
( function ( M, $ ) {
|
|
|
|
var loader = M.require( 'mobile.startup/rlModuleLoader' ),
|
|
|
|
LoadingOverlay = M.require( 'mobile.startup/LoadingOverlay' ),
|
|
|
|
$talk = $( '.talk' ),
|
|
|
|
// use the plain return value here - T128273
|
|
|
|
title = $talk.attr( 'data-title' ),
|
|
|
|
overlayManager = M.require( 'skins.minerva.scripts/overlayManager' ),
|
|
|
|
skin = M.require( 'skins.minerva.scripts/skin' ),
|
2017-09-28 20:06:39 +00:00
|
|
|
inTalkNamespace = false,
|
|
|
|
pageTitle, talkTitle, talkNs, pageNs;
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
// if there's no title for any reason, don't do anything
|
|
|
|
if ( !title ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// T127190
|
|
|
|
title = decodeURIComponent( title );
|
|
|
|
|
|
|
|
// sanity check: the talk namespace needs to have the next higher integer
|
|
|
|
// of the page namespace (the api should add topics only to the talk page of the current
|
|
|
|
// page)
|
|
|
|
// (https://www.mediawiki.org/wiki/Manual:Using_custom_namespaces#Creating_a_custom_namespace)
|
|
|
|
// The method to get associated namespaces will change later (maybe), see T487
|
|
|
|
pageTitle = mw.Title.newFromText( mw.config.get( 'wgPageName' ) );
|
|
|
|
talkTitle = mw.Title.newFromText( title );
|
2017-09-28 20:06:39 +00:00
|
|
|
|
|
|
|
if ( !pageTitle || !talkTitle || pageTitle.getMainText() !== talkTitle.getMainText() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
talkNs = talkTitle.getNamespaceId();
|
|
|
|
pageNs = pageTitle.getNamespaceId();
|
|
|
|
inTalkNamespace = talkNs === pageNs;
|
|
|
|
|
|
|
|
if ( pageNs + 1 !== talkNs && !inTalkNamespace ) {
|
2017-07-12 15:12:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
overlayManager.add( /^\/talk\/?(.*)$/, function ( id ) {
|
2018-08-22 00:26:46 +00:00
|
|
|
var talkOptions = {
|
|
|
|
api: new mw.Api(),
|
|
|
|
title: title,
|
2018-09-13 15:33:20 +00:00
|
|
|
// T184273 using `getCurrentPage` because 'wgPageName' contains underscores instead of
|
|
|
|
// spaces.
|
2018-08-22 00:26:46 +00:00
|
|
|
currentPageTitle: M.getCurrentPage().title,
|
|
|
|
licenseMsg: skin.getLicenseMsg()
|
|
|
|
};
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2018-08-22 00:26:46 +00:00
|
|
|
return loader.loadModule( 'mobile.talk.overlays' ).then( function () {
|
2017-07-12 15:12:40 +00:00
|
|
|
var Overlay;
|
|
|
|
if ( id === 'new' ) {
|
|
|
|
Overlay = M.require( 'mobile.talk.overlays/TalkSectionAddOverlay' );
|
|
|
|
} else if ( id ) {
|
|
|
|
talkOptions.id = id;
|
|
|
|
Overlay = M.require( 'mobile.talk.overlays/TalkSectionOverlay' );
|
|
|
|
} else {
|
|
|
|
Overlay = M.require( 'mobile.talk.overlays/TalkOverlay' );
|
|
|
|
}
|
2018-08-22 00:26:46 +00:00
|
|
|
return new Overlay( talkOptions );
|
2017-07-12 15:12:40 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create route '#/talk'
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
function init() {
|
|
|
|
$talk.on( 'click', function () {
|
2017-09-28 20:06:39 +00:00
|
|
|
if ( $talk.hasClass( 'add' ) ) {
|
|
|
|
window.location.hash = '#/talk/new';
|
|
|
|
} else {
|
|
|
|
window.location.hash = '#/talk';
|
|
|
|
}
|
2017-07-12 15:12:40 +00:00
|
|
|
return false;
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
init();
|
|
|
|
|
2017-09-28 20:06:39 +00:00
|
|
|
if ( inTalkNamespace ) {
|
2017-07-12 15:12:40 +00:00
|
|
|
// reload the page after the new discussion was added
|
|
|
|
M.on( 'talk-added-wo-overlay', function () {
|
|
|
|
var loadingOverlay = new LoadingOverlay();
|
|
|
|
|
|
|
|
window.location.hash = '';
|
2018-09-13 15:33:20 +00:00
|
|
|
// setTimeout to make sure, that loadingOverlay's overlayenabled class on html doesnt
|
|
|
|
// get removed by OverlayManager (who closes TalkSectionAddOverlay).
|
2017-07-12 15:12:40 +00:00
|
|
|
window.setTimeout( function () {
|
|
|
|
loadingOverlay.show();
|
|
|
|
window.location.reload();
|
|
|
|
}, 10 );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
}( mw.mobileFrontend, jQuery ) );
|