r41487 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41486‎ | r41487 | r41488 >
Date:15:31, 1 October 2008
Author:yaron
Status:old
Tags:
Comment:
Added loading image to form-redirect page, fixed some bugs in remote autocompletion
on property
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_GlobalFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_GlobalFunctions.php
@@ -9,7 +9,7 @@
1010
1111 if ( !defined( 'MEDIAWIKI' ) ) die();
1212
13 -define('SF_VERSION','1.3.2');
 13+define('SF_VERSION','1.3.3');
1414
1515 $wgExtensionCredits['specialpage'][]= array(
1616 'name' => 'Semantic Forms',
@@ -253,7 +253,9 @@
254254 else // $is_diff
255255 $action = "wpDiff";
256256
 257+ global $sfgScriptPath;
257258 $text =<<<END
 259+ <p style="position: absolute; left: 45%; top: 45%;"><img src="$sfgScriptPath/skins/loading.gif" /></p>
258260 <form id="editform" name="editform" method="post" action="$new_url">
259261 <input type="hidden" name="wpTextbox1" id="wpTextbox1" value="$page_contents" />
260262 <input type="hidden" name="wpSummary" value="$edit_summary" />
@@ -370,9 +372,9 @@
371373 return null;
372374 $ad = SpecialPage::getPage('AddData');
373375 if ($form_name)
374 - $add_data_url = $ad->getTitle()->getFullURL() . "/" . $form_name . "/" . sffTitleURLString($target_page_title);
 376+ $add_data_url = $ad->getTitle()->getLinkURL() . "/" . $form_name . "/" . sffTitleURLString($target_page_title);
375377 else
376 - $add_data_url = $ad->getTitle()->getFullURL() . "/" . sffTitleURLString($target_page_title);
 378+ $add_data_url = $ad->getTitle()->getLinkURL() . "/" . sffTitleURLString($target_page_title);
377379 foreach ($alt_forms as $i => $alt_form) {
378380 $add_data_url .= ($i == 0) ? "?" : "&";
379381 $add_data_url .= "alt_form[$i]=$alt_form";
@@ -578,11 +580,11 @@
579581 );
580582 }
581583
582 -function sffGetAllPagesForProperty_orig($is_relation, $property_name, $substring = null) {
 584+function sffGetAllValuesForProperty_orig($is_relation, $property_name, $substring = null) {
583585 global $sfgMaxAutocompleteValues;
584586
585 - $fname = "sffGetAllPagesForProperty_orig";
586 - $pages = array();
 587+ $fname = "sffGetAllValuesForProperty_orig";
 588+ $values = array();
587589 $db = wfGetDB( DB_SLAVE );
588590 $sql_options = array();
589591 $sql_options['LIMIT'] = $sfgMaxAutocompleteValues;
@@ -602,17 +604,17 @@
603605 $conditions, $fname, $sql_options);
604606 while ($row = $db->fetchRow($res)) {
605607 if ($substring != null) {
606 - $pages[] = array('title' => str_replace('_', ' ', $row[0]));
 608+ $values[] = array('title' => str_replace('_', ' ', $row[0]));
607609 } else {
608610 $cur_value = str_replace("'", "\'", $row[0]);
609 - $pages[] = str_replace('_', ' ', $cur_value);
 611+ $values[] = str_replace('_', ' ', $cur_value);
610612 }
611613 }
612614 $db->freeResult($res);
613 - return $pages;
 615+ return $values;
614616 }
615617
616 -function sffGetAllPagesForProperty_1_2($property_name, $substring = null) {
 618+function sffGetAllValuesForProperty_1_2($property_name, $substring = null) {
617619 global $sfgMaxAutocompleteValues;
618620
619621 $store = smwfGetStore();
@@ -623,18 +625,14 @@
624626 }
625627 $property = Title::newFromText($property_name, SMW_NS_PROPERTY);
626628 $data_values = $store->getPropertyValues(null, $property, $requestoptions);
627 - $pages = array();
 629+ $values = array();
628630 foreach ($data_values as $dv) {
629631 // getPropertyValues() gets many repeat values - we want
630632 // only one of each value
631633 $string_value = str_replace('_', ' ', $dv->getXSDValue());
632634 $string_value = str_replace("'", "\'", $string_value);
633 - if (array_search($string_value, $pages) === false)
634 - if ($substring != null)
635 - $pages[] = array('title' => str_replace('_', ' '
636 -, $string_value));
637 - else
638 - $pages[] = $string_value;
 635+ if (array_search($string_value, $values) === false)
 636+ $values[] = $string_value;
639637 }
640638 // if there was a substring specified, also find values that have
641639 // it after a space, not just at the beginning of the value
@@ -644,10 +642,23 @@
645643 $requestoptions2->addStringCondition(" $substring", SMWStringCondition::STRCOND_MID);
646644 $data_values = $store->getPropertyValues(null, $property, $requestoptions2);
647645 foreach ($data_values as $dv) {
648 - $pages[] = array('title' => str_replace('_', ' ', $dv->getXSDValue()));
 646+ $string_value = str_replace('_', ' ', $dv->getXSDValue());
 647+ if (array_search($string_value, $values) === false)
 648+ $values[] = $string_value;
649649 }
650650 }
651 - return $pages;
 651+ if ($substring == null)
 652+ return $values;
 653+ else {
 654+ $autocomplete_vals = array();
 655+ foreach ($values as $value) {
 656+ // if these values are being returned for remote
 657+ // autocompletion, undo the apostrophe-escaping
 658+ $value = str_replace("\'", "'", $value);
 659+ $autocomplete_vals[] = array('title' => $value);
 660+ }
 661+ return $autocomplete_vals;
 662+ }
652663 }
653664
654665 /*

Status & tagging log