Mattflaschen has uploaded a new change for review.
https://gerrit.wikimedia.org/r/172668
Change subject: Use core's postWithToken for watching, which handles badtoken
......................................................................
Use core's postWithToken for watching, which handles badtoken
This ensures a stale token (e.g. because a user has been on a page for
a while without taking any action) will not result in a failure when
watching topics.
This is implemented by adding a new field, _internal.topicType, to the
params array, which allows you to specify the token type to use (the
default is 'edit', as before).
_internal itself is also new, and is intended for use cases like this,
where you need to pass low-level information that specifies how
FlowApi makes the actual request. It is in order to clearly
distinguish this information from actual parameters.
Also, remove a dead attribute (value watchTopic) which was duplicating
another attribute. This is invalid HTML, and it's only luck that
it picked the right one (at least in some browsers).
Bug: 72500
Bug: 73291
Change-Id: I88e9ca8c1cd4eb643476f78da8cb127f690d067f
---
M handlebars/compiled/flow_block_topiclist.handlebars.php
M handlebars/flow_topic_titlebar_watch.handlebars
M modules/engine/components/board/base/flow-board-api-events.js
M modules/engine/misc/flow-api.js
4 files changed, 11 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow
refs/changes/68/172668/1
diff --git a/handlebars/compiled/flow_block_topiclist.handlebars.php
b/handlebars/compiled/flow_block_topiclist.handlebars.php
index 254685f..c1e2e44 100644
--- a/handlebars/compiled/flow_block_topiclist.handlebars.php
+++ b/handlebars/compiled/flow_block_topiclist.handlebars.php
@@ -191,7 +191,6 @@
class="mw-ui-anchor mw-ui-constructive '.((!LCRun3::ifvar($cx,
((isset($in['isWatched']) && is_array($in)) ? $in['isWatched'] : null))) ?
'mw-ui-quiet' : '').'
'.((LCRun3::ifvar($cx, ((isset($in['isWatched']) && is_array($in)) ?
$in['isWatched'] : null))) ? 'flow-watch-link-unwatch' :
'flow-watch-link-watch').'"
data-flow-api-handler="watchItem"
- data-flow-api-handler="watchTopic"
data-flow-api-target="< .flow-topic-watchlist"
data-flow-api-method="POST">'.htmlentities((string)((isset($in['null']) &&
is_array($in)) ? $in['null'] : null), ENT_QUOTES, 'UTF-8').'<span
class="wikiglyph
wikiglyph-star"></span>'.htmlentities((string)((isset($in['null']) &&
is_array($in)) ? $in['null'] : null), ENT_QUOTES,
'UTF-8').''.htmlentities((string)((isset($in['null']) && is_array($in)) ?
$in['null'] : null), ENT_QUOTES, 'UTF-8').'<span class="wikiglyph
wikiglyph-unstar"></span>'.htmlentities((string)((isset($in['null']) &&
is_array($in)) ? $in['null'] : null), ENT_QUOTES, 'UTF-8').'</a>
</div>
diff --git a/handlebars/flow_topic_titlebar_watch.handlebars
b/handlebars/flow_topic_titlebar_watch.handlebars
index 3bfbbbe..ca117ee 100644
--- a/handlebars/flow_topic_titlebar_watch.handlebars
+++ b/handlebars/flow_topic_titlebar_watch.handlebars
@@ -9,7 +9,6 @@
flow-watch-link-watch
{{~/if~}}"
data-flow-api-handler="watchItem"
- data-flow-api-handler="watchTopic"
data-flow-api-target="< .flow-topic-watchlist"
data-flow-api-method="POST">
{{~null~}}<span class="wikiglyph
wikiglyph-star"></span>{{~null~}}
diff --git a/modules/engine/components/board/base/flow-board-api-events.js
b/modules/engine/components/board/base/flow-board-api-events.js
index cfd6c78..e101039 100644
--- a/modules/engine/components/board/base/flow-board-api-events.js
+++ b/modules/engine/components/board/base/flow-board-api-events.js
@@ -142,7 +142,9 @@
var params = {
action: 'watch',
titles: queryMap.page,
- token: mw.user.tokens.get( 'watchToken' )
+ _internal: {
+ tokenType: 'watch'
+ }
};
if ( queryMap.submodule === 'unwatch' ) {
params.unwatch = 1;
diff --git a/modules/engine/misc/flow-api.js b/modules/engine/misc/flow-api.js
index 474b170..78a5832 100644
--- a/modules/engine/misc/flow-api.js
+++ b/modules/engine/misc/flow-api.js
@@ -45,6 +45,8 @@
* @returns {$.Deferred}
*/
function flowApiCall( params, method ) {
+ var tokenType;
+
params = params || {};
// Server is using page instead of title
// @todo this should not be necessary
@@ -65,7 +67,12 @@
if ( method === 'POST' ) {
if ( !params.hasOwnProperty( 'token' ) ) {
- return mwApi.postWithToken( 'edit',
params );
+ if ( params._internal &&
params._internal.tokenType ) {
+ tokenType =
params._internal.tokenType;
+ } else {
+ tokenType = 'edit';
+ }
+ return mwApi.postWithToken( tokenType,
params );
} else {
return mwApi.post( params );
}
--
To view, visit https://gerrit.wikimedia.org/r/172668
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I88e9ca8c1cd4eb643476f78da8cb127f690d067f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Mattflaschen <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits