Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php |
— | — | @@ -4,6 +4,10 @@ |
5 | 5 | * A base class for Semantic Search UIs. All Semantic Search UI's may subclass |
6 | 6 | * from this. |
7 | 7 | * |
| 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 | + * |
8 | 12 | * @author Markus Krötzsch |
9 | 13 | * @author Yaron Koren |
10 | 14 | * @author Sanyam Goyal |
— | — | @@ -11,28 +15,108 @@ |
12 | 16 | * @author Devayon Das |
13 | 17 | */ |
14 | 18 | 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 | + */ |
16 | 31 | private $autocompleteenabled = false; |
| 32 | + |
| 33 | + /* |
| 34 | + * |
| 35 | + */ |
17 | 36 | const ENABLE_AUTO_SUGGEST = true; |
18 | 37 | const DISABLE_AUTO_SUGGEST = false; |
19 | 38 | |
20 | 39 | /** |
| 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 | + /** |
21 | 98 | * Builds a read-only #ask embed code of the given query. |
22 | 99 | * |
23 | 100 | * @return string |
24 | 101 | */ |
25 | 102 | protected function getAskEmbedBox() { |
26 | 103 | $result = ''; |
27 | | - if ( $this->m_ui_helper->getQueryString() != "" ) { |
| 104 | + if ( $this->uiCore->getQueryString() != "" ) { |
28 | 105 | $result = Html::rawElement( 'div', array( 'id' => 'inlinequeryembed' ), |
29 | 106 | Html::rawElement( 'div', array( 'id' => 'inlinequeryembedinstruct' ), wfMsg( 'smw_ask_embed_instr' ) ) . |
30 | 107 | 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() ) ); |
32 | 109 | } |
33 | 110 | return $result; |
34 | 111 | } |
35 | 112 | |
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() { |
37 | 121 | global $wgOut, $smwgScriptPath, $smwgJQueryIncluded, $smwgJQueryUIIncluded; |
38 | 122 | if ( $this->autocompleteenabled == false ) { |
39 | 123 | $wgOut->addExtensionStyle( "$smwgScriptPath/skins/jquery-ui/base/jquery.ui.all.css" ); |
— | — | @@ -111,6 +195,13 @@ |
112 | 196 | } |
113 | 197 | } |
114 | 198 | |
| 199 | + /** |
| 200 | + * |
| 201 | + * @global OutputPage $wgOut |
| 202 | + * @global <type> $wgRequest |
| 203 | + * @param <type> $p |
| 204 | + * @todo remove this method |
| 205 | + */ |
115 | 206 | protected function makeRes( $p ) { |
116 | 207 | /* |
117 | 208 | * TODO: extract parameters from $p and decide: |
— | — | @@ -124,7 +215,7 @@ |
125 | 216 | $htmloutput .= $this->getForm(); |
126 | 217 | $param = array(); |
127 | 218 | |
128 | | - $this->m_ui_helper = $helper = new SMWQueryUIHelper; // or some factory method |
| 219 | + $this->uiCore = $helper = new SMWQueryUIHelper; // or some factory method |
129 | 220 | // here come some driver lines for testing; this is very temporary |
130 | 221 | |
131 | 222 | // form parameters default values |
— | — | @@ -191,7 +282,7 @@ |
192 | 283 | '     <b>' . |
193 | 284 | wfMsg( 'smw_result_results' ) . ' ' . ( $offset + 1 ) . |
194 | 285 | '– ' . |
195 | | - ( $offset + $this->m_ui_helper->getResultCount() ) . |
| 286 | + ( $offset + $this->uiCore->getResultCount() ) . |
196 | 287 | '</b>    '; |
197 | 288 | |
198 | 289 | if ( $has_further_results ) { |
— | — | @@ -265,9 +356,6 @@ |
266 | 357 | $result = "<br>Stub: The Form elements come here<br><br>"; |
267 | 358 | return $result; |
268 | 359 | } |
269 | | - protected function makeHtmlResult() { |
270 | | - // STUB |
271 | | - } |
272 | 360 | |
273 | 361 | /** |
274 | 362 | * Generates the form element(s) for the Query-string. Use its |
— | — | @@ -518,9 +606,9 @@ |
519 | 607 | * @return string An url-encoded string. |
520 | 608 | */ |
521 | 609 | protected function getUrlTail() { |
522 | | - $urltail = '&q=' . urlencode( $this->m_ui_helper->getQuerystring() ); |
| 610 | + $urltail = '&q=' . urlencode( $this->uiCore->getQuerystring() ); |
523 | 611 | $tmp_parray = array(); |
524 | | - $params = $this->m_ui_helper->getParams(); |
| 612 | + $params = $this->uiCore->getParams(); |
525 | 613 | foreach ( $params as $key => $value ) { |
526 | 614 | if ( !in_array( $key, array( 'sort', 'order', 'limit', 'offset', 'title' ) ) ) { |
527 | 615 | $tmp_parray[$key] = $value; |
— | — | @@ -529,7 +617,7 @@ |
530 | 618 | |
531 | 619 | $urltail .= '&p=' . urlencode( SMWInfolink::encodeParameters( $tmp_parray ) ); |
532 | 620 | $printoutstring = ''; |
533 | | - foreach ( $this->m_ui_helper->getPrintOuts() as $printout ) { |
| 621 | + foreach ( $this->uiCore->getPrintOuts() as $printout ) { |
534 | 622 | $printoutstring .= $printout->getSerialisation() . "\n"; |
535 | 623 | } |
536 | 624 | |
— | — | @@ -579,7 +667,7 @@ |
580 | 668 | |
581 | 669 | for ( $i = 0, $n = count( $optionsHtml ); $i < $n; $i++ ) { |
582 | 670 | 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"; |
584 | 672 | } |
585 | 673 | } |
586 | 674 | |
— | — | @@ -697,7 +785,7 @@ |
698 | 786 | $printer = SMWQueryProcessor::getResultPrinter( $default_format, SMWQueryProcessor::SPECIAL_PAGE ); |
699 | 787 | $url = $this->getTitle()->getLocalURL( "showformatoptions=' + this.value + '" ); |
700 | 788 | |
701 | | - foreach ( $this->m_ui_helper->getParams() as $param => $value ) { |
| 789 | + foreach ( $this->uiCore->getParams() as $param => $value ) { |
702 | 790 | if ( $param !== 'format' ) { |
703 | 791 | $url .= '¶ms[' . Xml::escapeJsString( $param ) . ']=' . Xml::escapeJsString( $value ); |
704 | 792 | } |
— | — | @@ -718,7 +806,7 @@ |
719 | 807 | } |
720 | 808 | |
721 | 809 | natcasesort( $formats ); |
722 | | - $params = $this->m_ui_helper->getParams(); |
| 810 | + $params = $this->uiCore->getParams(); |
723 | 811 | foreach ( $formats as $format => $name ) { |
724 | 812 | $result .= ' <option value="' . $format . '"' . ( $params['format'] == $format ? ' selected' : '' ) . '>' . $name . "</option>\n"; |
725 | 813 | } |
— | — | @@ -805,7 +893,7 @@ |
806 | 894 | */ |
807 | 895 | public function getPOStrings() { |
808 | 896 | $string = ""; |
809 | | - $printouts = $this->m_ui_helper->getPrintOuts(); |
| 897 | + $printouts = $this->uiCore->getPrintOuts(); |
810 | 898 | if ( !empty( $printouts ) ) { |
811 | 899 | foreach ( $printouts as $value ) { |
812 | 900 | $string .= $value->getSerialisation() . "\n"; |
— | — | @@ -821,7 +909,7 @@ |
822 | 910 | */ |
823 | 911 | protected function usesNavigationBar() { |
824 | 912 | // hide if no results are found |
825 | | - if ( $this->m_ui_helper->getResultCount() == 0 ) return false; |
| 913 | + if ( $this->uiCore->getResultCount() == 0 ) return false; |
826 | 914 | else return true; |
827 | 915 | } |
828 | 916 | |
Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php |
— | — | @@ -2,8 +2,7 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * 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. |
8 | 7 | * |
9 | 8 | * Currently adapted from current contents of SMW_SpecialAsk.php |
10 | 9 | * This page is currently under development as part of the Google Summer of |
— | — | @@ -33,52 +32,23 @@ |
34 | 33 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
35 | 34 | } |
36 | 35 | |
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 | + } |
46 | 43 | |
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>"; |
64 | 45 | |
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? |
79 | 48 | } |
80 | 49 | } |
81 | | - SMWOutputs::commitToOutputPage( $wgOut ); // make sure locally collected output data is pushed to the output! |
| 50 | + $wgOut->addHTML( $htmloutput ); |
82 | 51 | } |
| 52 | + |
83 | 53 | /** |
84 | 54 | * Adds the input query form. Overloaded from SMWQueryUI |
85 | 55 | */ |
— | — | @@ -92,7 +62,7 @@ |
93 | 63 | $result .= wfMsg( 'smw_qc_query_help' ); |
94 | 64 | // Main query and printouts. |
95 | 65 | $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>'; |
97 | 67 | // show|hide additional options and querying help |
98 | 68 | $result .= '<span id="show_additional_options" style="display:inline"><a href="#addtional" rel="nofollow" onclick="' . |
99 | 69 | "document.getElementById('additional_options').style.display='block';" . |
— | — | @@ -117,7 +87,7 @@ |
118 | 88 | } |
119 | 89 | $result .= "<br><br>" . $this->getFormatSelectBox( 'broadtable' ); |
120 | 90 | |
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 |
122 | 92 | $result .= $this->getAskEmbedBox(); |
123 | 93 | |
124 | 94 | $result .= '</div>'; // end of hidden additional options |