Index: trunk/extensions/PageSchemas/specials/PS_EditSchema.php |
— | — | @@ -3,6 +3,7 @@ |
4 | 4 | * Displays an interface to let users create and edit the <PageSchema> XML. |
5 | 5 | * |
6 | 6 | * @author Ankit Garg |
| 7 | + * @author Yaron Koren |
7 | 8 | */ |
8 | 9 | |
9 | 10 | class PSEditSchema extends IncludableSpecialPage { |
— | — | @@ -33,7 +34,7 @@ |
34 | 35 | .fadeOut('fast', function() { jQuery(this).remove(); }); |
35 | 36 | }); |
36 | 37 | jQuery('#fieldsList_'+template_num).append(newField); |
37 | | - addjQueryToCheckbox(); |
| 38 | + addjQueryToCheckboxes(); |
38 | 39 | } |
39 | 40 | |
40 | 41 | function psAddTemplate() { |
— | — | @@ -53,7 +54,14 @@ |
54 | 55 | fieldNum = field_num; |
55 | 56 | } |
56 | 57 | |
57 | | -function addjQueryToCheckbox( ) { |
| 58 | +function addjQueryToCheckboxes() { |
| 59 | + jQuery('.isListCheckbox').each(function() { |
| 60 | + if (jQuery(this).is(":checked")) { |
| 61 | + jQuery(this).closest('.fieldBox').find('.delimiterInput').css('display', ''); |
| 62 | + } else { |
| 63 | + jQuery(this).closest('.fieldBox').find('.delimiterInput').css('display', 'none'); |
| 64 | + } |
| 65 | + }); |
58 | 66 | jQuery('.isListCheckbox').click(function() { |
59 | 67 | if (jQuery(this).is(":checked")) { |
60 | 68 | jQuery(this).closest('.fieldBox').find('.delimiterInput').css('display', ''); |
— | — | @@ -74,7 +82,7 @@ |
75 | 83 | jQuery(this).closest(".templateBox") |
76 | 84 | .fadeOut('fast', function() { jQuery(this).remove(); }); |
77 | 85 | }); |
78 | | - addjQueryToCheckbox(); |
| 86 | + addjQueryToCheckboxes(); |
79 | 87 | jQuery('#editPageSchemaForm').submit( function() { |
80 | 88 | jQuery('#starterTemplate').find("input, select, textarea").attr('disabled', 'disabled'); |
81 | 89 | return true; |
— | — | @@ -218,8 +226,8 @@ |
219 | 227 | $fieldName = ''; |
220 | 228 | $delimiter = ''; |
221 | 229 | $fieldLabel = ''; |
222 | | - $attrs = array(); |
223 | | - $pAttrs = array( 'class' => 'delimiterInput' ); |
| 230 | + $isListAttrs = array( 'class' => 'isListCheckbox' ); |
| 231 | + $delimiterAttrs = array( 'class' => 'delimiterInput' ); |
224 | 232 | if ( is_null( $field_xml ) ) { |
225 | 233 | $text = '<div class="fieldBox" id="starterField" style="display: none" >'; |
226 | 234 | } else { |
— | — | @@ -234,9 +242,7 @@ |
235 | 243 | } |
236 | 244 | } |
237 | 245 | if ( ((string)$field_xml->attributes()->list) == "list" ) { |
238 | | - $attrs['checked'] = 'checked'; |
239 | | - } else { |
240 | | - $pAttrs['style'] = 'display: none'; |
| 246 | + $isListAttrs['checked'] = 'checked'; |
241 | 247 | } |
242 | 248 | } |
243 | 249 | $fieldHTML = '<p>Field name: '; |
— | — | @@ -244,10 +250,10 @@ |
245 | 251 | $fieldHTML .= wfMsg( 'ps-displaylabel' ) . ' '; |
246 | 252 | $fieldHTML .= Html::input( 'f_label_' . $field_count, $fieldLabel, 'text', array( 'size' => 15 ) ); |
247 | 253 | $fieldHTML .= "\t\t</p>\n"; |
248 | | - $fieldIsListInput = Html::input( 'f_is_list_' . $field_count, null, 'checkbox', $attrs ); |
| 254 | + $fieldIsListInput = Html::input( 'f_is_list_' . $field_count, null, 'checkbox', $isListAttrs ); |
249 | 255 | $fieldHTML .= Html::rawElement( 'p', null, $fieldIsListInput . ' ' . wfMsg( 'ps-field-list-label' ) ); |
250 | | - $fieldDelimiterInput = Html::input ( 'f_delimiter_' . $field_count, $delimiter, 'text', null ); |
251 | | - $fieldHTML .= Html::rawElement( 'p', $pAttrs, wfMsg( 'ps-delimiter-label' ) . ' ' . $fieldDelimiterInput ); |
| 256 | + $fieldDelimiterInput = Html::input ( 'f_delimiter_' . $field_count, $delimiter, 'text', array( 'size' => 3 ) ); |
| 257 | + $fieldHTML .= Html::rawElement( 'p', $delimiterAttrs, wfMsg( 'ps-delimiter-label' ) . ' ' . $fieldDelimiterInput ); |
252 | 258 | |
253 | 259 | // Insert HTML text from extensions |
254 | 260 | $htmlFromExtensions = array(); |
— | — | @@ -366,6 +372,7 @@ |
367 | 373 | $pageXMLChildren = $pageXML->children(); |
368 | 374 | } |
369 | 375 | |
| 376 | + $ps_add_xml = ''; |
370 | 377 | foreach ( $pageXMLChildren as $template_xml ) { |
371 | 378 | if ( ( $template_xml->getName() != 'Template') && ( $template_xml->getName() != 'semanticforms_Form' ) ) { |
372 | 379 | $ps_add_xml .= (string)$template_xml->asXML(); |
— | — | @@ -384,15 +391,15 @@ |
385 | 392 | $text .= '<div id="templatesList">'; |
386 | 393 | |
387 | 394 | $template_num = 0; |
388 | | - $pageSchemaTemplate = $template_all[$template_num]; |
389 | 395 | |
390 | 396 | // Add 'starter', hidden template section. |
391 | 397 | $text .= self::printTemplateSection(); |
392 | 398 | /* index for template objects */ |
393 | 399 | foreach ( $pageXMLChildren as $tag => $template_xml ) { |
394 | 400 | if ( $tag == 'Template' ) { |
| 401 | + $pageSchemaTemplate = $template_all[$template_num]; |
| 402 | + $text .= self::printTemplateSection( $template_num, $template_xml, $pageSchemaTemplate ); |
395 | 403 | $template_num++; |
396 | | - $text .= self::printTemplateSection( $template_num, $template_xml, $pageSchemaTemplate ); |
397 | 404 | } |
398 | 405 | } |
399 | 406 | $add_template_button = Xml::element( 'input', |
— | — | @@ -437,19 +444,23 @@ |
438 | 445 | $save_page = $wgRequest->getCheck( 'wpSave' ); |
439 | 446 | if ( $save_page ) { |
440 | 447 | $psXML = self::pageSchemaXMLFromRequest(); |
441 | | - $pageSchemaObj = new PSSchema( $category ); |
442 | 448 | $categoryTitle = Title::newFromText( $category, NS_CATEGORY ); |
443 | 449 | $categoryArticle = new Article( $categoryTitle ); |
444 | | - $pageText = $categoryArticle->getContent(); |
445 | | - if ( $pageSchemaObj->isPSDefined() ) { |
446 | | - // Do some preg_replace magic. |
447 | | - // This is necessary if the <PageSchema> tag |
448 | | - // accepts any attributes - which it currently |
449 | | - // does not, but it may well in the future. |
450 | | - $tag = "PageSchema"; |
451 | | - $pageText = preg_replace( '{<' . $tag . '[^>]*>([^@]*?)</' . $tag . '>' . '}', $psXML, $pageText ); |
| 450 | + if ( $categoryTitle->exists() ) { |
| 451 | + $pageText = $categoryArticle->getContent(); |
| 452 | + $pageSchemaObj = new PSSchema( $category ); |
| 453 | + if ( $pageSchemaObj->isPSDefined() ) { |
| 454 | + // Do some preg_replace magic. |
| 455 | + // This is necessary if the <PageSchema> tag |
| 456 | + // accepts any attributes - which it currently |
| 457 | + // does not, but it may well in the future. |
| 458 | + $tag = "PageSchema"; |
| 459 | + $pageText = preg_replace( '{<' . $tag . '[^>]*>([^@]*?)</' . $tag . '>' . '}', $psXML, $pageText ); |
| 460 | + } else { |
| 461 | + $pageText = $psXML . $pageText; |
| 462 | + } |
452 | 463 | } else { |
453 | | - $pageText = $psXML . $pageText; |
| 464 | + $pageText = $psXML; |
454 | 465 | } |
455 | 466 | $editSummary = $wgRequest->getVal( 'wpSummary' ); |
456 | 467 | $categoryArticle->doEdit( $pageText, $editSummary ); |