r97451 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97450‎ | r97451 | r97452 >
Date:05:56, 19 September 2011
Author:yaron
Status:deferred
Tags:
Comment:
Various additional fixes for Page Schemas-related code, including changing the name of a tag from <Label> to <Name> - and a follow-up to r97426
Modified paths:
  • /trunk/extensions/SemanticDrilldown/includes/SD_Filter.php (modified) (history)
  • /trunk/extensions/SemanticDrilldown/includes/SD_PageSchemas.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticDrilldown/includes/SD_Filter.php
@@ -30,8 +30,8 @@
3131 $sd_array = $object_values['sd'];
3232 $smw_array = $fieldObj->getObject('semanticmediawiki_Property'); //this returns an array with property values filled
3333 $prop_array = $smw_array['smw'];
34 - if ( array_key_exists( 'Label', $sd_array ) ) {
35 - $f->name = $sd_array['Label'];
 34+ if ( array_key_exists( 'Name', $sd_array ) ) {
 35+ $f->name = $sd_array['Name'];
3636 } else {
3737 $f->name = $prop_array['name'];
3838 }
Index: trunk/extensions/SemanticDrilldown/includes/SD_PageSchemas.php
@@ -7,33 +7,33 @@
88 * @author Ankit Garg
99 */
1010
11 -if ( !defined( 'MEDIAWIKI' ) ) die();
12 -
1311 class SDPageSchemas {
1412
1513 /**
16 - * Return an object containing information on a filter, based on XML
17 - * from the Page Schemas extensions
 14+ * Returns an object containing information on a filter, based on XML
 15+ * from the Page Schemas extension.
1816 */
1917 public static function createPageSchemasObject( $objectName, $xmlForField, &$object ) {
2018 $sdarray = array();
21 - if ( $objectName == "semanticdrilldown_Filter" ) {
22 - foreach ( $xmlForField->children() as $tag => $child ) {
23 - if ( $tag == $objectName ) {
24 - foreach ( $child->children() as $prop => $value) {
25 - if( $prop == "Values" ){
26 - $l_values = array();
27 - foreach ( $value->children() as $val_i => $val ) {
28 - $l_values[] = (string)$val;
29 - }
30 - $sdarray['Values'] = $l_values;
31 - } else {
32 - $sdarray[$prop] = (string)$value;
 19+ if ( $objectName != "semanticdrilldown_Filter" ) {
 20+ return true;
 21+ }
 22+
 23+ foreach ( $xmlForField->children() as $tag => $child ) {
 24+ if ( $tag == $objectName ) {
 25+ foreach ( $child->children() as $prop => $value) {
 26+ if( $prop == "Values" ){
 27+ $l_values = array();
 28+ foreach ( $value->children() as $val ) {
 29+ $l_values[] = (string)$val;
3330 }
 31+ $sdarray['Values'] = $l_values;
 32+ } else {
 33+ $sdarray[$prop] = (string)$value;
3434 }
35 - $object['sd'] = $sdarray;
36 - return true;
3735 }
 36+ $object['sd'] = $sdarray;
 37+ return true;
3838 }
3939 }
4040 return true;
@@ -44,11 +44,6 @@
4545 * Semantic Drilldown section in Page Schemas' "edit schema" page
4646 */
4747 public static function getFieldHTML( $field, &$text_extensions ){
48 - // TODO - add these options to the XML and HTML
49 - //$property_label = wfMsg( 'sd_createfilter_property' );
50 - //$label_label = wfMsg( 'sd_createfilter_label' );
51 - // need both label and value, in case user's language is different
52 - // from wiki's
5348 //$require_filter_label = wfMsg( 'sd_createfilter_requirefilter' );
5449
5550 $filter_array = array();
@@ -61,10 +56,10 @@
6257 }
6358 }
6459
65 - if ( array_key_exists( 'Label', $filter_array ) ) {
66 - $filterLabel = $filter_array['Label'];
 60+ if ( array_key_exists( 'Name', $filter_array ) ) {
 61+ $filterName = $filter_array['Name'];
6762 } else {
68 - $filterLabel = '';
 63+ $filterName = '';
6964 }
7065 $fromCategoryAttrs = array();
7166 if ( array_key_exists( 'ValuesFromCategory', $filter_array ) ) {
@@ -107,7 +102,7 @@
108103 $usePropertyValuesAttr['checked'] = true;
109104 }
110105
111 - // The "input type" field
 106+ // The "input type" field.
112107 $combo_box_value = wfMsgForContent( 'sd_filter_combobox' );
113108 $date_range_value = wfMsgForContent( 'sd_filter_daterange' );
114109 $valuesListAttrs = array( 'value' => '' );
@@ -127,8 +122,8 @@
128123 }
129124
130125 $html_text = '<p>' . wfMsg( 'ps-optional-name' ) . ' ';
131 - $html_text .= Html::input( 'sd_filter_name_num', $filterLabel, 'text', array( 'size' => 25 ) ) . "</p>\n";
132 - $html_text .= '<fieldset><legend>Values</legend>' . "\n";
 126+ $html_text .= Html::input( 'sd_filter_name_num', $filterName, 'text', array( 'size' => 25 ) ) . "</p>\n";
 127+ $html_text .= '<fieldset><legend>' . wfMsg( 'sd-pageschemas-values' ) . '</legend>' . "\n";
133128 $html_text .= '<p>' . Html::input( 'sd_values_source_num', 'property', 'radio', $usePropertyValuesAttr ) . ' ';
134129 $html_text .= wfMsg( 'sd_createfilter_usepropertyvalues' ) . "</p>\n";
135130 $html_text .= "\t<p>\n";
@@ -179,7 +174,7 @@
180175 if ( substr( $var, 0, 15 ) == 'sd_filter_name_' ) {
181176 $xml = '<semanticdrilldown_Filter>';
182177 $fieldNum = substr( $var, 15 );
183 - $xml .= '<Label>'.$val.'</Label>';
 178+ $xml .= '<Name>'.$val.'</Name>';
184179 } elseif ( substr( $var, 0, 17 ) == 'sd_values_source_') {
185180 if ( $val == 'category' ) {
186181 $xml .= '<ValuesFromCategory>' . $request->getText('sd_category_name_' . $fieldNum) . '</ValuesFromCategory>';
@@ -220,15 +215,15 @@
221216 public static function parseFieldElements( $field_xml, &$text_object ) {
222217 foreach ( $field_xml->children() as $tag => $child ) {
223218 if ( $tag == "semanticdrilldown_Filter" ) {
224 - $text = "";
225 - $text = PageSchemas::tableMessageRowHTML( "paramAttr", "SemanticDrillDown", (string)$tag );
 219+ $text = PageSchemas::tableMessageRowHTML( "paramAttr", wfMsg( 'specialpages-group-sd_group' ), "Filter" );
226220 foreach ( $child->children() as $prop => $value) {
227 - if( $prop == "Values" ){
228 - $l_values = "";
229 - foreach ( $value->children() as $val_i => $val ) {
230 - $l_values .= $val.", ";
 221+ if ( $prop == "Values" ) {
 222+ $filterValues = array();
 223+ foreach ( $value->children() as $valTag ) {
 224+ $filterValues[] = (string)$valTag;
231225 }
232 - $text .= PageSchemas::tableMessageRowHTML("paramAttrMsg", $prop, $l_values );
 226+ $valuesStr = implode( ', ', $filterValues );
 227+ $text .= PageSchemas::tableMessageRowHTML("paramAttrMsg", wfMsg( 'sd-pageschemas-values' ), $valuesStr );
233228 } else {
234229 $text .= PageSchemas::tableMessageRowHTML("paramAttrMsg", $prop, $value );
235230 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r97426Some code improvementsyaron16:29, 18 September 2011