2016-04-19 12:45:09 +00:00
|
|
|
<?php
|
2016-05-12 16:01:50 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2016-04-19 12:45:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* RevisionSlider extension hooks
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
|
|
|
* @license GPL-2.0+
|
|
|
|
*/
|
|
|
|
class RevisionSliderHooks {
|
2016-04-28 10:18:52 +00:00
|
|
|
|
2016-05-03 11:29:02 +00:00
|
|
|
public static function onDiffViewHeader(
|
|
|
|
DifferenceEngine $diff,
|
|
|
|
Revision $oldRev,
|
|
|
|
Revision $newRev
|
|
|
|
) {
|
2016-05-04 13:59:07 +00:00
|
|
|
/**
|
|
|
|
* If this extension is deployed with the BetaFeatures extension then require the
|
|
|
|
* current user to have it enabled as a BetaFeature.
|
|
|
|
*/
|
|
|
|
if (
|
|
|
|
class_exists( BetaFeatures::class ) &&
|
2016-07-14 19:42:59 +00:00
|
|
|
!BetaFeatures::isFeatureEnabled( $diff->getUser(), 'revisionslider' ) )
|
2016-05-04 13:59:07 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-25 20:15:15 +00:00
|
|
|
/**
|
|
|
|
* Do not show the RevisionSlider on special pages that use a Diff view for example
|
|
|
|
* Special:ComparePages
|
|
|
|
*/
|
|
|
|
if ( $diff->getTitle()->getNamespace() === NS_SPECIAL ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-12 16:01:50 +00:00
|
|
|
$config = MediaWikiServices::getInstance()->getMainConfig();
|
|
|
|
$timeOffset = $config->get( 'LocalTZoffset' );
|
|
|
|
if ( is_null( $config->get( 'Localtimezone' ) ) ) {
|
|
|
|
$timeOffset = 0;
|
|
|
|
} elseif ( is_null( $timeOffset ) ) {
|
|
|
|
$timeOffset = 0;
|
|
|
|
}
|
|
|
|
|
2016-05-03 11:29:02 +00:00
|
|
|
$out = RequestContext::getMain()->getOutput();
|
2016-05-03 11:44:01 +00:00
|
|
|
$out->addModules( 'ext.RevisionSlider.init' );
|
2016-05-31 14:03:08 +00:00
|
|
|
$out->addModuleStyles( 'ext.RevisionSlider.noscript' );
|
2016-05-12 15:55:02 +00:00
|
|
|
$out->addJsConfigVars( 'extRevisionSliderOldRev', $oldRev->getId() );
|
|
|
|
$out->addJsConfigVars( 'extRevisionSliderNewRev', $newRev->getId() );
|
2016-05-12 16:01:50 +00:00
|
|
|
$out->addJsConfigVars( 'extRevisionSliderTimeOffset', intval( $timeOffset ) );
|
2016-05-03 11:36:34 +00:00
|
|
|
$out->addHTML(
|
2016-05-06 10:37:30 +00:00
|
|
|
Html::rawElement(
|
|
|
|
'div',
|
|
|
|
[
|
2016-07-01 10:13:53 +00:00
|
|
|
'id' => 'mw-revslider-container',
|
2016-05-06 10:37:30 +00:00
|
|
|
'style' => 'min-height: 150px;',
|
|
|
|
],
|
|
|
|
Html::element(
|
|
|
|
'p',
|
|
|
|
[
|
2016-07-01 10:13:53 +00:00
|
|
|
'id' => 'mw-revslider-placeholder',
|
2016-05-06 10:37:30 +00:00
|
|
|
'style' => 'text-align: center',
|
|
|
|
],
|
2016-06-02 15:54:51 +00:00
|
|
|
( new Message( 'revisionslider-loading-placeholder' ) )->text()
|
2016-05-06 10:37:30 +00:00
|
|
|
)
|
|
|
|
)
|
2016-05-03 11:36:34 +00:00
|
|
|
);
|
2016-05-04 13:59:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getBetaFeaturePreferences( $user, &$prefs ) {
|
2016-06-16 15:23:00 +00:00
|
|
|
global $wgExtensionAssetsPath;
|
|
|
|
|
2016-05-09 08:18:34 +00:00
|
|
|
$prefs['revisionslider'] = [
|
2016-05-04 13:59:07 +00:00
|
|
|
'label-message' => 'revisionslider-beta-feature-message',
|
|
|
|
'desc-message' => 'revisionslider-beta-feature-description',
|
2016-06-16 15:23:00 +00:00
|
|
|
'screenshot' => [
|
|
|
|
'ltr' => "$wgExtensionAssetsPath/RevisionSlider/resources/RevisionSlider-beta-features-ltr.png",
|
|
|
|
'rtl' => "$wgExtensionAssetsPath/RevisionSlider/resources/RevisionSlider-beta-features-rtl.png",
|
|
|
|
],
|
2016-05-04 13:59:07 +00:00
|
|
|
'info-link' => 'https://www.mediawiki.org/wiki/Extension:RevisionSlider',
|
|
|
|
'discussion-link' => 'https://www.mediawiki.org/wiki/Extension_talk:RevisionSlider',
|
2016-05-09 08:18:34 +00:00
|
|
|
];
|
2016-05-03 11:29:02 +00:00
|
|
|
}
|
|
|
|
|
2016-04-28 10:18:52 +00:00
|
|
|
public static function onResourceLoaderTestModules( array &$testModules, ResourceLoader $rl ) {
|
|
|
|
$testModules['qunit']['ext.RevisionSlider.tests'] = [
|
|
|
|
'scripts' => [
|
2016-07-04 11:49:59 +00:00
|
|
|
'tests/qunit/QUnit.revisionSlider.testOrSkip.js',
|
2016-06-27 11:24:47 +00:00
|
|
|
'tests/qunit/RevisionSlider.Revision.test.js',
|
|
|
|
'tests/qunit/RevisionSlider.Pointer.test.js',
|
|
|
|
'tests/qunit/RevisionSlider.PointerView.test.js',
|
|
|
|
'tests/qunit/RevisionSlider.Slider.test.js',
|
|
|
|
'tests/qunit/RevisionSlider.SliderView.test.js',
|
|
|
|
'tests/qunit/RevisionSlider.RevisionList.test.js',
|
2016-06-29 10:43:46 +00:00
|
|
|
'tests/qunit/RevisionSlider.RevisionListView.test.js',
|
|
|
|
'tests/qunit/RevisionSlider.DiffPage.test.js',
|
|
|
|
'tests/qunit/RevisionSlider.HelpDialog.test.js',
|
2016-04-28 10:18:52 +00:00
|
|
|
],
|
|
|
|
'dependencies' => [
|
2016-05-03 11:26:42 +00:00
|
|
|
'ext.RevisionSlider.Revision',
|
|
|
|
'ext.RevisionSlider.Pointer',
|
|
|
|
'ext.RevisionSlider.PointerView',
|
2016-05-10 12:42:05 +00:00
|
|
|
'ext.RevisionSlider.Slider',
|
|
|
|
'ext.RevisionSlider.SliderView',
|
|
|
|
'ext.RevisionSlider.RevisionList',
|
2016-06-29 10:43:46 +00:00
|
|
|
'ext.RevisionSlider.RevisionListView',
|
|
|
|
'ext.RevisionSlider.DiffPage',
|
|
|
|
'ext.RevisionSlider.HelpDialog',
|
2016-05-10 16:45:11 +00:00
|
|
|
'jquery.ui.draggable',
|
|
|
|
'jquery.ui.tooltip',
|
|
|
|
'jquery.tipsy',
|
2016-06-29 10:43:46 +00:00
|
|
|
'oojs-ui'
|
2016-04-28 10:18:52 +00:00
|
|
|
],
|
|
|
|
'localBasePath' => __DIR__,
|
2016-07-01 10:19:51 +00:00
|
|
|
'remoteExtPath' => 'RevisionSlider',
|
2016-04-28 10:18:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-04-19 12:45:09 +00:00
|
|
|
}
|