Index: trunk/extensions/PageSchemas/specials/PS_EditSchema.php |
— | — | @@ -94,64 +94,15 @@ |
95 | 95 | $text_ex = preg_replace( '/starter/', '1', $htmlFromExtensions['sf_form'] ); |
96 | 96 | $text .= $text_ex; |
97 | 97 | } |
98 | | - $delimeter_label = wfMsg( 'ps-delimeter-label' ); |
99 | | - $multiple_temp_label = wfMsg( 'ps-multiple-temp-label' ); |
100 | | - $field_list_label = wfMsg( 'ps-field-list-label' ); |
101 | 98 | |
102 | 99 | $text .= '<div id="templatesList">'; |
103 | 100 | $text .= '<div class="templateBox" >'; |
104 | | - $text .= '<fieldset style="background: #ddd;"><legend>Template</legend> '; |
105 | | - $text .= '<p>Name: <input type="text" name="t_name_1"/></p> '; |
106 | | - $text .= '<p><input type="checkbox" name="is_multiple_1"/> '.$multiple_temp_label.'</p> '; |
107 | | - $text .= '<div id="fieldsList_1">'; |
108 | | - $text .= '<div class="fieldBox" >'; |
109 | | - $text .= '<fieldset style="background: #bbb;"><legend>Field</legend> |
110 | | - <p>Field name: <input size="15" name="f_name_1"> |
111 | | - Display label: <input size="15" name="f_label_1"> |
112 | | - </p> |
113 | | - <p><input type="checkbox" name="f_is_list_1" class="isListCheckbox" />'. |
114 | | - $field_list_label . ' |
115 | | - </p> |
116 | | - <div class="delimiterInput" style="display: none" ><p>' . $delimeter_label . ' <input type="text" name="f_delimiter_1" /> </p></div>'; |
117 | | - if ( $htmlFromExtensions['smw'] != null ) { |
118 | | - $text_ex = preg_replace( '/starter/', '1', $htmlFromExtensions['smw'] ); |
119 | | - $text .= $text_ex; |
120 | | - } |
121 | | - if ($htmlFromExtensions['sf'] != null ) { |
122 | | - $text_ex = preg_replace('/starter/', '1', $htmlFromExtensions['sf']); |
123 | | - $text .= $text_ex; |
124 | | - } |
125 | | - if ($htmlFromExtensions['sd'] != null ) { |
126 | | - $text_ex = preg_replace('/starter/', '1', $htmlFromExtensions['sd']); |
127 | | - $text .= $text_ex; |
128 | | - } |
| 101 | + $text .= '</div></div>'; |
129 | 102 | |
130 | | - $text .= '<p>' . $add_xml_label . ' |
131 | | - <textarea rows=4 style="width: 100%" name="f_add_xml_1"></textarea> |
132 | | - </p> |
133 | | - <input type="button" value="Remove field" class="deleteField" /></fieldset> |
134 | | - </div> |
135 | | - </div> |
136 | | - '; |
137 | | - $add_field_button = Xml::element( 'input', |
138 | | - array( |
139 | | - 'type' => 'button', |
140 | | - 'value' => 'Add field', |
141 | | - 'onclick' => "createTemplateAddField(1)" |
142 | | - ) |
143 | | - ); |
144 | | - $text .= Xml::tags( 'p', null, $add_field_button ) . "\n"; |
145 | | - $text .= '<hr /> |
146 | | - <p>'.$add_xml_label.' |
147 | | - <textarea rows=4 style="width: 100%" name="t_add_xml_1"></textarea> |
148 | | - </p> |
149 | | - <p><input type="button" value="Remove template" class="deleteTemplate" /></p> |
150 | | - </fieldset> </div></div>'; |
151 | | - |
152 | 103 | $add_template_button = Xml::element( 'input', |
153 | 104 | array( |
154 | 105 | 'type' => 'button', |
155 | | - 'value' => 'Add template', |
| 106 | + 'value' => wfMsg( 'ps-add-template' ), |
156 | 107 | 'onclick' => "createAddTemplate()" |
157 | 108 | ) |
158 | 109 | ); |
— | — | @@ -166,32 +117,59 @@ |
167 | 118 | } |
168 | 119 | |
169 | 120 | function starterFieldHTML( $htmlFromExtensions ) { |
170 | | - $starter_text = '<div class="templateBox" id="starterTemplate" style="display: none"> |
171 | | -<fieldset style="background: #ddd;"> |
172 | | -<legend>Template</legend> |
173 | | -<p>Name: <input type="text" name="t_name_starter"/></p> |
174 | | -<p><input type="checkbox" name="is_multiple_starter"/>Allow multiple instances of this template</p> |
175 | | -<div id="fieldsList_starter"> |
| 121 | + $template_label = wfMsg( 'pageschemas-template' ); |
| 122 | + $delimiter_label = wfMsg( 'ps-delimiter-label' ); |
| 123 | + $multiple_temp_label = wfMsg( 'ps-multiple-temp-label' ); |
| 124 | + $add_xml_label = wfMsg('ps-add-xml-label'); |
| 125 | + $field_list_label = wfMsg( 'ps-field-list-label' ); |
| 126 | + |
| 127 | + $starter_text = <<<END |
| 128 | +<div class="templateBox" id="starterTemplate" style="display: none"> |
| 129 | + <fieldset style="background: #ddd;"> |
| 130 | + <legend>$template_label</legend> |
| 131 | + <p>Name: <input type="text" name="t_name_starter"/></p> |
| 132 | + <p><input type="checkbox" name="is_multiple_starter"/>$multiple_temp_label</p> |
| 133 | + <div id="fieldsList_starter"> |
| 134 | + </div> |
| 135 | + |
| 136 | +END; |
| 137 | + $addFieldButton = Html::input( 'add-field', wfMsg( 'ps-add-field' ), 'button', |
| 138 | + array( 'onclick' => 'createTemplateAddField(starter)' ) |
| 139 | + ); |
| 140 | + $starter_text .= Html::rawElement( 'p', null, $addFieldButton ); |
| 141 | + $starter_text .= <<<END |
| 142 | + <hr /> |
| 143 | + <p>$add_xml_label |
| 144 | + <textarea rows=4 style="width: 100%" name="t_add_xml_starter"></textarea> |
| 145 | + </p> |
| 146 | + |
| 147 | +END; |
| 148 | + $removeTemplateButton = Html::input( 'remove-template', wfMsg( 'ps-remove-template' ), 'button', |
| 149 | + array( 'class' => 'deleteTemplate' ) |
| 150 | + ); |
| 151 | + $starter_text .= Html::rawElement( 'p', null, $removeTemplateButton ); |
| 152 | + $starter_text .= <<<END |
| 153 | + </fieldset> |
176 | 154 | </div> |
177 | | - <p><input type="button" value="Add Field" onclick="createTemplateAddField(starter)" /></p> |
| 155 | +<hr /> |
178 | 156 | |
179 | | -<hr /> |
180 | | - <p>'.$add_xml_label.' |
181 | | - <textarea rows=4 style="width: 100%" name="t_add_xml_starter"></textarea> |
182 | | - </p> |
183 | | - <p><input type="button" value="Remove template" class="deleteTemplate" /></p> |
184 | | - </fieldset> |
185 | | - </div> |
186 | | - <hr /> '; |
187 | | - $starter_text .= '<div class="fieldBox" id="starterField" style="display: none"> |
188 | | - <fieldset style="background: #bbb;"><legend>Field</legend> |
189 | | - <p> |
190 | | - <input size="15" name="f_name_starter"> |
191 | | - Display label: <input size="15" name="f_label_starter"> |
192 | | - </p> |
193 | | - <p><input type="checkbox" name="f_is_list_starter" class="isListCheckbox" /> This field can hold a list of values |
194 | | -   </p> |
195 | | - <div class="delimiterInput" style="display: none" ><p>Delimiter for values (default is ","): <input type="text" name="f_delimiter_starter" /> </p></div>'; |
| 157 | +END; |
| 158 | + $field_label = wfMsg( 'pageschemas-field' ); |
| 159 | + $display_label = wfMsg( 'pageschemas-displaylabel' ); |
| 160 | + $starter_text .= <<<END |
| 161 | +<div class="fieldBox" id="starterField" style="display: none"> |
| 162 | + <fieldset style="background: #bbb;"><legend>$field_label</legend> |
| 163 | + <p> |
| 164 | + Field name: <input size="15" name="f_name_starter"> |
| 165 | + $display_label <input size="15" name="f_label_starter"> |
| 166 | + </p> |
| 167 | + <p><input type="checkbox" name="f_is_list_starter" class="isListCheckbox" /> $field_list_label |
| 168 | +   </p> |
| 169 | + <p class="delimiterInput" style="display: none" > |
| 170 | + $delimiter_label <input type="text" name="f_delimiter_starter" /> |
| 171 | + </p> |
| 172 | + |
| 173 | +END; |
196 | 174 | if ($htmlFromExtensions['smw'] != null ) { |
197 | 175 | $starter_text .= $htmlFromExtensions['smw']; |
198 | 176 | } |
— | — | @@ -201,12 +179,21 @@ |
202 | 180 | if ($htmlFromExtensions['sd'] != null ) { |
203 | 181 | $starter_text .= $htmlFromExtensions['sd']; |
204 | 182 | } |
205 | | - $starter_text .= '<p>'.$add_xml_label.' |
206 | | - <textarea rows=4 style="width: 100%" name="f_add_xml_starter"></textarea> |
207 | | - </p> |
208 | | - <input type="button" value="Remove field" class="deleteField" /> |
209 | | -</fieldset> |
210 | | -</div>'; |
| 183 | + $starter_text .= <<<END |
| 184 | + <p>$add_xml_label |
| 185 | + <textarea rows=4 style="width: 100%" name="f_add_xml_starter"></textarea> |
| 186 | + </p> |
| 187 | + |
| 188 | +END; |
| 189 | + $removeFieldButton = Html::input( 'remove-field', wfMsg( 'ps-remove-field' ), 'button', |
| 190 | + array( 'class' => 'deleteField' ) |
| 191 | + ); |
| 192 | + $starter_text .= $removeFieldButton; |
| 193 | + $starter_text .= <<<END |
| 194 | + </fieldset> |
| 195 | +</div> |
| 196 | + |
| 197 | +END; |
211 | 198 | return $starter_text; |
212 | 199 | } |
213 | 200 | |
— | — | @@ -231,7 +218,7 @@ |
232 | 219 | $ps_add_xml = $wgRequest->getText( 'ps_add_xml' ); |
233 | 220 | $XMLtext .= $ps_add_xml; |
234 | 221 | $fieldName = ""; |
235 | | - $fieldNum= -1; |
| 222 | + $fieldNum = -1; |
236 | 223 | $templateNum = -1; |
237 | 224 | $xmlFromExtensions = array(); //This var. will save the xml text returned by the extensions |
238 | 225 | wfRunHooks( 'getXmlTextForFieldInputs', array( $wgRequest, &$xmlFromExtensions )); |
— | — | @@ -252,15 +239,15 @@ |
253 | 240 | $fieldNum = substr($var,7,1); |
254 | 241 | if ($wgRequest->getCheck( 'f_is_list_'.$fieldNum ) ) { |
255 | 242 | if ( $wgRequest->getText('f_delimiter_'.$fieldNum) != '' ) { |
256 | | - $delimeter = $wgRequest->getText('f_delimiter_'.$fieldNum); |
257 | | - $XMLtext .= '<Field name="'.$fieldName.'" list="list" delimiter="'.$delimeter.'">'; |
| 243 | + $delimiter = $wgRequest->getText('f_delimiter_'.$fieldNum); |
| 244 | + $XMLtext .= '<Field name="'.$fieldName.'" list="list" delimiter="'.$delimiter.'">'; |
258 | 245 | } else { |
259 | 246 | $XMLtext .= '<Field name="'.$fieldName.'" list="list">'; |
260 | 247 | } |
261 | 248 | } else { |
262 | 249 | $XMLtext .= '<Field name="'.$fieldName.'">'; |
263 | 250 | } |
264 | | - } elseif (substr($var,0,8) == 'f_label_' ) { |
| 251 | + } elseif ( substr( $var, 0, 8 ) == 'f_label_' ) { |
265 | 252 | $XMLtext .= '<Label>'.$val.'</Label>'; |
266 | 253 | //Get XML parsed from extensions |
267 | 254 | if ( $xmlFromExtensions['smw'] != null ) { |
— | — | @@ -282,10 +269,10 @@ |
283 | 270 | } |
284 | 271 | } |
285 | 272 | $indexGlobalField++ ; |
286 | | - } elseif (substr($var,0,10) == 'f_add_xml_' ) { |
| 273 | + } elseif ( substr( $var, 0, 10 ) == 'f_add_xml_' ) { |
287 | 274 | $XMLtext .= $val; |
288 | 275 | $XMLtext .= '</Field>'; |
289 | | - } elseif (substr($var,0,10) == 't_add_xml_' ) { |
| 276 | + } elseif ( substr( $var, 0, 10 ) == 't_add_xml_' ) { |
290 | 277 | $XMLtext .= $val; |
291 | 278 | $XMLtext .= '</Template>'; |
292 | 279 | } |
— | — | @@ -328,14 +315,14 @@ |
329 | 316 | 'pp_propname' => 'PageSchema' |
330 | 317 | ) |
331 | 318 | ); |
| 319 | + $editSchemaPage = SpecialPage::getTitleFor( 'EditSchema' ); |
332 | 320 | while ( $row = $dbr->fetchRow( $res ) ) { |
333 | 321 | if ( $row[2] != null ) { |
334 | 322 | $page_id_cat = $row[0]; |
335 | 323 | if ( Title::newFromId($page_id_cat)->getNamespace() == NS_CATEGORY ) { |
336 | 324 | $cat_text = Title::newFromId($page_id_cat)->getText(); |
337 | | - $generatePagesPage = SpecialPage::getTitleFor( 'EditSchema' ); |
338 | | - $url = $generatePagesPage ->getFullURL() . '/' . $cat_text; |
339 | | - $text .= '<a href='.$url.'>' . $cat_text . '</a> <br /> '; |
| 325 | + $url = $editSchemaPage ->getFullURL() . '/' . $cat_text; |
| 326 | + $text .= Html::element( 'a', array( 'href' => $url ), $cat_text ) . '<br />'; |
340 | 327 | } |
341 | 328 | } |
342 | 329 | } |
— | — | @@ -367,7 +354,7 @@ |
368 | 355 | //first row of the result set |
369 | 356 | $row = $dbr->fetchRow( $res ); |
370 | 357 | if ( $row == null && !$title->exists() ) { |
371 | | - //Create form here, Cat doesnt exist, create new cat with this text |
| 358 | + // Category doesn't exist. |
372 | 359 | $text = '<p>'.wfMsg( 'ps-page-desc-cat-not-exist' ).'</p>'; |
373 | 360 | $text .= $formHTML; |
374 | 361 | $wgOut->addHTML( $text ); |
— | — | @@ -375,12 +362,15 @@ |
376 | 363 | } |
377 | 364 | |
378 | 365 | if ( ($row[1] != 'PageSchema') || ($row[2] == null ) ) { |
| 366 | + // Category exists, but has no page schema. |
379 | 367 | $text = '<p>'.wfMsg( 'ps-page-desc-ps-not-exist' ).'</p>'; |
380 | 368 | $text .= $formHTML; |
381 | 369 | $wgOut->addHTML($text ); |
| 370 | + return true; |
382 | 371 | } |
383 | 372 | |
384 | | - // Populate the form here with autocompleted values |
| 373 | + // If we're here, it's a category with an existing page schema - populate the |
| 374 | + // form with its values. |
385 | 375 | $pageXMLstr = $row[2]; |
386 | 376 | $pageXML = simplexml_load_string( $pageXMLstr ); |
387 | 377 | $ps_add_xml = ""; |
— | — | @@ -411,30 +401,28 @@ |
412 | 402 | $template_num++; |
413 | 403 | $field_count = 0; |
414 | 404 | if ( count($template_xml->children()) > 0 ) { |
415 | | - $templateName = (string) $template_xml->attributes()->name; |
416 | 405 | $text_4 .= '<div class="templateBox" >'; |
417 | 406 | $text_4 .= '<fieldset style="background: #ddd;"><legend>Template</legend> '; |
418 | | - $text_4 .= '<p>Name: <input type="text" name="t_name_'.$template_num.'" value="'.$templateName.'" /></p> '; |
| 407 | + $templateName = (string) $template_xml->attributes()->name; |
| 408 | + $templateNameInput = Html::input( 't_name_' . $template_num, $templateName, 'text' ); |
| 409 | + $text_4 .= '<p>Name: ' . $templateNameInput . '</p> '; |
| 410 | + $attrs = array(); |
419 | 411 | if ( ((string) $template_xml->attributes()->multiple) == "multiple" ) { |
420 | | - $text_4 .= '<p><input type="checkbox" checked name="is_multiple_'.$template_num.'"/> Allow multiple instances of this template</p> '; |
421 | | - } else { |
422 | | - $text_4 .= '<p><input type="checkbox" name="is_multiple_'.$template_num.'"/> Allow multiple instances of this template</p> '; |
| 412 | + $attrs['checked'] = 'checked'; |
423 | 413 | } |
| 414 | + $templateIsMultipleInput = Html::input( 'is_multiple_' . $template_num, null, 'checkbox', $attrs ); |
| 415 | + $text_4 .= Html::rawElement( 'p', null, $templateIsMultipleInput . ' ' . wfMsg( 'ps-multiple-temp-label' ) ); |
424 | 416 | foreach ( $template_xml->children() as $field_xml ) { |
425 | 417 | if ( $field_xml->getName() != 'Field' ) { |
426 | 418 | $template_add_xml .= (string)$field_xml->asXML(); |
427 | 419 | } |
428 | 420 | } |
429 | 421 | $text_4 .= '<div id="fieldsList_'.$template_num.'">'; |
430 | | - $list_values = false; |
431 | 422 | foreach ( $template_xml->children() as $field_xml ) { |
432 | 423 | if ( $field_xml->getName() == "Field" ) { |
433 | 424 | $fieldName = (string)$field_xml->attributes()->name; |
434 | 425 | $text_4 .= '<div class="fieldBox" >'; |
435 | 426 | $text_4 .= '<fieldset style="background: #bbb;"><legend>Field</legend> '; |
436 | | - if ( ((string)$field_xml->attributes()->list) == "list") { |
437 | | - $list_values = true; |
438 | | - } |
439 | 427 | if ( ((string)$field_xml->attributes()->delimiter) != null || ((string)$field_xml->attributes()->delimiter) != '' ) { |
440 | 428 | $delimiter = (string)$field_xml->attributes()->delimiter; |
441 | 429 | } |
— | — | @@ -444,15 +432,21 @@ |
445 | 433 | } |
446 | 434 | } |
447 | 435 | $text_4 .= '<p>Field name: <input size="15" name="f_name_'.$field_count.'" value="'.$fieldName.'" >'; |
448 | | - $text_4 .= 'Display label: <input size="15" name="f_label_'.$field_count.'" value="'.$fieldLabel.'" > |
| 436 | + $display_label = wfMsg( 'pageschemas-displaylabel' ); |
| 437 | + $text_4 .= $display_label . ' <input size="15" name="f_label_'.$field_count.'" value="'.$fieldLabel.'" > |
449 | 438 | </p> '; |
450 | | - if ($list_values ) { |
451 | | - $text_4 .= '<p><input type="checkbox" name="f_is_list_'.$field_count.'" checked class="isListCheckbox" /> This field can hold a list of values</p> '; |
452 | | - $text_4 .= '<div class="delimiterInput" style="display:"><p>Delimiter for values (default is ","): <input type="text" name="f_delimiter_'.$field_count.'" value="'.$delimiter.'" /> </p></div>'; |
| 439 | + $attrs = array(); |
| 440 | + $pAttrs = array( 'class' => 'delimiterInput' ); |
| 441 | + if ( ((string)$field_xml->attributes()->list) == "list" ) { |
| 442 | + $attrs['checked'] = 'checked'; |
453 | 443 | } else { |
454 | | - $text_4 .= '<p><input type="checkbox" name="f_is_list_'.$field_count.'" class="isListCheckbox" /> This field can hold a list of values</p> '; |
455 | | - $text_4 .= '<div class="delimiterInput" style="display: none" ><p>Delimiter for values (default is ","): <input type="text" name="f_delimiter_'.$field_count.'" /> </p></div>'; |
| 444 | + $pAttrs['style'] = 'display: none'; |
456 | 445 | } |
| 446 | + $fieldIsListInput = Html::input( 'f_is_list_' . $field_count, null, 'checkbox', $attrs ); |
| 447 | + $text_4 .= Html::rawElement( 'p', null, $fieldIsListInput . ' ' . wfMsg( 'ps-field-list-label' ) ); |
| 448 | + $fieldDelimiterInput = Html::input ( 'f_delimiter_' . $field_count, $delimiter, 'text', null ); |
| 449 | + $text_4 .= Html::rawElement( 'p', $pAttrs, wfMsg( 'ps-delimiter-label' ) . ' ' . $fieldDelimiterInput ); |
| 450 | + |
457 | 451 | //Inserting HTML text from Extensions |
458 | 452 | |
459 | 453 | if ( $filledHTMLFromExtensions['smw'] != null ) { |
— | — | @@ -477,13 +471,22 @@ |
478 | 472 | } |
479 | 473 | } |
480 | 474 | |
481 | | - $text_4 .= '<p>'.$add_xml_label.' |
482 | | - <textarea rows=4 style="width: 100%" name="f_add_xml_'.$field_count.'"></textarea> |
| 475 | + $text_4 .= <<<END |
| 476 | + <p>$add_xml_label |
| 477 | + <textarea rows=4 style="width: 100%" name="f_add_xml_$field_count"></textarea> |
483 | 478 | </p> |
484 | | - <input type="button" value="Remove field" class="deleteField" /></fieldset> |
| 479 | + |
| 480 | +END; |
| 481 | + $removeFieldButton = Html::input( 'remove-field', wfMsg( 'ps-remove-field' ), 'button', |
| 482 | + array( 'class' => 'deleteField' ) |
| 483 | + ); |
| 484 | + $text_4 .= $removeFieldButton; |
| 485 | + $text_4 .= <<<END |
| 486 | + </fieldset> |
485 | 487 | </div> |
486 | 488 | </div> |
487 | | - '; |
| 489 | + |
| 490 | +END; |
488 | 491 | $field_count++; |
489 | 492 | $text_4 .= '<script type="text/javascript"> |
490 | 493 | updateFieldNum('.$field_count.'); |
— | — | @@ -494,7 +497,7 @@ |
495 | 498 | $add_field_button = Xml::element( 'input', |
496 | 499 | array( |
497 | 500 | 'type' => 'button', |
498 | | - 'value' => 'Add field', |
| 501 | + 'value' => wfMsg( 'ps-add-field' ), |
499 | 502 | 'onclick' => "createTemplateAddField($template_num)" |
500 | 503 | ) |
501 | 504 | ); |
— | — | @@ -511,7 +514,7 @@ |
512 | 515 | $add_template_button = Xml::element( 'input', |
513 | 516 | array( |
514 | 517 | 'type' => 'button', |
515 | | - 'value' => 'Add template', |
| 518 | + 'value' => wfMsg( 'ps-add-template' ), |
516 | 519 | 'onclick' => "createAddTemplate()" |
517 | 520 | ) |
518 | 521 | ); |