r43651 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r43650‎ | r43651 | r43652 >
Date:22:56, 17 November 2008
Author:yaron
Status:deferred
Tags:
Comment:
Added support for SMW 1.4
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.5');
 13+define('SF_VERSION','1.3.6');
1414
1515 $wgExtensionCredits['specialpage'][]= array(
1616 'name' => 'Semantic Forms',
@@ -32,6 +32,7 @@
3333 $wgHooks['BrokenLink'][] = 'sffSetBrokenLink_1_13';
3434 $wgHooks['LinkEnd'][] = 'sffSetBrokenLink';
3535 $wgHooks['UnknownAction'][] = 'sffEmbeddedEditForm';
 36+$wgHooks['smwInitProperties'][] = 'sffInitProperties';
3637
3738 $wgAPIModules['sfautocomplete'] = 'SFAutocompleteAPI';
3839
@@ -186,6 +187,12 @@
187188 /***** other global helpers *****/
188189 /**********************************************/
189190
 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+
190197 /**
191198 * Creates HTML linking to a wiki page
192199 */
@@ -313,6 +320,20 @@
314321 global $sfgContLang;
315322 $store = smwfGetStore();
316323 $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
317338 $sf_props = $sfgContLang->getSpecialPropertiesArray();
318339 $default_form_property = str_replace(' ', '_', $sf_props[SF_SP_HAS_DEFAULT_FORM]);
319340 $property = sffCreateProperty($default_form_property);
@@ -349,11 +370,27 @@
350371 */
351372 function sffGetAlternateForms($page_title, $page_namespace) {
352373 if ($page_title == NULL)
353 - return null;
 374+ return array();
354375
355376 global $sfgContLang;
356377 $store = smwfGetStore();
357378 $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
358395 $sf_props = $sfgContLang->getSpecialPropertiesArray();
359396 $alternate_form_property = str_replace(' ', '_', $sf_props[SF_SP_HAS_ALTERNATE_FORM]);
360397 $property = sffCreateProperty($alternate_form_property);

Status & tagging log