r94233 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94232‎ | r94233 | r94234 >
Date:09:20, 11 August 2011
Author:devayon
Status:deferred
Tags:
Comment:
added control for main column
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/languages/SMW_Messages.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php
@@ -66,7 +66,7 @@
6767 * Overridden from parent to ignore GUI parameters 'format' 'limit' and 'offset'
6868 */
6969 protected function showFormatOptions( $format, array $paramValues, array $ignoredAttribs = array() ) {
70 - return parent::showFormatOptions( $format, $paramValues, array( 'format', 'limit', 'offset' ) );
 70+ return parent::showFormatOptions( $format, $paramValues, array( 'format', 'limit', 'offset', 'mainlabel' ) );
7171 }
7272 /**
7373 * Creates the input form
@@ -143,8 +143,20 @@
144144 $property_values = $wgRequest->getArray( 'property' );
145145 $category_values = $wgRequest->getArray( 'category' );
146146 $category_label_values = $wgRequest->getArray( 'cat_label' );
 147+ $main_column_labels = $wgRequest->getArray( 'maincol_label' );
147148 $po = array();
148149 $category_namespace = $wgContLang->getNsText( NS_CATEGORY );
 150+ if ( is_array( $main_column_labels ) ) {
 151+ $po['mainlabel'] = '-'; // disables mainlabel parameter so that the UI can control it from here
 152+ foreach ( $main_column_labels as $key => $label ) {
 153+ if ( $label == '' ) {
 154+ $po[$key] = "?";
 155+ } else {
 156+ $po[$key] = "? = $label";
 157+ }
 158+
 159+ }
 160+ }
149161 if ( is_array( $category_values ) ) {
150162 foreach ( $category_values as $key => $value ) {
151163 if ( trim( $value ) == '' ) {
@@ -227,8 +239,9 @@
228240 $display_values = $wgRequest->getArray( 'display' );
229241 $category_values = $wgRequest->getArray( 'category' );
230242 $category_label_values = $wgRequest->getArray( 'cat_label' );
 243+ $main_column_labels = $wgRequest->getArray( 'maincol_label' );
231244
232 - if ( is_array( $property_values ) or is_array( $category_values ) ) {
 245+ if ( is_array( $property_values ) or is_array( $category_values ) or is_array( $main_column_labels ) ) {
233246 /*
234247 * Printouts were set via this Ui
235248 */
@@ -293,10 +306,18 @@
294307 $additional_POs[$value] = $category_values[$value]; // array_merge won't work because numeric keys need to be preserved
295308 }
296309 }
 310+ if ( is_array( $main_column_labels ) ) {
 311+ $keys = array_keys( $main_column_labels );
 312+ foreach ( $keys as $value ) {
 313+ $additional_POs[$value] = $main_column_labels[$value]; // array_merge won't work because numeric keys need to be preserved
 314+ }
 315+ }
297316 ksort( $additional_POs );
298317 foreach ( $additional_POs as $key => $value ) {
299318 if ( is_array( $property_values ) and array_key_exists( $key, $property_values ) ) {
300 - // make a element for additional properties
 319+ /*
 320+ * Make an element for additional properties
 321+ */
301322 $result .= Html::openElement( 'div', array( 'id' => "sort_div_$i", 'class' => 'smwsort' ) );
302323 $result .= '<span class="smw-remove"><a href="javascript:removePOInstance(\'sort_div_' . $i . '\')"><img src="' . $smwgScriptPath . '/skins/images/close-button.png" alt="' . wfMsg( 'smw_qui_delete' ) . '"></a></span>';
303324 $result .= wfMsg( 'smw_qui_property' );
@@ -322,6 +343,9 @@
323344 $i++;
324345 }
325346 if ( is_array( $category_values ) and array_key_exists( $key, $category_values ) ) {
 347+ /*
 348+ * Make an element for additional categories
 349+ */
326350 $result .= Html::openElement( 'div', array( 'id' => "sort_div_$i", 'class' => 'smwsort' ) );
327351 $result .= '<span class="smw-remove"><a href="javascript:removePOInstance(\'sort_div_' . $i . '\')"><img src="' . $smwgScriptPath . '/skins/images/close-button.png" alt="' . wfMsg( 'smw_qui_delete' ) . '"></a></span>' .
328352 'Category (optional)' . // todo: i18n
@@ -332,6 +356,17 @@
333357 Xml::closeElement( 'div' );
334358 $i++;
335359 }
 360+ if ( is_array( $main_column_labels ) and array_key_exists( $key, $main_column_labels ) ) {
 361+ /*
 362+ * Make an element for main column
 363+ */
 364+ $result .= Html::openElement( 'div', array( 'id' => "sort_div_$i", 'class' => 'smwsort' ) ) .
 365+ '<span class="smw-remove"><a href="javascript:removePOInstance(\'sort_div_' . $i . '\')"><img src="' . $smwgScriptPath . '/skins/images/close-button.png" alt="' . wfMsg( 'smw_qui_delete' ) . '"></a></span>' .
 366+ wfMsg( 'smw_qui_rescol' ) .
 367+ Xml::input( "maincol_label[$i]", '20', $main_column_labels[$key], array ( 'id' => "maincol_label$i" ) ) . " " .
 368+ Xml::closeElement( 'div' );
 369+ $i++;
 370+ }
336371 }
337372 $num_sort_values = $i;
338373 // END: create form elements already submitted earlier via form
@@ -359,6 +394,13 @@
360395 Xml::closeElement( 'div' );
361396 $hidden_category = json_encode( $hidden_category );
362397
 398+ $hidden_main_column = Html::openElement( 'div', array( 'id' => 'maincol_starter', 'class' => 'smwsort', 'style' => 'display:none' ) ) .
 399+ '<span class="smw-remove"><a><img src="' . $smwgScriptPath . '/skins/images/close-button.png" alt="' . wfMsg( 'smw_qui_delete' ) . '"></a></span>' .
 400+ wfMsg( 'smw_qui_rescol' ) .
 401+ Xml::input( "maincol_label_num", '20' ) . " " .
 402+ Xml::closeElement( 'div' );
 403+ $hidden_main_column = json_encode( $hidden_main_column );
 404+
363405 $property_dialog_box = Xml::openElement( 'div', array( 'id' => 'prop-dialog', 'title' => 'Property Options', 'class' => 'smwpropdialog' ) ) . // todo i18n
364406 Xml::inputLabel( 'Property:', '', 'd-property', 'd-property' ) . '<br/>' . // todo i18n
365407 Xml::inputLabel( 'Label:', '', 'd-property-label', 'd-property-label' ) . '<br/>' . // todo i18n
@@ -381,6 +423,7 @@
382424 $result .= '<div id="sorting_main"></div>' . "\n";
383425 $result .= '[<a href="javascript:smw_addPropertyInstance(\'property_starter\', \'sorting_main\')">' . wfMsg( 'smw_qui_addnprop' ) . '</a>]' .
384426 '[<a href="javascript:smw_addCategoryInstance(\'category_starter\', \'sorting_main\')">' . 'Add additional category' . '</a>]' . // todo i18n
 427+ '[<a href="javascript:smw_addMainColInstance(\'maincol_starter\', \'sorting_main\')">' . 'Add main column' . '</a>]' . // todo i18n
385428 "\n";
386429
387430 // Javascript code for handling adding and removing the "sort" inputs
@@ -563,6 +606,36 @@
564607 smw_category_autocomplete();
565608 }
566609
 610+function smw_addMainColInstance(starter_div_id, main_div_id) {
 611+ var starter_div = document.getElementById(starter_div_id);
 612+ var main_div = document.getElementById(main_div_id);
 613+
 614+ //Create the new instance
 615+ var new_div = starter_div.cloneNode(true);
 616+ var div_id = 'sort_div_' + num_elements;
 617+ new_div.id = div_id;
 618+ new_div.style.display = 'block';
 619+ jQuery(new_div.getElementsByTagName('label')).attr('for', 'display'+num_elements);
 620+ var children = new_div.getElementsByTagName('*');
 621+ var x;
 622+ for (x = 0; x < children.length; x++) {
 623+ if (children[x].for) children[x].for="display"+num_elements;
 624+ if (children[x].name){
 625+ children[x].id = children[x].name.replace(/_num/, ''+num_elements);
 626+ children[x].name = children[x].name.replace(/_num/, '[' + num_elements + ']');
 627+ }
 628+ }
 629+
 630+ //Add the new instance
 631+ main_div.appendChild(new_div);
 632+
 633+ // initialize delete button
 634+ st='sort_div_'+num_elements;
 635+ jQuery('#'+new_div.id).find(".smw-remove a")[0].href="javascript:removePOInstance('"+st+"')";
 636+ num_elements++;
 637+ smw_category_autocomplete();
 638+}
 639+
567640 function removePOInstance(div_id) {
568641 var olddiv = document.getElementById(div_id);
569642 var parent = olddiv.parentNode;
@@ -572,6 +645,7 @@
573646 jQuery(function(){
574647 jQuery('$hidden_property').appendTo(document.body);
575648 jQuery('$hidden_category').appendTo(document.body);
 649+ jQuery('$hidden_main_column').appendTo(document.body);
576650 jQuery('$property_dialog_box').appendTo(document.body);
577651 jQuery('$category_dialog_box').appendTo(document.body);
578652 jQuery('#cat-dialog').dialog({
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_Messages.php
@@ -254,6 +254,7 @@
255255 'smw_qui_descorder' => 'Descending',
256256 'smw_qui_addnprop' => 'Add additional properties',
257257 'smw_qui_delete' => 'Remove',
 258+ 'smw_qui_rescol' => 'Result column label',
258259
259260 // Messages for the search by property special
260261 'searchbyproperty' => 'Search by property',

Follow-up revisions

RevisionCommit summaryAuthorDate
r94234follow-up: r94233devayon09:40, 11 August 2011
r94336follow-up: r94233, r94116.devayon10:31, 12 August 2011