Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 59 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
PFLeafletInput | |
0.00% |
0 / 59 |
|
0.00% |
0 / 5 |
182 | |
0.00% |
0 / 1 |
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDefaultCargoTypes | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getOtherCargoTypesHandled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getHTML | |
0.00% |
0 / 49 |
|
0.00% |
0 / 1 |
90 | |||
getHtmlText | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * @author Peter Grassberger |
4 | * @author Yaron Koren |
5 | * @file |
6 | * @ingroup PF |
7 | */ |
8 | |
9 | /** |
10 | * @ingroup PFFormInput |
11 | */ |
12 | class PFLeafletInput extends PFOpenLayersInput { |
13 | |
14 | public static function getName(): string { |
15 | return 'leaflet'; |
16 | } |
17 | |
18 | public static function getDefaultCargoTypes() { |
19 | return []; |
20 | } |
21 | |
22 | public static function getOtherCargoTypesHandled() { |
23 | return [ 'Coordinates' ]; |
24 | } |
25 | |
26 | public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, array $other_args ) { |
27 | global $wgOut; |
28 | |
29 | $scripts = [ |
30 | "https://unpkg.com/leaflet@1.1.0/dist/leaflet.js" |
31 | ]; |
32 | $styles = [ |
33 | "https://unpkg.com/leaflet@1.1.0/dist/leaflet.css" |
34 | ]; |
35 | $scriptsHTML = ''; |
36 | $stylesHTML = ''; |
37 | foreach ( $scripts as $script ) { |
38 | $scriptsHTML .= Html::linkedScript( $script ); |
39 | } |
40 | foreach ( $styles as $style ) { |
41 | $stylesHTML .= Html::linkedStyle( $style ); |
42 | } |
43 | $wgOut->addHeadItem( $scriptsHTML, $scriptsHTML ); |
44 | $wgOut->addHeadItem( $stylesHTML, $stylesHTML ); |
45 | $wgOut->addModules( 'ext.pageforms.maps' ); |
46 | |
47 | if ( array_key_exists( 'image', $other_args ) ) { |
48 | global $wgUploadDirectory; |
49 | $fileName = $other_args['image']; |
50 | $fileTitle = Title::makeTitleSafe( NS_FILE, $fileName ); |
51 | $imagePage = new ImagePage( $fileTitle ); |
52 | $file = $imagePage->getDisplayedFile(); |
53 | $filePath = $wgUploadDirectory . '/' . $file->getUrlRel(); |
54 | list( $imageWidth, $imageHeight, $type, $attr ) = getimagesize( $filePath ); |
55 | if ( !array_key_exists( 'height', $other_args ) && !array_key_exists( 'width', $other_args ) ) { |
56 | // Scale down image if it's huge. |
57 | $maxDimension = max( $imageHeight, $imageWidth ); |
58 | $maxAllowedSize = 1000; |
59 | if ( $maxDimension > $maxAllowedSize ) { |
60 | $imageHeight *= $maxAllowedSize / $maxDimension; |
61 | $imageWidth *= $maxAllowedSize / $maxDimension; |
62 | } |
63 | $height = $imageHeight . 'px'; |
64 | $width = $imageWidth . 'px'; |
65 | } else { |
66 | $height = self::getHeight( $other_args ); |
67 | $width = self::getWidth( $other_args ); |
68 | // Reduce image height and width if necessary, |
69 | // to fit it into the display. |
70 | $heightRatio = (int)$height / $imageHeight; |
71 | $widthRatio = (int)$width / $imageWidth; |
72 | $smallerRatio = min( $heightRatio, $widthRatio ); |
73 | if ( $smallerRatio < 1 ) { |
74 | $imageHeight *= $smallerRatio; |
75 | $imageWidth *= $smallerRatio; |
76 | } |
77 | } |
78 | } else { |
79 | $fileName = null; |
80 | $height = self::getHeight( $other_args ); |
81 | $width = self::getWidth( $other_args ); |
82 | } |
83 | |
84 | $fullInputHTML = self::mapLookupHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, $other_args, $height, $width, $fileName == null ); |
85 | |
86 | $divAttrs = [ 'class' => 'pfLeafletInput' ]; |
87 | if ( $fileName !== null ) { |
88 | $divAttrs['data-image-path'] = $file->getUrl(); |
89 | $divAttrs['data-height'] = $imageHeight; |
90 | $divAttrs['data-width'] = $imageWidth; |
91 | } |
92 | |
93 | $text = Html::rawElement( 'div', $divAttrs, $fullInputHTML ); |
94 | |
95 | return $text; |
96 | } |
97 | |
98 | /** |
99 | * Returns the HTML code to be included in the output page for this input. |
100 | * @return string |
101 | */ |
102 | public function getHtmlText(): string { |
103 | return self::getHTML( |
104 | $this->mCurrentValue, |
105 | $this->mInputName, |
106 | $this->mIsMandatory, |
107 | $this->mIsDisabled, |
108 | $this->mOtherArgs |
109 | ); |
110 | } |
111 | } |