mediawiki-extensions-Visual.../VisualEditor.php
Trevor Parscal a5aeca3ff5 Major UI refactoring and improvements
Objective:

Refactor UI widgets, improve usability and accessibility of menus, general cleanup and style improvements.

Extras:
Fixed documentation in a few other files to make descriptions of jQuery event arguments more consistent, classes inherit correctly, and made use of the @cfg functionality in jsduck.

Changes:

.docs/config.json
* Added window, HTMLDocument, HTMLElement, DocumentFragment and XMLHttpRequest to externals, so jsduck doesn't throw warnings when they are used

demos/ve/index.php, modules/ve/test/index.php, VisualEditor.php
* Moved widgets above tools (since tools use widgets)

demos/ve/index.php
* Refactored widget initialization to use options
* Renamed variables to match widget names

ve.init.mw.ViewPageTarget.css
* Adjusted text sizes to make widgets work normally
* Added margins for buttons in toolbar (since button widgets
don't have any)
* Removed styles for init buttons (button widgets now)

ve.init.mw.ViewPageTarget.js
* Switched to using button widgets (involved moving things around
a bit)

ve.ui.LinkInspector.js, ve.ui.MWLinkInspector.js
* Renamed static property "inputWidget" to
"linkTargetInputWidget" to better reflect the required base class
for the properties value

icons.ai, check.png, check.svg
* Added "check" icon, used in menu right now to show which item
is selected

ve.ui.Icons-raster.css, ve.ui.Icons-vector.css
* Added check icon
* Removed :before pseudo selectors from most of the icon classes (not need by button tool anymore, makes them more reusable now)

ve.ui.Tool.css
* Adjusted drop down tool styles so menu appears below, instead
of on top, of the label
* Adjusted paragraph font size to better match actual content
* Updated class names to still work with menu widget changes
(items are their own widgets now)
* Updated selectors as per changes in the structure of button tools

ve.ui.Widget.css
* Added styles for buttons and menu items
* Adjusted menu styles

ve.ui.*ButtonTool.js
* Added config options argument passthrough

ve.ui.ButtonTool.js
* Moved var statement to the top inside constructor
* Switched to using "a" tag to get cross-browser :active support
* Added icon to inside of button to make icon styles more reusable
* Removed disabled support (now provided by widget parent class)

ve.ui.FormatDropDownTool.js
* Updated options initialization to construct menu item objects
* Modified handling of items to account for changes in menu and
item classes
* Optimized onUpdateState method a bit, adding early exit to
inner loop

ve.ui.ButtonTool.js, ve.ui.DropdownTool.js, ve.ui.Context.js,
ve.ui.Frame, ve.ui.Tool.js, ve.ui.Widget.js
* Added chain ability to non-getter methods

ve.ui.DropdownTool.js
* Removed items argument to constructor
* Updated code as per changes in menu class
* Fixed inconsistent naming of event handler methods
* Removed item event handling (now handled by items directly)
* Made use of this.$$ to ensure tool works in other frames

ve.ui.Tool.js
* Made tools inherit from widget
* Moved trigger registry event handler to a method

ve.ui.Context.js
* Switched from using menu to contain toolbar to a simple wrapper

ve.ui.js
* Added get$$ method, a convenience function for binding jQuery
to a specific document context

ve.ui.*Widget.js
* Switched to using a config options object instead of individual arguments
* Added options
* Factored out flags and labels into their own classes
* Refactored value setting methods for inputs

ve.ui.MenuWidget.js, ve.ui.MenuItemWidget.js
* Broke items out into their own classes
* Redesigned API
* Updated code that uses these classes
* Added support for keyboard interaction
* Made items flash when selected (delaying the hiding of the menu for 200ms)

ve.ui.LinkTargetInputWidget.js, ve.ui.MWLinkTargetInputWidget
* Refactored annotation setting methods

Change-Id: I7769bd5a5b79f1ab36f258ef9f2be583ca503ce6
2013-02-26 12:29:08 -08:00

433 lines
14 KiB
PHP

<?php
/**
* VisualEditor extension
*
* @file
* @ingroup Extensions
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/* Configuration */
// URL to the Parsoid instance
// MUST NOT end in a slash due to Parsoid bug
$wgVisualEditorParsoidURL = 'http://localhost:8000';
// Interwiki prefix to pass to the Parsoid instance
// Parsoid will be called as $url/$prefix/$pagename
$wgVisualEditorParsoidPrefix = 'localhost';
// Timeout for HTTP requests to Parsoid in seconds
$wgVisualEditorParsoidTimeout = 100;
// Namespaces to enable VisualEditor in
$wgVisualEditorNamespaces = array( NS_MAIN );
// Whether to use change tagging for VisualEditor edits
$wgVisualEditorUseChangeTagging = true;
/* Setup */
$wgExtensionCredits['other'][] = array(
'path' => __FILE__,
'name' => 'VisualEditor',
'author' => array(
'Trevor Parscal',
'Inez Korczyński',
'Roan Kattouw',
'Neil Kandalgaonkar',
'Gabriel Wicke',
'Brion Vibber',
'Christian Williams',
'Rob Moen',
'Subramanya Sastry',
'Timo Tijhof',
),
'version' => '0.1.0',
'url' => 'https://www.mediawiki.org/wiki/Extension:VisualEditor',
'descriptionmsg' => 'visualeditor-desc',
);
$dir = dirname( __FILE__ ) . '/';
$wgExtensionMessagesFiles['VisualEditor'] = $dir . 'VisualEditor.i18n.php';
$wgVisualEditorResourceTemplate = array(
'localBasePath' => dirname( __FILE__ ) . '/modules',
'remoteExtPath' => 'VisualEditor/modules',
'group' => 'ext.visualEditor',
);
$wgVisualEditorEditNotices = array( 'visualeditor-alphawarning' );
$wgVisualEditorEnableSectionEditLinks = false;
$wgResourceModules += array(
'rangy' => $wgVisualEditorResourceTemplate + array(
'scripts' => array(
'rangy/rangy-core.js',
'rangy/rangy-position.js',
),
),
'jquery.visibleText' => $wgVisualEditorResourceTemplate + array(
'scripts' => array(
'jquery/jquery.visibleText.js'
),
),
// Alias for backwards compat, safe to remove after
'ext.visualEditor.editPageInit' => $wgVisualEditorResourceTemplate + array(
'dependencies' => array(
'ext.visualEditor.viewPageTarget',
)
),
'ext.visualEditor.viewPageTarget.icons-raster' => $wgVisualEditorResourceTemplate + array(
'styles' => array(
've/init/mw/styles/ve.init.mw.ViewPageTarget.Icons-raster.css',
),
),
'ext.visualEditor.viewPageTarget.icons-vector' => $wgVisualEditorResourceTemplate + array(
'styles' => array(
've/init/mw/styles/ve.init.mw.ViewPageTarget.Icons-vector.css',
),
),
'ext.visualEditor.viewPageTarget' => $wgVisualEditorResourceTemplate + array(
'scripts' => array(
've/init/mw/ve.init.mw.js',
've/init/mw/ve.init.mw.Platform.js',
've/init/mw/ve.init.mw.Target.js',
've/init/mw/targets/ve.init.mw.ViewPageTarget.js',
),
'styles' => array(
've/init/mw/styles/ve.init.mw.ViewPageTarget.css',
),
'skinStyles' => array(
'vector' => array(
've/init/mw/styles/ve.init.mw.ViewPageTarget-vector.css',
've/init/mw/styles/ve.init.mw.ViewPageTarget-vector-hd.css' => array(
'media' => 'screen and (min-width: 982px)'
),
),
'apex' => array(
've/init/mw/styles/ve.init.mw.ViewPageTarget-apex.css',
),
'monobook' => array(
've/init/mw/styles/ve.init.mw.ViewPageTarget-monobook.css',
)
),
'dependencies' => array(
'ext.visualEditor.base',
'jquery.byteLength',
'jquery.byteLimit',
'jquery.client',
'jquery.placeholder',
'jquery.visibleText',
'mediawiki.jqueryMsg',
'mediawiki.Title',
'mediawiki.Uri',
'mediawiki.user',
'mediawiki.util',
'mediawiki.notify',
'mediawiki.feedback',
'user.options',
'user.tokens',
),
'messages' => array(
'minoredit',
'cancel',
'watchthis',
'copyrightwarning',
'copyrightpage',
'edit',
'create',
'accesskey-ca-edit',
'accesskey-ca-ve-edit',
'tooltip-ca-edit',
'tooltip-ca-ve-edit',
'viewsource',
'visualeditor-ca-ve-edit',
'visualeditor-ca-ve-create',
'visualeditor-notification-saved',
'visualeditor-notification-created',
'visualeditor-notification-restored',
'visualeditor-notification-reported',
'visualeditor-ca-editsource',
'visualeditor-loadwarning',
'visualeditor-editsummary',
'visualeditor-problem',
'visualeditor-editnotices-tool',
'visualeditor-feedback-tool',
'visualeditor-restore-page',
'visualeditor-create-page',
'visualeditor-save-title',
'visualeditor-report-notice',
'visualeditor-toolbar-savedialog',
'visualeditor-savedialog-title-review',
'visualeditor-savedialog-title-report',
'visualeditor-savedialog-title-save',
'visualeditor-savedialog-label-review-wrong',
'visualeditor-savedialog-label-review-good',
'visualeditor-savedialog-label-report',
'visualeditor-savedialog-label-create',
'visualeditor-savedialog-label-save',
'visualeditor-savedialog-label-restore',
'visualeditor-savedialog-label-report',
),
),
'ext.visualEditor.base' => $wgVisualEditorResourceTemplate + array(
'scripts' => array(
// ve
've/ve.js',
've/ve.EventEmitter.js',
've/init/ve.init.js',
've/init/ve.init.Platform.js',
),
'debugScripts' => array(
've/ve.debug.js',
),
),
'ext.visualEditor.specialMessages' => $wgVisualEditorResourceTemplate + array(
'class' => 'VisualEditorMessagesModule'
),
'ext.visualEditor.core' => $wgVisualEditorResourceTemplate + array(
'scripts' => array(
// ve
've/ve.Registry.js',
've/ve.Factory.js',
've/ve.Trigger.js',
've/ve.CommandRegistry.js',
've/ve.TriggerRegistry.js',
've/ve.Range.js',
've/ve.Node.js',
've/ve.BranchNode.js',
've/ve.LeafNode.js',
've/ve.Surface.js',
've/ve.Document.js',
've/ve.OrderedHashSet.js',
've/ve.AnnotationSet.js',
've/ve.Action.js',
've/ve.ActionFactory.js',
// actions
've/actions/ve.AnnotationAction.js',
've/actions/ve.ContentAction.js',
've/actions/ve.FormatAction.js',
've/actions/ve.HistoryAction.js',
've/actions/ve.IndentationAction.js',
've/actions/ve.InspectorAction.js',
've/actions/ve.ListAction.js',
// dm
've/dm/ve.dm.js',
've/dm/ve.dm.ModelRegistry.js',
've/dm/ve.dm.NodeFactory.js',
've/dm/ve.dm.AnnotationFactory.js',
've/dm/ve.dm.Node.js',
've/dm/ve.dm.BranchNode.js',
've/dm/ve.dm.LeafNode.js',
've/dm/ve.dm.Annotation.js',
've/dm/ve.dm.TransactionProcessor.js',
've/dm/ve.dm.Transaction.js',
've/dm/ve.dm.Surface.js',
've/dm/ve.dm.SurfaceFragment.js',
've/dm/ve.dm.Document.js',
've/dm/ve.dm.DocumentSlice.js',
've/dm/ve.dm.DocumentSynchronizer.js',
've/dm/ve.dm.Converter.js',
've/dm/nodes/ve.dm.AlienNode.js',
've/dm/nodes/ve.dm.BreakNode.js',
've/dm/nodes/ve.dm.CenterNode.js',
've/dm/nodes/ve.dm.DefinitionListItemNode.js',
've/dm/nodes/ve.dm.DefinitionListNode.js',
've/dm/nodes/ve.dm.DocumentNode.js',
've/dm/nodes/ve.dm.HeadingNode.js',
've/dm/nodes/ve.dm.ImageNode.js',
've/dm/nodes/ve.dm.ListItemNode.js',
've/dm/nodes/ve.dm.ListNode.js',
've/dm/nodes/ve.dm.MetaNode.js',
've/dm/nodes/ve.dm.MWEntityNode.js',
've/dm/nodes/ve.dm.MWMetaNode.js',
've/dm/nodes/ve.dm.ParagraphNode.js',
've/dm/nodes/ve.dm.PreformattedNode.js',
've/dm/nodes/ve.dm.TableCellNode.js',
've/dm/nodes/ve.dm.TableNode.js',
've/dm/nodes/ve.dm.TableRowNode.js',
've/dm/nodes/ve.dm.TableSectionNode.js',
've/dm/nodes/ve.dm.TextNode.js',
've/dm/annotations/ve.dm.LinkAnnotation.js',
've/dm/annotations/ve.dm.MWExternalLinkAnnotation.js',
've/dm/annotations/ve.dm.MWInternalLinkAnnotation.js',
've/dm/annotations/ve.dm.TextStyleAnnotation.js',
// ce
've/ce/ve.ce.js',
've/ce/ve.ce.RangyRange.js',
've/ce/ve.ce.NodeFactory.js',
've/ce/ve.ce.Document.js',
've/ce/ve.ce.Node.js',
've/ce/ve.ce.BranchNode.js',
've/ce/ve.ce.ContentBranchNode.js',
've/ce/ve.ce.LeafNode.js',
've/ce/ve.ce.Surface.js',
've/ce/ve.ce.SurfaceObserver.js',
've/ce/nodes/ve.ce.AlienNode.js',
've/ce/nodes/ve.ce.AlienInlineNode.js',
've/ce/nodes/ve.ce.AlienBlockNode.js',
've/ce/nodes/ve.ce.BreakNode.js',
've/ce/nodes/ve.ce.CenterNode.js',
've/ce/nodes/ve.ce.DefinitionListItemNode.js',
've/ce/nodes/ve.ce.DefinitionListNode.js',
've/ce/nodes/ve.ce.DocumentNode.js',
've/ce/nodes/ve.ce.HeadingNode.js',
've/ce/nodes/ve.ce.ImageNode.js',
've/ce/nodes/ve.ce.ListItemNode.js',
've/ce/nodes/ve.ce.ListNode.js',
've/ce/nodes/ve.ce.MWEntityNode.js',
've/ce/nodes/ve.ce.ParagraphNode.js',
've/ce/nodes/ve.ce.PreformattedNode.js',
've/ce/nodes/ve.ce.TableCellNode.js',
've/ce/nodes/ve.ce.TableNode.js',
've/ce/nodes/ve.ce.TableRowNode.js',
've/ce/nodes/ve.ce.TableSectionNode.js',
've/ce/nodes/ve.ce.TextNode.js',
// ui
've/ui/ve.ui.js',
've/ui/ve.ui.Context.js',
've/ui/ve.ui.Frame.js',
've/ui/ve.ui.Inspector.js',
've/ui/ve.ui.InspectorFactory.js',
've/ui/ve.ui.Widget.js',
've/ui/ve.ui.Tool.js',
've/ui/ve.ui.Toolbar.js',
've/ui/ve.ui.ToolFactory.js',
've/ui/tools/ve.ui.ButtonTool.js',
've/ui/tools/ve.ui.AnnotationButtonTool.js',
've/ui/tools/ve.ui.InspectorButtonTool.js',
've/ui/tools/ve.ui.IndentationButtonTool.js',
've/ui/tools/ve.ui.ListButtonTool.js',
've/ui/tools/ve.ui.DropdownTool.js',
've/ui/widgets/ve.ui.LabeledWidget.js',
've/ui/widgets/ve.ui.FlaggableWidget.js',
've/ui/widgets/ve.ui.ButtonWidget.js',
've/ui/widgets/ve.ui.InputWidget.js',
've/ui/widgets/ve.ui.InputLabelWidget.js',
've/ui/widgets/ve.ui.TextInputWidget.js',
've/ui/widgets/ve.ui.MenuItemWidget.js',
've/ui/widgets/ve.ui.MenuWidget.js',
've/ui/widgets/ve.ui.TextInputMenuWidget.js',
've/ui/widgets/ve.ui.LinkTargetInputWidget.js',
've/ui/widgets/ve.ui.MWLinkTargetInputWidget.js',
've/ui/tools/buttons/ve.ui.BoldButtonTool.js',
've/ui/tools/buttons/ve.ui.ItalicButtonTool.js',
've/ui/tools/buttons/ve.ui.ClearButtonTool.js',
've/ui/tools/buttons/ve.ui.LinkButtonTool.js',
've/ui/tools/buttons/ve.ui.MWLinkButtonTool.js',
've/ui/tools/buttons/ve.ui.BulletButtonTool.js',
've/ui/tools/buttons/ve.ui.NumberButtonTool.js',
've/ui/tools/buttons/ve.ui.IndentButtonTool.js',
've/ui/tools/buttons/ve.ui.OutdentButtonTool.js',
've/ui/tools/buttons/ve.ui.RedoButtonTool.js',
've/ui/tools/buttons/ve.ui.UndoButtonTool.js',
've/ui/tools/dropdowns/ve.ui.FormatDropdownTool.js',
've/ui/inspectors/ve.ui.LinkInspector.js',
've/ui/inspectors/ve.ui.MWLinkInspector.js',
),
'styles' => array(
// ve
've/styles/ve.Surface.css',
// ce
've/ce/styles/ve.ce.DocumentNode.css',
've/ce/styles/ve.ce.Node.css',
've/ce/styles/ve.ce.Surface.css',
// ui
've/ui/styles/ve.ui.Context.css',
've/ui/styles/ve.ui.Inspector.css',
've/ui/styles/ve.ui.Surface.css',
've/ui/styles/ve.ui.Toolbar.css',
've/ui/styles/ve.ui.Tool.css',
've/ui/styles/ve.ui.Widget.css',
),
'dependencies' => array(
'jquery',
'rangy',
'ext.visualEditor.base',
'mediawiki.Title',
'jquery.autoEllipsis',
),
'messages' => array(
'visualeditor',
'visualeditor-inspector-title',
'visualeditor-linkinspector-title',
'visualeditor-linkinspector-label-pagetitle',
'visualeditor-linkinspector-suggest-existing-page',
'visualeditor-linkinspector-suggest-new-page',
'visualeditor-linkinspector-suggest-external-link',
'visualeditor-formatdropdown-title',
'visualeditor-formatdropdown-format-paragraph',
'visualeditor-formatdropdown-format-heading1',
'visualeditor-formatdropdown-format-heading2',
'visualeditor-formatdropdown-format-heading3',
'visualeditor-formatdropdown-format-heading4',
'visualeditor-formatdropdown-format-heading5',
'visualeditor-formatdropdown-format-heading6',
'visualeditor-formatdropdown-format-preformatted',
'visualeditor-annotationbutton-bold-tooltip',
'visualeditor-annotationbutton-bold-tooltip-trigger-mac',
'visualeditor-annotationbutton-bold-tooltip-trigger-pc',
'visualeditor-annotationbutton-italic-tooltip',
'visualeditor-annotationbutton-italic-tooltip-trigger-mac',
'visualeditor-annotationbutton-italic-tooltip-trigger-pc',
'visualeditor-annotationbutton-link-tooltip',
'visualeditor-annotationbutton-link-tooltip-trigger-mac',
'visualeditor-annotationbutton-link-tooltip-trigger-pc',
'visualeditor-indentationbutton-indent-tooltip',
'visualeditor-indentationbutton-indent-tooltip-trigger',
'visualeditor-indentationbutton-outdent-tooltip',
'visualeditor-indentationbutton-outdent-tooltip-trigger',
'visualeditor-listbutton-number-tooltip',
'visualeditor-listbutton-bullet-tooltip',
'visualeditor-clearbutton-tooltip',
'visualeditor-historybutton-undo-tooltip',
'visualeditor-historybutton-undo-tooltip-trigger-mac',
'visualeditor-historybutton-undo-tooltip-trigger-pc',
'visualeditor-historybutton-redo-tooltip',
'visualeditor-historybutton-redo-tooltip-trigger-mac',
'visualeditor-historybutton-redo-tooltip-trigger-pc',
'visualeditor-inspector-close-tooltip',
'visualeditor-inspector-remove-tooltip',
'visualeditor-viewpage-savewarning',
'visualeditor-differror',
'visualeditor-saveerror',
'visualeditor-editconflict',
'visualeditor-aliennode-tooltip',
),
),
'ext.visualEditor.icons-raster' => $wgVisualEditorResourceTemplate + array(
'styles' => array(
've/ui/styles/ve.ui.Icons-raster.css',
),
),
'ext.visualEditor.icons-vector' => $wgVisualEditorResourceTemplate + array(
'styles' => array(
've/ui/styles/ve.ui.Icons-vector.css',
),
),
);
// Parsoid Wrapper API
$wgAutoloadClasses['ApiVisualEditor'] = $dir . 'ApiVisualEditor.php';
$wgAPIModules['visualeditor'] = 'ApiVisualEditor';
// Integration Hooks
$wgAutoloadClasses['VisualEditorHooks'] = $dir . 'VisualEditor.hooks.php';
$wgHooks['BeforePageDisplay'][] = 'VisualEditorHooks::onBeforePageDisplay';
$wgHooks['GetPreferences'][] = 'VisualEditorHooks::onGetPreferences';
$wgHooks['ListDefinedTags'][] = 'VisualEditorHooks::onListDefinedTags';
$wgHooks['MakeGlobalVariablesScript'][] = 'VisualEditorHooks::onMakeGlobalVariablesScript';
$wgHooks['ResourceLoaderTestModules'][] = 'VisualEditorHooks::onResourceLoaderTestModules';
$wgAutoloadClasses['VisualEditorMessagesModule'] = $dir . 'VisualEditorMessagesModule.php';