http://www.mediawiki.org/wiki/Special:Code/MediaWiki/94231

Revision: 94231
Author:   devayon
Date:     2011-08-11 07:22:52 +0000 (Thu, 11 Aug 2011)
Log Message:
-----------
follow-up: r94116

Modified Paths:
--------------
    
trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php

Modified: 
trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php
===================================================================
--- 
trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php
  2011-08-11 04:09:34 UTC (rev 94230)
+++ 
trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php
  2011-08-11 07:22:52 UTC (rev 94231)
@@ -37,13 +37,17 @@
                $html_output = $this->makeResults( $p );
                if ( $this->uiCore->getQueryString() != "" ) {
                        if ( $this->usesNavigationBar() ) {
-                               $html_output .= $this->getNavigationBar ( 
$this->uiCore->getLimit(), $this->uiCore->getOffset(), 
$this->uiCore->hasFurtherResults() ); // ? can we preload offset and limit?
+                               $html_output .= Html::rawElement( 'div', array( 
'class' => 'smw-qc-navbar' ),
+                                                                       
$this->getNavigationBar ( $this->uiCore->getLimit(), 
$this->uiCore->getOffset(), $this->uiCore->hasFurtherResults() )
+                                                               ); // ? can we 
preload offset and limit?
                        }
 
-                       $html_output .= "<br/>" . 
$this->uiCore->getHTMLResult() . "<br>";
+                       $html_output .= Html::rawElement( 'div', array( 'class' 
=> 'smw-qc-result' ), $this->uiCore->getHTMLResult() );
 
                        if ( $this->usesNavigationBar() ) {
-                               $html_output .= $this->getNavigationBar ( 
$this->uiCore->getLimit(), $this->uiCore->getOffset(), 
$this->uiCore->hasFurtherResults() ); // ? can we preload offset and limit?
+                               $html_output .= Html::rawElement( 'div', array( 
'class' => 'smw-qc-navbar' ),
+                                                                       
$this->getNavigationBar ( $this->uiCore->getLimit(), 
$this->uiCore->getOffset(), $this->uiCore->hasFurtherResults() )
+                                                               ); // ? can we 
preload offset and limit?
                        }
                }
                $wgOut->addHTML( $html_output );
@@ -112,7 +116,7 @@
                $result .= '</div>'; // end of hidden additional options
                $result .= '<br /><input type="submit" value="' . wfMsg( 
'smw_ask_submit' ) . '"/>' .
                        '<input type="hidden" name="eq" value="no"/>' .
-                       "\n</form>";
+                       "\n</form><br/>";
 
        return $result;
 
@@ -126,11 +130,12 @@
         * Overrides method from SMWQueryUI (modal window added)
         *
         * @global boolean $smwgQSortingSupport
+        * @global Language $wgContLang
         * @param WebRequest $wgRequest
         * @return string
         */
        protected function processPoSortFormBox( WebRequest $wgRequest ) {
-               global $smwgQSortingSupport;
+               global $smwgQSortingSupport, $wgContLang;
                if ( !$smwgQSortingSupport ) return array();
 
                $params = array();
@@ -139,12 +144,13 @@
                $category_values = $wgRequest->getArray( 'category' );
                $category_label_values = $wgRequest->getArray( 'cat_label' );
                $po = array();
+               $category_namespace = $wgContLang->getNsText( NS_CATEGORY );
                if ( is_array( $category_values ) ) {
                        foreach ( $category_values as $key => $value ) {
                                if ( trim( $value ) == '' ) {
-                                       $po[$key] = '?Category'; // Todo: i18n
+                                       $po[$key] = "?$category_namespace" ;
                                } else {
-                                       $po[$key] = '?Category:' . $value; // 
Todo: i18n
+                                       $po[$key] = 
"?$category_namespace:$value";
                                }
                        }
                }
@@ -222,12 +228,17 @@
                $category_values = $wgRequest->getArray( 'category' );
                $category_label_values = $wgRequest->getArray( 'cat_label' );
 
-               if ( is_array( $property_values ) ) {
-                       // removing empty values
-                       foreach ( $property_values as $key => $property_value ) 
{
-                               $property_values[$key] = trim( $property_value 
);
-                               if ( $property_value == '' ) {
-                                       unset( $property_values[$key] );
+               if ( is_array( $property_values ) or is_array( $category_values 
) ) {
+                       /*
+                        * Printouts were set via this Ui
+                        */
+                       if ( is_array( $property_values ) ) {
+                               // remove empty property values
+                               foreach ( $property_values as $key => 
$property_value ) {
+                                       $property_values[$key] = trim( 
$property_value );
+                                       if ( $property_value == '' ) {
+                                               unset( $property_values[$key] );
+                                       }
                                }
                        }
                } else {
@@ -258,19 +269,18 @@
                                $order_values = array(); // do not even show 
one sort input here
                                $property_values = array();
                        }
-
-                        foreach ( $po as $po_key => $po_value ) {
+                       foreach ( $po as $po_value ) {
                                 if ( !in_array( $po_value, $property_values ) 
) {
                                         $property_values[] = $po_value;
                                 }
-                        }
-                        $display_values = array();
-                        reset( $property_values );
-                        foreach ( $property_values as $property_key => 
$property_value ) {
-                                if ( in_array( $property_value, $po ) ) {
-                                        $display_values[$property_key] = "yes";
-                                }
-                        }
+                       }
+                       $display_values = array();
+                       reset( $property_values );
+                       foreach ( $property_values as $property_key => 
$property_value ) {
+                               if ( in_array( $property_value, $po ) ) {
+                                       $display_values[$property_key] = "yes";
+                               }
+                       }
                }
                $i = 0;
                $additional_POs = array();
@@ -278,11 +288,14 @@
                        $additional_POs = array_merge( $additional_POs, 
$property_values );
                }
                if ( is_array( $category_values ) ) {// same as testing 
$category_label_values
-                       $additional_POs = array_merge( $additional_POs, 
$category_values );
+                       $keys = array_keys( $category_values );
+                       foreach ( $keys as $value ) {
+                               $additional_POs[$value] = 
$category_values[$value]; // array_merge won't work because numeric keys need 
to be preserved
+                       }
                }
                ksort( $additional_POs );
                foreach ( $additional_POs as $key => $value ) {
-                       if ( array_key_exists( $key, $property_values ) ) {
+                       if ( is_array( $property_values ) and array_key_exists( 
$key, $property_values ) ) {
                                // make a element for additional properties
                                $result .= Html::openElement( 'div', array( 
'id' => "sort_div_$i", 'class' => 'smw-sort' ) );
                                $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>';
@@ -312,9 +325,9 @@
                                $result .= Html::openElement( 'div', array( 
'id' => "sort_div_$i", 'class' => 'smw-sort' ) );
                                $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>' .
                                                        'Category (optional)' . 
// todo: i18n
-                                                       Xml::input( 
"category[$i]", '20', $category_values[$key] ) . " " .
+                                                       Xml::input( 
"category[$i]", '20', $category_values[$key], array( 'id' => "category$i" ) ) . 
" " .
                                                        'Label' . // todo: i18n
-                                                       Xml::input( 
"cat_label[$i]", '20', array_key_exists( $key, $category_label_values ) ? 
$category_label_values[$key]:false ) . " " .
+                                                       Xml::input( 
"cat_label[$i]", '20', array_key_exists( $key, $category_label_values ) ? 
$category_label_values[$key]:false, array( 'id' => "cat_label$i" ) ) . " " .
                                                        ' <a  id="more' . $i . 
'" "class="smwq-more" href="javascript:smw_makeCatDialog(\'' . $i . '\')"> 
options </a> ' . // TODO: i18n
                                                        Xml::closeElement( 
'div' );
                                $i++;
@@ -349,7 +362,7 @@
                $property_dialog_box = Xml::openElement( 'div', array( 'id' => 
'prop-dialog', 'title' => 'Property Options', 'class' => 'smw-prop-dialog' ) ) 
. // todo i18n
                                        Xml::inputLabel( 'Property:', '', 
'd-property', 'd-property' ) . '<br/>' . // todo i18n
                                        Xml::inputLabel( 'Label:', '', 
'd-property-label', 'd-property-label' ) . '<br/>' . // todo i18n
-                                       'Format: ' . Html::openElement( 
'select', array( 'name' => 'd-format', 'id' => 'd-format' ) ) . // todo i18n
+                                       '<label for="d-format">Format:</label> 
' . Html::openElement( 'select', array( 'name' => 'd-format', 'id' => 
'd-format' ) ) . // todo i18n
                                                Xml::option( 'None (default)', 
' ' ) . // todo i18n
                                                Xml::option( 'Simple', '#-' ) . 
// todo i18n
                                        Xml::closeElement( 'select' ) .
@@ -397,6 +410,7 @@
                }
        });
 }
+
 function smw_category_autocomplete(){
                jQuery('[name*="category"]').autocomplete({
                minLength: 2,
@@ -417,47 +431,63 @@
                        $javascript_text .= <<<EOT
 function smw_property_autocomplete(){
 }
+
 function smw_category_autocomplete(){
 }
+
 EOT;
                }
 
                $javascript_text .= <<<EOT
 function smw_prop_code_update(){
-               code = '?'+\$j('#d-property')[0].value;
-               if(code!=''){
-                       if(\$j('#d-property-format-custom')[0].value !=''){
-                               code = code + 
\$j('#d-property-format-custom')[0].value;
-                       }
-                       if(\$j('#d-property-label')[0].value !=''){
-                               code = code + ' = '+ 
\$j('#d-property-label')[0].value;
-                       }
-                       \$j('#d-property-code')[0].value= code;
+       code = '?'+jQuery('#d-property')[0].value;
+       if(code!=''){
+               if(jQuery('#d-property-format-custom')[0].value !=''){
+                       code = code + 
jQuery('#d-property-format-custom')[0].value;
                }
+               if(jQuery('#d-property-label')[0].value !=''){
+                       code = code + ' = '+ 
jQuery('#d-property-label')[0].value;
+               }
+               jQuery('#d-property-code')[0].value= code;
+       }
 }
+
+function smw_cat_code_update(){
+
+}
+
+function smw_makeCatDialog(cat_id){
+       jQuery('#prop-cat input').attr('value','');
+       cat=jQuery('#category'+cat_id)[0].value;
+       jQuery('#d-category').attr('value',cat);
+       label=jQuery('#cat_label'+cat_id)[0].value;
+       jQuery('#d-category-label').attr('value',label);
+       //jQuery('#cat-dialog').dialog('open');
+}
+
 function smw_makePropDialog(prop_id){
-               jQuery('#prop-dialog input').attr('value','');
-               prop=val=\$j('#property'+prop_id)[0].value;
-               if(val[0]='?') val=prop=prop.substr(1);
-               if((i=val.indexOf('='))!=-1) prop=prop.substring(0, i);
-               if((i=val.indexOf('#'))!=-1) prop=prop.substring(0, i);
-               if(val.split('=')[1]){
-                       label=val.split('=')[1].trim();
-               }else{
-                       label="";
-               }
-               format = val.split('=')[0];
-               if(format.indexOf('#')!=-1){
-                       format=format.substr(format.indexOf('#'));
-               }else{
-                       format="";
-               }
+       jQuery('#prop-dialog input').attr('value','');
+       prop=val=jQuery('#property'+prop_id)[0].value;
+       if(val[0]='?') val=prop=prop.substr(1);
+       if((i=val.indexOf('='))!=-1) prop=prop.substring(0, i);
+       if((i=val.indexOf('#'))!=-1) prop=prop.substring(0, i);
+       if(val.split('=')[1]){
+               label=val.split('=')[1].trim();
+       }else{
+               label="";
+       }
+       format = val.split('=')[0];
+       if(format.indexOf('#')!=-1){
+               format=format.substr(format.indexOf('#'));
+       }else{
+               format="";
+       }
 
-               \$j('#d-property').attr('value', prop.trim());
-               \$j('#d-property-label').attr('value', label);
-               \$j('#d-property-format-custom').attr('value', format.trim());
-               \$j('#prop-dialog').dialog.id=prop_id;
-               \$j('#prop-dialog').dialog('open');
+       jQuery('#d-property').attr('value', prop.trim());
+       jQuery('#d-property-label').attr('value', label);
+       jQuery('#d-property-format-custom').attr('value', format.trim());
+       jQuery('#prop-dialog').dialog.id=prop_id;
+       jQuery('#prop-dialog').dialog('open');
 }
 // code for handling adding and removing the "sort" inputs
 
@@ -550,7 +580,20 @@
                resizable: true,
                minHeight: 200,
                minWidth: 400,
+               buttons: {
+                       "Ok": function(){ //todo i18
+                               smw_cat_code_update();
+                               // todo: move modal window data to main window 
form controls;
+                               jQuery(this).dialog("close");
+                       },
+                       "Cancel": function(){ //todo:i18n
+                               jQuery('#cat-dialog input').attr('value','');
+                               jQuery(this).dialog("close");
+                       }
+               }
        });
+       //todo: run smw_cat_code_update() when input values in category modal 
windows changes
+
        jQuery('#prop-dialog').dialog({
                autoOpen: false,
                modal: true,
@@ -560,7 +603,7 @@
                buttons: {
                        "Ok": function(){  //todo: i18n
                                smw_prop_code_update();
-                               
\$j('#property'+\$j('#prop-dialog').dialog.id)[0].value=\$j('#d-property-code')[0].value;
+                               
jQuery('#property'+jQuery('#prop-dialog').dialog.id)[0].value=jQuery('#d-property-code')[0].value;
                                jQuery(this).dialog("close");
                        },
                        "Cancel": function(){ //todo: i18n
@@ -577,10 +620,9 @@
                smw_prop_code_update();
        });
 });
-function smw_makeCatDialog(cat_id){
-               //\$j('#cat-dialog').dialog('open');
-}
+
 jQuery(document).ready(smw_property_autocomplete);
+jQuery(document).ready(smw_category_autocomplete);
 </script>
 
 EOT;


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to