Index: trunk/extensions/SemanticForms/includes/SF_GlobalFunctions.php |
— | — | @@ -13,7 +13,7 @@ |
14 | 14 | */ |
15 | 15 | if ( !defined( 'MEDIAWIKI' ) ) die(); |
16 | 16 | |
17 | | -define('SF_VERSION','1.2.4'); |
| 17 | +define('SF_VERSION','1.2.5'); |
18 | 18 | |
19 | 19 | // constants for special properties |
20 | 20 | define('SF_SP_HAS_DEFAULT_FORM', 1); |
— | — | @@ -297,43 +297,6 @@ |
298 | 298 | * (which should be a category, relation, or namespace page) |
299 | 299 | */ |
300 | 300 | 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) { |
338 | 301 | if ($page_title == NULL) |
339 | 302 | return null; |
340 | 303 | |
— | — | @@ -377,40 +340,6 @@ |
378 | 341 | * (which, for now, should always be a relation) |
379 | 342 | */ |
380 | 343 | 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) { |
415 | 344 | if ($page_title == NULL) |
416 | 345 | return null; |
417 | 346 | |
— | — | @@ -469,31 +398,13 @@ |
470 | 399 | * red-linked) page |
471 | 400 | */ |
472 | 401 | 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); |
479 | 403 | if ($link != '') |
480 | 404 | $u = $link; |
481 | 405 | return true; |
482 | 406 | } |
483 | 407 | |
484 | | -/* |
485 | | - * Legacy function, for use with the old MediaWiki patch |
486 | | - */ |
487 | 408 | 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) { |
498 | 409 | // get all properties pointing to this page, and if |
499 | 410 | // sffGetAddDataLinkForPage() returns a value with any of |
500 | 411 | // them, return that |
— | — | @@ -522,37 +433,6 @@ |
523 | 434 | return null; |
524 | 435 | } |
525 | 436 | |
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 | | - |
557 | 437 | /** |
558 | 438 | * Helper function - gets names of categories for a page; |
559 | 439 | * based on Title::getParentCategories(), but simpler |
— | — | @@ -649,10 +529,10 @@ |
650 | 530 | ); |
651 | 531 | } |
652 | 532 | |
653 | | -function sffGetAllPagesForProperty_0_7($is_relation, $property_name, $substring = null) { |
| 533 | +function sffGetAllPagesForProperty_orig($is_relation, $property_name, $substring = null) { |
654 | 534 | global $sfgMaxAutocompleteValues; |
655 | 535 | |
656 | | - $fname = "sffGetAllPagesForProperty_0_7"; |
| 536 | + $fname = "sffGetAllPagesForProperty_orig"; |
657 | 537 | $pages = array(); |
658 | 538 | $db = wfGetDB( DB_SLAVE ); |
659 | 539 | $sql_options = array(); |
— | — | @@ -690,7 +570,7 @@ |
691 | 571 | $requestoptions = new SMWRequestOptions(); |
692 | 572 | $requestoptions->limit = $sfgMaxAutocompleteValues; |
693 | 573 | if ($substring != null) { |
694 | | - $requestoptions->addStringCondition($substring, SMW_STRCOND_PRE); |
| 574 | + $requestoptions->addStringCondition($substring, SMWStringCondition::STRCOND_PRE); |
695 | 575 | } |
696 | 576 | $property = Title::newFromText($property_name, SMW_NS_PROPERTY); |
697 | 577 | $data_values = $store->getPropertyValues(null, $property, $requestoptions); |
— | — | @@ -707,7 +587,7 @@ |
708 | 588 | if ($substring != null) { |
709 | 589 | $requestoptions2 = new SMWRequestOptions(); |
710 | 590 | $requestoptions2->limit = $sfgMaxAutocompleteValues; |
711 | | - $requestoptions2->addStringCondition(" $substring", SMW_STRCOND_MID); |
| 591 | + $requestoptions2->addStringCondition(" $substring", SMWStringCondition::STRCOND_MID); |
712 | 592 | $data_values = $store->getPropertyValues(null, $property, $requestoptions2); |
713 | 593 | foreach ($data_values as $dv) { |
714 | 594 | $pages[] = $dv->getXSDValue(); |