jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/354745 )

Change subject: Fix edit conflict handling in lists.
......................................................................


Fix edit conflict handling in lists.

We assume the current DOM is latest, (since the change to allow
duplicate entries), so that should be the base timestamp.

Bug: T165672
Change-Id: Ib2e083cb262cdd0a0377c139709e624a60b6d17c
---
M extension.json
M includes/content/CollaborationListContent.php
M modules/ext.CollaborationKit.list.edit.js
3 files changed, 28 insertions(+), 2 deletions(-)

Approvals:
  Harej: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/extension.json b/extension.json
index 005c968..db5658e 100644
--- a/extension.json
+++ b/extension.json
@@ -86,6 +86,9 @@
                ],
                "OutputPageBodyAttributes": [
                        "CollaborationHubContentEditor::setCollabkitTheme"
+               ],
+               "BeforePageDisplay": [
+                       "CollaborationListContent::onBeforePageDisplay"
                ]
        },
        "@fixme": "Does having ext.CollaborationKit.list.styles as a dependency 
double load from addModuleStyles?",
diff --git a/includes/content/CollaborationListContent.php 
b/includes/content/CollaborationListContent.php
index 8027394..f39a580 100644
--- a/includes/content/CollaborationListContent.php
+++ b/includes/content/CollaborationListContent.php
@@ -1206,6 +1206,7 @@
                        && $title->userCan( 'edit', $user, 'quick' )
                ) {
                        $output->addJsConfigVars( 
'wgEnableCollaborationKitListEdit', true );
+
                        // FIXME: only load .list.members if the list is a 
member list
                        // (displaymode = members)
                        $output->addModules( [
@@ -1217,6 +1218,18 @@
        }
 
        /**
+        * Hook to add timestamp for edit conflict detection
+        *
+        * @param OutputPage $out
+        * @param Skin $skin
+        */
+       public static function onBeforePageDisplay( OutputPage $out, $skin ) {
+               // Used for edit conflict detection in lists.
+               $revTS = (int)$out->getRevisionTimestamp();
+               $out->addJsConfigVars( 'wgCollabkitLastEdit', $revTS );
+       }
+
+       /**
         * Hook to use custom edit page for lists
         *
         * @param WikiPage|Article|ImagePage|CategoryPage|Page $page
diff --git a/modules/ext.CollaborationKit.list.edit.js 
b/modules/ext.CollaborationKit.list.edit.js
index 85e8c0d..b01e31b 100644
--- a/modules/ext.CollaborationKit.list.edit.js
+++ b/modules/ext.CollaborationKit.list.edit.js
@@ -279,7 +279,9 @@
        saveJson = function ( params, callback ) {
                var api = new mw.Api(),
                        i,
-                       j;
+                       j,
+                       lastRevTS,
+                       baseTimestamp = params.timestamp;
 
                // Strip out UID; we don't want to save it.
                for ( i = 0; i < params.content.columns.length; i++ ) {
@@ -288,6 +290,14 @@
                        }
                }
 
+               // Since we depend on things in the DOM, make our base timestamp
+               // for edit conflict the earlier of the last edit + 1 second and
+               // the time data was fetched.
+               lastRevTS = mw.config.get( 'wgCollabkitLastEdit' );
+               if ( lastRevTS ) {
+                       lastRevTS += 1; // 1 second after last rev timestamp
+                       baseTimestamp = Math.min( lastRevTS, +( 
params.timestamp.replace( /\D/g, '' ) ) );
+               }
                // This will explode if we hit a captcha
                api.postWithEditToken( {
                        action: 'edit',
@@ -298,7 +308,7 @@
                        summary: params.summary,
                        pageid: params.pageid,
                        text: JSON.stringify( params.content ),
-                       basetimestamp: params.timestamp
+                       basetimestamp: baseTimestamp
                } ).done( callback ).fail( function () {
                        // FIXME proper error handling.
                        alert( mw.msg( 'collaborationkit-list-error-saving' ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/354745
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib2e083cb262cdd0a0377c139709e624a60b6d17c
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/CollaborationKit
Gerrit-Branch: master
Gerrit-Owner: Brian Wolff <bawolff...@gmail.com>
Gerrit-Reviewer: Harej <jamesmh...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to