Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 34 |
PackedMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 7 |
156 | |
0.00% |
0 / 34 |
__construct | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 4 |
|||
perRow | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
dimensions | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
scaleMedia | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 10 |
|||
useTraditionalGalleryText | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
galleryText | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 15 |
|||
getModules | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
<?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\Ext\PHPUtils; | |
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 = PHPUtils::arrayToObject( [ 'thumb' => 0, 'box' => 2, 'border' => 8 ] ); | |
} | |
/** @inheritDoc */ | |
protected function perRow( Opts $opts, Element $ul ): void { | |
/* do nothing */ | |
} | |
/** @inheritDoc */ | |
public function dimensions( Opts $opts ): string { | |
$size = ceil( $opts->imageHeight * $this->scale ); | |
return "x{$size}px"; | |
} | |
/** @inheritDoc */ | |
public function scaleMedia( Opts $opts, Element $wrapper ) { | |
$elt = $wrapper->firstChild->firstChild; | |
DOMUtils::assertElt( $elt ); | |
$width = $elt->getAttribute( '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 ); | |
} | |
/** | |
* @return array | |
*/ | |
public function getModules(): array { | |
return [ 'mediawiki.page.gallery' ]; | |
} | |
} |