http://www.mediawiki.org/wiki/Special:Code/MediaWiki/91836
Revision: 91836 Author: devayon Date: 2011-07-10 16:00:26 +0000 (Sun, 10 Jul 2011) Log Message: ----------- added documentation, follow up to r91793 Modified Paths: -------------- trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php Modified: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php =================================================================== --- trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php 2011-07-10 15:29:25 UTC (rev 91835) +++ trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php 2011-07-10 16:00:26 UTC (rev 91836) @@ -91,6 +91,7 @@ $this->autocompleteenabled = true; } } + protected function makeResults( $p ) { /* * TODO: extract parameters from $p and decide: @@ -245,17 +246,39 @@ $result = "<br>Stub: The Form elements come here<br><br>"; return $result; } - protected function getQueryFormBox( $contents, $errors = "" ) { + + /** + * A method which generates the form element(s) for the Query-string. Use its + * complement processQueryFormBox() to decode data sent through these elements. + * UI's may overload both to change form parameters. + * + * @param string $contents + * @param string $errors + * @return string + */ + protected function getQueryFormBox( $content, $errors = "" ) { $result = ""; - $result = Html::element( 'textarea', array( 'name' => 'q', 'id' => 'querybox', 'rows' => '6' ), $contents ); + $result = Html::element( 'textarea', array( 'name' => 'q', 'id' => 'querybox', 'rows' => '6' ), $content ); // TODO:enable/disable on checking for errors; perhaps show error messages right below the box return $result; } /** - * A method which generates the form box for PrintOuts. - * UIs may overload this to change the form parameter or the html elements. + * A method which decodes form data sent through form-elements generated by + * its complement, getQueryFormBox. UIs may overload both to change form parameters. * + * @param WebRequest $wgRequest + * @return string + */ + protected function processQueryFormBox(WebRequest $wgRequest){ + $query = $wgRequest->getVal('q'); + return $query; + } + + /** + * A method which generates the form element(s) for PrintOuts. + * Use its complement processPOFormBox() to decode data sent through these + * form elements. UIs may overload both to change the form parameter or the html elements. * * @global OutputPage $wgOut * @param string $content The content expected to appear in the box @@ -311,6 +334,33 @@ } /** + * A method which decodes form data sent through form-elements generated by + * its complement, getPOFormBox. UIs may overload both to change form parameters. + * + * @param WebRequest $wgRequest + * @return array + */ + protected function processPOFormBox(WebRequest $wgRequest){ + $postring = $wgRequest->getText( 'po' ); + $poarray=array(); + + if ( $postring != '' ) { // parameters from HTML input fields + $ps = explode( "\n", $postring ); // params separated by newlines here (compatible with text-input for printouts) + + foreach ( $ps as $param ) { // add initial ? if omitted (all params considered as printouts) + $param = trim( $param ); + + if ( ( $param != '' ) && ( $param { 0 } != '?' ) ) { + $param = '?' . $param; + } + + $poarray[] = $param; + } + } + return $poarray; + } + + /** * A method which generates the url parameters based on passed parameters. * UI implementations need to overload this if they use different form parameters. * @@ -337,9 +387,11 @@ if ( array_key_exists( 'order', $params ) ) $urltail .= '&order=' . $params['order']; return $urltail; } + protected function makeHtmlResult() { // STUB } + /** * Display a form section showing the options for a given format, * based on the getParameters() value for that format's query printer. @@ -411,8 +463,6 @@ * Returns a Validator style Parameter definition. * SMW 1.5.x style definitions are converted. * - * @since 1.6 - * * @param mixed $param * * @return Parameter @@ -450,8 +500,6 @@ /** * Get the HTML for a single parameter input. * - * @since 1.6 - * * @param Parameter $parameter * @param mixed $currentValue * @@ -470,11 +518,15 @@ /** * Creates form elements for choosing the result-format and their associated - * format. Use in conjunction with handleFormatOptions() to supply format - * options using ajax. + * format. Use in conjunction with processFormatOptions() to supply formats + * options using ajax. Also, use its complement processFormatSelectBox() to + * decode form data sent by these elements. UI's may overload these methods + * to change behaviour or form parameters. + * + * @param string $defaultformat The default format which remains selected in the form * @return string */ - protected function makeFormatSelectBox( $defaultformat = 'broadtable' ) { + protected function getFormatSelectBox( $defaultformat = 'broadtable' ) { global $smwgResultFormats, $smwgJQueryIncluded, $wgOut; @@ -531,8 +583,6 @@ // BEGIN: add javascript for updating formating options by ajax global $wgOut; - // $default_format_url = SpecialPage::getSafeTitleFor( 'Ask' )->getLocalURL( "showformatoptions=broadtable" ); - // $default_format_url .= '¶ms[title]=Special:Ask¶ms[offset]=0¶ms[limit]=20'; $javascript = <<<END <script type="text/javascript"> function updateOtherOptions(strURL) { @@ -550,12 +600,42 @@ } /** - * Returns form elements for a requested format. Use in conjunction with makeFormatSelectBox() + * A method which decodes form data sent through form-elements generated by + * its complement, getFormatSelectBox(). UIs may overload both to change form parameters. + * + * @param WebRequest $wgRequest + * @return array + */ + protected function processFormatSelectBox(WebRequest $wgRequest){ + $query_val = $wgRequest->getVal( 'p' ); + if ( !empty( $query_val ) ) + $params = SMWInfolink::decodeParameters( $query_val, false ); + else { + $query_values = $wgRequest->getArray( 'p' ); + + if ( is_array( $query_values ) ) { + foreach ( $query_values as $key => $val ) { + if ( empty( $val ) ) unset( $query_values[$key] ); + } + } + + // p is used for any additional parameters in certain links. + $params = SMWInfolink::decodeParameters( $query_values, false ); + } + return $query_values; + } + + /** + * Generates form elements for a (web)requested format. * + * Required by getFormatSelectBox() to recieve form elements from the web. + * UIs may need to overload processFormatOptions(), getgetFormatSelectBox() + * and getFormatSelectBox() to change behavior. + * * @param WebRequest $wgRequest - * @return boolean Returns true if formatoptions were requested and returned, else false + * @return boolean Returns true if format options were requested and returned, else false */ - protected function handleFormatOptions( $wgRequest ) { + protected function processFormatOptions( $wgRequest ) { global $wgOut; if ( $wgRequest->getCheck( 'showformatoptions' ) ) { // handle Ajax action @@ -568,6 +648,12 @@ return false; } } + + /** + * Returns true if this page shows the navigationBar. Overload to change behavior. + * + * @return boolean + */ protected function usesNavigationBar() { return true; } @@ -577,6 +663,9 @@ /** * This class helps to implement a Special Page for creating and executing queries. * + * It captures the primary activities of what a semantic search pages does: + * (take parameters, validate them and generate results, or errors, if any). + * * Query UIs may use this class and override methods to create a customised UI * interface. * _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs