http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88637
Revision: 88637
Author: yaron
Date: 2011-05-23 13:38:21 +0000 (Mon, 23 May 2011)
Log Message:
-----------
Fixed getAllPagesForConcept() to work with a non-null substring (i.e., for
remote autocompletion)
Modified Paths:
--------------
trunk/extensions/SemanticForms/includes/SF_Utils.php
Modified: trunk/extensions/SemanticForms/includes/SF_Utils.php
===================================================================
--- trunk/extensions/SemanticForms/includes/SF_Utils.php 2011-05-23
12:44:28 UTC (rev 88636)
+++ trunk/extensions/SemanticForms/includes/SF_Utils.php 2011-05-23
13:38:21 UTC (rev 88637)
@@ -495,19 +495,18 @@
static function getAllPagesForConcept( $concept_name, $substring = null
) {
global $sfgMaxAutocompleteValues;
- // TODO - substring isn't being handled. Is there a way to
- // include it through the API?
$store = smwfGetStore();
-/*
- $requestoptions = new SMWRequestOptions();
- if ($substring != null) {
- $requestoptions->addStringCondition($substring,
SMWStringCondition::STRCOND_PRE);
+
+ $concept = Title::makeTitleSafe( SMW_NS_CONCEPT, $concept_name
);
+ if ( !is_null( $substring ) ) {
+ $substring = strtolower( $substring );
}
-*/
- $concept = Title::makeTitleSafe( SMW_NS_CONCEPT, $concept_name
);
- // escape if there's a problem
- if ( $concept == null )
+
+ // Escape if there's a problem.
+ if ( $concept == null ) {
return array();
+ }
+
$desc = new SMWConceptDescription( $concept );
$printout = new SMWPrintRequest( SMWPrintRequest::PRINT_THIS,
"" );
$desc->addPrintRequest( $printout );
@@ -516,7 +515,20 @@
$query_result = $store->getQueryResult( $query );
$pages = array();
while ( $res = $query_result->getNext() ) {
- $pages[] = $res[0]->getNextText( SMW_OUTPUT_WIKI );
+ $pageName = $res[0]->getNextText( SMW_OUTPUT_WIKI );
+ if ( is_null( $substring ) ) {
+ $pages[] = $pageName;
+ } else {
+ // Filter on the substring manually. It would
+ // be better to do this filtering in the
+ // original SMW query, but that doesn't seem
+ // possible yet.
+ $lowercasePageName = strtolower( $pageName );
+ if ( strpos( $lowercasePageName, $substring )
=== 0 ||
+ strpos( $lowercasePageName, ' ' .
$substring ) > 0 ) {
+ $pages[] = array( 'title' =>
$pageName );
+ }
+ }
}
sort( $pages );
return $pages;
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs