2020-10-18 11:52:02 +00:00
|
|
|
var controller = require( './controller.js' ),
|
2022-03-29 21:25:21 +00:00
|
|
|
url = new URL( location.href );
|
2019-12-10 21:46:22 +00:00
|
|
|
|
2019-10-10 20:17:24 +00:00
|
|
|
/**
|
2019-12-10 21:46:22 +00:00
|
|
|
* @class mw.dt
|
2019-10-10 20:17:24 +00:00
|
|
|
* @singleton
|
|
|
|
*/
|
2019-12-10 21:46:22 +00:00
|
|
|
mw.dt = {};
|
2019-10-10 20:17:24 +00:00
|
|
|
|
2022-02-22 23:10:43 +00:00
|
|
|
mw.dt.initState = {
|
|
|
|
firstLoad: true
|
|
|
|
};
|
2021-07-29 06:12:10 +00:00
|
|
|
|
2021-12-17 16:34:23 +00:00
|
|
|
// New Topic A/B test for logged out users:
|
|
|
|
var tokenData = mw.storage.getObject( 'DTNewTopicABToken' );
|
|
|
|
if ( tokenData && tokenData.expires < Date.now() ) {
|
|
|
|
mw.storage.remove( 'DTNewTopicABToken' );
|
|
|
|
tokenData = null;
|
|
|
|
}
|
|
|
|
if ( mw.user.isAnon() && mw.config.get( 'wgDiscussionToolsABTest' ) ) {
|
|
|
|
if ( !tokenData ) {
|
|
|
|
tokenData = {
|
|
|
|
token: mw.user.generateRandomSessionId(),
|
|
|
|
// 90 days
|
|
|
|
expires: Date.now() + 90 * 24 * 60 * 60 * 1000
|
|
|
|
};
|
|
|
|
mw.storage.setObject( 'DTNewTopicABToken', tokenData );
|
|
|
|
}
|
|
|
|
mw.config.set( 'wgDiscussionToolsAnonymousUserId', tokenData.token );
|
|
|
|
var anonid = parseInt( tokenData.token.slice( 0, 8 ), 16 );
|
|
|
|
var abstate = anonid % 2 === 0 ? 'test' : 'control';
|
|
|
|
mw.config.set( 'wgDiscussionToolsABTestBucket', abstate );
|
|
|
|
var featuresEnabled = mw.config.get( 'wgDiscussionToolsFeaturesEnabled' ) || {};
|
|
|
|
if ( abstate === 'test' ) {
|
|
|
|
$( document.body ).addClass( 'ext-discussiontools-newtopictool-enabled' );
|
|
|
|
featuresEnabled.newtopictool = true;
|
|
|
|
} else {
|
|
|
|
$( document.body ).removeClass( 'ext-discussiontools-newtopictool-enabled' );
|
|
|
|
featuresEnabled.newtopictool = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-29 21:25:21 +00:00
|
|
|
if ( url.searchParams.get( 'dtrepliedto' ) ) {
|
2021-07-29 06:12:10 +00:00
|
|
|
// If we had to reload the page to highlight the new comment, extract that data from the URL and
|
|
|
|
// clean it up.
|
2022-03-29 21:25:21 +00:00
|
|
|
mw.dt.initState.repliedTo = url.searchParams.get( 'dtrepliedto' );
|
2021-07-29 06:12:10 +00:00
|
|
|
if ( window.history.replaceState ) {
|
2022-03-29 21:25:21 +00:00
|
|
|
url.searchParams.delete( 'dtrepliedto' );
|
|
|
|
window.history.replaceState( {}, '', url );
|
2021-07-29 06:12:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-24 20:27:53 +00:00
|
|
|
mw.dt.init = function ( $container ) {
|
|
|
|
if ( $container.is( '#mw-content-text' ) || $container.find( '#mw-content-text' ).length ) {
|
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
|
|
|
controller.init( $( '#mw-content-text' ), mw.dt.initState );
|
|
|
|
// Reset for next init
|
|
|
|
mw.dt.initState = {};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-29 21:25:21 +00:00
|
|
|
if ( url.searchParams.get( 'dtdebug' ) ) {
|
2019-10-24 14:38:31 +00:00
|
|
|
mw.loader.load( 'ext.discussionTools.debug' );
|
2021-03-24 18:41:39 +00:00
|
|
|
} else {
|
2020-06-24 20:27:53 +00:00
|
|
|
// Don't use an anonymous function, because ReplyWidget needs to be able to remove this handler
|
|
|
|
mw.hook( 'wikipage.content' ).add( mw.dt.init );
|
2019-10-24 14:38:31 +00:00
|
|
|
}
|
2020-02-25 02:10:27 +00:00
|
|
|
|
|
|
|
module.exports = {
|
2020-10-18 11:52:02 +00:00
|
|
|
controller: controller,
|
2020-07-20 21:15:03 +00:00
|
|
|
Parser: require( './Parser.js' ),
|
Change CommentParser into a service
Goal:
-----
To have a method like CommentParser::parse(), which just takes a node
to parse and a title and returns plain data, so that we don't need to
keep track of the config to construct a CommentParser object (the
required config like content language is provided by services) and
we don't need to keep that object around after parsing.
Changes:
--------
CommentParser.php:
* …is now a service. Constructor only takes services as arguments.
The node and title are passed to a new parse() method.
* parse() should return plain data, but I split this part to a separate
patch for ease of review: I49bfe019aa460651447fd383f73eafa9d7180a92.
* CommentParser still cheats and accesses global state in a few places,
e.g. calling Title::makeTitleSafe or CommentUtils::getTitleFromUrl,
so we can't turn its tests into true unit tests. This work is left
for future commits.
LanguageData.php:
* …is now a service, instead of a static class.
Parser.js:
* …is not a real service, but it's changed to behave in a similar way.
Constructor takes only the required config as argument,
and node and title are instead passed to a new parse() method.
CommentParserTest.php:
parser.test.js:
* Can be simplified, now that we don't need a useless node and title
to test internal methods that don't use them.
testUtils.js:
* Can be simplified, now that we don't need to override internal
ResourceLoader stuff just to change the parser config.
Change-Id: Iadb7757debe000025e52770ca51ebcf24ca8ee66
2022-02-19 02:43:21 +00:00
|
|
|
parserData: require( './parser/data.json' ),
|
2020-02-25 02:10:27 +00:00
|
|
|
modifier: require( './modifier.js' ),
|
2020-07-20 14:13:59 +00:00
|
|
|
ThreadItem: require( './ThreadItem.js' ),
|
|
|
|
HeadingItem: require( './HeadingItem.js' ),
|
|
|
|
CommentItem: require( './CommentItem.js' ),
|
2020-03-08 14:32:38 +00:00
|
|
|
utils: require( './utils.js' ),
|
2022-02-02 00:13:32 +00:00
|
|
|
logger: require( './logger.js' )
|
2020-02-25 02:10:27 +00:00
|
|
|
};
|