Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Approved revs #98

Merged
merged 45 commits into from
Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
0d19cd1
Optionally allow create PendingReview with Title
jamesmontalvo3 Oct 30, 2018
3244ec8
First attempt at approve revs in PendingReviews
jamesmontalvo3 Oct 31, 2018
6d82a23
list needs to be PendingReview objects
jamesmontalvo3 Oct 31, 2018
aa7a5b6
Create PendingApproval class
jamesmontalvo3 Oct 31, 2018
0a33c16
Minor fixes
jamesmontalvo3 Oct 31, 2018
92c0190
AImprove title of pending approvals
jamesmontalvo3 Oct 31, 2018
3c6bcf0
Add green star next to pending approved revs
jamesmontalvo3 Oct 31, 2018
f3f7c4f
v2.0.0 release
Nov 19, 2018
eeb0d4d
Merge branch 'master' of https://github.com/enterprisemediawiki/Watch…
Nov 19, 2018
fadf0c8
Merge branch 'master' of https://github.com/enterprisemediawiki/Watch…
Nov 27, 2018
0fd6a70
Merge branch 'master' of https://github.com/enterprisemediawiki/Watch…
Feb 4, 2019
459cf1e
Merge branch 'master' into approved-revs
Feb 4, 2019
7cf89ad
remove extraneous bracket
Feb 5, 2019
43c8574
seperates reviews from approvals
Feb 5, 2019
8f8205d
removes approvals from pr list
Feb 5, 2019
5c76852
fixes extraneous else
Feb 5, 2019
6657a9d
still trying to remove approve pages from reviews
Feb 5, 2019
d66004b
typo
Feb 5, 2019
e99a392
row counting cosistency
Feb 5, 2019
8fcb5d0
show approved revID
Feb 5, 2019
8fdf47f
add new diff id
Feb 5, 2019
2e9c362
change method for getting new rev id
Feb 5, 2019
1cf5f83
new rev
Feb 5, 2019
40c754a
learning
Feb 5, 2019
31119cb
more new rev id attemps
Feb 5, 2019
02dd4ae
diff link for approvals
Feb 5, 2019
df68313
difflink
Feb 5, 2019
bb9f2db
create new row style for approvable pages
Feb 6, 2019
7a9241d
approved revs styling
Feb 6, 2019
a5f85d9
aproved revs header
Feb 6, 2019
474046f
adds approval page header
krisfield Feb 7, 2019
f7a7d6a
integrates approved revs
krisfield Feb 11, 2019
a253f0b
formatting
krisfield Feb 11, 2019
29b9fc4
formatting
krisfield Feb 11, 2019
a1c4105
fix indents
krisfield Feb 11, 2019
fc2512a
space before elseif
krisfield Feb 11, 2019
b9bc152
maybe a correct format
krisfield Feb 11, 2019
11122bb
add back getQueryInfo
krisfield Feb 11, 2019
8f14547
adds back "getQueryInfo"
krisfield Feb 11, 2019
4bad3d6
sasad
krisfield Feb 11, 2019
c404f25
remove bad logic
krisfield Feb 14, 2019
f90752d
typo
krisfield Feb 14, 2019
f4f21bc
fix for approvals showing as reviews
krisfield Feb 14, 2019
1d810d7
only increment row count for reviews
krisfield Feb 14, 2019
5b39a65
remove whitespace on line 152
krisfield Feb 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}

}
52 changes: 26 additions & 26 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 @@ -63,15 +75,7 @@ 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',
// ),
Revision::selectFields(),
"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