Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F6110509
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
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
Oct 6 2026, 18:07 (6 w, 3 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
c3/ed/5c17afa500be9612a29cd58e7256
Default Alt Text
AddWrapperDivClass.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment