Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F2751677
ApiCentralNoticeLogs.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
ApiCentralNoticeLogs.php
View Options
<?php
use
MediaWiki\Api\ApiBase
;
use
MediaWiki\Api\ApiQueryBase
;
# TODO: bannerlogs
/** @todo: This needs some major cleanup to work more like the rest of the API. */
class
ApiCentralNoticeLogs
extends
ApiQueryBase
{
private
const
USER_FILTER
=
'/[a-zA-Z0-9_.]+/'
;
private
const
CAMPAIGNS_FILTER
=
'/[a-zA-Z0-9_|
\-
]+/'
;
public
function
execute
()
{
// Obtain the ApiResults object from the base
$result
=
$this
->
getResult
();
$params
=
$this
->
extractRequestParams
();
$start
=
$params
[
'start'
];
$end
=
$params
[
'end'
];
$limit
=
$params
[
'limit'
];
$offset
=
$params
[
'offset'
];
$user
=
self
::
sanitizeText
(
$params
[
'user'
],
self
::
USER_FILTER
);
# TODO: multiple
$campaign
=
self
::
sanitizeText
(
$params
[
'campaign'
],
self
::
CAMPAIGNS_FILTER
);
$logs
=
Campaign
::
campaignLogs
(
$campaign
,
$user
,
$start
,
$end
,
$limit
,
$offset
);
$result
->
addValue
(
[
'query'
,
$this
->
getModuleName
()
],
'logs'
,
$logs
);
}
public
function
getAllowedParams
()
{
return
[
'campaign'
=>
[
ApiBase
::
PARAM_TYPE
=>
'string'
,
],
'user'
=>
[
ApiBase
::
PARAM_TYPE
=>
'string'
,
],
'limit'
=>
[
ApiBase
::
PARAM_DFLT
=>
50
,
ApiBase
::
PARAM_TYPE
=>
'limit'
,
ApiBase
::
PARAM_MIN
=>
1
,
ApiBase
::
PARAM_MAX
=>
ApiBase
::
LIMIT_BIG1
,
ApiBase
::
PARAM_MAX2
=>
ApiBase
::
LIMIT_BIG2
,
],
'offset'
=>
[
ApiBase
::
PARAM_DFLT
=>
0
,
ApiBase
::
PARAM_TYPE
=>
'integer'
,
],
'start'
=>
[
ApiBase
::
PARAM_TYPE
=>
'timestamp'
,
],
'end'
=>
[
ApiBase
::
PARAM_TYPE
=>
'timestamp'
,
],
];
}
/**
* @inheritDoc
*/
protected
function
getExamplesMessages
()
{
return
[
'action=query&list=centralnoticelogs&format=json'
=>
'apihelp-query+centralnoticelogs-example-1'
,
];
}
/**
* Obtains the parameter $param, sanitizes by returning the first match to $regex or
* $default if there was no match.
*
* @param string $value Incoming value
* @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
(
$value
,
$regex
,
$default
=
null
)
{
$matches
=
[];
if
(
preg_match
(
$regex
,
$value
,
$matches
)
)
{
return
$matches
[
0
];
}
else
{
return
$default
;
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Jul 3, 18:59 (1 d, 20 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
6d/d5/f3033e438b9433e6e926ff6f3b0b
Default Alt Text
ApiCentralNoticeLogs.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment