Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F2751146
ApiCentralNoticeChoiceData.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
ApiCentralNoticeChoiceData.php
View Options
<?php
use
MediaWiki\Api\ApiBase
;
/**
* Module for the centralnoticechoicedata Web API.
*
* This is provided as a fallback mechanism for getting banner choice data
* from an infrastructure wiki, for cases in which direct cross-wiki DB
* queries are not possible.
*/
class
ApiCentralNoticeChoiceData
extends
ApiBase
{
private
const
LANG_FILTER
=
'/[a-zA-Z0-9
\-
]+/'
;
private
const
PROJECT_FILTER
=
'/[a-zA-Z0-9_
\-
]+/'
;
public
function
execute
()
{
// Extract, sanitize and munge the parameters
$params
=
$this
->
extractRequestParams
();
$project
=
self
::
sanitizeText
(
$params
[
'project'
],
self
::
PROJECT_FILTER
);
$lang
=
self
::
sanitizeText
(
$params
[
'language'
],
self
::
LANG_FILTER
);
$choices
=
ChoiceDataProvider
::
getChoices
(
$project
,
$lang
);
// Get the result object for creating the output
$apiResult
=
$this
->
getResult
();
$apiResult
->
addValue
(
null
,
'choices'
,
$choices
);
}
public
function
getAllowedParams
()
{
return
[
'project'
=>
[
ApiBase
::
PARAM_TYPE
=>
'string'
,
ApiBase
::
PARAM_REQUIRED
=>
true
],
'language'
=>
[
ApiBase
::
PARAM_TYPE
=>
'string'
,
ApiBase
::
PARAM_REQUIRED
=>
true
]
];
}
/** @inheritDoc */
protected
function
getExamplesMessages
()
{
return
[
'action=centralnoticechoicedata&project=wikipedia&language=en'
=>
'apihelp-centralnoticechoicedata-example-1'
];
}
/**
* Obtains the parameter $param, sanitizes by returning the first match to $regex or
* $default if there was no match.
*
* @param string $param Name of GET/POST parameter
* @param string $regex Sanitization regular expression
* @param string|null $default Default value to return on error
*
* @return string The sanitized value
*/
private
static
function
sanitizeText
(
$param
,
$regex
,
$default
=
null
)
{
$matches
=
[];
if
(
preg_match
(
$regex
,
$param
,
$matches
)
)
{
return
$matches
[
0
];
}
else
{
return
$default
;
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Jul 3, 17:57 (1 d, 5 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
fe/fa/9e6da4b92324bf6f64d8f5001e84
Default Alt Text
ApiCentralNoticeChoiceData.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment