Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 33 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
PackedMode | |
0.00% |
0 / 33 |
|
0.00% |
0 / 7 |
110 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
perRow | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
dimensions | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
scaleMedia | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
useTraditionalGalleryText | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
galleryText | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
12 | |||
getModules | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace Wikimedia\Parsoid\Ext\Gallery; |
5 | |
6 | use Wikimedia\Parsoid\DOM\Document; |
7 | use Wikimedia\Parsoid\DOM\Element; |
8 | use Wikimedia\Parsoid\Ext\DOMUtils; |
9 | use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI; |
10 | use Wikimedia\Parsoid\Utils\DOMCompat; |
11 | |
12 | class PackedMode extends TraditionalMode { |
13 | /** |
14 | * Create a PackedMode singleton. |
15 | * @param ?string $mode Only used by subclasses. |
16 | */ |
17 | protected function __construct( ?string $mode = null ) { |
18 | parent::__construct( $mode ?? 'packed' ); |
19 | $this->scale = 1.5; |
20 | $this->padding = (object)[ 'thumb' => 0, 'box' => 2, 'border' => 8 ]; |
21 | } |
22 | |
23 | /** @inheritDoc */ |
24 | protected function perRow( Opts $opts, Element $ul ): void { |
25 | /* do nothing */ |
26 | } |
27 | |
28 | /** @inheritDoc */ |
29 | public function dimensions( Opts $opts ): string { |
30 | $size = ceil( $opts->imageHeight * $this->scale ); |
31 | return "x{$size}px"; |
32 | } |
33 | |
34 | /** @inheritDoc */ |
35 | public function scaleMedia( Opts $opts, Element $wrapper ) { |
36 | $elt = $wrapper->firstChild->firstChild; |
37 | DOMUtils::assertElt( $elt ); |
38 | $width = DOMCompat::getAttribute( $elt, 'width' ); |
39 | if ( !is_numeric( $width ) ) { |
40 | $width = $opts->imageWidth; |
41 | } else { |
42 | $width = intval( $width, 10 ); |
43 | $width /= $this->scale; |
44 | } |
45 | $elt->setAttribute( 'width', strval( ceil( $width ) ) ); |
46 | $elt->setAttribute( 'height', "$opts->imageHeight" ); |
47 | return $width; |
48 | } |
49 | |
50 | protected function useTraditionalGalleryText(): bool { |
51 | return true; |
52 | } |
53 | |
54 | /** @inheritDoc */ |
55 | protected function galleryText( |
56 | Document $doc, Element $box, ?Element $gallerytext, float $width |
57 | ): void { |
58 | if ( $this->useTraditionalGalleryText() ) { |
59 | parent::galleryText( $doc, $box, $gallerytext, $width ); |
60 | return; |
61 | } |
62 | if ( !$gallerytext ) { |
63 | return; |
64 | } |
65 | $div = $doc->createElement( 'div' ); |
66 | $div->setAttribute( 'class', 'gallerytext' ); |
67 | ParsoidExtensionAPI::migrateChildrenAndTransferWrapperDataAttribs( |
68 | $gallerytext, $div |
69 | ); |
70 | $wrapper = $doc->createElement( 'div' ); |
71 | $wrapper->setAttribute( 'class', 'gallerytextwrapper' ); |
72 | $wrapper->setAttribute( 'style', 'width: ' . ceil( $width - 20 ) . 'px;' ); |
73 | $wrapper->appendChild( $div ); |
74 | $box->appendChild( $wrapper ); |
75 | } |
76 | |
77 | public function getModules(): array { |
78 | return [ 'mediawiki.page.gallery' ]; |
79 | } |
80 | } |