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
|
|
|
|
2013-07-30 10:58:07 +00:00
|
|
|
wfUseMW( '1.22alpha' );
|
|
|
|
|
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;
|
|
|
|
|
2013-07-19 02:44:22 +00:00
|
|
|
if ( $wgVisualEditorEnableEventLogging ) {
|
|
|
|
$output->addModules( array( 'schema.Edit' ) );
|
|
|
|
}
|
2013-06-26 17:23:56 +00:00
|
|
|
|
2013-07-19 02:44:22 +00:00
|
|
|
$output->addModules( array( 'ext.visualEditor.viewPageTarget.init' ) );
|
2013-06-26 17:23:56 +00:00
|
|
|
|
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'
|
|
|
|
);
|
2013-07-24 01:11:56 +00:00
|
|
|
$preferences['visualeditor-betatempdisable'] = array(
|
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'visualeditor-preference-betatempdisable',
|
|
|
|
'section' => 'editing/beta'
|
|
|
|
);
|
2012-11-05 20:46:14 +00:00
|
|
|
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 ) {
|
Infrastructure for loading plugins in the MW integration
Server-side, plugins can register themselves by adding to
$wgVisualEditorPluginModules. This is the recommended way for
MW extensions to extend VE. Client-side, plugins can register
themselves through mw.libs.ve.addPlugin(), which takes a string
(RL module name) or a callback.
When VisualEditor loads, we load the registered plugin modules in
parallel with ext.visualEditor.core. Note that they're loaded in
parallel, not after, and so the plugins should explicitly depend
on ext.visualEditor.core if they use or extend classes in VE core.
Once the modules finish loading and user and site scripts have run,
we execute the registered plugin callbacks. These callbacks can
optionally return a promise. We gather these promises and wait for
all of them to be resolved, then initialize the editor.
This allows Gadgets to extend VE by top-loading a small module that
depends on ext.visualEditor.viewPageTarget.init and calls
mw.libs.ve.addPlugin( 'ext.gadget.bottomHalfGadget' ); , the bottom
half being a hidden Gadget that depends on ext.visualEditor.core and
contains the actual code. The addPlugin() call needs to be in a
top-loading module because otherwise there's no guarantee that the
plugin will be registered before the user clicks edit and VE loads.
User and site scripts can extend VE by simply calling addPlugin()
directly, as mw.libs.ve is already present when user scripts run (since
it's top-loaded) and VE waits for 'user' and 'site' to run before
executing plugins.
If user/site scripts need to load additional JS files, they can load
these with $.getScript() and return the corresponding promise:
mw.libs.ve.addPlugin( function() { return $.getScript( 'URL' ); } );
For a diagram of all this, see
https://www.mediawiki.org/wiki/File:VE-plugin-infrastructure.jpg :)
VisualEditor.php:
* Add $wgVisualEditorPluginModules
VisualEditor.hooks.php:
* Expose $wgVisualEditorPluginModules in JS
ve.init.mw.ViewPageTarget.init.js:
* Add mw.libs.ve.addPlugin function that just stores the registered
values in an array and passes them into the mw.Target when it's
being initialized
ve.init.mw.Target.js:
* Add $wgVisualEditorPluginModules to the set of modules to load when
initializing VE
* Add a Deferred (this.modulesReady) to track module loading
* Add addPlugin() and addPlugins() methods that add to either
this.modules or this.pluginCallbacks
* In load(), instead of mw.loader.load()ing this.modules, use using()
to load this.modules plus user and site, and fire onModulesReady()
when they're loaded
* In onModulesReady(), execute the registered callbacks, gather the
returned promises, wait for all of them to be resolved, then resolve
this.modulesReady
* Fire onReady based on this.modulesReady being resolved, rather than
using a second using() call
Bug: 50514
Change-Id: Ib7d87a17eaac6ecdb8b0803b13840d7ee58902df
2013-07-22 20:34:28 +00:00
|
|
|
global $wgVisualEditorEnableEventLogging, $wgVisualEditorPluginModules,
|
|
|
|
$wgVisualEditorEnableExperimentalCode, $wgVisualEditorTabLayout,
|
|
|
|
$wgVisualEditorDisableForAnons, $wgVisualEditorNamespaces;
|
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,
|
2013-07-19 02:44:22 +00:00
|
|
|
'disableForAnons' => $wgVisualEditorDisableForAnons,
|
|
|
|
'namespaces' => $wgVisualEditorNamespaces,
|
|
|
|
'skins' => self::$supportedSkins,
|
Infrastructure for loading plugins in the MW integration
Server-side, plugins can register themselves by adding to
$wgVisualEditorPluginModules. This is the recommended way for
MW extensions to extend VE. Client-side, plugins can register
themselves through mw.libs.ve.addPlugin(), which takes a string
(RL module name) or a callback.
When VisualEditor loads, we load the registered plugin modules in
parallel with ext.visualEditor.core. Note that they're loaded in
parallel, not after, and so the plugins should explicitly depend
on ext.visualEditor.core if they use or extend classes in VE core.
Once the modules finish loading and user and site scripts have run,
we execute the registered plugin callbacks. These callbacks can
optionally return a promise. We gather these promises and wait for
all of them to be resolved, then initialize the editor.
This allows Gadgets to extend VE by top-loading a small module that
depends on ext.visualEditor.viewPageTarget.init and calls
mw.libs.ve.addPlugin( 'ext.gadget.bottomHalfGadget' ); , the bottom
half being a hidden Gadget that depends on ext.visualEditor.core and
contains the actual code. The addPlugin() call needs to be in a
top-loading module because otherwise there's no guarantee that the
plugin will be registered before the user clicks edit and VE loads.
User and site scripts can extend VE by simply calling addPlugin()
directly, as mw.libs.ve is already present when user scripts run (since
it's top-loaded) and VE waits for 'user' and 'site' to run before
executing plugins.
If user/site scripts need to load additional JS files, they can load
these with $.getScript() and return the corresponding promise:
mw.libs.ve.addPlugin( function() { return $.getScript( 'URL' ); } );
For a diagram of all this, see
https://www.mediawiki.org/wiki/File:VE-plugin-infrastructure.jpg :)
VisualEditor.php:
* Add $wgVisualEditorPluginModules
VisualEditor.hooks.php:
* Expose $wgVisualEditorPluginModules in JS
ve.init.mw.ViewPageTarget.init.js:
* Add mw.libs.ve.addPlugin function that just stores the registered
values in an array and passes them into the mw.Target when it's
being initialized
ve.init.mw.Target.js:
* Add $wgVisualEditorPluginModules to the set of modules to load when
initializing VE
* Add a Deferred (this.modulesReady) to track module loading
* Add addPlugin() and addPlugins() methods that add to either
this.modules or this.pluginCallbacks
* In load(), instead of mw.loader.load()ing this.modules, use using()
to load this.modules plus user and site, and fire onModulesReady()
when they're loaded
* In onModulesReady(), execute the registered callbacks, gather the
returned promises, wait for all of them to be resolved, then resolve
this.modulesReady
* Fire onReady based on this.modulesReady being resolved, rather than
using a second using() call
Bug: 50514
Change-Id: Ib7d87a17eaac6ecdb8b0803b13840d7ee58902df
2013-07-22 20:34:28 +00:00
|
|
|
'pluginModules' => $wgVisualEditorPluginModules,
|
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(
|
2013-07-03 01:30:10 +00:00
|
|
|
// MW config preload
|
|
|
|
've-mw/test/mw-preload.js',
|
2012-07-27 23:43:27 +00:00
|
|
|
// QUnit plugin
|
2013-07-03 01:30:10 +00:00
|
|
|
've/test/ve.qunit.js',
|
2013-07-16 22:45:11 +00:00
|
|
|
// UnicodeJS Tests
|
|
|
|
'unicodejs/test/unicodejs.test.js',
|
|
|
|
'unicodejs/test/unicodejs.graphemebreak.test.js',
|
|
|
|
'unicodejs/test/unicodejs.wordbreak.test.js',
|
2012-07-27 23:43:27 +00:00
|
|
|
// VisualEditor Tests
|
2013-07-03 01:30:10 +00:00
|
|
|
've/test/ve.test.utils.js',
|
|
|
|
've/test/ve.test.js',
|
|
|
|
've/test/ve.Document.test.js',
|
|
|
|
've/test/ve.Element.test.js',
|
|
|
|
've/test/ve.Node.test.js',
|
|
|
|
've/test/ve.BranchNode.test.js',
|
|
|
|
've/test/ve.LeafNode.test.js',
|
|
|
|
've/test/ve.Factory.test.js',
|
2012-07-27 23:43:27 +00:00
|
|
|
// VisualEditor DataModel Tests
|
2013-07-03 01:30:10 +00:00
|
|
|
've/test/dm/ve.dm.example.js',
|
|
|
|
've/test/dm/ve.dm.AnnotationSet.test.js',
|
|
|
|
've/test/dm/ve.dm.NodeFactory.test.js',
|
|
|
|
've/test/dm/ve.dm.Node.test.js',
|
|
|
|
've/test/dm/ve.dm.Converter.test.js',
|
|
|
|
've/test/dm/ve.dm.BranchNode.test.js',
|
|
|
|
've/test/dm/ve.dm.LeafNode.test.js',
|
|
|
|
've/test/dm/ve.dm.LinearData.test.js',
|
|
|
|
've/test/dm/nodes/ve.dm.TextNode.test.js',
|
|
|
|
've-mw/test/dm/nodes/ve.dm.MWTransclusionNode.test.js',
|
|
|
|
've/test/dm/ve.dm.Document.test.js',
|
|
|
|
've/test/dm/ve.dm.DocumentSynchronizer.test.js',
|
|
|
|
've/test/dm/ve.dm.IndexValueStore.test.js',
|
|
|
|
've/test/dm/ve.dm.InternalList.test.js',
|
2013-07-11 02:36:55 +00:00
|
|
|
've-mw/test/dm/ve.dm.InternalList.test.js',
|
2013-07-03 01:30:10 +00:00
|
|
|
've/test/dm/ve.dm.Transaction.test.js',
|
|
|
|
've/test/dm/ve.dm.TransactionProcessor.test.js',
|
|
|
|
've/test/dm/ve.dm.Surface.test.js',
|
|
|
|
've/test/dm/ve.dm.SurfaceFragment.test.js',
|
2013-07-11 02:36:55 +00:00
|
|
|
've-mw/test/dm/ve.dm.SurfaceFragment.test.js',
|
2013-07-03 01:30:10 +00:00
|
|
|
've/test/dm/ve.dm.ModelRegistry.test.js',
|
|
|
|
've/test/dm/ve.dm.MetaList.test.js',
|
|
|
|
've/test/dm/ve.dm.Model.test.js',
|
|
|
|
've/test/dm/lineardata/ve.dm.ElementLinearData.test.js',
|
|
|
|
've/test/dm/lineardata/ve.dm.MetaLinearData.test.js',
|
|
|
|
've-mw/test/dm/ve.dm.mwExample.js',
|
|
|
|
've-mw/test/dm/ve.dm.MWConverter.test.js',
|
2012-07-27 23:43:27 +00:00
|
|
|
// VisualEditor ContentEditable Tests
|
2013-07-03 01:30:10 +00:00
|
|
|
've/test/ce/ve.ce.test.js',
|
|
|
|
've/test/ce/ve.ce.Document.test.js',
|
2013-07-11 02:36:55 +00:00
|
|
|
've-mw/test/ce/ve.ce.Document.test.js',
|
2013-07-03 01:30:10 +00:00
|
|
|
've/test/ce/ve.ce.NodeFactory.test.js',
|
|
|
|
've/test/ce/ve.ce.Node.test.js',
|
|
|
|
've/test/ce/ve.ce.BranchNode.test.js',
|
|
|
|
've/test/ce/ve.ce.ContentBranchNode.test.js',
|
2013-07-11 02:36:55 +00:00
|
|
|
've-mw/test/ce/ve.ce.ContentBranchNode.test.js',
|
2013-07-03 01:30:10 +00:00
|
|
|
've/test/ce/ve.ce.LeafNode.test.js',
|
|
|
|
've/test/ce/nodes/ve.ce.TextNode.test.js',
|
2013-05-14 23:45:42 +00:00
|
|
|
// VisualEditor Actions Tests
|
2013-07-03 01:30:10 +00:00
|
|
|
've/test/ui/actions/ve.ui.FormatAction.test.js',
|
2013-07-11 02:36:55 +00:00
|
|
|
've-mw/test/ui/actions/ve.ui.FormatAction.test.js',
|
2013-07-03 01:30:10 +00:00
|
|
|
've/test/ui/actions/ve.ui.IndentationAction.test.js',
|
|
|
|
've/test/ui/actions/ve.ui.ListAction.test.js',
|
2012-12-04 06:56:41 +00:00
|
|
|
// VisualEditor initialization Tests
|
2013-07-03 01:30:10 +00:00
|
|
|
've/test/init/ve.init.Platform.test.js',
|
|
|
|
've-mw/test/init/targets/ve.init.mw.ViewPageTarget.test.js',
|
2012-07-27 23:43:27 +00:00
|
|
|
),
|
|
|
|
'dependencies' => array(
|
2013-07-16 22:45:11 +00:00
|
|
|
'unicodejs.wordbreak',
|
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',
|
2013-07-03 22:14:52 +00:00
|
|
|
'ext.visualEditor.viewPageTarget.init',
|
2012-07-27 23:43:27 +00:00
|
|
|
'ext.visualEditor.viewPageTarget',
|
|
|
|
),
|
2013-07-03 01:30:10 +00:00
|
|
|
'localBasePath' => dirname( __FILE__ ) . '/modules',
|
|
|
|
'remoteExtPath' => 'VisualEditor/modules',
|
2012-07-27 23:43:27 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
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
|
|
|
}
|