JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
/*!
|
2013-01-15 23:38:49 +00:00
|
|
|
* VisualEditor MediaWiki Initialization Target class.
|
2012-07-19 21:25:16 +00:00
|
|
|
*
|
2014-01-05 12:05:05 +00:00
|
|
|
* @copyright 2011-2014 VisualEditor Team and others; see AUTHORS.txt
|
2012-07-19 00:11:26 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2014-07-19 17:41:06 +00:00
|
|
|
/*global EasyDeflate */
|
2013-01-22 22:41:22 +00:00
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Initialization MediaWiki target.
|
2012-06-11 06:54:41 +00:00
|
|
|
*
|
|
|
|
* @class
|
2013-02-20 19:44:44 +00:00
|
|
|
* @extends ve.init.Target
|
|
|
|
*
|
2012-06-11 06:54:41 +00:00
|
|
|
* @constructor
|
2013-02-20 19:44:44 +00:00
|
|
|
* @param {jQuery} $container Conainter to render target into
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
* @param {string} pageName Name of target page
|
2013-07-05 07:56:28 +00:00
|
|
|
* @param {number} [revisionId] If the editor should load a revision of the page, pass the
|
|
|
|
* revision id here. Defaults to loading the latest version (see #load).
|
2012-06-11 06:54:41 +00:00
|
|
|
*/
|
2013-07-05 07:56:28 +00:00
|
|
|
ve.init.mw.Target = function VeInitMwTarget( $container, pageName, revisionId ) {
|
2013-12-18 01:29:04 +00:00
|
|
|
var conf = mw.config.get( 'wgVisualEditorConfig' );
|
2013-08-12 05:50:04 +00:00
|
|
|
|
Object management: Object create/inherit/clone utilities
* For the most common case:
- replace ve.extendClass with ve.inheritClass (chose slightly
different names to detect usage of the old/new one, and I
like 'inherit' better).
- move it up to below the constructor, see doc block for why.
* Cases where more than 2 arguments were passed to
ve.extendClass are handled differently depending on the case.
In case of a longer inheritance tree, the other arguments
could be omitted (like in "ve.ce.FooBar, ve.FooBar,
ve.Bar". ve.ce.FooBar only needs to inherit from ve.FooBar,
because ve.ce.FooBar inherits from ve.Bar).
In the case of where it previously had two mixins with
ve.extendClass(), either one becomes inheritClass and one
a mixin, both to mixinClass().
No visible changes should come from this commit as the
instances still all have the same visible properties in the
end. No more or less than before.
* Misc.:
- Be consistent in calling parent constructors in the
same order as the inheritance.
- Add missing @extends and @param documentation.
- Replace invalid {Integer} type hint with {Number}.
- Consistent doc comments order:
@class, @abstract, @constructor, @extends, @params.
- Fix indentation errors
A fairly common mistake was a superfluous space before the
identifier on the assignment line directly below the
documentation comment.
$ ack "^ [^*]" --js modules/ve
- Typo "Inhertiance" -> "Inheritance".
- Replacing the other confusing comment "Inheritance" (inside
the constructor) with "Parent constructor".
- Add missing @abstract for ve.ui.Tool.
- Corrected ve.FormatDropdownTool to ve.ui.FormatDropdownTool.js
- Add function names to all @constructor functions. Now that we
have inheritance it is important and useful to have these
functions not be anonymous.
Example of debug shot: http://cl.ly/image/1j3c160w3D45
Makes the difference between
< documentNode;
> ve_dm_DocumentNode
...
: ve_dm_BranchNode
...
: ve_dm_Node
...
: ve_dm_Node
...
: Object
...
without names (current situation):
< documentNode;
> Object
...
: Object
...
: Object
...
: Object
...
: Object
...
though before this commit, it really looks like this
(flattened since ve.extendClass really did a mixin):
< documentNode;
> Object
...
...
...
Pattern in Sublime (case-sensitive) to find nameless
constructor functions:
"^ve\..*\.([A-Z])([^\.]+) = function \("
Change-Id: Iab763954fb8cf375900d7a9a92dec1c755d5407e
2012-09-05 06:07:47 +00:00
|
|
|
// Parent constructor
|
2013-02-20 19:44:44 +00:00
|
|
|
ve.init.Target.call( this, $container );
|
2012-06-18 20:12:32 +00:00
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
// Properties
|
2012-06-19 04:46:49 +00:00
|
|
|
this.pageName = pageName;
|
2012-12-02 05:09:03 +00:00
|
|
|
this.pageExists = mw.config.get( 'wgArticleId', 0 ) !== 0;
|
2014-05-14 21:11:19 +00:00
|
|
|
|
|
|
|
// Sometimes we actually don't want to send a useful oldid
|
|
|
|
// if we do, PostEdit will give us a 'page restored' message
|
|
|
|
this.requestedRevId = revisionId;
|
2013-07-05 07:56:28 +00:00
|
|
|
this.revid = revisionId || mw.config.get( 'wgCurRevisionId' );
|
2014-05-14 21:11:19 +00:00
|
|
|
|
2013-07-05 07:56:28 +00:00
|
|
|
this.restoring = !!revisionId;
|
2012-06-11 06:54:41 +00:00
|
|
|
this.editToken = mw.user.tokens.get( 'editToken' );
|
2013-11-07 22:21:08 +00:00
|
|
|
this.submitUrl = ( new mw.Uri( mw.util.getUrl( this.pageName ) ) )
|
2014-08-22 20:50:48 +00:00
|
|
|
.extend( { action: 'submit' } );
|
2013-12-10 01:39:46 +00:00
|
|
|
this.events = new ve.init.mw.TargetEvents( this );
|
2013-10-11 13:04:11 +00:00
|
|
|
|
2013-04-16 17:31:17 +00:00
|
|
|
this.modules = [
|
2014-06-26 10:41:18 +00:00
|
|
|
'ext.visualEditor.mwcore',
|
|
|
|
'ext.visualEditor.mwlink',
|
|
|
|
'ext.visualEditor.data',
|
2014-07-01 23:50:57 +00:00
|
|
|
'ext.visualEditor.mwreference.core',
|
2014-07-16 22:34:41 +00:00
|
|
|
'ext.visualEditor.mwtransclusion.core',
|
|
|
|
'ext.visualEditor.mwreference',
|
|
|
|
'ext.visualEditor.mwtransclusion'
|
2014-06-26 10:41:18 +00:00
|
|
|
]
|
2014-05-21 23:02:22 +00:00
|
|
|
.concat( this.constructor.static.iconModuleStyles )
|
2013-10-15 18:36:06 +00:00
|
|
|
.concat( conf.pluginModules || [] );
|
2013-10-11 13:04:11 +00:00
|
|
|
|
2014-08-14 21:16:47 +00:00
|
|
|
if ( ve.init.platform.constructor.static.isInternetExplorer() ) {
|
2014-07-04 00:38:18 +00:00
|
|
|
this.modules.push( 'ext.visualEditor.iehacks' );
|
|
|
|
}
|
|
|
|
|
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
|
|
|
this.pluginCallbacks = [];
|
|
|
|
this.modulesReady = $.Deferred();
|
2013-11-06 08:22:11 +00:00
|
|
|
this.preparedCacheKeyPromise = null;
|
2013-12-03 02:29:11 +00:00
|
|
|
this.clearState();
|
2012-06-11 06:54:41 +00:00
|
|
|
};
|
|
|
|
|
2014-04-10 18:47:34 +00:00
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.init.mw.Target, ve.init.Target );
|
|
|
|
|
2013-12-19 02:06:55 +00:00
|
|
|
/* Events */
|
2013-03-20 07:09:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @event editConflict
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event save
|
2014-01-12 14:23:49 +00:00
|
|
|
* @param {string} html Rendered page HTML from server
|
|
|
|
* @param {string} categoriesHtml Rendered categories HTML from server
|
|
|
|
* @param {number} [newid] New revision id, undefined if unchanged
|
2014-06-10 14:35:29 +00:00
|
|
|
* @param {boolean} isRedirect Whether this page is now a redirect or not.
|
2013-03-20 07:09:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event showChanges
|
|
|
|
* @param {string} diff
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
*/
|
|
|
|
|
2013-05-14 17:40:00 +00:00
|
|
|
/**
|
|
|
|
* @event noChanges
|
|
|
|
*/
|
|
|
|
|
2013-11-26 19:29:14 +00:00
|
|
|
/**
|
|
|
|
* @event saveAsyncBegin
|
|
|
|
* Fired when we're waiting for network
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event saveAsyncComplete
|
|
|
|
* Fired when we're no longer waiting for network
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event saveErrorEmpty
|
|
|
|
* Fired when save API returns no data object
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event saveErrorSpamBlacklist
|
|
|
|
* Fired when save is considered spam or blacklisted
|
|
|
|
* @param {Object} editApi
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event saveErrorAbuseFilter
|
|
|
|
* Fired when AbuseFilter throws warnings
|
|
|
|
* @param {Object} editApi
|
|
|
|
*/
|
|
|
|
|
2013-12-10 01:39:46 +00:00
|
|
|
/**
|
|
|
|
* @event saveErrorBadToken
|
|
|
|
* Fired on save if we have to fetch a new edit token
|
|
|
|
* this is mainly for analytical purposes.
|
|
|
|
*/
|
|
|
|
|
2013-11-26 19:29:14 +00:00
|
|
|
/**
|
|
|
|
* @event saveErrorNewUser
|
|
|
|
* Fired when user is logged in as a new user
|
|
|
|
* @param {boolean|undefined} isAnon Is newly logged in user anonymous. If
|
|
|
|
* undefined, user is logged in
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event saveErrorCaptcha
|
|
|
|
* Fired when saveError indicates captcha field is required
|
|
|
|
* @param {Object} editApi
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event saveErrorUnknown
|
|
|
|
* Fired for any other type of save error
|
|
|
|
* @param {Object} editApi
|
|
|
|
* @param {Object|null} data API response data
|
|
|
|
*/
|
|
|
|
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
/**
|
|
|
|
* @event loadError
|
2013-03-20 07:09:43 +00:00
|
|
|
* @param {jqXHR|null} jqXHR
|
|
|
|
* @param {string} status Text status message
|
|
|
|
* @param {Mixed|null} error HTTP status text
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event saveError
|
2013-03-20 07:09:43 +00:00
|
|
|
* @param {jqXHR|null} jqXHR
|
|
|
|
* @param {string} status Text status message
|
2013-06-29 01:55:09 +00:00
|
|
|
* @param {Object|null} data API response data
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event showChangesError
|
2013-03-20 07:09:43 +00:00
|
|
|
* @param {jqXHR|null} jqXHR
|
|
|
|
* @param {string} status Text status message
|
|
|
|
* @param {Mixed|null} error HTTP status text
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event serializeError
|
|
|
|
* @param {jqXHR|null} jqXHR
|
|
|
|
* @param {string} status Text status message
|
|
|
|
* @param {Mixed|null} error HTTP status text
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
*/
|
|
|
|
|
2013-12-10 01:39:46 +00:00
|
|
|
/**
|
|
|
|
* @event serializeComplete
|
|
|
|
* Fired when serialization is complete
|
|
|
|
*/
|
|
|
|
|
2013-10-11 18:42:46 +00:00
|
|
|
/**
|
|
|
|
* @event sanityCheckComplete
|
|
|
|
*/
|
|
|
|
|
2013-12-13 20:24:54 +00:00
|
|
|
/* Static Properties */
|
|
|
|
|
2014-04-10 18:47:34 +00:00
|
|
|
ve.init.mw.Target.static.citationToolsLimit = 5;
|
|
|
|
|
2013-12-13 20:24:54 +00:00
|
|
|
ve.init.mw.Target.static.toolbarGroups = [
|
|
|
|
// History
|
2014-08-22 20:50:48 +00:00
|
|
|
{ include: [ 'undo', 'redo' ] },
|
2013-12-13 20:24:54 +00:00
|
|
|
// Format
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
type: 'menu',
|
|
|
|
indicator: 'down',
|
|
|
|
title: OO.ui.deferMsg( 'visualeditor-toolbar-format-tooltip' ),
|
|
|
|
include: [ { group: 'format' } ],
|
|
|
|
promote: [ 'paragraph' ],
|
|
|
|
demote: [ 'preformatted', 'heading1' ]
|
2013-12-13 20:24:54 +00:00
|
|
|
},
|
|
|
|
// Style
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
type: 'list',
|
|
|
|
icon: 'text-style',
|
|
|
|
indicator: 'down',
|
|
|
|
title: OO.ui.deferMsg( 'visualeditor-toolbar-style-tooltip' ),
|
|
|
|
include: [ { group: 'textStyle' }, 'language', 'clear' ],
|
|
|
|
promote: [ 'bold', 'italic' ],
|
|
|
|
demote: [ 'strikethrough', 'code', 'underline', 'language', 'clear' ]
|
2013-12-13 20:24:54 +00:00
|
|
|
},
|
|
|
|
// Link
|
2014-08-22 20:50:48 +00:00
|
|
|
{ include: [ 'link' ] },
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
// Cite
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
type: 'list',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-toolbar-cite-label' ),
|
|
|
|
indicator: 'down',
|
|
|
|
include: [ { group: 'cite' }, 'reference', 'reference/existing' ],
|
|
|
|
demote: [ 'reference', 'reference/existing' ]
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
},
|
2014-03-25 00:13:59 +00:00
|
|
|
// Structure
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
type: 'list',
|
|
|
|
icon: 'bullet-list',
|
|
|
|
indicator: 'down',
|
|
|
|
include: [ { group: 'structure' } ],
|
|
|
|
demote: [ 'outdent', 'indent' ]
|
2014-03-25 00:13:59 +00:00
|
|
|
},
|
2013-12-13 20:24:54 +00:00
|
|
|
// Insert
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
label: OO.ui.deferMsg( 'visualeditor-toolbar-insert' ),
|
|
|
|
indicator: 'down',
|
|
|
|
include: '*',
|
|
|
|
promote: [ 'media', 'transclusion' ],
|
|
|
|
demote: [ 'specialcharacter' ]
|
2013-12-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2014-02-06 22:30:07 +00:00
|
|
|
ve.init.mw.Target.static.pasteRules = {
|
2014-08-22 20:50:48 +00:00
|
|
|
external: {
|
|
|
|
blacklist: [
|
2014-02-06 22:30:07 +00:00
|
|
|
// Annotations
|
|
|
|
'link', 'textStyle/span', 'textStyle/underline',
|
|
|
|
// Nodes
|
2014-08-22 20:31:29 +00:00
|
|
|
'inlineImage', 'blockImage', 'div', 'alienInline', 'alienBlock'
|
2014-02-06 22:30:07 +00:00
|
|
|
],
|
2014-08-22 20:50:48 +00:00
|
|
|
removeHtmlAttributes: true
|
2014-02-06 22:30:07 +00:00
|
|
|
},
|
2014-08-22 20:50:48 +00:00
|
|
|
all: null
|
2014-02-06 22:30:07 +00:00
|
|
|
};
|
|
|
|
|
2014-02-06 23:33:21 +00:00
|
|
|
/**
|
|
|
|
* Defines modules needed to style icons.
|
|
|
|
*
|
2014-02-07 22:04:35 +00:00
|
|
|
* @static
|
|
|
|
* @inheritable
|
2014-05-21 23:02:22 +00:00
|
|
|
* @property {string[]} iconModuleStyles Modules that should be loaded to provide the icons
|
2014-02-06 23:33:21 +00:00
|
|
|
*/
|
2014-05-21 23:02:22 +00:00
|
|
|
ve.init.mw.Target.static.iconModuleStyles = [
|
|
|
|
'ext.visualEditor.icons'
|
|
|
|
];
|
2014-02-06 23:33:21 +00:00
|
|
|
|
2013-12-10 01:39:46 +00:00
|
|
|
/**
|
|
|
|
* Name of target class. Used by TargetEvents to identify which target we are tracking.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @property {string}
|
|
|
|
* @inheritable
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.static.name = 'mwTarget';
|
|
|
|
|
2012-06-18 20:12:32 +00:00
|
|
|
/* Static Methods */
|
|
|
|
|
2014-01-05 04:44:13 +00:00
|
|
|
/**
|
|
|
|
* Send an AJAX request to the MediaWiki API.
|
|
|
|
*
|
2014-01-05 04:48:16 +00:00
|
|
|
* This method has special behavior for certain options. If the request type is POST, then
|
|
|
|
* contentType will default to multipart/form-data. If the content type is multipart/form-data,
|
|
|
|
* then the necessary emulation will be performed to make this content type actually work.
|
|
|
|
*
|
2014-01-05 04:44:13 +00:00
|
|
|
* @param {Object} data Query string parameters (for GET requests) or POST data (for POST requests)
|
|
|
|
* @param {Object} [settings] Additional AJAX settings, or overrides of default settings
|
|
|
|
* @returns {jqXHR} Return value of $.ajax()
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.static.apiRequest = function ( data, settings ) {
|
2014-01-05 04:48:16 +00:00
|
|
|
var key, formData;
|
2014-06-09 19:41:35 +00:00
|
|
|
data = ve.extendObject( {
|
2014-08-22 20:50:48 +00:00
|
|
|
format: 'json',
|
|
|
|
uselang: mw.config.get( 'wgUserLanguage' )
|
2014-06-09 19:41:35 +00:00
|
|
|
}, data );
|
2014-01-05 04:44:13 +00:00
|
|
|
settings = ve.extendObject( {
|
2014-08-22 20:50:48 +00:00
|
|
|
url: mw.util.wikiScript( 'api' ),
|
|
|
|
dataType: 'json',
|
|
|
|
type: 'GET',
|
2014-01-05 04:44:13 +00:00
|
|
|
// Wait up to 100 seconds
|
2014-08-22 20:50:48 +00:00
|
|
|
timeout: 100000
|
2014-01-05 04:44:13 +00:00
|
|
|
}, settings );
|
|
|
|
|
2014-01-05 04:48:16 +00:00
|
|
|
// If multipart/form-data has been requested and emulation is possible, emulate it
|
|
|
|
if (
|
|
|
|
settings.type === 'POST' && window.FormData && (
|
|
|
|
settings.contentType === undefined ||
|
|
|
|
settings.contentType === 'multipart/form-data'
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
formData = new FormData();
|
|
|
|
for ( key in data ) {
|
|
|
|
formData.append( key, data[key] );
|
|
|
|
}
|
|
|
|
settings.data = formData;
|
|
|
|
// Prevent jQuery from mangling our FormData object
|
|
|
|
settings.processData = false;
|
|
|
|
// Prevent jQuery from overriding the Content-Type header
|
|
|
|
settings.contentType = false;
|
|
|
|
} else {
|
|
|
|
settings.data = data;
|
|
|
|
if ( settings.contentType === 'multipart/form-data' ) {
|
|
|
|
// We were asked to emulate but can't, so drop the Content-Type header, otherwise
|
|
|
|
// it'll be wrong and the server will fail to decode the POST body
|
|
|
|
delete settings.contentType;
|
|
|
|
}
|
|
|
|
}
|
2014-01-05 04:44:13 +00:00
|
|
|
|
|
|
|
return $.ajax( settings );
|
|
|
|
};
|
|
|
|
|
2014-03-27 04:49:59 +00:00
|
|
|
/**
|
|
|
|
* Take a target document with a possibly relative base URL, and modify it to be absolute.
|
|
|
|
* The base URL of the target document is resolved using the base URL of the source document.
|
|
|
|
* @param {HTMLDocument} targetDoc Document whose base URL should be resolved
|
|
|
|
* @param {HTMLDocument} sourceDoc Document whose base URL should be used for resolution
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.static.fixBase = function ( targetDoc, sourceDoc ) {
|
|
|
|
var $base;
|
|
|
|
if ( !targetDoc.baseURI ) {
|
|
|
|
$base = $( 'base', targetDoc );
|
|
|
|
if ( $base.length ) {
|
|
|
|
// Modify the existing <base> tag
|
|
|
|
$base.attr( 'href', ve.resolveUrl( $base.attr( 'href' ), sourceDoc ) );
|
|
|
|
} else {
|
|
|
|
// No <base> tag, add one
|
|
|
|
$base = $( '<base>', targetDoc ).attr( 'href', sourceDoc.baseURI );
|
|
|
|
$( 'head', sourceDoc ).append( $base );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Handle the RL modules for VE and registered plugin modules being loaded.
|
|
|
|
*
|
|
|
|
* This method is called within the context of a target instance. It executes all registered
|
|
|
|
* plugin callbacks, gathers any promises returned and resolves this.modulesReady when all of
|
|
|
|
* the gathered promises are resolved.
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.onModulesReady = function () {
|
|
|
|
var i, len, callbackResult, promises = [];
|
|
|
|
for ( i = 0, len = this.pluginCallbacks.length; i < len; i++ ) {
|
|
|
|
callbackResult = this.pluginCallbacks[i]( this );
|
|
|
|
if ( callbackResult && callbackResult.then ) { // duck-type jQuery.Promise using .then
|
|
|
|
promises.push( callbackResult );
|
|
|
|
}
|
|
|
|
}
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
this.generateCitationFeatures();
|
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
|
|
|
// Dereference the callbacks
|
|
|
|
this.pluginCallbacks = [];
|
2013-12-12 19:57:23 +00:00
|
|
|
// Add the platform promise to the list
|
|
|
|
promises.push( ve.init.platform.getInitializedPromise() );
|
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
|
|
|
// Create a master promise tracking all the promises we got, and wait for it
|
|
|
|
// to be resolved
|
|
|
|
$.when.apply( $, promises ).done( this.modulesReady.resolve ).fail( this.modulesReady.reject );
|
|
|
|
};
|
|
|
|
|
2012-06-18 20:12:32 +00:00
|
|
|
/**
|
|
|
|
* Handle response to a successful load request.
|
|
|
|
*
|
|
|
|
* This method is called within the context of a target instance. If successful the DOM from the
|
2013-10-11 18:42:46 +00:00
|
|
|
* server will be parsed, stored in {this.doc} and then {this.onReady} will be called once modules
|
|
|
|
* are ready.
|
2012-06-18 20:12:32 +00:00
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @method
|
|
|
|
* @param {Object} response XHR Response object
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
* @param {string} status Text status message
|
2013-10-22 17:54:59 +00:00
|
|
|
* @fires loadError
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2012-09-17 13:30:50 +00:00
|
|
|
ve.init.mw.Target.onLoad = function ( response ) {
|
2013-05-26 15:23:03 +00:00
|
|
|
var data = response ? response.visualeditor : null;
|
2012-12-13 00:22:10 +00:00
|
|
|
|
2012-11-14 18:33:57 +00:00
|
|
|
if ( !data && !response.error ) {
|
2012-11-28 23:57:00 +00:00
|
|
|
ve.init.mw.Target.onLoadError.call(
|
|
|
|
this, null, 'Invalid response in response from server', null
|
|
|
|
);
|
2012-11-14 18:33:57 +00:00
|
|
|
} else if ( response.error || data.result === 'error' ) {
|
2013-07-30 23:52:45 +00:00
|
|
|
ve.init.mw.Target.onLoadError.call( this, null,
|
|
|
|
response.error.code + ': ' + response.error.info,
|
|
|
|
null
|
|
|
|
);
|
2012-11-28 23:57:00 +00:00
|
|
|
} else if ( typeof data.content !== 'string' ) {
|
|
|
|
ve.init.mw.Target.onLoadError.call(
|
|
|
|
this, null, 'No HTML content in response from server', null
|
|
|
|
);
|
2012-06-18 20:12:32 +00:00
|
|
|
} else {
|
2013-04-18 01:22:39 +00:00
|
|
|
this.originalHtml = data.content;
|
2014-09-16 01:39:06 +00:00
|
|
|
this.doc = ve.parseXhtml( this.originalHtml );
|
2012-12-13 00:22:10 +00:00
|
|
|
|
2014-03-27 04:49:59 +00:00
|
|
|
// Parsoid outputs a protocol-relative <base> tag, so absolutize it
|
|
|
|
this.constructor.static.fixBase( this.doc, document );
|
|
|
|
|
2013-06-05 23:37:49 +00:00
|
|
|
this.remoteNotices = ve.getObjectValues( data.notices );
|
2014-04-30 19:28:29 +00:00
|
|
|
this.protectedClasses = data.protectedClasses;
|
2013-11-15 21:31:40 +00:00
|
|
|
this.$checkboxes = $( ve.getObjectValues( data.checkboxes ).join( '' ) );
|
|
|
|
// Populate checkboxes with default values for minor and watch
|
|
|
|
this.$checkboxes
|
|
|
|
.filter( '#wpMinoredit' )
|
|
|
|
.prop( 'checked', mw.user.options.get( 'minordefault' ) )
|
|
|
|
.end()
|
|
|
|
.filter( '#wpWatchthis' )
|
|
|
|
.prop( 'checked',
|
|
|
|
mw.user.options.get( 'watchdefault' ) ||
|
|
|
|
( mw.user.options.get( 'watchcreations' ) && !this.pageExists ) ||
|
|
|
|
mw.config.get( 'wgVisualEditor' ).isPageWatched
|
|
|
|
);
|
2012-12-13 00:22:10 +00:00
|
|
|
|
2012-11-28 23:57:00 +00:00
|
|
|
this.baseTimeStamp = data.basetimestamp;
|
|
|
|
this.startTimeStamp = data.starttimestamp;
|
2013-07-05 07:56:28 +00:00
|
|
|
this.revid = data.oldid;
|
2014-03-11 00:46:26 +00:00
|
|
|
|
|
|
|
// Populate link cache
|
|
|
|
if ( data.links ) {
|
|
|
|
ve.init.platform.linkCache.set( data.links );
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// Everything worked, the page was loaded, continue as soon as the modules are loaded
|
2014-07-08 22:33:32 +00:00
|
|
|
this.modulesReady.done( this.onReady.bind( this ) );
|
2012-06-18 20:12:32 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-05-26 15:23:03 +00:00
|
|
|
/**
|
|
|
|
* Handle the edit notices being ready for rendering.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
2013-10-11 18:42:46 +00:00
|
|
|
ve.init.mw.Target.prototype.onNoticesReady = function () {
|
2013-05-26 15:23:03 +00:00
|
|
|
var i, len, noticeHtmls, tmp, el;
|
|
|
|
|
|
|
|
// Since we're going to parse them, we might as well save these nodes
|
|
|
|
// so we don't have to parse them again later.
|
|
|
|
this.editNotices = {};
|
|
|
|
|
|
|
|
/* Don't show notices without visible html (bug 43013). */
|
|
|
|
|
|
|
|
// This is a temporary container for parsed notices in the <body>.
|
|
|
|
// We need the elements to be in the DOM in order for stylesheets to apply
|
|
|
|
// and jquery.visibleText to determine whether a node is visible.
|
|
|
|
tmp = document.createElement( 'div' );
|
|
|
|
|
|
|
|
// The following is essentially display none, but we can't use that
|
|
|
|
// since then all descendants will be considered invisible too.
|
|
|
|
tmp.style.cssText = 'position: static; top: 0; width: 0; height: 0; border: 0; visibility: hidden;';
|
|
|
|
document.body.appendChild( tmp );
|
|
|
|
|
|
|
|
// Merge locally and remotely generated notices
|
2013-06-05 23:37:49 +00:00
|
|
|
noticeHtmls = this.remoteNotices.slice();
|
2013-05-26 15:23:03 +00:00
|
|
|
for ( i = 0, len = this.localNoticeMessages.length; i < len; i++ ) {
|
|
|
|
noticeHtmls.push(
|
|
|
|
'<p>' + ve.init.platform.getParsedMessage( this.localNoticeMessages[i] ) + '</p>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( i = 0, len = noticeHtmls.length; i < len; i++ ) {
|
|
|
|
el = $( '<div>' )
|
2014-03-12 22:07:39 +00:00
|
|
|
// Public class for usage by third parties to change styling of
|
|
|
|
// edit notices within VisualEditor (bug 43013).
|
|
|
|
.addClass( 'mw-ve-editNotice' )
|
2013-05-26 15:23:03 +00:00
|
|
|
.html( noticeHtmls[i] )
|
|
|
|
.get( 0 );
|
|
|
|
|
|
|
|
tmp.appendChild( el );
|
|
|
|
if ( $.getVisibleText( el ).trim() !== '' ) {
|
|
|
|
this.editNotices[i] = el;
|
|
|
|
}
|
|
|
|
tmp.removeChild( el );
|
|
|
|
}
|
|
|
|
document.body.removeChild( tmp );
|
|
|
|
};
|
|
|
|
|
2012-06-18 20:12:32 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Handle both DOM and modules being loaded and ready.
|
2012-06-18 20:12:32 +00:00
|
|
|
*
|
|
|
|
* @method
|
2013-10-11 18:42:46 +00:00
|
|
|
* @fires surfaceReady
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2013-10-11 18:42:46 +00:00
|
|
|
ve.init.mw.Target.prototype.onReady = function () {
|
2013-05-26 15:23:03 +00:00
|
|
|
// We need to wait until onReady as local notices may require special messages
|
2013-10-11 18:42:46 +00:00
|
|
|
this.onNoticesReady();
|
2012-06-18 20:12:32 +00:00
|
|
|
this.loading = false;
|
2013-12-03 02:21:31 +00:00
|
|
|
this.edited = false;
|
2014-07-08 22:33:32 +00:00
|
|
|
this.setupSurface( this.doc, function () {
|
2013-12-03 02:21:31 +00:00
|
|
|
this.startSanityCheck();
|
|
|
|
this.emit( 'surfaceReady' );
|
2014-07-08 22:33:32 +00:00
|
|
|
}.bind( this ) );
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Handle an unsuccessful load request.
|
2012-06-18 20:12:32 +00:00
|
|
|
*
|
|
|
|
* This method is called within the context of a target instance.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @method
|
2012-12-07 16:23:23 +00:00
|
|
|
* @param {Object} jqXHR
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
* @param {string} status Text status message
|
|
|
|
* @param {Mixed} error HTTP status text
|
2013-10-22 17:54:59 +00:00
|
|
|
* @fires loadError
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2012-12-07 16:23:23 +00:00
|
|
|
ve.init.mw.Target.onLoadError = function ( jqXHR, status, error ) {
|
2012-06-18 20:12:32 +00:00
|
|
|
this.loading = false;
|
2012-12-07 16:23:23 +00:00
|
|
|
this.emit( 'loadError', jqXHR, status, error );
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Handle a successful save request.
|
2012-06-18 20:12:32 +00:00
|
|
|
*
|
|
|
|
* This method is called within the context of a target instance.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @method
|
2014-04-23 19:30:48 +00:00
|
|
|
* @param {HTMLDocument} doc HTML document we tried to save
|
|
|
|
* @param {Object} saveData Options that were used
|
2012-12-07 16:23:23 +00:00
|
|
|
* @param {Object} response Response data
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
* @param {string} status Text status message
|
2013-10-22 17:54:59 +00:00
|
|
|
* @fires editConflict
|
|
|
|
* @fires save
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2014-04-23 19:30:48 +00:00
|
|
|
ve.init.mw.Target.onSave = function ( doc, saveData, response ) {
|
2012-06-18 20:12:32 +00:00
|
|
|
this.saving = false;
|
2013-07-11 17:09:28 +00:00
|
|
|
var data = response.visualeditoredit;
|
2012-11-14 18:33:57 +00:00
|
|
|
if ( !data && !response.error ) {
|
2014-04-23 19:30:48 +00:00
|
|
|
this.onSaveError( doc, saveData, null, 'Invalid response from server', response );
|
2012-11-24 01:41:07 +00:00
|
|
|
} else if ( response.error ) {
|
2013-06-24 17:51:59 +00:00
|
|
|
if ( response.error.code === 'editconflict' ) {
|
2012-11-28 23:57:00 +00:00
|
|
|
this.emit( 'editConflict' );
|
|
|
|
} else {
|
2014-04-23 19:30:48 +00:00
|
|
|
this.onSaveError( doc, saveData, null, 'Save failure', response );
|
2012-11-28 23:57:00 +00:00
|
|
|
}
|
2012-11-24 01:41:07 +00:00
|
|
|
} else if ( data.result !== 'success' ) {
|
2013-06-29 01:55:09 +00:00
|
|
|
// Note, this could be any of db failure, hookabort, badtoken or even a captcha
|
2014-04-23 19:30:48 +00:00
|
|
|
this.onSaveError( doc, saveData, null, 'Save failure', response );
|
2012-06-18 20:12:32 +00:00
|
|
|
} else if ( typeof data.content !== 'string' ) {
|
2014-04-23 19:30:48 +00:00
|
|
|
this.onSaveError( doc, saveData, null, 'Invalid HTML content in response from server', response );
|
2012-06-18 20:12:32 +00:00
|
|
|
} else {
|
2014-06-21 01:37:30 +00:00
|
|
|
this.emit(
|
|
|
|
'save',
|
|
|
|
data.content,
|
|
|
|
data.categorieshtml,
|
|
|
|
data.newrevid,
|
|
|
|
data.isRedirect,
|
|
|
|
data.displayTitleHtml
|
|
|
|
);
|
2012-06-18 20:12:32 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Handle an unsuccessful save request.
|
2012-06-18 20:12:32 +00:00
|
|
|
*
|
2012-12-07 16:23:23 +00:00
|
|
|
* @method
|
2014-04-23 19:30:48 +00:00
|
|
|
* @param {HTMLDocument} doc HTML document we tried to save
|
|
|
|
* @param {Object} saveData Options that were used
|
2012-12-07 16:23:23 +00:00
|
|
|
* @param {Object} jqXHR
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
* @param {string} status Text status message
|
2013-06-29 01:55:09 +00:00
|
|
|
* @param {Object|null} data API response data
|
2013-11-26 19:29:14 +00:00
|
|
|
* @fires saveErrorEmpty
|
|
|
|
* @fires saveErrorSpamBlacklist
|
|
|
|
* @fires saveErrorAbuseFilter
|
2013-12-10 01:39:46 +00:00
|
|
|
* @fires saveErrorBadToken
|
2013-11-26 19:29:14 +00:00
|
|
|
* @fires saveErrorNewUser
|
|
|
|
* @fires saveErrorCaptcha
|
|
|
|
* @fires saveErrorUnknown
|
2012-12-07 16:23:23 +00:00
|
|
|
*/
|
2014-04-23 19:30:48 +00:00
|
|
|
ve.init.mw.Target.prototype.onSaveError = function ( doc, saveData, jqXHR, status, data ) {
|
2013-11-26 19:29:14 +00:00
|
|
|
var api, editApi,
|
|
|
|
viewPage = this;
|
2012-12-07 16:23:23 +00:00
|
|
|
this.saving = false;
|
2013-11-26 19:29:14 +00:00
|
|
|
|
|
|
|
// Handle empty response
|
|
|
|
if ( !data ) {
|
|
|
|
this.emit( 'saveErrorEmpty' );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
editApi = data && data.visualeditoredit && data.visualeditoredit.edit;
|
|
|
|
|
|
|
|
// Handle spam blacklist error (either from core or from Extension:SpamBlacklist)
|
|
|
|
if ( editApi && editApi.spamblacklist ) {
|
|
|
|
this.emit( 'saveErrorSpamBlacklist', editApi );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle warnings/errors from Extension:AbuseFilter
|
|
|
|
// TODO: Move this to a plugin
|
|
|
|
if ( editApi && editApi.info && editApi.info.indexOf( 'Hit AbuseFilter:' ) === 0 && editApi.warning ) {
|
|
|
|
this.emit( 'saveErrorAbuseFilter', editApi );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle token errors
|
|
|
|
if ( data.error && data.error.code === 'badtoken' ) {
|
|
|
|
api = new mw.Api();
|
|
|
|
api.get( {
|
|
|
|
// action=query&meta=userinfo and action=tokens&type=edit can't be combined
|
|
|
|
// but action=query&meta=userinfo and action=query&prop=info can, however
|
|
|
|
// that means we have to give it titles and deal with page ids.
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'query',
|
|
|
|
meta: 'userinfo',
|
|
|
|
prop: 'info',
|
2013-11-26 19:29:14 +00:00
|
|
|
// Try to send the normalised form so that it is less likely we get extra data like
|
|
|
|
// data.normalised back that we don't need.
|
2014-08-22 20:50:48 +00:00
|
|
|
titles: new mw.Title( viewPage.pageName ).toText(),
|
|
|
|
indexpageids: '',
|
|
|
|
intoken: 'edit'
|
2013-11-26 19:29:14 +00:00
|
|
|
} )
|
|
|
|
.always( function () {
|
2013-12-10 01:39:46 +00:00
|
|
|
viewPage.emit( 'saveErrorBadToken' );
|
2013-11-26 19:29:14 +00:00
|
|
|
} )
|
|
|
|
.done( function ( data ) {
|
|
|
|
var userMsg,
|
|
|
|
userInfo = data.query && data.query.userinfo,
|
|
|
|
pageInfo = data.query && data.query.pages && data.query.pageids &&
|
|
|
|
data.query.pageids[0] && data.query.pages[ data.query.pageids[0] ],
|
|
|
|
editToken = pageInfo && pageInfo.edittoken,
|
|
|
|
isAnon = mw.user.isAnon();
|
|
|
|
|
|
|
|
if ( userInfo && editToken ) {
|
|
|
|
viewPage.editToken = editToken;
|
|
|
|
|
|
|
|
if (
|
|
|
|
( isAnon && userInfo.anon !== undefined ) ||
|
|
|
|
// Comparing id instead of name to pretect against possible
|
|
|
|
// normalisation and against case where the user got renamed.
|
|
|
|
mw.config.get( 'wgUserId' ) === userInfo.id
|
|
|
|
) {
|
|
|
|
// New session is the same user still
|
2014-04-23 19:30:48 +00:00
|
|
|
viewPage.save( doc, saveData );
|
2013-11-26 19:29:14 +00:00
|
|
|
} else {
|
|
|
|
// The now current session is a different user
|
|
|
|
if ( isAnon ) {
|
|
|
|
// New session is an anonymous user
|
|
|
|
mw.config.set( {
|
|
|
|
// wgUserId is unset for anonymous users, not set to null
|
2014-08-22 20:50:48 +00:00
|
|
|
wgUserId: undefined,
|
2013-11-26 19:29:14 +00:00
|
|
|
// wgUserName is explicitly set to null for anonymous users,
|
|
|
|
// functions like mw.user.isAnon rely on this.
|
2014-08-22 20:50:48 +00:00
|
|
|
wgUserName: null
|
2013-11-26 19:29:14 +00:00
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
// New session is a different user
|
2014-08-22 20:50:48 +00:00
|
|
|
mw.config.set( { wgUserId: userInfo.id, wgUserName: userInfo.name } );
|
2013-11-26 19:29:14 +00:00
|
|
|
userMsg = 'visualeditor-savedialog-identify-user---' + userInfo.name;
|
|
|
|
mw.messages.set(
|
|
|
|
userMsg,
|
|
|
|
mw.messages.get( 'visualeditor-savedialog-identify-user' )
|
|
|
|
.replace( /\$1/g, userInfo.name )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
viewPage.emit( 'saveErrorNewUser', isAnon );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle captcha
|
|
|
|
// Captcha "errors" usually aren't errors. We simply don't know about them ahead of time,
|
|
|
|
// so we save once, then (if required) we get an error with a captcha back and try again after
|
|
|
|
// the user solved the captcha.
|
|
|
|
// TODO: ConfirmEdit API is horrible, there is no reliable way to know whether it is a "math",
|
|
|
|
// "question" or "fancy" type of captcha. They all expose differently named properties in the
|
2014-04-23 22:24:46 +00:00
|
|
|
// API for different things in the UI. At this point we only support the SimpleCaptcha and FancyCaptcha
|
|
|
|
// which we very intuitively detect by the presence of a "url" property.
|
2014-04-24 19:17:21 +00:00
|
|
|
if ( editApi && editApi.captcha && (
|
|
|
|
editApi.captcha.url ||
|
|
|
|
editApi.captcha.type === 'simple' ||
|
|
|
|
editApi.captcha.type === 'math' ||
|
|
|
|
editApi.captcha.type === 'question'
|
|
|
|
) ) {
|
2013-11-26 19:29:14 +00:00
|
|
|
this.emit( 'saveErrorCaptcha', editApi );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle (other) unknown and/or unrecoverable errors
|
|
|
|
this.emit( 'saveErrorUnknown', editApi, data );
|
2012-12-07 16:23:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Handle a successful show changes request.
|
2012-06-18 20:12:32 +00:00
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @method
|
2013-03-20 07:09:43 +00:00
|
|
|
* @param {Object} response API response data
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
* @param {string} status Text status message
|
2013-10-22 17:54:59 +00:00
|
|
|
* @fires showChanges
|
|
|
|
* @fires noChanges
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2012-12-07 16:23:23 +00:00
|
|
|
ve.init.mw.Target.onShowChanges = function ( response ) {
|
|
|
|
var data = response.visualeditor;
|
2013-11-06 08:22:11 +00:00
|
|
|
this.diffing = false;
|
2012-12-07 16:23:23 +00:00
|
|
|
if ( !data && !response.error ) {
|
|
|
|
ve.init.mw.Target.onShowChangesError.call( this, null, 'Invalid response from server', null );
|
|
|
|
} else if ( response.error ) {
|
|
|
|
ve.init.mw.Target.onShowChangesError.call(
|
|
|
|
this, null, 'Unsuccessful request: ' + response.error.info, null
|
|
|
|
);
|
2013-05-14 17:40:00 +00:00
|
|
|
} else if ( data.result === 'nochanges' ) {
|
|
|
|
this.emit( 'noChanges' );
|
2012-12-07 16:23:23 +00:00
|
|
|
} else if ( data.result !== 'success' ) {
|
|
|
|
ve.init.mw.Target.onShowChangesError.call( this, null, 'Failed request: ' + data.result, null );
|
|
|
|
} else if ( typeof data.diff !== 'string' ) {
|
|
|
|
ve.init.mw.Target.onShowChangesError.call(
|
|
|
|
this, null, 'Invalid HTML content in response from server', null
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this.emit( 'showChanges', data.diff );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-11-06 08:22:11 +00:00
|
|
|
* Handle errors during showChanges action.
|
2012-12-07 16:23:23 +00:00
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @method
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
* @this ve.init.mw.Target
|
2012-12-07 16:23:23 +00:00
|
|
|
* @param {Object} jqXHR
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
* @param {string} status Text status message
|
|
|
|
* @param {Mixed} error HTTP status text
|
2013-10-22 17:54:59 +00:00
|
|
|
* @fires showChangesError
|
2012-12-07 16:23:23 +00:00
|
|
|
*/
|
|
|
|
ve.init.mw.Target.onShowChangesError = function ( jqXHR, status, error ) {
|
2013-11-06 08:22:11 +00:00
|
|
|
this.diffing = false;
|
2012-12-07 16:23:23 +00:00
|
|
|
this.emit( 'showChangesError', jqXHR, status, error );
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
2012-11-28 23:57:00 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Handle a successful serialize request.
|
2012-11-28 23:57:00 +00:00
|
|
|
*
|
|
|
|
* This method is called within the context of a target instance.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @method
|
2013-03-20 07:09:43 +00:00
|
|
|
* @param {Object} data API response data
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
* @param {string} status Text status message
|
2013-12-10 01:39:46 +00:00
|
|
|
* @fires serializeComplete
|
2012-11-28 23:57:00 +00:00
|
|
|
*/
|
|
|
|
ve.init.mw.Target.onSerialize = function ( response ) {
|
|
|
|
this.serializing = false;
|
2012-11-30 23:00:04 +00:00
|
|
|
var data = response.visualeditor;
|
2012-11-28 23:57:00 +00:00
|
|
|
if ( !data && !response.error ) {
|
|
|
|
ve.init.mw.Target.onSerializeError.call( this, null, 'Invalid response from server', null );
|
2013-05-15 15:28:51 +00:00
|
|
|
} else if ( response.error ) {
|
|
|
|
ve.init.mw.Target.onSerializeError.call(
|
|
|
|
this, null, 'Unsuccessful request: ' + response.error.info, null
|
|
|
|
);
|
|
|
|
} else if ( data.result === 'error' ) {
|
2012-11-28 23:57:00 +00:00
|
|
|
ve.init.mw.Target.onSerializeError.call( this, null, 'Server error', null );
|
|
|
|
} else if ( typeof data.content !== 'string' ) {
|
|
|
|
ve.init.mw.Target.onSerializeError.call(
|
|
|
|
this, null, 'No Wikitext content in response from server', null
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
if ( typeof this.serializeCallback === 'function' ) {
|
|
|
|
this.serializeCallback( data.content );
|
2013-12-10 01:39:46 +00:00
|
|
|
this.emit( 'serializeComplete' );
|
2012-11-28 23:57:00 +00:00
|
|
|
delete this.serializeCallback;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Handle an unsuccessful serialize request.
|
2012-11-28 23:57:00 +00:00
|
|
|
*
|
|
|
|
* This method is called within the context of a target instance.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @method
|
2013-03-20 07:09:43 +00:00
|
|
|
* @param {jqXHR|null} jqXHR
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
* @param {string} status Text status message
|
2013-03-20 07:09:43 +00:00
|
|
|
* @param {Mixed|null} error HTTP status text
|
2013-10-22 17:54:59 +00:00
|
|
|
* @fires serializeError
|
2012-11-28 23:57:00 +00:00
|
|
|
*/
|
2013-03-20 07:09:43 +00:00
|
|
|
ve.init.mw.Target.onSerializeError = function ( jqXHR, status, error ) {
|
2012-11-28 23:57:00 +00:00
|
|
|
this.serializing = false;
|
2013-03-20 07:09:43 +00:00
|
|
|
this.emit( 'serializeError', jqXHR, status, error );
|
2012-11-28 23:57:00 +00:00
|
|
|
};
|
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
/* Methods */
|
|
|
|
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
/**
|
|
|
|
* Add reference insertion tools from on-wiki data.
|
|
|
|
*
|
|
|
|
* By adding a definition in JSON to MediaWiki:Visualeditor-cite-tool-definition, the cite menu can
|
|
|
|
* be populated with tools that create refrences containing a specific templates. The content of the
|
|
|
|
* definition should be an array containing a series of objects, one for each tool. Each object must
|
|
|
|
* contain a `name`, `icon` and `template` property. An optional `title` property can also be used
|
|
|
|
* to define the tool title in plain text. The `name` property is a unique identifier for the tool,
|
|
|
|
* and also provides a fallback title for the tool by being transformed into a message key. The name
|
|
|
|
* is prefixed with `visualeditor-cite-tool-name-`, and messages can be defined on Wiki. Some common
|
|
|
|
* messages are pre-defined for tool names such as `web`, `book`, `news` and `journal`.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [ { "name": "web", "icon": "cite-web", "template": "Cite web" }, ... ]
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.generateCitationFeatures = function () {
|
2014-04-10 18:47:34 +00:00
|
|
|
var i, len, item, name, data, tool, tools, dialog,
|
|
|
|
limit = this.constructor.static.citationToolsLimit;
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
|
2014-03-25 18:26:14 +00:00
|
|
|
if ( !ve.ui.MWCitationDialog ) {
|
|
|
|
// Citation module isn't loaded, so skip this
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
/*jshint loopfunc:true */
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Must use mw.message to avoid JSON being parsed as Wikitext
|
|
|
|
tools = JSON.parse( mw.message( 'visualeditor-cite-tool-definition.json' ).plain() );
|
|
|
|
} catch ( e ) { }
|
|
|
|
|
2014-09-24 00:58:09 +00:00
|
|
|
if ( Array.isArray( tools ) ) {
|
2014-04-10 18:47:34 +00:00
|
|
|
for ( i = 0, len = Math.min( limit, tools.length ); i < len; i++ ) {
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
item = tools[i];
|
2014-08-22 20:50:48 +00:00
|
|
|
data = { template: item.template };
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
// Generate transclusion tool
|
2014-04-02 23:29:04 +00:00
|
|
|
name = 'cite-transclusion-' + item.name;
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
tool = function GeneratedMWTransclusionDialogTool( toolbar, config ) {
|
|
|
|
ve.ui.MWTransclusionDialogTool.call( this, toolbar, config );
|
|
|
|
};
|
|
|
|
OO.inheritClass( tool, ve.ui.MWTransclusionDialogTool );
|
|
|
|
tool.static.group = 'cite-transclusion';
|
|
|
|
tool.static.name = name;
|
|
|
|
tool.static.icon = item.icon;
|
|
|
|
tool.static.title = item.title;
|
2014-04-02 23:29:04 +00:00
|
|
|
tool.static.commandName = name;
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
tool.static.template = item.template;
|
|
|
|
tool.static.autoAddToCatchall = false;
|
|
|
|
tool.static.autoAddToGroup = true;
|
|
|
|
ve.ui.toolFactory.register( tool );
|
2014-04-02 23:29:04 +00:00
|
|
|
ve.ui.commandRegistry.register(
|
2014-04-21 22:31:21 +00:00
|
|
|
new ve.ui.Command( name, 'window', 'open', 'transclusion', data )
|
2014-04-02 23:29:04 +00:00
|
|
|
);
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
// Generate citation tool
|
|
|
|
name = 'cite-' + item.name;
|
|
|
|
tool = function GeneratedMWCitationDialogTool( toolbar, config ) {
|
|
|
|
ve.ui.MWCitationDialogTool.call( this, toolbar, config );
|
|
|
|
};
|
|
|
|
OO.inheritClass( tool, ve.ui.MWCitationDialogTool );
|
|
|
|
tool.static.group = 'cite';
|
|
|
|
tool.static.name = name;
|
|
|
|
tool.static.icon = item.icon;
|
|
|
|
tool.static.title = item.title;
|
2014-04-02 23:29:04 +00:00
|
|
|
tool.static.commandName = name;
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
tool.static.template = item.template;
|
|
|
|
tool.static.autoAddToCatchall = false;
|
|
|
|
tool.static.autoAddToGroup = true;
|
|
|
|
ve.ui.toolFactory.register( tool );
|
2014-04-02 23:29:04 +00:00
|
|
|
ve.ui.commandRegistry.register(
|
2014-04-21 22:31:21 +00:00
|
|
|
new ve.ui.Command( name, 'window', 'open', name, data )
|
2014-04-02 23:29:04 +00:00
|
|
|
);
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
// Generate dialog
|
2014-04-04 17:42:13 +00:00
|
|
|
dialog = function GeneratedMWCitationDialog( config ) {
|
|
|
|
ve.ui.MWCitationDialog.call( this, config );
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
};
|
|
|
|
OO.inheritClass( dialog, ve.ui.MWCitationDialog );
|
|
|
|
dialog.static.name = name;
|
|
|
|
dialog.static.icon = item.icon;
|
|
|
|
dialog.static.title = item.title;
|
2014-04-21 22:31:21 +00:00
|
|
|
ve.ui.windowFactory.register( dialog );
|
Ultra-mega-hyper-citation editing on crack
Objectives:
* Allow users on-wiki to create tools and dialogs for citation templates
of their choosing
* Allow editing of citation templates directly, without having to go
through the reference dialog
* Provide citation template tools within reference editing that use the
same titles and icons as the citation tools do, but don't wrap the
inserted content in a ref tag
Changes:
* Reference list was cloning the DOM element it was inserting into its
view before the generated content node could finish rendering, so it
never ended up showing the finished rendering in the reference list
* Documenting hack about use of reference list node's destroy method,
and how we are depending on destroy not canceling generated content
rendering
* Introduced reference model
* Added saving/updating method to transclusion model
* Added getPartsList method to dm transclusion node, which caches the
result and invalidates the cache on update
* Added citation dialog, which extends transclusion dialog
* Added cite group to toolbars, cite-template in reference dialog toolbar
* Factored out getting the node to edit and saving changes procedures in
transclusion dialog so they could be extended in citation dialog
* Updated uses of autoAdd as per changes in oojs-ui (Ic353f91)
* Renamed MWDialogTool file since there was only one tool in it
* Expanded TransclusionDialogTool file out since there is now more logic
to it
* Switched to using ve.dm.MWReferenceModel instead of plain objects in
reference search widget
Configuration:
If you add to MediaWiki:Visualeditor-cite-tool-definition.json the
following code you will magically be presented with a delightful array
of citation options:
[
{ "name": "web", "icon": "ref-cite-web", "template": "Cite web" },
{ "name": "book", "icon": "ref-cite-book", "template": "Cite book" },
{ "name": "news", "icon": "ref-cite-news", "template": "Cite news" },
{ "name": "journal", "icon": "ref-cite-journal", "template": "Cite journal" }
]
...or...
[
{
"name": "any-name",
"icon": "any-ooui-icon",
"template": "Any template",
"title": "Any title text"
}
]
The title text is derived either from the title property or from the name
property by pre-pending the string 'visualeditor-cite-tool-name-' to
generate a message key. Titles for 'web', 'book', 'news' and 'journal' are
provided. The icon is a normal oo-ui-icon name, and more icons can be
added, as usual, by adding a class called .oo-ui-icon-{icon name} to
MediaWiki:Common.css. 'ref-cite-web', 'ref-cite-book', 'ref-cite-news'
and 'ref-cite-journal' are provided. The template name is simply the name
of the template without its namespace prefix.
Depends on Ic353f91 in oojs-ui
Bug: 50110
Bug: 50768
Change-Id: Id401d973b8d5fe2faec481cc777c17a24fd19dd4
2014-03-21 18:56:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Add a plugin module or callback.
|
|
|
|
*
|
|
|
|
* @param {string|Function} plugin Plugin module or callback
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.addPlugin = function ( plugin ) {
|
|
|
|
if ( typeof plugin === 'string' ) {
|
|
|
|
this.modules.push( plugin );
|
|
|
|
} else if ( $.isFunction( plugin ) ) {
|
|
|
|
this.pluginCallbacks.push( plugin );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an array of plugins.
|
|
|
|
*
|
|
|
|
* @see #addPlugin
|
|
|
|
* @param {Array} plugins
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.addPlugins = function ( plugins ) {
|
|
|
|
var i, len;
|
|
|
|
for ( i = 0, len = plugins.length; i < len; i++ ) {
|
|
|
|
this.addPlugin( plugins[i] );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-05-11 00:03:48 +00:00
|
|
|
/**
|
|
|
|
* Get HTML to send to Parsoid. This takes a document generated by the converter and
|
|
|
|
* transplants the head tag from the old document into it, as well as the attributes on the
|
|
|
|
* html and body tags.
|
|
|
|
*
|
|
|
|
* @param {HTMLDocument} newDoc Document generated by ve.dm.Converter. Will be modified.
|
|
|
|
* @returns {string} Full HTML document
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.getHtml = function ( newDoc ) {
|
|
|
|
var i, len, oldDoc = this.doc;
|
|
|
|
|
|
|
|
function copyAttributes( from, to ) {
|
|
|
|
var i, len;
|
|
|
|
for ( i = 0, len = from.attributes.length; i < len; i++ ) {
|
|
|
|
to.setAttribute( from.attributes[i].name, from.attributes[i].value );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the head from the old document
|
|
|
|
for ( i = 0, len = oldDoc.head.childNodes.length; i < len; i++ ) {
|
|
|
|
newDoc.head.appendChild( oldDoc.head.childNodes[i].cloneNode( true ) );
|
|
|
|
}
|
|
|
|
// Copy attributes from the old document for the html, head and body
|
|
|
|
copyAttributes( oldDoc.documentElement, newDoc.documentElement );
|
|
|
|
copyAttributes( oldDoc.head, newDoc.head );
|
|
|
|
copyAttributes( oldDoc.body, newDoc.body );
|
2014-09-30 21:31:55 +00:00
|
|
|
$( newDoc )
|
|
|
|
.remove( 'div[id = myEventWatcherDiv]' ) // Bug 51423
|
|
|
|
.remove( 'embed[type = "application/iodbc"]' ) // Bug 51521
|
|
|
|
.remove( 'embed[type = "application/x-datavault"]' ) // Bug 52791
|
|
|
|
.remove( 'script[id = FoxLingoJs]' ) // Bug 52884
|
|
|
|
.remove( 'style[id = _clearly_component__css]' ) // Bug 53252
|
|
|
|
.remove( 'div[id = sendToInstapaperResults]' ) // Bug 61776
|
|
|
|
.remove( 'embed[id ^= xunlei_com_thunder_helper_plugin]' ) // Bug 63121
|
|
|
|
.remove( 'object[type = cosymantecnisbfw], script[id=NortonInternetSecurityBF]' ) // Bug 63229
|
2014-09-30 22:01:00 +00:00
|
|
|
.remove( 'div[id = kloutify]' ) // Bug 67006
|
2014-10-01 18:04:31 +00:00
|
|
|
.remove( 'div[id ^= mittoHidden]' ); // Bug 68900#c1
|
2014-09-16 01:39:06 +00:00
|
|
|
// Add doctype manually
|
|
|
|
return '<!doctype html>' + ve.serializeXhtml( newDoc );
|
2013-05-11 00:03:48 +00:00
|
|
|
};
|
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get DOM data from the Parsoid API.
|
2012-06-11 06:54:41 +00:00
|
|
|
*
|
|
|
|
* This method performs an asynchronous action and uses a callback function to handle the result.
|
|
|
|
*
|
2012-11-28 23:57:00 +00:00
|
|
|
* A side-effect of calling this method is that it requests {this.modules} be loaded.
|
2012-06-11 06:54:41 +00:00
|
|
|
*
|
|
|
|
* @method
|
2013-10-11 18:42:46 +00:00
|
|
|
* @param {string[]} [additionalModules=[]] Resource loader modules
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
* @returns {boolean} Loading has been started
|
2012-06-11 06:54:41 +00:00
|
|
|
*/
|
2013-10-11 18:42:46 +00:00
|
|
|
ve.init.mw.Target.prototype.load = function ( additionalModules ) {
|
2013-12-10 01:39:46 +00:00
|
|
|
var data, start, xhr, target = this;
|
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
// Prevent duplicate requests
|
2012-06-18 20:12:32 +00:00
|
|
|
if ( this.loading ) {
|
2012-06-11 06:54:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-12-10 01:39:46 +00:00
|
|
|
this.events.timings.activationStart = ve.now();
|
2012-06-11 06:54:41 +00:00
|
|
|
// Start loading the module immediately
|
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
|
|
|
mw.loader.using(
|
|
|
|
// Wait for site and user JS before running plugins
|
2013-10-11 18:42:46 +00:00
|
|
|
this.modules.concat( additionalModules || [] ),
|
2014-07-08 22:33:32 +00:00
|
|
|
ve.init.mw.Target.onModulesReady.bind( this )
|
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
|
|
|
);
|
2013-07-05 07:56:28 +00:00
|
|
|
|
|
|
|
data = {
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'visualeditor',
|
|
|
|
paction: 'parse',
|
|
|
|
page: this.pageName
|
2013-07-05 07:56:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Only request the API to explicitly load the currently visible revision if we're restoring
|
|
|
|
// from oldid. Otherwise we should load the latest version. This prevents us from editing an
|
|
|
|
// old version if an edit was made while the user was viewing the page and/or the user is
|
|
|
|
// seeing (slightly) stale cache.
|
|
|
|
if ( this.restoring ) {
|
|
|
|
data.oldid = this.revid;
|
|
|
|
}
|
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
// Load DOM
|
2013-10-06 06:12:51 +00:00
|
|
|
start = ve.now();
|
|
|
|
|
2014-02-06 00:17:38 +00:00
|
|
|
xhr = this.constructor.static.apiRequest( data );
|
2014-06-26 10:41:18 +00:00
|
|
|
this.loading = xhr.then(
|
|
|
|
function ( data, status, jqxhr ) {
|
2013-12-10 01:39:46 +00:00
|
|
|
target.events.track( 'performance.system.domLoad', {
|
2014-08-22 20:50:48 +00:00
|
|
|
bytes: $.byteLength( jqxhr.responseText ),
|
|
|
|
duration: ve.now() - start,
|
|
|
|
cacheHit: /hit/i.test( jqxhr.getResponseHeader( 'X-Cache' ) ),
|
|
|
|
parsoid: jqxhr.getResponseHeader( 'X-Parsoid-Performance' )
|
2013-10-24 05:44:27 +00:00
|
|
|
} );
|
|
|
|
return jqxhr;
|
2014-06-26 10:41:18 +00:00
|
|
|
}
|
|
|
|
)
|
2014-07-08 22:33:32 +00:00
|
|
|
.done( ve.init.mw.Target.onLoad.bind( this ) )
|
|
|
|
.fail( ve.init.mw.Target.onLoadError.bind( this ) )
|
2014-08-22 20:50:48 +00:00
|
|
|
.promise( { abort: xhr.abort } );
|
2013-10-06 06:12:51 +00:00
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2013-12-03 02:29:11 +00:00
|
|
|
/**
|
|
|
|
* Clear the state of this target, preparing it to be reactivated later.
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.clearState = function () {
|
|
|
|
this.clearPreparedCacheKey();
|
|
|
|
this.loading = false;
|
|
|
|
this.saving = false;
|
|
|
|
this.diffing = false;
|
|
|
|
this.serializing = false;
|
|
|
|
this.submitting = false;
|
|
|
|
this.baseTimeStamp = null;
|
|
|
|
this.startTimeStamp = null;
|
|
|
|
this.doc = null;
|
|
|
|
this.originalHtml = null;
|
|
|
|
this.editNotices = null;
|
|
|
|
this.$checkboxes = null;
|
|
|
|
this.remoteNotices = [];
|
|
|
|
this.localNoticeMessages = [];
|
|
|
|
this.sanityCheckFinished = false;
|
|
|
|
this.sanityCheckVerified = false;
|
|
|
|
};
|
|
|
|
|
2013-11-06 08:22:11 +00:00
|
|
|
/**
|
|
|
|
* Serialize the current document and store the result in the serialization cache on the server.
|
|
|
|
*
|
|
|
|
* This function returns a promise that is resolved once serialization is complete, with the
|
|
|
|
* cache key passed as the first parameter.
|
|
|
|
*
|
|
|
|
* If there's already a request pending for the same (reference-identical) HTMLDocument, this
|
|
|
|
* function will not initiate a new request but will return the promise for the pending request.
|
|
|
|
* If a request for the same document has already been completed, this function will keep returning
|
|
|
|
* the same promise (which will already have been resolved) until clearPreparedCacheKey() is called.
|
|
|
|
*
|
|
|
|
* @param {HTMLDocument} doc Document to serialize
|
|
|
|
* @returns {jQuery.Promise} Abortable promise, resolved with the cache key.
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.prepareCacheKey = function ( doc ) {
|
2013-12-10 01:39:46 +00:00
|
|
|
var xhr, html, start = ve.now(), deferred = $.Deferred(), target = this;
|
2013-11-06 08:22:11 +00:00
|
|
|
|
|
|
|
if ( this.preparedCacheKeyPromise && this.preparedCacheKeyPromise.doc === doc ) {
|
|
|
|
return this.preparedCacheKeyPromise;
|
|
|
|
}
|
|
|
|
this.clearPreparedCacheKey();
|
|
|
|
|
2014-06-23 17:55:59 +00:00
|
|
|
html = EasyDeflate.deflate( this.getHtml( doc ) );
|
|
|
|
|
2014-01-05 04:44:13 +00:00
|
|
|
xhr = this.constructor.static.apiRequest( {
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'visualeditor',
|
|
|
|
paction: 'serializeforcache',
|
|
|
|
html: html,
|
|
|
|
page: this.pageName,
|
|
|
|
oldid: this.revid
|
|
|
|
}, { type: 'POST' } )
|
2013-11-06 08:22:11 +00:00
|
|
|
.done( function ( response ) {
|
2014-08-22 20:50:48 +00:00
|
|
|
var trackData = { duration: ve.now() - start };
|
2013-11-06 08:22:11 +00:00
|
|
|
if ( response.visualeditor && typeof response.visualeditor.cachekey === 'string' ) {
|
2013-12-10 01:39:46 +00:00
|
|
|
target.events.track( 'performance.system.serializeforcache', trackData );
|
2013-11-06 08:22:11 +00:00
|
|
|
deferred.resolve( response.visualeditor.cachekey );
|
|
|
|
} else {
|
2013-12-10 01:39:46 +00:00
|
|
|
target.events.track( 'performance.system.serializeforcache.nocachekey', trackData );
|
2013-11-06 08:22:11 +00:00
|
|
|
deferred.reject();
|
|
|
|
}
|
|
|
|
} )
|
|
|
|
.fail( function () {
|
2014-08-22 20:50:48 +00:00
|
|
|
target.events.track( 'performance.system.serializeforcache.fail', { duration: ve.now() - start } );
|
2013-11-06 08:22:11 +00:00
|
|
|
deferred.reject();
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.preparedCacheKeyPromise = deferred.promise( {
|
2014-08-22 20:50:48 +00:00
|
|
|
abort: xhr.abort,
|
|
|
|
html: html,
|
|
|
|
doc: doc
|
2013-11-06 08:22:11 +00:00
|
|
|
} );
|
|
|
|
return this.preparedCacheKeyPromise;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the prepared wikitext, if any. Same as prepareWikitext() but does not initiate a request
|
|
|
|
* if one isn't already pending or finished. Instead, it returns a rejected promise in that case.
|
|
|
|
*
|
|
|
|
* @param {HTMLDocument} doc Document to serialize
|
|
|
|
* @returns {jQuery.Promise} Abortable promise, resolved with the cache key.
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.getPreparedCacheKey = function ( doc ) {
|
|
|
|
var deferred;
|
|
|
|
if ( this.preparedCacheKeyPromise && this.preparedCacheKeyPromise.doc === doc ) {
|
|
|
|
return this.preparedCacheKeyPromise;
|
|
|
|
}
|
|
|
|
deferred = $.Deferred();
|
|
|
|
deferred.reject();
|
|
|
|
return deferred.promise();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the promise for the prepared wikitext cache key, and abort it if it's still in progress.
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.clearPreparedCacheKey = function () {
|
|
|
|
if ( this.preparedCacheKeyPromise ) {
|
|
|
|
this.preparedCacheKeyPromise.abort();
|
|
|
|
this.preparedCacheKeyPromise = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Try submitting an API request with a cache key for prepared wikitext, falling back to submitting
|
|
|
|
* HTML directly if there is no cache key present or pending, or if the request for the cache key
|
|
|
|
* fails, or if using the cache key fails with a badcachekey error.
|
|
|
|
*
|
|
|
|
* @param {HTMLDocument} doc Document to submit
|
|
|
|
* @param {Object} options POST parameters to send. Do not include 'html', 'cachekey' or 'format'.
|
|
|
|
* @param {string} [eventName] If set, log an event when the request completes successfully. The
|
|
|
|
* full event name used will be 'performance.system.{eventName}.withCacheKey' or .withoutCacheKey
|
|
|
|
* depending on whether or not a cache key was used.
|
|
|
|
* @returns {jQuery.Promise}
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.tryWithPreparedCacheKey = function ( doc, options, eventName ) {
|
|
|
|
var data, preparedCacheKey = this.getPreparedCacheKey( doc ), target = this;
|
2014-08-22 20:50:48 +00:00
|
|
|
data = ve.extendObject( {}, options, { format: 'json' } );
|
2013-11-06 08:22:11 +00:00
|
|
|
|
|
|
|
function ajaxRequest( cachekey ) {
|
|
|
|
var start = ve.now();
|
|
|
|
if ( typeof cachekey === 'string' ) {
|
|
|
|
data.cachekey = cachekey;
|
|
|
|
} else {
|
|
|
|
// Getting a cache key failed, fall back to sending the HTML
|
2014-06-23 17:55:59 +00:00
|
|
|
data.html = preparedCacheKey && preparedCacheKey.html || EasyDeflate.deflate( target.getHtml( doc ) );
|
2013-11-06 08:22:11 +00:00
|
|
|
// If using the cache key fails, we'll come back here with cachekey still set
|
|
|
|
delete data.cachekey;
|
|
|
|
}
|
2014-08-22 20:50:48 +00:00
|
|
|
return target.constructor.static.apiRequest( data, { type: 'POST' } )
|
2013-11-06 08:22:11 +00:00
|
|
|
.then( function ( response, status, jqxhr ) {
|
|
|
|
var fullEventName, eventData = {
|
2014-08-22 20:50:48 +00:00
|
|
|
bytes: $.byteLength( jqxhr.responseText ),
|
|
|
|
duration: ve.now() - start,
|
|
|
|
parsoid: jqxhr.getResponseHeader( 'X-Parsoid-Performance' )
|
2013-11-06 08:22:11 +00:00
|
|
|
};
|
|
|
|
if ( response.error && response.error.code === 'badcachekey' ) {
|
|
|
|
// Log the failure if eventName was set
|
|
|
|
if ( eventName ) {
|
|
|
|
fullEventName = 'performance.system.' + eventName + '.badCacheKey';
|
2013-12-10 01:39:46 +00:00
|
|
|
target.events.track( fullEventName, eventData );
|
2013-11-06 08:22:11 +00:00
|
|
|
}
|
|
|
|
// This cache key is evidently bad, clear it
|
|
|
|
target.clearPreparedCacheKey();
|
|
|
|
// Try again without a cache key
|
|
|
|
return ajaxRequest( null );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Log data about the request if eventName was set
|
|
|
|
if ( eventName ) {
|
|
|
|
fullEventName = 'performance.system.' + eventName +
|
|
|
|
( typeof cachekey === 'string' ? '.withCacheKey' : '.withoutCacheKey' );
|
2013-12-10 01:39:46 +00:00
|
|
|
target.events.track( fullEventName, eventData );
|
2013-11-06 08:22:11 +00:00
|
|
|
}
|
|
|
|
return jqxhr;
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we successfully get prepared wikitext, then invoke ajaxRequest() with the cache key,
|
|
|
|
// otherwise invoke it without.
|
|
|
|
return preparedCacheKey.then( ajaxRequest, ajaxRequest );
|
|
|
|
};
|
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Post DOM data to the Parsoid API.
|
2012-06-11 06:54:41 +00:00
|
|
|
*
|
|
|
|
* This method performs an asynchronous action and uses a callback function to handle the result.
|
|
|
|
*
|
2014-08-22 20:50:48 +00:00
|
|
|
* target.save( dom, { summary: 'test', minor: true, watch: false } );
|
2012-06-11 06:54:41 +00:00
|
|
|
*
|
|
|
|
* @method
|
2013-02-11 19:46:58 +00:00
|
|
|
* @param {HTMLDocument} doc Document to save
|
Render check boxes from EditPage
EditPage has a lovely getCheckboxes() function which includes the
minor and watch checkboxes as rendered by MW core, as well as any
checkboxes extensions like FlaggedRevs might have added. Output
these in the API, render them, and send their values back.
ApiVisualEditor.php:
* Build a fake EditPage, get its checkboxes, and return them
ApiVisualEditorEdit.php:
* Pass through posted request data to ApiEdit, which passes it
through to EditPage thanks to Idab5b524b0e3 in core
ve.init.mw.ViewPageTarget.js:
* Remove minor and watch checkboxes from the save dialog template
and replace them with a generic checkbox container
* Have getSaveOptions() pull the state of all checkboxes in
** Special-case minor and watch, and pass the rest straight through
** Move normalization from true/false to presence/absence here, from
ve.init.mw.Target.prototype.save(), because here we know which ones
are checkboxes and we don't know that in save() without
special-casing
* Remove getSaveDialogHtml(), we don't need to hide checkboxes based on
rights anymore because in that case the API just won't send them to us.
** Moved logic for checking the watch checkbox down to where the same
logic for the minor checkbox already is
* Unwrap getSaveDialogHtml() in setupSaveDialog()
* Access minor and watch by their new IDs throughout
ve.init.mw.Target.js:
* Get and store checkboxes from the API
* Pass all keys straight through to the API
Bug: 49699
Change-Id: I09d02a42b05146bc9b7080ab38338ae869bf15e3
2013-07-24 06:39:03 +00:00
|
|
|
* @param {Object} options Saving options. All keys are passed through, including unrecognized ones.
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
* - {string} summary Edit summary
|
|
|
|
* - {boolean} minor Edit is a minor edit
|
2013-01-15 23:38:49 +00:00
|
|
|
* - {boolean} watch Watch the page
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
* @returns {boolean} Saving has been started
|
2012-06-11 06:54:41 +00:00
|
|
|
*/
|
2013-02-11 19:46:58 +00:00
|
|
|
ve.init.mw.Target.prototype.save = function ( doc, options ) {
|
2013-11-06 08:22:11 +00:00
|
|
|
var data;
|
2012-06-11 06:54:41 +00:00
|
|
|
// Prevent duplicate requests
|
2012-06-18 20:12:32 +00:00
|
|
|
if ( this.saving ) {
|
2012-06-11 06:54:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-06-23 23:09:47 +00:00
|
|
|
|
2014-02-20 21:30:29 +00:00
|
|
|
data = ve.extendObject( {}, options, {
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'visualeditoredit',
|
|
|
|
page: this.pageName,
|
|
|
|
oldid: this.revid,
|
|
|
|
basetimestamp: this.baseTimeStamp,
|
|
|
|
starttimestamp: this.startTimeStamp,
|
|
|
|
token: this.editToken
|
Render check boxes from EditPage
EditPage has a lovely getCheckboxes() function which includes the
minor and watch checkboxes as rendered by MW core, as well as any
checkboxes extensions like FlaggedRevs might have added. Output
these in the API, render them, and send their values back.
ApiVisualEditor.php:
* Build a fake EditPage, get its checkboxes, and return them
ApiVisualEditorEdit.php:
* Pass through posted request data to ApiEdit, which passes it
through to EditPage thanks to Idab5b524b0e3 in core
ve.init.mw.ViewPageTarget.js:
* Remove minor and watch checkboxes from the save dialog template
and replace them with a generic checkbox container
* Have getSaveOptions() pull the state of all checkboxes in
** Special-case minor and watch, and pass the rest straight through
** Move normalization from true/false to presence/absence here, from
ve.init.mw.Target.prototype.save(), because here we know which ones
are checkboxes and we don't know that in save() without
special-casing
* Remove getSaveDialogHtml(), we don't need to hide checkboxes based on
rights anymore because in that case the API just won't send them to us.
** Moved logic for checking the watch checkbox down to where the same
logic for the minor checkbox already is
* Unwrap getSaveDialogHtml() in setupSaveDialog()
* Access minor and watch by their new IDs throughout
ve.init.mw.Target.js:
* Get and store checkboxes from the API
* Pass all keys straight through to the API
Bug: 49699
Change-Id: I09d02a42b05146bc9b7080ab38338ae869bf15e3
2013-07-24 06:39:03 +00:00
|
|
|
} );
|
2013-06-23 23:09:47 +00:00
|
|
|
|
2013-11-06 08:22:11 +00:00
|
|
|
this.saving = this.tryWithPreparedCacheKey( doc, data, 'save' )
|
2014-07-08 22:33:32 +00:00
|
|
|
.done( ve.init.mw.Target.onSave.bind( this, doc, data ) )
|
|
|
|
.fail( this.onSaveError.bind( this, doc, data ) );
|
2013-10-11 22:00:10 +00:00
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
return true;
|
|
|
|
};
|
2012-11-28 23:57:00 +00:00
|
|
|
|
2012-12-07 16:23:23 +00:00
|
|
|
/**
|
2013-11-06 08:22:11 +00:00
|
|
|
* Post DOM data to the Parsoid API to retrieve wikitext diff.
|
2012-12-07 16:23:23 +00:00
|
|
|
*
|
|
|
|
* @method
|
2013-03-20 07:09:43 +00:00
|
|
|
* @param {HTMLDocument} doc Document to compare against (via wikitext)
|
2013-11-06 08:22:11 +00:00
|
|
|
* @returns {boolean} Diffing has been started
|
2012-12-07 16:23:23 +00:00
|
|
|
*/
|
2013-02-11 19:46:58 +00:00
|
|
|
ve.init.mw.Target.prototype.showChanges = function ( doc ) {
|
2013-11-06 08:22:11 +00:00
|
|
|
if ( this.diffing ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
this.diffing = this.tryWithPreparedCacheKey( doc, {
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'visualeditor',
|
|
|
|
paction: 'diff',
|
|
|
|
page: this.pageName,
|
|
|
|
oldid: this.revid
|
2013-11-06 08:22:11 +00:00
|
|
|
}, 'diff' )
|
2014-07-08 22:33:32 +00:00
|
|
|
.done( ve.init.mw.Target.onShowChanges.bind( this ) )
|
|
|
|
.fail( ve.init.mw.Target.onShowChangesError.bind( this ) );
|
2013-11-06 08:22:11 +00:00
|
|
|
|
|
|
|
return true;
|
2012-12-07 16:23:23 +00:00
|
|
|
};
|
|
|
|
|
2012-11-28 23:57:00 +00:00
|
|
|
/**
|
2013-11-15 20:30:57 +00:00
|
|
|
* Post wikitext to MediaWiki.
|
2012-11-28 23:57:00 +00:00
|
|
|
*
|
|
|
|
* This method performs a synchronous action and will take the user to a new page when complete.
|
|
|
|
*
|
2014-08-22 20:50:48 +00:00
|
|
|
* target.submit( wikitext, { wpSummary: 'test', wpMinorEdit: 1, wpSave: 1 } );
|
2012-11-28 23:57:00 +00:00
|
|
|
*
|
|
|
|
* @method
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
* @param {string} wikitext Wikitext to submit
|
2013-11-15 20:30:57 +00:00
|
|
|
* @param {Object} fields Other form fields to add (e.g. wpSummary, wpWatchthis, etc.). To actually
|
2014-08-22 20:50:48 +00:00
|
|
|
* save the wikitext, add { wpSave: 1 }. To go to the diff view, add { wpDiff: 1 }.
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
* @returns {boolean} Submitting has been started
|
2012-11-28 23:57:00 +00:00
|
|
|
*/
|
2013-11-15 20:30:57 +00:00
|
|
|
ve.init.mw.Target.prototype.submit = function ( wikitext, fields ) {
|
2012-11-28 23:57:00 +00:00
|
|
|
// Prevent duplicate requests
|
|
|
|
if ( this.submitting ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Save DOM
|
|
|
|
this.submitting = true;
|
|
|
|
var key,
|
2013-11-15 20:30:57 +00:00
|
|
|
$form = $( '<form method="post" enctype="multipart/form-data" style="display: none;"></form>' ),
|
2014-02-20 21:30:29 +00:00
|
|
|
params = ve.extendObject( {
|
2014-08-22 20:50:48 +00:00
|
|
|
format: 'text/x-wiki',
|
|
|
|
model: 'wikitext',
|
|
|
|
oldid: this.requestedRevId,
|
|
|
|
wpStarttime: this.startTimeStamp,
|
|
|
|
wpEdittime: this.baseTimeStamp,
|
|
|
|
wpTextbox1: wikitext,
|
|
|
|
wpEditToken: this.editToken
|
2013-11-15 20:30:57 +00:00
|
|
|
}, fields );
|
2012-11-28 23:57:00 +00:00
|
|
|
// Add params as hidden fields
|
|
|
|
for ( key in params ) {
|
2014-08-22 20:50:48 +00:00
|
|
|
$form.append( $( '<input>' ).attr( { type: 'hidden', name: key, value: params[key] } ) );
|
2012-11-28 23:57:00 +00:00
|
|
|
}
|
|
|
|
// Submit the form, mimicking a traditional edit
|
2013-11-15 20:30:57 +00:00
|
|
|
// Firefox requires the form to be attached
|
2012-11-28 23:57:00 +00:00
|
|
|
$form.attr( 'action', this.submitUrl ).appendTo( 'body' ).submit();
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get Wikitext data from the Parsoid API.
|
2012-11-28 23:57:00 +00:00
|
|
|
*
|
|
|
|
* This method performs an asynchronous action and uses a callback function to handle the result.
|
|
|
|
*
|
|
|
|
* target.serialize(
|
|
|
|
* dom,
|
|
|
|
* function ( wikitext ) {
|
|
|
|
* // Do something with the loaded DOM
|
|
|
|
* }
|
|
|
|
* );
|
|
|
|
*
|
|
|
|
* @method
|
2013-02-11 19:46:58 +00:00
|
|
|
* @param {HTMLDocument} doc Document to serialize
|
2012-11-28 23:57:00 +00:00
|
|
|
* @param {Function} callback Function to call when complete, accepts error and wikitext arguments
|
2013-11-06 08:22:11 +00:00
|
|
|
* @returns {boolean} Serializing has been started
|
2012-11-28 23:57:00 +00:00
|
|
|
*/
|
2013-02-11 19:46:58 +00:00
|
|
|
ve.init.mw.Target.prototype.serialize = function ( doc, callback ) {
|
2012-11-28 23:57:00 +00:00
|
|
|
// Prevent duplicate requests
|
|
|
|
if ( this.serializing ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
this.serializeCallback = callback;
|
2013-11-06 08:22:11 +00:00
|
|
|
this.serializing = this.tryWithPreparedCacheKey( doc, {
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'visualeditor',
|
|
|
|
paction: 'serialize',
|
|
|
|
page: this.pageName,
|
|
|
|
oldid: this.revid
|
2013-11-06 08:22:11 +00:00
|
|
|
}, 'serialize' )
|
2014-07-08 22:33:32 +00:00
|
|
|
.done( ve.init.mw.Target.onSerialize.bind( this ) )
|
|
|
|
.fail( ve.init.mw.Target.onSerializeError.bind( this ) );
|
2012-11-28 23:57:00 +00:00
|
|
|
return true;
|
|
|
|
};
|
2013-10-17 17:35:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get list of edit notices.
|
|
|
|
*
|
|
|
|
* @returns {Object|null} List of edit notices or null if none are loaded
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.getEditNotices = function () {
|
|
|
|
return this.editNotices;
|
|
|
|
};
|
2013-10-11 18:42:46 +00:00
|
|
|
|
|
|
|
// FIXME: split out view specific functionality, emit to subclass
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Switch to editing mode.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {HTMLDocument} doc HTML DOM to edit
|
|
|
|
* @param {Function} [callback] Callback to call when done
|
|
|
|
*/
|
2014-06-06 10:04:24 +00:00
|
|
|
ve.init.mw.Target.prototype.setupSurface = function ( doc, callback ) {
|
2013-10-11 18:42:46 +00:00
|
|
|
var target = this;
|
|
|
|
setTimeout( function () {
|
2013-12-04 17:37:50 +00:00
|
|
|
// Build model
|
2014-04-04 01:13:27 +00:00
|
|
|
var dmDoc = ve.dm.converter.getModelFromDom(
|
2014-05-02 16:34:46 +00:00
|
|
|
doc,
|
|
|
|
null,
|
2014-04-04 01:13:27 +00:00
|
|
|
mw.config.get( 'wgVisualEditor' ).pageLanguageCode,
|
|
|
|
mw.config.get( 'wgVisualEditor' ).pageLanguageDir
|
|
|
|
);
|
2013-10-11 18:42:46 +00:00
|
|
|
setTimeout( function () {
|
2013-12-04 17:37:50 +00:00
|
|
|
// Create ui.Surface (also creates ce.Surface and dm.Surface and builds CE tree)
|
2014-06-10 20:51:58 +00:00
|
|
|
var surface = target.createSurface( dmDoc );
|
|
|
|
target.surface = surface;
|
|
|
|
surface.$element.addClass( 've-init-mw-viewPageTarget-surface' )
|
2014-04-30 19:28:29 +00:00
|
|
|
.addClass( target.protectedClasses );
|
2014-06-06 10:04:24 +00:00
|
|
|
surface.addCommands( target.constructor.static.surfaceCommands );
|
2013-10-11 18:42:46 +00:00
|
|
|
setTimeout( function () {
|
2014-06-10 20:51:58 +00:00
|
|
|
var surfaceView = surface.getView(),
|
|
|
|
$documentNode = surfaceView.getDocument().getDocumentNode().$element;
|
|
|
|
|
2013-12-04 17:37:50 +00:00
|
|
|
// Initialize surface
|
2014-07-14 21:32:49 +00:00
|
|
|
surface.getContext().toggle( false );
|
2014-06-10 20:51:58 +00:00
|
|
|
target.$element.append( surface.$element );
|
2014-06-06 10:04:24 +00:00
|
|
|
target.setupToolbar();
|
|
|
|
if ( ve.debug ) {
|
|
|
|
target.setupDebugBar();
|
|
|
|
}
|
2013-12-06 20:01:03 +00:00
|
|
|
|
2014-04-30 00:43:41 +00:00
|
|
|
// Apply mw-body-content to the view (ve-ce-surface).
|
|
|
|
// Not to surface (ve-ui-surface), since that contains both the view
|
|
|
|
// and the overlay container, and we don't want inspectors to
|
|
|
|
// inherit skin typography styles for wikipage content.
|
2014-06-10 20:51:58 +00:00
|
|
|
surfaceView.$element.addClass( 'mw-body-content' );
|
|
|
|
$documentNode.addClass(
|
2014-04-30 00:43:41 +00:00
|
|
|
// Add appropriately mw-content-ltr or mw-content-rtl class
|
2013-12-04 17:37:50 +00:00
|
|
|
'mw-content-' + mw.config.get( 'wgVisualEditor' ).pageLanguageDir
|
|
|
|
);
|
|
|
|
target.active = true;
|
|
|
|
// Now that the surface is attached to the document and ready,
|
|
|
|
// let it initialize itself
|
2014-06-10 20:51:58 +00:00
|
|
|
surface.initialize();
|
2013-12-04 17:37:50 +00:00
|
|
|
setTimeout( callback );
|
2013-10-11 18:42:46 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-06-06 10:04:24 +00:00
|
|
|
* @inheritdoc
|
2013-10-11 18:42:46 +00:00
|
|
|
*/
|
2014-06-06 10:04:24 +00:00
|
|
|
ve.init.mw.Target.prototype.setupToolbar = function () {
|
|
|
|
// Parent method
|
2014-08-22 20:50:48 +00:00
|
|
|
ve.init.Target.prototype.setupToolbar.call( this, { shadow: true, actions: true } );
|
2013-10-11 18:42:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fire off the sanity check. Must be called before the surface is activated.
|
|
|
|
*
|
|
|
|
* To access the result, check whether #sanityCheckPromise has been resolved or rejected
|
|
|
|
* (it's asynchronous, so it may still be pending when you check).
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @fires sanityCheckComplete
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.startSanityCheck = function () {
|
|
|
|
// We have to get a copy of the data now, before we unlock the surface and let the user edit,
|
|
|
|
// but we can defer the actual conversion and comparison
|
|
|
|
var viewPage = this,
|
|
|
|
doc = viewPage.surface.getModel().getDocument(),
|
|
|
|
data = new ve.dm.FlatLinearData( doc.getStore().clone(), ve.copy( doc.getFullData() ) ),
|
|
|
|
oldDom = viewPage.doc,
|
|
|
|
d = $.Deferred();
|
|
|
|
|
|
|
|
// Reset
|
|
|
|
viewPage.sanityCheckFinished = false;
|
|
|
|
viewPage.sanityCheckVerified = false;
|
|
|
|
|
|
|
|
setTimeout( function () {
|
|
|
|
// We can't compare oldDom.body and newDom.body directly, because the attributes on the
|
|
|
|
// <body> were ignored in the conversion. So compare each child separately.
|
|
|
|
var i,
|
|
|
|
len = oldDom.body.childNodes.length,
|
2014-04-04 01:13:27 +00:00
|
|
|
newDoc = new ve.dm.Document( data, oldDom, undefined, doc.getInternalList(), doc.getInnerWhitespace(), doc.getLang(), doc.getDir() ),
|
2013-11-25 15:10:49 +00:00
|
|
|
newDom = ve.dm.converter.getDomFromModel( newDoc );
|
2013-10-11 18:42:46 +00:00
|
|
|
|
|
|
|
// Explicitly unlink our full copy of the original version of the document data
|
|
|
|
data = undefined;
|
|
|
|
|
|
|
|
if ( len !== newDom.body.childNodes.length ) {
|
|
|
|
// Different number of children, so they're definitely different
|
|
|
|
d.reject();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for ( i = 0; i < len; i++ ) {
|
|
|
|
if ( !oldDom.body.childNodes[i].isEqualNode( newDom.body.childNodes[i] ) ) {
|
|
|
|
d.reject();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
d.resolve();
|
|
|
|
} );
|
|
|
|
|
|
|
|
viewPage.sanityCheckPromise = d.promise()
|
|
|
|
.done( function () {
|
|
|
|
// If we detect no roundtrip errors,
|
|
|
|
// don't emphasize "review changes" to the user.
|
|
|
|
viewPage.sanityCheckVerified = true;
|
|
|
|
})
|
|
|
|
.always( function () {
|
|
|
|
viewPage.sanityCheckFinished = true;
|
|
|
|
viewPage.emit( 'sanityCheckComplete' );
|
|
|
|
} );
|
|
|
|
};
|
2014-02-06 23:13:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Move the cursor in the editor to section specified by this.section.
|
|
|
|
* Do nothing if this.section is undefined.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.restoreEditSection = function () {
|
2014-06-25 15:38:56 +00:00
|
|
|
if ( this.section !== undefined && this.section > 0 ) {
|
2014-08-22 00:37:12 +00:00
|
|
|
var surfaceView = this.surface.getView(),
|
2014-06-10 20:51:58 +00:00
|
|
|
$documentNode = surfaceView.getDocument().getDocumentNode().$element,
|
|
|
|
$section = $documentNode.find( 'h1, h2, h3, h4, h5, h6' ).eq( this.section - 1 ),
|
2014-08-22 00:37:12 +00:00
|
|
|
headingNode = $section.data( 'view' );
|
2014-02-06 23:13:32 +00:00
|
|
|
|
2014-08-28 01:56:14 +00:00
|
|
|
if ( $section.length && new mw.Uri().query.summary === undefined ) {
|
2014-02-06 23:13:32 +00:00
|
|
|
this.initialEditSummary = '/* ' +
|
|
|
|
ve.graphemeSafeSubstring( $section.text(), 0, 244 ) + ' */ ';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( headingNode ) {
|
2014-08-22 00:37:12 +00:00
|
|
|
this.goToHeading( headingNode );
|
2014-02-06 23:13:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.section = undefined;
|
|
|
|
}
|
|
|
|
};
|
2014-07-23 22:30:38 +00:00
|
|
|
|
2014-08-22 00:37:12 +00:00
|
|
|
/**
|
|
|
|
* Move the cursor to a given heading and scroll to it.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.ce.HeadingNode} headingNode Heading node to scroll to
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.goToHeading = function ( headingNode ) {
|
|
|
|
var nextNode, offset,
|
|
|
|
target = this,
|
|
|
|
offsetNode = headingNode,
|
|
|
|
surfaceModel = this.surface.getView().getModel(),
|
|
|
|
lastHeadingLevel = -1;
|
|
|
|
|
|
|
|
// Find next sibling which isn't a heading
|
|
|
|
while ( offsetNode instanceof ve.ce.HeadingNode && offsetNode.getModel().getAttribute( 'level' ) > lastHeadingLevel ) {
|
|
|
|
lastHeadingLevel = offsetNode.getModel().getAttribute( 'level' );
|
|
|
|
// Next sibling
|
|
|
|
nextNode = offsetNode.parent.children[ve.indexOf( offsetNode, offsetNode.parent.children ) + 1];
|
|
|
|
if ( !nextNode ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
offsetNode = nextNode;
|
|
|
|
}
|
|
|
|
offset = surfaceModel.getDocument().data.getNearestContentOffset(
|
|
|
|
offsetNode.getModel().getOffset(), 1
|
|
|
|
);
|
|
|
|
// onDocumentFocus is debounced, so wait for that to happen before setting
|
|
|
|
// the model selection, otherwise it will get reset
|
|
|
|
this.surface.getView().once( 'focus', function () {
|
2014-09-30 16:34:33 +00:00
|
|
|
surfaceModel.setLinearSelection( new ve.Range( offset ) );
|
2014-08-22 00:37:12 +00:00
|
|
|
target.scrollToHeading( headingNode );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2014-07-23 22:30:38 +00:00
|
|
|
/**
|
2014-07-28 21:54:12 +00:00
|
|
|
* Scroll to a given heading in the document.
|
2014-07-23 22:30:38 +00:00
|
|
|
*
|
|
|
|
* @method
|
2014-07-28 21:54:12 +00:00
|
|
|
* @param {ve.ce.HeadingNode} headingNode Heading node to scroll to
|
2014-07-23 22:30:38 +00:00
|
|
|
*/
|
2014-07-28 21:54:12 +00:00
|
|
|
ve.init.mw.Target.prototype.scrollToHeading = function ( headingNode ) {
|
2014-08-22 00:37:12 +00:00
|
|
|
var $window = $( OO.ui.Element.getWindow( this.$element ) );
|
2014-07-28 21:54:12 +00:00
|
|
|
|
2014-08-22 00:37:12 +00:00
|
|
|
$window.scrollTop( headingNode.$element.offset().top - this.toolbar.$element.height() );
|
2014-07-23 22:30:38 +00:00
|
|
|
};
|