Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7478408
PackedMode.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
PackedMode.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
Wikimedia\Parsoid\Ext\Gallery
;
use
Wikimedia\Parsoid\DOM\Document
;
use
Wikimedia\Parsoid\DOM\Element
;
use
Wikimedia\Parsoid\Ext\DOMUtils
;
use
Wikimedia\Parsoid\Ext\ParsoidExtensionAPI
;
use
Wikimedia\Parsoid\Utils\DOMCompat
;
class
PackedMode
extends
TraditionalMode
{
/**
* Create a PackedMode singleton.
* @param ?string $mode Only used by subclasses.
*/
protected
function
__construct
(
?
string
$mode
=
null
)
{
parent
::
__construct
(
$mode
??
'packed'
);
$this
->
scale
=
1.5
;
$this
->
padding
=
(
object
)[
'thumb'
=>
0
,
'box'
=>
2
,
'border'
=>
8
];
}
/** @inheritDoc */
protected
function
perRow
(
Opts
$opts
,
Element
$ul
):
void
{
/* do nothing */
}
/** @inheritDoc */
public
function
dimensions
(
Opts
$opts
):
string
{
$height
=
floor
(
$opts
->
imageHeight
*
$this
->
scale
);
// The legacy parser does this so that the width is not the contraining factor
$width
=
floor
(
(
$opts
->
imageHeight
*
10
+
100
)
*
$this
->
scale
);
return
"{$width}x{$height}px"
;
}
/** @inheritDoc */
public
function
scaleMedia
(
Opts
$opts
,
Element
$wrapper
)
{
$elt
=
$wrapper
->
firstChild
->
firstChild
;
DOMUtils
::
assertElt
(
$elt
);
$width
=
DOMCompat
::
getAttribute
(
$elt
,
'width'
);
if
(
!
is_numeric
(
$width
)
)
{
$width
=
$opts
->
imageWidth
;
}
else
{
$width
=
intval
(
$width
,
10
);
$width
/=
$this
->
scale
;
}
$elt
->
setAttribute
(
'width'
,
strval
(
ceil
(
$width
)
)
);
$elt
->
setAttribute
(
'height'
,
"$opts->imageHeight"
);
return
$width
;
}
protected
function
useTraditionalGalleryText
():
bool
{
return
true
;
}
/** @inheritDoc */
protected
function
galleryText
(
Document
$doc
,
Element
$box
,
?
Element
$gallerytext
,
float
$width
):
void
{
if
(
$this
->
useTraditionalGalleryText
()
)
{
parent
::
galleryText
(
$doc
,
$box
,
$gallerytext
,
$width
);
return
;
}
if
(
!
$gallerytext
)
{
return
;
}
$div
=
$doc
->
createElement
(
'div'
);
$div
->
setAttribute
(
'class'
,
'gallerytext'
);
ParsoidExtensionAPI
::
migrateChildrenAndTransferWrapperDataAttribs
(
$gallerytext
,
$div
);
$wrapper
=
$doc
->
createElement
(
'div'
);
$wrapper
->
setAttribute
(
'class'
,
'gallerytextwrapper'
);
$wrapper
->
setAttribute
(
'style'
,
'width: '
.
ceil
(
$width
-
20
)
.
'px;'
);
$wrapper
->
appendChild
(
$div
);
$box
->
appendChild
(
$wrapper
);
}
public
function
getModules
():
array
{
return
[
'mediawiki.page.gallery'
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Nov 23, 11:15 (4 d, 17 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
24/5e/f44dc7b2d2255c146767484689f3
Default Alt Text
PackedMode.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment