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
|
|
|
/*!
|
2015-07-29 13:41:30 +00:00
|
|
|
* VisualEditor MediaWiki Initialization DesktopArticleTarget class.
|
2012-07-19 21:25:16 +00:00
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2012-07-19 00:11:26 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2019-02-20 20:23:43 +00:00
|
|
|
/* eslint-disable no-jquery/no-global-selector */
|
2019-01-08 17:00:09 +00:00
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
/**
|
2015-08-04 13:37:13 +00:00
|
|
|
* MediaWiki desktop article target.
|
2012-06-11 06:54:41 +00:00
|
|
|
*
|
|
|
|
* @class
|
2015-12-10 16:07:50 +00:00
|
|
|
* @extends ve.init.mw.ArticleTarget
|
2013-02-20 19:44:44 +00:00
|
|
|
*
|
2012-06-11 06:54:41 +00:00
|
|
|
* @constructor
|
2023-02-02 09:47:32 +00:00
|
|
|
* @param {Object} [config]
|
2012-06-11 06:54:41 +00:00
|
|
|
*/
|
2015-07-30 09:32:40 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget = function VeInitMwDesktopArticleTarget( config ) {
|
2012-09-17 23:53:03 +00:00
|
|
|
// Parent constructor
|
2017-09-11 14:59:38 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.super.call( this, config );
|
2012-06-11 06:54:41 +00:00
|
|
|
|
2014-12-12 02:18:46 +00:00
|
|
|
// Parent constructor bound key event handlers, but we don't want them bound until
|
|
|
|
// we activate; so unbind them again
|
|
|
|
this.unbindHandlers();
|
|
|
|
|
2015-02-05 00:05:56 +00:00
|
|
|
this.onWatchToggleHandler = this.onWatchToggle.bind( this );
|
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
// Properties
|
2012-06-21 03:16:10 +00:00
|
|
|
this.onBeforeUnloadFallback = null;
|
2017-03-08 17:32:03 +00:00
|
|
|
this.onBeforeUnload = this.onBeforeUnload.bind( this );
|
2014-12-02 23:21:50 +00:00
|
|
|
this.onUnloadHandler = this.onUnload.bind( this );
|
2013-12-03 02:21:31 +00:00
|
|
|
this.activating = false;
|
|
|
|
this.deactivating = false;
|
2022-04-07 20:10:41 +00:00
|
|
|
this.deactivatingDeferred = null;
|
2014-10-30 00:36:02 +00:00
|
|
|
this.recreating = false;
|
2015-02-23 08:44:51 +00:00
|
|
|
this.activatingDeferred = null;
|
|
|
|
this.toolbarSetupDeferred = null;
|
2016-03-15 01:10:51 +00:00
|
|
|
this.suppressNormalStartupDialogs = false;
|
2016-03-23 01:07:01 +00:00
|
|
|
this.editingTabDialog = null;
|
2020-04-17 21:19:55 +00:00
|
|
|
this.welcomeDialog = null;
|
|
|
|
this.welcomeDialogPromise = null;
|
2015-03-25 21:52:06 +00:00
|
|
|
|
2013-06-05 22:39:43 +00:00
|
|
|
// If this is true then #transformPage / #restorePage will not call pushState
|
|
|
|
// This is to avoid adding a new history entry for the url we just got from onpopstate
|
|
|
|
// (which would mess up with the expected order of Back/Forwards browsing)
|
|
|
|
this.actFromPopState = false;
|
2014-03-12 21:26:52 +00:00
|
|
|
this.popState = {
|
|
|
|
tag: 'visualeditor'
|
|
|
|
};
|
2012-06-18 20:12:32 +00:00
|
|
|
this.scrollTop = null;
|
2016-12-08 19:19:17 +00:00
|
|
|
this.section = null;
|
2016-03-02 11:55:50 +00:00
|
|
|
if ( $( '#wpSummary' ).length ) {
|
|
|
|
this.initialEditSummary = $( '#wpSummary' ).val();
|
|
|
|
} else {
|
2022-12-17 15:44:56 +00:00
|
|
|
this.initialEditSummary = this.currentUrl.searchParams.get( 'summary' );
|
2016-03-02 11:55:50 +00:00
|
|
|
}
|
2020-05-26 22:08:49 +00:00
|
|
|
this.initialCheckboxes = $( '.editCheckboxes input' ).toArray()
|
|
|
|
.reduce( function ( initialCheckboxes, node ) {
|
|
|
|
initialCheckboxes[ node.name ] = node.checked;
|
|
|
|
return initialCheckboxes;
|
|
|
|
}, {} );
|
|
|
|
|
2013-06-03 22:23:45 +00:00
|
|
|
this.tabLayout = mw.config.get( 'wgVisualEditorConfig' ).tabLayout;
|
2015-12-10 16:07:50 +00:00
|
|
|
this.events = new ve.init.mw.ArticleTargetEvents( this );
|
2016-04-11 12:18:36 +00:00
|
|
|
this.$originalContent = $( '<div>' ).addClass( 've-init-mw-desktopArticleTarget-originalContent' );
|
2022-02-17 22:06:14 +00:00
|
|
|
this.$editableContent.addClass( 've-init-mw-desktopArticleTarget-editableContent' );
|
2016-05-09 22:28:24 +00:00
|
|
|
|
2015-07-30 09:32:40 +00:00
|
|
|
// Initialization
|
2016-04-11 12:18:36 +00:00
|
|
|
this.$element
|
|
|
|
.addClass( 've-init-mw-desktopArticleTarget' )
|
|
|
|
.append( this.$originalContent );
|
2015-07-30 09:32:40 +00:00
|
|
|
|
2022-12-12 19:47:32 +00:00
|
|
|
// We replace the current state with one that's marked with our tag. This way, when users
|
|
|
|
// use the Back button to exit the editor we can restore Read mode. This is because we want
|
|
|
|
// to ignore foreign states in onWindowPopState. Without this, the Read state is foreign.
|
|
|
|
// FIXME: There should be a much better solution than this.
|
2022-12-17 15:44:56 +00:00
|
|
|
history.replaceState( this.popState, '', this.currentUrl );
|
2013-06-05 21:38:39 +00:00
|
|
|
|
|
|
|
this.setupSkinTabs();
|
2013-06-05 22:39:43 +00:00
|
|
|
|
2014-11-25 01:44:24 +00:00
|
|
|
window.addEventListener( 'popstate', this.onWindowPopState.bind( this ) );
|
2012-06-11 06:54:41 +00:00
|
|
|
};
|
|
|
|
|
Object management: Object create/inherit/clone utilities
* For the most common case:
- replace ve.extendClass with ve.inheritClass (chose slightly
different names to detect usage of the old/new one, and I
like 'inherit' better).
- move it up to below the constructor, see doc block for why.
* Cases where more than 2 arguments were passed to
ve.extendClass are handled differently depending on the case.
In case of a longer inheritance tree, the other arguments
could be omitted (like in "ve.ce.FooBar, ve.FooBar,
ve.Bar". ve.ce.FooBar only needs to inherit from ve.FooBar,
because ve.ce.FooBar inherits from ve.Bar).
In the case of where it previously had two mixins with
ve.extendClass(), either one becomes inheritClass and one
a mixin, both to mixinClass().
No visible changes should come from this commit as the
instances still all have the same visible properties in the
end. No more or less than before.
* Misc.:
- Be consistent in calling parent constructors in the
same order as the inheritance.
- Add missing @extends and @param documentation.
- Replace invalid {Integer} type hint with {Number}.
- Consistent doc comments order:
@class, @abstract, @constructor, @extends, @params.
- Fix indentation errors
A fairly common mistake was a superfluous space before the
identifier on the assignment line directly below the
documentation comment.
$ ack "^ [^*]" --js modules/ve
- Typo "Inhertiance" -> "Inheritance".
- Replacing the other confusing comment "Inheritance" (inside
the constructor) with "Parent constructor".
- Add missing @abstract for ve.ui.Tool.
- Corrected ve.FormatDropdownTool to ve.ui.FormatDropdownTool.js
- Add function names to all @constructor functions. Now that we
have inheritance it is important and useful to have these
functions not be anonymous.
Example of debug shot: http://cl.ly/image/1j3c160w3D45
Makes the difference between
< documentNode;
> ve_dm_DocumentNode
...
: ve_dm_BranchNode
...
: ve_dm_Node
...
: ve_dm_Node
...
: Object
...
without names (current situation):
< documentNode;
> Object
...
: Object
...
: Object
...
: Object
...
: Object
...
though before this commit, it really looks like this
(flattened since ve.extendClass really did a mixin):
< documentNode;
> Object
...
...
...
Pattern in Sublime (case-sensitive) to find nameless
constructor functions:
"^ve\..*\.([A-Z])([^\.]+) = function \("
Change-Id: Iab763954fb8cf375900d7a9a92dec1c755d5407e
2012-09-05 06:07:47 +00:00
|
|
|
/* Inheritance */
|
|
|
|
|
2015-12-10 16:07:50 +00:00
|
|
|
OO.inheritClass( ve.init.mw.DesktopArticleTarget, ve.init.mw.ArticleTarget );
|
Object management: Object create/inherit/clone utilities
* For the most common case:
- replace ve.extendClass with ve.inheritClass (chose slightly
different names to detect usage of the old/new one, and I
like 'inherit' better).
- move it up to below the constructor, see doc block for why.
* Cases where more than 2 arguments were passed to
ve.extendClass are handled differently depending on the case.
In case of a longer inheritance tree, the other arguments
could be omitted (like in "ve.ce.FooBar, ve.FooBar,
ve.Bar". ve.ce.FooBar only needs to inherit from ve.FooBar,
because ve.ce.FooBar inherits from ve.Bar).
In the case of where it previously had two mixins with
ve.extendClass(), either one becomes inheritClass and one
a mixin, both to mixinClass().
No visible changes should come from this commit as the
instances still all have the same visible properties in the
end. No more or less than before.
* Misc.:
- Be consistent in calling parent constructors in the
same order as the inheritance.
- Add missing @extends and @param documentation.
- Replace invalid {Integer} type hint with {Number}.
- Consistent doc comments order:
@class, @abstract, @constructor, @extends, @params.
- Fix indentation errors
A fairly common mistake was a superfluous space before the
identifier on the assignment line directly below the
documentation comment.
$ ack "^ [^*]" --js modules/ve
- Typo "Inhertiance" -> "Inheritance".
- Replacing the other confusing comment "Inheritance" (inside
the constructor) with "Parent constructor".
- Add missing @abstract for ve.ui.Tool.
- Corrected ve.FormatDropdownTool to ve.ui.FormatDropdownTool.js
- Add function names to all @constructor functions. Now that we
have inheritance it is important and useful to have these
functions not be anonymous.
Example of debug shot: http://cl.ly/image/1j3c160w3D45
Makes the difference between
< documentNode;
> ve_dm_DocumentNode
...
: ve_dm_BranchNode
...
: ve_dm_Node
...
: ve_dm_Node
...
: Object
...
without names (current situation):
< documentNode;
> Object
...
: Object
...
: Object
...
: Object
...
: Object
...
though before this commit, it really looks like this
(flattened since ve.extendClass really did a mixin):
< documentNode;
> Object
...
...
...
Pattern in Sublime (case-sensitive) to find nameless
constructor functions:
"^ve\..*\.([A-Z])([^\.]+) = function \("
Change-Id: Iab763954fb8cf375900d7a9a92dec1c755d5407e
2012-09-05 06:07:47 +00:00
|
|
|
|
2013-01-15 23:38:49 +00:00
|
|
|
/* Static Properties */
|
2012-06-11 06:54:41 +00:00
|
|
|
|
2023-06-29 18:14:07 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.static.toolbarGroups = ve.copy( ve.init.mw.DesktopArticleTarget.static.toolbarGroups );
|
|
|
|
ve.init.mw.DesktopArticleTarget.static.toolbarGroups.push(
|
2015-12-11 16:42:23 +00:00
|
|
|
{
|
2018-05-12 15:18:07 +00:00
|
|
|
name: 'help',
|
2023-06-29 18:14:07 +00:00
|
|
|
align: 'after',
|
2023-06-07 14:48:43 +00:00
|
|
|
type: 'mwHelpList',
|
|
|
|
icon: 'help',
|
|
|
|
indicator: null,
|
2023-11-02 11:44:11 +00:00
|
|
|
title: ve.msg( 'visualeditor-help-tool' ),
|
2023-06-07 14:48:43 +00:00
|
|
|
include: [ { group: 'help' } ],
|
|
|
|
promote: [ 'mwUserGuide' ]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'notices',
|
|
|
|
align: 'after',
|
|
|
|
include: [ { group: 'notices' } ]
|
2018-05-12 15:18:07 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'pageMenu',
|
2023-06-29 18:14:07 +00:00
|
|
|
align: 'after',
|
2015-12-11 16:42:23 +00:00
|
|
|
type: 'list',
|
|
|
|
icon: 'menu',
|
2017-02-04 10:25:37 +00:00
|
|
|
indicator: null,
|
2015-12-11 16:42:23 +00:00
|
|
|
title: ve.msg( 'visualeditor-pagemenu-tooltip' ),
|
2020-03-13 21:03:50 +00:00
|
|
|
label: ve.msg( 'visualeditor-pagemenu-tooltip' ),
|
|
|
|
invisibleLabel: true,
|
2023-06-15 23:02:57 +00:00
|
|
|
include: [ { group: 'utility' } ],
|
|
|
|
demote: [ 'changeDirectionality', 'findAndReplace' ]
|
2015-12-11 16:42:23 +00:00
|
|
|
},
|
2017-02-24 14:29:21 +00:00
|
|
|
{
|
2018-05-12 15:18:07 +00:00
|
|
|
name: 'editMode',
|
2023-06-29 18:14:07 +00:00
|
|
|
align: 'after',
|
2017-02-24 14:29:21 +00:00
|
|
|
type: 'list',
|
2017-02-28 22:59:51 +00:00
|
|
|
icon: 'edit',
|
2017-02-24 14:29:21 +00:00
|
|
|
title: ve.msg( 'visualeditor-mweditmode-tooltip' ),
|
2020-03-13 21:03:50 +00:00
|
|
|
label: ve.msg( 'visualeditor-mweditmode-tooltip' ),
|
|
|
|
invisibleLabel: true,
|
2023-06-15 23:02:57 +00:00
|
|
|
include: [ { group: 'editMode' } ]
|
2019-04-15 22:39:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'save',
|
2023-06-29 18:14:07 +00:00
|
|
|
align: 'after',
|
2019-04-15 22:39:56 +00:00
|
|
|
type: 'bar',
|
2023-06-15 23:02:57 +00:00
|
|
|
include: [ { group: 'save' } ]
|
2017-02-24 14:29:21 +00:00
|
|
|
}
|
2023-06-29 18:14:07 +00:00
|
|
|
);
|
2015-12-11 16:42:23 +00:00
|
|
|
|
2012-08-22 21:24:50 +00:00
|
|
|
/**
|
2017-10-12 15:53:13 +00:00
|
|
|
* Compatibility map used with jQuery.client to decide if a browser should
|
|
|
|
* receive a compatibility warning. Blacklisting is handled in DesktopArticleTarget.init.
|
2012-08-22 21:24:50 +00:00
|
|
|
*
|
|
|
|
* @static
|
2020-06-18 18:16:52 +00:00
|
|
|
* @property {Object}
|
2012-08-22 21:24:50 +00:00
|
|
|
*/
|
2015-07-31 15:03:33 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.static.compatibility = {
|
2013-05-26 15:23:03 +00:00
|
|
|
// The key is the browser name returned by jQuery.client
|
|
|
|
// The value is either null (match all versions) or a list of tuples
|
|
|
|
// containing an inequality (<,>,<=,>=) and a version number
|
2020-06-10 11:03:51 +00:00
|
|
|
supportedList: {
|
2015-07-22 22:13:09 +00:00
|
|
|
chrome: [ [ '>=', 19 ] ],
|
2017-10-12 15:53:13 +00:00
|
|
|
opera: [ [ '>=', 15 ] ],
|
2020-06-10 11:03:51 +00:00
|
|
|
// All versions not in unsupportedList are fully supported:
|
2017-10-12 15:53:13 +00:00
|
|
|
firefox: null,
|
|
|
|
safari: null,
|
|
|
|
msie: null,
|
|
|
|
edge: null
|
2012-08-22 21:24:50 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-09-03 01:24:48 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.static.platformType = 'desktop';
|
|
|
|
|
2013-12-10 01:39:46 +00:00
|
|
|
/* Events */
|
|
|
|
|
2016-04-15 02:05:27 +00:00
|
|
|
/**
|
2024-04-29 11:52:40 +00:00
|
|
|
* @event ve.init.mw.DesktopArticleTarget#deactivate
|
2016-04-15 02:05:27 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2024-04-29 11:52:40 +00:00
|
|
|
* @event ve.init.mw.DesktopArticleTarget#transformPage
|
2016-04-15 02:05:27 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2024-04-29 11:52:40 +00:00
|
|
|
* @event ve.init.mw.DesktopArticleTarget#restorePage
|
2016-04-15 02:05:27 +00:00
|
|
|
*/
|
|
|
|
|
2013-12-10 01:39:46 +00:00
|
|
|
/**
|
2024-04-29 11:52:40 +00:00
|
|
|
* @event ve.init.mw.DesktopArticleTarget#saveWorkflowBegin
|
2014-10-29 01:19:52 +00:00
|
|
|
* Fired when user clicks the button to open the save dialog.
|
2013-12-10 01:39:46 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2024-04-29 11:52:40 +00:00
|
|
|
* @event ve.init.mw.DesktopArticleTarget#saveWorkflowEnd
|
2013-12-10 01:39:46 +00:00
|
|
|
* Fired when user exits the save workflow
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2024-04-29 11:52:40 +00:00
|
|
|
* @event ve.init.mw.DesktopArticleTarget#saveReview
|
2013-12-10 01:39:46 +00:00
|
|
|
* Fired when user initiates review changes in save workflow
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2024-04-29 11:52:40 +00:00
|
|
|
* @event ve.init.mw.DesktopArticleTarget#saveInitiated
|
2013-12-10 01:39:46 +00:00
|
|
|
* Fired when user initiates saving of the document
|
|
|
|
*/
|
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2018-04-26 13:40:42 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2018-05-18 14:12:48 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.addSurface = function ( dmDoc, config ) {
|
2022-03-19 13:46:46 +00:00
|
|
|
config = ve.extendObject( {
|
2022-06-21 18:01:30 +00:00
|
|
|
$overlayContainer: $(
|
2022-06-23 14:49:07 +00:00
|
|
|
document.querySelector( '[data-mw-ve-target-container]' ) ||
|
2022-06-21 18:01:30 +00:00
|
|
|
document.getElementById( 'content' )
|
|
|
|
),
|
2022-03-19 13:46:46 +00:00
|
|
|
// Vector-2022 content area has no padding itself, so popups render too close
|
|
|
|
// to the edge of the text (T258501). Use a negative value to allow popups to
|
|
|
|
// position slightly outside the content. Padding elsewhere means we are
|
|
|
|
// guaranteed 30px of space between the content and the edge of the viewport.
|
|
|
|
// Other skins pass 'undefined' to use the default padding of +10px.
|
|
|
|
overlayPadding: mw.config.get( 'skin' ) === 'vector-2022' ? -10 : undefined
|
|
|
|
}, config );
|
2023-11-02 16:42:31 +00:00
|
|
|
return ve.init.mw.DesktopArticleTarget.super.prototype.addSurface.call( this, dmDoc, config );
|
2018-04-26 13:40:42 +00:00
|
|
|
};
|
|
|
|
|
2016-05-09 22:28:24 +00:00
|
|
|
/**
|
|
|
|
* Set the container for the target, appending the target to it
|
|
|
|
*
|
2021-06-04 11:58:18 +00:00
|
|
|
* @param {jQuery} $container
|
2016-05-09 22:28:24 +00:00
|
|
|
*/
|
2016-06-01 16:44:55 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.setContainer = function ( $container ) {
|
2016-05-09 22:28:24 +00:00
|
|
|
$container.append( this.$element );
|
|
|
|
this.$container = $container;
|
|
|
|
};
|
|
|
|
|
2014-03-12 21:26:52 +00:00
|
|
|
/**
|
|
|
|
* Verify that a PopStateEvent correlates to a state we created.
|
|
|
|
*
|
|
|
|
* @param {Mixed} popState From PopStateEvent#state
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.verifyPopState = function ( popState ) {
|
2014-03-12 21:26:52 +00:00
|
|
|
return popState && popState.tag === 'visualeditor';
|
|
|
|
};
|
|
|
|
|
2014-02-07 22:04:35 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.setupToolbar = function ( surface ) {
|
2021-10-13 12:57:45 +00:00
|
|
|
var mode = surface.getMode(),
|
2015-02-23 08:44:51 +00:00
|
|
|
wasSetup = !!this.toolbar,
|
|
|
|
target = this;
|
2015-02-21 10:42:58 +00:00
|
|
|
|
2017-12-07 11:14:00 +00:00
|
|
|
ve.track( 'trace.setupToolbar.enter', { mode: mode } );
|
2014-12-16 21:14:01 +00:00
|
|
|
|
2014-02-07 22:04:35 +00:00
|
|
|
// Parent method
|
2015-08-02 11:30:49 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.super.prototype.setupToolbar.call( this, surface );
|
2014-02-07 22:04:35 +00:00
|
|
|
|
2021-10-13 12:57:45 +00:00
|
|
|
var toolbar = this.getToolbar();
|
2014-05-02 16:34:46 +00:00
|
|
|
|
2021-12-21 18:48:27 +00:00
|
|
|
// Allow the toolbar to start floating now if necessary
|
|
|
|
this.onContainerScroll();
|
|
|
|
|
2017-12-07 11:14:00 +00:00
|
|
|
ve.track( 'trace.setupToolbar.exit', { mode: mode } );
|
2015-02-21 10:42:58 +00:00
|
|
|
if ( !wasSetup ) {
|
2024-04-05 08:19:00 +00:00
|
|
|
toolbar.$element
|
|
|
|
.addClass( 've-init-mw-desktopArticleTarget-toolbar-open' );
|
2022-01-24 23:35:50 +00:00
|
|
|
if ( !toolbar.isFloating() ) {
|
|
|
|
toolbar.$element.css( 'height', '' );
|
2017-10-18 22:50:31 +00:00
|
|
|
}
|
2022-01-24 23:35:50 +00:00
|
|
|
this.toolbarSetupDeferred.resolve();
|
2015-02-18 20:11:49 +00:00
|
|
|
|
2015-03-07 18:02:06 +00:00
|
|
|
this.toolbarSetupDeferred.done( function () {
|
2020-08-18 12:16:49 +00:00
|
|
|
var newSurface = target.getSurface();
|
2015-03-07 18:02:06 +00:00
|
|
|
// Check the surface wasn't torn down while the toolbar was animating
|
2020-08-18 12:16:49 +00:00
|
|
|
if ( newSurface ) {
|
2017-12-07 11:14:00 +00:00
|
|
|
ve.track( 'trace.initializeToolbar.enter', { mode: mode } );
|
2015-03-07 18:02:06 +00:00
|
|
|
target.getToolbar().initialize();
|
2020-08-18 12:16:49 +00:00
|
|
|
newSurface.getView().emit( 'position' );
|
|
|
|
newSurface.getContext().updateDimensions();
|
2017-12-07 11:14:00 +00:00
|
|
|
ve.track( 'trace.initializeToolbar.exit', { mode: mode } );
|
|
|
|
ve.track( 'trace.activate.exit', { mode: mode } );
|
2015-03-07 18:02:06 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
2014-02-06 23:33:21 +00:00
|
|
|
};
|
|
|
|
|
2015-02-19 18:22:20 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.attachToolbar = function () {
|
2022-02-12 22:16:42 +00:00
|
|
|
// Set edit notices, will be shown after welcome dialog.
|
|
|
|
// Make sure notices actually exists, because this might be a mode-switch and
|
|
|
|
// we've already removed it.
|
|
|
|
var editNotices = this.getEditNotices(),
|
2023-04-27 13:51:35 +00:00
|
|
|
actionTools = this.toolbar.tools;
|
2022-02-12 22:16:42 +00:00
|
|
|
if ( editNotices && editNotices.length && actionTools.notices ) {
|
|
|
|
actionTools.notices.setNotices( editNotices );
|
|
|
|
} else if ( actionTools.notices ) {
|
|
|
|
actionTools.notices.destroy();
|
|
|
|
actionTools.notices = null;
|
|
|
|
}
|
|
|
|
|
2015-02-19 18:22:20 +00:00
|
|
|
// Move the toolbar to top of target, before heading etc.
|
|
|
|
// Avoid re-attaching as it breaks CSS animations
|
2015-02-23 08:44:51 +00:00
|
|
|
if ( !this.toolbar.$element.parent().is( this.$element ) ) {
|
|
|
|
this.toolbar.$element
|
|
|
|
// Set 0 before attach (expanded in #setupToolbar)
|
|
|
|
.css( 'height', '0' )
|
2015-07-30 11:08:56 +00:00
|
|
|
.addClass( 've-init-mw-desktopArticleTarget-toolbar' );
|
2015-02-23 08:44:51 +00:00
|
|
|
this.$element.prepend( this.toolbar.$element );
|
2022-02-12 21:13:32 +00:00
|
|
|
|
|
|
|
// Calculate if the 'oo-ui-toolbar-narrow' class is needed (OOUI does it too late for our
|
|
|
|
// toolbar because the methods are called in the wrong order, see T92282).
|
|
|
|
this.toolbar.onWindowResize();
|
2015-02-19 18:22:20 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-04-15 22:39:56 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.setupToolbarSaveButton = function () {
|
2023-04-27 13:51:35 +00:00
|
|
|
this.toolbarSaveButton = this.toolbar.getToolGroupByName( 'save' ).items[ 0 ];
|
2015-02-19 18:22:20 +00:00
|
|
|
};
|
|
|
|
|
2014-05-15 19:56:13 +00:00
|
|
|
/**
|
|
|
|
* Set up notices for things like unknown browsers.
|
2014-12-16 21:14:01 +00:00
|
|
|
* Needs to be done on each activation because localNoticeMessages is cleared in clearState.
|
2014-05-15 19:56:13 +00:00
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.setupLocalNoticeMessages = function () {
|
2014-05-15 19:56:13 +00:00
|
|
|
if ( !(
|
2022-12-17 15:44:56 +00:00
|
|
|
this.currentUrl.searchParams.has( 'vesupported' ) ||
|
2020-06-10 11:03:51 +00:00
|
|
|
$.client.test( this.constructor.static.compatibility.supportedList, null, true )
|
2014-05-15 19:56:13 +00:00
|
|
|
) ) {
|
|
|
|
// Show warning in unknown browsers that pass the support test
|
|
|
|
// Continue at own risk.
|
|
|
|
this.localNoticeMessages.push( 'visualeditor-browserwarning' );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-08-10 16:00:17 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2022-08-10 16:11:16 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.updateTabs = function () {
|
|
|
|
mw.libs.ve.updateTabs( true, this.getDefaultMode(), this.section === 'new' );
|
2022-08-10 16:00:17 +00:00
|
|
|
};
|
|
|
|
|
2015-08-05 21:43:23 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2016-11-05 06:16:26 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.loadSuccess = function () {
|
2021-10-13 12:57:45 +00:00
|
|
|
var target = this;
|
2015-08-19 18:05:01 +00:00
|
|
|
|
2015-08-05 21:43:23 +00:00
|
|
|
// Parent method
|
|
|
|
ve.init.mw.DesktopArticleTarget.super.prototype.loadSuccess.apply( this, arguments );
|
|
|
|
|
2016-11-16 18:40:39 +00:00
|
|
|
this.wikitextFallbackLoading = false;
|
2015-10-23 16:29:56 +00:00
|
|
|
// Duplicate of this code in ve.init.mw.DesktopArticleTarget.init.js
|
2019-08-01 01:48:24 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-class-state
|
2015-10-23 16:29:56 +00:00
|
|
|
if ( $( '#ca-edit' ).hasClass( 'visualeditor-showtabdialog' ) ) {
|
2016-05-20 01:36:25 +00:00
|
|
|
$( '#ca-edit' ).removeClass( 'visualeditor-showtabdialog' );
|
2015-10-23 16:29:56 +00:00
|
|
|
// Set up a temporary window manager
|
2021-10-13 12:57:45 +00:00
|
|
|
var windowManager = new OO.ui.WindowManager();
|
2023-10-31 21:06:04 +00:00
|
|
|
$( OO.ui.getTeleportTarget() ).append( windowManager.$element );
|
2016-03-23 01:07:01 +00:00
|
|
|
this.editingTabDialog = new mw.libs.ve.EditingTabDialog();
|
|
|
|
windowManager.addWindows( [ this.editingTabDialog ] );
|
2016-04-13 21:46:14 +00:00
|
|
|
windowManager.openWindow( this.editingTabDialog )
|
2017-06-01 22:21:58 +00:00
|
|
|
.closed.then( function ( data ) {
|
2015-10-23 16:29:56 +00:00
|
|
|
// Detach the temporary window manager
|
|
|
|
windowManager.destroy();
|
|
|
|
|
|
|
|
if ( data && data.action === 'prefer-wt' ) {
|
2019-04-15 22:39:04 +00:00
|
|
|
target.switchToWikitextEditor( false );
|
2016-03-11 05:36:15 +00:00
|
|
|
} else if ( data && data.action === 'multi-tab' ) {
|
|
|
|
location.reload();
|
2015-10-23 16:29:56 +00:00
|
|
|
}
|
|
|
|
} );
|
2016-03-09 21:02:18 +00:00
|
|
|
|
|
|
|
// Pretend the user saw the welcome dialog before suppressing it.
|
2020-04-17 21:25:58 +00:00
|
|
|
mw.libs.ve.stopShowingWelcomeDialog();
|
2016-03-15 01:10:51 +00:00
|
|
|
this.suppressNormalStartupDialogs = true;
|
2015-10-23 16:29:56 +00:00
|
|
|
}
|
2015-08-05 21:43:23 +00:00
|
|
|
};
|
|
|
|
|
2015-02-05 00:05:56 +00:00
|
|
|
/**
|
|
|
|
* Handle the watch button being toggled on/off.
|
2015-08-13 16:39:24 +00:00
|
|
|
*
|
2021-10-25 15:53:15 +00:00
|
|
|
* @param {boolean} isWatched
|
|
|
|
* @param {string} expiry
|
|
|
|
* @param {string} expirySelected
|
2015-02-05 00:05:56 +00:00
|
|
|
*/
|
2021-10-25 15:53:15 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.onWatchToggle = function ( isWatched ) {
|
2015-02-05 00:05:56 +00:00
|
|
|
if ( !this.active && !this.activating ) {
|
|
|
|
return;
|
|
|
|
}
|
2023-02-06 21:58:45 +00:00
|
|
|
if ( this.checkboxesByName && this.checkboxesByName.wpWatchthis ) {
|
2015-08-13 16:39:24 +00:00
|
|
|
this.checkboxesByName.wpWatchthis.setSelected(
|
|
|
|
!!mw.user.options.get( 'watchdefault' ) ||
|
|
|
|
( !!mw.user.options.get( 'watchcreations' ) && !this.pageExists ) ||
|
2021-10-25 15:53:15 +00:00
|
|
|
isWatched
|
2015-02-05 00:05:56 +00:00
|
|
|
);
|
2015-08-13 16:39:24 +00:00
|
|
|
}
|
2015-02-05 00:05:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.bindHandlers = function () {
|
|
|
|
ve.init.mw.DesktopArticleTarget.super.prototype.bindHandlers.call( this );
|
2015-02-05 00:05:56 +00:00
|
|
|
if ( this.onWatchToggleHandler ) {
|
2021-10-25 15:53:15 +00:00
|
|
|
mw.hook( 'wikipage.watchlistChange' ).add( this.onWatchToggleHandler );
|
2015-02-05 00:05:56 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.unbindHandlers = function () {
|
|
|
|
ve.init.mw.DesktopArticleTarget.super.prototype.unbindHandlers.call( this );
|
2015-02-05 00:05:56 +00:00
|
|
|
if ( this.onWatchToggleHandler ) {
|
2021-10-25 15:53:15 +00:00
|
|
|
mw.hook( 'wikipage.watchlistChange' ).remove( this.onWatchToggleHandler );
|
2015-02-05 00:05:56 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Switch to edit mode.
|
2012-06-11 06:54:41 +00:00
|
|
|
*
|
2015-03-13 15:50:23 +00:00
|
|
|
* @param {jQuery.Promise} [dataPromise] Promise for pending request from
|
|
|
|
* mw.libs.ve.targetLoader#requestPageData, if any
|
2014-10-21 01:10:41 +00:00
|
|
|
* @return {jQuery.Promise}
|
2012-06-11 06:54:41 +00:00
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.activate = function ( dataPromise ) {
|
2021-10-13 12:57:45 +00:00
|
|
|
var target = this;
|
2015-03-10 19:15:11 +00:00
|
|
|
|
2020-03-11 14:45:06 +00:00
|
|
|
// We may be re-activating an old target, during which time ve.init.target
|
|
|
|
// has been overridden.
|
|
|
|
ve.init.target = ve.init.articleTarget;
|
|
|
|
|
2012-06-14 01:26:21 +00:00
|
|
|
if ( !this.active && !this.activating ) {
|
|
|
|
this.activating = true;
|
2019-11-02 05:06:28 +00:00
|
|
|
this.activatingDeferred = ve.createDeferred();
|
|
|
|
this.toolbarSetupDeferred = ve.createDeferred();
|
2013-06-05 21:38:39 +00:00
|
|
|
|
2016-06-01 13:52:57 +00:00
|
|
|
$( 'html' ).addClass( 've-activating' );
|
2019-11-02 16:29:11 +00:00
|
|
|
ve.promiseAll( [ this.activatingDeferred, this.toolbarSetupDeferred ] ).done( function () {
|
2023-06-20 08:33:17 +00:00
|
|
|
if ( !target.suppressNormalStartupDialogs ) {
|
|
|
|
target.maybeShowWelcomeDialog();
|
|
|
|
target.maybeShowMetaDialog();
|
|
|
|
}
|
2016-04-21 15:44:23 +00:00
|
|
|
target.afterActivate();
|
2015-05-03 10:51:48 +00:00
|
|
|
} ).fail( function () {
|
|
|
|
$( 'html' ).removeClass( 've-activating' );
|
2015-02-05 01:45:19 +00:00
|
|
|
} );
|
|
|
|
|
2017-10-05 16:31:15 +00:00
|
|
|
// Handlers were unbound in constructor. Will be unbound again in teardown.
|
2014-12-12 02:18:46 +00:00
|
|
|
this.bindHandlers();
|
|
|
|
|
2014-09-25 20:19:18 +00:00
|
|
|
this.originalEditondbclick = mw.user.options.get( 'editondblclick' );
|
|
|
|
mw.user.options.set( 'editondblclick', 0 );
|
|
|
|
|
2012-06-18 20:12:32 +00:00
|
|
|
// User interface changes
|
2018-06-15 20:10:25 +00:00
|
|
|
this.changeDocumentTitle();
|
2013-06-05 21:38:39 +00:00
|
|
|
this.transformPage();
|
2014-05-15 19:56:13 +00:00
|
|
|
this.setupLocalNoticeMessages();
|
2013-10-06 19:50:06 +00:00
|
|
|
|
2015-03-13 15:50:23 +00:00
|
|
|
this.load( dataPromise );
|
2012-06-11 06:54:41 +00:00
|
|
|
}
|
2014-10-21 01:10:41 +00:00
|
|
|
return this.activatingDeferred.promise();
|
2012-06-14 21:31:08 +00:00
|
|
|
};
|
|
|
|
|
2016-04-21 15:44:23 +00:00
|
|
|
/**
|
|
|
|
* Edit mode has finished activating
|
|
|
|
*/
|
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.afterActivate = function () {
|
|
|
|
$( 'html' ).removeClass( 've-activating' ).addClass( 've-active' );
|
2020-06-05 15:48:00 +00:00
|
|
|
|
|
|
|
// Disable TemplateStyles in the original content
|
|
|
|
// (We do this here because toggling 've-active' class above hides it)
|
|
|
|
this.$editableContent.find( 'style[data-mw-deduplicate^="TemplateStyles:"]' ).prop( 'disabled', true );
|
|
|
|
|
2021-12-21 18:41:36 +00:00
|
|
|
this.afterSurfaceReady();
|
|
|
|
|
2016-04-21 15:44:23 +00:00
|
|
|
if ( !this.editingTabDialog ) {
|
2016-12-08 19:24:10 +00:00
|
|
|
if ( this.sectionTitle ) {
|
|
|
|
this.sectionTitle.focus();
|
|
|
|
} else {
|
|
|
|
// We have to focus the page after hiding the original content, otherwise
|
|
|
|
// in firefox the contentEditable container was below the view page, and
|
|
|
|
// 'focus' scrolled the screen down.
|
|
|
|
// Support: Firefox
|
|
|
|
this.getSurface().getView().focus();
|
|
|
|
}
|
2018-01-23 20:51:11 +00:00
|
|
|
// Transfer and initial source range to the surface (e.g. from tempWikitextEditor)
|
|
|
|
if ( this.initialSourceRange && this.getSurface().getMode() === 'source' ) {
|
2021-10-13 12:57:45 +00:00
|
|
|
var surfaceModel = this.getSurface().getModel();
|
|
|
|
var range = surfaceModel.getRangeFromSourceOffsets( this.initialSourceRange.from, this.initialSourceRange.to );
|
2018-01-23 20:51:11 +00:00
|
|
|
surfaceModel.setLinearSelection( range );
|
|
|
|
}
|
2016-04-21 15:44:23 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-26 10:56:08 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.setSurface = function ( surface ) {
|
2018-04-24 16:08:55 +00:00
|
|
|
var resetSurface = surface !== this.surface;
|
|
|
|
|
|
|
|
if ( resetSurface ) {
|
2016-05-26 10:56:08 +00:00
|
|
|
this.$editableContent.after( surface.$element );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parent method
|
|
|
|
ve.init.mw.DesktopArticleTarget.super.prototype.setSurface.apply( this, arguments );
|
2018-04-24 16:08:55 +00:00
|
|
|
|
|
|
|
if ( resetSurface ) {
|
|
|
|
this.setupNewSection( surface );
|
|
|
|
}
|
2016-05-26 10:56:08 +00:00
|
|
|
};
|
|
|
|
|
2016-12-08 19:24:10 +00:00
|
|
|
/**
|
2017-10-05 15:20:48 +00:00
|
|
|
* Setup new section input for a surface, if required
|
2016-12-08 19:24:10 +00:00
|
|
|
*
|
2021-06-04 11:58:18 +00:00
|
|
|
* @param {ve.ui.Surface} surface
|
2016-12-08 19:24:10 +00:00
|
|
|
*/
|
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.setupNewSection = function ( surface ) {
|
|
|
|
if ( surface.getMode() === 'source' && this.section === 'new' ) {
|
|
|
|
if ( !this.sectionTitle ) {
|
|
|
|
this.sectionTitle = new OO.ui.TextInputWidget( {
|
2017-03-03 11:59:06 +00:00
|
|
|
$element: $( '<h2>' ),
|
2022-03-12 14:45:16 +00:00
|
|
|
classes: [ 've-init-mw-desktopArticleTarget-sectionTitle' ],
|
2017-11-15 17:13:50 +00:00
|
|
|
placeholder: ve.msg( 'visualeditor-section-title-placeholder' ),
|
|
|
|
spellcheck: true
|
2016-12-08 19:24:10 +00:00
|
|
|
} );
|
2018-03-12 12:25:12 +00:00
|
|
|
if ( this.recovered ) {
|
|
|
|
this.sectionTitle.setValue(
|
2019-04-24 14:22:19 +00:00
|
|
|
ve.init.platform.sessionStorage.get( 've-docsectiontitle' ) || ''
|
2018-03-12 12:25:12 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
this.sectionTitle.connect( this, { change: 'onSectionTitleChange' } );
|
2016-12-08 19:24:10 +00:00
|
|
|
}
|
|
|
|
surface.setPlaceholder( ve.msg( 'visualeditor-section-body-placeholder' ) );
|
|
|
|
this.$editableContent.before( this.sectionTitle.$element );
|
2017-09-18 15:05:32 +00:00
|
|
|
|
2022-12-17 15:44:56 +00:00
|
|
|
if ( this.currentUrl.searchParams.has( 'preloadtitle' ) ) {
|
|
|
|
this.sectionTitle.setValue( this.currentUrl.searchParams.get( 'preloadtitle' ) );
|
2017-09-18 15:05:32 +00:00
|
|
|
}
|
2017-10-05 15:20:48 +00:00
|
|
|
surface.once( 'destroy', this.teardownNewSection.bind( this, surface ) );
|
2018-03-12 12:25:12 +00:00
|
|
|
} else {
|
2019-04-24 14:22:19 +00:00
|
|
|
ve.init.platform.sessionStorage.remove( 've-docsectiontitle' );
|
2016-12-08 19:24:10 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-12 12:25:12 +00:00
|
|
|
/**
|
|
|
|
* Handle section title changes
|
|
|
|
*/
|
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.onSectionTitleChange = function () {
|
2019-04-24 14:22:19 +00:00
|
|
|
ve.init.platform.sessionStorage.set( 've-docsectiontitle', this.sectionTitle.getValue() );
|
2018-03-12 12:25:12 +00:00
|
|
|
this.updateToolbarSaveButtonState();
|
|
|
|
};
|
|
|
|
|
2016-12-08 19:24:10 +00:00
|
|
|
/**
|
|
|
|
* Teardown new section inputs
|
2019-04-16 15:17:29 +00:00
|
|
|
*
|
2021-06-04 11:58:18 +00:00
|
|
|
* @param {ve.ui.Surface} surface
|
2016-12-08 19:24:10 +00:00
|
|
|
*/
|
2017-10-05 15:20:48 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.teardownNewSection = function ( surface ) {
|
|
|
|
surface.setPlaceholder( '' );
|
2016-12-08 19:24:10 +00:00
|
|
|
if ( this.sectionTitle ) {
|
|
|
|
this.sectionTitle.$element.remove();
|
|
|
|
this.sectionTitle = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-06-12 01:21:31 +00:00
|
|
|
/**
|
2018-03-26 14:23:56 +00:00
|
|
|
* @inheritdoc
|
2014-12-03 00:39:56 +00:00
|
|
|
*
|
2018-03-26 14:23:56 +00:00
|
|
|
* A prompt will not be shown if tryTeardown() is called while activation is still in progress.
|
|
|
|
* If tryTeardown() is called while the target is deactivating, or while it's not active and
|
|
|
|
* not activating, nothing happens.
|
2012-06-12 01:21:31 +00:00
|
|
|
*/
|
2018-03-26 14:23:56 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.tryTeardown = function ( noPrompt, trackMechanism ) {
|
2014-12-03 00:39:56 +00:00
|
|
|
if ( this.deactivating || ( !this.active && !this.activating ) ) {
|
2023-02-06 23:03:07 +00:00
|
|
|
return this.teardownPromise || ve.createDeferred().resolve().promise();
|
2014-12-03 00:39:56 +00:00
|
|
|
}
|
|
|
|
|
2016-04-13 21:39:54 +00:00
|
|
|
// Just in case these weren't closed before
|
2015-03-27 18:45:26 +00:00
|
|
|
if ( this.welcomeDialog ) {
|
|
|
|
this.welcomeDialog.close();
|
|
|
|
}
|
2016-04-13 21:39:54 +00:00
|
|
|
if ( this.editingTabDialog ) {
|
|
|
|
this.editingTabDialog.close();
|
|
|
|
}
|
2016-03-23 01:07:01 +00:00
|
|
|
this.editingTabDialog = null;
|
2015-03-25 21:52:06 +00:00
|
|
|
|
2018-04-23 20:30:37 +00:00
|
|
|
// Parent method
|
2018-03-26 14:23:56 +00:00
|
|
|
return ve.init.mw.DesktopArticleTarget.super.prototype.tryTeardown.call( this, noPrompt || this.activating, trackMechanism );
|
2012-06-12 01:21:31 +00:00
|
|
|
};
|
|
|
|
|
2014-04-29 14:04:19 +00:00
|
|
|
/**
|
2017-10-05 16:31:15 +00:00
|
|
|
* @inheritdoc
|
2014-04-29 14:04:19 +00:00
|
|
|
*
|
2017-10-05 16:31:15 +00:00
|
|
|
* @param {string} [trackMechanism]
|
|
|
|
* @fires deactivate
|
2014-10-29 01:19:52 +00:00
|
|
|
*/
|
2017-10-05 16:31:15 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.teardown = function ( trackMechanism ) {
|
2022-05-13 17:51:34 +00:00
|
|
|
var target = this;
|
2017-10-05 16:31:15 +00:00
|
|
|
|
2014-10-29 01:19:52 +00:00
|
|
|
// Event tracking
|
2021-07-27 20:48:05 +00:00
|
|
|
var abortType, abortedMode;
|
2014-10-29 01:19:52 +00:00
|
|
|
if ( trackMechanism ) {
|
|
|
|
if ( this.activating ) {
|
|
|
|
abortType = 'preinit';
|
|
|
|
} else if ( !this.edited ) {
|
|
|
|
abortType = 'nochange';
|
|
|
|
} else if ( this.saving ) {
|
|
|
|
abortType = 'abandonMidsave';
|
|
|
|
} else {
|
|
|
|
// switchwith and switchwithout do not go through this code path,
|
|
|
|
// they go through switchToWikitextEditor() instead
|
|
|
|
abortType = 'abandon';
|
|
|
|
}
|
2021-07-27 20:48:05 +00:00
|
|
|
abortedMode = this.surface ? this.surface.getMode() : this.getDefaultMode();
|
2014-10-29 01:19:52 +00:00
|
|
|
}
|
2014-07-14 21:32:49 +00:00
|
|
|
|
2015-12-23 12:13:50 +00:00
|
|
|
// Cancel activating, start deactivating
|
2014-04-29 14:04:19 +00:00
|
|
|
this.deactivating = true;
|
2022-04-07 20:10:41 +00:00
|
|
|
this.deactivatingDeferred = ve.createDeferred();
|
2015-12-23 12:13:50 +00:00
|
|
|
this.activating = false;
|
|
|
|
this.activatingDeferred.reject();
|
2015-02-23 08:44:18 +00:00
|
|
|
$( 'html' ).addClass( 've-deactivating' ).removeClass( 've-activated ve-active' );
|
2015-12-23 12:13:50 +00:00
|
|
|
|
2022-04-07 20:10:41 +00:00
|
|
|
this.emit( 'deactivate' );
|
|
|
|
|
2020-06-05 15:48:00 +00:00
|
|
|
// Restore TemplateStyles of the original content
|
|
|
|
// (We do this here because toggling 've-active' class above displays it)
|
|
|
|
this.$editableContent.find( 'style[data-mw-deduplicate^="TemplateStyles:"]' ).prop( 'disabled', false );
|
|
|
|
|
2014-04-29 14:04:19 +00:00
|
|
|
// User interface changes
|
|
|
|
this.restorePage();
|
2018-06-15 20:10:25 +00:00
|
|
|
this.restoreDocumentTitle();
|
2014-04-29 14:04:19 +00:00
|
|
|
|
2014-09-25 20:19:18 +00:00
|
|
|
mw.user.options.set( 'editondblclick', this.originalEditondbclick );
|
|
|
|
this.originalEditondbclick = undefined;
|
|
|
|
|
2017-10-05 16:31:15 +00:00
|
|
|
// TODO: Use better checks to see if these restorations are required.
|
2015-12-23 12:13:50 +00:00
|
|
|
if ( this.getSurface() ) {
|
|
|
|
if ( this.active ) {
|
|
|
|
this.teardownUnloadHandlers();
|
|
|
|
}
|
2015-05-03 10:51:48 +00:00
|
|
|
}
|
|
|
|
|
2022-05-13 17:51:34 +00:00
|
|
|
// Parent method
|
|
|
|
return ve.init.mw.DesktopArticleTarget.super.prototype.teardown.call( this ).then( function () {
|
|
|
|
// After teardown
|
|
|
|
target.active = false;
|
2014-04-29 14:04:19 +00:00
|
|
|
|
2022-05-13 17:51:34 +00:00
|
|
|
// If there is a load in progress, try to abort it
|
|
|
|
if ( target.loading && target.loading.abort ) {
|
|
|
|
target.loading.abort();
|
|
|
|
}
|
2017-10-05 16:31:15 +00:00
|
|
|
|
2022-05-13 17:51:34 +00:00
|
|
|
target.clearState();
|
2022-12-17 15:44:56 +00:00
|
|
|
target.initialEditSummary = new URL( location.href ).searchParams.get( 'summary' );
|
2022-05-13 17:51:34 +00:00
|
|
|
target.editSummaryValue = null;
|
2017-10-05 16:31:15 +00:00
|
|
|
|
2022-05-13 17:51:34 +00:00
|
|
|
// Move original content back out of the target
|
|
|
|
target.$element.parent().append( target.$originalContent.children() );
|
2020-06-05 15:48:00 +00:00
|
|
|
|
2022-05-13 17:51:34 +00:00
|
|
|
$( '.ve-init-mw-desktopArticleTarget-uneditableContent' )
|
|
|
|
.removeClass( 've-init-mw-desktopArticleTarget-uneditableContent' );
|
2015-01-21 14:55:38 +00:00
|
|
|
|
2022-05-13 17:51:34 +00:00
|
|
|
target.deactivating = false;
|
|
|
|
target.deactivatingDeferred.resolve();
|
|
|
|
$( 'html' ).removeClass( 've-deactivating' );
|
2022-04-07 20:10:41 +00:00
|
|
|
|
2022-05-13 17:51:34 +00:00
|
|
|
// Event tracking
|
|
|
|
if ( trackMechanism ) {
|
2023-03-18 02:34:32 +00:00
|
|
|
ve.track( 'editAttemptStep', {
|
|
|
|
action: 'abort',
|
2022-05-13 17:51:34 +00:00
|
|
|
type: abortType,
|
|
|
|
mechanism: trackMechanism,
|
|
|
|
mode: abortedMode
|
|
|
|
} );
|
|
|
|
}
|
2021-07-27 20:48:05 +00:00
|
|
|
|
2022-05-13 17:51:34 +00:00
|
|
|
if ( !target.isViewPage ) {
|
2022-12-17 15:44:56 +00:00
|
|
|
var newUrl = new URL( target.viewUrl );
|
|
|
|
if ( mw.config.get( 'wgIsRedirect' ) ) {
|
|
|
|
newUrl.searchParams.set( 'redirect', 'no' );
|
|
|
|
}
|
|
|
|
location.href = newUrl;
|
2022-05-13 17:51:34 +00:00
|
|
|
}
|
2014-12-16 21:14:01 +00:00
|
|
|
} );
|
2014-04-29 14:04:19 +00:00
|
|
|
};
|
|
|
|
|
2012-06-12 17:32:10 +00:00
|
|
|
/**
|
2015-08-04 13:37:13 +00:00
|
|
|
* @inheritdoc
|
2012-06-12 17:32:10 +00:00
|
|
|
*/
|
2016-12-21 03:19:19 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.loadFail = function ( code, errorDetails ) {
|
2021-10-13 12:57:45 +00:00
|
|
|
var target = this;
|
2016-11-11 13:13:58 +00:00
|
|
|
|
2015-07-31 15:03:33 +00:00
|
|
|
// Parent method
|
2015-08-04 13:37:13 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.super.prototype.loadFail.apply( this, arguments );
|
2015-07-31 15:03:33 +00:00
|
|
|
|
2016-11-16 18:40:39 +00:00
|
|
|
if ( this.wikitextFallbackLoading ) {
|
|
|
|
// Failed twice now
|
2016-12-21 03:19:19 +00:00
|
|
|
mw.log.warn( 'Failed to fall back to wikitext', code, errorDetails );
|
2022-12-17 15:44:56 +00:00
|
|
|
var newUrl = new URL( target.viewUrl );
|
|
|
|
newUrl.searchParams.set( 'action', 'edit' );
|
|
|
|
newUrl.searchParams.set( 'veswitched', '1' );
|
|
|
|
location.href = newUrl;
|
2016-11-16 18:40:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-28 15:05:00 +00:00
|
|
|
if ( !this.activating ) {
|
2022-02-18 18:11:29 +00:00
|
|
|
// Load failed after activation abandoned (e.g. user pressed escape).
|
2022-01-28 15:05:00 +00:00
|
|
|
// Nothing more to do.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-13 12:57:45 +00:00
|
|
|
var $confirmPromptMessage = this.extractErrorMessages( errorDetails );
|
2019-12-12 00:38:00 +00:00
|
|
|
|
|
|
|
OO.ui.confirm( $confirmPromptMessage, {
|
|
|
|
actions: [
|
|
|
|
{ action: 'accept', label: OO.ui.msg( 'ooui-dialog-process-retry' ), flags: 'primary' },
|
|
|
|
{ action: 'reject', label: OO.ui.msg( 'ooui-dialog-message-reject' ), flags: 'safe' }
|
|
|
|
]
|
|
|
|
} ).done( function ( confirmed ) {
|
|
|
|
if ( confirmed ) {
|
2022-01-28 15:05:00 +00:00
|
|
|
// Retry load
|
2019-12-12 00:38:00 +00:00
|
|
|
target.load();
|
2016-07-31 20:53:44 +00:00
|
|
|
} else {
|
2022-04-26 15:31:12 +00:00
|
|
|
// User pressed "cancel"
|
2022-01-28 15:05:00 +00:00
|
|
|
if ( target.getSurface() ) {
|
2022-04-26 15:31:12 +00:00
|
|
|
// Restore the mode of the current surface
|
|
|
|
target.setDefaultMode( target.getSurface().getMode() );
|
2022-01-28 15:05:00 +00:00
|
|
|
target.activatingDeferred.reject();
|
|
|
|
} else {
|
|
|
|
// We're switching from read mode or the 2010 wikitext editor:
|
|
|
|
// just give up and stay where you are
|
|
|
|
target.tryTeardown( true );
|
|
|
|
}
|
2014-03-12 23:39:30 +00:00
|
|
|
}
|
2019-12-12 00:38:00 +00:00
|
|
|
} );
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
2013-10-11 18:42:46 +00:00
|
|
|
/**
|
2015-08-04 13:37:13 +00:00
|
|
|
* @inheritdoc
|
2013-10-11 18:42:46 +00:00
|
|
|
*/
|
2015-12-11 14:57:49 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.surfaceReady = function () {
|
2014-11-19 02:16:27 +00:00
|
|
|
if ( !this.activating ) {
|
|
|
|
// Activation was aborted before we got here. Do nothing
|
|
|
|
// TODO are there things we need to clean up?
|
|
|
|
return;
|
|
|
|
}
|
2015-02-05 01:45:19 +00:00
|
|
|
|
2022-02-12 22:16:42 +00:00
|
|
|
var surface = this.getSurface();
|
2021-07-27 15:40:13 +00:00
|
|
|
|
2013-12-03 02:21:31 +00:00
|
|
|
this.activating = false;
|
2014-03-19 22:51:23 +00:00
|
|
|
|
|
|
|
// TODO: mwTocWidget should probably live in a ve.ui.MWSurface subclass
|
2014-01-09 01:32:13 +00:00
|
|
|
if ( mw.config.get( 'wgVisualEditorConfig' ).enableTocWidget ) {
|
2016-07-06 14:16:00 +00:00
|
|
|
surface.mwTocWidget = new ve.ui.MWTocWidget( this.getSurface() );
|
2017-10-05 15:03:55 +00:00
|
|
|
surface.once( 'destroy', function () {
|
|
|
|
surface.mwTocWidget.$element.remove();
|
|
|
|
} );
|
2014-01-09 01:32:13 +00:00
|
|
|
}
|
2013-12-06 20:01:03 +00:00
|
|
|
|
2022-01-19 14:25:39 +00:00
|
|
|
var metaList = this.getSurface().getModel().getDocument().getMetaList();
|
2017-03-20 11:07:52 +00:00
|
|
|
|
2020-07-13 19:00:25 +00:00
|
|
|
metaList.connect( this, {
|
2016-02-25 23:27:54 +00:00
|
|
|
insert: 'onMetaItemInserted',
|
|
|
|
remove: 'onMetaItemRemoved'
|
|
|
|
} );
|
2020-07-13 19:00:25 +00:00
|
|
|
// Rebuild the category list from the page we got from the API. This makes
|
|
|
|
// it work regardless of whether we came here from activating on an
|
|
|
|
// existing page, or loading via an edit URL.
|
|
|
|
this.rebuildCategories( metaList.getItemsInGroup( 'mwCategory' ), true );
|
2016-02-25 23:27:54 +00:00
|
|
|
|
2015-07-01 11:11:36 +00:00
|
|
|
// Parent method
|
2015-12-11 14:57:49 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.super.prototype.surfaceReady.apply( this, arguments );
|
2015-07-01 11:11:36 +00:00
|
|
|
|
2022-01-19 14:25:39 +00:00
|
|
|
var redirectMetaItems = metaList.getItemsInGroup( 'mwRedirect' );
|
2017-03-28 15:40:23 +00:00
|
|
|
if ( redirectMetaItems.length ) {
|
|
|
|
this.setFakeRedirectInterface( redirectMetaItems[ 0 ].getAttribute( 'title' ) );
|
|
|
|
} else {
|
|
|
|
this.setFakeRedirectInterface( null );
|
|
|
|
}
|
|
|
|
|
2015-02-12 02:35:52 +00:00
|
|
|
this.setupUnloadHandlers();
|
2015-03-10 19:15:11 +00:00
|
|
|
|
2014-10-21 01:10:41 +00:00
|
|
|
this.activatingDeferred.resolve();
|
2015-04-09 03:48:46 +00:00
|
|
|
this.events.trackActivationComplete();
|
2013-10-11 18:42:46 +00:00
|
|
|
};
|
|
|
|
|
2016-02-25 23:27:54 +00:00
|
|
|
/**
|
2017-03-28 15:40:23 +00:00
|
|
|
* Update the redirect and category interfaces when a meta item is inserted into the page.
|
2016-02-25 23:27:54 +00:00
|
|
|
*
|
|
|
|
* @param {ve.dm.MetaItem} metaItem Item that was inserted
|
|
|
|
*/
|
2017-03-28 15:40:23 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.onMetaItemInserted = function ( metaItem ) {
|
2016-12-01 20:06:19 +00:00
|
|
|
switch ( metaItem.getType() ) {
|
|
|
|
case 'mwRedirect':
|
2017-03-28 15:40:23 +00:00
|
|
|
this.setFakeRedirectInterface( metaItem.getAttribute( 'title' ) );
|
2016-12-01 20:06:19 +00:00
|
|
|
break;
|
|
|
|
case 'mwCategory':
|
2022-01-19 14:25:39 +00:00
|
|
|
var metaList = this.getSurface().getModel().getDocument().getMetaList();
|
2016-12-01 20:06:19 +00:00
|
|
|
this.rebuildCategories( metaList.getItemsInGroup( 'mwCategory' ) );
|
|
|
|
break;
|
2016-02-25 23:27:54 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-03-28 15:40:23 +00:00
|
|
|
* Update the redirect and category interfaces when a meta item is removed from the page.
|
2016-02-25 23:27:54 +00:00
|
|
|
*
|
|
|
|
* @param {ve.dm.MetaItem} metaItem Item that was removed
|
|
|
|
* @param {number} offset Linear model offset that the item was at
|
|
|
|
* @param {number} index Index within that offset the item was at
|
|
|
|
*/
|
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.onMetaItemRemoved = function ( metaItem ) {
|
2016-12-01 20:06:19 +00:00
|
|
|
switch ( metaItem.getType() ) {
|
|
|
|
case 'mwRedirect':
|
2017-03-28 15:40:23 +00:00
|
|
|
this.setFakeRedirectInterface( null );
|
2016-12-01 20:06:19 +00:00
|
|
|
break;
|
|
|
|
case 'mwCategory':
|
2022-01-19 14:25:39 +00:00
|
|
|
var metaList = this.getSurface().getModel().getDocument().getMetaList();
|
2016-12-01 20:06:19 +00:00
|
|
|
this.rebuildCategories( metaList.getItemsInGroup( 'mwCategory' ) );
|
|
|
|
break;
|
2016-02-25 23:27:54 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-01 20:06:19 +00:00
|
|
|
/**
|
|
|
|
* Redisplay the category list on the page
|
|
|
|
*
|
2018-05-09 20:12:26 +00:00
|
|
|
* This is used for the preview while editing. Leaving the editor either restores the initial
|
|
|
|
* categories, or uses the ones generated by the save API.
|
|
|
|
*
|
2016-12-01 20:06:19 +00:00
|
|
|
* @param {ve.dm.MetaItem[]} categoryItems Array of category metaitems to display
|
|
|
|
*/
|
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.rebuildCategories = function ( categoryItems ) {
|
|
|
|
var target = this;
|
2018-05-09 20:12:26 +00:00
|
|
|
this.renderCategories( categoryItems ).done( function ( $categories ) {
|
|
|
|
// Clone the existing catlinks for any specific properties which might
|
|
|
|
// be needed by the rest of the page. Also gives us a not-attached
|
|
|
|
// version, which we can pass to wikipage.categories as it requests.
|
2019-02-21 17:39:19 +00:00
|
|
|
var $catlinks = $( '#catlinks' ).clone().empty().removeClass( 'categories-allhidden' )
|
|
|
|
.append( $categories.children() );
|
|
|
|
// If all categories are hidden, we need to hide the box.
|
|
|
|
$catlinks.toggleClass( 'catlinks-allhidden',
|
|
|
|
$catlinks.find( '.mw-normal-catlinks' ).length === 0 &&
|
|
|
|
// Some situations make the hidden-categories visible (a user
|
|
|
|
// preference, and being on a category page) so rather than
|
|
|
|
// encoding that logic here just check whether they're visible:
|
2019-08-01 01:48:24 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-sizzle
|
2019-02-21 17:39:19 +00:00
|
|
|
$catlinks.find( '.mw-hidden-catlinks:visible' ).length === 0
|
|
|
|
);
|
2018-05-09 20:12:26 +00:00
|
|
|
target.transformCategoryLinks( $catlinks );
|
|
|
|
mw.hook( 'wikipage.categories' ).fire( $catlinks );
|
|
|
|
$( '#catlinks' ).replaceWith( $catlinks );
|
2016-12-01 20:06:19 +00:00
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2014-12-03 00:39:56 +00:00
|
|
|
/**
|
|
|
|
* Handle clicks on the view tab.
|
|
|
|
*
|
|
|
|
* @param {jQuery.Event} e Mouse click event
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.onViewTabClick = function ( e ) {
|
2018-06-18 15:46:33 +00:00
|
|
|
if ( ( !this.active && !this.activating ) || !ve.isUnmodifiedLeftClick( e ) ) {
|
2014-12-03 00:39:56 +00:00
|
|
|
return;
|
2014-11-25 01:44:24 +00:00
|
|
|
}
|
2018-03-26 14:23:56 +00:00
|
|
|
this.tryTeardown( false, 'navigate-read' );
|
2014-12-03 00:39:56 +00:00
|
|
|
e.preventDefault();
|
2014-11-25 01:44:24 +00:00
|
|
|
};
|
|
|
|
|
2012-06-18 20:12:32 +00:00
|
|
|
/**
|
2015-08-04 13:37:13 +00:00
|
|
|
* @inheritdoc
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2019-11-04 14:54:53 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.saveComplete = function ( data ) {
|
2022-02-24 20:47:46 +00:00
|
|
|
// Parent method
|
|
|
|
ve.init.mw.DesktopArticleTarget.super.prototype.saveComplete.apply( this, arguments );
|
|
|
|
|
2023-06-03 01:19:38 +00:00
|
|
|
// If there is no content, then parent method will reload the whole page
|
|
|
|
if ( !data.nocontent ) {
|
2022-02-17 22:06:14 +00:00
|
|
|
// Fix permalinks
|
2019-11-04 14:54:53 +00:00
|
|
|
if ( data.newrevid !== undefined ) {
|
2022-12-06 00:05:06 +00:00
|
|
|
$( '#t-permalink' ).add( '#coll-download-as-rl' ).find( 'a' ).each( function () {
|
2022-12-17 15:44:56 +00:00
|
|
|
var permalinkUrl = new URL( this.href );
|
|
|
|
permalinkUrl.searchParams.set( 'oldid', data.newrevid );
|
|
|
|
$( this ).attr( 'href', permalinkUrl.toString() );
|
2015-01-28 21:10:22 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2022-02-24 20:47:46 +00:00
|
|
|
// Actually fire the postEdit hook now that the save is complete
|
2019-11-04 14:54:53 +00:00
|
|
|
if ( data.newrevid !== undefined ) {
|
2023-06-10 02:23:42 +00:00
|
|
|
require( 'mediawiki.action.view.postEdit' ).fireHook( 'saved' );
|
2014-07-29 22:37:28 +00:00
|
|
|
}
|
2012-06-20 19:15:42 +00:00
|
|
|
}
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
2013-04-24 00:01:44 +00:00
|
|
|
/**
|
2015-08-04 13:37:13 +00:00
|
|
|
* @inheritdoc
|
2013-04-24 00:01:44 +00:00
|
|
|
*/
|
2019-11-04 14:54:53 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.serialize = function () {
|
2015-08-04 13:37:13 +00:00
|
|
|
// Parent method
|
2019-11-04 14:54:53 +00:00
|
|
|
var promise = ve.init.mw.DesktopArticleTarget.super.prototype.serialize.apply( this, arguments ),
|
|
|
|
target = this;
|
2015-08-04 13:37:13 +00:00
|
|
|
|
2019-11-04 14:54:53 +00:00
|
|
|
return promise.fail( function ( error, response ) {
|
2021-10-25 15:51:29 +00:00
|
|
|
var $errorMessages = target.extractErrorMessages( response );
|
2022-06-15 23:28:19 +00:00
|
|
|
OO.ui.alert( $errorMessages );
|
2013-11-15 21:34:59 +00:00
|
|
|
|
2019-11-04 14:54:53 +00:00
|
|
|
// It's possible to get here while the save dialog has never been opened (if the user uses
|
|
|
|
// the switch to source mode option)
|
|
|
|
if ( target.saveDialog ) {
|
|
|
|
target.saveDialog.popPending();
|
|
|
|
}
|
|
|
|
} );
|
2013-04-24 00:01:44 +00:00
|
|
|
};
|
|
|
|
|
2013-06-05 19:28:00 +00:00
|
|
|
/**
|
|
|
|
* Handle clicks on the MwMeta button in the toolbar.
|
|
|
|
*
|
|
|
|
* @param {jQuery.Event} e Mouse click event
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.onToolbarMetaButtonClick = function () {
|
2014-11-27 20:51:04 +00:00
|
|
|
this.getSurface().getDialogs().openWindow( 'meta' );
|
2013-06-05 19:28:00 +00:00
|
|
|
};
|
|
|
|
|
2012-06-18 20:12:32 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Modify tabs in the skin to support in-place editing.
|
2016-11-08 12:37:51 +00:00
|
|
|
*
|
|
|
|
* 'Read' and 'Edit source' (when not using single edit tab) bound here,
|
|
|
|
* 'Edit' and single edit tab are bound in mw.DesktopArticleTarget.init.
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.setupSkinTabs = function () {
|
2012-06-18 23:18:48 +00:00
|
|
|
if ( this.isViewPage ) {
|
2021-10-13 12:57:45 +00:00
|
|
|
var namespaceNumber = mw.config.get( 'wgNamespaceNumber' );
|
|
|
|
var namespaceName = mw.config.get( 'wgCanonicalNamespace' );
|
|
|
|
var isTalkNamespace = mw.Title.isTalkNamespace( namespaceNumber );
|
2018-09-13 09:04:47 +00:00
|
|
|
// Title::getNamespaceKey()
|
2021-10-13 12:57:45 +00:00
|
|
|
var namespaceKey = namespaceName.toLowerCase() || 'main';
|
2018-03-10 19:05:08 +00:00
|
|
|
if ( namespaceKey === 'file' ) {
|
|
|
|
namespaceKey = 'image';
|
|
|
|
}
|
2021-10-13 12:57:45 +00:00
|
|
|
var namespaceTabId;
|
2018-09-13 09:04:47 +00:00
|
|
|
// SkinTemplate::buildContentNavigationUrls()
|
|
|
|
if ( isTalkNamespace ) {
|
|
|
|
namespaceTabId = 'ca-talk';
|
|
|
|
} else {
|
|
|
|
namespaceTabId = 'ca-nstab-' + namespaceKey;
|
|
|
|
}
|
2012-08-01 06:40:22 +00:00
|
|
|
// Allow instant switching back to view mode, without refresh
|
2022-12-06 00:05:06 +00:00
|
|
|
$( '#ca-view' ).add( '#' + namespaceTabId ).find( 'a' )
|
2018-06-18 15:46:33 +00:00
|
|
|
.on( 'click.ve-target', this.onViewTabClick.bind( this ) );
|
2016-01-28 02:29:11 +00:00
|
|
|
}
|
2013-07-09 01:35:35 +00:00
|
|
|
|
2018-11-29 14:38:53 +00:00
|
|
|
// Used by Extension:GuidedTour
|
2013-07-09 01:35:35 +00:00
|
|
|
mw.hook( 've.skinTabSetupComplete' ).fire();
|
2012-06-11 06:54:41 +00:00
|
|
|
};
|
|
|
|
|
2012-12-11 23:19:21 +00:00
|
|
|
/**
|
2015-07-31 12:15:31 +00:00
|
|
|
* @inheritdoc
|
2012-12-11 23:19:21 +00:00
|
|
|
*/
|
2016-06-30 14:01:24 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.getSaveDialogOpeningData = function () {
|
2016-11-30 17:21:38 +00:00
|
|
|
var data = ve.init.mw.DesktopArticleTarget.super.prototype.getSaveDialogOpeningData.apply( this, arguments );
|
2017-03-09 20:23:36 +00:00
|
|
|
data.editSummary = this.editSummaryValue || this.initialEditSummary;
|
2016-11-05 06:16:26 +00:00
|
|
|
return data;
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-10-05 16:31:15 +00:00
|
|
|
* @inheritdoc
|
2012-06-11 06:54:41 +00:00
|
|
|
*/
|
2015-08-05 21:43:23 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.teardownToolbar = function () {
|
2015-02-23 08:44:51 +00:00
|
|
|
var target = this,
|
2019-11-02 05:06:28 +00:00
|
|
|
deferred = ve.createDeferred();
|
2017-10-05 16:31:15 +00:00
|
|
|
|
|
|
|
if ( !this.toolbar ) {
|
|
|
|
return deferred.resolve().promise();
|
|
|
|
}
|
|
|
|
|
2022-01-24 23:35:50 +00:00
|
|
|
this.toolbar.$element
|
|
|
|
.addClass( 've-init-mw-desktopArticleTarget-toolbar-preclose' )
|
|
|
|
.css( 'height', this.toolbar.$bar[ 0 ].offsetHeight );
|
2015-02-23 08:44:51 +00:00
|
|
|
setTimeout( function () {
|
2016-10-25 22:32:40 +00:00
|
|
|
target.toolbar.$element
|
|
|
|
.css( 'height', '0' )
|
2022-01-24 23:35:50 +00:00
|
|
|
.addClass( 've-init-mw-desktopArticleTarget-toolbar-close' );
|
2016-04-14 15:09:51 +00:00
|
|
|
setTimeout( function () {
|
2016-11-11 22:38:19 +00:00
|
|
|
// Parent method
|
|
|
|
ve.init.mw.DesktopArticleTarget.super.prototype.teardownToolbar.call( target );
|
2015-02-23 08:44:51 +00:00
|
|
|
deferred.resolve();
|
2017-10-18 18:17:05 +00:00
|
|
|
}, 250 );
|
2014-12-16 21:14:01 +00:00
|
|
|
} );
|
2015-02-23 08:44:51 +00:00
|
|
|
return deferred.promise();
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
2013-05-17 16:09:20 +00:00
|
|
|
/**
|
|
|
|
* Change the document title to state that we are now editing.
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.changeDocumentTitle = function () {
|
2018-05-04 13:30:10 +00:00
|
|
|
var title = mw.Title.newFromText( this.getPageName() );
|
2023-05-31 22:09:29 +00:00
|
|
|
var pageTitleMsg = mw.message( 'pagetitle',
|
2017-10-05 16:31:15 +00:00
|
|
|
ve.msg(
|
|
|
|
this.pageExists ? 'editing' : 'creating',
|
|
|
|
title.getPrefixedText()
|
|
|
|
)
|
|
|
|
);
|
2023-05-31 22:09:29 +00:00
|
|
|
|
|
|
|
// T317600
|
|
|
|
if ( pageTitleMsg.isParseable() ) {
|
|
|
|
// Use the real title if we loaded a view page, otherwise reconstruct it
|
|
|
|
this.originalDocumentTitle = this.isViewPage ? document.title : ve.msg( 'pagetitle', title.getPrefixedText() );
|
|
|
|
// Reconstruct an edit title
|
|
|
|
document.title = pageTitleMsg.text();
|
|
|
|
} else {
|
|
|
|
mw.log.warn( 'VisualEditor: MediaWiki:Pagetitle contains unsupported syntax. ' +
|
|
|
|
'https://www.mediawiki.org/wiki/Manual:Messages_API#Feature_support_in_JavaScript' );
|
|
|
|
}
|
2013-05-17 16:09:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restore the original document title.
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.restoreDocumentTitle = function () {
|
2023-05-31 22:09:29 +00:00
|
|
|
if ( this.originalDocumentTitle ) {
|
|
|
|
document.title = this.originalDocumentTitle;
|
|
|
|
}
|
2013-05-17 16:09:20 +00:00
|
|
|
};
|
|
|
|
|
2012-06-18 20:12:32 +00:00
|
|
|
/**
|
2013-06-05 21:38:39 +00:00
|
|
|
* Page modifications for switching to edit mode.
|
2021-09-30 11:04:30 +00:00
|
|
|
*
|
|
|
|
* @fires transformPage
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.transformPage = function () {
|
2022-08-10 16:11:16 +00:00
|
|
|
this.updateTabs();
|
2016-04-15 02:05:27 +00:00
|
|
|
this.emit( 'transformPage' );
|
2013-06-05 21:38:39 +00:00
|
|
|
|
2018-11-29 14:38:53 +00:00
|
|
|
// TODO: Deprecate in favour of ve.activationComplete
|
|
|
|
// Only used by one gadget
|
2014-05-14 23:23:07 +00:00
|
|
|
mw.hook( 've.activate' ).fire();
|
2014-05-14 22:19:39 +00:00
|
|
|
|
2015-02-21 10:42:58 +00:00
|
|
|
// Move all native content inside the target
|
2017-09-27 13:50:59 +00:00
|
|
|
// Exclude notification area to work around T143837
|
2022-01-24 23:35:50 +00:00
|
|
|
this.$originalContent.append(
|
|
|
|
this.$element.siblings()
|
|
|
|
.not( '.mw-notification-area' )
|
|
|
|
.not( '.ve-init-mw-desktopArticleTarget-toolbarPlaceholder' )
|
|
|
|
);
|
2018-08-20 17:32:43 +00:00
|
|
|
|
2021-07-09 11:51:09 +00:00
|
|
|
// To preserve event handlers (e.g. HotCat) if editing is cancelled, detach the original container
|
|
|
|
// and replace it with a clone during editing
|
|
|
|
this.$originalCategories = $( '#catlinks' );
|
|
|
|
this.$originalCategories.after( this.$originalCategories.clone() );
|
|
|
|
this.$originalCategories.detach();
|
2015-02-21 10:42:58 +00:00
|
|
|
|
2016-05-09 22:28:24 +00:00
|
|
|
// Mark every non-direct ancestor between editableContent and the container as uneditable
|
2021-10-13 12:57:45 +00:00
|
|
|
var $content = this.$editableContent;
|
2017-01-11 18:10:03 +00:00
|
|
|
while ( $content && $content.length && !$content.parent().is( this.$container ) ) {
|
2017-10-18 22:50:31 +00:00
|
|
|
$content.prevAll( ':not( .ve-init-mw-tempWikitextEditorWidget )' ).addClass( 've-init-mw-desktopArticleTarget-uneditableContent' );
|
|
|
|
$content.nextAll( ':not( .ve-init-mw-tempWikitextEditorWidget )' ).addClass( 've-init-mw-desktopArticleTarget-uneditableContent' );
|
2016-05-09 22:28:24 +00:00
|
|
|
$content = $content.parent();
|
|
|
|
}
|
2016-09-30 19:07:56 +00:00
|
|
|
|
2022-06-13 20:42:11 +00:00
|
|
|
this.restoreEditTabsIfNeeded( $content );
|
2016-12-01 20:06:19 +00:00
|
|
|
this.updateHistoryState();
|
|
|
|
};
|
|
|
|
|
2022-06-13 20:42:11 +00:00
|
|
|
/**
|
|
|
|
* Checks the edit/view tabs have not been marked as disabled. The view tab provides a way
|
|
|
|
* to exit the VisualEditor so its important it is not marked as uneditable.
|
|
|
|
*
|
|
|
|
* @param {jQuery} $content area
|
|
|
|
*/
|
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.restoreEditTabsIfNeeded = function ( $content ) {
|
|
|
|
var $viewTab = $content.find( '.ve-init-mw-desktopArticleTarget-uneditableContent #ca-view' );
|
|
|
|
if ( $viewTab.length ) {
|
|
|
|
$viewTab.parents( '.ve-init-mw-desktopArticleTarget-uneditableContent' ).removeClass( 've-init-mw-desktopArticleTarget-uneditableContent' );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-01 20:06:19 +00:00
|
|
|
/**
|
|
|
|
* Category link section transformations for switching to edit mode. Broken out
|
|
|
|
* so it can be re-applied when displaying changes to the categories.
|
|
|
|
*
|
|
|
|
* @param {jQuery} $catlinks Category links container element
|
|
|
|
*/
|
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.transformCategoryLinks = function ( $catlinks ) {
|
|
|
|
var target = this;
|
2016-09-30 19:07:56 +00:00
|
|
|
// Un-disable the catlinks wrapper, but not the links
|
2017-03-20 11:07:52 +00:00
|
|
|
if ( this.getSurface() && this.getSurface().getMode() === 'visual' ) {
|
|
|
|
$catlinks.removeClass( 've-init-mw-desktopArticleTarget-uneditableContent' )
|
|
|
|
.on( 'click.ve-target', function () {
|
|
|
|
var windowAction = ve.ui.actionFactory.create( 'window', target.getSurface() );
|
|
|
|
windowAction.open( 'meta', { page: 'categories' } );
|
|
|
|
return false;
|
|
|
|
} )
|
|
|
|
.find( 'a' ).addClass( 've-init-mw-desktopArticleTarget-uneditableContent' );
|
|
|
|
} else {
|
2018-02-21 12:23:12 +00:00
|
|
|
$catlinks.addClass( 've-init-mw-desktopArticleTarget-uneditableContent' ).off( 'click.ve-target' );
|
2017-03-20 11:07:52 +00:00
|
|
|
}
|
2016-12-01 20:06:19 +00:00
|
|
|
};
|
2016-09-30 19:07:56 +00:00
|
|
|
|
2016-08-25 21:02:40 +00:00
|
|
|
/**
|
|
|
|
* Update the history state based on the editor mode
|
|
|
|
*/
|
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.updateHistoryState = function () {
|
2021-10-13 12:57:45 +00:00
|
|
|
var veaction = this.getDefaultMode() === 'visual' ? 'edit' : 'editsource',
|
2022-12-17 15:44:56 +00:00
|
|
|
section = this.section;
|
2016-08-25 21:02:40 +00:00
|
|
|
|
2023-06-20 07:13:57 +00:00
|
|
|
// Push veaction=edit(source) url in history (if not already present).
|
|
|
|
// If we got here from DesktopArticleTarget.init, then it will be already present.
|
2015-10-23 16:29:56 +00:00
|
|
|
if (
|
|
|
|
!this.actFromPopState &&
|
2016-12-13 16:42:45 +00:00
|
|
|
(
|
2022-12-17 15:44:56 +00:00
|
|
|
this.currentUrl.searchParams.get( 'veaction' ) !== veaction ||
|
|
|
|
this.currentUrl.searchParams.get( 'section' ) !== section
|
2016-12-13 16:42:45 +00:00
|
|
|
) &&
|
2022-12-17 15:44:56 +00:00
|
|
|
this.currentUrl.searchParams.get( 'action' ) !== 'edit'
|
2015-10-23 16:29:56 +00:00
|
|
|
) {
|
2014-10-21 01:10:41 +00:00
|
|
|
// Set the current URL
|
2022-12-17 15:44:56 +00:00
|
|
|
var url = this.currentUrl;
|
2015-10-23 16:29:56 +00:00
|
|
|
|
2016-12-29 19:38:09 +00:00
|
|
|
if ( mw.libs.ve.isSingleEditTab ) {
|
2022-12-17 15:44:56 +00:00
|
|
|
url.searchParams.set( 'action', 'edit' );
|
2015-10-23 16:29:56 +00:00
|
|
|
mw.config.set( 'wgAction', 'edit' );
|
|
|
|
} else {
|
2022-12-17 15:44:56 +00:00
|
|
|
url.searchParams.set( 'veaction', veaction );
|
|
|
|
url.searchParams.delete( 'action' );
|
2015-10-23 16:29:56 +00:00
|
|
|
mw.config.set( 'wgAction', 'view' );
|
|
|
|
}
|
2016-12-13 15:21:36 +00:00
|
|
|
if ( this.section !== null ) {
|
2022-12-17 15:44:56 +00:00
|
|
|
url.searchParams.set( 'section', this.section );
|
2016-12-13 16:42:45 +00:00
|
|
|
} else {
|
2022-12-17 15:44:56 +00:00
|
|
|
url.searchParams.delete( 'section' );
|
2016-12-13 15:21:36 +00:00
|
|
|
}
|
2013-06-05 22:39:43 +00:00
|
|
|
|
2022-12-17 15:44:56 +00:00
|
|
|
history.pushState( this.popState, '', url );
|
2013-06-05 22:39:43 +00:00
|
|
|
}
|
|
|
|
this.actFromPopState = false;
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-06-05 21:38:39 +00:00
|
|
|
* Page modifications for switching back to view mode.
|
2021-09-30 11:04:30 +00:00
|
|
|
*
|
|
|
|
* @fires restorePage
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.restorePage = function () {
|
2016-07-14 03:16:38 +00:00
|
|
|
// Restore any previous redirectMsg/redirectsub
|
2017-03-28 15:40:23 +00:00
|
|
|
this.setRealRedirectInterface();
|
2016-12-01 20:06:19 +00:00
|
|
|
if ( this.$originalCategories ) {
|
|
|
|
$( '#catlinks' ).replaceWith( this.$originalCategories );
|
|
|
|
}
|
|
|
|
|
2018-11-29 14:38:53 +00:00
|
|
|
// TODO: Deprecate in favour of ve.deactivationComplete
|
2014-05-14 23:23:07 +00:00
|
|
|
mw.hook( 've.deactivate' ).fire();
|
2016-04-15 02:05:27 +00:00
|
|
|
this.emit( 'restorePage' );
|
2014-05-14 22:19:39 +00:00
|
|
|
|
2015-06-15 11:45:26 +00:00
|
|
|
// Push article url into history
|
2022-12-12 19:47:32 +00:00
|
|
|
if ( !this.actFromPopState ) {
|
2015-06-15 11:45:26 +00:00
|
|
|
// Remove the VisualEditor query parameters
|
2022-12-17 15:44:56 +00:00
|
|
|
var url = this.currentUrl;
|
|
|
|
if ( url.searchParams.has( 'veaction' ) ) {
|
|
|
|
url.searchParams.delete( 'veaction' );
|
2013-06-05 22:39:43 +00:00
|
|
|
}
|
2019-02-13 13:21:26 +00:00
|
|
|
if ( this.section !== null ) {
|
2022-12-17 15:44:56 +00:00
|
|
|
// Translate into a hash for the new URL:
|
2017-12-13 17:55:18 +00:00
|
|
|
// This should be after replacePageContent if this is post-save, so we can just look
|
|
|
|
// at the headers on the page.
|
2022-12-17 15:44:56 +00:00
|
|
|
var hash = this.getSectionHashFromPage();
|
|
|
|
if ( hash ) {
|
|
|
|
url.hash = hash;
|
|
|
|
this.viewUrl.hash = hash;
|
|
|
|
var target = document.getElementById( hash.slice( 1 ) );
|
2019-02-13 13:21:26 +00:00
|
|
|
|
|
|
|
if ( target ) {
|
|
|
|
// Scroll the page to the edited section
|
|
|
|
setTimeout( function () {
|
|
|
|
target.scrollIntoView( true );
|
|
|
|
} );
|
|
|
|
}
|
2017-12-13 17:55:18 +00:00
|
|
|
}
|
2022-12-17 15:44:56 +00:00
|
|
|
url.searchParams.delete( 'section' );
|
2014-07-10 12:16:37 +00:00
|
|
|
}
|
2022-12-17 15:44:56 +00:00
|
|
|
if ( url.searchParams.has( 'action' ) && $( '#wpTextbox1:not(.ve-dummyTextbox)' ).length === 0 ) {
|
2018-06-25 16:55:51 +00:00
|
|
|
// If we're not overlaid on an edit page, remove action=edit
|
2022-12-17 15:44:56 +00:00
|
|
|
url.searchParams.delete( 'action' );
|
2015-11-04 01:40:49 +00:00
|
|
|
mw.config.set( 'wgAction', 'view' );
|
2015-10-08 22:16:56 +00:00
|
|
|
}
|
2022-12-17 15:44:56 +00:00
|
|
|
if ( url.searchParams.has( 'oldid' ) && !this.restoring ) {
|
2016-07-26 03:04:47 +00:00
|
|
|
// We have an oldid in the query string but it's the most recent one, so remove it
|
2022-12-17 15:44:56 +00:00
|
|
|
url.searchParams.delete( 'oldid' );
|
2016-07-26 03:04:47 +00:00
|
|
|
}
|
2013-06-05 22:39:43 +00:00
|
|
|
|
2023-05-29 00:12:08 +00:00
|
|
|
// Remove parameters which are only intended for the editor, not for read mode
|
|
|
|
url.searchParams.delete( 'editintro' );
|
|
|
|
url.searchParams.delete( 'preload' );
|
|
|
|
url.searchParams.delete( 'preloadparams[]' );
|
|
|
|
url.searchParams.delete( 'preloadtitle' );
|
|
|
|
url.searchParams.delete( 'summary' );
|
|
|
|
|
2022-12-17 15:44:56 +00:00
|
|
|
// If there are any other query parameters left, re-use that URL object.
|
|
|
|
// Otherwise use the canonical style view URL (T44553, T102363).
|
|
|
|
var keys = [];
|
|
|
|
url.searchParams.forEach( function ( val, key ) {
|
|
|
|
keys.push( key );
|
|
|
|
} );
|
2015-08-19 17:33:02 +00:00
|
|
|
if ( !keys.length || ( keys.length === 1 && keys[ 0 ] === 'title' ) ) {
|
2022-12-17 15:44:56 +00:00
|
|
|
history.pushState( this.popState, '', this.viewUrl );
|
2015-06-15 11:45:26 +00:00
|
|
|
} else {
|
2022-12-17 15:44:56 +00:00
|
|
|
history.pushState( this.popState, '', url );
|
2013-06-05 22:39:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Event} e Native event object
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.onWindowPopState = function ( e ) {
|
2021-10-13 12:57:45 +00:00
|
|
|
var target = this;
|
2014-03-12 21:26:52 +00:00
|
|
|
|
|
|
|
if ( !this.verifyPopState( e.state ) ) {
|
|
|
|
// Ignore popstate events fired for states not created by us
|
2018-08-09 14:10:53 +00:00
|
|
|
// This also filters out the initial fire in Chrome (T59901).
|
2014-03-12 21:26:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-17 15:44:56 +00:00
|
|
|
var oldUrl = this.currentUrl;
|
2020-09-21 15:21:58 +00:00
|
|
|
|
2022-12-17 15:44:56 +00:00
|
|
|
this.currentUrl = new URL( location.href );
|
|
|
|
var veaction = this.currentUrl.searchParams.get( 'veaction' );
|
|
|
|
var action = this.currentUrl.searchParams.get( 'action' );
|
2022-09-01 13:52:43 +00:00
|
|
|
|
|
|
|
if ( !veaction && action === 'edit' ) {
|
|
|
|
veaction = this.getDefaultMode() === 'source' ? 'editsource' : 'edit';
|
|
|
|
}
|
2014-03-12 21:26:52 +00:00
|
|
|
|
2019-07-22 19:41:36 +00:00
|
|
|
if ( this.isModeAvailable( 'source' ) && this.active ) {
|
2016-11-30 12:03:56 +00:00
|
|
|
if ( veaction === 'editsource' && this.getDefaultMode() === 'visual' ) {
|
2016-11-14 16:07:13 +00:00
|
|
|
this.actFromPopState = true;
|
|
|
|
this.switchToWikitextEditor();
|
2016-11-30 12:03:56 +00:00
|
|
|
} else if ( veaction === 'edit' && this.getDefaultMode() === 'source' ) {
|
2016-11-14 16:07:13 +00:00
|
|
|
this.actFromPopState = true;
|
|
|
|
this.switchToVisualEditor();
|
|
|
|
}
|
|
|
|
}
|
2016-08-25 21:02:40 +00:00
|
|
|
if ( !this.active && ( veaction === 'edit' || veaction === 'editsource' ) ) {
|
2013-06-05 22:39:43 +00:00
|
|
|
this.actFromPopState = true;
|
2022-02-16 15:03:38 +00:00
|
|
|
this.emit( 'reactivate' );
|
2013-06-05 22:39:43 +00:00
|
|
|
}
|
2016-08-25 21:02:40 +00:00
|
|
|
if ( this.active && veaction !== 'edit' && veaction !== 'editsource' ) {
|
2013-06-05 22:39:43 +00:00
|
|
|
this.actFromPopState = true;
|
2020-09-21 15:21:58 +00:00
|
|
|
// "Undo" the pop-state, as the event is not cancellable
|
2022-12-17 15:44:56 +00:00
|
|
|
history.pushState( this.popState, '', oldUrl );
|
|
|
|
this.currentUrl = oldUrl;
|
2020-09-21 15:21:58 +00:00
|
|
|
this.tryTeardown( false, 'navigate-back' ).then( function () {
|
|
|
|
// Teardown was successful, re-apply the undone state
|
|
|
|
history.back();
|
|
|
|
} ).always( function () {
|
|
|
|
target.actFromPopState = false;
|
|
|
|
} );
|
2013-06-05 22:39:43 +00:00
|
|
|
}
|
2012-06-21 19:44:33 +00:00
|
|
|
};
|
|
|
|
|
2012-06-18 20:12:32 +00:00
|
|
|
/**
|
2022-02-17 22:06:14 +00:00
|
|
|
* @inheritdoc
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.replacePageContent = function (
|
2022-08-24 12:28:07 +00:00
|
|
|
html, categoriesHtml, displayTitle, lastModified /* , contentSub, sections */
|
2014-10-31 00:26:32 +00:00
|
|
|
) {
|
2022-08-24 12:28:07 +00:00
|
|
|
// Parent method
|
|
|
|
ve.init.mw.DesktopArticleTarget.super.prototype.replacePageContent.apply( this, arguments );
|
|
|
|
|
2014-11-17 01:00:06 +00:00
|
|
|
if ( lastModified ) {
|
2014-11-17 01:16:29 +00:00
|
|
|
// If we were not viewing the most recent revision before (a requirement
|
|
|
|
// for lastmod to have been added by MediaWiki), we will be now.
|
|
|
|
if ( !$( '#footer-info-lastmod' ).length ) {
|
|
|
|
$( '#footer-info' ).prepend(
|
|
|
|
$( '<li>' ).attr( 'id', 'footer-info-lastmod' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-20 02:13:29 +00:00
|
|
|
// Intentionally treated as HTML
|
2021-11-15 17:03:35 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-html
|
2014-11-18 23:35:52 +00:00
|
|
|
$( '#footer-info-lastmod' ).html( ' ' + mw.msg(
|
2014-11-17 01:00:06 +00:00
|
|
|
'lastmodifiedat',
|
|
|
|
lastModified.date,
|
|
|
|
lastModified.time
|
|
|
|
) );
|
|
|
|
}
|
2016-02-25 23:27:54 +00:00
|
|
|
|
2016-12-07 00:19:21 +00:00
|
|
|
this.$originalCategories = null;
|
|
|
|
|
2017-10-16 17:02:00 +00:00
|
|
|
// Re-set any edit section handlers now that the page content has been replaced
|
|
|
|
mw.libs.ve.setupEditLinks();
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
2012-06-21 03:16:10 +00:00
|
|
|
/**
|
2015-08-05 21:43:23 +00:00
|
|
|
* Add onunload and onbeforeunload handlers.
|
2012-06-21 03:16:10 +00:00
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.setupUnloadHandlers = function () {
|
2017-03-08 17:32:03 +00:00
|
|
|
if ( window.onbeforeunload !== this.onBeforeUnload ) {
|
|
|
|
// Remember any already set beforeunload handler
|
|
|
|
this.onBeforeUnloadFallback = window.onbeforeunload;
|
|
|
|
// Attach our handlers
|
|
|
|
window.onbeforeunload = this.onBeforeUnload;
|
|
|
|
window.addEventListener( 'unload', this.onUnloadHandler );
|
|
|
|
}
|
2012-06-21 03:16:10 +00:00
|
|
|
};
|
|
|
|
/**
|
2015-02-12 02:35:52 +00:00
|
|
|
* Remove onunload and onbeforunload handlers.
|
2012-06-21 03:16:10 +00:00
|
|
|
*/
|
2015-08-05 21:43:23 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.teardownUnloadHandlers = function () {
|
2014-12-02 23:21:50 +00:00
|
|
|
// Restore whatever previous onbeforeunload hook existed
|
2012-06-21 03:16:10 +00:00
|
|
|
window.onbeforeunload = this.onBeforeUnloadFallback;
|
2014-12-02 23:21:50 +00:00
|
|
|
this.onBeforeUnloadFallback = null;
|
|
|
|
window.removeEventListener( 'unload', this.onUnloadHandler );
|
2012-06-21 03:16:10 +00:00
|
|
|
};
|
|
|
|
|
2020-04-17 21:19:55 +00:00
|
|
|
/**
|
|
|
|
* Show the beta dialog as needed
|
|
|
|
*/
|
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.maybeShowWelcomeDialog = function () {
|
|
|
|
var editorMode = this.getDefaultMode(),
|
|
|
|
windowManager = this.getSurface().dialogs,
|
|
|
|
target = this;
|
|
|
|
|
|
|
|
this.welcomeDialogPromise = ve.createDeferred();
|
|
|
|
|
2020-04-17 21:25:58 +00:00
|
|
|
if ( mw.libs.ve.shouldShowWelcomeDialog() ) {
|
2020-04-17 21:19:55 +00:00
|
|
|
this.welcomeDialog = new mw.libs.ve.WelcomeDialog();
|
|
|
|
windowManager.addWindows( [ this.welcomeDialog ] );
|
|
|
|
windowManager.openWindow(
|
|
|
|
this.welcomeDialog,
|
|
|
|
{
|
|
|
|
switchable: editorMode === 'source' ? this.isModeAvailable( 'visual' ) : true,
|
|
|
|
editor: editorMode
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.closed.then( function ( data ) {
|
|
|
|
target.welcomeDialogPromise.resolve();
|
|
|
|
target.welcomeDialog = null;
|
|
|
|
if ( data && data.action === 'switch-wte' ) {
|
|
|
|
target.switchToWikitextEditor( false );
|
|
|
|
} else if ( data && data.action === 'switch-ve' ) {
|
|
|
|
target.switchToVisualEditor();
|
|
|
|
}
|
|
|
|
} );
|
2020-04-17 21:25:58 +00:00
|
|
|
mw.libs.ve.stopShowingWelcomeDialog();
|
2020-04-17 21:19:55 +00:00
|
|
|
} else {
|
|
|
|
this.welcomeDialogPromise.reject();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-25 21:52:06 +00:00
|
|
|
/**
|
|
|
|
* Show the meta dialog as needed on load.
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.maybeShowMetaDialog = function () {
|
2021-10-13 12:57:45 +00:00
|
|
|
var target = this;
|
2015-03-25 21:52:06 +00:00
|
|
|
|
2016-03-09 21:02:18 +00:00
|
|
|
if ( this.welcomeDialogPromise ) {
|
2017-04-20 17:47:51 +00:00
|
|
|
// Pop out the notices when the welcome dialog is closed
|
2016-03-09 21:02:18 +00:00
|
|
|
this.welcomeDialogPromise
|
|
|
|
.always( function () {
|
2016-04-04 16:31:39 +00:00
|
|
|
if (
|
|
|
|
target.switched &&
|
|
|
|
!mw.user.options.get( 'visualeditor-hidevisualswitchpopup' )
|
|
|
|
) {
|
2017-04-20 17:47:51 +00:00
|
|
|
// Show "switched" popup
|
2021-10-13 12:57:45 +00:00
|
|
|
var popup = new mw.libs.ve.SwitchPopupWidget( 'visual' );
|
2023-04-27 13:51:35 +00:00
|
|
|
target.toolbar.tools.editModeSource.toolGroup.$element.append( popup.$element );
|
2017-02-24 14:29:21 +00:00
|
|
|
popup.toggle( true );
|
2023-04-27 13:51:35 +00:00
|
|
|
} else if ( target.toolbar.tools.notices ) {
|
2017-04-20 17:47:51 +00:00
|
|
|
// Show notices
|
2023-04-27 13:51:35 +00:00
|
|
|
target.toolbar.tools.notices.getPopup().toggle( true );
|
2016-04-04 16:31:39 +00:00
|
|
|
}
|
2016-03-09 21:02:18 +00:00
|
|
|
} );
|
|
|
|
}
|
2013-11-13 20:15:44 +00:00
|
|
|
|
2022-01-19 14:25:39 +00:00
|
|
|
var redirectMetaItems = this.getSurface().getModel().getDocument().getMetaList().getItemsInGroup( 'mwRedirect' );
|
2016-02-25 23:27:54 +00:00
|
|
|
if ( redirectMetaItems.length ) {
|
2021-10-13 12:57:45 +00:00
|
|
|
var windowAction = ve.ui.actionFactory.create( 'window', this.getSurface() );
|
2016-02-19 17:35:11 +00:00
|
|
|
windowAction.open( 'meta', { page: 'settings' } );
|
2013-11-13 20:15:44 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-06-21 03:16:10 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Handle before unload event.
|
2012-06-21 03:16:10 +00:00
|
|
|
*
|
2019-04-16 15:17:29 +00:00
|
|
|
* @return {string} Message
|
2012-06-21 03:16:10 +00:00
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.onBeforeUnload = function () {
|
2012-06-21 03:16:10 +00:00
|
|
|
// Check if someone already set on onbeforeunload hook
|
|
|
|
if ( this.onBeforeUnloadFallback ) {
|
|
|
|
// Get the result of their onbeforeunload hook
|
2021-10-13 12:57:45 +00:00
|
|
|
var fallbackResult = this.onBeforeUnloadFallback();
|
2014-12-02 23:21:50 +00:00
|
|
|
// If it returned something, exit here and return their message
|
|
|
|
if ( fallbackResult !== undefined ) {
|
|
|
|
return fallbackResult;
|
2012-06-21 03:16:10 +00:00
|
|
|
}
|
|
|
|
}
|
2014-12-02 23:21:50 +00:00
|
|
|
// Check if there's been an edit
|
2016-08-17 05:41:54 +00:00
|
|
|
if (
|
|
|
|
this.getSurface() &&
|
|
|
|
$.contains( document, this.getSurface().$element.get( 0 ) ) &&
|
|
|
|
this.edited &&
|
|
|
|
!this.submitting &&
|
|
|
|
mw.user.options.get( 'useeditwarning' )
|
|
|
|
) {
|
2014-12-02 23:21:50 +00:00
|
|
|
// Return our message
|
2019-05-06 19:57:51 +00:00
|
|
|
return ve.msg( 'mw-widgets-abandonedit' );
|
2012-06-21 03:16:10 +00:00
|
|
|
}
|
|
|
|
};
|
2014-07-07 19:51:41 +00:00
|
|
|
|
2015-02-12 02:35:52 +00:00
|
|
|
/**
|
|
|
|
* Handle unload event.
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.onUnload = function () {
|
2014-12-02 23:21:50 +00:00
|
|
|
if ( !this.submitting ) {
|
2023-03-18 02:34:32 +00:00
|
|
|
ve.track( 'editAttemptStep', {
|
|
|
|
action: 'abort',
|
2015-02-12 02:35:52 +00:00
|
|
|
type: this.edited ? 'unknown-edited' : 'unknown',
|
2017-12-07 11:14:00 +00:00
|
|
|
mechanism: 'navigate',
|
|
|
|
mode: this.surface ? this.surface.getMode() : this.getDefaultMode()
|
2015-02-12 02:35:52 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-06-27 21:44:20 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.switchToVisualEditor = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.init.mw.DesktopArticleTarget.super.prototype.switchToVisualEditor.apply( this, arguments );
|
|
|
|
|
2019-07-22 19:41:36 +00:00
|
|
|
if ( this.isModeAvailable( 'visual' ) ) {
|
2019-06-27 21:44:20 +00:00
|
|
|
ve.track( 'activity.editor-switch', { action: 'visual-desktop' } );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.switchToWikitextEditor = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.init.mw.DesktopArticleTarget.super.prototype.switchToWikitextEditor.apply( this, arguments );
|
|
|
|
|
2019-07-22 19:41:36 +00:00
|
|
|
if ( this.isModeAvailable( 'source' ) ) {
|
2019-06-27 21:44:20 +00:00
|
|
|
ve.track( 'activity.editor-switch', { action: 'source-nwe-desktop' } );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.switchToWikitextSection = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.init.mw.DesktopArticleTarget.super.prototype.switchToWikitextSection.apply( this, arguments );
|
|
|
|
|
|
|
|
ve.track( 'activity.editor-switch', { action: 'source-nwe-desktop' } );
|
|
|
|
};
|
|
|
|
|
2014-07-07 19:51:41 +00:00
|
|
|
/**
|
2017-01-19 22:09:20 +00:00
|
|
|
* @inheritdoc
|
2014-07-07 19:51:41 +00:00
|
|
|
*/
|
2019-04-15 22:39:04 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.switchToFallbackWikitextEditor = function ( modified ) {
|
2021-10-13 12:57:45 +00:00
|
|
|
var target = this;
|
|
|
|
var oldId = mw.config.get( 'wgRevisionId' ) || $( 'input[name=parentRevId]' ).val();
|
|
|
|
var prefPromise = mw.libs.ve.setEditorPreference( 'wikitext' );
|
2016-12-15 01:34:30 +00:00
|
|
|
|
2019-04-15 22:39:04 +00:00
|
|
|
if ( !modified ) {
|
2019-06-27 21:44:20 +00:00
|
|
|
ve.track( 'activity.editor-switch', { action: 'source-desktop' } );
|
2023-03-18 02:34:32 +00:00
|
|
|
ve.track( 'editAttemptStep', {
|
|
|
|
action: 'abort',
|
|
|
|
type: 'switchnochange',
|
|
|
|
mechanism: 'navigate',
|
|
|
|
mode: 'visual'
|
|
|
|
} );
|
2017-01-19 22:09:20 +00:00
|
|
|
this.submitting = true;
|
2022-04-26 15:31:12 +00:00
|
|
|
return prefPromise.then( function () {
|
2022-12-17 15:44:56 +00:00
|
|
|
var url = new URL( target.viewUrl );
|
|
|
|
url.searchParams.set( 'action', 'edit' );
|
|
|
|
// No changes, safe to stay in section mode
|
|
|
|
if ( target.section !== null ) {
|
|
|
|
url.searchParams.set( 'section', target.section );
|
|
|
|
} else {
|
|
|
|
url.searchParams.delete( 'section' );
|
|
|
|
}
|
|
|
|
url.searchParams.set( 'veswitched', '1' );
|
2019-05-22 13:32:54 +00:00
|
|
|
if ( oldId && oldId !== mw.config.get( 'wgCurRevisionId' ) ) {
|
2022-12-17 15:44:56 +00:00
|
|
|
url.searchParams.set( 'oldid', oldId );
|
2017-01-19 22:09:20 +00:00
|
|
|
}
|
2021-01-05 02:07:33 +00:00
|
|
|
if ( mw.libs.ve.isWelcomeDialogSuppressed() ) {
|
2022-12-17 15:44:56 +00:00
|
|
|
url.searchParams.set( 'vehidebetadialog', '1' );
|
2021-01-05 02:07:33 +00:00
|
|
|
}
|
2022-12-17 15:44:56 +00:00
|
|
|
location.href = url.toString();
|
2017-01-19 22:09:20 +00:00
|
|
|
} );
|
2014-07-07 19:51:41 +00:00
|
|
|
} else {
|
2022-04-26 15:31:12 +00:00
|
|
|
return this.serialize( this.getDocToSave() ).then( function ( data ) {
|
2019-11-04 14:54:53 +00:00
|
|
|
ve.track( 'activity.editor-switch', { action: 'source-desktop' } );
|
2023-03-18 02:34:32 +00:00
|
|
|
ve.track( 'editAttemptStep', {
|
|
|
|
action: 'abort',
|
|
|
|
type: 'switchwith',
|
|
|
|
mechanism: 'navigate',
|
|
|
|
mode: 'visual'
|
|
|
|
} );
|
2019-11-04 14:54:53 +00:00
|
|
|
target.submitWithSaveFields( { wpDiff: true, wpAutoSummary: '' }, data.content );
|
|
|
|
} );
|
2014-07-07 19:51:41 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-13 16:42:45 +00:00
|
|
|
/**
|
2017-01-19 22:09:20 +00:00
|
|
|
* @inheritdoc
|
2016-11-14 16:07:13 +00:00
|
|
|
*/
|
2017-01-19 22:09:20 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.reloadSurface = function () {
|
2016-11-14 16:07:13 +00:00
|
|
|
var target = this;
|
2016-12-04 15:51:57 +00:00
|
|
|
|
2016-11-14 16:07:13 +00:00
|
|
|
this.activating = true;
|
2019-11-02 05:06:28 +00:00
|
|
|
this.activatingDeferred = ve.createDeferred();
|
2017-01-19 22:09:20 +00:00
|
|
|
|
|
|
|
// Parent method
|
|
|
|
ve.init.mw.DesktopArticleTarget.super.prototype.reloadSurface.apply( this, arguments );
|
|
|
|
|
2016-11-14 16:07:13 +00:00
|
|
|
this.activatingDeferred.done( function () {
|
|
|
|
target.updateHistoryState();
|
|
|
|
target.afterActivate();
|
|
|
|
target.setupTriggerListeners();
|
|
|
|
} );
|
|
|
|
this.toolbarSetupDeferred.resolve();
|
|
|
|
};
|
|
|
|
|
2016-04-21 11:28:00 +00:00
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.init.mw.targetFactory.register( ve.init.mw.DesktopArticleTarget );
|