Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4102643
ApiParseExtender.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
ApiParseExtender.php
View Options
<?php
namespace
MobileFrontend\Api
;
use
MediaWiki\Api\ApiBase
;
use
MediaWiki\Api\Hook\APIGetAllowedParamsHook
;
use
Wikimedia\ParamValidator\ParamValidator
;
/**
* Adds the `mobileformat` param to API calls which use ApiParse.
*
* The param should be used in conjunction with the `useskin` paramater (to
* ensure ApiParse is in skin mode), and will cause MobileFrontend's
* onOutputPageBeforeHTML to apply mobile-specific page transformations.
*/
class
ApiParseExtender
implements
APIGetAllowedParamsHook
{
/**
* Check if an API action can have the mobileformat param
*
* @param string $action
* @return bool
*/
public
static
function
isParseAction
(
string
$action
):
bool
{
return
$action
===
'parse'
||
// VE calls parse indirectly
$action
===
'visualeditoredit'
||
// DT calls VE indirectly
$action
===
'discussiontoolsedit'
||
$action
===
'discussiontoolspreview'
;
}
/**
* APIGetAllowedParams hook handler
* @see https://www.mediawiki.org/wiki/Manual:Hooks/APIGetAllowedParams
* @param ApiBase $module
* @param array &$params Array of parameters
* @param int $flags
*/
public
function
onAPIGetAllowedParams
(
$module
,
&
$params
,
$flags
)
{
$name
=
$module
->
getModuleName
();
// $name is supposed to always be a string, but in some tests it returns null :/
if
(
$name
&&
self
::
isParseAction
(
$name
)
)
{
$params
[
'mobileformat'
]
=
[
ParamValidator
::
PARAM_TYPE
=>
'boolean'
,
ApiBase
::
PARAM_HELP_MSG
=>
'apihelp-parse-param-mobileformat'
,
];
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Aug 18, 17:32 (3 w, 3 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
60/cd/09e90d8973e8df7fa1a0d79a7dc6
Default Alt Text
ApiParseExtender.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment