PageRenderTime 42ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php

#
PHP | 265 lines | 173 code | 26 blank | 66 comment | 16 complexity | f55fbd56f6c718af9458fa335f43040a MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * This special page for Semantic MediaWiki implements a customisable form for
  4. * executing queries outside of articles.
  5. *
  6. * @file SMW_SpecialQueryCreator.php
  7. * @ingroup SMWSpecialPage
  8. * @ingroup SpecialPage
  9. *
  10. * @author Markus Kr??tzsch
  11. * @author Jeroen De Dauw
  12. * @author Sergey Chernyshev
  13. * @author Devayon Das
  14. */
  15. class SMWQueryCreatorPage extends SMWQueryUI {
  16. /**
  17. * Constructor.
  18. */
  19. public function __construct() {
  20. parent::__construct( 'QueryCreator' );
  21. }
  22. /**
  23. * The main method for creating the output page.
  24. * Calls the various methods of SMWQueryUI and SMWQueryUIHelper to build
  25. * UI elements and to process them.
  26. *
  27. * @global OutputPage $wgOut
  28. * @param string $p
  29. */
  30. protected function makePage( $p ) {
  31. $htmlOutput = $this->makeForm( $p );
  32. if ( $this->uiCore->getQueryString() != "" ) {
  33. if ( $this->usesNavigationBar() ) {
  34. $navigationBar = $this->getNavigationBar (
  35. $this->uiCore->getLimit(),
  36. $this->uiCore->getOffset(),
  37. $this->uiCore->hasFurtherResults() );
  38. $navigation = Html::rawElement( 'div',
  39. array( 'class' => 'smwqcnavbar' ),
  40. $navigationBar );
  41. } else {
  42. $navigation = '';
  43. }
  44. $htmlOutput .= $navigation .
  45. Html::rawElement( 'div', array( 'class' => 'smwqcresult' ),
  46. $this->uiCore->getHTMLResult() ) .
  47. $navigation;
  48. }
  49. return $htmlOutput;
  50. }
  51. /**
  52. * This method calls the various processXXXBox() methods for each
  53. * of the corresponding getXXXBox() methods which the UI uses. Then it
  54. * merges the results of these methods and return them.
  55. *
  56. * @global WebRequest $wgRequest
  57. * @return array
  58. */
  59. protected function processParams() {
  60. global $wgRequest;
  61. $params = array_merge(
  62. array(
  63. 'format' => $wgRequest->getVal( 'format' ),
  64. 'offset' => $wgRequest->getVal( 'offset', '0' ),
  65. 'limit' => $wgRequest->getVal( 'limit', '20' ) ),
  66. $this->processPoSortFormBox( $wgRequest ),
  67. $this->processFormatSelectBox( $wgRequest )
  68. );
  69. return $params;
  70. }
  71. /**
  72. * Displays a form section showing the options for a given format,
  73. * based on the getParameters() value for that format's query printer.
  74. *
  75. * @param string $format
  76. * @param array $paramValues The current values for the parameters (name => value)
  77. * @param array $ignoredAttribs Attributes which should not be generated by this method.
  78. *
  79. * @return string
  80. *
  81. * Overridden from parent to ignore some parameters.
  82. */
  83. protected function showFormatOptions( $format, array $paramValues, array $ignoredAttribs = array() ) {
  84. return parent::showFormatOptions( $format, $paramValues, array(
  85. 'format', 'limit', 'offset', 'mainlabel', 'intro', 'outro', 'default'
  86. ) );
  87. }
  88. /**
  89. * Create the search form.
  90. *
  91. * @return string HTML code for search form
  92. */
  93. protected function makeForm() {
  94. SMWOutputs::requireResource( 'jquery' );
  95. $specTitle = $this->getTitle();
  96. $formatBox = $this->getFormatSelectBoxSep( 'broadtable' );
  97. $result = '<div class="smwqcerrors">' . $this->getErrorsHtml() . '</div>';
  98. $formParameters = array( 'name' => 'qc', 'id'=>'smwqcform',
  99. 'action' => htmlspecialchars( $specTitle->getLocalURL() ), 'method' => 'get' );
  100. $result .= Html::openElement( 'form', $formParameters ) . "\n" .
  101. Html::hidden( 'title', $specTitle->getPrefixedText() ) .
  102. // Header:
  103. wfMsg( 'smw_qc_query_help' ) .
  104. // Main query and format options:
  105. $this->getQueryFormBox() .
  106. // Sorting and prinouts:
  107. '<div class="smwqcsortbox">' . $this->getPoSortFormBox() . '</div>';
  108. // Control to show/hide additional options:
  109. $result .= '<div class="smwqcformatas">' .
  110. Html::element( 'strong', array(), wfMsg( 'smw_ask_format_as' ) ) .
  111. $formatBox[0] .
  112. '<span id="show_additional_options" style="display:inline;">' .
  113. '<a href="#addtional" rel="nofollow" onclick="' .
  114. "jQuery('#additional_options').show('blind');" .
  115. "document.getElementById('show_additional_options').style.display='none';" .
  116. "document.getElementById('hide_additional_options').style.display='inline';" . '">' .
  117. wfMsg( 'smw_qc_show_addnal_opts' ) . '</a></span>' .
  118. '<span id="hide_additional_options" style="display:none"><a href="#" rel="nofollow" onclick="' .
  119. "jQuery('#additional_options').hide('blind');;" .
  120. "document.getElementById('hide_additional_options').style.display='none';" .
  121. "document.getElementById('show_additional_options').style.display='inline';" . '">' .
  122. wfMsg( 'smw_qc_hide_addnal_opts' ) . '</a></span>' .
  123. '</div>';
  124. // Controls for additional options:
  125. $result .= '<div id="additional_options" style="display:none">' .
  126. $this->getOtherParametersBox() .
  127. '<fieldset><legend>' . wfMsg( 'smw_qc_formatopt' ) . "</legend>\n" .
  128. $formatBox[1] . // display the format options
  129. "</fieldset>\n" .
  130. '</div>'; // end of hidden additional options
  131. // Submit button and documentation link:
  132. $result .= '<br/><input type="submit" value="' . wfMsg( 'smw_ask_submit' ) . '"/><br/>' .
  133. '<a href="' . htmlspecialchars( wfMsg( 'smw_ask_doculink' ) ) . '">' .
  134. wfMsg( 'smw_ask_help' ) . '</a>';
  135. // Control for showing #ask syntax of query:
  136. if ( $this->uiCore->getQueryString() !== '' ) { // only show if query given
  137. $result .= ' | <a name="show-embed-code" id="show-embed-code" href="##" rel="nofollow">' .
  138. wfMsg( 'smw_ask_show_embed' ) . '</a>' .
  139. '<div id="embed-code-dialog">' . $this->getAskEmbedBox() . '</div>';
  140. SMWOutputs::requireResource( 'jquery.ui.autocomplete' );
  141. SMWOutputs::requireResource( 'jquery.ui.dialog' );
  142. SMWOutputs::requireResource( 'ext.smw.style' );
  143. $javascriptText = <<<EOT
  144. <script type="text/javascript">
  145. jQuery( document ).ready( function(){
  146. jQuery( '#embed-code-dialog' ).dialog( {
  147. autoOpen:false,
  148. modal: true,
  149. buttons: {
  150. Ok: function(){
  151. jQuery( this ).dialog( "close" );
  152. }
  153. }
  154. } );
  155. jQuery( '#show-embed-code' ).bind( 'click', function(){
  156. jQuery( '#embed-code-dialog' ).dialog( "open" );
  157. } );
  158. } );
  159. </script>
  160. EOT;
  161. SMWOutputs::requireScript( 'smwToggleAskSyntaxQC', $javascriptText );
  162. }
  163. $result .= '<input type="hidden" name="eq" value="no"/>' .
  164. "\n</form><br/>";
  165. return $result;
  166. }
  167. /**
  168. * Overridden to include form parameters.
  169. *
  170. * @return array of strings in the urlparamater=>value format
  171. */
  172. protected function getUrlArgs() {
  173. $tmpArray = array();
  174. $params = $this->uiCore->getParameters();
  175. foreach ( $params as $key => $value ) {
  176. if ( !in_array( $key, array( 'sort', 'order', 'limit', 'offset', 'title' ) ) ) {
  177. $tmpArray[$key] = $value;
  178. }
  179. }
  180. $this->setUrlArgs( $tmpArray );
  181. return $this->urlArgs;
  182. }
  183. /**
  184. * Creates controls for limit, intro, outro, default and offset
  185. *
  186. * @return string
  187. */
  188. protected function getOtherParametersBox() {
  189. $params = $this->uiCore->getParameters();
  190. if ( array_key_exists( 'limit', $params ) ) {
  191. $limit = $params['limit'];
  192. } else {
  193. $limit = '';
  194. }
  195. if ( array_key_exists( 'offset', $params ) ) {
  196. $offset = $params['offset'];
  197. } else {
  198. $offset = '';
  199. }
  200. if ( array_key_exists( 'intro', $params ) ) {
  201. $intro = $params['intro'];
  202. } else {
  203. $intro = '';
  204. }
  205. if ( array_key_exists( 'outro', $params ) ) {
  206. $outro = $params['outro'];
  207. } else {
  208. $outro = '';
  209. }
  210. if ( array_key_exists( 'default', $params ) ) {
  211. $default = $params['default'];
  212. } else {
  213. $default = '';
  214. }
  215. $result = '<fieldset><legend>' . wfMsg( 'smw_ask_otheroptions' ) . "</legend>\n" .
  216. Html::rawElement( 'div',
  217. array( 'style' => 'width: 30%; min-width:220px; margin:5px; padding: 1px; float: left;' ),
  218. wfMsg( 'smw_qc_intro' ) .
  219. '<input name="p[intro]" value="' . $intro . '" style="width:220px;"/> <br/>' .
  220. wfMsg( 'smw_paramdesc_intro' )
  221. ) .
  222. Html::rawElement( 'div',
  223. array( 'style' => 'width: 30%; min-width:220px; margin:5px; padding: 1px; float: left;' ),
  224. wfMsg( 'smw_qc_outro' ) .
  225. '<input name="p[outro]" value="' . $outro . '" style="width:220px;"/> <br/>' .
  226. wfMsg( 'smw_paramdesc_outro' )
  227. ) .
  228. Html::rawElement( 'div',
  229. array( 'style' => 'width: 30%; min-width:220px; margin:5px; padding: 1px; float: left;' ),
  230. wfMsg( 'smw_qc_default' ) .
  231. '<input name="p[default]" value="' . $default . '" style="width:220px;" /> <br/>' .
  232. wfMsg( 'smw_paramdesc_default' )
  233. ) .
  234. Html::hidden( 'p[limit]', $limit ) .
  235. Html::hidden( 'p[offset]', $offset ) .
  236. '</fieldset>';
  237. return $result;
  238. }
  239. }