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
|
|
|
|
*/
|
2016-07-26 11:09:45 +00:00
|
|
|
if ( $diff->getTitle()->inNamespace( NS_SPECIAL ) ) {
|
2016-07-25 20:15:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-12 09:31:18 +00:00
|
|
|
$stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
|
|
|
|
$stats->increment( 'RevisionSlider.event.hookinit' );
|
|
|
|
|
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-08-05 16:14:28 +00:00
|
|
|
$out->enableOOUI();
|
|
|
|
|
|
|
|
// FIXME: this really not nice to inject those elements to ButtonWidget like that
|
|
|
|
// but this is only done to have inline styles set for those elements, so they are
|
|
|
|
// rendered as intended before RL loads all CSS styles (avoid jumping after CSS is loaded).
|
|
|
|
// Some better and more future-proof solution (what if ButtonWidget switches to use other tags?)
|
|
|
|
// should be used if possible.
|
|
|
|
$button = new OOUI\Tag( 'a' );
|
|
|
|
$label = new OOUI\Tag( 'span' );
|
|
|
|
$icon = new OOUI\Tag( 'span' );
|
|
|
|
$button->setAttributes( [ 'style' => 'width: 100%;' ] );
|
|
|
|
$label->setAttributes( [ 'style' => 'line-height: 1.875em;' ] );
|
|
|
|
$icon->setAttributes( [ 'style' => 'float: right;' ] );
|
|
|
|
|
|
|
|
$toggleButton = new OOUI\ButtonWidget( [
|
|
|
|
'label' => ( new Message( 'revisionslider-toggle-label' ) )->text(),
|
|
|
|
'icon' => 'expand',
|
|
|
|
'button' => $button,
|
|
|
|
'labelElement' => $label,
|
|
|
|
'iconElement' => $icon,
|
|
|
|
'classes' => [ 'mw-revslider-toggle-button' ],
|
|
|
|
'infusable' => true,
|
|
|
|
'framed' => false,
|
|
|
|
'title' => ( new Message( 'revisionslider-toggle-title-expand' ) )->text(),
|
|
|
|
] );
|
|
|
|
$toggleButton->setAttributes( [ 'style' => 'width: 100%; text-align: center;' ] );
|
|
|
|
|
2016-05-03 11:36:34 +00:00
|
|
|
$out->addHTML(
|
2016-05-06 10:37:30 +00:00
|
|
|
Html::rawElement(
|
|
|
|
'div',
|
|
|
|
[
|
2016-07-02 20:14:00 +00:00
|
|
|
'class' => 'mw-revslider-container',
|
2016-08-05 16:14:28 +00:00
|
|
|
'style' => 'border: 1px solid #cccccc;'
|
2016-05-06 10:37:30 +00:00
|
|
|
],
|
2016-08-05 16:14:28 +00:00
|
|
|
$toggleButton .
|
|
|
|
Html::rawElement(
|
|
|
|
'div',
|
2016-05-06 10:37:30 +00:00
|
|
|
[
|
2016-07-02 20:14:00 +00:00
|
|
|
'class' => 'mw-revslider-slider-wrapper',
|
2016-08-05 16:14:28 +00:00
|
|
|
'style' => 'min-height: 142px; display: none; border-top: 1px solid #cccccc;',
|
2016-05-06 10:37:30 +00:00
|
|
|
],
|
2016-08-05 16:14:28 +00:00
|
|
|
Html::element(
|
|
|
|
'p',
|
|
|
|
[
|
2016-07-02 20:14:00 +00:00
|
|
|
'class' => 'mw-revslider-placeholder',
|
2016-08-05 16:14:28 +00:00
|
|
|
'style' => 'text-align: center',
|
|
|
|
],
|
|
|
|
( 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;
|
|
|
|
}
|
|
|
|
|
2016-08-19 10:05:17 +00:00
|
|
|
public static function getBetaFeaturePreferences( User $user, array &$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',
|
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
|
|
|
}
|