2012-05-25 19:50:48 +00:00
|
|
|
<?php
|
2012-07-19 00:11:26 +00:00
|
|
|
/**
|
|
|
|
* VisualEditor extension hooks
|
2012-07-19 21:25:16 +00:00
|
|
|
*
|
2012-07-19 00:11:26 +00:00
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
2013-02-19 23:37:34 +00:00
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
2012-07-19 00:11:26 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
2012-05-25 19:50:48 +00:00
|
|
|
|
|
|
|
class VisualEditorHooks {
|
2012-08-15 23:35:52 +00:00
|
|
|
/** List of skins VisualEditor integration supports */
|
2012-08-23 18:01:20 +00:00
|
|
|
protected static $supportedSkins = array( 'vector', 'apex', 'monobook' );
|
2012-08-15 23:35:52 +00:00
|
|
|
|
2013-06-11 22:14:44 +00:00
|
|
|
public static function onSetup() {
|
2013-06-28 22:55:36 +00:00
|
|
|
global $wgVisualEditorEnableEventLogging, $wgResourceModules,
|
|
|
|
$wgVisualEditorEnableGenderSurvey;
|
2013-06-11 22:14:44 +00:00
|
|
|
|
|
|
|
if ( $wgVisualEditorEnableEventLogging ) {
|
|
|
|
if ( class_exists( 'ResourceLoaderSchemaModule' ) ) {
|
|
|
|
// EventLogging schema module for logging edit events.
|
|
|
|
// See <http://meta.wikimedia.org/wiki/Schema:Edit>
|
|
|
|
$wgResourceModules['schema.Edit'] = array(
|
|
|
|
'class' => 'ResourceLoaderSchemaModule',
|
|
|
|
'schema' => 'Edit',
|
2013-06-14 18:13:59 +00:00
|
|
|
'revision' => 5570274,
|
2013-06-11 22:14:44 +00:00
|
|
|
);
|
2013-06-28 22:55:36 +00:00
|
|
|
|
|
|
|
if ( $wgVisualEditorEnableGenderSurvey ) {
|
|
|
|
$wgResourceModules['schema.GenderSurvey'] = array(
|
|
|
|
'class' => 'ResourceLoaderSchemaModule',
|
|
|
|
'schema' => 'GenderSurvey',
|
2013-07-01 22:49:57 +00:00
|
|
|
'revision' => 5607845,
|
2013-06-28 22:55:36 +00:00
|
|
|
);
|
|
|
|
}
|
2013-06-11 22:14:44 +00:00
|
|
|
} else {
|
|
|
|
wfWarn( 'VisualEditor is configured to use EventLogging, but the extension is ' .
|
|
|
|
' not available. Disabling wgVisualEditorEnableEventLogging.' );
|
|
|
|
$wgVisualEditorEnableEventLogging = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-25 19:50:48 +00:00
|
|
|
/**
|
2012-06-11 06:54:41 +00:00
|
|
|
* Adds VisualEditor JS to the output if in the correct namespace.
|
|
|
|
*
|
|
|
|
* This is attached to the MediaWiki 'BeforePageDisplay' hook.
|
2012-05-25 19:50:48 +00:00
|
|
|
*
|
|
|
|
* @param $output OutputPage
|
|
|
|
* @param $skin Skin
|
|
|
|
*/
|
2012-06-11 06:54:41 +00:00
|
|
|
public static function onBeforePageDisplay( &$output, &$skin ) {
|
2013-06-30 02:46:18 +00:00
|
|
|
global $wgVisualEditorNamespaces, $wgVisualEditorEnableEventLogging,
|
|
|
|
$wgVisualEditorDisableForAnons;
|
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
if (
|
2013-06-30 02:46:18 +00:00
|
|
|
// Bug 50000: Allow disabling for anonymous users separately from changing
|
|
|
|
// the default preference
|
|
|
|
!( $wgVisualEditorDisableForAnons && $skin->getUser()->isAnon() ) &&
|
|
|
|
|
|
|
|
// Bug 47328: Disable on redirect pages until redirects are editable
|
2013-05-17 11:23:11 +00:00
|
|
|
!$skin->getTitle()->isRedirect() &&
|
2013-06-26 17:23:56 +00:00
|
|
|
|
2012-12-11 01:49:11 +00:00
|
|
|
// User has the 'visualeditor-enable' preference set
|
2013-06-26 17:23:56 +00:00
|
|
|
$skin->getUser()->getOption(
|
|
|
|
'visualeditor-enable',
|
|
|
|
/*default=*/ false,
|
|
|
|
// HACK: Allows us to suppress the option in preferences when it's on for all.
|
|
|
|
/*ignoreHidden=*/ true
|
|
|
|
) &&
|
|
|
|
|
|
|
|
// The user's current skin is supported
|
2012-08-15 23:35:52 +00:00
|
|
|
in_array( $skin->getSkinName(), self::$supportedSkins ) &&
|
2013-06-26 17:23:56 +00:00
|
|
|
|
2012-06-18 21:13:26 +00:00
|
|
|
(
|
|
|
|
// Article in the VisualEditor namespace
|
2012-11-05 20:46:14 +00:00
|
|
|
in_array( $skin->getTitle()->getNamespace(), $wgVisualEditorNamespaces ) ||
|
2012-06-18 21:13:26 +00:00
|
|
|
// Special page action for an article in the VisualEditor namespace
|
2012-11-05 20:46:14 +00:00
|
|
|
in_array( $skin->getRelevantTitle()->getNamespace(), $wgVisualEditorNamespaces )
|
2013-05-11 21:14:08 +00:00
|
|
|
) &&
|
2013-06-26 17:23:56 +00:00
|
|
|
|
2013-05-11 21:14:08 +00:00
|
|
|
// Only use VisualEditor if the page is wikitext, not CSS/JS
|
|
|
|
$skin->getTitle()->getContentModel() === CONTENT_MODEL_WIKITEXT
|
2012-06-11 06:54:41 +00:00
|
|
|
) {
|
2013-06-11 22:14:44 +00:00
|
|
|
if ( $wgVisualEditorEnableEventLogging ) {
|
|
|
|
$output->addModules( array( 'schema.Edit' ) );
|
|
|
|
}
|
2012-06-28 09:52:03 +00:00
|
|
|
$output->addModules( array( 'ext.visualEditor.viewPageTarget' ) );
|
2013-06-17 21:12:21 +00:00
|
|
|
} else {
|
|
|
|
if ( $wgVisualEditorEnableEventLogging ) {
|
|
|
|
$output->addModules( array( 'schema.Edit', 'ext.visualEditor.splitTest' ) );
|
|
|
|
}
|
2012-05-25 19:50:48 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-28 22:55:36 +00:00
|
|
|
// Temporary survey in conjuction with split test (bug 49604)
|
|
|
|
// To be removed once no longer needed.
|
|
|
|
// Depends on GuidedTour and EventLogging
|
|
|
|
public static function onBeforeWelcomeCreation( &$welcomeCreationMsg, &$injectHtml ) {
|
|
|
|
global $wgOut, $wgVisualEditorEnableGenderSurvey;
|
|
|
|
|
|
|
|
if ( $wgVisualEditorEnableGenderSurvey ) {
|
|
|
|
$wgOut->addModules( array(
|
|
|
|
'ext.guidedTour.lib',
|
|
|
|
'ext.guidedTour.tour.vegendersurvey',
|
|
|
|
'ext.visualEditor.genderSurvey'
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-05 20:46:14 +00:00
|
|
|
public static function onGetPreferences( $user, &$preferences ) {
|
|
|
|
$preferences['visualeditor-enable'] = array(
|
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'visualeditor-preference-enable',
|
|
|
|
'section' => 'editing/beta'
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-22 02:26:29 +00:00
|
|
|
public static function onListDefinedTags( &$tags ) {
|
|
|
|
$tags[] = 'visualeditor';
|
2013-06-23 23:09:47 +00:00
|
|
|
$tags[] = 'visualeditor-needcheck';
|
2012-11-22 02:26:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-25 19:50:48 +00:00
|
|
|
/**
|
2012-06-11 06:54:41 +00:00
|
|
|
* Adds extra variables to the page config.
|
2012-05-25 19:50:48 +00:00
|
|
|
*/
|
2012-12-06 05:57:53 +00:00
|
|
|
public static function onMakeGlobalVariablesScript( array &$vars, OutputPage $out ) {
|
2013-05-23 05:47:11 +00:00
|
|
|
global $wgStylePath, $wgContLang;
|
2012-06-11 06:54:41 +00:00
|
|
|
$vars['wgVisualEditor'] = array(
|
2012-12-12 23:35:33 +00:00
|
|
|
'isPageWatched' => $out->getUser()->isWatched( $out->getTitle() ),
|
2013-05-10 18:04:31 +00:00
|
|
|
'pageLanguageCode' => $out->getTitle()->getPageLanguage()->getHtmlCode(),
|
2013-05-23 05:47:11 +00:00
|
|
|
'pageLanguageDir' => $out->getTitle()->getPageLanguage()->getDir(),
|
2013-05-30 11:00:36 +00:00
|
|
|
// Same as in Linker.php
|
|
|
|
'magnifyClipIconURL' => $wgStylePath .
|
|
|
|
'/common/images/magnify-clip' .
|
|
|
|
( $wgContLang->isRTL() ? '-rtl' : '' ) . '.png'
|
2013-04-17 16:48:09 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds extra variables to the global config
|
|
|
|
*/
|
|
|
|
public static function onResourceLoaderGetConfigVars( array &$vars ) {
|
2013-06-13 22:02:27 +00:00
|
|
|
global $wgVisualEditorEnableEventLogging,
|
2013-06-11 22:14:44 +00:00
|
|
|
$wgVisualEditorEnableExperimentalCode, $wgVisualEditorTabLayout;
|
2013-06-03 22:23:45 +00:00
|
|
|
|
2013-04-17 16:48:09 +00:00
|
|
|
$vars['wgVisualEditorConfig'] = array(
|
2013-04-16 17:31:17 +00:00
|
|
|
'enableExperimentalCode' => $wgVisualEditorEnableExperimentalCode,
|
2013-06-11 22:14:44 +00:00
|
|
|
'enableEventLogging' => $wgVisualEditorEnableEventLogging,
|
2013-06-03 22:23:45 +00:00
|
|
|
'tabLayout' => $wgVisualEditorTabLayout,
|
2012-06-11 06:54:41 +00:00
|
|
|
);
|
2012-12-06 05:57:53 +00:00
|
|
|
|
2012-06-01 23:26:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-07-27 23:43:27 +00:00
|
|
|
|
2013-05-30 11:00:36 +00:00
|
|
|
public static function onResourceLoaderTestModules(
|
|
|
|
array &$testModules,
|
|
|
|
ResourceLoader &$resourceLoader
|
|
|
|
) {
|
2012-07-27 23:43:27 +00:00
|
|
|
$testModules['qunit']['ext.visualEditor.test'] = array(
|
|
|
|
'scripts' => array(
|
|
|
|
// QUnit plugin
|
|
|
|
've.qunit.js',
|
|
|
|
// VisualEditor Tests
|
2012-08-12 18:27:31 +00:00
|
|
|
've.test.js',
|
2012-07-27 23:43:27 +00:00
|
|
|
've.Document.test.js',
|
2013-05-21 17:18:46 +00:00
|
|
|
've.Element.test.js',
|
2012-07-27 23:43:27 +00:00
|
|
|
've.Node.test.js',
|
|
|
|
've.BranchNode.test.js',
|
|
|
|
've.LeafNode.test.js',
|
|
|
|
've.Factory.test.js',
|
|
|
|
// VisualEditor DataModel Tests
|
|
|
|
'dm/ve.dm.example.js',
|
2013-03-20 22:35:05 +00:00
|
|
|
'dm/ve.dm.AnnotationSet.test.js',
|
2012-07-27 23:43:27 +00:00
|
|
|
'dm/ve.dm.NodeFactory.test.js',
|
|
|
|
'dm/ve.dm.Node.test.js',
|
|
|
|
'dm/ve.dm.Converter.test.js',
|
|
|
|
'dm/ve.dm.BranchNode.test.js',
|
|
|
|
'dm/ve.dm.LeafNode.test.js',
|
2013-04-02 21:29:20 +00:00
|
|
|
'dm/ve.dm.LinearData.test.js',
|
2012-07-27 23:43:27 +00:00
|
|
|
'dm/nodes/ve.dm.TextNode.test.js',
|
2013-06-11 19:16:04 +00:00
|
|
|
'dm/nodes/ve.dm.MWTransclusionNode.test.js',
|
2012-07-27 23:43:27 +00:00
|
|
|
'dm/ve.dm.Document.test.js',
|
|
|
|
'dm/ve.dm.DocumentSynchronizer.test.js',
|
2013-03-20 22:35:05 +00:00
|
|
|
'dm/ve.dm.IndexValueStore.test.js',
|
2013-05-28 18:21:59 +00:00
|
|
|
'dm/ve.dm.InternalList.test.js',
|
2012-07-27 23:43:27 +00:00
|
|
|
'dm/ve.dm.Transaction.test.js',
|
|
|
|
'dm/ve.dm.TransactionProcessor.test.js',
|
|
|
|
'dm/ve.dm.Surface.test.js',
|
2012-08-24 22:25:37 +00:00
|
|
|
'dm/ve.dm.SurfaceFragment.test.js',
|
2013-01-18 05:29:01 +00:00
|
|
|
'dm/ve.dm.ModelRegistry.test.js',
|
2013-03-15 04:07:23 +00:00
|
|
|
'dm/ve.dm.MetaList.test.js',
|
2013-05-07 21:23:07 +00:00
|
|
|
'dm/ve.dm.Model.test.js',
|
2013-03-20 22:35:05 +00:00
|
|
|
'dm/lineardata/ve.dm.ElementLinearData.test.js',
|
|
|
|
'dm/lineardata/ve.dm.MetaLinearData.test.js',
|
2013-06-26 21:18:39 +00:00
|
|
|
'dm/ve.dm.mwExample.js',
|
|
|
|
'dm/ve.dm.MWConverter.test.js',
|
2012-07-27 23:43:27 +00:00
|
|
|
// VisualEditor ContentEditable Tests
|
|
|
|
'ce/ve.ce.test.js',
|
|
|
|
'ce/ve.ce.Document.test.js',
|
|
|
|
'ce/ve.ce.NodeFactory.test.js',
|
|
|
|
'ce/ve.ce.Node.test.js',
|
|
|
|
'ce/ve.ce.BranchNode.test.js',
|
2013-05-07 21:48:23 +00:00
|
|
|
'ce/ve.ce.ContentBranchNode.test.js',
|
2012-07-27 23:43:27 +00:00
|
|
|
'ce/ve.ce.LeafNode.test.js',
|
|
|
|
'ce/nodes/ve.ce.TextNode.test.js',
|
2013-05-14 23:45:42 +00:00
|
|
|
// VisualEditor Actions Tests
|
|
|
|
'ui/actions/ve.ui.FormatAction.test.js',
|
|
|
|
'ui/actions/ve.ui.IndentationAction.test.js',
|
|
|
|
'ui/actions/ve.ui.ListAction.test.js',
|
2012-12-04 06:56:41 +00:00
|
|
|
// VisualEditor initialization Tests
|
|
|
|
'init/ve.init.Platform.test.js',
|
2013-06-04 18:46:49 +00:00
|
|
|
'init/mw/targets/ve.init.mw.ViewPageTarget.test.js',
|
2012-07-27 23:43:27 +00:00
|
|
|
),
|
|
|
|
'dependencies' => array(
|
2013-05-14 23:45:42 +00:00
|
|
|
'ext.visualEditor.standalone',
|
2012-07-27 23:43:27 +00:00
|
|
|
'ext.visualEditor.core',
|
2013-04-16 17:31:17 +00:00
|
|
|
'ext.visualEditor.experimental',
|
2012-07-27 23:43:27 +00:00
|
|
|
'ext.visualEditor.viewPageTarget',
|
|
|
|
),
|
|
|
|
'localBasePath' => dirname( __FILE__ ) . '/modules/ve/test',
|
|
|
|
'remoteExtPath' => 'VisualEditor/modules/ve/test',
|
|
|
|
);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2013-06-15 02:07:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets user preference to enable the VisualEditor account if their new
|
|
|
|
* account's userID is even, if $wgVisualEditorEnableSplitTest is true.
|
|
|
|
*
|
|
|
|
* Added per bug 49604; to be removed once no longer needed.
|
|
|
|
*/
|
|
|
|
public static function onAddNewAccount( $user, $byEmail ) {
|
|
|
|
global $wgVisualEditorEnableSplitTest;
|
|
|
|
|
|
|
|
if ( $wgVisualEditorEnableSplitTest &&
|
|
|
|
$user->isLoggedin() &&
|
|
|
|
( ( $user->getId() % 2 ) === 0 ) ) {
|
|
|
|
$user->setOption( 'visualeditor-enable', 1 );
|
|
|
|
$user->saveSettings();
|
|
|
|
}
|
2013-06-18 03:13:39 +00:00
|
|
|
|
|
|
|
return true;
|
2013-06-15 02:07:34 +00:00
|
|
|
}
|
2012-05-25 19:50:48 +00:00
|
|
|
}
|