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

Add support for request flagging #606

Draft
wants to merge 76 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
304ec68
Add support for request flagging
Universal-Omega Oct 22, 2024
0116941
Move
Universal-Omega Oct 22, 2024
3bee9b7
Move
Universal-Omega Oct 22, 2024
9a82d2c
CI: lint code to MediaWiki standards
Oct 22, 2024
477eba9
Add
Universal-Omega Oct 22, 2024
7589c9d
Perm
Universal-Omega Oct 22, 2024
fb70c0e
CI: lint code to MediaWiki standards
Oct 22, 2024
481f22e
Add
Universal-Omega Oct 22, 2024
f649933
-
Universal-Omega Oct 22, 2024
6c3633c
Move
Universal-Omega Oct 22, 2024
0d31a4c
Update
Universal-Omega Oct 22, 2024
9eaba72
Add
Universal-Omega Oct 22, 2024
4842a1c
CI: lint code to MediaWiki standards
Oct 22, 2024
f3011d0
Add cw_flags
Universal-Omega Oct 22, 2024
744e94c
Add cw_flags
Universal-Omega Oct 22, 2024
b8a6e43
Fix
Universal-Omega Oct 22, 2024
9868914
Fix
Universal-Omega Oct 22, 2024
ba8e6f8
Fix
Universal-Omega Oct 22, 2024
0985295
Fix
Universal-Omega Oct 22, 2024
f9c91d8
Fix
Universal-Omega Oct 22, 2024
459eaa6
Add
Universal-Omega Oct 22, 2024
9a724e5
Fix
Universal-Omega Oct 22, 2024
7e8bf7b
Add messages
Universal-Omega Oct 22, 2024
f24494d
Fix
Universal-Omega Oct 22, 2024
3da07e6
Update
Universal-Omega Oct 22, 2024
da5a1a0
Add
Universal-Omega Oct 22, 2024
f5bd238
Add
Universal-Omega Oct 22, 2024
ee0a4ad
Fix
Universal-Omega Oct 22, 2024
8a29dcb
Try
Universal-Omega Oct 22, 2024
e31eb7e
Fix
Universal-Omega Oct 22, 2024
473e99c
Add
Universal-Omega Oct 22, 2024
121cb7b
Add getUrl
Universal-Omega Oct 22, 2024
22b0e6c
Use WikiManagerFactory
Universal-Omega Oct 22, 2024
28549e1
-
Universal-Omega Oct 22, 2024
754be70
Add check if request is more than 0
Universal-Omega Oct 22, 2024
1b4a71f
-
Universal-Omega Oct 22, 2024
2927e20
-
Universal-Omega Oct 22, 2024
3e0f87b
+
Universal-Omega Oct 22, 2024
89f21d8
-
Universal-Omega Oct 22, 2024
704dabd
Use FlaggedWikis
Universal-Omega Oct 22, 2024
6f6f0d7
Use FlaggedWikis
Universal-Omega Oct 22, 2024
8658aa3
Use FlaggedWikis
Universal-Omega Oct 22, 2024
d293474
Use FlaggedWikis
Universal-Omega Oct 22, 2024
ea9ba75
Use FlaggedWikis
Universal-Omega Oct 22, 2024
316af85
Fix
Universal-Omega Oct 22, 2024
20fc524
Fix
Universal-Omega Oct 22, 2024
58c66e5
Fix
Universal-Omega Oct 22, 2024
e5c8016
Fix
Universal-Omega Oct 22, 2024
168642f
Add expiry
Universal-Omega Oct 22, 2024
7120d99
try
Universal-Omega Oct 22, 2024
93cb666
Try
Universal-Omega Oct 22, 2024
e988d54
CI: lint code to MediaWiki standards
Oct 22, 2024
98d01e7
Try
Universal-Omega Oct 22, 2024
c049eca
Try
Universal-Omega Oct 22, 2024
be67b4c
Try
Universal-Omega Oct 22, 2024
1c78b4a
Try
Universal-Omega Oct 22, 2024
044339f
CI: lint code to MediaWiki standards
Oct 22, 2024
0107536
Try
Universal-Omega Oct 22, 2024
0008eca
Try
Universal-Omega Oct 22, 2024
f9c895f
Try
Universal-Omega Oct 22, 2024
34cce69
OR
Universal-Omega Oct 22, 2024
fa4cddf
Try
Universal-Omega Oct 22, 2024
14117a0
Fix
Universal-Omega Oct 22, 2024
c0efd7e
Add trackChange
Universal-Omega Oct 23, 2024
d722779
Merge branch 'master' into flagging
Universal-Omega Oct 27, 2024
f9d131d
Merge branch 'master' into flagging
Universal-Omega Oct 28, 2024
635aaf8
Use expression builder
Universal-Omega Nov 2, 2024
55ef224
-
Universal-Omega Nov 2, 2024
3123f2a
Merge branch 'master' into flagging
Universal-Omega Nov 5, 2024
c676f24
-
Universal-Omega Nov 20, 2024
c28b931
Merge branch 'master' into flagging
Universal-Omega Nov 20, 2024
006fb30
Add
Universal-Omega Nov 20, 2024
0541260
Use virtual
Universal-Omega Nov 20, 2024
a1f1a9b
-
Universal-Omega Nov 20, 2024
35ef1da
Update
Universal-Omega Nov 20, 2024
8b78ecf
Add
Universal-Omega Nov 20, 2024
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
10 changes: 10 additions & 0 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@
"WikiManagerFactory"
]
},
"FlaggedWikis": {
"class": "Miraheze\\CreateWiki\\RequestWiki\\Specials\\SpecialFlaggedWikis",
"services": [
"ConnectionProvider",
"CreateWikiDatabaseUtils",
"PermissionManager",
"UserFactory",
"WikiManagerFactory"
]
},
"RequestWiki": {
"class": "Miraheze\\CreateWiki\\RequestWiki\\Specials\\SpecialRequestWiki",
"services": [
Expand Down
3 changes: 3 additions & 0 deletions i18n/aliases/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"CreateWiki": [
"CreateWiki"
],
"FlaggedWikis": [
"FlaggedWikis"
],
"RequestWiki": [
"RequestWiki"
],
Expand Down
7 changes: 7 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
"createwiki-error-requestcountwarn": "'''WARNING:''' [[User:$2|$2]] has already [[Special:Log/farmer/$2|requested]] $1 wikis.",
"createwiki-error-subdomaintaken": "The subdomain you requested is already taken. Please select another subdomain and try again.",
"createwiki-extensionname": "CreateWiki",
"createwiki-flaggedwikis-label-actor": "Flagged by",
"createwiki-flaggedwikis-label-reason": "Flagged reason",
"createwiki-flaggedwikis-label-request": "Flagged request",
"createwiki-flaggedwikis-label-timestamp": "Flagged at",
"createwiki-flaggedwikis-label-wiki": "Flagged wiki",
"createwiki-help-agreement": "Failure to follow these policies may lead to your wiki being closed.",
"createwiki-help-bio": "Make sure to follow this farm's policy on covering people.",
"createwiki-help-category": "The categorization of this wiki will reflect in places such as the global wiki directory.",
Expand Down Expand Up @@ -74,6 +79,8 @@
"farmer-log-name": "Farmer log",
"farmersuppression-log-header": "This is a private log tracking usage of the wiki request suppression function.",
"farmersuppression-log-name": "Suppressed wiki requests log",
"flaggedwikis": "Flagged wikis",
"flaggedwikis-info": "This page allows you to flag wikis and view all wikis that have already been flagged for later review.",
"ipb-action-requestwiki": "Requesting wikis",
"log-action-filter-farmer": "Type of action:",
"log-action-filter-farmer-comment": "New comment on wiki request",
Expand Down
8 changes: 8 additions & 0 deletions includes/Hooks/Handlers/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public function onLoadExtensionSchemaUpdates( $updater ) {
true,
] );

$updater->addExtensionUpdateOnVirtualDomain( [
'virtual-createwiki-central',
'addTable',
'cw_flags',
"$dir/cw_flags.sql",
true,
] );

$updater->addExtensionUpdateOnVirtualDomain( [
'virtual-createwiki',
'addTable',
Expand Down
140 changes: 140 additions & 0 deletions includes/RequestWiki/FlaggedWikisPager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?php

namespace Miraheze\CreateWiki\RequestWiki;

use MediaWiki\Context\IContextSource;
use MediaWiki\Html\Html;
use MediaWiki\Linker\Linker;
use MediaWiki\Linker\LinkRenderer;
use MediaWiki\Pager\TablePager;
use MediaWiki\SpecialPage\SpecialPage;
use MediaWiki\User\UserFactory;
use Miraheze\CreateWiki\Services\WikiManagerFactory;
use Wikimedia\Rdbms\IConnectionProvider;

class FlaggedWikisPager extends TablePager {

private LinkRenderer $linkRenderer;
private UserFactory $userFactory;
private WikiManagerFactory $wikiManagerFactory;

public function __construct(
IContextSource $context,
IConnectionProvider $connectionProvider,
LinkRenderer $linkRenderer,
UserFactory $userFactory,
WikiManagerFactory $wikiManagerFactory
) {
parent::__construct( $context, $linkRenderer );

$this->mDb = $connectionProvider->getReplicaDatabase( 'virtual-createwiki-central' );

$this->linkRenderer = $linkRenderer;
$this->userFactory = $userFactory;
$this->wikiManagerFactory = $wikiManagerFactory;
}

/** @inheritDoc */
public function getFieldNames(): array {
return [
'cw_flag_timestamp' => $this->msg( 'createwiki-flaggedwikis-label-timestamp' )->text(),
'cw_id' => $this->msg( 'createwiki-flaggedwikis-label-request' )->text(),
'cw_flag_dbname' => $this->msg( 'createwiki-flaggedwikis-label-wiki' )->text(),
'cw_flag_actor' => $this->msg( 'createwiki-flaggedwikis-label-actor' )->text(),
'cw_flag_reason' => $this->msg( 'createwiki-flaggedwikis-label-reason' )->text(),
];
}

/** @inheritDoc */
public function formatValue( $name, $value ): string {
$row = $this->getCurrentRow();

switch ( $name ) {
case 'cw_flag_timestamp':
$formatted = $this->escape( $this->getLanguage()->userTimeAndDate(
$row->cw_flag_timestamp, $this->getUser()
) );
break;
case 'cw_id':
if ( $row->cw_id > 0 ) {
$formatted = $this->linkRenderer->makeLink(
SpecialPage::getTitleValueFor( 'RequestWikiQueue', $row->cw_id ),
"#{$row->cw_id}"
);
break;
}

$formatted = '-';
break;
case 'cw_flag_reason':
$formatted = $this->escape( $row->cw_flag_reason );
break;
case 'cw_flag_actor':
$formatted = Linker::userLink(
$this->userFactory->newFromActorId( $row->cw_flag_actor )->getId(),
$this->userFactory->newFromActorId( $row->cw_flag_actor )->getName()
Comment on lines +74 to +75
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps use an intermediary variable to avoid having to call UserFactory::newFromActorId() twice?

);
break;
case 'cw_flag_dbname':
$wikiManager = $this->wikiManagerFactory->newInstance( $row->cw_flag_dbname );
if ( $wikiManager->exists() ) {
// TODO: when we require 1.43, use LinkRenderer::makeExternalLink
$formatted = Html::element( 'a', [
'href' => $wikiManager->getUrl()
], $wikiManager->getUrl() );
break;
}

$formatted = $this->escape( $row->cw_flag_dbname );
break;
default:
$formatted = $this->escape( "Unable to format {$name}" );
}

return $formatted;
}

/**
* Safely HTML-escapes $value
*/
private function escape( string $value ): string {
return htmlspecialchars( $value, ENT_QUOTES, 'UTF-8', false );
}

/** @inheritDoc */
public function getQueryInfo(): array {
$dbr = $this->getDatabase();

$info = [
'tables' => [
'cw_flags',
],
'fields' => [
'cw_id',
'cw_flag_actor',
'cw_flag_dbname',
'cw_flag_reason',
'cw_flag_timestamp',
],
'conds' => [
// TODO: all allowed visibilities
$dbr->expr( 'cw_flag_visibility', '=', 0 ),
$dbr->expr( 'cw_flag_expiry', '=', 0 )
->or( 'cw_flag_expiry', '>', $dbr->timestamp() )
],
'joins_conds' => [],
];

return $info;
}

/** @inheritDoc */
public function getDefaultSort(): string {
return 'cw_flag_timestamp';
}

/** @inheritDoc */
public function isFieldSortable( $name ): bool {
return $name !== 'cw_flag_actor';
}
}
21 changes: 21 additions & 0 deletions includes/RequestWiki/RequestWikiRequestViewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,20 @@ public function getFormDescriptor(): array {
'default' => $this->wikiRequestManager->isLocked(),
'section' => 'handling',
],
'handle-flag' => [
'type' => 'check',
'label-message' => 'createwiki-label-flag',
'default' => (bool)$this->wikiRequestManager->getFlaggedReason(),
'section' => 'handling',
],
'handle-flag-reason' => [
'type' => 'text',
'label-message' => 'createwiki-label-flag-reason',
'hide-if' => [ '!==', 'handle-flag', '1' ],
'default' => $this->wikiRequestManager->getFlaggedReason(),
'required' => true,
'section' => 'handling',
],
'handle-changevisibility' => [
'type' => 'check',
'label-message' => 'revdelete-legend',
Expand Down Expand Up @@ -609,6 +623,13 @@ protected function submitForm(
}
}

if ( $formData['handle-flag'] ?? false ) {
$this->wikiRequestManager->addFlaggedRequest(
$formData['handle-flag-reason'],
$user
);
}

// Handle locking wiki request
if ( $this->wikiRequestManager->isLocked() !== (bool)$formData['handle-lock'] ) {
$this->wikiRequestManager->setLocked( (bool)$formData['handle-lock'] );
Expand Down
Loading
Loading