Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5969441
SupportAid.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
SupportAid.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Extension\Translate\TranslatorInterface\Aid
;
use
MediaWiki\Extension\Translate\MessageLoading\MessageHandle
;
use
MediaWiki\Extension\Translate\TranslatorInterface\TranslationHelperException
;
use
MediaWiki\Extension\Translate\Utilities\Utilities
;
use
MediaWiki\Title\Title
;
/**
* Translation aid that provides an url where users can ask for help
* @author Niklas Laxström
* @license GPL-2.0-or-later
* @since 2013-01-02
* @ingroup TranslationAids
*/
class
SupportAid
extends
TranslationAid
{
public
function
getData
():
array
{
return
[
'url'
=>
self
::
getSupportUrl
(
$this
->
handle
),
];
}
/**
* Target URL for a link provided by a support button/aid.
* @param MessageHandle $handle MessageHandle object for the translation message.
* @return string
* @throws TranslationHelperException
*/
public
static
function
getSupportUrl
(
MessageHandle
$handle
):
string
{
$title
=
$handle
->
getTitle
();
$config
=
self
::
getConfig
(
$handle
);
$placeholders
=
[
'%MESSAGE%'
=>
$title
->
getPrefixedText
(),
'%MESSAGE_URL%'
=>
Utilities
::
getEditorUrl
(
$handle
)
];
// Preprocess params
$params
=
[];
if
(
isset
(
$config
[
'params'
]
)
)
{
foreach
(
$config
[
'params'
]
as
$key
=>
$value
)
{
$params
[
$key
]
=
strtr
(
$value
,
$placeholders
);
}
}
// Return the URL or make one from the page
if
(
isset
(
$config
[
'url'
]
)
)
{
return
wfAppendQuery
(
$config
[
'url'
],
$params
);
}
elseif
(
isset
(
$config
[
'page'
]
)
)
{
$page
=
Title
::
newFromText
(
$config
[
'page'
]
);
if
(
$page
)
{
return
$page
->
getFullURL
(
$params
);
}
}
throw
new
TranslationHelperException
(
'Support page not configured properly'
);
}
/**
* Fetches Support URL config
* @param MessageHandle $handle
* @return array
* @throws TranslationHelperException
*/
private
static
function
getConfig
(
MessageHandle
$handle
):
array
{
global
$wgTranslateSupportUrl
,
$wgTranslateSupportUrlNamespace
;
if
(
!
$handle
->
isValid
()
)
{
throw
new
TranslationHelperException
(
'Invalid MessageHandle'
);
}
// Fetch group level configuration if possible, fallback to namespace based, or default
$group
=
$handle
->
getGroup
();
$namespace
=
$handle
->
getTitle
()->
getNamespace
();
$config
=
$group
->
getSupportConfig
()
??
$wgTranslateSupportUrlNamespace
[
$namespace
]
??
$wgTranslateSupportUrl
;
if
(
!
$config
)
{
throw
new
TranslationHelperException
(
'Support page not configured'
);
}
return
$config
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Oct 3, 13:46 (1 d, 1 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
bd/8f/12c3a321d25a585a607e2b6d2da1
Default Alt Text
SupportAid.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment