r95735 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95734‎ | r95735 | r95736 >
Date:03:29, 30 August 2011
Author:yaron
Status:deferred
Tags:
Comment:
More improvements to layout, added use of Html class, replaced some hardcoded strings
Modified paths:
  • /trunk/extensions/PageSchemas/specials/PS_EditSchema.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PageSchemas/specials/PS_EditSchema.php
@@ -94,64 +94,15 @@
9595 $text_ex = preg_replace( '/starter/', '1', $htmlFromExtensions['sf_form'] );
9696 $text .= $text_ex;
9797 }
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' );
10198
10299 $text .= '<div id="templatesList">';
103100 $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>';
129102
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 -
152103 $add_template_button = Xml::element( 'input',
153104 array(
154105 'type' => 'button',
155 - 'value' => 'Add template',
 106+ 'value' => wfMsg( 'ps-add-template' ),
156107 'onclick' => "createAddTemplate()"
157108 )
158109 );
@@ -166,32 +117,59 @@
167118 }
168119
169120 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>
176154 </div>
177 - <p><input type="button" value="Add Field" onclick="createTemplateAddField(starter)" /></p>
 155+<hr />
178156
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 - &#160;&#160;</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+ &#160;&#160;</p>
 169+ <p class="delimiterInput" style="display: none" >
 170+ $delimiter_label <input type="text" name="f_delimiter_starter" />
 171+ </p>
 172+
 173+END;
196174 if ($htmlFromExtensions['smw'] != null ) {
197175 $starter_text .= $htmlFromExtensions['smw'];
198176 }
@@ -201,12 +179,21 @@
202180 if ($htmlFromExtensions['sd'] != null ) {
203181 $starter_text .= $htmlFromExtensions['sd'];
204182 }
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;
211198 return $starter_text;
212199 }
213200
@@ -231,7 +218,7 @@
232219 $ps_add_xml = $wgRequest->getText( 'ps_add_xml' );
233220 $XMLtext .= $ps_add_xml;
234221 $fieldName = "";
235 - $fieldNum= -1;
 222+ $fieldNum = -1;
236223 $templateNum = -1;
237224 $xmlFromExtensions = array(); //This var. will save the xml text returned by the extensions
238225 wfRunHooks( 'getXmlTextForFieldInputs', array( $wgRequest, &$xmlFromExtensions ));
@@ -252,15 +239,15 @@
253240 $fieldNum = substr($var,7,1);
254241 if ($wgRequest->getCheck( 'f_is_list_'.$fieldNum ) ) {
255242 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.'">';
258245 } else {
259246 $XMLtext .= '<Field name="'.$fieldName.'" list="list">';
260247 }
261248 } else {
262249 $XMLtext .= '<Field name="'.$fieldName.'">';
263250 }
264 - } elseif (substr($var,0,8) == 'f_label_' ) {
 251+ } elseif ( substr( $var, 0, 8 ) == 'f_label_' ) {
265252 $XMLtext .= '<Label>'.$val.'</Label>';
266253 //Get XML parsed from extensions
267254 if ( $xmlFromExtensions['smw'] != null ) {
@@ -282,10 +269,10 @@
283270 }
284271 }
285272 $indexGlobalField++ ;
286 - } elseif (substr($var,0,10) == 'f_add_xml_' ) {
 273+ } elseif ( substr( $var, 0, 10 ) == 'f_add_xml_' ) {
287274 $XMLtext .= $val;
288275 $XMLtext .= '</Field>';
289 - } elseif (substr($var,0,10) == 't_add_xml_' ) {
 276+ } elseif ( substr( $var, 0, 10 ) == 't_add_xml_' ) {
290277 $XMLtext .= $val;
291278 $XMLtext .= '</Template>';
292279 }
@@ -328,14 +315,14 @@
329316 'pp_propname' => 'PageSchema'
330317 )
331318 );
 319+ $editSchemaPage = SpecialPage::getTitleFor( 'EditSchema' );
332320 while ( $row = $dbr->fetchRow( $res ) ) {
333321 if ( $row[2] != null ) {
334322 $page_id_cat = $row[0];
335323 if ( Title::newFromId($page_id_cat)->getNamespace() == NS_CATEGORY ) {
336324 $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 />';
340327 }
341328 }
342329 }
@@ -367,7 +354,7 @@
368355 //first row of the result set
369356 $row = $dbr->fetchRow( $res );
370357 if ( $row == null && !$title->exists() ) {
371 - //Create form here, Cat doesnt exist, create new cat with this text
 358+ // Category doesn't exist.
372359 $text = '<p>'.wfMsg( 'ps-page-desc-cat-not-exist' ).'</p>';
373360 $text .= $formHTML;
374361 $wgOut->addHTML( $text );
@@ -375,12 +362,15 @@
376363 }
377364
378365 if ( ($row[1] != 'PageSchema') || ($row[2] == null ) ) {
 366+ // Category exists, but has no page schema.
379367 $text = '<p>'.wfMsg( 'ps-page-desc-ps-not-exist' ).'</p>';
380368 $text .= $formHTML;
381369 $wgOut->addHTML($text );
 370+ return true;
382371 }
383372
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.
385375 $pageXMLstr = $row[2];
386376 $pageXML = simplexml_load_string( $pageXMLstr );
387377 $ps_add_xml = "";
@@ -411,30 +401,28 @@
412402 $template_num++;
413403 $field_count = 0;
414404 if ( count($template_xml->children()) > 0 ) {
415 - $templateName = (string) $template_xml->attributes()->name;
416405 $text_4 .= '<div class="templateBox" >';
417406 $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();
419411 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';
423413 }
 414+ $templateIsMultipleInput = Html::input( 'is_multiple_' . $template_num, null, 'checkbox', $attrs );
 415+ $text_4 .= Html::rawElement( 'p', null, $templateIsMultipleInput . ' ' . wfMsg( 'ps-multiple-temp-label' ) );
424416 foreach ( $template_xml->children() as $field_xml ) {
425417 if ( $field_xml->getName() != 'Field' ) {
426418 $template_add_xml .= (string)$field_xml->asXML();
427419 }
428420 }
429421 $text_4 .= '<div id="fieldsList_'.$template_num.'">';
430 - $list_values = false;
431422 foreach ( $template_xml->children() as $field_xml ) {
432423 if ( $field_xml->getName() == "Field" ) {
433424 $fieldName = (string)$field_xml->attributes()->name;
434425 $text_4 .= '<div class="fieldBox" >';
435426 $text_4 .= '<fieldset style="background: #bbb;"><legend>Field</legend> ';
436 - if ( ((string)$field_xml->attributes()->list) == "list") {
437 - $list_values = true;
438 - }
439427 if ( ((string)$field_xml->attributes()->delimiter) != null || ((string)$field_xml->attributes()->delimiter) != '' ) {
440428 $delimiter = (string)$field_xml->attributes()->delimiter;
441429 }
@@ -444,15 +432,21 @@
445433 }
446434 }
447435 $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.'" >
449438 </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';
453443 } 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';
456445 }
 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+
457451 //Inserting HTML text from Extensions
458452
459453 if ( $filledHTMLFromExtensions['smw'] != null ) {
@@ -477,13 +471,22 @@
478472 }
479473 }
480474
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>
483478 </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>
485487 </div>
486488 </div>
487 - ';
 489+
 490+END;
488491 $field_count++;
489492 $text_4 .= '<script type="text/javascript">
490493 updateFieldNum('.$field_count.');
@@ -494,7 +497,7 @@
495498 $add_field_button = Xml::element( 'input',
496499 array(
497500 'type' => 'button',
498 - 'value' => 'Add field',
 501+ 'value' => wfMsg( 'ps-add-field' ),
499502 'onclick' => "createTemplateAddField($template_num)"
500503 )
501504 );
@@ -511,7 +514,7 @@
512515 $add_template_button = Xml::element( 'input',
513516 array(
514517 'type' => 'button',
515 - 'value' => 'Add template',
 518+ 'value' => wfMsg( 'ps-add-template' ),
516519 'onclick' => "createAddTemplate()"
517520 )
518521 );

Status & tagging log