Skip to content

Instantly share code, notes, and snippets.

@Fannon
Last active May 11, 2016 14:48
Show Gist options
  • Save Fannon/031d4c51e91dccd74aa34648c9c44aea to your computer and use it in GitHub Desktop.
Save Fannon/031d4c51e91dccd74aa34648c9c44aea to your computer and use it in GitHub Desktop.
Index: SemanticForms.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- SemanticForms.php (revision 8a4dad116c93e0b47b1452d903520fb3cbd7d41d)
+++ SemanticForms.php (revision )
@@ -473,6 +473,12 @@
$GLOBALS['sfgAutocompleteOnAllChars'] = false;
# ##
+# If enabled, SF will additionally use the display title for autocompletion
+# By default, only the page title is searched
+# ##
+$GLOBALS['sfgAutocompleteOnDisplayTitle'] = false;
+
+# ##
# Used for caching of autocompletion values.
# ##
$GLOBALS['sfgCacheAutocompleteValues'] = false;
Index: includes/SF_Utils.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- includes/SF_Utils.php (revision 8a4dad116c93e0b47b1452d903520fb3cbd7d41d)
+++ includes/SF_Utils.php (revision )
@@ -406,7 +406,7 @@
/**
* Returns an array of all form names on this wiki.
- */
+ */
public static function getAllForms() {
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select( 'page',
@@ -506,6 +506,7 @@
public static function getAllPagesForCategory( $top_category, $num_levels, $substring = null ) {
if ( 0 == $num_levels ) return $top_category;
global $sfgMaxAutocompleteValues;
+ global $sfgAutocompleteOnDisplayTitle;
$db = wfGetDB( DB_SLAVE );
$top_category = str_replace( ' ', '_', $top_category );
@@ -518,12 +519,30 @@
$conditions = array();
$conditions[] = 'cl_from = page_id';
$conditions['cl_to'] = $category;
+ if ($sfgAutocompleteOnDisplayTitle) {
+ $conditions[] = 'cl_from = pp_page';
+ }
if ( $substring != null ) {
- $conditions[] = self::getSQLConditionForAutocompleteInColumn( 'page_title', $substring ) . ' OR page_namespace = ' . NS_CATEGORY;
+ $substringCondition = self::getSQLConditionForAutocompleteInColumn( 'page_title', $substring ) . ' OR page_namespace = ' . NS_CATEGORY;
+ if ( $sfgAutocompleteOnDisplayTitle ) {
+ // $substringCondition .= " OR pp_value LIKE CAST('%$substring%' as CHAR(256))";
+ $substringCondition .= " OR pp_value LIKE '%$substring%'";
- }
+ }
+ $conditions[] = $substringCondition;
+
+ }
+ $selectTables = array( 'categorylinks', 'page' );
+ $selectColumns = array( 'page_title', 'page_namespace');
+
+
+ if ($sfgAutocompleteOnDisplayTitle) {
+ $selectTables[] = 'page_props';
+ $selectColumns[] = 'pp_value';
+ }
+
$res = $db->select( // make the query
- array( 'categorylinks', 'page' ),
- array( 'page_title', 'page_namespace' ),
+ $selectTables,
+ $selectColumns,
$conditions,
__METHOD__,
'SORT BY cl_sortkey' );
@@ -532,6 +551,7 @@
if ( !array_key_exists( 'page_title', $row ) ) {
continue;
}
+
$page_namespace = $row['page_namespace'];
$page_name = $row[ 'page_title' ];
if ( $page_namespace == NS_CATEGORY ) {
@@ -795,7 +815,35 @@
return SFUtils::disambiguateLabels( $labels );
}
+ /**
+ * Helper function to get the display title from an array of values (page titles)
+ */
+ public static function getLabelsFromDisplayTitle($values) {
+ $labels = array();
+ foreach ( $values as $value ) {
+ $dbr = wfGetDB( DB_SLAVE );
+ $result = $dbr->select(
+ 'page_props',
+ array( 'pp_value' ),
+ array(
+ 'pp_page' => Title::newFromText($value)->getArticleID(),
+ 'pp_propname' => 'displaytitle'
+ ),
+ __METHOD__
+ );
+
+ if ( $result->numRows() > 0 ) {
+ $row = $result->fetchRow();
+ $labels[$value] = $row['pp_value'];
+ } else {
+ $labels[$value] = $value;
+ }
+ }
+ return SFUtils::disambiguateLabels( $labels );
+ }
+
+
/**
* Private function to disambiguate labels.
*/
@@ -1067,18 +1115,20 @@
}
/**
- * Returns a SQL condition for autocompletion substring value in a column.
- * @param string $value_column Value column name
- * @param string $substring Substring to look for
- * @return SQL condition for use in WHERE clause
- *
- * @author Ilmars Poikans
- * @author Yaron Koren
- */
+ * Returns a SQL condition for autocompletion substring value in a column.
+ * @param string $value_column Value column name
+ * @param string $substring Substring to look for
+ * @return SQL condition for use in WHERE clause
+ *
+ * @author Ilmars Poikans
+ * @author Yaron Koren
+ */
public static function getSQLConditionForAutocompleteInColumn( $column, $substring, $replaceSpaces = true ) {
global $sfgAutocompleteOnAllChars;
+ global $sfgAutocompleteOnDisplayTitle;
$column_value = "LOWER(CONVERT($column USING utf8))";
+
if ( $replaceSpaces ) {
$substring = str_replace( ' ', '_', strtolower( $substring ) );
}
@@ -1086,12 +1136,16 @@
$substring = str_replace( '_', '\_', $substring );
$substring = str_replace( '%', '\%', $substring );
+ $condition = '';
+
if ( $sfgAutocompleteOnAllChars ) {
- return "$column_value LIKE '%$substring%'";
+ $condition = "$column_value LIKE '%$substring%'";
} else {
$spaceRepresentation = $replaceSpaces ? '\_' : ' ';
- return "$column_value LIKE '$substring%' OR $column_value LIKE '%" . $spaceRepresentation . $substring . "%'";
+ $condition = "$column_value LIKE '$substring%' OR $column_value LIKE '%" . $spaceRepresentation . $substring . "%'";
}
+
+ return $condition;
}
/**
@@ -1144,7 +1198,7 @@
static function createFormLink( &$parser, $params, $parserFunctionName ) {
// Set defaults.
$inFormName = $inLinkStr = $inExistingPageLinkStr = $inLinkType =
- $inTooltip = $inQueryStr = $inTargetName = '';
+ $inTooltip = $inQueryStr = $inTargetName = '';
if ( $parserFunctionName == 'queryformlink' ) {
$inLinkStr = wfMessage( 'runquery' )->text();
}
@@ -1397,8 +1451,8 @@
// Support subpages only for talk pages by default
$wgNamespacesWithSubpages = $wgNamespacesWithSubpages + array(
- SF_NS_FORM_TALK => true
- );
+ SF_NS_FORM_TALK => true
+ );
return true;
}
Index: includes/SF_FormField.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- includes/SF_FormField.php (revision 8a4dad116c93e0b47b1452d903520fb3cbd7d41d)
+++ includes/SF_FormField.php (revision )
@@ -332,7 +332,7 @@
}
// If we're using Cargo, there's no equivalent for "values from
- // property" - instead, we just always get the values if a
+ // property" - instead, we just always get the values if a
// field and table have been specified.
if ( is_null( $f->mPossibleValues ) && defined( 'CARGO_VERSION' ) && $cargo_table != null && $cargo_field != null ) {
// We only want the non-null values. Ideally this could
@@ -353,6 +353,8 @@
} elseif ( array_key_exists( 'mapping cargo table', $f->mFieldArgs ) &&
array_key_exists( 'mapping cargo field', $f->mFieldArgs ) ) {
$f->mPossibleValues = SFUtils::getLabelsFromCargoField( $f->mPossibleValues, $f->mFieldArgs['mapping cargo table'], $f->mFieldArgs['mapping cargo field'] );
+ } elseif ( array_key_exists( 'mapping display title', $f->mFieldArgs ) ) {
+ $f->mPossibleValues = SFUtils::getLabelsFromDisplayTitle( $f->mPossibleValues);
}
}
// Backwards compatibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment