Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
krisfield committed Mar 22, 2019
2 parents 0fd6a70 + de5e9d9 commit 38692cb
Show file tree
Hide file tree
Showing 14 changed files with 614 additions and 110 deletions.
28 changes: 23 additions & 5 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 All @@ -55,7 +71,7 @@ public static function onPersonalUrls( array &$personal_urls ) {
*
* 1) Determine if user should see shaky pending reviews link
* 2) Insert page scores on applicable pages
* 3) REMOVED FOR MW 1.27: If a page review has occured on this page view, display an unreview
* 3) REMOVED FOR MW 1.27: If a page review has occurred on this page view, display an unreview
* option and record that the review happened.
*
* Also supports parameter: Skin $skin.
Expand Down Expand Up @@ -243,8 +259,10 @@ public static function handleMagicWords( &$parser, &$text ) {
* @return bool
*/
public static function onPageViewUpdates( WikiPage $wikiPage, User $user ) {
global $wgRequest;
$title = $wikiPage->getTitle();
$reviewHandler = ReviewHandler::setup( $user, $title );
$isDiff = $wgRequest->getText( 'oldid' );
$reviewHandler = ReviewHandler::setup( $user, $title, $isDiff );

if ( $reviewHandler::pageIsBeingReviewed() ) {

Expand Down
6 changes: 5 additions & 1 deletion extension.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "WatchAnalytics",
"version": "2.0.1",
"version": "3.1.0",
"author": [
"[https://www.mediawiki.org/wiki/User:Jamesmontalvo3 James Montalvo]"
],
Expand Down 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 Expand Up @@ -205,6 +206,9 @@
"config": {
"_prefix": "eg",
"WatchAnalyticsPageCounter": false,
"WatchAnalyticsShowUnreviewDiff": true,
"PendingReviewMaxDiffChar": 3500,
"PendingReviewMaxDiffRows": 15,
"PendingReviewsEmphasizeDays": 7,
"PendingReviewsRedPagesThreshold": 2,
"PendingReviewsOrangePagesThreshold": 4,
Expand Down
15 changes: 13 additions & 2 deletions 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 @@ -75,7 +77,8 @@
"watchanalytics-watch-forcegraph-description": "Orange dots represent users. Blue dots represent pages. Lines between the dots represent the user being a watcher of the page. Lines are gray if the latest page revision has been reviewed. Lines are red if reviews are pending. Move your mouse over a dot to see the user or page name.",
"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-pendingreviews-diff-revisions": "View {{PLURAL:$1|change|$1 changes}} on page",
"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,10 @@
"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-other-user-reviews": "$1 has $2 pending {{PLURAL:$2|review|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 @@ -103,12 +109,15 @@
"watchanalytics-pagestats-chart-header": "Number of reviewers over time",

"watchanalytics-unreview-button": "Defer review",
"watchanalytics-accept-change-close-banner": "Close banner",
"watchanalytics-unreview-banner-text": "'''Page reviewed!''' By navigating to this page you have marked it reviewed. If you did not want to review the page you may un-review it to save it for another time.",
"watchanalytics-unreview-complete": "'''This page has been un-reviewed''' and is again in your [[Special:PendingReviews|Pending Reviews]].",

"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 @@ -117,6 +126,7 @@
"pendingreviews-accept-deletion": "Accept deletion",
"pendingreviews-accept-move-without-redirect": "Accept move without redirect",
"pendingreviews-accept-redirect": "Accept redirect",
"pendingreviews-accept-change": "Mark reviewed",
"pendingreviews-clear-page-notification": "Page \"$1\" has been marked reviewed. Return to $2",
"pendingreviews-log-approved": "[[$1]] approved a revision",
"pendingreviews-log-unapproved": "[[$1]] removed all revision approvals",
Expand All @@ -135,6 +145,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;
}

}
Loading

0 comments on commit 38692cb

Please sign in to comment.