r36733 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36732‎ | r36733 | r36734 >
Date:13:08, 27 June 2008
Author:yaron
Status:old
Tags:
Comment:
Removed most "0_7" (SMW-0.7-compatible) versions of functions, except for
sffGetAllPagesForProperty_0_7(), which was renamed sffGetAllPagesForProperty_orig();
replaced "SMW_STRCOND" constants with new constants
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_GlobalFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_GlobalFunctions.php
@@ -13,7 +13,7 @@
1414 */
1515 if ( !defined( 'MEDIAWIKI' ) ) die();
1616
17 -define('SF_VERSION','1.2.4');
 17+define('SF_VERSION','1.2.5');
1818
1919 // constants for special properties
2020 define('SF_SP_HAS_DEFAULT_FORM', 1);
@@ -297,43 +297,6 @@
298298 * (which should be a category, relation, or namespace page)
299299 */
300300 function sffGetDefaultForm($page_title, $page_namespace) {
301 - $smw_version = SMW_VERSION;
302 - if ($smw_version{0} == '0') {
303 - return sffGetDefaultForm_0_7($page_title, $page_namespace);
304 - } else {
305 - return sffGetDefaultForm_1_0($page_title, $page_namespace);
306 - }
307 -}
308 -
309 -// Version for SMW 0.7 and lower
310 -function sffGetDefaultForm_0_7($page_title, $page_namespace) {
311 - global $sfgContLang;
312 - $db = wfGetDB( DB_SLAVE );
313 - $sf_props = $sfgContLang->getSpecialPropertiesArray();
314 - $default_form_relation = str_replace(' ', '_', $sf_props[SF_SP_HAS_DEFAULT_FORM]);
315 - $sql = "SELECT DISTINCT object_title FROM {$db->tableName('smw_relations')} " .
316 - "WHERE subject_title = '" . $db->strencode($page_title) .
317 - "' AND subject_namespace = '" . $page_namespace .
318 - "' AND (relation_title = '" . $db->strencode($default_form_relation) . "'";
319 - // try aliases for SF_SP_HAS_DEFAULT_FORM, too
320 - foreach ($sfgContLang->getSpecialPropertyAliases() as $alias => $property) {
321 - if ($property == SF_SP_HAS_DEFAULT_FORM) {
322 - $sql .= " OR relation_title = '" . str_replace(' ', '_', $alias) . "'";
323 - }
324 - }
325 - $sql .= ") AND object_namespace = " . SF_NS_FORM;
326 - $res = $db->query( $sql );
327 - if ($db->numRows( $res ) > 0) {
328 - $row = $db->fetchRow($res);
329 - $form_name = $row[0];
330 - return $form_name;
331 - }
332 - $db->freeResult($res);
333 - return null;
334 -}
335 -
336 -// Version for SMW 1.0 and higher
337 -function sffGetDefaultForm_1_0($page_title, $page_namespace) {
338301 if ($page_title == NULL)
339302 return null;
340303
@@ -377,40 +340,6 @@
378341 * (which, for now, should always be a relation)
379342 */
380343 function sffGetAlternateForms($page_title, $page_namespace) {
381 - $smw_version = SMW_VERSION;
382 - if ($smw_version{0} == '0') {
383 - return sffGetAlternateForms_0_7($page_title, $page_namespace);
384 - } else {
385 - return sffGetAlternateForms_1_0($page_title, $page_namespace);
386 - }
387 -}
388 -
389 -// Version for SMW 0.7 and lower
390 -function sffGetAlternateForms_0_7($page_title, $page_namespace) {
391 - global $sfgContLang;
392 - $db = wfGetDB( DB_SLAVE );
393 - $sf_props = $sfgContLang->getSpecialPropertiesArray();
394 - $alternate_form_relation = str_replace(' ', '_', $sf_props[SF_SP_HAS_ALTERNATE_FORM]);
395 - $sql = "SELECT DISTINCT object_title FROM {$db->tableName('smw_relations')} " .
396 - "WHERE subject_title = '" . $db->strencode($page_title) .
397 - "' AND subject_namespace = '" . $page_namespace .
398 - "' AND (relation_title = '" . $db->strencode($alternate_form_relation);
399 - // try English version too, if this is in another language
400 - if ($alternate_form_relation != "Has_alternate_form") {
401 - $sql .= "' OR relation_title = 'Has_alternate_form";
402 - }
403 - $sql .= "') AND object_namespace = " . SF_NS_FORM;
404 - $res = $db->query( $sql );
405 - $form_names = array();
406 - while ($row = $db->fetchRow($res)) {
407 - $form_names[] = $row[0];
408 - }
409 - $db->freeResult($res);
410 - return $form_names;
411 -}
412 -
413 -// Version for SMW 1.0 and higher
414 -function sffGetAlternateForms_1_0($page_title, $page_namespace) {
415344 if ($page_title == NULL)
416345 return null;
417346
@@ -469,31 +398,13 @@
470399 * red-linked) page
471400 */
472401 function sffSetBrokenLink(&$linker, $title, $query, &$u, &$style, &$prefix, &$text, &$inside, &$trail) {
473 - $smw_version = SMW_VERSION;
474 - if ($smw_version{0} == '0') {
475 - $link = sffAddDataLink_0_7($title);
476 - } else {
477 - $link = sffAddDataLink_1_0($title);
478 - }
 402+ $link = sffAddDataLink($title);
479403 if ($link != '')
480404 $u = $link;
481405 return true;
482406 }
483407
484 -/*
485 - * Legacy function, for use with the old MediaWiki patch
486 - */
487408 function sffAddDataLink($title) {
488 - $smw_version = SMW_VERSION;
489 - if ($smw_version{0} == '0') {
490 - return sffAddDataLink_0_7($title);
491 - } else {
492 - return sffAddDataLink_1_0($title);
493 - }
494 -}
495 -
496 -// Version for SMW 1.0 and higher
497 -function sffAddDataLink_1_0($title) {
498409 // get all properties pointing to this page, and if
499410 // sffGetAddDataLinkForPage() returns a value with any of
500411 // them, return that
@@ -522,37 +433,6 @@
523434 return null;
524435 }
525436
526 -// Version for SMW 0.7 and lower
527 -function sffAddDataLink_0_7($title) {
528 - // get all relations that have this page as an object,
529 - // and see if any of them have a default form specified
530 - $db = wfGetDB( DB_SLAVE );
531 - $sql = "SELECT DISTINCT relation_title FROM {$db->tableName('smw_relations')} WHERE object_title = '" . $db->strencode($title->getDBkey()) . "' AND object_namespace = '" . $title->getNamespace() . "'";
532 - $res = $db->query( $sql );
533 - if ($db->numRows( $res ) > 0) {
534 - while ($row = $db->fetchRow($res)) {
535 - $relation = $row[0];
536 - if ($add_data_link = sffGetAddDataLinkForPage($title, $relation, SMW_NS_RELATION)) {
537 - return $add_data_link;
538 - }
539 - }
540 - }
541 - // if that didn't work, check if this page's namespace
542 - // has a default form specified
543 - $namespace = $title->getNsText();
544 - if ('' === $namespace) {
545 - // if it's in the main (blank) namespace, check for the file
546 - // named with the word for "Main" in this language
547 - $namespace = wfMsgForContent('sf_blank_namespace');
548 - }
549 - if ($add_data_link = sffGetAddDataLinkForPage($title, $namespace, NS_PROJECT)) {
550 - return $add_data_link;
551 - }
552 - // if nothing found still, return null
553 - return null;
554 -}
555 -
556 -
557437 /**
558438 * Helper function - gets names of categories for a page;
559439 * based on Title::getParentCategories(), but simpler
@@ -649,10 +529,10 @@
650530 );
651531 }
652532
653 -function sffGetAllPagesForProperty_0_7($is_relation, $property_name, $substring = null) {
 533+function sffGetAllPagesForProperty_orig($is_relation, $property_name, $substring = null) {
654534 global $sfgMaxAutocompleteValues;
655535
656 - $fname = "sffGetAllPagesForProperty_0_7";
 536+ $fname = "sffGetAllPagesForProperty_orig";
657537 $pages = array();
658538 $db = wfGetDB( DB_SLAVE );
659539 $sql_options = array();
@@ -690,7 +570,7 @@
691571 $requestoptions = new SMWRequestOptions();
692572 $requestoptions->limit = $sfgMaxAutocompleteValues;
693573 if ($substring != null) {
694 - $requestoptions->addStringCondition($substring, SMW_STRCOND_PRE);
 574+ $requestoptions->addStringCondition($substring, SMWStringCondition::STRCOND_PRE);
695575 }
696576 $property = Title::newFromText($property_name, SMW_NS_PROPERTY);
697577 $data_values = $store->getPropertyValues(null, $property, $requestoptions);
@@ -707,7 +587,7 @@
708588 if ($substring != null) {
709589 $requestoptions2 = new SMWRequestOptions();
710590 $requestoptions2->limit = $sfgMaxAutocompleteValues;
711 - $requestoptions2->addStringCondition(" $substring", SMW_STRCOND_MID);
 591+ $requestoptions2->addStringCondition(" $substring", SMWStringCondition::STRCOND_MID);
712592 $data_values = $store->getPropertyValues(null, $property, $requestoptions2);
713593 foreach ($data_values as $dv) {
714594 $pages[] = $dv->getXSDValue();

Status & tagging log