Index: trunk/extensions/SemanticForms/includes/SF_LinkUtils.inc |
— | — | @@ -42,7 +42,8 @@ |
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
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 |
47 | 48 | */ |
48 | 49 | static function titleString($title) { |
49 | 50 | $namespace = $title->getNsText(); |
— | — | @@ -62,15 +63,21 @@ |
63 | 64 | |
64 | 65 | global $sfgContLang; |
65 | 66 | $store = smwfGetStore(); |
66 | | - $title = Title::newFromText($page_title, $page_namespace); |
| 67 | + $title = Title::makeTitleSafe($page_namespace, $page_title); |
67 | 68 | // we can do this easily if we're using SMW 1.4 or higher |
68 | 69 | if (class_exists('SMWPropertyValue')) { |
69 | 70 | $default_form_property = SMWPropertyValue::makeProperty('_SF_DF'); |
70 | 71 | $res = $store->getPropertyValues($title, $default_form_property); |
71 | 72 | if (isset($res[0])) |
72 | 73 | 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; |
75 | 82 | } |
76 | 83 | |
77 | 84 | // otherwise, it's a bit more complex |
— | — | @@ -114,15 +121,21 @@ |
115 | 122 | |
116 | 123 | global $sfgContLang; |
117 | 124 | $store = smwfGetStore(); |
118 | | - $title = Title::newFromText($page_title, $page_namespace); |
| 125 | + $title = Title::makeTitleSafe($page_namespace, $page_title); |
119 | 126 | // we can do this easily if we're using SMW 1.4 or higher |
120 | 127 | if (class_exists('SMWPropertyValue')) { |
121 | 128 | $alternate_form_property = SMWPropertyValue::makeProperty('_SF_AF'); |
122 | 129 | $res = $store->getPropertyValues($title, $alternate_form_property); |
123 | 130 | // there could be multiple alternate forms |
124 | 131 | $form_names = array(); |
125 | | - foreach ($res as $wiki_page_value) { |
| 132 | + foreach ($res as $wiki_page_value) |
126 | 133 | $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(); |
127 | 140 | } |
128 | 141 | return $form_names; |
129 | 142 | } |
— | — | @@ -160,15 +173,15 @@ |
161 | 174 | * corresponding 'add data' link, if any such properties are defined |
162 | 175 | */ |
163 | 176 | 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); |
166 | 179 | if (! $form_name && count($alt_forms) == 0) |
167 | 180 | return null; |
168 | 181 | $ad = SpecialPage::getPage('AddData'); |
169 | 182 | 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); |
171 | 184 | 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); |
173 | 186 | foreach ($alt_forms as $i => $alt_form) { |
174 | 187 | $add_data_url .= (strpos($add_data_url, "?")) ? "&" : "?"; |
175 | 188 | $add_data_url .= "alt_form[$i]=$alt_form"; |
— | — | @@ -178,10 +191,10 @@ |
179 | 192 | |
180 | 193 | /** |
181 | 194 | * 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 |
183 | 196 | */ |
184 | 197 | static function setBrokenLink_1_13(&$linker, $title, $query, &$u, &$style, &$prefix, &$text, &$inside, &$trail) { |
185 | | - $link = SFLinkUtils::addDataLink($title); |
| 198 | + $link = self::addDataLink($title); |
186 | 199 | if ($link != '') |
187 | 200 | $u = $link; |
188 | 201 | return true; |
— | — | @@ -193,7 +206,7 @@ |
194 | 207 | */ |
195 | 208 | static function setBrokenLink($linker, $target, $options, $text, &$attribs, &$ret) { |
196 | 209 | if (in_array('broken', $options)) { |
197 | | - $link = SFLinkUtils::addDataLink($target); |
| 210 | + $link = self::addDataLink($target); |
198 | 211 | if ($link != '') { |
199 | 212 | $attribs['href'] = $link; |
200 | 213 | } |
— | — | @@ -206,12 +219,12 @@ |
207 | 220 | // getAddDataLinkForPage() returns a value with any of |
208 | 221 | // them, return that |
209 | 222 | $store = smwfGetStore(); |
210 | | - $title_text = SFLinkUtils::titleString($title); |
| 223 | + $title_text = self::titleString($title); |
211 | 224 | $value = SMWDataValueFactory::newTypeIDValue('_wpg', $title_text); |
212 | 225 | $incoming_properties = $store->getInProperties($value); |
213 | 226 | foreach ($incoming_properties as $property) { |
214 | 227 | $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)) { |
216 | 229 | return $add_data_link; |
217 | 230 | } |
218 | 231 | } |
— | — | @@ -225,7 +238,7 @@ |
226 | 239 | wfLoadExtensionMessages('SemanticForms'); |
227 | 240 | $namespace = wfMsgForContent('sf_blank_namespace'); |
228 | 241 | } |
229 | | - if ($add_data_link = SFLinkUtils::getAddDataLinkForPage($title, $namespace, NS_PROJECT)) { |
| 242 | + if ($add_data_link = self::getAddDataLinkForPage($title, $namespace, NS_PROJECT)) { |
230 | 243 | return $add_data_link; |
231 | 244 | } |
232 | 245 | // if nothing found still, return null |
— | — | @@ -260,13 +273,13 @@ |
261 | 274 | |
262 | 275 | /** |
263 | 276 | * 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 |
265 | 278 | * default form for the article's namespace, if there is one |
266 | 279 | */ |
267 | 280 | static function getFormForArticle($obj) { |
268 | | - $categories = SFLinkUtils::getCategoriesForArticle($obj); |
| 281 | + $categories = self::getCategoriesForArticle($obj); |
269 | 282 | foreach ($categories as $category) { |
270 | | - if ($form_name = SFLinkUtils::getDefaultForm($category, NS_CATEGORY)) { |
| 283 | + if ($form_name = self::getDefaultForm($category, NS_CATEGORY)) { |
271 | 284 | return $form_name; |
272 | 285 | } |
273 | 286 | } |
— | — | @@ -279,7 +292,7 @@ |
280 | 293 | wfLoadExtensionMessages('SemanticForms'); |
281 | 294 | $namespace = wfMsgForContent('sf_blank_namespace'); |
282 | 295 | } |
283 | | - return SFLinkUtils::getDefaultForm($namespace, NS_PROJECT); |
| 296 | + return self::getDefaultForm($namespace, NS_PROJECT); |
284 | 297 | } |
285 | 298 | |
286 | 299 | } |