Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1428009
JsSelectToInput.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
JsSelectToInput.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Extension\Translate\Utilities
;
use
MediaWiki\Context\RequestContext
;
use
RuntimeException
;
use
Xml
;
use
XmlSelect
;
/**
* Code for JavaScript enhanced \<option> selectors.
* @author Niklas Laxström
* @license GPL-2.0-or-later
*/
class
JsSelectToInput
{
/** @var string Id of the text field where stuff is appended */
protected
$targetId
;
/** @var string Id of the \<option> field */
protected
$sourceId
;
/** @var XmlSelect */
protected
$select
;
/** @var string Id on the button */
protected
$buttonId
;
/** @var string Text for the append button */
protected
$msg
=
'translate-jssti-add'
;
public
function
__construct
(
XmlSelect
$select
)
{
$this
->
select
=
$select
;
}
public
function
getSourceId
():
string
{
return
$this
->
sourceId
;
}
public
function
setTargetId
(
string
$id
)
{
$this
->
targetId
=
$id
;
}
public
function
getTargetId
():
string
{
return
$this
->
targetId
;
}
/** Set the message key. */
public
function
setMessage
(
string
$message
):
void
{
$this
->
msg
=
$message
;
}
/** @return string a message key. */
public
function
getMessage
():
string
{
return
$this
->
msg
;
}
/**
* Returns the whole input element and injects needed JavaScript
* @return string Html code.
*/
public
function
getHtmlAndPrepareJS
():
string
{
$this
->
sourceId
=
$this
->
select
->
getAttribute
(
'id'
);
if
(
!
is_string
(
$this
->
sourceId
)
)
{
throw
new
RuntimeException
(
'ID needs to be specified for the selector'
);
}
self
::
injectJs
();
$html
=
$this
->
select
->
getHTML
();
$html
.=
$this
->
getButton
(
$this
->
msg
,
$this
->
sourceId
,
$this
->
targetId
);
return
$html
;
}
/**
* Constructs the append button.
* @param string $msg Message key.
* @param string $source Html id.
* @param string $target Html id.
* @return string
*/
protected
function
getButton
(
string
$msg
,
string
$source
,
string
$target
):
string
{
$html
=
Xml
::
element
(
'input'
,
[
'type'
=>
'button'
,
'value'
=>
wfMessage
(
$msg
)->
text
(),
'class'
=>
'mw-translate-jssti'
,
'data-translate-jssti-sourceid'
=>
$source
,
'data-translate-jssti-targetid'
=>
$target
]
);
return
$html
;
}
/** Inject needed JavaScript in the page. */
public
static
function
injectJs
():
void
{
static
$done
=
false
;
if
(
$done
)
{
return
;
}
RequestContext
::
getMain
()->
getOutput
()->
addModules
(
'ext.translate.selecttoinput'
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 16, 15:28 (13 h, 43 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
20/1a/3ac28e56df0fe6d3e84380ac384f
Default Alt Text
JsSelectToInput.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment