Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4150260
MarginAtRuleSanitizer.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
MarginAtRuleSanitizer.php
View Options
<?php
/**
* @file
* @license https://opensource.org/licenses/Apache-2.0 Apache-2.0
*/
namespace
Wikimedia\CSS\Sanitizer
;
use
Wikimedia\CSS\Objects\AtRule
;
use
Wikimedia\CSS\Objects\CSSObject
;
use
Wikimedia\CSS\Objects\Rule
;
use
Wikimedia\CSS\Util
;
/**
* Sanitizes the margin at-rules inside a CSS \@page rule
* @see https://www.w3.org/TR/2018/WD-css-page-3-20181018/
*/
class
MarginAtRuleSanitizer
extends
RuleSanitizer
{
/** @var string[] */
protected
static
$marginRuleNames
=
[
'top-left-corner'
,
'top-left'
,
'top-center'
,
'top-right'
,
'top-right-corner'
,
'bottom-left-corner'
,
'bottom-left'
,
'bottom-center'
,
'bottom-right'
,
'bottom-right-corner'
,
'left-top'
,
'left-middle'
,
'left-bottom'
,
'right-top'
,
'right-middle'
,
'right-bottom'
,
];
/** @var PropertySanitizer */
protected
$propertySanitizer
;
/**
* @param PropertySanitizer $propertySanitizer Sanitizer for declarations
*/
public
function
__construct
(
PropertySanitizer
$propertySanitizer
)
{
$this
->
propertySanitizer
=
$propertySanitizer
;
}
/** @inheritDoc */
public
function
handlesRule
(
Rule
$rule
)
{
return
$rule
instanceof
AtRule
&&
in_array
(
strtolower
(
$rule
->
getName
()
),
self
::
$marginRuleNames
,
true
);
}
/** @inheritDoc */
protected
function
doSanitize
(
CSSObject
$object
)
{
if
(
!
$object
instanceof
AtRule
||
!
$this
->
handlesRule
(
$object
)
)
{
$this
->
sanitizationError
(
'expected-page-margin-at-rule'
,
$object
);
return
null
;
}
if
(
$object
->
getBlock
()
===
null
)
{
$this
->
sanitizationError
(
'at-rule-block-required'
,
$object
,
[
$object
->
getName
()
]
);
return
null
;
}
// No non-whitespace prelude allowed
if
(
Util
::
findFirstNonWhitespace
(
$object
->
getPrelude
()
)
)
{
$this
->
sanitizationError
(
'invalid-page-margin-at-rule'
,
$object
,
[
$object
->
getName
()
]
);
return
null
;
}
$ret
=
clone
$object
;
$this
->
fixPreludeWhitespace
(
$ret
,
false
);
$this
->
sanitizeDeclarationBlock
(
$ret
->
getBlock
(),
$this
->
propertySanitizer
);
return
$ret
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Aug 19 2026, 19:29 (6 w, 6 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
94/c8/f992b948edd4c59fef07f9b26764
Default Alt Text
MarginAtRuleSanitizer.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment