Index: trunk/extensions/SemanticForms/includes/SF_GlobalFunctions.php |
— | — | @@ -9,7 +9,7 @@ |
10 | 10 | |
11 | 11 | if ( !defined( 'MEDIAWIKI' ) ) die(); |
12 | 12 | |
13 | | -define('SF_VERSION','1.3.5'); |
| 13 | +define('SF_VERSION','1.3.6'); |
14 | 14 | |
15 | 15 | $wgExtensionCredits['specialpage'][]= array( |
16 | 16 | 'name' => 'Semantic Forms', |
— | — | @@ -32,6 +32,7 @@ |
33 | 33 | $wgHooks['BrokenLink'][] = 'sffSetBrokenLink_1_13'; |
34 | 34 | $wgHooks['LinkEnd'][] = 'sffSetBrokenLink'; |
35 | 35 | $wgHooks['UnknownAction'][] = 'sffEmbeddedEditForm'; |
| 36 | +$wgHooks['smwInitProperties'][] = 'sffInitProperties'; |
36 | 37 | |
37 | 38 | $wgAPIModules['sfautocomplete'] = 'SFAutocompleteAPI'; |
38 | 39 | |
— | — | @@ -186,6 +187,12 @@ |
187 | 188 | /***** other global helpers *****/ |
188 | 189 | /**********************************************/ |
189 | 190 | |
| 191 | +function sffInitProperties() { |
| 192 | + SMWPropertyValue::registerProperty('_SF_DF', '__spf', 'Has default form', true); |
| 193 | + SMWPropertyValue::registerProperty('_SF_AF', '__spf', 'Has alternate form', true); |
| 194 | + return true; |
| 195 | +} |
| 196 | + |
190 | 197 | /** |
191 | 198 | * Creates HTML linking to a wiki page |
192 | 199 | */ |
— | — | @@ -313,6 +320,20 @@ |
314 | 321 | global $sfgContLang; |
315 | 322 | $store = smwfGetStore(); |
316 | 323 | $title = Title::newFromText($page_title, $page_namespace); |
| 324 | + // we can do this easily if we're using SMW 1.4 or higher |
| 325 | + if (class_exists('SMWPropertyValue')) { |
| 326 | + $default_form_property = SMWPropertyValue::makeProperty('_SF_DF'); |
| 327 | + $res = $store->getPropertyValues($title, $default_form_property); |
| 328 | + // make sure it's in the form namespace |
| 329 | + if (isset($res[0]) && ($res[0]->getNamespace() == SF_NS_FORM)) { |
| 330 | + $form_name = $res[0]->getTitle()->getText(); |
| 331 | + return $form_name; |
| 332 | + } else { |
| 333 | + return null; |
| 334 | + } |
| 335 | + } |
| 336 | + |
| 337 | + // otherwise, it's a bit more complex |
317 | 338 | $sf_props = $sfgContLang->getSpecialPropertiesArray(); |
318 | 339 | $default_form_property = str_replace(' ', '_', $sf_props[SF_SP_HAS_DEFAULT_FORM]); |
319 | 340 | $property = sffCreateProperty($default_form_property); |
— | — | @@ -349,11 +370,27 @@ |
350 | 371 | */ |
351 | 372 | function sffGetAlternateForms($page_title, $page_namespace) { |
352 | 373 | if ($page_title == NULL) |
353 | | - return null; |
| 374 | + return array(); |
354 | 375 | |
355 | 376 | global $sfgContLang; |
356 | 377 | $store = smwfGetStore(); |
357 | 378 | $title = Title::newFromText($page_title, $page_namespace); |
| 379 | + // we can do this easily if we're using SMW 1.4 or higher |
| 380 | + if (class_exists('SMWPropertyValue')) { |
| 381 | + $alternate_form_property = SMWPropertyValue::makeProperty('_SF_AF'); |
| 382 | + $res = $store->getPropertyValues($title, $alternate_form_property); |
| 383 | + // there could be multiple alternate forms |
| 384 | + $form_names = array(); |
| 385 | + foreach ($res as $wiki_page_value) { |
| 386 | + // make sure it's in the form namespace |
| 387 | + if ($wiki_page_value->getNamespace() == SF_NS_FORM) { |
| 388 | + $form_names[] = $wiki_page_value->getTitle()->getText(); |
| 389 | + } |
| 390 | + } |
| 391 | + return $form_names; |
| 392 | + } |
| 393 | + |
| 394 | + // otherwise, it's a bit more complex |
358 | 395 | $sf_props = $sfgContLang->getSpecialPropertiesArray(); |
359 | 396 | $alternate_form_property = str_replace(' ', '_', $sf_props[SF_SP_HAS_ALTERNATE_FORM]); |
360 | 397 | $property = sffCreateProperty($alternate_form_property); |