Special:MobileDIff no longer exists so remove associated code

Bug: T360389
Change-Id: I0cd7e1269beb707b8e98d37e824dc260c8e670ea
This commit is contained in:
Jon Robson 2024-03-18 17:13:47 -07:00
parent 9a6def1004
commit b119a36f62
7 changed files with 2 additions and 281 deletions

View file

@ -103,30 +103,6 @@
"ext.thanks"
]
},
"ext.thanks.mobilediff": {
"styles": [
"ext.thanks.mobilediff.less"
],
"scripts": [
"ext.thanks.mobilediff.js"
],
"messages": [
"thanks-button-action-queued",
"thanks-button-action-cancel",
"thanks-button-action-completed",
"thanks-button-thank",
"thanks-button-thanked",
"thanks-error-invalidrevision",
"thanks-error-ratelimited",
"thanks-error-undefined",
"thanks-thanked-notice"
],
"dependencies": [
"mobile.startup",
"mediawiki.api",
"mediawiki.jqueryMsg"
]
},
"ext.thanks.flowthank": {
"scripts": [
"jquery.findWithParent.js",
@ -154,19 +130,16 @@
"localBasePath": "tests/qunit",
"remoteExtPath": "Thanks/tests/qunit",
"scripts": [
"test_ext.thanks.thank.js",
"test_ext.thanks.mobilediff.js"
"test_ext.thanks.thank.js"
],
"dependencies": [
"ext.thanks",
"ext.thanks.mobilediff"
"ext.thanks"
]
},
"Hooks": {
"ApiMain::moduleManager": "main",
"BeforeCreateEchoEvent": "echo",
"BeforePageDisplay": "main",
"BeforeSpecialMobileDiffDisplay": "mobile-frontend",
"DiffTools": "main",
"DifferenceEngineViewHeader": "main",
"EchoGetBundleRules": "echo",
@ -189,13 +162,6 @@
"UserOptionsManager"
]
},
"mobile-frontend": {
"class": "MediaWiki\\Extension\\Thanks\\MobileFrontendHandler",
"services": [
"MainConfig",
"UserFactory"
]
},
"echo": {
"class": "MediaWiki\\Extension\\Thanks\\EchoHooks"
}

View file

@ -9,9 +9,6 @@
"thanks-thanked": "{{GENDER:$1|{{GENDER:$2|thanked}}}}",
"thanks-button-thank": "{{GENDER:$1|{{GENDER:$2|Thank}}}}",
"thanks-button-thanked": "{{GENDER:$1|{{GENDER:$2|Thanked}}}}",
"thanks-button-action-queued": "{{GENDER:$1|{{GENDER:$2|Thanking}}}} $1…",
"thanks-button-action-cancel": "Cancel",
"thanks-button-action-completed": "You {{GENDER:$1|{{GENDER:$2|thanked}}}} $1",
"thanks-error-undefined": "Thank action failed (error code: $1). Please try again.",
"thanks-error-invalid-log-id": "Log entry not found",
"thanks-error-invalid-log-type": "Log type '$1' is not in the list of permitted log types.",

View file

@ -22,9 +22,6 @@
"thanks-thanked": "This message immediately replaces the message {{msg-mw|Thanks-thank}} after it's pressed. It means that the thanking operation has been completed. It can be translated as \"''thanked''\" in \"You ''thanked'' the user\" or \"The user has just been ''thanked''\" - whatever is appropriate to your language.\n\nFor languages that need it, the gender of each of the thanked and thanking users is available.\n\nParameters:\n* $1 - The user that is thanking\n* $2 - The user that has been thanked\n\n{{Identical|Thanked}}",
"thanks-button-thank": "Text of a button to thank another user. Same as {{msg-mw|Thanks-thank}}, but the context is in a button.\n\nFor languages that need it, the gender of each of the thanked and thanking users is available.\n\nParameters:\n* $1 - The user that is thanking\n* $2 - The user that is being thanked\n\n{{Identical|Thank}}",
"thanks-button-thanked": "This message immediately replaces the message {{msg-mw|Thanks-button-thank}} after it's pressed. It means that the thanking operation has been completed. Same as {{msg-mw|Thanks-thanked}}, but the context is in a button.\n\nFor languages that need it, the gender of each of the thanked and thanking users is available.\n\nParameters:\n* $1 - The user that is thanking\n* $2 - The user that has been thanked\n\n{{Identical|Thanked}}",
"thanks-button-action-queued": "Informs the user the thanks will happen ($1)\n\nParameters:\n* $1 - username \n* $2 - gender",
"thanks-button-action-cancel": "Follows {{msg-mw|thanks-button-action-queued}} and is clickable to cancel the action.\n{{Identical|Cancel}}",
"thanks-button-action-completed": "You {{GENDER:$1|{{GENDER:$2|thanked}}}} $1",
"thanks-error-undefined": "Error message that is displayed when the thank action fails. $1 is the error code returned by the API (an English string).",
"thanks-error-invalid-log-id": "Error message that is displayed when the thank action can't find the log entry it's supposed to thank for.",
"thanks-error-invalid-log-type": "Error message that is displayed when thanks is attempted for a log entry of a non-allowed type. $1 is the offending log type.",

View file

@ -1,63 +0,0 @@
<?php
namespace MediaWiki\Extension\Thanks;
use ExtensionRegistry;
use MediaWiki\Config\Config;
use MediaWiki\Output\OutputPage;
use MediaWiki\User\UserFactory;
use MobileContext;
use MobileFrontend\Hooks\BeforeSpecialMobileDiffDisplayHook;
/**
* HookHandler for extension MobileFrontend
*
* @file
* @ingroup Extensions
*/
class MobileFrontendHandler implements
BeforeSpecialMobileDiffDisplayHook
{
private Config $config;
private UserFactory $userFactory;
public function __construct(
Config $config,
UserFactory $userFactory
) {
$this->config = $config;
$this->userFactory = $userFactory;
}
/**
* Add thanks button to SpecialMobileDiff page
* @param OutputPage &$output OutputPage object
* @param MobileContext $ctx MobileContext object
* @param array $revisions Array with two elements, either nulls or RevisionRecord objects for
* the two revisions that are being compared in the diff
*/
public function onBeforeSpecialMobileDiffDisplay(
OutputPage &$output,
MobileContext $ctx,
array $revisions
) {
$rev = $revisions[1];
// If the MobileFrontend extension is installed and the user is
// logged in or recipient is not a bot if bots cannot receive thanks, show a 'Thank' link.
if ( $rev
&& ExtensionRegistry::getInstance()->isLoaded( 'MobileFrontend' )
&& $rev->getUser()
&& Hooks::canReceiveThanks( $this->config, $this->userFactory, $rev->getUser() )
&& $output->getUser()->isRegistered()
) {
$output->addModules( [ 'ext.thanks.mobilediff' ] );
if ( $output->getRequest()->getSessionData( 'thanks-thanked-' . $rev->getId() ) ) {
// User already sent thanks for this revision
$output->addJsConfigVars( 'wgThanksAlreadySent', true );
}
}
}
}

View file

@ -1,155 +0,0 @@
( function () {
// To allow users to cancel a thanks in the event of an accident, the action is delayed.
const THANKS_DELAY = 2000,
msgOptions = {
// tag ensures that only one message in workflow is shown at any time
tag: 'thanks'
};
/**
* Attempt to execute a thank operation for a given edit
*
* @param {string} name The username of the user who made the edit
* @param {string} revision The revision the user created
* @param {string} recipientGender The gender of the user who made the edit
* @return {jQuery.Promise} The thank operation's status.
*/
function thankUser( name, revision, recipientGender ) {
return ( new mw.Api() ).postWithToken( 'csrf', {
action: 'thank',
rev: revision,
source: 'mobilediff'
} ).then( function () {
mw.notify( mw.msg( 'thanks-button-action-completed', name, recipientGender, mw.user ),
msgOptions );
}, function ( errorCode ) {
let msg;
switch ( errorCode ) {
case 'invalidrevision':
msg = mw.msg( 'thanks-error-invalidrevision' );
break;
case 'ratelimited':
msg = mw.msg( 'thanks-error-ratelimited', recipientGender );
break;
default:
msg = mw.msg( 'thanks-error-undefined', errorCode );
}
mw.notify( msg, msgOptions );
} );
}
/**
* Disables the thank button marking the user as thanked
*
* @param {jQuery} $button used for thanking
* @param {string} gender The gender of the user who made the edit
* @return {jQuery} $button now disabled
*/
function disableThanks( $button, gender ) {
$button
.addClass( 'thanked' )
.prop( 'disabled', true );
$button.find( 'span' ).eq( 1 )
.text( mw.msg( 'thanks-button-thanked', mw.user, gender ) );
return $button;
}
/**
* Create a thank button for a given edit
*
* @param {string} name The username of the user who made the edit
* @param {string} rev The revision the user created
* @param {string} gender The gender of the user who made the edit
* @return {jQuery|null} The HTML of the button.
*/
function createThankLink( name, rev, gender ) {
const button = document.createElement( 'button' ),
label = document.createElement( 'span' ),
icon = document.createElement( 'span' );
let timeout;
// https://doc.wikimedia.org/codex/latest/components/demos/button.html#css-only-version
button.classList.add(
'cdx-button',
'mw-mf-action-button',
'cdx-button--action-progressive',
'cdx-button--weight-primary'
);
label.textContent = mw.msg( 'thanks-button-thank', mw.user, gender );
icon.classList.add( 'mw-thanks-icon', 'cdx-button__icon' );
icon.setAttribute( 'aria-hidden', 'true' );
button.appendChild( icon );
button.appendChild( label );
const $button = $( button );
// Don't make thank button for self
if ( name === mw.config.get( 'wgUserName' ) ) {
return null;
}
// See if user has already been thanked for this edit
if ( mw.config.get( 'wgThanksAlreadySent' ) ) {
return disableThanks( $button, gender );
}
function cancelThanks( $btn ) {
// Hide the notification
$( '.mw-notification' ).hide();
// Clear the queued thanks!
clearTimeout( timeout );
timeout = null;
$btn.prop( 'disabled', false );
}
function queueThanks( $btn ) {
const $msg = $( '<div>' ).addClass( 'mw-thanks-notification' )
.text( mw.msg( 'thanks-button-action-queued', name, gender ) )
.append( $( '<a>' ).text( mw.msg( 'thanks-button-action-cancel' ) )
.on( 'click', function () {
cancelThanks( $btn );
} )
);
mw.notify( $msg, msgOptions );
timeout = setTimeout( function () {
timeout = null;
thankUser( name, rev, gender ).then( function () {
disableThanks( $btn, gender );
} );
}, THANKS_DELAY );
}
return $button.on( 'click', function () {
const $this = $( this );
$this.prop( 'disabled', true );
// eslint-disable-next-line no-jquery/no-class-state
if ( !$this.hasClass( 'thanked' ) && !timeout ) {
queueThanks( $this );
}
} );
}
/**
* Initialise a thank button in the given container.
*
* @param {jQuery} $user existing element with data attributes associated describing a user.
* @param {jQuery} $container to render button in
*/
function init( $user, $container ) {
const username = $user.data( 'user-name' ),
rev = $user.data( 'revision-id' ),
gender = $user.data( 'user-gender' );
const $thankBtn = createThankLink( username, rev, gender );
if ( $thankBtn ) {
$thankBtn.prependTo( $container );
}
}
$( function () {
init( $( '.mw-mf-user' ), $( '#mw-mf-userinfo' ) );
} );
// Expose for testing purposes
mw.thanks = $.extend( {}, mw.thanks || {}, {
_mobileDiffInit: init
} );
}() );

View file

@ -1,6 +0,0 @@
@import 'mediawiki.skin.variables.less';
.mw-thanks-icon {
.cdx-mixin-css-icon( @cdx-icon-user-talk, @color-inverted, @param-is-button-icon: true );
margin-right: 8px;
}

View file

@ -1,15 +0,0 @@
QUnit.module( 'Thanks mobilediff', function () {
QUnit.test( 'render button for logged in users', function ( assert ) {
const $container = $( '<div>' );
const $user = $( '<div>' )
.data( 'user-name', 'jon' )
.data( 'revision-id', 1 )
.data( 'user-gender', 'male' );
// eslint-disable-next-line no-underscore-dangle
mw.thanks._mobileDiffInit( $user, $container );
assert.strictEqual( $container.find( '.cdx-button' ).length, 1, 'Thanks button was created.' );
} );
} );