-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Universal-Omega
wants to merge
76
commits into
master
Choose a base branch
from
flagging
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
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 0116941
Move
Universal-Omega 3bee9b7
Move
Universal-Omega 9a82d2c
CI: lint code to MediaWiki standards
477eba9
Add
Universal-Omega 7589c9d
Perm
Universal-Omega fb70c0e
CI: lint code to MediaWiki standards
481f22e
Add
Universal-Omega f649933
-
Universal-Omega 6c3633c
Move
Universal-Omega 0d31a4c
Update
Universal-Omega 9eaba72
Add
Universal-Omega 4842a1c
CI: lint code to MediaWiki standards
f3011d0
Add cw_flags
Universal-Omega 744e94c
Add cw_flags
Universal-Omega b8a6e43
Fix
Universal-Omega 9868914
Fix
Universal-Omega ba8e6f8
Fix
Universal-Omega 0985295
Fix
Universal-Omega f9c91d8
Fix
Universal-Omega 459eaa6
Add
Universal-Omega 9a724e5
Fix
Universal-Omega 7e8bf7b
Add messages
Universal-Omega f24494d
Fix
Universal-Omega 3da07e6
Update
Universal-Omega da5a1a0
Add
Universal-Omega f5bd238
Add
Universal-Omega ee0a4ad
Fix
Universal-Omega 8a29dcb
Try
Universal-Omega e31eb7e
Fix
Universal-Omega 473e99c
Add
Universal-Omega 121cb7b
Add getUrl
Universal-Omega 22b0e6c
Use WikiManagerFactory
Universal-Omega 28549e1
-
Universal-Omega 754be70
Add check if request is more than 0
Universal-Omega 1b4a71f
-
Universal-Omega 2927e20
-
Universal-Omega 3e0f87b
+
Universal-Omega 89f21d8
-
Universal-Omega 704dabd
Use FlaggedWikis
Universal-Omega 6f6f0d7
Use FlaggedWikis
Universal-Omega 8658aa3
Use FlaggedWikis
Universal-Omega d293474
Use FlaggedWikis
Universal-Omega ea9ba75
Use FlaggedWikis
Universal-Omega 316af85
Fix
Universal-Omega 20fc524
Fix
Universal-Omega 58c66e5
Fix
Universal-Omega e5c8016
Fix
Universal-Omega 168642f
Add expiry
Universal-Omega 7120d99
try
Universal-Omega 93cb666
Try
Universal-Omega e988d54
CI: lint code to MediaWiki standards
98d01e7
Try
Universal-Omega c049eca
Try
Universal-Omega be67b4c
Try
Universal-Omega 1c78b4a
Try
Universal-Omega 044339f
CI: lint code to MediaWiki standards
0107536
Try
Universal-Omega 0008eca
Try
Universal-Omega f9c895f
Try
Universal-Omega 34cce69
OR
Universal-Omega fa4cddf
Try
Universal-Omega 14117a0
Fix
Universal-Omega c0efd7e
Add trackChange
Universal-Omega d722779
Merge branch 'master' into flagging
Universal-Omega f9d131d
Merge branch 'master' into flagging
Universal-Omega 635aaf8
Use expression builder
Universal-Omega 55ef224
-
Universal-Omega 3123f2a
Merge branch 'master' into flagging
Universal-Omega c676f24
-
Universal-Omega c28b931
Merge branch 'master' into flagging
Universal-Omega 006fb30
Add
Universal-Omega 0541260
Use virtual
Universal-Omega a1f1a9b
-
Universal-Omega 35ef1da
Update
Universal-Omega 8b78ecf
Add
Universal-Omega File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ | |
"CreateWiki": [ | ||
"CreateWiki" | ||
], | ||
"FlaggedWikis": [ | ||
"FlaggedWikis" | ||
], | ||
"RequestWiki": [ | ||
"RequestWiki" | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
); | ||
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'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?