Ricordisamoa has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/230818

Change subject: [WIP] "Mark all as patrolled" link for multi-edit diffs
......................................................................

[WIP] "Mark all as patrolled" link for multi-edit diffs

Bug: T10697
Change-Id: Id6389ff12bb560d8c68d1b561559b63491354d38
---
M includes/actions/MarkpatrolledAction.php
M includes/diff/DifferenceEngine.php
M languages/i18n/en.json
M languages/i18n/qqq.json
4 files changed, 111 insertions(+), 61 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/18/230818/1

diff --git a/includes/actions/MarkpatrolledAction.php 
b/includes/actions/MarkpatrolledAction.php
index 4016f67..064c8a0 100644
--- a/includes/actions/MarkpatrolledAction.php
+++ b/includes/actions/MarkpatrolledAction.php
@@ -40,18 +40,27 @@
        public function onView() {
                $request = $this->getRequest();
 
-               $rcId = $request->getInt( 'rcid' );
-               $rc = RecentChange::newFromId( $rcId );
-               if ( is_null( $rc ) ) {
-                       throw new ErrorPageError( 'markedaspatrollederror', 
'markedaspatrollederrortext' );
+               $rcIds = $request->getIntArray( 'rcid' );
+               $rcs = array();
+               foreach ( $rcIds as $rcId ) {
+                       $rc = RecentChange::newFromId( $rcId );
+                       if ( is_null( $rc ) ) {
+                               throw new ErrorPageError( 
'markedaspatrollederror', 'markedaspatrollederrortext' );
+                       }
+                       $rcs[] = $rc;
                }
 
                $user = $this->getUser();
-               if ( !$user->matchEditToken( $request->getVal( 'token' ), $rcId 
) ) {
+               if ( !$user->matchEditToken( $request->getVal( 'token' ), 
$rcIds[0] ) ) {
                        throw new ErrorPageError( 'sessionfailure-title', 
'sessionfailure' );
                }
 
-               $errors = $rc->doMarkPatrolled( $user );
+               foreach ( $rcs as $rc ) {
+                       $errors = $rc->doMarkPatrolled( $user );
+                       if ( $errors ) {
+                               break;
+                       }
+               }
 
                if ( in_array( array( 'rcpatroldisabled' ), $errors ) ) {
                        throw new ErrorPageError( 'rcpatroldisabled', 
'rcpatroldisabledtext' );
diff --git a/includes/diff/DifferenceEngine.php 
b/includes/diff/DifferenceEngine.php
index c138eec..7b5c116 100644
--- a/includes/diff/DifferenceEngine.php
+++ b/includes/diff/DifferenceEngine.php
@@ -465,65 +465,101 @@
         *
         * @return string
         */
-       protected function markPatrolledLink() {
+       protected function getMarkPatrolledLink( $multi = false ) {
                global $wgUseRCPatrol, $wgEnableAPI, $wgEnableWriteAPI;
                $user = $this->getUser();
 
+               if (
+                       // Is patrolling enabled and the user allowed to?
+                       $wgUseRCPatrol && $this->mNewPage->quickUserCan( 
'patrol', $user ) &&
+                       // Only do this if the revision isn't more than 6 hours 
older
+                       // than the Max RC age (6h because the RC might not be 
cleaned out regularly)
+                       RecentChange::isInRCLifespan( 
$this->mNewRev->getTimestamp(), 21600 )
+               ) {
+                       // Look for an unpatrolled change corresponding to this 
diff
+
+                       $conds = array(
+                               'rc_patrolled' => 0
+                       );
+                       $db = wfGetDB( DB_SLAVE );
+                       if ( $multi ) {
+                               $conds[] = 'rc_timestamp > ' . $db->timestamp( 
$this->mOldRev->getTimestamp() );
+                               $conds[] = 'rc_timestamp <= ' . $db->timestamp( 
$this->mNewRev->getTimestamp() );
+                               $conds[] = 'rc_this_oldid > ' . $this->mOldid;
+                               $conds[] = 'rc_this_oldid <= ' . $this->mNewid;
+                       } else {
+                               $conds['rc_timestamp'] = $db->timestamp( 
$this->mNewRev->getTimestamp() );
+                               $conds['rc_this_oldid'] = $this->mNewid;
+                       }
+
+                       $res = $db->select(
+                               'recentchanges',
+                               RecentChange::selectFields(),
+                               $conds,
+                               __METHOD__,
+                               array( 'USE INDEX' => 'rc_timestamp' )
+                       );
+                       if ( $multi && $res->numRows() < 2 ) {
+                               // "Mark all as patrolled" wouldn't make sense.
+                               // We check for that later, but let's skip the 
RecentChange
+                               // initialization altogether if we can.
+                               return '';
+                       }
+                       $rcids = array();
+                       foreach ( $res as $row ) {
+                               if ( $row !== false ) {
+                                       $change = RecentChange::newFromRow( 
$row );
+                                       if (
+                                               $change && 
!$change->getPerformer()->equals( $user ) &&
+                                               ( !$multi || 
$change->getTitle()->equals( $this->mNewPage ) ) // 'normal' mode or same title
+                                       ) {
+                                               $rcids[] = 
$change->getAttribute( 'rc_id' );
+                                       }
+                               }
+                       }
+
+                       // Build the link
+                       if ( $rcids ) {
+                               if ( $multi && count( $rcids ) < 2 ) {
+                                       // Final check against nonsense "Mark 
all as patrolled"
+                                       return '';
+                               }
+                               $this->getOutput()->preventClickjacking();
+                               if ( $wgEnableAPI && $wgEnableWriteAPI
+                                       && $user->isAllowed( 'writeapi' )
+                               ) {
+                                       $this->getOutput()->addModules( 
'mediawiki.page.patrol.ajax' );
+                               }
+
+                               $token = $user->getEditToken( $rcids[0] );
+                               return ' <span class="patrollink">[' . 
Linker::linkKnown(
+                                       $this->mNewPage,
+                                       $this->msg( $multi ? 
'markaspatrolleddiffmulti' : 'markaspatrolleddiff' )->escaped(),
+                                       array(),
+                                       array(
+                                               'action' => 'markpatrolled',
+                                               'rcid' => $rcids,
+                                               'token' => $token,
+                                       )
+                               ) . ']</span>';
+                       }
+               }
+
+               return '';
+       }
+
+       /**
+        * Get a link to mark the change as patrolled, or '' if there's either 
no
+        * revision to patrol or the user is not allowed to to it.
+        * Side effect: When the patrol link is build, this method will call
+        * OutputPage::preventClickjacking() and load 
mediawiki.page.patrol.ajax.
+        *
+        * @return string
+        */
+       protected function markPatrolledLink() {
                if ( $this->mMarkPatrolledLink === null ) {
                        // Prepare a change patrol link, if applicable
-                       if (
-                               // Is patrolling enabled and the user allowed 
to?
-                               $wgUseRCPatrol && 
$this->mNewPage->quickUserCan( 'patrol', $user ) &&
-                               // Only do this if the revision isn't more than 
6 hours older
-                               // than the Max RC age (6h because the RC might 
not be cleaned out regularly)
-                               RecentChange::isInRCLifespan( 
$this->mNewRev->getTimestamp(), 21600 )
-                       ) {
-                               // Look for an unpatrolled change corresponding 
to this diff
-
-                               $db = wfGetDB( DB_SLAVE );
-                               $change = RecentChange::newFromConds(
-                                       array(
-                                               'rc_timestamp' => 
$db->timestamp( $this->mNewRev->getTimestamp() ),
-                                               'rc_this_oldid' => 
$this->mNewid,
-                                               'rc_patrolled' => 0
-                                       ),
-                                       __METHOD__,
-                                       array( 'USE INDEX' => 'rc_timestamp' )
-                               );
-
-                               if ( $change && 
!$change->getPerformer()->equals( $user ) ) {
-                                       $rcid = $change->getAttribute( 'rc_id' 
);
-                               } else {
-                                       // None found or the page has been 
created by the current user.
-                                       // If the user could patrol this it 
already would be patrolled
-                                       $rcid = 0;
-                               }
-                               // Build the link
-                               if ( $rcid ) {
-                                       
$this->getOutput()->preventClickjacking();
-                                       if ( $wgEnableAPI && $wgEnableWriteAPI
-                                               && $user->isAllowed( 'writeapi' 
)
-                                       ) {
-                                               $this->getOutput()->addModules( 
'mediawiki.page.patrol.ajax' );
-                                       }
-
-                                       $token = $user->getEditToken( $rcid );
-                                       $this->mMarkPatrolledLink = ' <span 
class="patrollink">[' . Linker::linkKnown(
-                                               $this->mNewPage,
-                                               $this->msg( 
'markaspatrolleddiff' )->escaped(),
-                                               array(),
-                                               array(
-                                                       'action' => 
'markpatrolled',
-                                                       'rcid' => $rcid,
-                                                       'token' => $token,
-                                               )
-                                       ) . ']</span>';
-                               } else {
-                                       $this->mMarkPatrolledLink = '';
-                               }
-                       } else {
-                               $this->mMarkPatrolledLink = '';
-                       }
+                       $this->mMarkPatrolledLink = 
$this->getMarkPatrolledLink();
                }
 
                return $this->mMarkPatrolledLink;
@@ -963,7 +999,10 @@
                                $numUsers = 0; // special case to say "by the 
same user" instead of "by one other user"
                        }
 
-                       return self::intermediateEditsMsg( $nEdits, $numUsers, 
$limit );
+                       $markPatrolledLink = $this->getMarkPatrolledLink( true 
);
+
+                       return self::intermediateEditsMsg( $nEdits, $numUsers, 
$limit ) .
+                               ( $markPatrolledLink === '' ? '' : '<br/>' . 
$markPatrolledLink );
                }
 
                return ''; // nothing
diff --git a/languages/i18n/en.json b/languages/i18n/en.json
index aa71f3b..95645e5 100644
--- a/languages/i18n/en.json
+++ b/languages/i18n/en.json
@@ -2642,6 +2642,7 @@
        "pageinfo-category-subcats": "Number of subcategories",
        "pageinfo-category-files": "Number of files",
        "markaspatrolleddiff": "Mark as patrolled",
+       "markaspatrolleddiffmulti": "Mark all as patrolled",
        "markaspatrolledlink": "[$1]",
        "markaspatrolledtext": "Mark this page as patrolled",
        "markedaspatrolled": "Marked as patrolled",
diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json
index 1a7b182..e7a1b5c 100644
--- a/languages/i18n/qqq.json
+++ b/languages/i18n/qqq.json
@@ -2813,6 +2813,7 @@
        "pageinfo-category-subcats": "See also:\n* 
{{msg-mw|Pageinfo-category-pages}}\n* {{msg-mw|Pageinfo-category-files}}",
        "pageinfo-category-files": "See also:\n* 
{{msg-mw|Pageinfo-category-pages}}\n* {{msg-mw|Pageinfo-category-subcats}}",
        "markaspatrolleddiff": "{{doc-actionlink}}\nSee also:\n* 
{{msg-mw|Markaspatrolledtext}}\n{{Identical|Mark as patrolled}}",
+       "markaspatrolleddiffmulti": "{{doc-actionlink}}\nSee also:\n* 
{{msg-mw|Markaspatrolleddiff}}",
        "markaspatrolledlink": "{{notranslate}}\nParameters:\n* $1 - link which 
has text {{msg-mw|Markaspatrolledtext}}",
        "markaspatrolledtext": "{{doc-actionlink}}\nSee also:\n* 
{{msg-mw|Markaspatrolleddiff}}",
        "markedaspatrolled": "Used as title of the message 
{{msg-mw|Markedaspatrolledtext}}, when marking a change as 
patrolled.\n{{Related|Markedaspatrolled}}",

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id6389ff12bb560d8c68d1b561559b63491354d38
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <[email protected]>

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

Reply via email to