r88637 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88636‎ | r88637 | r88638 >
Date:13:38, 23 May 2011
Author:yaron
Status:deferred
Tags:
Comment:
Fixed getAllPagesForConcept() to work with a non-null substring (i.e., for remote autocompletion)
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_Utils.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_Utils.php
@@ -495,19 +495,18 @@
496496 static function getAllPagesForConcept( $concept_name, $substring = null ) {
497497 global $sfgMaxAutocompleteValues;
498498
499 - // TODO - substring isn't being handled. Is there a way to
500 - // include it through the API?
501499 $store = smwfGetStore();
502 -/*
503 - $requestoptions = new SMWRequestOptions();
504 - if ($substring != null) {
505 - $requestoptions->addStringCondition($substring, SMWStringCondition::STRCOND_PRE);
 500+
 501+ $concept = Title::makeTitleSafe( SMW_NS_CONCEPT, $concept_name );
 502+ if ( !is_null( $substring ) ) {
 503+ $substring = strtolower( $substring );
506504 }
507 -*/
508 - $concept = Title::makeTitleSafe( SMW_NS_CONCEPT, $concept_name );
509 - // escape if there's a problem
510 - if ( $concept == null )
 505+
 506+ // Escape if there's a problem.
 507+ if ( $concept == null ) {
511508 return array();
 509+ }
 510+
512511 $desc = new SMWConceptDescription( $concept );
513512 $printout = new SMWPrintRequest( SMWPrintRequest::PRINT_THIS, "" );
514513 $desc->addPrintRequest( $printout );
@@ -516,7 +515,20 @@
517516 $query_result = $store->getQueryResult( $query );
518517 $pages = array();
519518 while ( $res = $query_result->getNext() ) {
520 - $pages[] = $res[0]->getNextText( SMW_OUTPUT_WIKI );
 519+ $pageName = $res[0]->getNextText( SMW_OUTPUT_WIKI );
 520+ if ( is_null( $substring ) ) {
 521+ $pages[] = $pageName;
 522+ } else {
 523+ // Filter on the substring manually. It would
 524+ // be better to do this filtering in the
 525+ // original SMW query, but that doesn't seem
 526+ // possible yet.
 527+ $lowercasePageName = strtolower( $pageName );
 528+ if ( strpos( $lowercasePageName, $substring ) === 0 ||
 529+ strpos( $lowercasePageName, ' ' . $substring ) > 0 ) {
 530+ $pages[] = array( 'title' => $pageName );
 531+ }
 532+ }
521533 }
522534 sort( $pages );
523535 return $pages;