Skip to content

Commit

Permalink
Show pending Approved Revs in Pending Reviews (#98)
Browse files Browse the repository at this point in the history
* Optionally allow create PendingReview with Title
* Create PendingApproval class
* Improve title of pending approvals
* Add green star next to pending approved revs
* show approved revID
* diff link for approvals
  • Loading branch information
krisfield authored and jamesmontalvo3 committed Feb 15, 2019
1 parent 4c685ba commit 3382a1c
Show file tree
Hide file tree
Showing 7 changed files with 274 additions and 46 deletions.
22 changes: 19 additions & 3 deletions Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ public static function onPersonalUrls( array &$personal_urls ) {
$numPending = $watchStats['num_pending'];
$maxPendingDays = $watchStats['max_pending_days'];

// Get user's pending approvals
// Check that Approved Revs is installed
$numPendingApprovals = 0;
if ( class_exists( 'ApprovedRevs' ) ) {
$numPendingApprovals = count( PendingApproval::getUserPendingApprovals( $user ) );
}

// Determine CSS class of Watchlist/PendingReviews link
$personal_urls['watchlist']['class'] = [ 'mw-watchanalytics-watchlist-badge' ];
if ( $numPending != 0 ) {
Expand All @@ -37,10 +44,19 @@ public static function onPersonalUrls( array &$personal_urls ) {
global $egPendingReviewsEmphasizeDays;
if ( $maxPendingDays > $egPendingReviewsEmphasizeDays ) {
$personal_urls['watchlist']['class'][] = 'mw-watchanalytics-watchlist-pending-old';
$text = wfMessage( 'watchanalytics-personal-url-old' )->params( $numPending, $maxPendingDays )->text();
if ( $numPendingApprovals != 0 ) {
$text = wfMessage( 'watchanalytics-personal-url-approvals-old' )->params( $numPending, $maxPendingDays, $numPendingApprovals )->text();
} else {
$text = wfMessage( 'watchanalytics-personal-url-old' )->params( $numPending, $maxPendingDays )->text();
}
} else {
// when $sk (third arg) available, replace wfMessage with $sk->msg()
$text = wfMessage( 'watchanalytics-personal-url' )->params( $numPending )->text();
if ( $numPendingApprovals != 0 ) {
$text = wfMessage( 'watchanalytics-personal-url-approvals' )->params( $numPending, $numPendingApprovals )->text();
} else {
// when $sk (third arg) available, replace wfMessage with $sk->msg()
$text = wfMessage( 'watchanalytics-personal-url' )->params( $numPending )->text();
}

}
$personal_urls['watchlist']['text'] = $text;

Expand Down
1 change: 1 addition & 0 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"WatchAnalyticsUser": "WatchAnalyticsUser.php",
"WatchAnalyticsUpdaterHooks": "schema/WatchAnalyticsUpdaterHooks.php",
"PendingReview": "includes/PendingReview.php",
"PendingApproval": "includes/PendingApproval.php",
"WatchSuggest": "includes/WatchSuggest.php",
"ReviewHandler": "includes/ReviewHandler.php",
"PageScore": "includes/PageScore.php",
Expand Down
10 changes: 9 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
},
"watchanalytics-desc": "Encouraging good distribution of watchers",
"watchanalytics-personal-url": "Pending reviews ($1)",
"watchanalytics-personal-url-approvals": "Pending reviews ($1)/approvals ($2)",
"watchanalytics-personal-url-old": "{{PLURAL:$1|1 review|$1 reviews}} (oldest: {{PLURAL:$2|1 day|$2 days}})",
"watchanalytics-personal-url-approvals-old": "{{PLURAL:$1|1 review|$1 reviews}} (oldest: {{PLURAL:$2|1 day|$2 days}})/approvals ($3)",
"watchanalytics-view": "View:",
"pendingreviews": "Pending reviews",
"watchanalytics": "Watch analytics",
Expand Down Expand Up @@ -76,6 +78,7 @@
"watchanalytics-pause-visualization": "Pause visualization",
"watchanalytics-unpause-visualization": "Unpause visualization",
"watchanalytics-pendingreviews-diff-revisions": "Display {{PLURAL:$1|1 change|$1 changes}} since last visit",
"watchanalytics-view-and-approve": "View/Approve changes",
"watchanalytics-pendingreviews-users-first-view": "New page - view latest",
"watchanalytics-pendingreviews-history-link": "view page history",
"watchanalytics-pendingreviews-prev-revisions": "< Previous",
Expand All @@ -85,7 +88,9 @@
"pendingreviews-timediff-minutes": "Changed {{PLURAL:$1|1 minute|$1 minutes}} ago",
"pendingreviews-timediff-just-now": "Changed just now",
"pendingreviews-no-revisions": "No page content changes",
"pendingreviews-num-reviews": "You have $1 pending {{PLURAL:$1|review|reviews}}.",
"pendingreviews-num-reviews": "You have $1 pending {{PLURAL:$1|review|reviews}}",
"pendingreviews-num-reviews-complete": "Congrats! You completed your reviews." ,
"pendingreviews-num-approvals": "/$1 pending {{PLURAL:$1|approval|approvals}}.",
"pendingreviews-reviewer-criticality-danger": "Pages reviewed by 0 - {{PLURAL:$1|1 person|$1 people}}",
"pendingreviews-reviewer-criticality-danger-zero": "Pages reviewed by 0 people",
"pendingreviews-reviewer-criticality-generic": "Pages reviewed by $1 or more people",
Expand All @@ -109,6 +114,8 @@
"watchanalytics-view-user-pendingreviews": "pending reviews",
"pendingreviews-watch-suggestion-thanks": "Thanks for watching!",

"pendingreviews-pending-approvedrev": "Has revisions which require approval",
"pendingreviews-pending-approvedrev-title": "Revision approval required: $1",
"pendingreviews-edited-by": "[[$1]] made an edit '''without a summary'''",
"pendingreviews-with-comment": "[[$1]] made an edit with summary: ",
"pendingreviews-page-deleted": "Deleted page: $1",
Expand All @@ -135,6 +142,7 @@
"log-description-pendingreviews": "Tracks actions taken using tools from the Watch Analytics extension related to Pending Reviews.",
"logentry-pendingreviews-clearreivews": "$1 {{GENDER:$2|cleared $4 pending reviews}} with criteria -category$5 -title like$6 using $3",
"pendingreviews-watch-suggestion-title": "This wiki needs your help watching pages",
"pendingreviews-approve-revs-title": "{{PLURAL:$1|Page|Pages}} needing your approval ($1)",
"pendingreviews-watch-suggestion-description": "Few (if any) people are watching the pages below. They are related to other pages in your watchlist, and it'd be real swell if you could help by watching some of them.",
"pendingreviews-watch-suggestion-watchlink": "Watch"

Expand Down
100 changes: 100 additions & 0 deletions includes/PendingApproval.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php
/**
* MediaWiki Extension: WatchAnalytics
* http://www.mediawiki.org/wiki/Extension:WatchAnalytics
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* This program is distributed WITHOUT ANY WARRANTY.
*/

/**
*
* @file
* @ingroup Extensions
* @author James Montalvo
* @license MIT
*/

# Alert the user that this is not a valid entry point to MediaWiki if they try to access the special pages file directly.
if ( !defined( 'MEDIAWIKI' ) ) {
echo <<<EOT
To install this extension, put the following line in LocalSettings.php:
require_once( "$IP/extensions/WatchAnalytics/WatchAnalytics.php" );
EOT;
exit( 1 );
}

class PendingApproval extends PendingReview {
public function __construct( $row, Title $title ) {
$this->title = $title;

$this->notificationTimestamp = $row['notificationtimestamp'];
$this->numReviewers = intval( $row['num_reviewed'] );

// Keep these just to be consistent with PendingReview class
$this->deletedTitle = false;
$this->deletedNS = false;
$this->deletionLog = false;

// FIXME
// no log for now, maybe link to approval log
// no list of revisions for now
$this->log = [];
$this->newRevisions = [];
}

/**
* Get an array of pages user can approve that require approvals
* @param User $user
* @return Array
*/
public static function getUserPendingApprovals( User $user ) {
$dbr = wfGetDB( DB_REPLICA );

$queryInfo = ApprovedRevs::getQueryInfoPageApprovals( 'notlatest' );
$latestNotApproved = $dbr->select(
$queryInfo['tables'],
$queryInfo['fields'],
$queryInfo['conds'],
__METHOD__,
$queryInfo['options'],
$queryInfo['join_conds']
);
$pagesUserCanApprove = [];

while ( $page = $latestNotApproved->fetchRow() ) {

// $page with keys id, rev_id, latest_id
$title = Title::newFromID( $page['id'] );

if ( ApprovedRevs::userCanApprove( $user, $title ) ) {

// FIXME: May want to get these in there so PendingReviews can
// show the list of revs in the approval.
// 'approved_rev_id' => $page['rev_id']
// 'latest_rev_id' => $page['latest_id']
$pagesUserCanApprove[] = new self(
[
'notificationtimestamp' => null,
'num_reviewed' => 0, // if page has pending approval, zero people have approved
],
$title
);

}

}

return $pagesUserCanApprove;
}

}
50 changes: 25 additions & 25 deletions includes/PendingReview.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,26 @@ class PendingReview {
*/
public $log;

public function __construct( $row ) {
$pageID = $row['page_id'];
public function __construct( $row, Title $title = null ) {
$notificationTimestamp = $row['notificationtimestamp'];

if ( $pageID ) {
$title = Title::newFromID( $pageID );
$this->notificationTimestamp = $notificationTimestamp;
$this->numReviewers = intval( $row['num_reviewed'] );

if ( $title ) {
$pageID = $title->getArticleID();
$namespace = $title->getNamespace();
$titleDBkey = $title->getDBkey();
} else {
$title = false;
$pageID = $row['page_id'];
$namespace = $row['namespace'];
$titleDBkey = $row['title'];

if ( $pageID ) {
$title = Title::newFromID( $pageID );
} else {
$title = false;
}
}

if ( $pageID && $title->exists() ) {
Expand All @@ -64,14 +76,6 @@ public function __construct( $row ) {
$revResults = $dbr->select(
[ 'r' => 'revision' ],
Revision::getQueryInfo()['fields'],
// array(
// 'r.rev_id AS rev_id',
// 'r.rev_comment AS rev_comment',
// 'r.rev_user AS rev_user_id',
// 'r.rev_user_text AS rev_user_name',
// 'r.rev_timestamp AS rev_timestamp',
// 'r.rev_len AS rev_len',
// ),
"r.rev_page=$pageID AND r.rev_timestamp>=$notificationTimestamp",
__METHOD__,
[ 'ORDER BY' => 'rev_timestamp ASC' ],
Expand All @@ -85,14 +89,6 @@ public function __construct( $row ) {
$logResults = $dbr->select(
[ 'l' => 'logging' ],
[ '*' ],
// array(
// 'l.log_id AS log_id',
// 'l.log_type AS log_type',
// 'l.log_action AS log_action',
// 'l.log_timestamp AS log_timestamp',
// 'l.log_user AS log_user_id',
// 'l.log_user_text AS log_user_name',
// ),
"l.log_page=$pageID AND l.log_timestamp>=$notificationTimestamp
AND l.log_type NOT IN ('interwiki','newusers','patrol','rights','upload')",
__METHOD__,
Expand All @@ -109,21 +105,19 @@ public function __construct( $row ) {
$deletionLog = false;

} else {
$deletedNS = $row['namespace'];
$deletedTitle = $row['title'];
$deletedNS = $namespace;
$deletedTitle = $titleDBkey;
$deletionLog = $this->getDeletionLog( $deletedTitle, $deletedNS, $notificationTimestamp );
$logPending = false;
$revsPending = false;
}

$this->notificationTimestamp = $notificationTimestamp;
$this->title = $title;
$this->newRevisions = $revsPending;
$this->deletedTitle = $deletedTitle;
$this->deletedNS = $deletedNS;
$this->deletionLog = $deletionLog;
$this->log = $logPending;
$this->numReviewers = intval( $row['num_reviewed'] );
}

public static function getPendingReviewsList( User $user, $limit, $offset ) {
Expand Down Expand Up @@ -188,6 +182,12 @@ public static function getPendingReviewsList( User $user, $limit, $offset ) {

}

// If ApprovedRevs is installed, append any pages in need of approvals
// to the front of the Pending Reviews list
if ( class_exists( 'ApprovedRevs' ) ) {
$pending = array_merge( PendingApproval::getUserPendingApprovals( $user ), $pending );
}

return $pending;
}

Expand Down
4 changes: 4 additions & 0 deletions modules/base/ext.watchanalytics.base.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ tr.ext-watchanalytics-criticality-okay td:first-child {
tr.ext-watchanalytics-criticality-excellent td:first-child {
border-left: solid #00af89 5px;
}

tr.ext-watchanalytics-approvable-page td:first-child {
border-left: solid #00B050 5px;
}
Loading

0 comments on commit 3382a1c

Please sign in to comment.