|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* File containing the Modification class |
|
4
|
|
|
* |
|
5
|
|
|
* This file is part of the MediaWiki skin Chameleon. |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright 2013 - 2014, Stephan Gambke |
|
8
|
|
|
* @license GNU General Public License, version 3 (or any later version) |
|
9
|
|
|
* |
|
10
|
|
|
* The Chameleon skin is free software: you can redistribute it and/or modify |
|
11
|
|
|
* it under the terms of the GNU General Public License as published by the Free |
|
12
|
|
|
* Software Foundation, either version 3 of the License, or (at your option) any |
|
13
|
|
|
* later version. |
|
14
|
|
|
* |
|
15
|
|
|
* The Chameleon skin is distributed in the hope that it will be useful, but |
|
16
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
17
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
18
|
|
|
* details. |
|
19
|
|
|
* |
|
20
|
|
|
* You should have received a copy of the GNU General Public License along |
|
21
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>. |
|
22
|
|
|
* |
|
23
|
|
|
* @file |
|
24
|
|
|
* @ingroup Skins |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace Skins\Chameleon\Components\Modifications; |
|
28
|
|
|
|
|
29
|
|
|
use Skins\Chameleon\ChameleonTemplate; |
|
30
|
|
|
use Skins\Chameleon\Components\Component; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Modification class |
|
34
|
|
|
* |
|
35
|
|
|
* This is the abstract base class of all modifications. |
|
36
|
|
|
* |
|
37
|
|
|
* Follows the Decorator pattern (Decorator role). |
|
38
|
|
|
* |
|
39
|
|
|
* @author Stephan Gambke |
|
40
|
|
|
* @since 1.0 |
|
41
|
|
|
* @ingroup Skins |
|
42
|
|
|
*/ |
|
43
|
|
|
abstract class Modification extends Component { |
|
44
|
|
|
|
|
45
|
|
|
private $component = null; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param Component $component |
|
49
|
|
|
* @param \DOMElement $domElement |
|
50
|
|
|
*/ |
|
51
|
2 |
|
public function __construct( Component $component, \DOMElement $domElement = null ) { |
|
52
|
|
|
|
|
53
|
2 |
|
$this->component = $component; |
|
54
|
2 |
|
parent::__construct( $component->getSkinTemplate(), $domElement, $component->getIndent() ); |
|
55
|
2 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* This method should apply any modifications to the decorated component |
|
59
|
|
|
* available from the getComponent() method. |
|
60
|
|
|
*/ |
|
61
|
|
|
abstract protected function applyModification(); |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return \DOMElement|null |
|
65
|
|
|
*/ |
|
66
|
|
|
public function getDomElementOfModification() { |
|
67
|
|
|
return parent::getDomElement(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return \DOMElement |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getDomElementOfComponent() { |
|
74
|
|
|
return $this->getDomElement(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Sets the class string that should be assigned to the top-level html element of this component |
|
79
|
|
|
* |
|
80
|
|
|
* @param string | array | null $classes |
|
81
|
|
|
* |
|
82
|
|
|
*/ |
|
83
|
|
|
public function setClasses( $classes ) { |
|
84
|
|
|
$this->getComponent()->setClasses( $classes ); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return Component |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getComponent() { |
|
91
|
|
|
return $this->component; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @param Component $component |
|
96
|
|
|
* @since 1.1 |
|
97
|
|
|
*/ |
|
98
|
7 |
|
protected function setComponent( Component $component ) { |
|
99
|
7 |
|
$this->component = $component; |
|
100
|
7 |
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Adds the given class to the class string that should be assigned to the top-level html element of this component |
|
104
|
|
|
* |
|
105
|
|
|
* @param string | array | null $classes |
|
106
|
|
|
* |
|
107
|
|
|
* @return string | array |
|
108
|
|
|
*/ |
|
109
|
|
|
public function addClasses( $classes ) { |
|
110
|
|
|
$this->getComponent()->addClasses( $classes ); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @return ChameleonTemplate |
|
115
|
|
|
*/ |
|
116
|
|
|
public function getSkinTemplate() { |
|
117
|
|
|
return $this->getComponent()->getSkinTemplate(); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Returns the current indentation level |
|
122
|
|
|
* |
|
123
|
|
|
* @return int |
|
124
|
|
|
*/ |
|
125
|
|
|
public function getIndent() { |
|
126
|
|
|
return $this->getComponent()->getIndent(); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Returns the class string that should be assigned to the top-level html element of this component |
|
131
|
|
|
* |
|
132
|
|
|
* @return string |
|
133
|
|
|
*/ |
|
134
|
|
|
public function getClassString() { |
|
135
|
|
|
return $this->getComponent()->getClassString(); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Removes the given class from the class string that should be assigned to the top-level html element of this component |
|
140
|
|
|
* |
|
141
|
|
|
* @param string | array | null $classes |
|
142
|
|
|
* |
|
143
|
|
|
* @return string |
|
144
|
|
|
*/ |
|
145
|
|
|
public function removeClasses( $classes ) { |
|
146
|
|
|
$this->getComponent()->removeClasses( $classes ); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Returns the DOMElement from the description XML file associated with this element. |
|
151
|
|
|
* |
|
152
|
|
|
* @return \DOMElement |
|
153
|
|
|
*/ |
|
154
|
|
|
public function getDomElement() { |
|
155
|
|
|
return $this->getComponent()->getDomElement(); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* Builds the HTML code for this component |
|
160
|
|
|
* |
|
161
|
|
|
* @return String the HTML code |
|
162
|
|
|
*/ |
|
163
|
7 |
|
public function getHtml() { |
|
164
|
7 |
|
$this->applyModification(); |
|
165
|
7 |
|
return $this->getComponent()->getHtml(); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @return array the resource loader modules needed by this component |
|
170
|
|
|
*/ |
|
171
|
|
|
public function getResourceLoaderModules() { |
|
172
|
|
|
return $this->getComponent()->getResourceLoaderModules(); |
|
173
|
|
|
} |
|
174
|
|
|
} |
|
175
|
|
|
|