r91836 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91835‎ | r91836 | r91837 >
Date:16:00, 10 July 2011
Author:devayon
Status:deferred (Comments)
Tags:
Comment:
added documentation, follow up to r91793
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php
@@ -91,6 +91,7 @@
9292 $this->autocompleteenabled = true;
9393 }
9494 }
 95+
9596 protected function makeResults( $p ) {
9697 /*
9798 * TODO: extract parameters from $p and decide:
@@ -245,17 +246,39 @@
246247 $result = "<br>Stub: The Form elements come here<br><br>";
247248 return $result;
248249 }
249 - protected function getQueryFormBox( $contents, $errors = "" ) {
 250+
 251+ /**
 252+ * A method which generates the form element(s) for the Query-string. Use its
 253+ * complement processQueryFormBox() to decode data sent through these elements.
 254+ * UI's may overload both to change form parameters.
 255+ *
 256+ * @param string $contents
 257+ * @param string $errors
 258+ * @return string
 259+ */
 260+ protected function getQueryFormBox( $content, $errors = "" ) {
250261 $result = "";
251 - $result = Html::element( 'textarea', array( 'name' => 'q', 'id' => 'querybox', 'rows' => '6' ), $contents );
 262+ $result = Html::element( 'textarea', array( 'name' => 'q', 'id' => 'querybox', 'rows' => '6' ), $content );
252263 // TODO:enable/disable on checking for errors; perhaps show error messages right below the box
253264 return $result;
254265 }
255266
256267 /**
257 - * A method which generates the form box for PrintOuts.
258 - * UIs may overload this to change the form parameter or the html elements.
 268+ * A method which decodes form data sent through form-elements generated by
 269+ * its complement, getQueryFormBox. UIs may overload both to change form parameters.
259270 *
 271+ * @param WebRequest $wgRequest
 272+ * @return string
 273+ */
 274+ protected function processQueryFormBox(WebRequest $wgRequest){
 275+ $query = $wgRequest->getVal('q');
 276+ return $query;
 277+ }
 278+
 279+ /**
 280+ * A method which generates the form element(s) for PrintOuts.
 281+ * Use its complement processPOFormBox() to decode data sent through these
 282+ * form elements. UIs may overload both to change the form parameter or the html elements.
260283 *
261284 * @global OutputPage $wgOut
262285 * @param string $content The content expected to appear in the box
@@ -311,6 +334,33 @@
312335 }
313336
314337 /**
 338+ * A method which decodes form data sent through form-elements generated by
 339+ * its complement, getPOFormBox. UIs may overload both to change form parameters.
 340+ *
 341+ * @param WebRequest $wgRequest
 342+ * @return array
 343+ */
 344+ protected function processPOFormBox(WebRequest $wgRequest){
 345+ $postring = $wgRequest->getText( 'po' );
 346+ $poarray=array();
 347+
 348+ if ( $postring != '' ) { // parameters from HTML input fields
 349+ $ps = explode( "\n", $postring ); // params separated by newlines here (compatible with text-input for printouts)
 350+
 351+ foreach ( $ps as $param ) { // add initial ? if omitted (all params considered as printouts)
 352+ $param = trim( $param );
 353+
 354+ if ( ( $param != '' ) && ( $param { 0 } != '?' ) ) {
 355+ $param = '?' . $param;
 356+ }
 357+
 358+ $poarray[] = $param;
 359+ }
 360+ }
 361+ return $poarray;
 362+ }
 363+
 364+ /**
315365 * A method which generates the url parameters based on passed parameters.
316366 * UI implementations need to overload this if they use different form parameters.
317367 *
@@ -337,9 +387,11 @@
338388 if ( array_key_exists( 'order', $params ) ) $urltail .= '&order=' . $params['order'];
339389 return $urltail;
340390 }
 391+
341392 protected function makeHtmlResult() {
342393 // STUB
343394 }
 395+
344396 /**
345397 * Display a form section showing the options for a given format,
346398 * based on the getParameters() value for that format's query printer.
@@ -411,8 +463,6 @@
412464 * Returns a Validator style Parameter definition.
413465 * SMW 1.5.x style definitions are converted.
414466 *
415 - * @since 1.6
416 - *
417467 * @param mixed $param
418468 *
419469 * @return Parameter
@@ -450,8 +500,6 @@
451501 /**
452502 * Get the HTML for a single parameter input.
453503 *
454 - * @since 1.6
455 - *
456504 * @param Parameter $parameter
457505 * @param mixed $currentValue
458506 *
@@ -470,11 +518,15 @@
471519
472520 /**
473521 * Creates form elements for choosing the result-format and their associated
474 - * format. Use in conjunction with handleFormatOptions() to supply format
475 - * options using ajax.
 522+ * format. Use in conjunction with processFormatOptions() to supply formats
 523+ * options using ajax. Also, use its complement processFormatSelectBox() to
 524+ * decode form data sent by these elements. UI's may overload these methods
 525+ * to change behaviour or form parameters.
 526+ *
 527+ * @param string $defaultformat The default format which remains selected in the form
476528 * @return string
477529 */
478 - protected function makeFormatSelectBox( $defaultformat = 'broadtable' ) {
 530+ protected function getFormatSelectBox( $defaultformat = 'broadtable' ) {
479531
480532 global $smwgResultFormats, $smwgJQueryIncluded, $wgOut;
481533
@@ -531,8 +583,6 @@
532584
533585 // BEGIN: add javascript for updating formating options by ajax
534586 global $wgOut;
535 - // $default_format_url = SpecialPage::getSafeTitleFor( 'Ask' )->getLocalURL( "showformatoptions=broadtable" );
536 - // $default_format_url .= '&params[title]=Special:Ask&params[offset]=0&params[limit]=20';
537587 $javascript = <<<END
538588 <script type="text/javascript">
539589 function updateOtherOptions(strURL) {
@@ -550,12 +600,42 @@
551601 }
552602
553603 /**
554 - * Returns form elements for a requested format. Use in conjunction with makeFormatSelectBox()
 604+ * A method which decodes form data sent through form-elements generated by
 605+ * its complement, getFormatSelectBox(). UIs may overload both to change form parameters.
 606+ *
 607+ * @param WebRequest $wgRequest
 608+ * @return array
 609+ */
 610+ protected function processFormatSelectBox(WebRequest $wgRequest){
 611+ $query_val = $wgRequest->getVal( 'p' );
 612+ if ( !empty( $query_val ) )
 613+ $params = SMWInfolink::decodeParameters( $query_val, false );
 614+ else {
 615+ $query_values = $wgRequest->getArray( 'p' );
 616+
 617+ if ( is_array( $query_values ) ) {
 618+ foreach ( $query_values as $key => $val ) {
 619+ if ( empty( $val ) ) unset( $query_values[$key] );
 620+ }
 621+ }
 622+
 623+ // p is used for any additional parameters in certain links.
 624+ $params = SMWInfolink::decodeParameters( $query_values, false );
 625+ }
 626+ return $query_values;
 627+ }
 628+
 629+ /**
 630+ * Generates form elements for a (web)requested format.
555631 *
 632+ * Required by getFormatSelectBox() to recieve form elements from the web.
 633+ * UIs may need to overload processFormatOptions(), getgetFormatSelectBox()
 634+ * and getFormatSelectBox() to change behavior.
 635+ *
556636 * @param WebRequest $wgRequest
557 - * @return boolean Returns true if formatoptions were requested and returned, else false
 637+ * @return boolean Returns true if format options were requested and returned, else false
558638 */
559 - protected function handleFormatOptions( $wgRequest ) {
 639+ protected function processFormatOptions( $wgRequest ) {
560640 global $wgOut;
561641 if ( $wgRequest->getCheck( 'showformatoptions' ) ) {
562642 // handle Ajax action
@@ -568,6 +648,12 @@
569649 return false;
570650 }
571651 }
 652+
 653+ /**
 654+ * Returns true if this page shows the navigationBar. Overload to change behavior.
 655+ *
 656+ * @return boolean
 657+ */
572658 protected function usesNavigationBar() {
573659 return true;
574660 }
@@ -577,6 +663,9 @@
578664 /**
579665 * This class helps to implement a Special Page for creating and executing queries.
580666 *
 667+ * It captures the primary activities of what a semantic search pages does:
 668+ * (take parameters, validate them and generate results, or errors, if any).
 669+ *
581670 * Query UIs may use this class and override methods to create a customised UI
582671 * interface.
583672 *

Follow-up revisions

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

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r91793added form boxesdevayon17:32, 9 July 2011

Comments

#Comment by Nikerabbit (talk | contribs)   17:03, 10 July 2011

Curly braces as string indexing are also deprected, use $param[0] instead :)

if ( ( $param != '' ) && ( $param { 0 } != '?' ) ) {