2019-03-01 17:37:53 +00:00
|
|
|
( function ( M ) {
|
2019-02-07 16:34:18 +00:00
|
|
|
var
|
|
|
|
mobile = M.require( 'mobile.startup' ),
|
|
|
|
loader = mobile.rlModuleLoader,
|
2019-02-22 22:12:28 +00:00
|
|
|
loadingOverlay = mobile.loadingOverlay,
|
2019-03-01 17:37:53 +00:00
|
|
|
eventBus = mobile.eventBusSingleton,
|
2019-02-21 23:20:45 +00:00
|
|
|
PageGateway = mobile.PageGateway,
|
2019-02-25 20:52:18 +00:00
|
|
|
api = new mw.Api(),
|
|
|
|
gateway = new PageGateway( api ),
|
2019-04-03 23:32:18 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
2019-01-10 22:59:56 +00:00
|
|
|
$talk = $( '.talk, [rel="discussion"]' ),
|
2017-07-12 15:12:40 +00:00
|
|
|
// use the plain return value here - T128273
|
|
|
|
title = $talk.attr( 'data-title' ),
|
2019-07-02 21:10:10 +00:00
|
|
|
overlayManager = require( 'skins.minerva.scripts' ).overlayManager,
|
|
|
|
// FIXME: This dependency shouldn't exist
|
2019-07-17 18:14:23 +00:00
|
|
|
skin = mobile.Skin.getSingleton(),
|
2017-09-28 20:06:39 +00:00
|
|
|
inTalkNamespace = false,
|
|
|
|
pageTitle, talkTitle, talkNs, pageNs;
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
// T127190
|
2019-01-10 22:59:56 +00:00
|
|
|
if ( title ) {
|
|
|
|
title = decodeURIComponent( title );
|
|
|
|
}
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
// 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
|
2019-06-18 19:38:33 +00:00
|
|
|
pageTitle = mw.Title.newFromText( mw.config.get( 'wgRelevantPageName' ) );
|
2019-01-10 22:59:56 +00:00
|
|
|
talkTitle = title ? mw.Title.newFromText( title ) : pageTitle.getTalkPage();
|
2017-09-28 20:06:39 +00:00
|
|
|
|
2019-01-10 22:59:56 +00:00
|
|
|
// Check that there is a valid page and talk title
|
|
|
|
if ( !pageTitle || !talkTitle ||
|
|
|
|
// the talk link points to something other than the current page
|
|
|
|
// so we chose to leave this as a normal link
|
|
|
|
pageTitle.getMainText() !== talkTitle.getMainText() ) {
|
2017-09-28 20:06:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
talkNs = talkTitle.getNamespaceId();
|
|
|
|
pageNs = pageTitle.getNamespaceId();
|
|
|
|
inTalkNamespace = talkNs === pageNs;
|
|
|
|
|
|
|
|
if ( pageNs + 1 !== talkNs && !inTalkNamespace ) {
|
2017-07-12 15:12:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-24 22:05:35 +00:00
|
|
|
/**
|
|
|
|
* Render a talk overlay for a given section
|
|
|
|
* @param {string} id (a number e.g. '1' or the string 'new')
|
|
|
|
* @param {Object} talkOptions
|
|
|
|
* @return {Overlay}
|
|
|
|
*/
|
|
|
|
function talkSectionOverlay( id, talkOptions ) {
|
|
|
|
if ( id === 'new' ) {
|
|
|
|
return new ( M.require( 'mobile.talk.overlays/TalkSectionAddOverlay' ) )( talkOptions );
|
|
|
|
}
|
|
|
|
return new ( M.require( 'mobile.talk.overlays/TalkSectionOverlay' ) )( talkOptions );
|
|
|
|
}
|
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
overlayManager.add( /^\/talk\/?(.*)$/, function ( id ) {
|
2019-02-21 23:20:45 +00:00
|
|
|
var title = talkTitle.toText(),
|
|
|
|
talkOptions = {
|
|
|
|
api: api,
|
|
|
|
title: title,
|
2019-07-18 20:12:44 +00:00
|
|
|
onSaveComplete: function () {
|
|
|
|
gateway.invalidatePage( title );
|
2019-08-07 20:17:39 +00:00
|
|
|
// navigate back. the overlay is done with so close it
|
|
|
|
overlayManager.router.back();
|
|
|
|
try {
|
|
|
|
overlayManager.replaceCurrent(
|
|
|
|
mobile.talk.overlay( title, gateway )
|
|
|
|
);
|
|
|
|
overlayManager.router.navigateTo( null, {
|
|
|
|
// This should be defined in Minerva.
|
|
|
|
path: '#/talk',
|
|
|
|
useReplaceState: true
|
|
|
|
} );
|
|
|
|
} catch ( e ) {
|
|
|
|
// the user came directly - there is no overlay to replace
|
|
|
|
// so no overlay to refresh
|
|
|
|
}
|
2019-07-18 20:12:44 +00:00
|
|
|
mw.notify( mw.msg( 'mobile-frontend-talk-topic-feedback' ) );
|
|
|
|
},
|
2019-07-11 00:56:04 +00:00
|
|
|
// T184273 using `currentPage` because 'wgPageName'
|
2019-02-21 23:20:45 +00:00
|
|
|
// contains underscores instead of spaces.
|
2019-07-11 00:56:04 +00:00
|
|
|
currentPageTitle: mobile.currentPage().title,
|
2019-02-21 23:20:45 +00:00
|
|
|
licenseMsg: skin.getLicenseMsg(),
|
|
|
|
eventBus: eventBus,
|
|
|
|
id: id
|
|
|
|
};
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2019-02-21 23:20:45 +00:00
|
|
|
// talk case
|
|
|
|
if ( id ) {
|
2019-07-24 22:05:35 +00:00
|
|
|
// If the module is already loaded return it instantly and synchronously.
|
|
|
|
// this avoids a flash of
|
|
|
|
// content when transitioning from mobile.talk.overlay to this overlay (T221978)
|
|
|
|
return mw.loader.getState( 'mobile.talk.overlays' ) === 'ready' ?
|
|
|
|
talkSectionOverlay( id, talkOptions ) :
|
|
|
|
// otherwise pull it from ResourceLoader async
|
|
|
|
loader.loadModule( 'mobile.talk.overlays' ).then( function () {
|
|
|
|
return talkSectionOverlay( id, talkOptions );
|
|
|
|
} );
|
2019-02-21 23:20:45 +00:00
|
|
|
} else {
|
|
|
|
return mobile.talk.overlay( title, gateway );
|
|
|
|
}
|
2017-07-12 15:12:40 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create route '#/talk'
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
function init() {
|
2019-08-26 18:23:42 +00:00
|
|
|
$talk.on( 'click', function ( ev ) {
|
2017-09-28 20:06:39 +00:00
|
|
|
if ( $talk.hasClass( 'add' ) ) {
|
|
|
|
window.location.hash = '#/talk/new';
|
|
|
|
} else {
|
|
|
|
window.location.hash = '#/talk';
|
|
|
|
}
|
2019-08-26 18:23:42 +00:00
|
|
|
// avoiding navigating to original URL
|
|
|
|
// DO NOT USE stopPropagation or you'll break click tracking in WikimediaEvents
|
|
|
|
ev.preventDefault();
|
2017-07-12 15:12:40 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2018-12-04 22:05:46 +00:00
|
|
|
eventBus.on( 'talk-added-wo-overlay', function () {
|
2019-02-22 22:12:28 +00:00
|
|
|
var overlay = loadingOverlay();
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
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 () {
|
2019-02-22 22:12:28 +00:00
|
|
|
overlay.show();
|
2017-07-12 15:12:40 +00:00
|
|
|
window.location.reload();
|
|
|
|
}, 10 );
|
|
|
|
} );
|
|
|
|
}
|
2019-03-01 17:37:53 +00:00
|
|
|
}( mw.mobileFrontend ) );
|