r46855 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46854‎ | r46855 | r46856 >
Date:17:14, 5 February 2009
Author:yaron
Status:deferred
Tags:
Comment:
Added handling of "backup" special properties, cosmetic improvements
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_LinkUtils.inc (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_LinkUtils.inc
@@ -42,7 +42,8 @@
4343 }
4444
4545 /**
46 - * A very similar function, to get the non-URL-encoded title string
 46+ * A very similar function to titleURLString(), to get the
 47+ * non-URL-encoded title string
4748 */
4849 static function titleString($title) {
4950 $namespace = $title->getNsText();
@@ -62,15 +63,21 @@
6364
6465 global $sfgContLang;
6566 $store = smwfGetStore();
66 - $title = Title::newFromText($page_title, $page_namespace);
 67+ $title = Title::makeTitleSafe($page_namespace, $page_title);
6768 // we can do this easily if we're using SMW 1.4 or higher
6869 if (class_exists('SMWPropertyValue')) {
6970 $default_form_property = SMWPropertyValue::makeProperty('_SF_DF');
7071 $res = $store->getPropertyValues($title, $default_form_property);
7172 if (isset($res[0]))
7273 return $res[0]->getTitle()->getText();
73 - else
74 - return null;
 74+ // if we're using a non-English language, check for the English string as well
 75+ if (! $sfgContLang instanceof SF_LanguageEn) {
 76+ $backup_default_form_property = SMWPropertyValue::makeProperty('_SF_DF_BACKUP');
 77+ $res = $store->getPropertyValues($title, $backup_default_form_property);
 78+ if (isset($res[0]))
 79+ return $res[0]->getTitle()->getText();
 80+ }
 81+ return null;
7582 }
7683
7784 // otherwise, it's a bit more complex
@@ -114,15 +121,21 @@
115122
116123 global $sfgContLang;
117124 $store = smwfGetStore();
118 - $title = Title::newFromText($page_title, $page_namespace);
 125+ $title = Title::makeTitleSafe($page_namespace, $page_title);
119126 // we can do this easily if we're using SMW 1.4 or higher
120127 if (class_exists('SMWPropertyValue')) {
121128 $alternate_form_property = SMWPropertyValue::makeProperty('_SF_AF');
122129 $res = $store->getPropertyValues($title, $alternate_form_property);
123130 // there could be multiple alternate forms
124131 $form_names = array();
125 - foreach ($res as $wiki_page_value) {
 132+ foreach ($res as $wiki_page_value)
126133 $form_names[] = $wiki_page_value->getTitle()->getText();
 134+ // if we're using a non-English language, check for the English string as well
 135+ if (! $sfgContLang instanceof SF_LanguageEn) {
 136+ $backup_alternate_form_property = SMWPropertyValue::makeProperty('_SF_AF_BACKUP');
 137+ $res = $store->getPropertyValues($title, $backup_alternate_form_property);
 138+ foreach ($res as $wiki_page_value)
 139+ $form_names[] = $wiki_page_value->getTitle()->getText();
127140 }
128141 return $form_names;
129142 }
@@ -160,15 +173,15 @@
161174 * corresponding 'add data' link, if any such properties are defined
162175 */
163176 static function getAddDataLinkForPage($target_page_title, $page_title, $page_namespace) {
164 - $form_name = SFLinkUtils::getDefaultForm($page_title, $page_namespace);
165 - $alt_forms = SFLinkUtils::getAlternateForms($page_title, $page_namespace);
 177+ $form_name = self::getDefaultForm($page_title, $page_namespace);
 178+ $alt_forms = self::getAlternateForms($page_title, $page_namespace);
166179 if (! $form_name && count($alt_forms) == 0)
167180 return null;
168181 $ad = SpecialPage::getPage('AddData');
169182 if ($form_name)
170 - $add_data_url = $ad->getTitle()->getLocalURL() . "/" . $form_name . "/" . SFLinkUtils::titleURLString($target_page_title);
 183+ $add_data_url = $ad->getTitle()->getLocalURL() . "/" . $form_name . "/" . self::titleURLString($target_page_title);
171184 else
172 - $add_data_url = $ad->getTitle()->getLocalURL() . "/" . SFLinkUtils::titleURLString($target_page_title);
 185+ $add_data_url = $ad->getTitle()->getLocalURL() . "/" . self::titleURLString($target_page_title);
173186 foreach ($alt_forms as $i => $alt_form) {
174187 $add_data_url .= (strpos($add_data_url, "?")) ? "&" : "?";
175188 $add_data_url .= "alt_form[$i]=$alt_form";
@@ -178,10 +191,10 @@
179192
180193 /**
181194 * Sets the URL for form-based adding of a nonexistent (broken-linked,
182 - * AKA red-linked) page
 195+ * AKA red-linked) page, for MediaWiki 1.13
183196 */
184197 static function setBrokenLink_1_13(&$linker, $title, $query, &$u, &$style, &$prefix, &$text, &$inside, &$trail) {
185 - $link = SFLinkUtils::addDataLink($title);
 198+ $link = self::addDataLink($title);
186199 if ($link != '')
187200 $u = $link;
188201 return true;
@@ -193,7 +206,7 @@
194207 */
195208 static function setBrokenLink($linker, $target, $options, $text, &$attribs, &$ret) {
196209 if (in_array('broken', $options)) {
197 - $link = SFLinkUtils::addDataLink($target);
 210+ $link = self::addDataLink($target);
198211 if ($link != '') {
199212 $attribs['href'] = $link;
200213 }
@@ -206,12 +219,12 @@
207220 // getAddDataLinkForPage() returns a value with any of
208221 // them, return that
209222 $store = smwfGetStore();
210 - $title_text = SFLinkUtils::titleString($title);
 223+ $title_text = self::titleString($title);
211224 $value = SMWDataValueFactory::newTypeIDValue('_wpg', $title_text);
212225 $incoming_properties = $store->getInProperties($value);
213226 foreach ($incoming_properties as $property) {
214227 $property_title = SFUtils::getPropertyName($property);
215 - if ($add_data_link = SFLinkUtils::getAddDataLinkForPage($title, $property_title, SMW_NS_PROPERTY)) {
 228+ if ($add_data_link = self::getAddDataLinkForPage($title, $property_title, SMW_NS_PROPERTY)) {
216229 return $add_data_link;
217230 }
218231 }
@@ -225,7 +238,7 @@
226239 wfLoadExtensionMessages('SemanticForms');
227240 $namespace = wfMsgForContent('sf_blank_namespace');
228241 }
229 - if ($add_data_link = SFLinkUtils::getAddDataLinkForPage($title, $namespace, NS_PROJECT)) {
 242+ if ($add_data_link = self::getAddDataLinkForPage($title, $namespace, NS_PROJECT)) {
230243 return $add_data_link;
231244 }
232245 // if nothing found still, return null
@@ -260,13 +273,13 @@
261274
262275 /**
263276 * Get the form used to edit this article: either the default form for
264 - * a category that this article belongs to (if there is one), or the
 277+ * a category that this article belongs to, if there is one, or the
265278 * default form for the article's namespace, if there is one
266279 */
267280 static function getFormForArticle($obj) {
268 - $categories = SFLinkUtils::getCategoriesForArticle($obj);
 281+ $categories = self::getCategoriesForArticle($obj);
269282 foreach ($categories as $category) {
270 - if ($form_name = SFLinkUtils::getDefaultForm($category, NS_CATEGORY)) {
 283+ if ($form_name = self::getDefaultForm($category, NS_CATEGORY)) {
271284 return $form_name;
272285 }
273286 }
@@ -279,7 +292,7 @@
280293 wfLoadExtensionMessages('SemanticForms');
281294 $namespace = wfMsgForContent('sf_blank_namespace');
282295 }
283 - return SFLinkUtils::getDefaultForm($namespace, NS_PROJECT);
 296+ return self::getDefaultForm($namespace, NS_PROJECT);
284297 }
285298
286299 }

Status & tagging log