r73986 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73985‎ | r73986 | r73987 >
Date:21:39, 29 September 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 1.5.3 - fixing a whole bunch of style fails
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialAsk.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialAsk.php
@@ -1,20 +1,16 @@
22 <?php
3 -/**
4 - * @file
5 - * @ingroup SMWSpecialPage
6 - * @ingroup SpecialPage
7 - */
83
94 /**
10 - * @author Markus Krötzsch
11 - * @author Yaron Koren
12 - * @author Sanyam Goyal
13 - *
145 * This special page for MediaWiki implements a customisable form for
156 * executing queries outside of articles.
167 *
 8+ * @file SMW_SpecialAsk.php
179 * @ingroup SMWSpecialPage
1810 * @ingroup SpecialPage
 11+ *
 12+ * @author Markus Krötzsch
 13+ * @author Yaron Koren
 14+ * @author Sanyam Goyal
1915 */
2016 class SMWAskPage extends SpecialPage {
2117
@@ -24,7 +20,7 @@
2521 protected $m_editquery = false;
2622
2723 // MW 1.13 compatibilty
28 - private static $pipeseparator = '|';
 24+ protected static $pipeseparator = '|';
2925
3026 /**
3127 * Constructor
@@ -34,13 +30,16 @@
3531 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
3632 }
3733
38 - function execute( $p ) {
 34+ public function execute( $p ) {
3935 global $wgOut, $wgRequest, $smwgQEnabled, $smwgRSSEnabled, $smwgMW_1_14;
 36+
4037 $this->setHeaders();
4138 wfProfileIn( 'doSpecialAsk (SMW)' );
 39+
4240 if ( $smwgMW_1_14 ) { // since MW 1.14.0 this is governed by a message
4341 SMWAskPage::$pipeseparator = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
4442 }
 43+
4544 if ( !$smwgQEnabled ) {
4645 $wgOut->addHTML( '<br />' . wfMsg( 'smw_iq_disabled' ) );
4746 } else {
@@ -55,6 +54,7 @@
5655 $this->makeHTMLResult();
5756 }
5857 }
 58+
5959 SMWOutputs::commitToOutputPage( $wgOut ); // make sure locally collected output data is pushed to the output!
6060 wfProfileOut( 'doSpecialAsk (SMW)' );
6161 }
@@ -70,6 +70,7 @@
7171 if ( $wgRequest->getCheck( 'q' ) ) { // called by own Special, ignore full param string in that case
7272 $query_values = $wgRequest->getArray( 'p' );
7373 $query_val = $wgRequest->getVal( 'p' );
 74+
7475 if ( ! empty( $query_val ) )
7576 $rawparams = SMWInfolink::decodeParameters( $query_val, false ); // p is used for any additional parameters in certain links
7677 else {
@@ -82,15 +83,19 @@
8384 } else { // called from wiki, get all parameters
8485 $rawparams = SMWInfolink::decodeParameters( $p, true );
8586 }
 87+
8688 // Check for q= query string, used whenever this special page calls itself (via submit or plain link):
8789 $this->m_querystring = $wgRequest->getText( 'q' );
8890 if ( $this->m_querystring != '' ) {
8991 $rawparams[] = $this->m_querystring;
9092 }
 93+
9194 // Check for param strings in po (printouts), appears in some links and in submits:
9295 $paramstring = $wgRequest->getText( 'po' );
 96+
9397 if ( $paramstring != '' ) { // parameters from HTML input fields
9498 $ps = explode( "\n", $paramstring ); // params separated by newlines here (compatible with text-input for printouts)
 99+
95100 foreach ( $ps as $param ) { // add initial ? if omitted (all params considered as printouts)
96101 $param = trim( $param );
97102 if ( ( $param != '' ) && ( $param { 0 } != '?' ) ) {
@@ -110,6 +115,7 @@
111116 $this->m_params['format'] = 'broadtable';
112117 }
113118 }
 119+
114120 if ( !array_key_exists( 'order', $this->m_params ) ) {
115121 $order_values = $wgRequest->getArray( 'order' );
116122 if ( is_array( $order_values ) ) {
@@ -120,7 +126,9 @@
121127 }
122128 }
123129 }
 130+
124131 $this->m_num_sort_values = 0;
 132+
125133 if ( !array_key_exists( 'sort', $this->m_params ) ) {
126134 $sort_values = $wgRequest->getArray( 'sort' );
127135 if ( is_array( $sort_values ) ) {
@@ -128,6 +136,7 @@
129137 $this->m_num_sort_values = count( $sort_values );
130138 }
131139 }
 140+
132141 // Find implicit ordering for RSS -- needed for downwards compatibility with SMW <=1.1
133142 /*
134143 if ( ($this->m_params['format'] == 'rss') && ($this->m_params['sort'] == '') && ($sortcount==0)) {
@@ -139,16 +148,20 @@
140149 }
141150 }
142151 */
 152+
143153 if ( !array_key_exists( 'offset', $this->m_params ) ) {
144154 $this->m_params['offset'] = $wgRequest->getVal( 'offset' );
145155 if ( $this->m_params['offset'] == '' ) $this->m_params['offset'] = 0;
146156 }
 157+
147158 if ( !array_key_exists( 'limit', $this->m_params ) ) {
148159 $this->m_params['limit'] = $wgRequest->getVal( 'limit' );
 160+
149161 if ( $this->m_params['limit'] == '' ) {
150 - $this->m_params['limit'] = ( $this->m_params['format'] == 'rss' ) ? 10:20; // standard limit for RSS
 162+ $this->m_params['limit'] = ( $this->m_params['format'] == 'rss' ) ? 10 : 20; // Standard limit for RSS.
151163 }
152164 }
 165+
153166 $this->m_params['limit'] = min( $this->m_params['limit'], $smwgQMaxInlineLimit );
154167
155168 $this->m_editquery = ( $wgRequest->getVal( 'eq' ) == 'yes' ) || ( $this->m_querystring == '' );
@@ -157,7 +170,7 @@
158171 static protected function addAutocompletionJavascriptAndCSS() {
159172 global $wgOut, $smwgScriptPath, $smwgJQueryIncluded, $smwgJQueryUIIncluded;
160173
161 - // Add CSS and JavaScript for jQuery and jQuery UI
 174+ // Add CSS and JavaScript for jQuery and jQuery UI.
162175 $wgOut->addExtensionStyle( "$smwgScriptPath/skins/jquery-ui/base/jquery.ui.all.css" );
163176
164177 $scripts = array();
@@ -186,13 +199,17 @@
187200 /* collect property names for autocomplete */
188201 $propertyNames[] = array();
189202 $results = smwfGetStore()->getPropertiesSpecial();
 203+
190204 foreach ( $results as $result ) {
191205 $propertyNames[] = $result[0]->getWikiValue();
192206 }
 207+
193208 $results = smwfGetStore()->getUnusedPropertiesSpecial();
 209+
194210 foreach ( $results as $result ) {
195211 $propertyNames[] = $result->getWikiValue();
196212 }
 213+
197214 sort( $propertyNames );
198215
199216 $properties_po = "[";
@@ -355,11 +372,14 @@
356373 $tmp_parray[$key] = $value;
357374 }
358375 }
 376+
359377 $urltail .= '&p=' . urlencode( SMWInfolink::encodeParameters( $tmp_parray ) );
360378 $printoutstring = '';
 379+
361380 foreach ( $this->m_printouts as $printout ) {
362381 $printoutstring .= $printout->getSerialisation() . "\n";
363382 }
 383+
364384 if ( $printoutstring != '' ) $urltail .= '&po=' . urlencode( $printoutstring );
365385 if ( array_key_exists( 'sort', $this->m_params ) ) $urltail .= '&sort=' . $this->m_params['sort'];
366386 if ( array_key_exists( 'order', $this->m_params ) ) $urltail .= '&order=' . $this->m_params['order'];
@@ -367,7 +387,8 @@
368388 if ( $this->m_querystring != '' ) {
369389 $queryobj = SMWQueryProcessor::createQuery( $this->m_querystring, $this->m_params, SMWQueryProcessor::SPECIAL_PAGE , $this->m_params['format'], $this->m_printouts );
370390 $res = smwfGetStore()->getQueryResult( $queryobj );
371 - // try to be smart for rss/ical if no description/title is given and we have a concept query:
 391+
 392+ // Try to be smart for rss/ical if no description/title is given and we have a concept query:
372393 if ( $this->m_params['format'] == 'rss' ) {
373394 $desckey = 'rssdescription';
374395 $titlekey = 'rsstitle';
@@ -375,12 +396,15 @@
376397 $desckey = 'icalendardescription';
377398 $titlekey = 'icalendartitle';
378399 } else { $desckey = false; }
 400+
379401 if ( ( $desckey ) && ( $queryobj->getDescription() instanceof SMWConceptDescription ) &&
380402 ( !isset( $this->m_params[$desckey] ) || !isset( $this->m_params[$titlekey] ) ) ) {
381403 $concept = $queryobj->getDescription()->getConcept();
 404+
382405 if ( !isset( $this->m_params[$titlekey] ) ) {
383406 $this->m_params[$titlekey] = $concept->getText();
384407 }
 408+
385409 if ( !isset( $this->m_params[$desckey] ) ) {
386410 $dv = end( smwfGetStore()->getPropertyValues( SMWWikiPageValue::makePageFromTitle( $concept ), SMWPropertyValue::makeProperty( '_CONC' ) ) );
387411 if ( $dv instanceof SMWConceptValue ) {
@@ -388,9 +412,12 @@
389413 }
390414 }
391415 }
 416+
392417 $printer = SMWQueryProcessor::getResultPrinter( $this->m_params['format'], SMWQueryProcessor::SPECIAL_PAGE );
393418 $result_mime = $printer->getMimeType( $res );
 419+
394420 global $wgRequest;
 421+
395422 $hidequery = $wgRequest->getVal( 'eq' ) == 'no';
396423 // if it's an export format (like CSV, JSON, etc.),
397424 // don't actually export the data if 'eq' is set to
@@ -400,18 +427,19 @@
401428 $result_mime = false;
402429 if ( $result_mime == false ) {
403430 if ( $res->getCount() > 0 ) {
404 - if ( $this->m_editquery )
405 - $urltail .= '&eq=yes';
406 - if ( $hidequery )
407 - $urltail .= '&eq=no';
 431+ if ( $this->m_editquery ) $urltail .= '&eq=yes';
 432+ if ( $hidequery ) $urltail .= '&eq=no';
 433+
408434 $navigation = $this->getNavigationBar( $res, $urltail );
409435 $result .= '<div style="text-align: center;">' . "\n" . $navigation . "\n</div>\n";
410436 $query_result = $printer->getResult( $res, $this->m_params, SMW_OUTPUT_HTML );
 437+
411438 if ( is_array( $query_result ) ) {
412439 $result .= $query_result[0];
413440 } else {
414441 $result .= $query_result;
415442 }
 443+
416444 $result .= '<div style="text-align: center;">' . "\n" . $navigation . "\n</div>\n";
417445 } else {
418446 $result = '<div style="text-align: center;">' . wfMsg( 'smw_result_noresults' ) . '</div>';
@@ -428,14 +456,18 @@
429457 } else {
430458 $wgOut->setHTMLtitle( wfMsg( 'ask' ) );
431459 }
 460+
432461 $result = $this->getInputForm( $printoutstring, 'offset=' . $this->m_params['offset'] . '&limit=' . $this->m_params['limit'] . $urltail ) . $result;
433462 $wgOut->addHTML( $result );
434463 } else {
435464 $wgOut->disable();
 465+
436466 header( "Content-type: $result_mime; charset=UTF-8" );
 467+
437468 if ( $result_name !== false ) {
438469 header( "content-disposition: attachment; filename=$result_name" );
439470 }
 471+
440472 print $result;
441473 }
442474 }
@@ -443,6 +475,7 @@
444476
445477 protected function getInputForm( $printoutstring, $urltail ) {
446478 global $wgUser, $smwgQSortingSupport, $wgLang, $smwgResultFormats;
 479+
447480 $skin = $wgUser->getSkin();
448481 $result = '';
449482
@@ -466,16 +499,20 @@
467500 $orders = explode( ',', $this->m_params['order'] );
468501 reset( $sorts );
469502 }
 503+
470504 foreach ( $orders as $i => $order ) {
471505 $result .= "<div id=\"sort_div_$i\">" . wfMsg( 'smw_ask_sortby' ) . ' <input type="text" name="sort[' . $i . ']" value="' .
472506 htmlspecialchars( $sorts[$i] ) . "\" size=\"35\"/>\n" . '<select name="order[' . $i . ']"><option ';
 507+
473508 if ( $order == 'ASC' ) $result .= 'selected="selected" ';
474509 $result .= 'value="ASC">' . wfMsg( 'smw_ask_ascorder' ) . '</option><option ';
475510 if ( $order == 'DESC' ) $result .= 'selected="selected" ';
 511+
476512 $result .= 'value="DESC">' . wfMsg( 'smw_ask_descorder' ) . "</option></select>\n";
477513 $result .= '[<a href="javascript:removeInstance(\'sort_div_' . $i . '\')">' . wfMsg( 'delete' ) . '</a>]' . "\n";
478514 $result .= "</div>\n";
479515 }
 516+
480517 $result .= '<div id="sorting_starter" style="display: none">' . wfMsg( 'smw_ask_sortby' ) . ' <input type="text" name="sort_num" size="35" />' . "\n";
481518 $result .= ' <select name="order_num">' . "\n";
482519 $result .= ' <option value="ASC">' . wfMsg( 'smw_ask_ascorder' ) . "</option>\n";
@@ -487,23 +524,27 @@
488525
489526 $printer = SMWQueryProcessor::getResultPrinter( 'broadtable', SMWQueryProcessor::SPECIAL_PAGE );
490527 $url = htmlspecialchars( $skin->makeSpecialUrl( 'Ask', "showformatoptions=\" + this.value + \"" ) );
 528+
491529 foreach ( $this->m_params as $param => $value ) {
492 - if ( $param !== 'format' )
493 - $url .= "&params[$param]=$value";
 530+ if ( $param !== 'format' ) $url .= "&params[$param]=$value";
494531 }
 532+
495533 $result .= "<br /><br />\n<p>" . wfMsg( 'smw_ask_format_as' ) . ' <input type="hidden" name="eq" value="yes"/>' . "\n" .
496534 '<select id="formatSelector" name="p[format]" onChange=\'JavaScript:xmlhttpPost("' . $url . "\")'>\n" .
497535 ' <option value="broadtable"' . ( $this->m_params['format'] == 'broadtable' ? ' selected' : '' ) . '>' .
498536 $printer->getName() . ' (' . wfMsg( 'smw_ask_defaultformat' ) . ')</option>' . "\n";
499537
500538 $formats = array();
 539+
501540 foreach ( array_keys( $smwgResultFormats ) as $format ) {
502541 if ( ( $format != 'broadtable' ) && ( $format != 'count' ) && ( $format != 'debug' ) ) { // special formats "count" and "debug" currently not supported
503542 $printer = SMWQueryProcessor::getResultPrinter( $format, SMWQueryProcessor::SPECIAL_PAGE );
504543 $formats[$format] = $printer->getName();
505544 }
506545 }
 546+
507547 natcasesort( $formats );
 548+
508549 foreach ( $formats as $format => $name ) {
509550 $result .= ' <option value="' . $format . '"' . ( $this->m_params['format'] == $format ? ' selected' : '' ) . '>' . $name . "</option>\n";
510551 }
@@ -549,8 +590,7 @@
550591 return $result;
551592 }
552593
553 - private static function getEmbedToggle()
554 - {
 594+ protected static function getEmbedToggle() {
555595 return '<span id="embed_show"><a href="#" rel="nofollow" onclick="' .
556596 "document.getElementById('inlinequeryembed').style.display='block';" .
557597 "document.getElementById('embed_hide').style.display='inline';" .
@@ -565,14 +605,16 @@
566606 }
567607
568608 /**
569 - * Build the navigation for some given query result, reuse url-tail parameters
 609+ * Build the navigation for some given query result, reuse url-tail parameters.
570610 */
571611 protected function getNavigationBar( $res, $urltail ) {
572612 global $wgUser, $smwgQMaxInlineLimit;
 613+
573614 $skin = $wgUser->getSkin();
574615 $offset = $this->m_params['offset'];
575616 $limit = $this->m_params['limit'];
576 - // prepare navigation bar
 617+
 618+ // Prepare navigation bar.
577619 if ( $offset > 0 ) {
578620 $navigation = '<a href="' . htmlspecialchars( $skin->makeSpecialUrl( 'Ask', 'offset=' . max( 0, $offset - $limit ) . '&limit=' . $limit . $urltail ) ) . '" rel="nofollow">' . wfMsg( 'smw_result_prev' ) . '</a>';
579621 } else {
@@ -588,21 +630,26 @@
589631 }
590632
591633 $first = true;
 634+
592635 foreach ( array( 20, 50, 100, 250, 500 ) as $l ) {
593636 if ( $l > $smwgQMaxInlineLimit ) break;
 637+
594638 if ( $first ) {
595639 $navigation .= '&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(';
596640 $first = false;
597641 } else {
598642 $navigation .= ' ' . SMWAskPage::$pipeseparator . ' ';
599643 }
 644+
600645 if ( $limit != $l ) {
601646 $navigation .= '<a href="' . htmlspecialchars( $skin->makeSpecialUrl( 'Ask', 'offset=' . $offset . '&limit=' . $l . $urltail ) ) . '" rel="nofollow">' . $l . '</a>';
602647 } else {
603648 $navigation .= '<b>' . $l . '</b>';
604649 }
605650 }
 651+
606652 $navigation .= ')';
 653+
607654 return $navigation;
608655 }
609656
@@ -611,63 +658,69 @@
612659 * based on the getParameters() value for that format's query printer
613660 */
614661 function showFormatOptions( $format, $param_values ) {
615 - $text = "";
 662+ $text = '';
 663+
616664 $printer = SMWQueryProcessor::getResultPrinter( $format, SMWQueryProcessor::SPECIAL_PAGE );
617 - if ( method_exists( $printer, 'getParameters' ) )
618 - $params = $printer->getParameters();
619 - else
620 - $params = array();
 665+
 666+
 667+ $params = method_exists( $printer, 'getParameters' ) ? $printer->getParameters() : array();
 668+
621669 foreach ( $params as $i => $param ) {
622670 $param_name = $param['name'];
623671 $type = $param['type'];
624672 $desc = $param['description'];
625 - $cur_value = ( array_key_exists( $param_name, $param_values ) ) ? $param_values[$param_name] : "";
 673+ $cur_value = ( array_key_exists( $param_name, $param_values ) ) ? $param_values[$param_name] : '';
 674+
626675 // 3 values per row, with alternating colors for rows
627676 if ( $i % 3 == 0 ) {
628677 $bgcolor = ( $i % 6 ) == 0 ? '#dddddd' : 'white';
629678 $text .= "<div style=\"background: $bgcolor;\">";
630679 }
 680+
631681 $text .= "<div style=\"width: 30%; padding: 5px; float: left;\">$param_name:\n";
 682+
632683 switch ( $type ) {
633 - case 'int':
634 - $text .= "<input type=\"text\" name=\"p[$param_name]\" size=\"6\" value=\"$cur_value\" />";
635 - break;
636 - case 'string':
637 - $text .= "<input type=\"text\" name=\"p[$param_name]\" size=\"32\" value=\"$cur_value\" />";
638 - break;
639 - case 'enumeration':
640 - $values = $param['values'];
641 - $text .= "<select name=\"p[$param_name]\">\n";
642 - $text .= " <option value=''></option>\n";
643 - foreach ( $values as $val ) {
644 - if ( $cur_value == $val )
645 - $selected_str = 'selected';
646 - else
647 - $selected_str = '';
648 - $text .= " <option value='$val' $selected_str>$val</option>\n";
649 - }
650 - $text .= "</select>";
651 - break;
652 - case 'enum-list':
653 - $all_values = $param['values'];
654 - $cur_values = explode( ',', $cur_value );
655 - foreach ( $all_values as $val ) {
656 - $checked_str = ( in_array( $val, $cur_values ) ) ? "checked" : "";
657 - $text .= "<span style=\"white-space: nowrap; padding-right: 5px;\"><input type=\"checkbox\" name=\"p[$param_name][$val]\" value=\"true\" $checked_str /> <tt>$val</tt></span>\n";
658 - }
659 - break;
660 - case 'boolean':
661 - $checked_str = ( array_key_exists( $param_name, $param_values ) ) ? 'checked' : '';
662 - $text .= "<input type=\"checkbox\" name=\"p[$param_name]\" value=\"true\" $checked_str />";
663 - break;
 684+ case 'int':
 685+ $text .= "<input type=\"text\" name=\"p[$param_name]\" size=\"6\" value=\"$cur_value\" />";
 686+ break;
 687+ case 'string':
 688+ $text .= "<input type=\"text\" name=\"p[$param_name]\" size=\"32\" value=\"$cur_value\" />";
 689+ break;
 690+ case 'enumeration':
 691+ $values = $param['values'];
 692+ $text .= "<select name=\"p[$param_name]\">\n";
 693+ $text .= " <option value=''></option>\n";
 694+ foreach ( $values as $val ) {
 695+ if ( $cur_value == $val )
 696+ $selected_str = 'selected';
 697+ else
 698+ $selected_str = '';
 699+ $text .= " <option value='$val' $selected_str>$val</option>\n";
 700+ }
 701+ $text .= "</select>";
 702+ break;
 703+ case 'enum-list':
 704+ $all_values = $param['values'];
 705+ $cur_values = explode( ',', $cur_value );
 706+ foreach ( $all_values as $val ) {
 707+ $checked_str = ( in_array( $val, $cur_values ) ) ? "checked" : "";
 708+ $text .= "<span style=\"white-space: nowrap; padding-right: 5px;\"><input type=\"checkbox\" name=\"p[$param_name][$val]\" value=\"true\" $checked_str /> <tt>$val</tt></span>\n";
 709+ }
 710+ break;
 711+ case 'boolean':
 712+ $checked_str = ( array_key_exists( $param_name, $param_values ) ) ? 'checked' : '';
 713+ $text .= "<input type=\"checkbox\" name=\"p[$param_name]\" value=\"true\" $checked_str />";
 714+ break;
664715 }
 716+
665717 $text .= "\n <br /><em>$desc</em>\n</div>\n";
 718+
666719 if ( $i % 3 == 2 || $i == count( $params ) - 1 ) {
667720 $text .= "<div style=\"clear: both\";></div></div>\n";
668721 }
669722 }
 723+
670724 return $text;
671725 }
672726
673727 }
674 -

Follow-up revisions

RevisionCommit summaryAuthorDate
r73989Follow up to r73986jeroendedauw22:07, 29 September 2010
r73997Follow up to r73986jeroendedauw22:46, 29 September 2010
r74002Follow up to r73986jeroendedauw23:09, 29 September 2010

Status & tagging log