Page MenuHomePhabricator

Stop using onclick attributes and global functions in Translate js
Open, LowPublic

Description

This be yuck
https://github.com/wikimedia/mediawiki-extensions-Translate/search?utf8=✓&q=onclick

onclick html attributes depend on globally scoped javascript functions, which we try to avoid using. Instead, we should be using JS resource loader modules, that find the right elements from the page ready and attach eventlisteners to those elements

protected function getButton( $msg, $source, $target ) {
		$html = Xml::element( 'input', [
			'type' => 'button',
			'value' => wfMessage( $msg )->text(),
			'onclick' => Xml::encodeJsCall( 'appendFromSelect', [ $source, $target ] )
		] );

		return $html;
	}
window.appendFromSelect = function ( selectid, targetid ) {
}

rewrite, so that the JS setup is no longer in the HTML, but instead in something like $( document ).ready, which finds the thml button and then attaches a click handler calling appendFromSelect (an removing appendFromSelect from the window object).

Event Timeline

Nikerabbit added a subscriber: Nikerabbit.

Most of these are in the deprecated TUX ui.

Hello, The bug represents to remove the onclick attributes?

@Dheerajmalisetty: The task summary says "Stop using onclick attributes". Hence I am not sure what exactly is unclear and made you ask. :)

@Aklapper : Do I need to comment the onclick attribute.

@Dheerajmalisetty: Why don't you just try it, make your changes locally, test if your changes fix this task, and then propose a patch in Gerrit?
Please see the first bullet point here: https://www.mediawiki.org/wiki/How_to_become_a_MediaWiki_hacker#Feedback,_questions_and_support

@Dheerajmalisetty i slightly expanded the description of the ticket to further clarify what needs to be done.

i gave you some more details to work with :D

@Swayamsrk: Hi! This task has been assigned to you a while ago. Could you maybe share an update? Do you need any help? Thanks.

Currently I am not working on this issue .Please assign it to someone else.Thanks

Soda added a subscriber: Soda.

I'll try and figure this one out...

Change 578997 had a related patch set uploaded (by Sohom Datta; owner: Sohom Datta):
[mediawiki/extensions/Translate@master] Converted JsSelectToInput.php to not use onclick

https://gerrit.wikimedia.org/r/578997

Krinkle renamed this task from Stop using onclick attributes and globally scoped functions to Stop using onclick attributes and global functions in Translate js.Mar 12 2020, 2:01 AM

Change 578997 merged by Abijeet Patro:
[mediawiki/extensions/Translate@master] Converted JsSelectToInput.php to not use onclick

https://gerrit.wikimedia.org/r/578997