2019-10-10 13:25:11 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* DiscussionTools extension hooks
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
|
|
|
* @license MIT
|
|
|
|
*/
|
2019-09-26 07:06:56 +00:00
|
|
|
|
2019-10-10 19:11:07 +00:00
|
|
|
class DiscussionToolsHooks {
|
2019-10-28 16:52:37 +00:00
|
|
|
|
|
|
|
public static function onRegistration() {
|
|
|
|
global $wgLocaltimezone;
|
|
|
|
// If $wgLocaltimezone isn't hard-coded, it is evaluated from the system
|
|
|
|
// timezone. On some systems this isn't guaranteed to be static, for example
|
|
|
|
// on Debian, GMT can get converted to UTC, instead of Europe/London.
|
|
|
|
//
|
|
|
|
// Timestamp parsing assumes that the timezone never changes.
|
|
|
|
//
|
|
|
|
// HACK: Do not run this test on CI as $wgLocaltimezone is not configured.
|
|
|
|
if ( !$wgLocaltimezone && !getenv( 'ZUUL_PROJECT' ) ) {
|
|
|
|
throw new \ConfigException( 'DiscussionTools requires $wgLocaltimezone to be set' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-10 19:11:07 +00:00
|
|
|
/**
|
|
|
|
* Adds DiscussionTools JS to the output.
|
|
|
|
*
|
|
|
|
* This is attached to the MediaWiki 'BeforePageDisplay' hook.
|
|
|
|
*
|
|
|
|
* @param OutputPage $output The page view.
|
|
|
|
* @param Skin $skin The skin that's going to build the UI.
|
|
|
|
*/
|
|
|
|
public static function onBeforePageDisplay( OutputPage $output, Skin $skin ) {
|
|
|
|
$title = $output->getTitle();
|
2019-12-09 14:43:39 +00:00
|
|
|
$actionName = Action::getActionName( $output->getContext() );
|
2019-10-10 19:11:07 +00:00
|
|
|
if (
|
2019-12-09 14:43:39 +00:00
|
|
|
// Don't show on edit pages
|
|
|
|
$actionName !== 'edit' &&
|
|
|
|
$actionName !== 'submit' &&
|
2019-10-10 19:11:07 +00:00
|
|
|
// Only wikitext pages (e.g. not Flow boards)
|
|
|
|
$title->getContentModel() === CONTENT_MODEL_WIKITEXT &&
|
|
|
|
$title->isTalkPage()
|
|
|
|
// TODO: Allow non talk pages to be treated as talk pages
|
|
|
|
// using a magic word.
|
|
|
|
) {
|
2019-09-26 07:06:56 +00:00
|
|
|
$output->addModules( [
|
|
|
|
'ext.discussionTools.init'
|
|
|
|
] );
|
2019-10-10 19:11:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|