Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4024340
AddWrapperDivClass.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
AddWrapperDivClass.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\OutputTransform\Stages
;
use
MediaWiki\Config\ServiceOptions
;
use
MediaWiki\Html\Html
;
use
MediaWiki\Language\Language
;
use
MediaWiki\Languages\LanguageFactory
;
use
MediaWiki\OutputTransform\ContentTextTransformStage
;
use
MediaWiki\Parser\ParserOptions
;
use
MediaWiki\Parser\ParserOutput
;
use
Psr\Log\LoggerInterface
;
/**
* Wrap the output in a div with the provided class name
* @internal
*/
class
AddWrapperDivClass
extends
ContentTextTransformStage
{
private
LanguageFactory
$langFactory
;
private
Language
$contentLang
;
public
function
__construct
(
ServiceOptions
$options
,
LoggerInterface
$logger
,
LanguageFactory
$langFactory
,
Language
$contentLang
)
{
parent
::
__construct
(
$options
,
$logger
);
$this
->
langFactory
=
$langFactory
;
$this
->
contentLang
=
$contentLang
;
}
public
function
shouldRun
(
ParserOutput
$po
,
?
ParserOptions
$popts
,
array
$options
=
[]
):
bool
{
return
(
$options
[
'wrapperDivClass'
]
??
$po
->
getWrapperDivClass
()
)
!==
''
&&
!(
$options
[
'unwrap'
]
??
false
);
}
protected
function
transformText
(
string
$text
,
ParserOutput
$po
,
?
ParserOptions
$popts
,
array
&
$options
):
string
{
$wrapperDivClass
=
$options
[
'wrapperDivClass'
]
??
$po
->
getWrapperDivClass
();
$pageLang
=
$this
->
getLanguageWithFallbackGuess
(
$po
);
$extraAttrs
=
[];
$parsoidVersion
=
$po
->
getExtensionData
(
'core:parsoid-version'
);
$htmlVersion
=
$po
->
getExtensionData
(
'core:html-version'
);
if
(
$parsoidVersion
!==
null
)
{
$extraAttrs
[
'data-mw-parsoid-version'
]
=
$parsoidVersion
;
}
if
(
$htmlVersion
!==
null
)
{
$extraAttrs
[
'data-mw-html-version'
]
=
$htmlVersion
;
}
return
Html
::
rawElement
(
'div'
,
[
'class'
=>
'mw-content-'
.
$pageLang
->
getDir
()
.
' '
.
$wrapperDivClass
,
'lang'
=>
$pageLang
->
toBcp47Code
(),
'dir'
=>
$pageLang
->
getDir
(),
]
+
$extraAttrs
,
$text
);
}
private
function
getLanguageWithFallbackGuess
(
ParserOutput
$po
):
Language
{
$pageLang
=
$po
->
getLanguage
();
if
(
$pageLang
)
{
return
$this
->
langFactory
->
getLanguage
(
$pageLang
);
}
return
$this
->
contentLang
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Aug 14 2026, 19:41 (13 w, 1 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
d1/f7/e9cb36210990b91e6907c2f1e999
Default Alt Text
AddWrapperDivClass.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment