Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
Opts | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
110 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
110 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace Wikimedia\Parsoid\Ext\Gallery; |
5 | |
6 | use Wikimedia\Parsoid\Core\Sanitizer; |
7 | use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI; |
8 | use Wikimedia\Parsoid\Ext\Utils; |
9 | |
10 | class Opts { |
11 | /** |
12 | * Parse options from an attribute array. |
13 | * @param ParsoidExtensionAPI $extApi |
14 | * @param array<string,string> $attrs The attribute array |
15 | */ |
16 | public function __construct( ParsoidExtensionAPI $extApi, array $attrs ) { |
17 | // Set default values from config |
18 | // The options 'showDimensions' and 'showBytes' for traditional mode are not implemented, |
19 | // They are not used for galleries in wikitext (only on category pages or special pages) |
20 | // The deprecated option 'captionLength' for traditional mode is not implemented. |
21 | $galleryOptions = $extApi->getSiteConfig()->galleryOptions(); |
22 | $this->imagesPerRow = $galleryOptions['imagesPerRow']; |
23 | $this->imageWidth = $galleryOptions['imageWidth']; |
24 | $this->imageHeight = $galleryOptions['imageHeight']; |
25 | $this->mode = $galleryOptions['mode']; |
26 | |
27 | // Override values from given attributes |
28 | if ( is_numeric( $attrs['perrow'] ?? null ) ) { |
29 | $this->imagesPerRow = intval( $attrs['perrow'], 10 ); |
30 | } |
31 | |
32 | $maybeDim = Utils::parseMediaDimensions( $attrs['widths'] ?? '', true ); |
33 | if ( $maybeDim && Utils::validateMediaParam( $maybeDim['x'] ) ) { |
34 | $this->imageWidth = $maybeDim['x']; |
35 | } |
36 | |
37 | $maybeDim = Utils::parseMediaDimensions( $attrs['heights'] ?? '', true ); |
38 | if ( $maybeDim && Utils::validateMediaParam( $maybeDim['x'] ) ) { |
39 | $this->imageHeight = $maybeDim['x']; |
40 | } |
41 | |
42 | $mode = strtolower( $attrs['mode'] ?? '' ); |
43 | if ( Mode::byName( $mode ) !== null ) { |
44 | $this->mode = $mode; |
45 | } |
46 | |
47 | $this->showfilename = isset( $attrs['showfilename'] ); |
48 | $this->showthumbnails = isset( $attrs['showthumbnails'] ); |
49 | $this->caption = (bool)( $attrs['caption'] ?? false ); |
50 | |
51 | // TODO: Good contender for T54941 |
52 | $validUlAttrs = Sanitizer::attributesAllowedInternal( 'ul' ); |
53 | $this->attrs = []; |
54 | foreach ( $attrs as $k => $v ) { |
55 | if ( !isset( $validUlAttrs[$k] ) ) { |
56 | continue; |
57 | } |
58 | if ( $k === 'style' ) { |
59 | $v = Sanitizer::checkCss( $v ); |
60 | } |
61 | $this->attrs[$k] = $v; |
62 | } |
63 | } |
64 | |
65 | /** @var array<string,string> */ |
66 | public $attrs; |
67 | |
68 | /** @var int */ |
69 | public $imagesPerRow; |
70 | |
71 | /** @var int */ |
72 | public $imageWidth; |
73 | |
74 | /** @var int */ |
75 | public $imageHeight; |
76 | |
77 | /** @var string */ |
78 | public $mode; |
79 | |
80 | /** @var bool */ |
81 | public $showfilename; |
82 | |
83 | /** @var bool */ |
84 | public $showthumbnails; |
85 | |
86 | /** @var bool */ |
87 | public $caption; |
88 | |
89 | } |