Skip to content

GlobalContributions: Highlight pending edits (FlaggedRevs extension) #531

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions assets/css/_darkmode.scss
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,13 @@ $tooltip-shadow: #333;

.reverted-edit {
background: #4e4c40 !important;
}

.pending-edit:not(.reverted-edit) {
background: #333127 !important;
}

.reverted-edit, .pending-edit {
.text-info {
color: #74cefa;
}
Expand Down
4 changes: 4 additions & 0 deletions assets/css/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -730,3 +730,7 @@ a.help-icon {
.reverted-edit {
background: #fcf8e3 !important;
}

.pending-edit:not(.reverted-edit) {
background:#fffdf2 !important;
}
10 changes: 9 additions & 1 deletion config/packages/nelmio_api_doc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,17 @@ nelmio_api_doc:
type: boolean
description:
Whether the edit has definitively been reverted.
A `false` value or commission of the `reverted` property does not
A `false` value or ommission of the `reverted` property does not
necessarily mean it wasn't reverted.
example: true
pending:
type: boolean
description:
Whether the edit is pending review.
(From the FlaggedRevs extension.)
A `false` value or omission of the property does not
necessarily mean it isn't pending.
example: true
EditWithProject:
allOf:
- properties:
Expand Down
1 change: 1 addition & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@
"pattern-input-desc": "A pattern can be any text where $1 is a wildcard.",
"pc-accept": "Pending change accept",
"pc-reject": "Pending change unaccept",
"pending": "Pending",
"percent-of-edit-count": "% of edit count",
"percent-of-tools": "% of tools",
"percentage": "Percentage",
Expand Down
1 change: 1 addition & 0 deletions i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@
"pattern-input-desc": "Description of the syntax that should be used for the 'Inclusion pattern' and 'Exclusion pattern' fields in the Largest Pages tool. $1 is the character that should be used for a wildcard.",
"pc-accept": "Name of MediaWiki action to accept a pending change. On some wikis this may be referred to as 'flagged revision'. When in doubt, use a direct translation of 'accept'.\n{{Identical|Accept}}",
"pc-reject": "Name of MediaWiki action to reject a pending change. On some wikis this may be referred to as 'flagged revision'. When in doubt, use a direct translation of 'reject'.\n{{Identical|Reject}}",
"pending": "Label for pending edits (from the FlaggedRevs extension). Try to keep this label short",
"percent-of-edit-count": "In the AutoEdits tool, this is the heading for the column that shows the percentage that a tool was used compared to the user's total edit count.",
"percent-of-tools": "In the AutoEdits tool, this is the heading for the column that shows the percentage that a tool was used compared to all other tools that were used.",
"percentage": "Label for the a percentage value.\n{{Identical|Percentage}}",
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/build/entrypoints.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"/build/app.a7d89f5a.js"
],
"css": [
"/build/app.da10c09b.css"
"/build/app.03693828.css"
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion public/build/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"build/app.css": "/build/app.da10c09b.css",
"build/app.css": "/build/app.03693828.css",
"build/app.js": "/build/app.a7d89f5a.js",
"build/runtime.js": "/build/runtime.c217f8c4.js",
"build/95.7a87ed1a.js": "/build/95.7a87ed1a.js",
Expand Down
15 changes: 15 additions & 0 deletions src/Model/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
/** @var bool|null Whether this edit was later reverted. */
protected ?bool $reverted;

/** @var bool|null Whether this edit is pending review (FlaggedRevs extension). */
protected ?bool $pending;

/** @var int Deletion status of the revision. */
protected int $deleted;

Expand Down Expand Up @@ -98,6 +101,9 @@
// Note that the Edit class knows nothing about it's value, and
// is not capable of detecting whether the given edit was actually reverted.
$this->reverted = isset($attrs['reverted']) ? (bool)$attrs['reverted'] : null;

// for FlaggedRevs
$this->pending = isset($attrs['is_pending']) ? (bool)$attrs['is_pending'] : null;
}

/**
Expand Down Expand Up @@ -264,6 +270,15 @@
return $this->sha;
}

/**
* Is this edit pending? (from flaggedrevs)
* @return bool|null
*/
public function isPending(): ?bool

Check warning on line 277 in src/Model/Edit.php

View check run for this annotation

Codecov / codecov/patch

src/Model/Edit.php#L277

Added line #L277 was not covered by tests
{
return $this->pending;

Check warning on line 279 in src/Model/Edit.php

View check run for this annotation

Codecov / codecov/patch

src/Model/Edit.php#L279

Added line #L279 was not covered by tests
}

/**
* Was this edit reported as having been reverted?
* The value for this is merely passed in from precomputed data.
Expand Down
19 changes: 16 additions & 3 deletions src/Model/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,18 +249,20 @@
}

/**
* List of extensions that are installed on the wiki.
* List of extensions that are installed on the given project instance (or this if not given).
* @param Project|null $project Optional, resorts to the current instance if not given.
* @return string[]
*/
public function getInstalledExtensions(): array
public function getInstalledExtensions(?Project $project = null): array

Check warning on line 256 in src/Model/Project.php

View check run for this annotation

Codecov / codecov/patch

src/Model/Project.php#L256

Added line #L256 was not covered by tests
{
$project = $project ?? $this;

Check warning on line 258 in src/Model/Project.php

View check run for this annotation

Codecov / codecov/patch

src/Model/Project.php#L258

Added line #L258 was not covered by tests
// Quick cache, valid only for the same request.
static $installedExtensions = null;
if (is_array($installedExtensions)) {
return $installedExtensions;
}

return $installedExtensions = $this->getRepository()->getInstalledExtensions($this);
return $installedExtensions = $this->getRepository()->getInstalledExtensions($project);

Check warning on line 265 in src/Model/Project.php

View check run for this annotation

Codecov / codecov/patch

src/Model/Project.php#L265

Added line #L265 was not covered by tests
}

/**
Expand All @@ -273,6 +275,17 @@
return in_array('PageTriage', $extensions);
}

/**
* Get if the given Project has the FlaggedRevs extensions
* (for pending changes)
* @return bool
*/
public function projectHasFlaggedRevs(Project $project) : bool

Check warning on line 283 in src/Model/Project.php

View check run for this annotation

Codecov / codecov/patch

src/Model/Project.php#L283

Added line #L283 was not covered by tests
{
$extensions = $this->getInstalledExtensions($project);
return in_array('FlaggedRevs', $extensions);

Check warning on line 286 in src/Model/Project.php

View check run for this annotation

Codecov / codecov/patch

src/Model/Project.php#L285-L286

Added lines #L285 - L286 were not covered by tests
}

/**
* Whether the project has temporary accounts enabled.
* @return bool
Expand Down
21 changes: 21 additions & 0 deletions src/Repository/GlobalContribsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,25 @@ public function getRevisions(
$whereClause = 'revs.rev_actor = '.$actorIds[$dbName];
}

$thisProject = $this->projectRepo->getProject($dbName);
if ($this->caProject->projectHasFlaggedRevs($thisProject)) {
/* If fp_reviewed == 1, this page has flaggedrevs activated but all of its revs are accepted.
If fp_pending_since is null (but fp_reviewed != 1), this page doesn't have flaggedrevs on.
And then >= as fp_pending_since is the timestamp of the oldest unaccepted rev. */
$frSelect = ",
(fp_reviewed != 1 &&
fp_pending_since IS NOT NULL &&
revs.rev_timestamp >= fp_pending_since
) as is_pending";
$frTable = $this->projectRepo->getTableName($dbName, "flaggedpages");
$frJoin = "
LEFT OUTER JOIN $frTable
ON fp_page_id = revs.rev_page";
} else {
$frSelect = "";
$frJoin = "";
}

$slice = $this->getDbList()[$dbName];
$queriesBySlice[$slice][] = "
SELECT
Expand Down Expand Up @@ -307,12 +326,14 @@ public function getRevisions(
)
LIMIT 1
) AS reverted
$frSelect
FROM $revisionTable AS revs
$ipcJoin
JOIN $pageTable AS page ON (rev_page = page_id)
JOIN $actorTable ON (actor_id = revs.rev_actor)
LEFT JOIN $revisionTable AS parentrevs ON (revs.rev_parent_id = parentrevs.rev_id)
LEFT OUTER JOIN $commentTable ON revs.rev_comment_id = comment_id
$frJoin
WHERE $whereClause
$namespaceCond
$revDateConditions";
Expand Down
3 changes: 2 additions & 1 deletion templates/globalContribs/result.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
{% set substr = user.ipSubstringFromCidr %}
{% for edit in gc.globalEdits %}
{% if edit.project.exists %}
<tr{% if edit.isReverted %} class="reverted-edit"{% endif %}>
<tr{% if (edit.isReverted or edit.isPending) %} class="{% if edit.isReverted %}reverted-edit{% endif %}{% if edit.isPending %} pending-edit{% endif %}"{% endif %}>
<td class="sort-entry--date contribs-row-date" data-value="{{ edit.utcTimestamp }}">
{{ wiki.diffLink(edit, edit.timestamp) }}
</td>
Expand All @@ -158,6 +158,7 @@
</td>
<td class="sort-entry--summary" data-value="{{ edit.comment }}">
{% if edit.isReverted %}<i class="text-info">({{ msg('reverted')|lower }})</i>&nbsp;{% endif %}
{% if edit.isPending %}<i class="text-info">({{ msg('pending')|lower }})</i>&nbsp;{% endif %}
{% if edit.deletedSummary %}
<i class="text-muted">{{ msg('edit-summary-removed') }}</i>
{% else %}
Expand Down
Loading