Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 100 |
|
0.00% |
0 / 16 |
CRAP | |
0.00% |
0 / 1 |
PFPageSection | |
0.00% |
0 / 100 |
|
0.00% |
0 / 16 |
1406 | |
0.00% |
0 / 1 |
create | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
newFromFormTag | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
272 | |||
getSectionName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getSectionLevel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setSectionLevel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setIsMandatory | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isMandatory | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setIsHidden | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isHidden | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setIsRestricted | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isRestricted | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isHideIfEmpty | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setSectionArgs | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getSectionArgs | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
createMarkup | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
56 | |||
getParameters | |
0.00% |
0 / 37 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Represents a page section in a user-defined form. |
4 | * This class should really be called "PFPageSectionInForm", to differentiate |
5 | * it from the PFWikiPageSection class. |
6 | * |
7 | * @author Himeshi |
8 | * @file |
9 | * @ingroup PF |
10 | */ |
11 | class PFPageSection { |
12 | private $mSectionName; |
13 | private $mSectionLevel = 2; |
14 | private $mIsMandatory = false; |
15 | private $mIsHidden = false; |
16 | private $mIsRestricted = false; |
17 | private $mHideIfEmpty = false; |
18 | private $mSectionArgs = []; |
19 | |
20 | static function create( $section_name ) { |
21 | $ps = new PFPageSection(); |
22 | $ps->mSectionName = $section_name; |
23 | |
24 | return $ps; |
25 | } |
26 | |
27 | static function newFromFormTag( $tag_components, User $user ) { |
28 | $ps = new PFPageSection(); |
29 | $ps->mSectionName = trim( $tag_components[1] ); |
30 | |
31 | // cycle through the other components |
32 | for ( $i = 2; $i < count( $tag_components ); $i++ ) { |
33 | $component = trim( $tag_components[$i] ); |
34 | |
35 | if ( $component === 'mandatory' ) { |
36 | $ps->mIsMandatory = true; |
37 | } elseif ( $component === 'hidden' ) { |
38 | $ps->mIsHidden = true; |
39 | } elseif ( $component === 'restricted' ) { |
40 | $ps->mIsRestricted = ( !$user || !$user->isAllowed( 'editrestrictedfields' ) ); |
41 | } elseif ( $component === 'autogrow' ) { |
42 | $ps->mSectionArgs['autogrow'] = true; |
43 | } elseif ( $component === 'hide if empty' ) { |
44 | $ps->mHideIfEmpty = true; |
45 | } |
46 | |
47 | $sub_components = array_map( 'trim', explode( '=', $component, 2 ) ); |
48 | |
49 | if ( count( $sub_components ) === 2 ) { |
50 | switch ( $sub_components[0] ) { |
51 | case 'level': |
52 | $ps->mSectionLevel = $sub_components[1]; |
53 | break; |
54 | case 'rows': |
55 | case 'cols': |
56 | case 'class': |
57 | case 'editor': |
58 | case 'placeholder': |
59 | $ps->mSectionArgs[$sub_components[0]] = $sub_components[1]; |
60 | break; |
61 | default: |
62 | // Ignore unknown |
63 | } |
64 | } |
65 | } |
66 | return $ps; |
67 | } |
68 | |
69 | public function getSectionName() { |
70 | return $this->mSectionName; |
71 | } |
72 | |
73 | public function getSectionLevel() { |
74 | return $this->mSectionLevel; |
75 | } |
76 | |
77 | public function setSectionLevel( $section_level ) { |
78 | $this->mSectionLevel = $section_level; |
79 | } |
80 | |
81 | public function setIsMandatory( $isMandatory ) { |
82 | $this->mIsMandatory = $isMandatory; |
83 | } |
84 | |
85 | public function isMandatory() { |
86 | return $this->mIsMandatory; |
87 | } |
88 | |
89 | public function setIsHidden( $isHidden ) { |
90 | $this->mIsHidden = $isHidden; |
91 | } |
92 | |
93 | public function isHidden() { |
94 | return $this->mIsHidden; |
95 | } |
96 | |
97 | public function setIsRestricted( $isRestricted ) { |
98 | $this->mIsRestricted = $isRestricted; |
99 | } |
100 | |
101 | public function isRestricted() { |
102 | return $this->mIsRestricted; |
103 | } |
104 | |
105 | public function isHideIfEmpty() { |
106 | return $this->mHideIfEmpty; |
107 | } |
108 | |
109 | public function setSectionArgs( $key, $value ) { |
110 | $this->mSectionArgs[$key] = $value; |
111 | } |
112 | |
113 | public function getSectionArgs() { |
114 | return $this->mSectionArgs; |
115 | } |
116 | |
117 | function createMarkup() { |
118 | $section_name = $this->mSectionName; |
119 | $section_level = $this->mSectionLevel; |
120 | // Set default section level to 2 |
121 | if ( $section_level == '' ) { |
122 | $section_level = 2; |
123 | } |
124 | // display the section headers in wikitext |
125 | $header_string = ""; |
126 | $header_string .= str_repeat( "=", $section_level ); |
127 | $text = $header_string . $section_name . $header_string . "\n"; |
128 | |
129 | $text .= "{{{section|" . $section_name . "|level=" . $section_level; |
130 | |
131 | if ( $this->mIsMandatory ) { |
132 | $text .= "|mandatory"; |
133 | } elseif ( $this->mIsRestricted ) { |
134 | $text .= "|restricted"; |
135 | } elseif ( $this->mIsHidden ) { |
136 | $text .= "|hidden"; |
137 | } |
138 | foreach ( $this->mSectionArgs as $arg => $value ) { |
139 | if ( $value === true ) { |
140 | $text .= "|$arg"; |
141 | } else { |
142 | $text .= "|$arg=$value"; |
143 | } |
144 | } |
145 | $text .= "}}}\n"; |
146 | |
147 | return $text; |
148 | } |
149 | |
150 | public static function getParameters() { |
151 | $params = []; |
152 | |
153 | $params['mandatory'] = [ |
154 | 'name' => 'mandatory', |
155 | 'type' => 'boolean', |
156 | 'description' => wfMessage( 'pf_forminputs_mandatory' )->text() |
157 | ]; |
158 | $params['restricted'] = [ |
159 | 'name' => 'restricted', |
160 | 'type' => 'boolean', |
161 | 'description' => wfMessage( 'pf_forminputs_restricted' )->text() |
162 | ]; |
163 | $params['hidden'] = [ |
164 | 'name' => 'hidden', |
165 | 'type' => 'boolean', |
166 | 'description' => wfMessage( 'pf_createform_hiddensection' )->text() |
167 | ]; |
168 | $params['class'] = [ |
169 | 'name' => 'class', |
170 | 'type' => 'string', |
171 | 'description' => wfMessage( 'pf_forminputs_class' )->text() |
172 | ]; |
173 | $params['rows'] = [ |
174 | 'name' => 'rows', |
175 | 'type' => 'int', |
176 | 'description' => wfMessage( 'pf_forminputs_rows' )->text() |
177 | ]; |
178 | $params['cols'] = [ |
179 | 'name' => 'cols', |
180 | 'type' => 'int', |
181 | 'description' => wfMessage( 'pf_forminputs_cols' )->text() |
182 | ]; |
183 | $params['autogrow'] = [ |
184 | 'name' => 'autogrow', |
185 | 'type' => 'boolean', |
186 | 'description' => wfMessage( 'pf_forminputs_autogrow' )->text() |
187 | ]; |
188 | |
189 | return $params; |
190 | } |
191 | } |