r41035 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41034‎ | r41035 | r41036 >
Date:16:38, 19 September 2008
Author:yaron
Status:old
Tags:
Comment:
Updated red-link handling for MediaWiki 1.14, now that 'BrokenLink' hook has
been replaced with 'LinkBegin' and 'LinkEnd' hooks
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');
 13+define('SF_VERSION','1.3.1');
1414
1515 $wgExtensionCredits['specialpage'][]= array(
1616 'name' => 'Semantic Forms',
@@ -27,7 +27,10 @@
2828 $wgExtensionFunctions[] = 'sfgParserFunctions';
2929
3030 $wgHooks['LanguageGetMagic'][] = 'sffLanguageGetMagic';
31 -$wgHooks['BrokenLink'][] = 'sffSetBrokenLink';
 31+// the 'BrokenLink' hook exists only in MediaWiki v1.13 - it was replaced
 32+// by 'LinkBegin' and 'LinkEnd'
 33+$wgHooks['BrokenLink'][] = 'sffSetBrokenLink_1_13';
 34+$wgHooks['LinkEnd'][] = 'sffSetBrokenLink';
3235 $wgHooks['UnknownAction'][] = 'sffEmbeddedEditForm';
3336
3437 $wgAPIModules['sfautocomplete'] = 'SFAutocompleteAPI';
@@ -335,7 +338,7 @@
336339 $form_names = array();
337340 foreach ($prop_vals as $prop_val) {
338341 // make sure it's in the form namespace
339 - if (($res[0] instanceof SMWWikiPageValue || $res[0] instanceof Title) &&
 342+ if (($prop_val instanceof SMWWikiPageValue || $prop_val instanceof Title) &&
340343 $prop_val->getNamespace() == SF_NS_FORM) {
341344 $form_names[] = str_replace(' ', '_', $prop_val->getTitle()->getText());
342345 }
@@ -345,7 +348,7 @@
346349 $property = Title::newFromText("Has_alternate_form", SMW_NS_PROPERTY);
347350 $prop_vals = $store->getPropertyValues($title, $property);
348351 foreach ($prop_vals as $prop_val) {
349 - if (($res[0] instanceof SMWWikiPageValue || $res[0] instanceof Title)
 352+ if (($prop_val instanceof SMWWikiPageValue || $prop_val instanceof Title)
350353 && $prop_val->getNamespace() == SF_NS_FORM) {
351354 $form_names[] = str_replace(' ', '_', $prop_val->getTitle()->getText());
352355 }
@@ -381,13 +384,27 @@
382385 * Sets the URL for form-based adding of a nonexistent (broken-linked, AKA
383386 * red-linked) page
384387 */
385 -function sffSetBrokenLink(&$linker, $title, $query, &$u, &$style, &$prefix, &$text, &$inside, &$trail) {
 388+function sffSetBrokenLink_1_13(&$linker, $title, $query, &$u, &$style, &$prefix, &$text, &$inside, &$trail) {
386389 $link = sffAddDataLink($title);
387390 if ($link != '')
388391 $u = $link;
389392 return true;
390393 }
391394
 395+/**
 396+ * Sets the URL for form-based adding of a nonexistent (broken-linked, AKA
 397+ * red-linked) page
 398+ */
 399+function sffSetBrokenLink($linker, $target, $options, $text, &$attribs, &$ret) {
 400+ if (in_array('broken', $options)) {
 401+ $link = sffAddDataLink($target);
 402+ if ($link != '') {
 403+ $attribs['href'] = $link;
 404+ }
 405+ }
 406+ return true;
 407+}
 408+
392409 function sffAddDataLink($title) {
393410 // get all properties pointing to this page, and if
394411 // sffGetAddDataLinkForPage() returns a value with any of

Status & tagging log