r92049 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92048‎ | r92049 | r92050 >
Date:06:24, 13 July 2011
Author:devayon
Status:deferred
Tags:
Comment:
Added support for info-link, follow up to r91837
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php
@@ -4,6 +4,10 @@
55 * A base class for Semantic Search UIs. All Semantic Search UI's may subclass
66 * from this.
77 *
 8+ * The commonly used and overloaded methods are the ones which create some default
 9+ * UI elements (the getxxxFormBox() methods) and corresponding methods that
 10+ * extract data from them (the processxxxFormBox() methods).
 11+ *
812 * @author Markus Krötzsch
913 * @author Yaron Koren
1014 * @author Sanyam Goyal
@@ -11,28 +15,108 @@
1216 * @author Devayon Das
1317 */
1418 abstract class SMWQueryUI extends SpecialPage {
15 - protected $m_ui_helper;
 19+ /**
 20+ * The handle for the underlying SMWQueryUIHelper class.
 21+ * @var SMWQueryUIHelper
 22+ * @see SMWQueryUIHelper
 23+ */
 24+ protected $uiCore;
 25+
 26+ /**
 27+ * Is auto-complete enabled for these UI elements?
 28+ *
 29+ * @var mixed SMWQUeryUI::ENABLE_AUTO_SUGGEST | SMWQUeryUI::DISABLE_AUTO_SUGGEST
 30+ */
1631 private $autocompleteenabled = false;
 32+
 33+ /*
 34+ *
 35+ */
1736 const ENABLE_AUTO_SUGGEST = true;
1837 const DISABLE_AUTO_SUGGEST = false;
1938
2039 /**
 40+ * Initialises the page. Sets the property $uiCore to the appropriate helper object.
 41+ *
 42+ * To create a custom UI, adding changes to makePage() is usually enough, but one might want to
 43+ * overload this method to get better handling of form parameters.
 44+ *
 45+ * @global OutputPage $wgOut
 46+ * @global WebRequest $wgRequest
 47+ * @global boolean $smwgQEnabled
 48+ * @param string $p the sub-page string
 49+ */
 50+ public function execute( $p ) {
 51+ global $wgOut, $wgRequest, $smwgQEnabled;
 52+
 53+ $this->setHeaders();
 54+
 55+ if ( !$smwgQEnabled ) {
 56+ $wgOut->addHTML( '<br />' . wfMsg( 'smw_iq_disabled' ) );
 57+ } else {
 58+ $format_options_requested = $this->processFormatOptions( $wgRequest ); // handling ajax for format options
 59+ if ( !$format_options_requested ) {
 60+ // Checking if a query string has been sent by using the form
 61+ // the 'q' is dependent from the form parameter set by getQueryFormBox()
 62+ // and processQueryFormBox()
 63+ if ( $wgRequest->getCheck( 'q' ) ) {
 64+ $params = array_merge(
 65+ array(
 66+ 'format' => $wgRequest->getVal( 'format' ),
 67+ 'offset' => $wgRequest->getVal( 'offset', '0' ),
 68+ 'limit' => $wgRequest->getVal( 'limit', '20' )
 69+ ), $this->processFormatSelectBox( $wgRequest ) );
 70+ $this->uiCore = SMWQueryUIHelper::makeForUI(
 71+ $this->processQueryFormBox( $wgRequest ),
 72+ $params,
 73+ $this->processPOFormBox( $wgRequest ),
 74+ false );
 75+ if ( $this->uiCore->getQueryString() != "" ) {
 76+ $this->uiCore->execute( $p );
 77+ }
 78+ }
 79+ else {
 80+ // the user has entered this page from a wiki-page using an infolink,
 81+ // or no query has been set
 82+ $this->uiCore = SMWQueryUIHelper::makeForInfoLink( $p );
 83+ }
 84+ $this->makepage( $p );
 85+ }
 86+ }
 87+
 88+ SMWOutputs::commitToOutputPage( $wgOut ); // make sure locally collected output data is pushed to the output!
 89+ }
 90+
 91+ /**
 92+ * The main entrypoint for your UI. Call the various methods of SMWQueryUI and
 93+ * SMWQueryUIHelper to build ui elements and to process them.
 94+ */
 95+ protected abstract function makePage( $p );
 96+
 97+ /**
2198 * Builds a read-only #ask embed code of the given query.
2299 *
23100 * @return string
24101 */
25102 protected function getAskEmbedBox() {
26103 $result = '';
27 - if ( $this->m_ui_helper->getQueryString() != "" ) {
 104+ if ( $this->uiCore->getQueryString() != "" ) {
28105 $result = Html::rawElement( 'div', array( 'id' => 'inlinequeryembed' ),
29106 Html::rawElement( 'div', array( 'id' => 'inlinequeryembedinstruct' ), wfMsg( 'smw_ask_embed_instr' ) ) .
30107 Html::element( 'textarea', array( 'id' => 'inlinequeryembedarea', 'readonly' => 'yes', 'cols' => '20', 'rows' => '6', 'onclick' => 'this.select()' ),
31 - $this->m_ui_helper->getAsk() ) );
 108+ $this->uiCore->getAsk() ) );
32109 }
33110 return $result;
34111 }
35112
36 - protected function addAutocompletionJavascriptAndCSS() {
 113+ /**
 114+ * Adds common JS and CSS required for Autocompletion.
 115+ * @global OutputPage $wgOut
 116+ * @global string $smwgScriptPath
 117+ * @global boolean $smwgJQueryIncluded
 118+ * @global boolean $smwgJQueryUIIncluded
 119+ */
 120+ private function addAutocompletionJavascriptAndCSS() {
37121 global $wgOut, $smwgScriptPath, $smwgJQueryIncluded, $smwgJQueryUIIncluded;
38122 if ( $this->autocompleteenabled == false ) {
39123 $wgOut->addExtensionStyle( "$smwgScriptPath/skins/jquery-ui/base/jquery.ui.all.css" );
@@ -111,6 +195,13 @@
112196 }
113197 }
114198
 199+ /**
 200+ *
 201+ * @global OutputPage $wgOut
 202+ * @global <type> $wgRequest
 203+ * @param <type> $p
 204+ * @todo remove this method
 205+ */
115206 protected function makeRes( $p ) {
116207 /*
117208 * TODO: extract parameters from $p and decide:
@@ -124,7 +215,7 @@
125216 $htmloutput .= $this->getForm();
126217 $param = array();
127218
128 - $this->m_ui_helper = $helper = new SMWQueryUIHelper; // or some factory method
 219+ $this->uiCore = $helper = new SMWQueryUIHelper; // or some factory method
129220 // here come some driver lines for testing; this is very temporary
130221
131222 // form parameters default values
@@ -191,7 +282,7 @@
192283 '&#160;&#160;&#160;&#160; <b>' .
193284 wfMsg( 'smw_result_results' ) . ' ' . ( $offset + 1 ) .
194285 '&#150; ' .
195 - ( $offset + $this->m_ui_helper->getResultCount() ) .
 286+ ( $offset + $this->uiCore->getResultCount() ) .
196287 '</b>&#160;&#160;&#160;&#160;';
197288
198289 if ( $has_further_results ) {
@@ -265,9 +356,6 @@
266357 $result = "<br>Stub: The Form elements come here<br><br>";
267358 return $result;
268359 }
269 - protected function makeHtmlResult() {
270 - // STUB
271 - }
272360
273361 /**
274362 * Generates the form element(s) for the Query-string. Use its
@@ -518,9 +606,9 @@
519607 * @return string An url-encoded string.
520608 */
521609 protected function getUrlTail() {
522 - $urltail = '&q=' . urlencode( $this->m_ui_helper->getQuerystring() );
 610+ $urltail = '&q=' . urlencode( $this->uiCore->getQuerystring() );
523611 $tmp_parray = array();
524 - $params = $this->m_ui_helper->getParams();
 612+ $params = $this->uiCore->getParams();
525613 foreach ( $params as $key => $value ) {
526614 if ( !in_array( $key, array( 'sort', 'order', 'limit', 'offset', 'title' ) ) ) {
527615 $tmp_parray[$key] = $value;
@@ -529,7 +617,7 @@
530618
531619 $urltail .= '&p=' . urlencode( SMWInfolink::encodeParameters( $tmp_parray ) );
532620 $printoutstring = '';
533 - foreach ( $this->m_ui_helper->getPrintOuts() as $printout ) {
 621+ foreach ( $this->uiCore->getPrintOuts() as $printout ) {
534622 $printoutstring .= $printout->getSerialisation() . "\n";
535623 }
536624
@@ -579,7 +667,7 @@
580668
581669 for ( $i = 0, $n = count( $optionsHtml ); $i < $n; $i++ ) {
582670 if ( $i % 3 == 2 || $i == $n - 1 ) {
583 - $optionsHtml[$i] .= "<div style=\"clear: both\";></div>\n";
 671+ $optionsHtml[$i] .= Html::element( 'div', array( 'style' => 'clear: both;' ) ) . "\n";
584672 }
585673 }
586674
@@ -697,7 +785,7 @@
698786 $printer = SMWQueryProcessor::getResultPrinter( $default_format, SMWQueryProcessor::SPECIAL_PAGE );
699787 $url = $this->getTitle()->getLocalURL( "showformatoptions=' + this.value + '" );
700788
701 - foreach ( $this->m_ui_helper->getParams() as $param => $value ) {
 789+ foreach ( $this->uiCore->getParams() as $param => $value ) {
702790 if ( $param !== 'format' ) {
703791 $url .= '&params[' . Xml::escapeJsString( $param ) . ']=' . Xml::escapeJsString( $value );
704792 }
@@ -718,7 +806,7 @@
719807 }
720808
721809 natcasesort( $formats );
722 - $params = $this->m_ui_helper->getParams();
 810+ $params = $this->uiCore->getParams();
723811 foreach ( $formats as $format => $name ) {
724812 $result .= ' <option value="' . $format . '"' . ( $params['format'] == $format ? ' selected' : '' ) . '>' . $name . "</option>\n";
725813 }
@@ -805,7 +893,7 @@
806894 */
807895 public function getPOStrings() {
808896 $string = "";
809 - $printouts = $this->m_ui_helper->getPrintOuts();
 897+ $printouts = $this->uiCore->getPrintOuts();
810898 if ( !empty( $printouts ) ) {
811899 foreach ( $printouts as $value ) {
812900 $string .= $value->getSerialisation() . "\n";
@@ -821,7 +909,7 @@
822910 */
823911 protected function usesNavigationBar() {
824912 // hide if no results are found
825 - if ( $this->m_ui_helper->getResultCount() == 0 ) return false;
 913+ if ( $this->uiCore->getResultCount() == 0 ) return false;
826914 else return true;
827915 }
828916
Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php
@@ -2,8 +2,7 @@
33
44 /**
55 * This special page for Semantic MediaWiki implements a customisable form for
6 - * executing queries outside of articles. Results and format options are generated by
7 - * SMW_SpecialAsk.php.
 6+ * executing queries outside of articles.
87 *
98 * Currently adapted from current contents of SMW_SpecialAsk.php
109 * This page is currently under development as part of the Google Summer of
@@ -33,52 +32,23 @@
3433 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
3534 }
3635
37 - /**
38 - * Main entrypoint for the special page.
39 - *
40 - * @param string $p
41 - */
42 - public function execute( $p ) {
43 - global $wgOut, $wgRequest, $smwgQEnabled, $smwgIgnoreQueryErrors;
44 - $smwgIgnoreQueryErrors = false;
45 - $this->setHeaders();
 36+ protected function makePage( $p ) {
 37+ global $wgOut;
 38+ $htmloutput = $this->makeResults( $p );
 39+ if ( $this->uiCore->getQueryString() != "" ) {
 40+ if ( $this->usesNavigationBar() ) {
 41+ $htmloutput .= $this->getNavigationBar ( $this->uiCore->getLimit(), $this->uiCore->getOffset(), $this->uiCore->hasFurtherResults() ); // ? can we preload offset and limit?
 42+ }
4643
47 - if ( !$smwgQEnabled ) {
48 - $wgOut->addHTML( '<br />' . wfMsg( 'smw_iq_disabled' ) );
49 - } else {
50 - if ( !( $this->processFormatOptions( $wgRequest ) ) ) {
51 - $params = array_merge(
52 - array(
53 - 'format' => $wgRequest->getVal( 'format' ),
54 - 'offset' => $wgRequest->getVal( 'offset', '0' ),
55 - 'limit' => $wgRequest->getVal( 'limit', '20' )
56 - ), $this->processFormatSelectBox( $wgRequest ) );
57 - $this->m_ui_helper = SMWQueryUIHelper::makeForUI(
58 - $this->processQueryFormBox( $wgRequest ),
59 - $params,
60 - $this->processPOFormBox( $wgRequest ),
61 - false );
62 - if ( $this->m_ui_helper->getQueryString() != "" ) {
63 - $this->m_ui_helper->execute( $p );
 44+ $htmloutput .= "<br/>" . $this->uiCore->getHTMLResult() . "<br>";
6445
65 - }
66 - $htmloutput = $this->makeResults( $p );
67 - if ( $this->m_ui_helper->getQueryString() != "" ) {
68 - if ( $this->usesNavigationBar() ) {
69 - $htmloutput .= $this->getNavigationBar ( $this->m_ui_helper->getLimit(), $this->m_ui_helper->getOffset(), $this->m_ui_helper->hasFurtherResults() ); // ? can we preload offset and limit?
70 - }
71 -
72 - $htmloutput .= "<br/>" . $this->m_ui_helper->getHTMLResult() . "<br>";
73 -
74 - if ( $this->usesNavigationBar() ) {
75 - $htmloutput .= $this->getNavigationBar ( $this->m_ui_helper->getLimit(), $this->m_ui_helper->getOffset(), $this->m_ui_helper->hasFurtherResults() ); // ? can we preload offset and limit?
76 - }
77 - }
78 - $wgOut->addHTML( $htmloutput );
 46+ if ( $this->usesNavigationBar() ) {
 47+ $htmloutput .= $this->getNavigationBar ( $this->uiCore->getLimit(), $this->uiCore->getOffset(), $this->uiCore->hasFurtherResults() ); // ? can we preload offset and limit?
7948 }
8049 }
81 - SMWOutputs::commitToOutputPage( $wgOut ); // make sure locally collected output data is pushed to the output!
 50+ $wgOut->addHTML( $htmloutput );
8251 }
 52+
8353 /**
8454 * Adds the input query form. Overloaded from SMWQueryUI
8555 */
@@ -92,7 +62,7 @@
9363 $result .= wfMsg( 'smw_qc_query_help' );
9464 // Main query and printouts.
9565 $result .= '<p><strong>' . wfMsg( 'smw_ask_queryhead' ) . "</strong></p>\n";
96 - $result .= '<p>' . $this->getQueryFormBox( $this->m_ui_helper->getQueryString() ) . '</p>';
 66+ $result .= '<p>' . $this->getQueryFormBox( $this->uiCore->getQueryString() ) . '</p>';
9767 // show|hide additional options and querying help
9868 $result .= '<span id="show_additional_options" style="display:inline"><a href="#addtional" rel="nofollow" onclick="' .
9969 "document.getElementById('additional_options').style.display='block';" .
@@ -117,7 +87,7 @@
11888 }
11989 $result .= "<br><br>" . $this->getFormatSelectBox( 'broadtable' );
12090
121 - if ( $this->m_ui_helper->getQueryString() != '' ) // hide #ask if there isnt any query defined
 91+ if ( $this->uiCore->getQueryString() != '' ) // hide #ask if there isnt any query defined
12292 $result .= $this->getAskEmbedBox();
12393
12494 $result .= '</div>'; // end of hidden additional options

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r91837moving towards a test setup, follow up to r91836, r91836devayon17:33, 10 July 2011