Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5975239
ApiParamValidatorCallbacks.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
ApiParamValidatorCallbacks.php
View Options
<?php
namespace
MediaWiki\Api\Validator
;
use
MediaWiki\Api\ApiBase
;
use
MediaWiki\Api\ApiMain
;
use
MediaWiki\Message\Converter
as
MessageConverter
;
use
Wikimedia\Message\DataMessageValue
;
use
Wikimedia\ParamValidator\Callbacks
;
use
Wikimedia\ParamValidator\Util\UploadedFile
;
/**
* ParamValidator callbacks for the Action API
* @since 1.35
* @ingroup API
*/
class
ApiParamValidatorCallbacks
implements
Callbacks
{
/** @var ApiMain */
private
$apiMain
;
/** @var MessageConverter */
private
$messageConverter
;
/**
* @internal
* @param ApiMain $main
*/
public
function
__construct
(
ApiMain
$main
)
{
$this
->
apiMain
=
$main
;
$this
->
messageConverter
=
new
MessageConverter
();
}
public
function
hasParam
(
$name
,
array
$options
)
{
return
$this
->
apiMain
->
getCheck
(
$name
);
}
public
function
getValue
(
$name
,
$default
,
array
$options
)
{
$value
=
$this
->
apiMain
->
getVal
(
$name
,
$default
);
$request
=
$this
->
apiMain
->
getRequest
();
$rawValue
=
$request
->
getRawVal
(
$name
);
if
(
$options
[
'raw'
]
??
false
)
{
// Bypass NFC normalization
return
$rawValue
;
}
if
(
is_string
(
$rawValue
)
)
{
// Preserve U+001F for multi-values
if
(
substr
(
$rawValue
,
0
,
1
)
===
"
\x
1f"
)
{
// This loses the potential checkTitleEncoding() transformation done by
// WebRequest for $_GET. Let's call that a feature.
$value
=
implode
(
"
\x
1f"
,
$request
->
normalizeUnicode
(
explode
(
"
\x
1f"
,
$rawValue
)
)
);
}
// Check for NFC normalization, and warn
if
(
$rawValue
!==
$value
)
{
$options
[
'module'
]->
handleParamNormalization
(
$name
,
$value
,
$rawValue
);
}
}
return
$value
;
}
public
function
hasUpload
(
$name
,
array
$options
)
{
return
$this
->
getUploadedFile
(
$name
,
$options
)
!==
null
;
}
public
function
getUploadedFile
(
$name
,
array
$options
)
{
$upload
=
$this
->
apiMain
->
getUpload
(
$name
);
if
(
!
$upload
->
exists
()
)
{
return
null
;
}
return
new
UploadedFile
(
[
'error'
=>
$upload
->
getError
(),
'tmp_name'
=>
$upload
->
getTempName
(),
'size'
=>
$upload
->
getSize
(),
'name'
=>
$upload
->
getName
(),
'type'
=>
$upload
->
getType
(),
]
);
}
public
function
recordCondition
(
DataMessageValue
$message
,
$name
,
$value
,
array
$settings
,
array
$options
)
{
/** @var ApiBase $module */
$module
=
$options
[
'module'
];
$code
=
$message
->
getCode
();
switch
(
$code
)
{
case
'param-deprecated'
:
// @codeCoverageIgnore
case
'deprecated-value'
:
// @codeCoverageIgnore
if
(
$code
===
'param-deprecated'
)
{
$feature
=
$name
;
}
else
{
$feature
=
$name
.
'='
.
$value
;
$data
=
$message
->
getData
()
??
[];
if
(
isset
(
$data
[
'💩'
]
)
)
{
// This is from an old-style Message. Strip out ParamValidator's added params.
unset
(
$data
[
'💩'
]
);
$message
=
DataMessageValue
::
new
(
$message
->
getKey
(),
array_slice
(
$message
->
getParams
(),
2
),
$code
,
$data
);
}
}
$m
=
$module
;
while
(
!
$m
->
isMain
()
)
{
$p
=
$m
->
getParent
();
$mName
=
$m
->
getModuleName
();
$mParam
=
$p
->
encodeParamName
(
$p
->
getModuleManager
()->
getModuleGroup
(
$mName
)
);
$feature
=
"{$mParam}={$mName}&{$feature}"
;
$m
=
$p
;
}
$module
->
addDeprecation
(
$this
->
messageConverter
->
convertMessageValue
(
$message
),
$feature
,
$message
->
getData
()
);
break
;
case
'param-sensitive'
:
// @codeCoverageIgnore
$module
->
getMain
()->
markParamsSensitive
(
$name
);
break
;
default
:
$module
->
addWarning
(
$this
->
messageConverter
->
convertMessageValue
(
$message
),
$message
->
getCode
(),
$message
->
getData
()
);
break
;
}
}
public
function
useHighLimits
(
array
$options
)
{
return
$this
->
apiMain
->
canApiHighLimits
();
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Oct 3, 18:04 (20 h, 4 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
ae/87/3135f94d0e11853f6d78b2b46ee1
Default Alt Text
ApiParamValidatorCallbacks.php (3 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment