r71266 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71265‎ | r71266 | r71267 >
Date:20:05, 18 August 2010
Author:yaron
Status:deferred (Comments)
Tags:
Comment:
Added Sanyam Goyal's changes (with some modifications by me) to move combobox handling from Ext to jQuery
Modified paths:
  • /trunk/extensions/SemanticDrilldown/specials/SD_BrowseData.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticDrilldown/specials/SD_BrowseData.php
@@ -5,6 +5,7 @@
66 * previously been created.
77 *
88 * @author Yaron Koren
 9+ * @author Sanyam Goyal
910 */
1011
1112 if ( !defined( 'MEDIAWIKI' ) ) die();
@@ -28,25 +29,13 @@
2930 $wgParser->disableCache();
3031 }
3132 $this->setHeaders();
32 - $mainCssDir = $sdgScriptPath . '/skins/';
3333 $wgOut->addLink( array(
3434 'rel' => 'stylesheet',
3535 'type' => 'text/css',
3636 'media' => "screen",
37 - 'href' => $mainCssDir . 'SD_main.css'
 37+ 'href' => $sdgScriptPath . '/skins/SD_main.css'
3838 ) );
39 - $wgOut->addLink( array(
40 - 'rel' => 'stylesheet',
41 - 'type' => 'text/css',
42 - 'media' => "screen",
43 - 'href' => $mainCssDir . 'xtheme-gray.css'
44 - ) );
45 - $wgOut->addLink( array(
46 - 'rel' => 'stylesheet',
47 - 'type' => 'text/css',
48 - 'media' => "screen",
49 - 'href' => $mainCssDir . 'combos.css'
50 - ) );
 39+
5140 $javascript_text = <<<END
5241 function toggleFilterDiv(element_id, label_element) {
5342 element = document.getElementById(element_id);
@@ -67,7 +56,7 @@
6857 }
6958
7059 END;
71 - $wgOut->addScript( ' <script type="text/javascript">' . "\n" . $javascript_text . '</script>' . "\n" );
 60+ $wgOut->addScript( '<script type="text/javascript">' . "\n" . $javascript_text . '</script>' );
7261
7362 // set default
7463 if ( $sdgNumResultsPerPage == null )
@@ -594,49 +583,90 @@
595584 }
596585
597586 function printComboBoxInput( $filter_name, $filter_values, $cur_value = null ) {
598 - global $wgRequest;
 587+ global $wgRequest, $smwgJQueryIncluded, $smwgJQueryUIIncluded,
 588+ $sdgJQueryIncluded, $sdgScriptPath, $wgOut;
599589
600590 $filter_name = str_replace( ' ', '_', $filter_name );
601591 $input_id = "_search_$filter_name";
602 - $text = <<<END
 592+ $combobox_id = "c_search_$filter_name";
 593+ if ( !$sdgJQueryIncluded ) {
 594+ $wgOut->addLink(
 595+ array(
 596+ 'rel' => 'stylesheet',
 597+ 'type' => 'text/css',
 598+ 'media' => "screen",
 599+ 'href' => $sdgScriptPath . "/skins/jquery-ui/base/jquery.ui.all.css"
 600+ )
 601+ );
 602+ }
603603
604 -<script>
605 -Ext.onReady(function(){
606 - var {$filter_name}_values = [
 604+ $scripts = array();
 605+ if ( !$smwgJQueryIncluded ) {
 606+ $scripts[] = "$sdgScriptPath/libs/jquery-1.4.2.min.js";
 607+ $smwgJQueryIncluded = true;
 608+ };
607609
 610+ if ( !$smwgJQueryUIIncluded ) {
 611+ $scripts[] = "$sdgScriptPath/libs/jquery-ui/jquery.ui.core.min.js";
 612+ $scripts[] = "$sdgScriptPath/libs/jquery-ui/jquery.ui.widget.min.js";
 613+ }
 614+ if ( !$sdgJQueryIncluded ) {
 615+ $scripts[] = "$sdgScriptPath/libs/jquery-ui/jquery.ui.button.min.js";
 616+ }
 617+ if ( !$smwgJQueryUIIncluded ) {
 618+ $scripts[] = "$sdgScriptPath/libs/jquery-ui/jquery.ui.position.min.js";
 619+ $scripts[] = "$sdgScriptPath/libs/jquery-ui/jquery.ui.autocomplete.min.js";
 620+ $smwgJQueryUIIncluded = true;
 621+ }
 622+ if ( !$sdgJQueryIncluded ) {
 623+ $scripts[] = "$sdgScriptPath/libs/SemanticDrilldown.js";
 624+ $sdgJQueryIncluded = true;
 625+ }
 626+
 627+ foreach ( $scripts as $script ) {
 628+ $wgOut->addScript( '<script type="text/javascript" src="' . $script . '"></script> ');
 629+ }
 630+
 631+ $combobox_js =<<<END
 632+<script type="text/javascript">
 633+ jQuery(document).ready(function(){
 634+ jQuery("#$combobox_id").combobox();
 635+ });
 636+</script>
608637 END;
 638+ $wgOut->addScript( $combobox_js );
 639+
 640+ $text =<<< END
 641+<form method="get">
 642+ <div class="ui-widget">
 643+ <select id="$combobox_id" name="$cur_value">
 644+ <option value="$input_id"></option>;
 645+
 646+END;
609647 foreach ( $filter_values as $value => $num_instances ) {
610648 if ( $value != '_other' && $value != '_none' ) {
611649 $display_value = str_replace( '_', ' ', $value );
612650 $display_value = str_replace( '\'', '\\\'', $display_value );
613 - $text .= " ['$display_value', '$display_value'],\n";
 651+ $text .= ' <option value="'.$display_value.'">'.$display_value.'</option>';
614652 }
615653 }
616 - $text .= <<<END
617 - ]
618654
619 - var comboFromArray = new Ext.form.ComboBox({
620 - store: {$filter_name}_values,
621 - emptyText: '$cur_value',
622 - applyTo: '$input_id'
623 - });
624 -});
625 -</script>
626 -<form method="get">
627 -<input type="text" name="$input_id" id="$input_id" value="">
 655+ $text .=<<<END
 656+ </select>
 657+ </div>
628658
629659 END;
630660
631661 foreach ( $wgRequest->getValues() as $key => $val ) {
632662 if ( $key != $input_id )
633663 $text .= <<<END
634 -<input type="hidden" name="$key" value="$val" />
 664+ <input type="hidden" name="$key" value="$val" />
635665
636666 END;
637667 }
638668 $search_label = wfMsg( 'searchresultshead' );
639669 $text .= <<<END
640 -<input type="submit" value="$search_label" />
 670+ <input type="submit" value="$search_label" />
641671 </form>
642672
643673 END;
@@ -831,7 +861,7 @@
832862 $header .= "$subcategory_text: ";
833863 $subcat_string = str_replace( '_', ' ', $this->subcategory );
834864 $remove_filter_url = $this->makeBrowseURL( $this->category, $this->applied_filters );
835 - $header .= "\n" . ' <span class="drilldown-header-value">' . $subcat_string . '</span> <a href="' . $remove_filter_url . '" title="' . wfMsg( 'sd_browsedata_removesubcategoryfilter' ) . '"><img src="' . $sdgScriptPath . '/skins/filter-x.png" /></a>';
 865+ $header .= "\n" . ' <span class="drilldown-header-value">' . $subcat_string . '</span> <a href="' . $remove_filter_url . '" title="' . wfMsg( 'sd_browsedata_removesubcategoryfilter' ) . '"><img src="' . $sdgScriptPath . '/skins/filter-x.png" /></a> ';
836866 }
837867 foreach ( $this->applied_filters as $i => $af ) {
838868 $header .= ( ! $this->subcategory && $i == 0 ) ? " > " : "\n <span class=\"drilldown-header-value\">&</span> ";
@@ -862,7 +892,7 @@
863893 $temp_filters_array[$i]->search_term = null;
864894 $remove_filter_url = $this->makeBrowseURL( $this->category, $temp_filters_array, $this->subcategory );
865895 $temp_filters_array[$i]->search_term = $removed_search_term;
866 - $header .= "\n " . ' <span class="drilldown-header-value">~ \'' . $af->search_term . '\'</span> <a href="' . $remove_filter_url . '" title="' . wfMsg( 'sd_browsedata_removefilter' ) . '"><img src="' . $sdgScriptPath . '/skins/filter-x.png" /></a>';
 896+ $header .= "\n " . ' <span class="drilldown-header-value">~ \'' . $af->search_term . '\'</span> <a href="' . $remove_filter_url . '" title="' . wfMsg( 'sd_browsedata_removefilter' ) . '"><img src="' . $sdgScriptPath . '/skins/filter-x.png" /> </a>';
867897 } elseif ( $af->lower_date != null || $af->upper_date != null ) {
868898 $header .= "\n <span class=\"drilldown-header-value\">" . $af->lower_date_string . " - " . $af->upper_date_string . "</span>";
869899 }
@@ -1058,19 +1088,6 @@
10591089 : implode( '', $html );
10601090
10611091 $out->addHTML( $html );
1062 -
1063 - global $sdgScriptPath;
1064 - $out->addLink( array(
1065 - 'rel' => 'stylesheet',
1066 - 'type' => 'text/css',
1067 - 'media' => "screen",
1068 - 'href' => $sdgScriptPath . '/skins/ext-all.css'
1069 - ) );
1070 - // overwrite style from ext-all.css, to set the correct
1071 - // image for the combobox arrow
1072 - $out->addScript( "<style>.x-form-field-wrap .x-form-trigger{background:transparent url($sdgScriptPath/skins/trigger.gif) no-repeat 0 0;}</style>" );
1073 - $out->addScript( '<script type="text/javascript" src="' . $sdgScriptPath . '/libs/ext-base.js"></script>' );
1074 - $out->addScript( '<script type="text/javascript" src="' . $sdgScriptPath . '/libs/ext-all.js"></script>' );
10751092 }
10761093
10771094 // Take non-semantic result set returned by Database->query() method, and

Comments

#Comment by Jeroen De Dauw (talk | contribs)   13:08, 19 August 2010

This needs some htmlspecialchars :)

Status & tagging log