jenkins-bot has submitted this change and it was merged.

Change subject: Some design to the patrol link and use ajax to patrol
......................................................................


Some design to the patrol link and use ajax to patrol

* Use a neutral button for the patrol link instead of a simple text link
* Use JavaScript for ajax patrolling a revision instead of redirecting
  to a new page

Bug: T101491
Depends-On: Id09ccf60aec9b693d7df648a6dfcde629545f620
Change-Id: I08b871fb1608f8cc576cec73ef2e9864d26a9a38
---
M extension.json
M includes/diff/InlineDifferenceEngine.php
M includes/specials/SpecialMobileDiff.php
A resources/mobile.patrol.ajax/init.js
M resources/mobile.special.mobilediff.styles/mobilediff.less
5 files changed, 121 insertions(+), 7 deletions(-)

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



diff --git a/extension.json b/extension.json
index d4bf2f8..f0d46ad 100644
--- a/extension.json
+++ b/extension.json
@@ -1390,6 +1390,24 @@
                                "resources/mobile.swipe/Swipe.js"
                        ]
                },
+               "mobile.patrol.ajax": {
+                       "targets": [
+                               "mobile",
+                               "desktop"
+                       ],
+                       "dependencies": [
+                               "mobile.startup",
+                               "mobile.toast",
+                               "mediawiki.Title"
+                       ],
+                       "scripts": [
+                               "resources/mobile.patrol.ajax/init.js"
+                       ],
+                       "messages": [
+                               "markedaspatrollednotify",
+                               "markedaspatrollederrornotify"
+                       ]
+               },
                "mobile.site": {
                        "dependencies": [
                                "mobile.startup"
diff --git a/includes/diff/InlineDifferenceEngine.php 
b/includes/diff/InlineDifferenceEngine.php
index 01054f9..0eb67a9 100644
--- a/includes/diff/InlineDifferenceEngine.php
+++ b/includes/diff/InlineDifferenceEngine.php
@@ -157,6 +157,20 @@
         * @return String
         */
        public function getPatrolledLink() {
-               return $this->markPatrolledLink();
+               $linkInfo = $this->getMarkPatrolledLinkInfo();
+               if ( $linkInfo ) {
+                       $this->getOutput()->addModules( 'mobile.patrol.ajax' );
+                       $linkInfo = Html::linkButton(
+                               $this->msg( 'markaspatrolleddiff' )->escaped(),
+                               array(
+                                       'href' => $this->mNewPage->getLocalUrl( 
array(
+                                               'action' => 'markpatrolled',
+                                               'rcid' => $linkInfo['rcid'],
+                                               'token' => $linkInfo['token'],
+                                       ) ),
+                               )
+                       );
+               }
+               return $linkInfo;
        }
 }
diff --git a/includes/specials/SpecialMobileDiff.php 
b/includes/specials/SpecialMobileDiff.php
index 5524163..894c209 100644
--- a/includes/specials/SpecialMobileDiff.php
+++ b/includes/specials/SpecialMobileDiff.php
@@ -217,6 +217,7 @@
         * using InlineDiffEngine
         */
        function showDiff() {
+               $output = $this->getOutput();
                $ctx = MobileContext::singleton();
 
                $prevId = $this->prevRev ? $this->prevRev->getId() : 0;
@@ -250,7 +251,7 @@
                if ( $warnings ) {
                        $warnings = MobileUI::warningBox( $warnings );
                }
-               $this->getOutput()->addHtml(
+               $output->addHtml(
                        $warnings .
                        '<div id="mw-mf-minidiff">' .
                        $diff .
@@ -273,7 +274,18 @@
                                        ), $this->msg( 'nextdiff' ) ) . 
Html::closeElement( 'li' );
                        }
                        $history .= Html::closeElement( 'ul' );
-                       $this->getOutput()->addHtml( $history );
+                       $output->addHtml( $history );
+               }
+
+               $diffEngine = $this->mDiffEngine;
+               if ( $diffEngine instanceof InlineDifferenceEngine ) {
+                       $output->addHtml( Html::rawElement(
+                               'div',
+                               array(
+                                       'class' => 'patrollink'
+                               ),
+                               $diffEngine->getPatrolledLink()
+                       ) );
                }
        }
 
@@ -328,10 +340,6 @@
                                        Linker::link( $userPage, 
htmlspecialchars( $ipAddr ) ) .
                                '</div>'
                        );
-               }
-
-               if ( $this->mDiffEngine instanceof InlineDifferenceEngine ) {
-                       $output->addHtml( 
$this->mDiffEngine->getPatrolledLink() );
                }
 
                $output->addHtml(
diff --git a/resources/mobile.patrol.ajax/init.js 
b/resources/mobile.patrol.ajax/init.js
new file mode 100644
index 0000000..60575a9
--- /dev/null
+++ b/resources/mobile.patrol.ajax/init.js
@@ -0,0 +1,70 @@
+/*!
+ * Animate patrol links to use asynchronous API requests to
+ * patrol pages, rather than navigating to a different URI.
+ *
+ * @author Florian Schmidt <[email protected]>
+ */
+( function ( M, $ ) {
+       if ( !mw.user.tokens.exists( 'patrolToken' ) ) {
+               // Current user has no patrol right, or an old cached version 
of user.tokens
+               // that didn't have patrolToken yet.
+               return;
+       }
+       $( function () {
+               var $patrolLinks = $( '.patrollink a' ),
+                       Icon = M.require( 'mobile.startup/Icon' ),
+                       toast = M.require( 'mobile.toast/toast' ),
+                       $spinner = $( new Icon( {
+                               name: 'spinner',
+                               additionalClassNames: 'savespinner loading'
+                       } ).toHtmlString() ),
+                       href, rcid, apiRequest;
+
+               $patrolLinks.on( 'click', function ( e ) {
+                       // Hide the link show a spinner instead.
+                       $( e.target ).hide().after( $spinner );
+
+                       href = $( this ).attr( 'href' );
+                       rcid = mw.util.getParamValue( 'rcid', href );
+                       apiRequest = new mw.Api();
+                       apiRequest.postWithToken( 'patrol', {
+                               action: 'patrol',
+                               rcid: rcid
+                       } )
+                       .done( function ( data ) {
+                               var title;
+
+                               // Disable all patrollinks from the page.
+                               $patrolLinks.closest( '.patrollink' 
).replaceWith(
+                                       $( '<button>' )
+                                               .addClass( 'mw-ui-button 
patrollink' )
+                                               .prop( 'disabled', true )
+                                               .text( $patrolLinks.closest( 
'.patrollink' ).text() )
+                               );
+                               $spinner.remove();
+                               if ( data.patrol !== undefined ) {
+                                       // Success
+                                       title = new mw.Title( data.patrol.title 
);
+                                       toast.show( mw.msg( 
'markedaspatrollednotify', title.toText() ) );
+                               } else {
+                                       // This should never happen as errors 
should trigger fail
+                                       toast.show( mw.msg( 
'markedaspatrollederrornotify' ), 'error' );
+                               }
+                       } )
+                       .fail( function ( error ) {
+                               $spinner.remove();
+                               // Restore the patrol link. This allows the 
user to try again
+                               // (or open it in a new window, bypassing this 
ajax module).
+                               $patrolLinks.show();
+                               if ( error === 'noautopatrol' ) {
+                                       // Can't patrol own
+                                       toast.show( mw.msg( 
'markedaspatrollederror-noautopatrol' ), 'warn' );
+                               } else {
+                                       toast.show( mw.msg( 
'markedaspatrollederrornotify' ), 'error' );
+                               }
+                       } );
+
+                       e.preventDefault();
+               } );
+       } );
+}( mw.mobileFrontend, jQuery ) );
diff --git a/resources/mobile.special.mobilediff.styles/mobilediff.less 
b/resources/mobile.special.mobilediff.styles/mobilediff.less
index 351190d..d7d19ef 100644
--- a/resources/mobile.special.mobilediff.styles/mobilediff.less
+++ b/resources/mobile.special.mobilediff.styles/mobilediff.less
@@ -105,6 +105,10 @@
                        display: inline;
                }
        }
+
+       .patrollink {
+               margin-top: 1em;
+       }
 }
 
 .revision-history-links {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I08b871fb1608f8cc576cec73ef2e9864d26a9a38
Gerrit-PatchSet: 15
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to