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

Upgrade extension Thanks to MW 1.43 | Pull all Fandom patches into Thanks 1.43 #11

Open
wants to merge 43 commits into
base: REL1_43
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Mar 30, 2023
d51e232
UGC-4012 Customize the extension to allow our styling
emkarcinos Apr 18, 2023
59bb4c5
UGC-4012 Display thank links in RecentChanges
emkarcinos Apr 20, 2023
b904180
UGC-4012 Load JS files on mobile
emkarcinos Apr 20, 2023
8f734c0
UGC-4012 PHPCS: Type hints and if simplification
emkarcinos Apr 20, 2023
4d0afc5
UGC-4012 Enable thanks on Special:Contributions
emkarcinos Apr 20, 2023
d644b8d
Changed the extension JS to allow matching our designs
Apr 27, 2023
761ce63
UGC-4120 Disable upstream hook to override it
emkarcinos Apr 28, 2023
074f785
Revert "UGC-4120 Disable upstream hook to override it"
maaartyyynaa Jan 24, 2025
43c0447
UGC-4120 Disable upstream hook to override it
emkarcinos Apr 28, 2023
d503da4
Fixed null pointer exception on RecentChanges
May 12, 2023
95a0994
PHPCS
May 12, 2023
99ee461
Added thanks links on Recentchanges old changeslist
May 23, 2023
4e266e0
Revert "Added thanks links on Recentchanges old changeslist"
maaartyyynaa Jan 24, 2025
e431190
Added thanks links on Recentchanges old changeslist
May 23, 2023
b5e2ba4
UGC-4257 | Add wrapper to the thank link in `Special:Contributions`
tmusial99 Jun 20, 2023
3dc7139
UGC-4379 | Avoid fetching revision data one by one for RC entries
mszabo-wikia Aug 30, 2023
4bf18b7
UGC-4319 Trigger addActionLinks on wikipage.content action
kasperekt Sep 4, 2023
a49596f
UGC-4319 Reload thanked state on content change
kasperekt Sep 6, 2023
4971d94
UGC-4319 Observe wikipage.content only on Watchlist and Recentchanges
kasperekt Sep 6, 2023
39d01e3
UGC-4533 Optimized backend cache for thanked links / localStorage for…
emkarcinos Oct 3, 2023
b10d16e
Revert "UGC-4533 Optimized backend cache for thanked links / localSto…
maaartyyynaa Jan 24, 2025
03ba282
UGC-4533 Optimized backend cache for thanked links / localStorage for…
emkarcinos Oct 3, 2023
9b77171
UGC-4573 Check permissions on desktop diff and special contributions …
dariuszpaluch Oct 6, 2023
292ffe6
UGC-4573 Clean code for Thanks permissions
dariuszpaluch Oct 9, 2023
d06c50d
UGC-4573 Remove relation for external fandom class
dariuszpaluch Oct 10, 2023
05b80e2
UGC-4573 Check user permission on AMC mobile history
dariuszpaluch Oct 17, 2023
66e7cd5
Added thanks links on Recentchanges old changeslist
May 23, 2023
e6e21d5
UGC-4257 | Add wrapper to the thank link in `Special:Contributions`
tmusial99 Jun 20, 2023
b9302ab
UGC-4379 | Avoid fetching revision data one by one for RC entries
mszabo-wikia Aug 30, 2023
f2b5127
UGC-4319 Trigger addActionLinks on wikipage.content action
kasperekt Sep 4, 2023
04fc4f5
UGC-4319 Reload thanked state on content change
kasperekt Sep 6, 2023
172a9e4
UGC-4319 Observe wikipage.content only on Watchlist and Recentchanges
kasperekt Sep 6, 2023
03f56d0
UGC-4533 Optimized backend cache for thanked links / localStorage for…
emkarcinos Oct 3, 2023
1a8e43a
UGC-4573 Check permissions on desktop diff and special contributions …
dariuszpaluch Oct 6, 2023
64e42a3
UGC-4573 Clean code for Thanks permissions
dariuszpaluch Oct 9, 2023
75c63a6
UGC-4573 Remove relation for external fandom class
dariuszpaluch Oct 10, 2023
c22bda9
UGC-4573 Check user permission on AMC mobile history
dariuszpaluch Oct 17, 2023
f964994
PLATFORM-10109 | Thanks to MW 1.43 with custom patches - add fixes fo…
maaartyyynaa Jan 24, 2025
bdb10e0
feat(PLATFORM-10109): update Thanks extension
Jan 27, 2025
d874715
feat(PLATFORM-10109): reduce fork size
Jan 28, 2025
9f74b67
feat(PLATFORM-10109): remove duplicated Thanks link
Jan 29, 2025
97049bb
PLATFORM-10109 | Thanks to MW 1.43 - code review
maaartyyynaa Feb 4, 2025
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
78 changes: 78 additions & 0 deletions .github/workflows/php-pr-checks.yml
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
14 changes: 10 additions & 4 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
"license-name": "MIT",
"type": "other",
"requires": {
"MediaWiki": ">= 1.43",
"extensions": {
"Echo": "*"
}
"MediaWiki": ">= 1.43"
},
"DefaultUserOptions": {
"echo-subscriptions-web-edit-thank": true,
Expand Down Expand Up @@ -81,6 +78,10 @@
"dependencies": [
"mediawiki.cookie",
"mediawiki.api"
],
"targets": [
"desktop",
"mobile"
]
},
"ext.thanks.corethank": {
Expand All @@ -106,6 +107,10 @@
"mediawiki.api",
"jquery.confirmable",
"ext.thanks"
],
"targets": [
"desktop",
"mobile"
]
},
"ext.thanks.flowthank": {
Expand Down Expand Up @@ -161,6 +166,7 @@
"main": {
"class": "MediaWiki\\Extension\\Thanks\\Hooks",
"services": [
"Fandom\\FandomThanks\\ThanksCache",
"MainConfig",
"GenderCache",
"PermissionManager",
Expand Down
32 changes: 20 additions & 12 deletions includes/Api/ApiCoreThank.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
namespace MediaWiki\Extension\Thanks\Api;

use DatabaseLogEntry;
use Fandom\FandomThanks\ThanksCache;
use LogEntry;
use MediaWiki\Api\ApiBase;
use MediaWiki\Api\ApiMain;
use MediaWiki\Extension\Notifications\DiscussionParser;
use MediaWiki\Extension\Notifications\Model\Event;
use MediaWiki\Context\RequestContext;
use MediaWiki\Extension\Thanks\Storage\Exceptions\InvalidLogType;
use MediaWiki\Extension\Thanks\Storage\Exceptions\LogDeleted;
use MediaWiki\Extension\Thanks\Storage\LogStore;
use MediaWiki\MediaWikiServices;
use MediaWiki\Permissions\PermissionManager;
use MediaWiki\Revision\RevisionRecord;
use MediaWiki\Revision\RevisionStore;
Expand Down Expand Up @@ -93,7 +94,6 @@ public function execute() {
}
if ( $type === 'rev' ) {
$revision = $this->getRevisionFromId( $id );
$excerpt = DiscussionParser::getEditExcerpt( $revision, $this->getLanguage() );
$title = $this->getTitleFromRevision( $revision );
$this->dieOnUserBlockedFromTitle( $user, $title );

Expand All @@ -115,7 +115,7 @@ public function execute() {
$user,
$type,
$id,
$excerpt,
'', // We don't need the excerpt for our notification, and it would come from Echo
$recipient,
$this->getSourceFromParams( $params ),
$title,
Expand All @@ -132,11 +132,13 @@ public function execute() {
* @return bool
*/
protected function userAlreadySentThanks( User $user, $type, $id ) {
if ( $type === 'rev' ) {
// For b/c with old-style keys
$type = '';
}
return (bool)$user->getRequest()->getSessionData( "thanks-thanked-$type$id" );
/**
* Fandom change - start - UGC-4533 - Cache thanks data in session in a better way
* @author Mkostrzewski
*/
return MediaWikiServices::getInstance()->getService( ThanksCache::class )
->haveThanked( RequestContext::getMain(), $user->getActorId(), $id, $type );
// Fandom change - end
}

private function getRevisionFromId( $revId ) {
Expand Down Expand Up @@ -241,8 +243,8 @@ protected function sendThanks(
return;
}

// Create the notification via Echo extension
Event::create( [
// Create notification via hook
$this->getHookContainer()->run( 'ThankCreated', [
'type' => 'edit-thank',
'title' => $title,
'extra' => [
Expand All @@ -256,7 +258,13 @@ protected function sendThanks(
] );

// And mark the thank in session for a cheaper check to prevent duplicates (Phab:T48690).
$user->getRequest()->setSessionData( "thanks-thanked-$type$id", true );
/**
* Fandom change - start - UGC-4533 - Cache thanks data in session in a better way
* @author Mkostrzewski
*/
MediaWikiServices::getInstance()->getService( ThanksCache::class )
->appendUserThanks( $this->getContext(), $user->getActorId(), $uniqueId );
// Fandom change - end
// Set success message
$this->markResultSuccess( $recipient->getName() );
$this->logThanks( $user, $recipient, $uniqueId );
Expand Down
39 changes: 28 additions & 11 deletions includes/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

Comment on lines +107 to +110

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.

$this->insertThankLink( $revisionRecord,
$links, $userIdentity );
}
Expand All @@ -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

Choose a reason for hiding this comment

The 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 );
Expand Down Expand Up @@ -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 ],
Expand Down
20 changes: 18 additions & 2 deletions modules/ext.thanks.corethank.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,14 @@
( new mw.Api() ).postWithToken( 'csrf', apiParams )
.then(
// Success
() => {
$thankElement.before( mw.message( 'thanks-thanked', mw.user, $thankLink.data( 'recipient-gender' ) ).escaped() );
() => {
// FANDOM change. Gave the "before" element a class, so we can style it.
$thankElement.before(
`<span class="mw-thanks-thank-confirmation">
${mw.message( 'thanks-thanked', mw.user, $thankLink.data( 'recipient-gender' ) ).escaped()}
</span>`
);
// FANDOM change end.
$thankElement.remove();
mw.thanks.thanked.push( $thankLink.attr( attrName ) );
},
Expand Down Expand Up @@ -133,5 +139,15 @@

mw.hook( 'wikipage.content' ).add( ( $content ) => {
addActionToLinks( $content );
reloadThankedState();
} );

// Add `wikipage.content` hook only to special pages that are dynamically reloading DOM
const specialPageName = mw.config.get( 'wgCanonicalSpecialPageName' );
if ( specialPageName === 'Recentchanges' || specialPageName === 'Watchlist' ) {
mw.hook( 'wikipage.content' ).add( function ( $content ) {
addActionToLinks( $content );
reloadThankedState();
} );
}
}() );
14 changes: 12 additions & 2 deletions modules/ext.thanks.thank.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
* @return {string[]} Thanks IDs
*/
load: function ( cookieName ) {
const cookie = mw.cookie.get( cookieName || this.cookieName );
/**
* Fandom change - start - UGC-4533 - Use localStorage instead of a cookie
* @author Mkostrzewski
*/
const cookie = mw.storage.get( cookieName || this.cookieName );
// Fandom change - end
if ( cookie === null ) {
return [];
}
Expand All @@ -31,7 +36,12 @@
if ( saved.length > this.maxHistory ) { // prevent forever growing
saved = saved.slice( saved.length - this.maxHistory );
}
mw.cookie.set( cookieName || this.cookieName, escape( saved.join( ',' ) ) );
/**
* Fandom change - start - UGC-4533 - Use localStorage instead of a cookie
* @author Mkostrzewski
*/
mw.storage.set( cookieName || this.cookieName, escape( saved.join( ',' ) ) );
// Fandom change - end
},

/**
Expand Down