forked from wikimedia/mediawiki-extensions-Thanks
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Upgrade extension Thanks to MW 1.43 | Pull all Fandom patches into Thanks 1.43 #11
Open
maaartyyynaa
wants to merge
43
commits into
REL1_43
Choose a base branch
from
REL1_43-fandom-changes
base: REL1_43
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.
Open
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
3bf77b2
Replaced Echo dependency from the core flow with a hook
d51e232
UGC-4012 Customize the extension to allow our styling
emkarcinos 59bb4c5
UGC-4012 Display thank links in RecentChanges
emkarcinos b904180
UGC-4012 Load JS files on mobile
emkarcinos 8f734c0
UGC-4012 PHPCS: Type hints and if simplification
emkarcinos 4d0afc5
UGC-4012 Enable thanks on Special:Contributions
emkarcinos d644b8d
Changed the extension JS to allow matching our designs
761ce63
UGC-4120 Disable upstream hook to override it
emkarcinos 074f785
Revert "UGC-4120 Disable upstream hook to override it"
maaartyyynaa 43c0447
UGC-4120 Disable upstream hook to override it
emkarcinos d503da4
Fixed null pointer exception on RecentChanges
95a0994
PHPCS
99ee461
Added thanks links on Recentchanges old changeslist
4e266e0
Revert "Added thanks links on Recentchanges old changeslist"
maaartyyynaa e431190
Added thanks links on Recentchanges old changeslist
b5e2ba4
UGC-4257 | Add wrapper to the thank link in `Special:Contributions`
tmusial99 3dc7139
UGC-4379 | Avoid fetching revision data one by one for RC entries
mszabo-wikia 4bf18b7
UGC-4319 Trigger addActionLinks on wikipage.content action
kasperekt a49596f
UGC-4319 Reload thanked state on content change
kasperekt 4971d94
UGC-4319 Observe wikipage.content only on Watchlist and Recentchanges
kasperekt 39d01e3
UGC-4533 Optimized backend cache for thanked links / localStorage for…
emkarcinos b10d16e
Revert "UGC-4533 Optimized backend cache for thanked links / localSto…
maaartyyynaa 03ba282
UGC-4533 Optimized backend cache for thanked links / localStorage for…
emkarcinos 9b77171
UGC-4573 Check permissions on desktop diff and special contributions …
dariuszpaluch 292ffe6
UGC-4573 Clean code for Thanks permissions
dariuszpaluch d06c50d
UGC-4573 Remove relation for external fandom class
dariuszpaluch 05b80e2
UGC-4573 Check user permission on AMC mobile history
dariuszpaluch 66e7cd5
Added thanks links on Recentchanges old changeslist
e6e21d5
UGC-4257 | Add wrapper to the thank link in `Special:Contributions`
tmusial99 b9302ab
UGC-4379 | Avoid fetching revision data one by one for RC entries
mszabo-wikia f2b5127
UGC-4319 Trigger addActionLinks on wikipage.content action
kasperekt 04fc4f5
UGC-4319 Reload thanked state on content change
kasperekt 172a9e4
UGC-4319 Observe wikipage.content only on Watchlist and Recentchanges
kasperekt 03f56d0
UGC-4533 Optimized backend cache for thanked links / localStorage for…
emkarcinos 1a8e43a
UGC-4573 Check permissions on desktop diff and special contributions …
dariuszpaluch 64e42a3
UGC-4573 Clean code for Thanks permissions
dariuszpaluch 75c63a6
UGC-4573 Remove relation for external fandom class
dariuszpaluch c22bda9
UGC-4573 Check user permission on AMC mobile history
dariuszpaluch f964994
PLATFORM-10109 | Thanks to MW 1.43 with custom patches - add fixes fo…
maaartyyynaa bdb10e0
feat(PLATFORM-10109): update Thanks extension
d874715
feat(PLATFORM-10109): reduce fork size
9f74b67
feat(PLATFORM-10109): remove duplicated Thanks link
97049bb
PLATFORM-10109 | Thanks to MW 1.43 - code review
maaartyyynaa 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
name: PHPUnit / PHPCS / Phan | ||
on: | ||
pull_request: | ||
branches: '**' | ||
|
||
push: | ||
branches: [ REL1_43 ] | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
matrix: | ||
php_version: ['8.0'] | ||
mw: ['REL1_43'] | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php_version }} | ||
# We don't run any coverage, so we should set this parameter to none | ||
# as this will disable xdebug which slows all processes significantly | ||
coverage: none | ||
extensions: ast | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Checkout Mediawiki | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: wikimedia/mediawiki | ||
path: mediawiki | ||
ref: ${{ matrix.mw }} | ||
|
||
- name: Checkout Echo (dependency) extension | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: wikimedia/mediawiki-extensions-Echo | ||
path: mediawiki/extensions/Echo | ||
|
||
- name: Checkout Flow (implicit dependency) extension | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: wikimedia/mediawiki-extensions-Flow | ||
path: mediawiki/extensions/Flow | ||
|
||
- name: Checkout MobileFrontend (implicit dependency) extension | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: wikimedia/mediawiki-extensions-MobileFrontend | ||
path: mediawiki/extensions/MobileFrontend | ||
|
||
- name: Checkout CheckUser (implicit dependency) extension | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: wikimedia/mediawiki-extensions-CheckUser | ||
path: mediawiki/extensions/CheckUser | ||
|
||
- name: Checkout Thanks extension | ||
uses: actions/checkout@v2 | ||
with: | ||
path: mediawiki/extensions/Thanks | ||
|
||
- name: Cache Composer packages | ||
id: composer-cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: vendor | ||
key: ${{ runner.os }}-php-v3-${{ hashFiles('**/composer.lock') }} | ||
|
||
- name: Install composer dependencies | ||
if: steps.composer-cache.outputs.cache-hit != 'true' | ||
working-directory: ./mediawiki/extensions/Thanks | ||
run: composer install --prefer-dist --no-progress | ||
|
||
- name: Run PHPCS | ||
working-directory: ./mediawiki/extensions/Thanks | ||
run: composer phpcs |
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 |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
use Article; | ||
use DatabaseLogEntry; | ||
use DifferenceEngine; | ||
use Fandom\FandomThanks\ThanksCache; | ||
use Fandom\FandomThanks\ThanksPermissions; | ||
use LogEventsList; | ||
use LogPage; | ||
use MediaWiki\Api\ApiModuleManager; | ||
|
@@ -63,14 +65,15 @@ class Hooks implements | |
PageHistoryPager__doBatchLookupsHook, | ||
ChangesListInitRowsHook | ||
{ | ||
private Config $config; | ||
private GenderCache $genderCache; | ||
private PermissionManager $permissionManager; | ||
private RevisionLookup $revisionLookup; | ||
private UserFactory $userFactory; | ||
private UserOptionsManager $userOptionsManager; | ||
protected Config $config; | ||
protected GenderCache $genderCache; | ||
protected PermissionManager $permissionManager; | ||
protected RevisionLookup $revisionLookup; | ||
protected UserFactory $userFactory; | ||
protected UserOptionsManager $userOptionsManager; | ||
|
||
public function __construct( | ||
protected ThanksCache $thanksCache, | ||
Config $config, | ||
GenderCache $genderCache, | ||
PermissionManager $permissionManager, | ||
|
@@ -100,6 +103,11 @@ public function onHistoryTools( | |
$oldRevisionRecord, | ||
$userIdentity | ||
) { | ||
// [UGC-4257] Don't show thank links if user doesn't have specific permission | ||
if ( !ThanksPermissions::checkUserPermissionsForThanks( RequestContext::getMain()->getOutput() ) ) { | ||
return; | ||
} | ||
|
||
$this->insertThankLink( $revisionRecord, | ||
$links, $userIdentity ); | ||
} | ||
|
@@ -118,6 +126,13 @@ public function onDiffTools( | |
$oldRevisionRecord, | ||
$userIdentity | ||
) { | ||
$out = RequestContext::getMain()->getOutput(); | ||
|
||
// [UGC-4257] Don't show thank links if user doesn't have specific permission | ||
if ( !ThanksPermissions::checkUserPermissionsForThanks( $out ) ) { | ||
return; | ||
} | ||
Comment on lines
+129
to
+134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (non-blocking), same as above, invoke a hook |
||
|
||
// Don't allow thanking for a diff that includes multiple revisions | ||
// This does a query that is too expensive for history rows (T284274) | ||
$previous = $this->revisionLookup->getPreviousRevision( $revisionRecord ); | ||
|
@@ -245,16 +260,18 @@ protected function generateThankElement( | |
bool $isPrimaryButton = false | ||
) { | ||
$useCodex = RequestContext::getMain()->getSkin()->getSkinName() === 'minerva'; | ||
// Check if the user has already thanked for this revision or log entry. | ||
// Session keys are backwards-compatible, and are also used in the ApiCoreThank class. | ||
$sessionKey = ( $type === 'revision' ) ? $id : $type . $id; | ||
$class = $useCodex ? 'cdx-button cdx-button--fake-button cdx-button--fake-button--enabled' : ''; | ||
if ( $isPrimaryButton && $useCodex ) { | ||
$class .= ' cdx-button--weight-primary cdx-button--action-progressive'; | ||
} | ||
if ( $sender->getRequest()->getSessionData( "thanks-thanked-$sessionKey" ) ) { | ||
// Check if the user has already thanked for this revision or log entry. | ||
/** | ||
* Fandom change - start - UGC-4533 - Cache thanks data in session in a better way | ||
* @author Mkostrzewski | ||
*/ | ||
if ( $this->thanksCache->haveThanked( RequestContext::getMain(), $sender->getActorId(), $id, $type ) ) { | ||
// Fandom change - end | ||
$class .= ' mw-thanks-thanked'; | ||
|
||
return Html::element( | ||
'span', | ||
[ 'class' => $class ], | ||
|
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
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.
(non-blocking) This can be replaced with a hook invocation, that way Fandom code wouldn't be coupled with this class anymore. It's likely that the hook can be upstreamed, which will reduce the fork size in future versions.