Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4126183
StyleAttributeSanitizer.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
StyleAttributeSanitizer.php
View Options
<?php
/**
* @file
* @license https://opensource.org/licenses/Apache-2.0 Apache-2.0
*/
namespace
Wikimedia\CSS\Sanitizer
;
use
Wikimedia\CSS\Grammar\MatcherFactory
;
use
Wikimedia\CSS\Objects\CSSObject
;
use
Wikimedia\CSS\Objects\DeclarationList
;
use
Wikimedia\CSS\Parser\Parser
;
/**
* Sanitizes a CSS style attribute (i.e. `<tag style="...">`)
* @see https://www.w3.org/TR/2013/REC-css-style-attr-20131107/
*/
class
StyleAttributeSanitizer
extends
Sanitizer
{
/** @var Sanitizer */
protected
$propertySanitizer
;
/**
* @param PropertySanitizer $propertySanitizer Sanitizer to test property declarations.
* Probably an instance of StylePropertySanitizer.
*/
public
function
__construct
(
PropertySanitizer
$propertySanitizer
)
{
$this
->
propertySanitizer
=
$propertySanitizer
;
}
/**
* Create and return a default StyleAttributeSanitizer.
* @note This method exists more to be an example of how to put everything
* together than to be used directly.
* @return StyleAttributeSanitizer
*/
public
static
function
newDefault
()
{
// First, we need a matcher factory for the stuff all the sanitizers
// will need.
$matcherFactory
=
MatcherFactory
::
singleton
();
// This is the sanitizer for a single "property: value"
$propertySanitizer
=
new
StylePropertySanitizer
(
$matcherFactory
);
// StyleAttributeSanitizer brings it all together
return
new
StyleAttributeSanitizer
(
$propertySanitizer
);
}
/** @inheritDoc */
protected
function
doSanitize
(
CSSObject
$object
)
{
if
(
!
$object
instanceof
DeclarationList
)
{
$this
->
sanitizationError
(
'expected-declaration-list'
,
$object
);
return
null
;
}
return
$this
->
sanitizeList
(
$this
->
propertySanitizer
,
$object
);
}
/**
* Sanitize a string value.
* @param string $string
* @return DeclarationList
*/
public
function
sanitizeString
(
$string
)
{
$parser
=
Parser
::
newFromString
(
$string
);
$declarations
=
$parser
->
parseDeclarationList
();
$this
->
sanitizationErrors
=
array_merge
(
$this
->
sanitizationErrors
,
$parser
->
getParseErrors
()
);
// @phan-suppress-next-line PhanTypeMismatchReturnSuperType
return
$this
->
sanitizeList
(
$this
->
propertySanitizer
,
$declarations
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Aug 19, 07:58 (2 w, 3 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
59/35/873540d1a3224fc51f241844babd
Default Alt Text
StyleAttributeSanitizer.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment