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
|
|
|
*
|
2015-01-08 23:54:03 +00:00
|
|
|
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
2012-07-19 00:11:26 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2015-09-25 22:59:08 +00:00
|
|
|
/*global EasyDeflate, alert */
|
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
|
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
|
2015-07-30 09:32:40 +00:00
|
|
|
* @param {string} [revisionId] If the editor should load a revision of the page, pass the
|
2013-07-05 07:56:28 +00:00
|
|
|
* revision id here. Defaults to loading the latest version (see #load).
|
2015-07-30 09:32:40 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2012-06-11 06:54:41 +00:00
|
|
|
*/
|
2015-07-30 09:32:40 +00:00
|
|
|
ve.init.mw.Target = function VeInitMwTarget( pageName, revisionId, config ) {
|
|
|
|
config = config || {};
|
|
|
|
config.toolbarConfig = $.extend( {
|
2015-04-09 09:18:22 +00:00
|
|
|
shadow: true,
|
|
|
|
actions: true,
|
2015-08-10 12:31:46 +00:00
|
|
|
floatable: true
|
2015-07-30 09:32:40 +00:00
|
|
|
}, config.toolbarConfig );
|
|
|
|
|
|
|
|
// Parent constructor
|
|
|
|
ve.init.mw.Target.super.call( this, config );
|
2014-12-03 00:04:07 +00:00
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
// Properties
|
2015-08-05 21:43:23 +00:00
|
|
|
this.saveDialog = null;
|
|
|
|
this.saveDeferred = null;
|
|
|
|
this.captcha = null;
|
|
|
|
this.docToSave = null;
|
2015-07-31 11:03:14 +00:00
|
|
|
this.toolbarSaveButton = null;
|
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;
|
2015-08-10 12:31:46 +00:00
|
|
|
this.toolbarScrollOffset = mw.config.get( 'wgVisualEditorToolbarScrollOffset', 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;
|
2015-08-04 13:37:13 +00:00
|
|
|
this.pageDeletedWarning = false;
|
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' } );
|
2015-10-01 19:35:25 +00:00
|
|
|
this.events = { track: $.noop, trackActivationStart: $.noop, trackActivationComplete: $.noop };
|
2013-10-11 13:04:11 +00:00
|
|
|
|
2013-11-06 08:22:11 +00:00
|
|
|
this.preparedCacheKeyPromise = null;
|
2013-12-03 02:29:11 +00:00
|
|
|
this.clearState();
|
Load RL modules in one load.php request, rather than in two stages
This introduces TargetLoader, which manages plugins and RL modules
in a slightly more generic fashion so that Targets themselves don't
have to. This allows us to load all RL modules in one load.php
request, rather than first loading ViewPageTarget which then
loads the other modules.
TargetLoader loads in the bottom queue, so it will be loaded
as part of the main load.php request, but in VPT.init.js we
still have to wait for it with using() because it might not
have arrived yet. This also degrades gracefully on cached pages
where TargetLoader isn't in the bottom queue: it'll be loaded
as a separate request instead, which is suboptimal but no
worse that what we were doing before.
Right now TargetLoader is small enough that it could also be in
the top queue, but in the future we want to add things like
the action=visualeditor API request to it, and mw.Api is
relatively big.
Note: this also makes a breaking change to the plugin API:
plugin callbacks no longer receive the target instance
as a parameter, as they're now executed before the target
has been constructed rather than after. In the long term,
if we want to give plugins access to the target instance,
we could give them the target promise somehow. For now,
I've killed this feature because nothing used it and
the change from a direct object reference to a promise
would have been a breaking change anyway.
Also fixed incorrect documentation index for ve.init.mw.ViewPageTarget.init.
Bug: T53569
Change-Id: Ibfa6abbeaf872ae2aadc6ed9d5beba7473ea441a
2015-02-26 01:22:44 +00:00
|
|
|
this.generateCitationFeatures();
|
2015-07-01 11:11:36 +00:00
|
|
|
|
2015-07-30 09:32:40 +00:00
|
|
|
// Initialization
|
|
|
|
this.$element.addClass( 've-init-mw-target' );
|
|
|
|
|
2015-07-01 11:11:36 +00:00
|
|
|
// Events
|
|
|
|
this.connect( this, {
|
|
|
|
surfaceReady: 'onSurfaceReady'
|
|
|
|
} );
|
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
|
2013-03-20 07:09:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event showChanges
|
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 saveErrorEmpty
|
|
|
|
* Fired when save API returns no data object
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event saveErrorSpamBlacklist
|
|
|
|
* Fired when save is considered spam or blacklisted
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event saveErrorAbuseFilter
|
|
|
|
* Fired when AbuseFilter throws warnings
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event saveErrorCaptcha
|
|
|
|
* Fired when saveError indicates captcha field is required
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event saveErrorUnknown
|
|
|
|
* Fired for any other type of save error
|
|
|
|
*/
|
|
|
|
|
2014-10-30 00:36:02 +00:00
|
|
|
/**
|
|
|
|
* @event saveErrorPageDeleted
|
|
|
|
* Fired when user tries to save page that was deleted after opening VE
|
|
|
|
*/
|
|
|
|
|
2015-03-18 21:19:17 +00:00
|
|
|
/**
|
|
|
|
* @event saveErrorTitleBlacklist
|
|
|
|
* Fired when the user tries to save page in violation of the TitleBlacklist
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event showChangesError
|
2013-03-20 07:09:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event serializeError
|
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-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-11-27 12:39:38 +00:00
|
|
|
classes: [ 've-test-toolbar-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' ],
|
2014-11-26 02:57:26 +00:00
|
|
|
demote: [ 'preformatted', 'blockquote', 'heading1' ]
|
2013-12-13 20:24:54 +00:00
|
|
|
},
|
|
|
|
// Style
|
|
|
|
{
|
2015-03-24 08:55:51 +00:00
|
|
|
classes: [ 've-test-toolbar-style' ],
|
2014-08-22 20:50:48 +00:00
|
|
|
type: 'list',
|
2015-04-16 20:46:49 +00:00
|
|
|
icon: 'textStyle',
|
2014-08-22 20:50:48 +00:00
|
|
|
indicator: 'down',
|
|
|
|
title: OO.ui.deferMsg( 'visualeditor-toolbar-style-tooltip' ),
|
|
|
|
include: [ { group: 'textStyle' }, 'language', 'clear' ],
|
2014-10-30 19:22:20 +00:00
|
|
|
forceExpand: [ 'bold', 'italic', 'clear' ],
|
2014-08-22 20:50:48 +00:00
|
|
|
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-11-27 12:39:38 +00:00
|
|
|
classes: [ 've-test-toolbar-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
|
|
|
|
{
|
2015-01-27 05:41:17 +00:00
|
|
|
classes: [ 've-test-toolbar-structure' ],
|
2014-08-22 20:50:48 +00:00
|
|
|
type: 'list',
|
2015-04-16 20:46:49 +00:00
|
|
|
icon: 'listBullet',
|
2014-08-22 20:50:48 +00:00
|
|
|
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-11-27 12:39:38 +00:00
|
|
|
classes: [ 've-test-toolbar-insert' ],
|
2014-08-22 20:50:48 +00:00
|
|
|
label: OO.ui.deferMsg( 'visualeditor-toolbar-insert' ),
|
|
|
|
indicator: 'down',
|
|
|
|
include: '*',
|
2014-10-30 19:22:20 +00:00
|
|
|
forceExpand: [ 'media', 'transclusion', 'insertTable' ],
|
2015-10-04 12:28:55 +00:00
|
|
|
promote: [ 'media', 'transclusion', 'insertTable' ]
|
2014-10-29 18:45:29 +00:00
|
|
|
},
|
|
|
|
// Table
|
|
|
|
{
|
|
|
|
header: OO.ui.deferMsg( 'visualeditor-toolbar-table' ),
|
|
|
|
type: 'list',
|
2015-04-16 20:46:49 +00:00
|
|
|
icon: 'table',
|
2014-10-29 18:45:29 +00:00
|
|
|
indicator: 'down',
|
|
|
|
include: [ { group: 'table' } ],
|
|
|
|
demote: [ 'deleteTable' ]
|
2015-02-03 19:06:18 +00:00
|
|
|
},
|
|
|
|
// SpecialCharacter
|
|
|
|
{ include: [ 'specialCharacter' ] }
|
2013-12-13 20:24:54 +00:00
|
|
|
];
|
|
|
|
|
2014-11-24 11:27:25 +00:00
|
|
|
ve.init.mw.Target.static.importRules = {
|
2014-08-22 20:50:48 +00:00
|
|
|
external: {
|
|
|
|
blacklist: [
|
2014-02-06 22:30:07 +00:00
|
|
|
// Annotations
|
2015-04-21 12:23:23 +00:00
|
|
|
'link', 'textStyle/span', 'textStyle/font', 'textStyle/underline', 'meta/language',
|
2014-02-06 22:30:07 +00:00
|
|
|
// Nodes
|
2015-05-16 17:02:33 +00:00
|
|
|
'div', 'alienInline', 'alienBlock', 'comment'
|
2014-02-06 22:30:07 +00:00
|
|
|
],
|
2015-02-17 00:36:52 +00:00
|
|
|
removeOriginalDomElements: 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
|
|
|
};
|
|
|
|
|
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';
|
|
|
|
|
2014-10-29 01:19:52 +00:00
|
|
|
/**
|
|
|
|
* Type of integration. Used by ve.init.mw.trackSubscriber.js for event tracking.
|
2015-09-03 01:24:48 +00:00
|
|
|
*
|
2014-10-29 01:19:52 +00:00
|
|
|
* @static
|
|
|
|
* @property {string}
|
|
|
|
* @inheritable
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.static.integrationType = 'page';
|
|
|
|
|
2015-09-03 01:24:48 +00:00
|
|
|
/**
|
|
|
|
* Type of platform. Used by ve.init.mw.trackSubscriber.js for event tracking.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @property {string}
|
|
|
|
* @inheritable
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.static.platformType = 'other';
|
|
|
|
|
2012-06-18 20:12:32 +00:00
|
|
|
/* Static Methods */
|
|
|
|
|
2014-03-27 04:49:59 +00:00
|
|
|
/**
|
2015-04-24 21:41:22 +00:00
|
|
|
* Fix the base URL from Parsoid if necessary.
|
|
|
|
*
|
|
|
|
* Absolutizes the base URL if it's relative, and sets a base URL based on wgArticlePath
|
|
|
|
* if there was no base URL at all.
|
|
|
|
*
|
|
|
|
* @param {HTMLDocument} doc Parsoid document
|
2014-03-27 04:49:59 +00:00
|
|
|
*/
|
2015-04-24 21:41:22 +00:00
|
|
|
ve.init.mw.Target.static.fixBase = function ( doc ) {
|
|
|
|
ve.fixBase( doc, document, ve.resolveUrl(
|
|
|
|
// Don't replace $1 with the page name, because that'll break if
|
|
|
|
// the page name contains a slash
|
|
|
|
mw.config.get( 'wgArticlePath' ).replace( '$1', '' ),
|
|
|
|
document
|
|
|
|
) );
|
2014-03-27 04:49:59 +00:00
|
|
|
};
|
|
|
|
|
2015-07-31 15:03:33 +00:00
|
|
|
/* Methods */
|
|
|
|
|
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
|
Load RL modules in one load.php request, rather than in two stages
This introduces TargetLoader, which manages plugins and RL modules
in a slightly more generic fashion so that Targets themselves don't
have to. This allows us to load all RL modules in one load.php
request, rather than first loading ViewPageTarget which then
loads the other modules.
TargetLoader loads in the bottom queue, so it will be loaded
as part of the main load.php request, but in VPT.init.js we
still have to wait for it with using() because it might not
have arrived yet. This also degrades gracefully on cached pages
where TargetLoader isn't in the bottom queue: it'll be loaded
as a separate request instead, which is suboptimal but no
worse that what we were doing before.
Right now TargetLoader is small enough that it could also be in
the top queue, but in the future we want to add things like
the action=visualeditor API request to it, and mw.Api is
relatively big.
Note: this also makes a breaking change to the plugin API:
plugin callbacks no longer receive the target instance
as a parameter, as they're now executed before the target
has been constructed rather than after. In the long term,
if we want to give plugins access to the target instance,
we could give them the target promise somehow. For now,
I've killed this feature because nothing used it and
the change from a direct object reference to a promise
would have been a breaking change anyway.
Also fixed incorrect documentation index for ve.init.mw.ViewPageTarget.init.
Bug: T53569
Change-Id: Ibfa6abbeaf872ae2aadc6ed9d5beba7473ea441a
2015-02-26 01:22:44 +00:00
|
|
|
* server will be parsed, stored in {this.doc} and then {this.onReady} will be called.
|
2012-06-18 20:12:32 +00:00
|
|
|
*
|
|
|
|
* @method
|
2015-01-24 00:22:17 +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
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2015-07-31 15:03:33 +00:00
|
|
|
ve.init.mw.Target.prototype.loadSuccess = function ( response ) {
|
2015-04-24 21:41:22 +00:00
|
|
|
var i, len, linkData, aboutDoc, docRevIdMatches,
|
2015-03-26 17:39:45 +00:00
|
|
|
docRevId = 0,
|
2015-02-03 04:30:00 +00:00
|
|
|
data = response ? response.visualeditor : null;
|
2012-12-13 00:22:10 +00:00
|
|
|
|
2015-01-24 00:22:17 +00:00
|
|
|
if ( typeof data.content !== 'string' ) {
|
2015-07-31 15:03:33 +00:00
|
|
|
this.loadFail( 've-api', 'No HTML content in response from server' );
|
2012-06-18 20:12:32 +00:00
|
|
|
} else {
|
2015-02-18 20:11:49 +00:00
|
|
|
ve.track( 'trace.parseResponse.enter' );
|
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
|
|
|
|
2015-04-24 21:41:22 +00:00
|
|
|
// Fix relative or missing base URL if needed
|
|
|
|
this.constructor.static.fixBase( this.doc );
|
2015-03-31 04:21:15 +00:00
|
|
|
|
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;
|
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
|
|
|
|
2015-03-26 17:39:45 +00:00
|
|
|
aboutDoc = this.doc.documentElement.getAttribute( 'about' );
|
|
|
|
if ( aboutDoc ) {
|
|
|
|
docRevIdMatches = aboutDoc.match( /revision\/([0-9]*)$/ );
|
|
|
|
if ( docRevIdMatches.length >= 2 ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
docRevId = parseInt( docRevIdMatches[ 1 ] );
|
2015-03-26 17:39:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( docRevId !== this.revid ) {
|
2015-03-20 03:48:55 +00:00
|
|
|
if ( this.retriedRevIdConflict ) {
|
|
|
|
// Retried already, just error the second time.
|
2015-07-31 15:03:33 +00:00
|
|
|
this.loadFail(
|
2015-03-20 03:48:55 +00:00
|
|
|
've-api',
|
|
|
|
'Revision IDs (doc=' + docRevId + ',api=' + this.revid + ') ' +
|
|
|
|
'returned by server do not match'
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this.retriedRevIdConflict = true;
|
2015-03-26 23:06:43 +00:00
|
|
|
// TODO this retries both requests, in RESTbase mode we should only retry
|
|
|
|
// the request that gave us the lower revid
|
2015-03-20 03:48:55 +00:00
|
|
|
this.loading = false;
|
2015-03-26 23:06:43 +00:00
|
|
|
// HACK: Load with explicit revid to hopefully prevent this from happening again
|
|
|
|
if ( !this.requestedRevId ) {
|
|
|
|
this.requestedRevId = Math.max( docRevId, this.revid );
|
|
|
|
}
|
2015-03-20 03:48:55 +00:00
|
|
|
this.load();
|
|
|
|
}
|
|
|
|
return;
|
2015-04-23 20:46:09 +00:00
|
|
|
} else {
|
|
|
|
// Set this to false after a successful load, so we don't immediately give up
|
|
|
|
// if a subsequent load mismatches again
|
|
|
|
this.retriedRevIdConflict = false;
|
2015-03-20 03:48:55 +00:00
|
|
|
}
|
|
|
|
|
2014-03-11 00:46:26 +00:00
|
|
|
// Populate link cache
|
|
|
|
if ( data.links ) {
|
2015-07-03 13:19:41 +00:00
|
|
|
// Format from the API: { missing: [titles], known: 1|[titles] }
|
2015-02-03 04:30:00 +00:00
|
|
|
// Format expected by LinkCache: { title: { missing: true|false } }
|
|
|
|
linkData = {};
|
|
|
|
for ( i = 0, len = data.links.missing.length; i < len; i++ ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
linkData[ data.links.missing[ i ] ] = { missing: true };
|
2015-02-03 04:30:00 +00:00
|
|
|
}
|
2015-07-03 13:19:41 +00:00
|
|
|
if ( data.links.known === 1 ) {
|
2015-02-03 04:30:00 +00:00
|
|
|
// Set back to false by onReady()
|
|
|
|
ve.init.platform.linkCache.setAssumeExistence( true );
|
|
|
|
} else {
|
2015-07-03 13:19:41 +00:00
|
|
|
for ( i = 0, len = data.links.known.length; i < len; i++ ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
linkData[ data.links.known[ i ] ] = { missing: false };
|
2015-02-03 04:30:00 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-24 15:17:35 +00:00
|
|
|
ve.init.platform.linkCache.setMissing( linkData );
|
2014-03-11 00:46:26 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 20:11:49 +00:00
|
|
|
ve.track( 'trace.parseResponse.exit' );
|
Load RL modules in one load.php request, rather than in two stages
This introduces TargetLoader, which manages plugins and RL modules
in a slightly more generic fashion so that Targets themselves don't
have to. This allows us to load all RL modules in one load.php
request, rather than first loading ViewPageTarget which then
loads the other modules.
TargetLoader loads in the bottom queue, so it will be loaded
as part of the main load.php request, but in VPT.init.js we
still have to wait for it with using() because it might not
have arrived yet. This also degrades gracefully on cached pages
where TargetLoader isn't in the bottom queue: it'll be loaded
as a separate request instead, which is suboptimal but no
worse that what we were doing before.
Right now TargetLoader is small enough that it could also be in
the top queue, but in the future we want to add things like
the action=visualeditor API request to it, and mw.Api is
relatively big.
Note: this also makes a breaking change to the plugin API:
plugin callbacks no longer receive the target instance
as a parameter, as they're now executed before the target
has been constructed rather than after. In the long term,
if we want to give plugins access to the target instance,
we could give them the target promise somehow. For now,
I've killed this feature because nothing used it and
the change from a direct object reference to a promise
would have been a breaking change anyway.
Also fixed incorrect documentation index for ve.init.mw.ViewPageTarget.init.
Bug: T53569
Change-Id: Ibfa6abbeaf872ae2aadc6ed9d5beba7473ea441a
2015-02-26 01:22:44 +00:00
|
|
|
// Everything worked, the page was loaded, continue initializing the editor
|
|
|
|
this.onReady();
|
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
|
|
|
*
|
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 () {
|
2014-12-16 21:14:01 +00:00
|
|
|
var target = this;
|
2015-03-30 19:35:38 +00:00
|
|
|
|
2013-05-26 15:23:03 +00:00
|
|
|
// We need to wait until onReady as local notices may require special messages
|
2015-03-30 19:35:38 +00:00
|
|
|
this.editNotices = this.remoteNotices.concat(
|
|
|
|
this.localNoticeMessages.map( function ( msgKey ) {
|
|
|
|
return '<p>' + ve.init.platform.getParsedMessage( msgKey ) + '</p>';
|
|
|
|
} )
|
|
|
|
);
|
|
|
|
|
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 () {
|
2015-07-31 15:03:33 +00:00
|
|
|
// loadSuccess() may have called setAssumeExistence( true );
|
2015-02-03 04:30:00 +00:00
|
|
|
ve.init.platform.linkCache.setAssumeExistence( false );
|
2015-07-01 11:11:36 +00:00
|
|
|
target.getSurface().getModel().connect( target, {
|
|
|
|
history: 'updateToolbarSaveButtonState'
|
|
|
|
} );
|
2014-12-16 21:14:01 +00:00
|
|
|
target.emit( 'surfaceReady' );
|
|
|
|
} );
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
2015-07-01 11:11:36 +00:00
|
|
|
/**
|
|
|
|
* Once surface is ready ready, init UI
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.onSurfaceReady = function () {
|
|
|
|
this.setupToolbarSaveButton();
|
|
|
|
this.attachToolbarSaveButton();
|
|
|
|
this.restoreEditSection();
|
|
|
|
};
|
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* @method
|
2015-01-24 00:22:17 +00:00
|
|
|
* @param {string} errorTypeText Error type text from mw.Api
|
|
|
|
* @param {Object} error Object containing xhr, textStatus and exception keys
|
2013-10-22 17:54:59 +00:00
|
|
|
* @fires loadError
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2015-08-04 13:37:13 +00:00
|
|
|
ve.init.mw.Target.prototype.loadFail = function () {
|
2012-06-18 20:12:32 +00:00
|
|
|
this.loading = false;
|
2015-08-04 13:37:13 +00:00
|
|
|
this.emit( 'loadError' );
|
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.
|
|
|
|
*
|
|
|
|
* @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
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2015-08-04 10:34:07 +00:00
|
|
|
ve.init.mw.Target.prototype.saveSuccess = function ( doc, saveData, response ) {
|
2013-07-11 17:09:28 +00:00
|
|
|
var data = response.visualeditoredit;
|
2015-08-19 18:05:01 +00:00
|
|
|
this.saving = false;
|
2015-03-19 01:51:30 +00:00
|
|
|
if ( !data ) {
|
2015-08-04 10:34:07 +00:00
|
|
|
this.saveFail( doc, saveData, null, 'Invalid response from server', response );
|
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
|
2015-08-04 10:34:07 +00:00
|
|
|
this.saveFail( doc, saveData, null, 'Save failure', response );
|
2012-06-18 20:12:32 +00:00
|
|
|
} else if ( typeof data.content !== 'string' ) {
|
2015-08-04 10:34:07 +00:00
|
|
|
this.saveFail( doc, saveData, null, 'Invalid HTML content in response from server', response );
|
2012-06-18 20:12:32 +00:00
|
|
|
} else {
|
2015-08-04 13:37:13 +00:00
|
|
|
this.saveComplete(
|
2014-06-21 01:37:30 +00:00
|
|
|
data.content,
|
|
|
|
data.categorieshtml,
|
|
|
|
data.newrevid,
|
2015-08-04 01:01:04 +00:00
|
|
|
data.isRedirect,
|
2014-10-31 00:26:32 +00:00
|
|
|
data.displayTitleHtml,
|
2014-11-07 00:31:34 +00:00
|
|
|
data.lastModified,
|
2015-07-27 19:27:03 +00:00
|
|
|
data.contentSub,
|
|
|
|
data.modules,
|
|
|
|
data.jsconfigvars
|
2014-06-21 01:37:30 +00:00
|
|
|
);
|
2012-06-18 20:12:32 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-08-04 13:37:13 +00:00
|
|
|
/**
|
|
|
|
* Handle successful DOM save event.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @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
|
|
|
|
* @param {boolean} isRedirect Whether this page is a redirect or not
|
|
|
|
* @param {string} displayTitle What HTML to show as the page title
|
|
|
|
* @param {Object} lastModified Object containing user-formatted date
|
|
|
|
* and time strings, or undefined if we made no change.
|
|
|
|
* @param {string} contentSub HTML to show as the content subtitle
|
2015-07-27 19:27:03 +00:00
|
|
|
* @param {Array} modules The modules to be loaded on the page
|
|
|
|
* @param {Object} jsconfigvars The mw.config values needed on the page
|
2015-08-04 13:37:13 +00:00
|
|
|
* @fires save
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.saveComplete = function () {
|
2015-08-05 21:43:23 +00:00
|
|
|
this.saveDeferred.resolve();
|
2015-08-04 13:37:13 +00:00
|
|
|
this.emit( 'save' );
|
|
|
|
};
|
|
|
|
|
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
|
2012-12-07 16:23:23 +00:00
|
|
|
*/
|
2015-08-04 10:34:07 +00:00
|
|
|
ve.init.mw.Target.prototype.saveFail = function ( doc, saveData, jqXHR, status, data ) {
|
2013-11-26 19:29:14 +00:00
|
|
|
var api, editApi,
|
2014-11-27 20:51:04 +00:00
|
|
|
target = this;
|
2015-08-04 13:37:13 +00:00
|
|
|
|
2012-12-07 16:23:23 +00:00
|
|
|
this.saving = false;
|
2015-08-04 13:37:13 +00:00
|
|
|
this.pageDeletedWarning = false;
|
2013-11-26 19:29:14 +00:00
|
|
|
|
|
|
|
// Handle empty response
|
|
|
|
if ( !data ) {
|
2015-08-04 13:37:13 +00:00
|
|
|
this.saveErrorEmpty();
|
2013-11-26 19:29:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-03-19 01:51:30 +00:00
|
|
|
|
2013-11-26 19:29:14 +00:00
|
|
|
editApi = data && data.visualeditoredit && data.visualeditoredit.edit;
|
|
|
|
|
|
|
|
// Handle spam blacklist error (either from core or from Extension:SpamBlacklist)
|
|
|
|
if ( editApi && editApi.spamblacklist ) {
|
2015-08-04 13:37:13 +00:00
|
|
|
this.saveErrorSpamBlacklist( editApi );
|
2013-11-26 19:29:14 +00:00
|
|
|
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 ) {
|
2015-08-04 13:37:13 +00:00
|
|
|
this.saveErrorAbuseFilter( editApi );
|
2013-11-26 19:29:14 +00:00
|
|
|
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-11-27 20:51:04 +00:00
|
|
|
titles: new mw.Title( target.pageName ).toText(),
|
2014-08-22 20:50:48 +00:00
|
|
|
indexpageids: '',
|
|
|
|
intoken: 'edit'
|
2013-11-26 19:29:14 +00:00
|
|
|
} )
|
|
|
|
.always( function () {
|
2015-08-04 13:37:13 +00:00
|
|
|
target.saveErrorBadToken();
|
2013-11-26 19:29:14 +00:00
|
|
|
} )
|
|
|
|
.done( function ( data ) {
|
2015-10-06 17:04:10 +00:00
|
|
|
var
|
2013-11-26 19:29:14 +00:00
|
|
|
userInfo = data.query && data.query.userinfo,
|
|
|
|
pageInfo = data.query && data.query.pages && data.query.pageids &&
|
2015-08-19 17:33:02 +00:00
|
|
|
data.query.pageids[ 0 ] && data.query.pages[ data.query.pageids[ 0 ] ],
|
2013-11-26 19:29:14 +00:00
|
|
|
editToken = pageInfo && pageInfo.edittoken,
|
|
|
|
isAnon = mw.user.isAnon();
|
|
|
|
|
|
|
|
if ( userInfo && editToken ) {
|
2014-11-27 20:51:04 +00:00
|
|
|
target.editToken = editToken;
|
2013-11-26 19:29:14 +00:00
|
|
|
|
|
|
|
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-11-27 20:51:04 +00:00
|
|
|
target.save( doc, saveData );
|
2013-11-26 19:29:14 +00:00
|
|
|
} else {
|
|
|
|
// The now current session is a different user
|
2014-11-22 02:19:14 +00:00
|
|
|
if ( userInfo.anon !== undefined ) {
|
2013-11-26 19:29:14 +00:00
|
|
|
// 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
|
|
|
} );
|
2015-08-04 13:37:13 +00:00
|
|
|
target.saveErrorNewUser( 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 } );
|
2015-08-04 13:37:13 +00:00
|
|
|
target.saveErrorNewUser( userInfo.name );
|
2013-11-26 19:29:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
return;
|
2015-03-19 01:51:30 +00:00
|
|
|
} else if ( data.error && data.error.code === 'editconflict' ) {
|
2015-08-04 13:37:13 +00:00
|
|
|
this.editConflict();
|
2015-03-19 01:51:30 +00:00
|
|
|
return;
|
2014-10-30 00:36:02 +00:00
|
|
|
} else if ( data.error && data.error.code === 'pagedeleted' ) {
|
2015-08-04 13:37:13 +00:00
|
|
|
this.saveErrorPageDeleted();
|
2015-03-19 01:51:30 +00:00
|
|
|
return;
|
2015-03-18 21:19:17 +00:00
|
|
|
} else if ( data.error && data.error.code === 'titleblacklist-forbidden-edit' ) {
|
2015-08-04 13:37:13 +00:00
|
|
|
this.saveErrorTitleBlacklist();
|
2015-03-19 01:51:30 +00:00
|
|
|
return;
|
2013-11-26 19:29:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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'
|
|
|
|
) ) {
|
2015-08-04 13:37:13 +00:00
|
|
|
this.saveErrorCaptcha( editApi );
|
2013-11-26 19:29:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle (other) unknown and/or unrecoverable errors
|
2015-08-04 13:37:13 +00:00
|
|
|
this.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
|
|
|
*
|
|
|
|
* @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
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2015-07-31 15:03:33 +00:00
|
|
|
ve.init.mw.Target.prototype.showChangesSuccess = function ( response ) {
|
2012-12-07 16:23:23 +00:00
|
|
|
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 ) {
|
2015-07-31 15:03:33 +00:00
|
|
|
this.showChangesFail( null, 'Invalid response from server', null );
|
2012-12-07 16:23:23 +00:00
|
|
|
} else if ( response.error ) {
|
2015-07-31 15:03:33 +00:00
|
|
|
this.showChangesFail(
|
|
|
|
null, 'Unsuccessful request: ' + response.error.info, null
|
2012-12-07 16:23:23 +00:00
|
|
|
);
|
2013-05-14 17:40:00 +00:00
|
|
|
} else if ( data.result === 'nochanges' ) {
|
2015-08-04 13:37:13 +00:00
|
|
|
this.noChanges();
|
2012-12-07 16:23:23 +00:00
|
|
|
} else if ( data.result !== 'success' ) {
|
2015-07-31 15:03:33 +00:00
|
|
|
this.showChangesFail( null, 'Failed request: ' + data.result, null );
|
2012-12-07 16:23:23 +00:00
|
|
|
} else if ( typeof data.diff !== 'string' ) {
|
2015-07-31 15:03:33 +00:00
|
|
|
this.showChangesFail(
|
|
|
|
null, 'Invalid HTML content in response from server', null
|
2012-12-07 16:23:23 +00:00
|
|
|
);
|
|
|
|
} else {
|
2015-08-04 13:37:13 +00:00
|
|
|
this.showChangesDiff( data.diff );
|
2012-12-07 16:23:23 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-08-04 13:37:13 +00:00
|
|
|
/**
|
|
|
|
* Show changes diff HTML
|
|
|
|
*
|
|
|
|
* @param {string} diffHtml Diff HTML
|
|
|
|
* @fires showChanges
|
|
|
|
*/
|
2015-09-25 22:59:08 +00:00
|
|
|
ve.init.mw.Target.prototype.showChangesDiff = function ( diffHtml ) {
|
2015-08-04 13:37:13 +00:00
|
|
|
this.emit( 'showChanges' );
|
2015-09-25 22:59:08 +00:00
|
|
|
|
|
|
|
// Invalidate the viewer diff on next change
|
|
|
|
this.getSurface().getModel().getDocument().once( 'transact',
|
|
|
|
this.saveDialog.clearDiff.bind( this.saveDialog )
|
|
|
|
);
|
|
|
|
this.saveDialog.setDiffAndReview( diffHtml );
|
2015-08-04 13:37:13 +00:00
|
|
|
};
|
|
|
|
|
2012-12-07 16:23:23 +00:00
|
|
|
/**
|
2013-11-06 08:22:11 +00:00
|
|
|
* Handle errors during showChanges action.
|
2012-12-07 16:23:23 +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
|
|
|
* @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
|
|
|
*/
|
2015-09-25 22:59:08 +00:00
|
|
|
ve.init.mw.Target.prototype.showChangesFail = function ( jqXHR, status ) {
|
2013-11-06 08:22:11 +00:00
|
|
|
this.diffing = false;
|
2015-08-04 13:37:13 +00:00
|
|
|
this.emit( 'showChangesError' );
|
2015-09-25 22:59:08 +00:00
|
|
|
|
|
|
|
alert( ve.msg( 'visualeditor-differror', status ) );
|
|
|
|
this.saveDialog.popPending();
|
2015-08-04 13:37:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show an save process error message
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {string|jQuery|Node[]} msg Message content (string of HTML, jQuery object or array of
|
|
|
|
* Node objects)
|
|
|
|
* @param {boolean} [allowReapply=true] Whether or not to allow the user to reapply.
|
|
|
|
* Reset when swapping panels. Assumed to be true unless explicitly set to false.
|
|
|
|
* @param {boolean} [warning=false] Whether or not this is a warning.
|
|
|
|
*/
|
2015-08-05 21:43:23 +00:00
|
|
|
ve.init.mw.Target.prototype.showSaveError = function ( msg, allowReapply, warning ) {
|
|
|
|
this.saveDeferred.reject( [ new OO.ui.Error( msg, { recoverable: allowReapply, warning: warning } ) ] );
|
2015-08-04 13:37:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle general save error
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @fires saveErrorEmpty
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.saveErrorEmpty = function () {
|
|
|
|
this.showSaveError( ve.msg( 'visualeditor-saveerror', 'Empty server response' ), false /* prevents reapply */ );
|
|
|
|
this.emit( 'saveErrorEmpty' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle spam blacklist error
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {Object} editApi
|
|
|
|
* @fires saveErrorSpamBlacklist
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.saveErrorSpamBlacklist = function ( editApi ) {
|
|
|
|
this.showSaveError(
|
|
|
|
$( $.parseHTML( editApi.sberrorparsed ) ),
|
|
|
|
false // prevents reapply
|
|
|
|
);
|
|
|
|
this.emit( 'saveErrorSpamBlacklist' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handel abuse filter error
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {Object} editApi
|
|
|
|
* @fires saveErrorAbuseFilter
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.saveErrorAbuseFilter = function ( editApi ) {
|
|
|
|
this.showSaveError( $( $.parseHTML( editApi.warning ) ) );
|
|
|
|
// Don't disable the save button. If the action is not disallowed the user may save the
|
|
|
|
// edit by pressing Save again. The AbuseFilter API currently has no way to distinguish
|
|
|
|
// between filter triggers that are and aren't disallowing the action.
|
|
|
|
this.emit( 'saveErrorAbuseFilter' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle title blacklist save error
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @fires saveErrorTitleBlacklist
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.saveErrorTitleBlacklist = function () {
|
|
|
|
this.showSaveError( mw.msg( 'visualeditor-saveerror-titleblacklist' ) );
|
|
|
|
this.emit( 'saveErrorTitleBlacklist' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle token fetch indicating another user is logged in
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {string|null} username Name of newly logged-in user, or null if anonymous
|
|
|
|
* @fires saveErrorNewUser
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.saveErrorNewUser = function ( username ) {
|
|
|
|
var badToken, userMsg;
|
|
|
|
badToken = document.createTextNode( mw.msg( 'visualeditor-savedialog-error-badtoken' ) + ' ' );
|
|
|
|
if ( username === null ) {
|
|
|
|
userMsg = 'visualeditor-savedialog-identify-anon';
|
|
|
|
} else {
|
2015-10-06 17:04:10 +00:00
|
|
|
userMsg = 'visualeditor-savedialog-identify-user';
|
2015-08-04 13:37:13 +00:00
|
|
|
}
|
|
|
|
this.showSaveError(
|
2015-10-06 17:04:10 +00:00
|
|
|
$( badToken ).add( $.parseHTML( mw.message( userMsg, username ).parse() ) )
|
2015-08-04 13:37:13 +00:00
|
|
|
);
|
|
|
|
this.emit( 'saveErrorNewUser' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle unknown save error
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {Object} editApi
|
|
|
|
* @param {Object|null} data API response data
|
|
|
|
* @fires onSaveErrorUnknown
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.saveErrorUnknown = function ( editApi, data ) {
|
|
|
|
this.showSaveError(
|
|
|
|
$( document.createTextNode(
|
|
|
|
( editApi && editApi.info ) ||
|
|
|
|
( data.error && data.error.info ) ||
|
|
|
|
( editApi && editApi.code ) ||
|
|
|
|
( data.error && data.error.code ) ||
|
|
|
|
'Unknown error'
|
|
|
|
) ),
|
|
|
|
false // prevents reapply
|
|
|
|
);
|
|
|
|
this.emit( 'onSaveErrorUnknown' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a bad token
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @fires saveErrorBadToken
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.saveErrorBadToken = function () {
|
|
|
|
this.emit( 'saveErrorBadToken' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle captcha error
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {Object} editApi
|
|
|
|
* @fires saveErrorCaptcha
|
|
|
|
*/
|
2015-08-05 21:43:23 +00:00
|
|
|
ve.init.mw.Target.prototype.saveErrorCaptcha = function ( editApi ) {
|
|
|
|
var $captchaDiv = $( '<div>' ),
|
|
|
|
$captchaParagraph = $( '<p>' );
|
|
|
|
|
|
|
|
this.captcha = {
|
|
|
|
input: new OO.ui.TextInputWidget(),
|
|
|
|
id: editApi.captcha.id
|
|
|
|
};
|
|
|
|
$captchaDiv.append( $captchaParagraph );
|
|
|
|
$captchaParagraph.append(
|
|
|
|
$( '<strong>' ).text( mw.msg( 'captcha-label' ) ),
|
|
|
|
document.createTextNode( mw.msg( 'colon-separator' ) )
|
|
|
|
);
|
|
|
|
if ( editApi.captcha.url ) { // FancyCaptcha
|
|
|
|
mw.loader.load( 'ext.confirmEdit.fancyCaptcha' );
|
|
|
|
$captchaParagraph.append(
|
|
|
|
$( $.parseHTML( mw.message( 'fancycaptcha-edit' ).parse() ) )
|
|
|
|
.filter( 'a' ).attr( 'target', '_blank' ).end()
|
|
|
|
);
|
|
|
|
$captchaDiv.append(
|
|
|
|
$( '<img>' ).attr( 'src', editApi.captcha.url ).addClass( 'fancycaptcha-image' ),
|
|
|
|
' ',
|
|
|
|
$( '<a>' ).addClass( 'fancycaptcha-reload' ).text( mw.msg( 'fancycaptcha-reload-text' ) )
|
|
|
|
);
|
|
|
|
} else if ( editApi.captcha.type === 'simple' || editApi.captcha.type === 'math' ) {
|
|
|
|
// SimpleCaptcha and MathCaptcha
|
|
|
|
$captchaParagraph.append(
|
|
|
|
mw.message( 'captcha-edit' ).parse(),
|
|
|
|
'<br>',
|
|
|
|
document.createTextNode( editApi.captcha.question )
|
|
|
|
);
|
|
|
|
} else if ( editApi.captcha.type === 'question' ) {
|
|
|
|
// QuestyCaptcha
|
|
|
|
$captchaParagraph.append(
|
|
|
|
mw.message( 'questycaptcha-edit' ).parse(),
|
|
|
|
'<br>',
|
|
|
|
editApi.captcha.question
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$captchaDiv.append( this.captcha.input.$element );
|
|
|
|
|
|
|
|
// ProcessDialog's error system isn't great for this yet.
|
|
|
|
this.saveDialog.clearMessage( 'api-save-error' );
|
|
|
|
this.saveDialog.showMessage( 'api-save-error', $captchaDiv );
|
|
|
|
this.saveDialog.popPending();
|
2015-08-17 13:21:36 +00:00
|
|
|
|
|
|
|
this.captcha.input.focus();
|
|
|
|
|
2015-08-04 13:37:13 +00:00
|
|
|
this.emit( 'saveErrorCaptcha' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle page deleted error
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @fires saveErrorPageDeleted
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.saveErrorPageDeleted = function () {
|
|
|
|
this.pageDeletedWarning = true;
|
|
|
|
this.showSaveError( mw.msg( 'visualeditor-recreate', mw.msg( 'ooui-dialog-process-continue' ) ), true, true );
|
|
|
|
this.emit( 'saveErrorPageDeleted' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle an edit conflict
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @fires editConflict
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.editConflict = function () {
|
|
|
|
this.emit( 'editConflict' );
|
2015-09-25 22:59:08 +00:00
|
|
|
this.saveDialog.popPending();
|
|
|
|
this.saveDialog.swapPanel( 'conflict' );
|
2015-08-04 13:37:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle no changes in diff
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @fires noChanges
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.noChanges = function () {
|
|
|
|
this.emit( 'noChanges' );
|
2015-09-25 22:59:08 +00:00
|
|
|
this.saveDialog.popPending();
|
|
|
|
this.saveDialog.swapPanel( 'nochanges' );
|
|
|
|
this.saveDialog.getActions().setAbilities( { approve: true } );
|
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
|
2015-08-19 18:33:59 +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-12-10 01:39:46 +00:00
|
|
|
* @fires serializeComplete
|
2012-11-28 23:57:00 +00:00
|
|
|
*/
|
2015-08-04 13:37:13 +00:00
|
|
|
ve.init.mw.Target.prototype.serializeSuccess = function ( response ) {
|
2012-11-30 23:00:04 +00:00
|
|
|
var data = response.visualeditor;
|
2015-08-19 18:05:01 +00:00
|
|
|
this.serializing = false;
|
2012-11-28 23:57:00 +00:00
|
|
|
if ( !data && !response.error ) {
|
2015-08-04 13:37:13 +00:00
|
|
|
this.serializeFail( null, 'Invalid response from server', null );
|
2013-05-15 15:28:51 +00:00
|
|
|
} else if ( response.error ) {
|
2015-08-04 13:37:13 +00:00
|
|
|
this.serializeFail(
|
2015-07-31 15:03:33 +00:00
|
|
|
null, 'Unsuccessful request: ' + response.error.info, null
|
2013-05-15 15:28:51 +00:00
|
|
|
);
|
|
|
|
} else if ( data.result === 'error' ) {
|
2015-08-04 13:37:13 +00:00
|
|
|
this.serializeFail( null, 'Server error', null );
|
2012-11-28 23:57:00 +00:00
|
|
|
} else if ( typeof data.content !== 'string' ) {
|
2015-08-04 13:37:13 +00:00
|
|
|
this.serializeFail(
|
2015-07-31 15:03:33 +00:00
|
|
|
null, 'No Wikitext content in response from server', null
|
2012-11-28 23:57:00 +00:00
|
|
|
);
|
|
|
|
} 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.
|
|
|
|
*
|
|
|
|
* @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
|
|
|
*/
|
2015-08-04 13:37:13 +00:00
|
|
|
ve.init.mw.Target.prototype.serializeFail = function () {
|
2012-11-28 23:57:00 +00:00
|
|
|
this.serializing = false;
|
2015-08-04 13:37:13 +00:00
|
|
|
this.emit( 'serializeError' );
|
2012-11-28 23:57:00 +00:00
|
|
|
};
|
|
|
|
|
2015-08-05 21:43:23 +00:00
|
|
|
/**
|
|
|
|
* Handle clicks on the review button in the save dialog.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @fires saveReview
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.onSaveDialogReview = function () {
|
|
|
|
if ( !this.saveDialog.$reviewViewer.find( 'table, pre' ).length ) {
|
|
|
|
this.emit( 'saveReview' );
|
|
|
|
this.saveDialog.getActions().setAbilities( { approve: false } );
|
|
|
|
this.saveDialog.pushPending();
|
|
|
|
if ( this.pageExists ) {
|
|
|
|
// Has no callback, handled via target.showChangesDiff
|
|
|
|
this.showChanges( this.docToSave );
|
|
|
|
} else {
|
|
|
|
this.serialize( this.docToSave, this.onSaveDialogReviewComplete.bind( this ) );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.saveDialog.swapPanel( 'review' );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle completed serialize request for diff views for new page creations.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {string} wikitext
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.onSaveDialogReviewComplete = function ( wikitext ) {
|
|
|
|
// Invalidate the viewer wikitext on next change
|
|
|
|
this.getSurface().getModel().getDocument().once( 'transact',
|
|
|
|
this.saveDialog.clearDiff.bind( this.saveDialog )
|
|
|
|
);
|
|
|
|
this.saveDialog.setDiffAndReview( $( '<pre>' ).text( wikitext ) );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle clicks on the resolve conflict button in the conflict dialog.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.onSaveDialogResolveConflict = function () {
|
|
|
|
// Get Wikitext from the DOM, and set up a submit call when it's done
|
|
|
|
this.serialize(
|
|
|
|
this.docToSave,
|
|
|
|
this.submitWithSaveFields.bind( this, { wpSave: 1 } )
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle dialog retry events
|
|
|
|
* So we can handle trying to save again after page deletion warnings
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.onSaveDialogRetry = function () {
|
|
|
|
if ( this.pageDeletedWarning ) {
|
|
|
|
this.recreating = true;
|
|
|
|
this.pageExists = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle dialog close events.
|
|
|
|
*
|
|
|
|
* @fires saveWorkflowEnd
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.onSaveDialogClose = function () {
|
|
|
|
var target = this;
|
|
|
|
|
|
|
|
function clear() {
|
|
|
|
target.docToSave = null;
|
|
|
|
target.clearPreparedCacheKey();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the cached HTML and cache key once the document changes
|
|
|
|
if ( this.getSurface() ) {
|
|
|
|
this.getSurface().getModel().getDocument().once( 'transact', clear );
|
|
|
|
} else {
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.emit( 'saveWorkflowEnd' );
|
|
|
|
};
|
|
|
|
|
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 () {
|
2015-02-25 22:56:28 +00:00
|
|
|
var i, len, item, name, data, tool, tools, dialog, contextItem,
|
2014-04-10 18:47:34 +00:00
|
|
|
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++ ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
item = tools[ i ];
|
2014-08-22 20:50:48 +00:00
|
|
|
data = { template: item.template };
|
2015-02-27 18:47:42 +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;
|
2015-02-27 18:47:42 +00:00
|
|
|
if ( !ve.ui.toolFactory.lookup( 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;
|
|
|
|
tool.static.commandName = name;
|
|
|
|
tool.static.template = item.template;
|
|
|
|
tool.static.autoAddToCatchall = false;
|
|
|
|
tool.static.autoAddToGroup = true;
|
2015-06-26 18:51:13 +00:00
|
|
|
tool.static.associatedWindows = [ name ];
|
2015-02-27 18:47:42 +00:00
|
|
|
ve.ui.toolFactory.register( tool );
|
|
|
|
ve.ui.commandRegistry.register(
|
|
|
|
new ve.ui.Command(
|
2015-07-22 22:13:09 +00:00
|
|
|
name, 'mwcite', 'open', { args: [ name, data ], supportedSelections: [ 'linear' ] }
|
2015-02-27 18:47:42 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-02-25 22:56:28 +00:00
|
|
|
// Generate citation context item
|
2015-02-27 18:47:42 +00:00
|
|
|
if ( !ve.ui.contextItemFactory.lookup( name ) ) {
|
|
|
|
contextItem = function GeneratedMWCitationContextItem( toolbar, config ) {
|
|
|
|
ve.ui.MWCitationContextItem.call( this, toolbar, config );
|
|
|
|
};
|
|
|
|
OO.inheritClass( contextItem, ve.ui.MWCitationContextItem );
|
|
|
|
contextItem.static.name = name;
|
|
|
|
contextItem.static.icon = item.icon;
|
|
|
|
contextItem.static.label = item.title;
|
|
|
|
contextItem.static.commandName = name;
|
|
|
|
contextItem.static.template = item.template;
|
|
|
|
ve.ui.contextItemFactory.register( contextItem );
|
|
|
|
}
|
|
|
|
|
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
|
2015-02-27 18:47:42 +00:00
|
|
|
if ( !ve.ui.windowFactory.lookup( name ) ) {
|
|
|
|
dialog = function GeneratedMWCitationDialog( config ) {
|
|
|
|
ve.ui.MWCitationDialog.call( this, config );
|
|
|
|
};
|
|
|
|
OO.inheritClass( dialog, ve.ui.MWCitationDialog );
|
|
|
|
dialog.static.name = name;
|
|
|
|
dialog.static.icon = item.icon;
|
|
|
|
dialog.static.title = item.title;
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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.
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {string} Full HTML document
|
2013-05-11 00:03:48 +00:00
|
|
|
*/
|
|
|
|
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++ ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
to.setAttribute( from.attributes[ i ].name, from.attributes[ i ].value );
|
2013-05-11 00:03:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the head from the old document
|
|
|
|
for ( i = 0, len = oldDoc.head.childNodes.length; i < len; i++ ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
newDoc.head.appendChild( oldDoc.head.childNodes[ i ].cloneNode( true ) );
|
2013-05-11 00:03:48 +00:00
|
|
|
}
|
|
|
|
// 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 )
|
2015-02-17 23:31:57 +00:00
|
|
|
.find(
|
2015-06-23 01:09:39 +00:00
|
|
|
'script, ' + // T54884, T65229, T96533, T103430
|
|
|
|
'object, ' + // T65229
|
|
|
|
'style, ' + // T55252
|
|
|
|
'embed, ' + // T53521, T54791, T65121
|
2015-04-19 22:01:21 +00:00
|
|
|
'div[id="myEventWatcherDiv"], ' + // T53423
|
|
|
|
'div[id="sendToInstapaperResults"], ' + // T63776
|
|
|
|
'div[id="kloutify"], ' + // T69006
|
2015-06-23 01:09:39 +00:00
|
|
|
'div[id^="mittoHidden"]' // T70900
|
2015-02-17 23:31:57 +00:00
|
|
|
)
|
|
|
|
.remove();
|
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
|
|
|
};
|
|
|
|
|
2015-03-31 19:52:14 +00:00
|
|
|
/**
|
|
|
|
* Get deflated HTML. This function is async because easy-deflate may not have finished loading yet.
|
|
|
|
*
|
|
|
|
* @param {HTMLDocument} newDoc Document to get HTML for
|
|
|
|
* @return {jQuery.Promise} Promise resolved with deflated HTML
|
|
|
|
* @see #getHtml
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.deflateHtml = function ( newDoc ) {
|
|
|
|
var html = this.getHtml( newDoc );
|
|
|
|
return mw.loader.using( 'easy-deflate.deflate' )
|
|
|
|
.then( function () {
|
|
|
|
return EasyDeflate.deflate( html );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
/**
|
2015-02-23 20:51:33 +00:00
|
|
|
* Load the editor.
|
2012-06-11 06:54:41 +00:00
|
|
|
*
|
2015-03-13 15:50:23 +00:00
|
|
|
* This method initiates an API request for the page data unless dataPromise is passed in,
|
|
|
|
* in which case it waits for that promise instead.
|
2012-06-11 06:54:41 +00:00
|
|
|
*
|
2015-03-13 15:50:23 +00:00
|
|
|
* @param {jQuery.Promise} [dataPromise] Promise for pending request, if any
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {boolean} Loading has been started
|
2012-06-11 06:54:41 +00:00
|
|
|
*/
|
2015-03-13 15:50:23 +00:00
|
|
|
ve.init.mw.Target.prototype.load = function ( dataPromise ) {
|
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;
|
|
|
|
}
|
2015-04-09 03:48:46 +00:00
|
|
|
this.events.trackActivationStart( mw.libs.ve.activationStart );
|
|
|
|
mw.libs.ve.activationStart = null;
|
2013-07-05 07:56:28 +00:00
|
|
|
|
2015-04-09 12:48:16 +00:00
|
|
|
this.loading = dataPromise || mw.libs.ve.targetLoader.requestPageData(
|
|
|
|
this.pageName,
|
|
|
|
this.requestedRevId,
|
|
|
|
this.constructor.name
|
|
|
|
);
|
2015-02-23 20:51:33 +00:00
|
|
|
this.loading
|
2015-07-31 15:03:33 +00:00
|
|
|
.done( this.loadSuccess.bind( this ) )
|
|
|
|
.fail( this.loadFail.bind( this ) );
|
2015-02-23 20:51:33 +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.remoteNotices = [];
|
|
|
|
this.localNoticeMessages = [];
|
|
|
|
};
|
|
|
|
|
2015-07-30 11:08:56 +00:00
|
|
|
/**
|
|
|
|
* Switch to edit source mode
|
|
|
|
*
|
|
|
|
* @abstract
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.editSource = null;
|
|
|
|
|
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
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {jQuery.Promise} Abortable promise, resolved with the cache key.
|
2013-11-06 08:22:11 +00:00
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.prepareCacheKey = function ( doc ) {
|
2015-03-31 19:52:14 +00:00
|
|
|
var xhr, deflated,
|
|
|
|
aborted = false,
|
2015-01-31 00:41:37 +00:00
|
|
|
start = ve.now(),
|
|
|
|
target = this;
|
2013-11-06 08:22:11 +00:00
|
|
|
|
|
|
|
if ( this.preparedCacheKeyPromise && this.preparedCacheKeyPromise.doc === doc ) {
|
|
|
|
return this.preparedCacheKeyPromise;
|
|
|
|
}
|
|
|
|
this.clearPreparedCacheKey();
|
|
|
|
|
2015-03-31 19:52:14 +00:00
|
|
|
this.preparedCacheKeyPromise = this.deflateHtml( doc )
|
|
|
|
.then( function ( deflatedHtml ) {
|
|
|
|
deflated = deflatedHtml;
|
|
|
|
if ( aborted ) {
|
|
|
|
return $.Deferred().reject();
|
2013-11-06 08:22:11 +00:00
|
|
|
}
|
2015-03-31 19:52:14 +00:00
|
|
|
xhr = new mw.Api().post(
|
|
|
|
{
|
|
|
|
action: 'visualeditor',
|
|
|
|
paction: 'serializeforcache',
|
|
|
|
html: deflatedHtml,
|
|
|
|
page: target.pageName,
|
|
|
|
oldid: target.revid
|
|
|
|
},
|
|
|
|
{ contentType: 'multipart/form-data' }
|
|
|
|
);
|
|
|
|
return xhr.then(
|
|
|
|
function ( response ) {
|
|
|
|
var trackData = { duration: ve.now() - start };
|
|
|
|
if ( response.visualeditor && typeof response.visualeditor.cachekey === 'string' ) {
|
|
|
|
target.events.track( 'performance.system.serializeforcache', trackData );
|
|
|
|
return response.visualeditor.cachekey;
|
|
|
|
} else {
|
|
|
|
target.events.track( 'performance.system.serializeforcache.nocachekey', trackData );
|
|
|
|
return $.Deferred().reject();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
target.events.track( 'performance.system.serializeforcache.fail', { duration: ve.now() - start } );
|
|
|
|
}
|
|
|
|
);
|
2013-11-06 08:22:11 +00:00
|
|
|
} )
|
2015-03-31 19:52:14 +00:00
|
|
|
.promise( {
|
|
|
|
abort: function () {
|
|
|
|
if ( xhr ) {
|
|
|
|
xhr.abort();
|
|
|
|
}
|
|
|
|
aborted = true;
|
|
|
|
},
|
|
|
|
getDeflatedHtml: function () {
|
|
|
|
return deflated;
|
|
|
|
},
|
|
|
|
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
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {jQuery.Promise} Abortable promise, resolved with the cache key.
|
2013-11-06 08:22:11 +00:00
|
|
|
*/
|
|
|
|
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.
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {jQuery.Promise}
|
2013-11-06 08:22:11 +00:00
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.tryWithPreparedCacheKey = function ( doc, options, eventName ) {
|
2015-01-31 00:41:37 +00:00
|
|
|
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
|
|
|
|
2015-03-06 01:45:30 +00:00
|
|
|
function ajaxRequest( cachekey, isRetried ) {
|
2015-03-31 19:52:14 +00:00
|
|
|
var fullEventName,
|
|
|
|
start = ve.now(),
|
|
|
|
deflatePromise = $.Deferred().resolve().promise();
|
2015-01-24 00:22:17 +00:00
|
|
|
|
2013-11-06 08:22:11 +00:00
|
|
|
if ( typeof cachekey === 'string' ) {
|
|
|
|
data.cachekey = cachekey;
|
|
|
|
} else {
|
|
|
|
// Getting a cache key failed, fall back to sending the HTML
|
2015-03-31 19:52:14 +00:00
|
|
|
data.html = preparedCacheKey && preparedCacheKey.getDeflatedHtml && preparedCacheKey.getDeflatedHtml();
|
|
|
|
if ( !data.html ) {
|
|
|
|
deflatePromise = target.deflateHtml( doc ).then( function ( deflatedHtml ) {
|
|
|
|
data.html = deflatedHtml;
|
|
|
|
} );
|
|
|
|
}
|
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;
|
|
|
|
}
|
2015-03-31 19:52:14 +00:00
|
|
|
return deflatePromise
|
|
|
|
.then( function () {
|
|
|
|
return new mw.Api().post( data, { contentType: 'multipart/form-data' } );
|
|
|
|
} )
|
2015-01-24 00:22:17 +00:00
|
|
|
.then(
|
|
|
|
function ( response, jqxhr ) {
|
|
|
|
var eventData = {
|
|
|
|
bytes: $.byteLength( jqxhr.responseText ),
|
2015-03-25 02:36:44 +00:00
|
|
|
duration: ve.now() - start
|
2015-01-24 00:22:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Log data about the request if eventName was set
|
2013-11-06 08:22:11 +00:00
|
|
|
if ( eventName ) {
|
2015-01-24 00:22:17 +00:00
|
|
|
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
|
|
|
}
|
2015-01-24 00:22:17 +00:00
|
|
|
return jqxhr;
|
|
|
|
},
|
|
|
|
function ( errorName, errorObject ) {
|
|
|
|
var eventData;
|
|
|
|
if ( errorObject && errorObject.xhr ) {
|
|
|
|
eventData = {
|
|
|
|
bytes: $.byteLength( errorObject.xhr.responseText ),
|
2015-03-25 02:36:44 +00:00
|
|
|
duration: ve.now() - start
|
2015-01-24 00:22:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if ( eventName ) {
|
|
|
|
if ( errorName === 'badcachekey' ) {
|
|
|
|
fullEventName = 'performance.system.' + eventName + '.badCacheKey';
|
|
|
|
} else {
|
|
|
|
fullEventName = 'performance.system.' + eventName + '.withoutCacheKey';
|
|
|
|
}
|
|
|
|
target.events.track( fullEventName, eventData );
|
|
|
|
}
|
|
|
|
}
|
2013-11-06 08:22:11 +00:00
|
|
|
// This cache key is evidently bad, clear it
|
|
|
|
target.clearPreparedCacheKey();
|
2015-08-21 01:01:56 +00:00
|
|
|
if ( !isRetried && errorName === 'badcachekey' ) {
|
2015-03-06 01:45:30 +00:00
|
|
|
// Try again without a cache key
|
|
|
|
return ajaxRequest( null, true );
|
|
|
|
} else {
|
|
|
|
// Failed twice in a row, must be some other error - let caller handle it.
|
|
|
|
// FIXME Can't just `return this` because all callers are broken.
|
|
|
|
return $.Deferred().reject( null, errorName, errorObject ).promise();
|
|
|
|
}
|
2013-11-06 08:22:11 +00:00
|
|
|
}
|
2015-01-24 00:22:17 +00:00
|
|
|
);
|
2013-11-06 08:22:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we successfully get prepared wikitext, then invoke ajaxRequest() with the cache key,
|
|
|
|
// otherwise invoke it without.
|
|
|
|
return preparedCacheKey.then( ajaxRequest, ajaxRequest );
|
|
|
|
};
|
|
|
|
|
2015-08-04 13:37:13 +00:00
|
|
|
/**
|
|
|
|
* Prepare to save the article
|
|
|
|
*
|
2015-08-05 21:43:23 +00:00
|
|
|
* @param {jQuery.Deferred} saveDeferred Deferred object to resolve/reject when the save
|
|
|
|
* succeeds/fails.
|
2015-08-04 13:37:13 +00:00
|
|
|
* @fires saveInitiated
|
|
|
|
*/
|
2015-08-05 21:43:23 +00:00
|
|
|
ve.init.mw.Target.prototype.startSave = function ( saveDeferred ) {
|
2015-08-19 18:05:01 +00:00
|
|
|
var saveOptions;
|
|
|
|
|
2015-08-05 21:43:23 +00:00
|
|
|
if ( this.deactivating ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-19 18:05:01 +00:00
|
|
|
saveOptions = this.getSaveOptions();
|
2015-08-17 13:06:59 +00:00
|
|
|
|
2015-08-05 21:43:23 +00:00
|
|
|
// Reset any old captcha data
|
|
|
|
if ( this.captcha ) {
|
|
|
|
this.saveDialog.clearMessage( 'captcha' );
|
|
|
|
delete this.captcha;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
+mw.user.options.get( 'forceeditsummary' ) &&
|
|
|
|
saveOptions.summary === '' &&
|
|
|
|
!this.saveDialog.messages.missingsummary
|
|
|
|
) {
|
|
|
|
this.saveDialog.showMessage(
|
|
|
|
'missingsummary',
|
|
|
|
// Wrap manually since this core message already includes a bold "Warning:" label
|
|
|
|
$( '<p>' ).append( ve.init.platform.getParsedMessage( 'missingsummary' ) ),
|
|
|
|
{ wrap: false }
|
|
|
|
);
|
|
|
|
this.saveDialog.popPending();
|
|
|
|
} else {
|
|
|
|
this.emit( 'saveInitiated' );
|
|
|
|
if ( !this.docToSave ) {
|
|
|
|
this.docToSave = this.getSurface().getDom();
|
|
|
|
}
|
2015-08-17 13:06:59 +00:00
|
|
|
this.save( this.docToSave, saveOptions );
|
2015-08-05 21:43:23 +00:00
|
|
|
this.saveDeferred = saveDeferred;
|
2015-08-04 13:37:13 +00:00
|
|
|
}
|
2015-08-05 21:43:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get save form fields from the save dialog form.
|
|
|
|
*
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {Object} Form data for submission to the MediaWiki action=edit UI
|
2015-08-05 21:43:23 +00:00
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.getSaveFields = function () {
|
|
|
|
var fields = {
|
|
|
|
wpSummary: this.saveDialog ? this.saveDialog.editSummaryInput.getValue() : this.initialEditSummary,
|
|
|
|
wpCaptchaId: this.captcha && this.captcha.id,
|
|
|
|
wpCaptchaWord: this.captcha && this.captcha.input.getValue()
|
|
|
|
};
|
|
|
|
if ( this.recreating ) {
|
|
|
|
fields.wpRecreate = true;
|
|
|
|
}
|
|
|
|
return fields;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoke #submit with the data from #getSaveFields
|
|
|
|
*
|
|
|
|
* @param {Object} fields Fields to add in addition to those from #getSaveFields
|
|
|
|
* @param {string} wikitext Wikitext to submit
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {boolean} Whether submission was started
|
2015-08-05 21:43:23 +00:00
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.submitWithSaveFields = function ( fields, wikitext ) {
|
|
|
|
return this.submit( wikitext, $.extend( this.getSaveFields(), fields ) );
|
2015-08-04 13:37:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get edit API options from the save dialog form.
|
|
|
|
*
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {Object} Save options for submission to the MediaWiki API
|
2015-08-04 13:37:13 +00:00
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.getSaveOptions = function () {
|
2015-08-05 21:43:23 +00:00
|
|
|
var key,
|
|
|
|
options = this.getSaveFields(),
|
|
|
|
fieldMap = {
|
|
|
|
wpSummary: 'summary',
|
|
|
|
wpMinoredit: 'minor',
|
|
|
|
wpWatchthis: 'watch',
|
|
|
|
wpCaptchaId: 'captchaid',
|
|
|
|
wpCaptchaWord: 'captchaword'
|
|
|
|
};
|
|
|
|
|
|
|
|
for ( key in fieldMap ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
if ( options[ key ] !== undefined ) {
|
|
|
|
options[ fieldMap[ key ] ] = options[ key ];
|
|
|
|
delete options[ key ];
|
2015-08-05 21:43:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return options;
|
2015-08-04 13:37:13 +00:00
|
|
|
};
|
|
|
|
|
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
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {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' )
|
2015-08-04 10:34:07 +00:00
|
|
|
.done( this.saveSuccess.bind( this, doc, data ) )
|
|
|
|
.fail( this.saveFail.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)
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {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' )
|
2015-07-31 15:03:33 +00:00
|
|
|
.done( this.showChangesSuccess.bind( this ) )
|
|
|
|
.fail( this.showChangesFail.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 }.
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {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 ) {
|
2015-08-19 18:05:01 +00:00
|
|
|
var key, $form, params;
|
|
|
|
|
2012-11-28 23:57:00 +00:00
|
|
|
// Prevent duplicate requests
|
|
|
|
if ( this.submitting ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Save DOM
|
|
|
|
this.submitting = true;
|
2015-08-19 18:05:01 +00:00
|
|
|
$form = $( '<form method="post" enctype="multipart/form-data" style="display: none;"></form>' );
|
|
|
|
params = ve.extendObject( {
|
|
|
|
format: 'text/x-wiki',
|
|
|
|
model: 'wikitext',
|
|
|
|
oldid: this.requestedRevId,
|
|
|
|
wpStarttime: this.startTimeStamp,
|
|
|
|
wpEdittime: this.baseTimeStamp,
|
|
|
|
wpTextbox1: wikitext,
|
|
|
|
wpEditToken: this.editToken
|
|
|
|
}, fields );
|
2012-11-28 23:57:00 +00:00
|
|
|
// Add params as hidden fields
|
|
|
|
for ( key in params ) {
|
2015-08-19 17:33:02 +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
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {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' )
|
2015-08-04 13:37:13 +00:00
|
|
|
.done( ve.init.mw.Target.prototype.serializeSuccess.bind( this ) )
|
|
|
|
.fail( ve.init.mw.Target.prototype.serializeFail.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.
|
|
|
|
*
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {Object|null} List of edit notices or null if none are loaded
|
2013-10-17 17:35:16 +00:00
|
|
|
*/
|
|
|
|
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
|
2015-08-19 18:05:01 +00:00
|
|
|
var dmDoc;
|
2015-02-18 20:11:49 +00:00
|
|
|
ve.track( 'trace.convertModelFromDom.enter' );
|
2015-08-19 18:05:01 +00:00
|
|
|
dmDoc = ve.dm.converter.getModelFromDom( doc, {
|
2015-04-17 21:40:43 +00:00
|
|
|
lang: mw.config.get( 'wgVisualEditor' ).pageLanguageCode,
|
|
|
|
dir: mw.config.get( 'wgVisualEditor' ).pageLanguageDir
|
|
|
|
} );
|
2015-02-18 20:11:49 +00:00
|
|
|
ve.track( 'trace.convertModelFromDom.exit' );
|
2015-02-18 20:27:34 +00:00
|
|
|
// Build DM tree now (otherwise it gets lazily built when building the CE tree)
|
|
|
|
ve.track( 'trace.buildModelTree.enter' );
|
|
|
|
dmDoc.buildNodeTree();
|
|
|
|
ve.track( 'trace.buildModelTree.exit' );
|
2013-10-11 18:42:46 +00:00
|
|
|
setTimeout( function () {
|
2015-08-19 18:05:01 +00:00
|
|
|
var surface, surfaceView, $documentNode;
|
2015-02-21 10:42:58 +00:00
|
|
|
// Clear dummy surfaces
|
|
|
|
target.clearSurfaces();
|
2015-01-21 14:55:38 +00:00
|
|
|
|
2013-12-04 17:37:50 +00:00
|
|
|
// Create ui.Surface (also creates ce.Surface and dm.Surface and builds CE tree)
|
2015-02-18 20:11:49 +00:00
|
|
|
ve.track( 'trace.createSurface.enter' );
|
2015-08-19 18:05:01 +00:00
|
|
|
surface = target.addSurface( dmDoc );
|
|
|
|
surfaceView = surface.getView();
|
|
|
|
$documentNode = surfaceView.getDocument().getDocumentNode().$element;
|
2015-02-18 20:11:49 +00:00
|
|
|
ve.track( 'trace.createSurface.exit' );
|
2015-02-03 04:23:57 +00:00
|
|
|
|
2014-12-03 00:04:07 +00:00
|
|
|
surface.$element
|
2015-07-29 13:51:40 +00:00
|
|
|
.addClass( 've-init-mw-target-surface' )
|
2014-12-03 00:04:07 +00:00
|
|
|
.addClass( target.protectedClasses )
|
|
|
|
.appendTo( target.$element );
|
2015-02-03 04:23:57 +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.
|
|
|
|
surfaceView.$element.addClass( 'mw-body-content' );
|
2015-06-30 08:46:55 +00:00
|
|
|
surface.$placeholder.addClass( 'mw-body-content' );
|
2015-02-03 04:23:57 +00:00
|
|
|
$documentNode.addClass(
|
|
|
|
// Add appropriately mw-content-ltr or mw-content-rtl class
|
|
|
|
'mw-content-' + mw.config.get( 'wgVisualEditor' ).pageLanguageDir
|
|
|
|
);
|
|
|
|
|
2015-09-01 16:47:18 +00:00
|
|
|
target.dummyToolbar = false;
|
2014-12-03 00:04:07 +00:00
|
|
|
target.setSurface( surface );
|
|
|
|
|
2013-10-11 18:42:46 +00:00
|
|
|
setTimeout( function () {
|
2013-12-04 17:37:50 +00:00
|
|
|
// Initialize surface
|
2015-02-18 20:11:49 +00:00
|
|
|
ve.track( 'trace.initializeSurface.enter' );
|
2014-07-14 21:32:49 +00:00
|
|
|
surface.getContext().toggle( false );
|
2013-12-06 20:01:03 +00:00
|
|
|
|
2013-12-04 17:37:50 +00:00
|
|
|
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();
|
2015-02-18 20:11:49 +00:00
|
|
|
ve.track( 'trace.initializeSurface.exit' );
|
2013-12-04 17:37:50 +00:00
|
|
|
setTimeout( callback );
|
2013-10-11 18:42:46 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2015-07-01 11:11:36 +00:00
|
|
|
/**
|
|
|
|
* Add content and event bindings to toolbar save button.
|
|
|
|
*
|
|
|
|
* @param {Object} [config] Configuration options for the button
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.setupToolbarSaveButton = function ( config ) {
|
|
|
|
this.toolbarSaveButton = new OO.ui.ButtonWidget( ve.extendObject( {
|
|
|
|
label: ve.msg( 'visualeditor-toolbar-savedialog' ),
|
|
|
|
flags: [ 'progressive', 'primary' ],
|
|
|
|
disabled: !this.restoring
|
|
|
|
}, config ) );
|
|
|
|
|
|
|
|
// NOTE (phuedx, 2014-08-20): This class is used by the firsteditve guided
|
|
|
|
// tour to attach a guider to the "Save page" button.
|
|
|
|
this.toolbarSaveButton.$element.addClass( 've-ui-toolbar-saveButton' );
|
|
|
|
|
|
|
|
if ( ve.msg( 'accesskey-save' ) !== '-' && ve.msg( 'accesskey-save' ) !== '' ) {
|
|
|
|
// FlaggedRevs tries to use this - it's useless on VE pages because all that stuff gets hidden, but it will still conflict so get rid of it
|
|
|
|
this.elementsThatHadOurAccessKey = $( '[accesskey="' + ve.msg( 'accesskey-save' ) + '"]' ).removeAttr( 'accesskey' );
|
|
|
|
this.toolbarSaveButton.$button.attr( 'accesskey', ve.msg( 'accesskey-save' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
this.updateToolbarSaveButtonState();
|
|
|
|
|
|
|
|
this.toolbarSaveButton.connect( this, { click: 'onToolbarSaveButtonClick' } );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the save button to the user interface.
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.attachToolbarSaveButton = function () {
|
|
|
|
this.toolbar.$actions.append( this.toolbarSaveButton.$element );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Re-evaluate whether the toolbar save button should be disabled or not.
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.updateToolbarSaveButtonState = function () {
|
|
|
|
var isDisabled;
|
|
|
|
|
|
|
|
this.edited = this.getSurface().getModel().hasBeenModified();
|
|
|
|
// Disable the save button if we have no history
|
|
|
|
isDisabled = !this.edited && !this.restoring;
|
|
|
|
this.toolbarSaveButton.setDisabled( isDisabled );
|
|
|
|
mw.hook( 've.toolbarSaveButton.stateChanged' ).fire( isDisabled );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle clicks on the save button in the toolbar.
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.onToolbarSaveButtonClick = function () {
|
|
|
|
if ( this.edited || this.restoring ) {
|
2015-07-31 12:15:31 +00:00
|
|
|
this.showSaveDialog();
|
2015-07-01 11:11:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-31 12:15:31 +00:00
|
|
|
/**
|
|
|
|
* Show a save dialog
|
2015-08-04 13:37:13 +00:00
|
|
|
*
|
|
|
|
* @fires saveWorkflowBegin
|
2015-07-31 12:15:31 +00:00
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.showSaveDialog = function () {
|
2015-08-19 18:05:01 +00:00
|
|
|
var target = this;
|
2015-08-04 13:37:13 +00:00
|
|
|
this.emit( 'saveWorkflowBegin' );
|
|
|
|
|
|
|
|
// Preload the serialization
|
|
|
|
if ( !this.docToSave ) {
|
|
|
|
this.docToSave = this.getSurface().getDom();
|
|
|
|
}
|
|
|
|
this.prepareCacheKey( this.docToSave );
|
2015-08-05 21:43:23 +00:00
|
|
|
|
|
|
|
// Connect events to save dialog
|
|
|
|
this.getSurface().getDialogs().getWindow( 'mwSave' ).done( function ( win ) {
|
|
|
|
if ( !target.saveDialog ) {
|
|
|
|
target.saveDialog = win;
|
|
|
|
|
|
|
|
// Connect to save dialog
|
|
|
|
target.saveDialog.connect( target, {
|
|
|
|
save: 'startSave',
|
|
|
|
review: 'onSaveDialogReview',
|
|
|
|
resolve: 'onSaveDialogResolveConflict',
|
|
|
|
retry: 'onSaveDialogRetry',
|
|
|
|
close: 'onSaveDialogClose'
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.openSaveDialog();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open the save dialog
|
|
|
|
*/
|
|
|
|
ve.init.mw.Target.prototype.openSaveDialog = function () {
|
|
|
|
var windowAction = ve.ui.actionFactory.create( 'window', this.getSurface() );
|
|
|
|
|
|
|
|
// Open the dialog
|
|
|
|
windowAction.open( 'mwSave', { target: this } );
|
2015-07-31 12:15:31 +00:00
|
|
|
};
|
|
|
|
|
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 () {
|
2015-08-19 18:05:01 +00:00
|
|
|
var surfaceView, $documentNode, $section, headingNode;
|
|
|
|
|
2014-06-25 15:38:56 +00:00
|
|
|
if ( this.section !== undefined && this.section > 0 ) {
|
2015-08-19 18:05:01 +00:00
|
|
|
surfaceView = this.getSurface().getView();
|
|
|
|
$documentNode = surfaceView.getDocument().getDocumentNode().$element;
|
|
|
|
$section = $documentNode.find( 'h1, h2, h3, h4, h5, h6' ).eq( this.section - 1 );
|
|
|
|
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,
|
2015-07-08 14:34:43 +00:00
|
|
|
surface = this.getSurface(),
|
|
|
|
surfaceModel = surface.getModel(),
|
|
|
|
surfaceView = surface.getView(),
|
2014-08-22 00:37:12 +00:00
|
|
|
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
|
2015-08-19 17:33:02 +00:00
|
|
|
nextNode = offsetNode.parent.children[ offsetNode.parent.children.indexOf( offsetNode ) + 1 ];
|
2014-08-22 00:37:12 +00:00
|
|
|
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
|
2015-07-08 14:34:43 +00:00
|
|
|
surfaceView.once( 'focus', function () {
|
2014-09-30 16:34:33 +00:00
|
|
|
surfaceModel.setLinearSelection( new ve.Range( offset ) );
|
2015-07-08 14:34:43 +00:00
|
|
|
// Focussing the document triggers showSelection which calls scrollIntoView
|
|
|
|
// which uses a jQuery animation, so make sure this is aborted.
|
2015-08-19 17:33:02 +00:00
|
|
|
$( OO.ui.Element.static.getClosestScrollableContainer( surfaceView.$element[ 0 ] ) ).stop( true );
|
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-12-06 02:06:53 +00:00
|
|
|
var $window = $( OO.ui.Element.static.getWindow( this.$element ) );
|
2014-07-28 21:54:12 +00:00
|
|
|
|
2014-12-03 00:04:07 +00:00
|
|
|
$window.scrollTop( headingNode.$element.offset().top - this.getToolbar().$element.height() );
|
2014-07-23 22:30:38 +00:00
|
|
|
};
|