r97024 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97023‎ | r97024 | r97025 >
Date:00:08, 14 September 2011
Author:yaron
Status:deferred
Tags:
Comment:
Various bug fixes
Modified paths:
  • /trunk/extensions/PageSchemas/specials/PS_EditSchema.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PageSchemas/specials/PS_EditSchema.php
@@ -3,6 +3,7 @@
44 * Displays an interface to let users create and edit the <PageSchema> XML.
55 *
66 * @author Ankit Garg
 7+ * @author Yaron Koren
78 */
89
910 class PSEditSchema extends IncludableSpecialPage {
@@ -33,7 +34,7 @@
3435 .fadeOut('fast', function() { jQuery(this).remove(); });
3536 });
3637 jQuery('#fieldsList_'+template_num).append(newField);
37 - addjQueryToCheckbox();
 38+ addjQueryToCheckboxes();
3839 }
3940
4041 function psAddTemplate() {
@@ -53,7 +54,14 @@
5455 fieldNum = field_num;
5556 }
5657
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+ });
5866 jQuery('.isListCheckbox').click(function() {
5967 if (jQuery(this).is(":checked")) {
6068 jQuery(this).closest('.fieldBox').find('.delimiterInput').css('display', '');
@@ -74,7 +82,7 @@
7583 jQuery(this).closest(".templateBox")
7684 .fadeOut('fast', function() { jQuery(this).remove(); });
7785 });
78 - addjQueryToCheckbox();
 86+ addjQueryToCheckboxes();
7987 jQuery('#editPageSchemaForm').submit( function() {
8088 jQuery('#starterTemplate').find("input, select, textarea").attr('disabled', 'disabled');
8189 return true;
@@ -218,8 +226,8 @@
219227 $fieldName = '';
220228 $delimiter = '';
221229 $fieldLabel = '';
222 - $attrs = array();
223 - $pAttrs = array( 'class' => 'delimiterInput' );
 230+ $isListAttrs = array( 'class' => 'isListCheckbox' );
 231+ $delimiterAttrs = array( 'class' => 'delimiterInput' );
224232 if ( is_null( $field_xml ) ) {
225233 $text = '<div class="fieldBox" id="starterField" style="display: none" >';
226234 } else {
@@ -234,9 +242,7 @@
235243 }
236244 }
237245 if ( ((string)$field_xml->attributes()->list) == "list" ) {
238 - $attrs['checked'] = 'checked';
239 - } else {
240 - $pAttrs['style'] = 'display: none';
 246+ $isListAttrs['checked'] = 'checked';
241247 }
242248 }
243249 $fieldHTML = '<p>Field name: ';
@@ -244,10 +250,10 @@
245251 $fieldHTML .= wfMsg( 'ps-displaylabel' ) . ' ';
246252 $fieldHTML .= Html::input( 'f_label_' . $field_count, $fieldLabel, 'text', array( 'size' => 15 ) );
247253 $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 );
249255 $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 );
252258
253259 // Insert HTML text from extensions
254260 $htmlFromExtensions = array();
@@ -366,6 +372,7 @@
367373 $pageXMLChildren = $pageXML->children();
368374 }
369375
 376+ $ps_add_xml = '';
370377 foreach ( $pageXMLChildren as $template_xml ) {
371378 if ( ( $template_xml->getName() != 'Template') && ( $template_xml->getName() != 'semanticforms_Form' ) ) {
372379 $ps_add_xml .= (string)$template_xml->asXML();
@@ -384,15 +391,15 @@
385392 $text .= '<div id="templatesList">';
386393
387394 $template_num = 0;
388 - $pageSchemaTemplate = $template_all[$template_num];
389395
390396 // Add 'starter', hidden template section.
391397 $text .= self::printTemplateSection();
392398 /* index for template objects */
393399 foreach ( $pageXMLChildren as $tag => $template_xml ) {
394400 if ( $tag == 'Template' ) {
 401+ $pageSchemaTemplate = $template_all[$template_num];
 402+ $text .= self::printTemplateSection( $template_num, $template_xml, $pageSchemaTemplate );
395403 $template_num++;
396 - $text .= self::printTemplateSection( $template_num, $template_xml, $pageSchemaTemplate );
397404 }
398405 }
399406 $add_template_button = Xml::element( 'input',
@@ -437,19 +444,23 @@
438445 $save_page = $wgRequest->getCheck( 'wpSave' );
439446 if ( $save_page ) {
440447 $psXML = self::pageSchemaXMLFromRequest();
441 - $pageSchemaObj = new PSSchema( $category );
442448 $categoryTitle = Title::newFromText( $category, NS_CATEGORY );
443449 $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+ }
452463 } else {
453 - $pageText = $psXML . $pageText;
 464+ $pageText = $psXML;
454465 }
455466 $editSummary = $wgRequest->getVal( 'wpSummary' );
456467 $categoryArticle->doEdit( $pageText, $editSummary );

Status & tagging log