jenkins-bot has submitted this change and it was merged.
Change subject: Update watchlist link/star when doing Wikibase edits
......................................................................
Update watchlist link/star when doing Wikibase edits
Use the watch.ajax module to update the watchlist link
(a star in the Vector skin) whenever something was edited.
I tried to avoid useless AJAX calls as good as I could.
Note that the stopItemPageEditMode event I used is described
as "to be removed or marked deprecated" in wikibase.js.
I had to use it since I did not found an other solution that
supports both implementations of edit widgets.
This patch set also includes a new implementation for the
label editor. It uses the translation now (instead of a hard
coded ' - ') and updates live while typing.
Bug: 58534
Change-Id: I8bed80355706455d779a7235f998ff6ce75c06b9
---
M lib/resources/jquery.wikibase/jquery.wikibase.entityview.js
M lib/resources/wikibase.js
M lib/resources/wikibase.ui.PropertyEditTool.EditableValue.js
M lib/resources/wikibase.ui.PropertyEditTool.js
M repo/resources/Resources.php
M repo/resources/wikibase.ui.entityViewInit.js
M repo/resources/wikibase.ui.initTermBox.js
7 files changed, 110 insertions(+), 49 deletions(-)
Approvals:
Tobias Gritschacher: Looks good to me, approved
WikidataJenkins: Verified
jenkins-bot: Verified
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.entityview.js
b/lib/resources/jquery.wikibase/jquery.wikibase.entityview.js
index be8c318..a8b6201 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.entityview.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.entityview.js
@@ -96,7 +96,7 @@
// between toolbars should be managed via
the toolbar controller.
var originToolbars = null;
if ( options ) {
- if ( typeof options.exclusive ===
'boolean' && !options.exclusive ) {
+ if ( options.exclusive === false ) {
originToolbars = findToolbars(
$( origin ) );
} else if ( typeof options.exclusive
=== 'string' ) {
originToolbars = $( origin
).find( options.exclusive );
@@ -142,21 +142,32 @@
] );
} )
.on( 'referenceviewafterstartediting', function( event ) {
- $( wb ).trigger(
- 'startItemPageEditMode',
- [ event.target, { exclusive: false,
wbCopyrightWarningGravity: 'sw' } ]
- );
+ $( wb ).trigger( 'startItemPageEditMode', [
+ event.target,
+ {
+ exclusive: false,
+ wbCopyrightWarningGravity: 'sw'
+ }
+ ] );
} )
.on( 'snakviewstopediting', function( event, dropValue ) {
// snak view got already removed from the DOM on
"snakviewafterstopediting"
if ( dropValue ) {
- $( wb ).trigger( 'stopItemPageEditMode',
[event.target] );
+ // Return true on dropValue === false as well
as dropValue === undefined
+ $( wb ).trigger( 'stopItemPageEditMode', [
+ event.target,
+ { save: dropValue !== true }
+ ] );
}
} )
.on( 'statementviewafterstopediting claimlistviewafterremove '
+ 'referenceviewafterstopediting
statementviewafterremove',
- function( event ) {
- $( wb ).trigger( 'stopItemPageEditMode',
[event.target] );
+ function( event, dropValue ) {
+ // Return true on dropValue === false as well
as dropValue === undefined
+ $( wb ).trigger( 'stopItemPageEditMode', [
+ event.target,
+ { save: dropValue !== true }
+ ] );
}
);
}
diff --git a/lib/resources/wikibase.js b/lib/resources/wikibase.js
index 2a9db29..aca13a4 100644
--- a/lib/resources/wikibase.js
+++ b/lib/resources/wikibase.js
@@ -16,33 +16,38 @@
* bubble through the DOM anyhow, so everyone can listen to those on any
level of a pages DOM.
*
* @event startItemPageEditMode: Triggered when any edit mode on the item page
is started
- * (1) {jQuery.Event}
+ * (1) {jQuery.Event} event
* (2) {wb.ui.PropertyEditTool.EditableValue|jQuery} origin Object
which triggered the event.
* If the origin of the event is one of the new (jQuery.wikibase)
widgets, then this will
* be the widget's DOM node.
+ * (3) {Object} options An object with any of the following properties:
+ * {boolean|string} exclusive Whether action shall influence
sub-toolbars of origin.
+ * {string} wbCopyrightWarningGravity Direction, defaults to "nw".
*
* @event newItemCreated: Triggered after an item has been created and the
necessary API request has
* returned.
- * (1) {jQuery.Event}
+ * (1) {jQuery.Event} event
* (2) {Object} item The new item returned by the API request. | FIXME:
this should be an
* 'Item' object!
*
* @event stopItemPageEditMode: Triggered when any edit mode on the item page
is stopped.
- * (1) {jQuery.Event}
+ * (1) {jQuery.Event} event
* (2) {wb.ui.PropertyEditTool.EditableValue|jQuery} origin Object
which triggered the event.
* If the origin of the event is one of the new (jQuery.wikibase)
widgets, then this will
* be the widget's DOM node.
- * (3) {Boolean} wasPending Whether value was a previously not
existent/new value that has
- * just been added
+ * (3) {Object} options An object with any of the following properties:
+ * {boolean} save Whether the change got saved or canceled and
dropped. Defaults to true.
+ * {boolean} wasPending Whether value was a previously not
existent/new value that has
+ * just been added. Defaults to false.
*
* @event restrictEntityPageActions: Triggered when editing is not allowed for
the user.
* (see TODO/FIXME in wikibase.ui.entityViewInit - handle edit
restrictions)
- * (1) {jQuery.Event}
+ * (1) {jQuery.Event} event
*
* @event blockEntityPageActions: Triggered when editing is not allowed for
the user because he is
* blocked from the page.
* (see TODO/FIXME in wikibase.ui.entityViewInit - handle edit
restrictions)
- * (1) {jQuery.Event}
+ * (1) {jQuery.Event} event
*/
this.wikibase = this.wb = new ( function Wb( mw, $ ) {
'use strict';
diff --git a/lib/resources/wikibase.ui.PropertyEditTool.EditableValue.js
b/lib/resources/wikibase.ui.PropertyEditTool.EditableValue.js
index d66981f..ae621bf 100644
--- a/lib/resources/wikibase.ui.PropertyEditTool.EditableValue.js
+++ b/lib/resources/wikibase.ui.PropertyEditTool.EditableValue.js
@@ -242,7 +242,7 @@
$( this._toolbar.$editGroup )
.on( 'toolbareditgroupedit', function( event, callback ) {
// The default event would trigger toolbar edit mode as
well, but startEditing()
- // requires that the mode has been changed already in
order to detect wheter to trigger
+ // requires that the mode has been changed already in
order to detect whether to trigger
// a startItemPageEditMode event. This refers to
initially having one or more empty
// values whose edit modes are started instantly when
loading the page.
// (see this.startEditing())
@@ -340,7 +340,9 @@
var degrade = $.proxy( function() {
if( !this.preserveEmptyForm ) {
- $( wb ).triggerHandler( 'stopItemPageEditMode',
[ this, this.isPending() ] );
+ $( wb ).triggerHandler( 'stopItemPageEditMode',
[ this,
+ { wasPending: this.isPending() }
+ ] );
// remove value totally
this.destroy();
this._subject.empty().remove();
@@ -441,7 +443,7 @@
* are started instantly when loading the page
*/
if ( !this._toolbar.isDisabled() ) {
- $( wb ).triggerHandler( 'startItemPageEditMode', this );
+ $( wb ).triggerHandler( 'startItemPageEditMode', [ this
] );
}
return promise;
@@ -470,7 +472,9 @@
promise = this.remove(); // not yet existing
value, no state to go back to -> do not trigger 'afterStopEditing' here!
} else { // cancel...
this._resetToolbar( promise.promisor.apiAction
);
- $( wb ).triggerHandler( 'stopItemPageEditMode',
[ this, this.isPending() ] );
+ $( wb ).triggerHandler( 'stopItemPageEditMode',
[ this,
+ { save: save, wasPending:
this.isPending() }
+ ] );
return promise;
}
} else {
@@ -493,7 +497,9 @@
this._resetToolbar(
promise.promisor.apiAction );
}
- $( wb ).triggerHandler( 'stopItemPageEditMode',
[ this, wasPending ] );
+ $( wb ).triggerHandler( 'stopItemPageEditMode',
[ this,
+ { wasPending: wasPending }
+ ] );
}, this )
);
@@ -632,7 +638,9 @@
* re-enable all actions when removing fails
since it is just using edit mode for
* disabling all actions while the remove
action is being processed
*/
- $( wb ).triggerHandler( 'stopItemPageEditMode',
[ self, self.isPending() ] );
+ $( wb ).triggerHandler( 'stopItemPageEditMode',
[ self,
+ { save: false, wasPending:
self.isPending() }
+ ] );
}
var editGroup = self._toolbar.$editGroup.data(
'toolbareditgroup' ),
@@ -949,12 +957,12 @@
*/
if ( disableSave && disableCancel && this.preserveEmptyForm ) {
if ( this._propagateInterfaceEvents || this.isNew() ) {
- $( wb ).triggerHandler( 'stopItemPageEditMode',
[ this, false ] );
+ $( wb ).triggerHandler( 'stopItemPageEditMode',
[ this, { wasPending: false } ] );
}
this._propagateInterfaceEvents = true;
} else if ( this.isNew() ) {
if ( this._propagateInterfaceEvents ) {
- $( wb ).triggerHandler(
'startItemPageEditMode', this );
+ $( wb ).triggerHandler(
'startItemPageEditMode', [ this ] );
this._propagateInterfaceEvents = false;
}
}
diff --git a/lib/resources/wikibase.ui.PropertyEditTool.js
b/lib/resources/wikibase.ui.PropertyEditTool.js
index 8df9117..03a23b2 100644
--- a/lib/resources/wikibase.ui.PropertyEditTool.js
+++ b/lib/resources/wikibase.ui.PropertyEditTool.js
@@ -108,9 +108,11 @@
}
)
// re-enabling all actions then stopping an edit mode
- .on( 'stopItemPageEditMode', function( event, origin ) {
- self.enable();
- } )
+ .on( 'stopItemPageEditMode',
+ function( event, origin ) {
+ self.enable();
+ }
+ )
/**
* highlight whole PropertyEditTool context if there may no
additionally EditableValues be
* added (in that case, PropertyEditTool is a container for a
fixed set of EditableValues
@@ -124,12 +126,11 @@
}
)
.on( 'stopItemPageEditMode',
- function( event, origin, wasPending ) {
+ function( event, origin, options ) {
subject.removeClass( self.UI_CLASS +
'-ineditmode wb-edit' );
if(
self.getOption( 'allowsMultipleValues' )
- && wasPending !== undefined
- && wasPending
+ && options && options.wasPending
&& self.hasValue( origin )
) {
// Focus "add" button after adding a
value to a multi-value property to
diff --git a/repo/resources/Resources.php b/repo/resources/Resources.php
index 2c50082..d67d170 100644
--- a/repo/resources/Resources.php
+++ b/repo/resources/Resources.php
@@ -37,6 +37,7 @@
'wikibase.ui.scrapeFormattedValues',
),
'messages' => array(
+ 'pagetitle',
'wikibase-statements',
'wikibase-copyrighttooltip-acknowledge',
'wikibase-anonymouseditwarning',
diff --git a/repo/resources/wikibase.ui.entityViewInit.js
b/repo/resources/wikibase.ui.entityViewInit.js
index 5133e09..615f80e 100644
--- a/repo/resources/wikibase.ui.entityViewInit.js
+++ b/repo/resources/wikibase.ui.entityViewInit.js
@@ -34,22 +34,23 @@
// add an edit tool for the main label. This will be integrated
into the heading nicely:
if ( $( '.wb-firstHeading' ).length ) { // Special pages do not
have a custom wb heading
var labelEditTool = new wb.ui.LabelEditTool( $(
'.wb-firstHeading' )[0] ),
- editableLabel = labelEditTool.getValues( true
)[0]; // [0] will always be set
+ editableLabel = labelEditTool.getValues( true
)[0], // [0] will always be set
+ fn = function( event, origin ) {
+ // Limit the global
stopItemPageEditMode event to that element
+ if ( event.type !==
'stopItemPageEditMode' || origin === editableLabel ) {
+ var title =
editableLabel.isEmpty()
+ ? mw.config.get(
'wgTitle' )
+ :
editableLabel.getValue()[0];
- // make sure we update the 'title' tag of the page when
label changes
- editableLabel.on( 'afterStopEditing', function() {
- var value;
+ // update 'title' tag
+ $( 'title' ).text( mw.msg(
'pagetitle', title ) );
+ }
+ };
- if( editableLabel.isEmpty() ) {
- value = mw.config.get( 'wgTitle' );
- } else {
- value = editableLabel.getValue()[0];
- }
- value += ' - ' + mw.config.get( 'wgSiteName' );
-
- // update 'title' tag
- $( 'html title' ).text( value );
- } );
+ editableLabel.getSubject().on( 'eachchange', fn );
+ // Can't use afterStopEditing because it does not fire
on cancel
+ // but this is needed to reset the title
+ $( wb ).on( 'stopItemPageEditMode', fn );
}
// add an edit tool for all properties in the data view:
@@ -233,9 +234,7 @@
text: mw.msg(
'wikibase-copyrighttooltip-acknowledge' )
} ).appendTo( $message );
- var gravity = ( options &&
options.wbCopyrightWarningGravity )
- ? options.wbCopyrightWarningGravity
- : 'nw';
+ var gravity = ( options &&
options.wbCopyrightWarningGravity ) || 'nw';
// Tooltip gets its own anchor since other
elements might have their own tooltip.
// we don't even have to add this new toolbar
element to the toolbar, we only use it
@@ -277,7 +276,7 @@
$messageAnchor.data( 'wbtooltip' ).show();
// destroy tooltip after edit mode gets closed
again:
- $( wb ).one( 'stopItemPageEditMode', function(
event ) {
+ $( wb ).one( 'stopItemPageEditMode', function(
event, origin ) {
if( $messageAnchor.data( 'wbtooltip' )
!== undefined ) {
$messageAnchor.data(
'wbtooltip' ).degrade( true );
}
@@ -285,6 +284,42 @@
}
} );
+ // Check if the watch link (star in the Vector skin) needs to
be updated after an edit
+ $( wb ).on( 'stopItemPageEditMode', function( event, origin,
options ) {
+ // If save is undefined it should default to true
+ var canceled = options && options.save === false;
+ var updateWatchLink = mw.page && mw.page.watch ?
mw.page.watch.updateWatchLink : null;
+
+ // Skip if module isn't loaded or user doesn't have
"watch by default" enabled anyway
+ if ( canceled || !updateWatchLink ||
!mw.user.options.get( 'watchdefault' ) ) {
+ return;
+ }
+
+ // All four supported skins are using the same ID, the
other selectors
+ // in mediawiki.page.watch.ajax.js are undocumented and
probably legacy stuff
+ var $link = $( '#ca-watch a' );
+
+ // Skip if page is already watched and there is no
"watch this page" link
+ // Note: The exposed function fails for empty jQuery
collections
+ if ( $link.length ) {
+ updateWatchLink( $link, 'watch', 'loading' );
+ var api = new mw.Api();
+ var pageid = mw.config.get( 'wgArticleId' );
+ api.get( {
+ 'action': 'query',
+ 'prop': 'info',
+ 'inprop': 'watched',
+ 'pageids': pageid
+ } ).done( function( data ) {
+ var watched = data.query &&
data.query.pages[pageid] &&
+
data.query.pages[pageid].watched !== undefined;
+ updateWatchLink( $link, watched ?
'unwatch' : 'watch' );
+ } ).fail( function() {
+ updateWatchLink( $link, 'watch' );
+ } );
+ }
+ } );
+
// remove loading spinner after JavaScript has kicked in
$( '.wb-entity' ).fadeTo( 0, 1 );
$( '.wb-entity-spinner' ).remove();
diff --git a/repo/resources/wikibase.ui.initTermBox.js
b/repo/resources/wikibase.ui.initTermBox.js
index 79ced99..70b86f7 100644
--- a/repo/resources/wikibase.ui.initTermBox.js
+++ b/repo/resources/wikibase.ui.initTermBox.js
@@ -50,7 +50,7 @@
} );
$( wb )
- .on( 'startItemPageEditMode', function( event, origin, options
) {
+ .on( 'startItemPageEditMode', function( event, origin ) {
// disable language terms table's editable value or
mark it as the active one if it is
// the one being edited by the user and therefore the
origin of the event
$.each( termsValueTools, function( i, termValueTool ) {
@@ -64,7 +64,7 @@
}
} );
} )
- .on( 'stopItemPageEditMode', function( event ) {
+ .on( 'stopItemPageEditMode', function( event, origin ) {
$( 'table.wb-terms' ).removeClass( 'wb-edit' );
$.each( termsValueTools, function( i, termValueTool ) {
termValueTool.enable();
--
To view, visit https://gerrit.wikimedia.org/r/112464
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8bed80355706455d779a7235f998ff6ce75c06b9
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Adrian Lang <[email protected]>
Gerrit-Reviewer: Fomafix
Gerrit-Reviewer: Henning Snater <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: WikidataJenkins <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits