Index: trunk/extensions/SemanticForms/includes/SF_LinkUtils.inc |
— | — | @@ -198,6 +198,9 @@ |
199 | 199 | * AKA red-linked) page, for MediaWiki 1.13 |
200 | 200 | */ |
201 | 201 | static function setBrokenLink_1_13(&$linker, $title, $query, &$u, &$style, &$prefix, &$text, &$inside, &$trail) { |
| 202 | + if (self::createLinkedPage($title)) { |
| 203 | + return true; |
| 204 | + } |
202 | 205 | $link = self::addDataLink($title); |
203 | 206 | if ($link != '') |
204 | 207 | $u = $link; |
— | — | @@ -210,6 +213,9 @@ |
211 | 214 | */ |
212 | 215 | static function setBrokenLink($linker, $target, $options, $text, &$attribs, &$ret) { |
213 | 216 | if (in_array('broken', $options)) { |
| 217 | + if (self::createLinkedPage($target)) { |
| 218 | + return true; |
| 219 | + } |
214 | 220 | $link = self::addDataLink($target); |
215 | 221 | if ($link != '') { |
216 | 222 | $attribs['href'] = $link; |
— | — | @@ -218,6 +224,43 @@ |
219 | 225 | return true; |
220 | 226 | } |
221 | 227 | |
| 228 | + /** |
| 229 | + * Automatically creates a page that's red-linked from the page being |
| 230 | + * viewed, if there's a property pointing from anywhere to that page |
| 231 | + * that's defined with the 'Creates pages with form' special property |
| 232 | + */ |
| 233 | + static function createLinkedPage($title) { |
| 234 | + $store = smwfGetStore(); |
| 235 | + $title_text = self::titleString($title); |
| 236 | + $value = SMWDataValueFactory::newTypeIDValue('_wpg', $title_text); |
| 237 | + $create_pages_property = SMWPropertyValue::makeProperty('_SF_CP_BACKUP'); |
| 238 | + $incoming_properties = $store->getInProperties($value); |
| 239 | + foreach ($incoming_properties as $property) { |
| 240 | + $property_name = SFUtils::getPropertyName($property); |
| 241 | + $property_title = Title::makeTitleSafe(SMW_NS_PROPERTY, $property_name); |
| 242 | + $res = $store->getPropertyValues($property_title, $create_pages_property); |
| 243 | + if (count($res) > 0) { |
| 244 | + global $sfgFormPrinter; |
| 245 | + $form_name = $res[0]->getTitle()->getText(); |
| 246 | + $form_title = Title::makeTitleSafe(SF_NS_FORM, $form_name); |
| 247 | + $form_article = new Article($form_title); |
| 248 | + $form_definition = $form_article->getContent(); |
| 249 | + list ($form_text, $javascript_text, $data_text, $form_page_title, $generated_page_name) = |
| 250 | + $sfgFormPrinter->formHTML($form_definition, false, false, null, 'Some very long page name that will hopefully never get created ABCDEF123', null); |
| 251 | + $params = array(); |
| 252 | + global $wgUser; |
| 253 | + $params['user_id'] = $wgUser->getId(); |
| 254 | + $params['page_text'] = $data_text; |
| 255 | + $job = new SFCreatePageJob( $title, $params ); |
| 256 | + Job::batchInsert( array($job) ); |
| 257 | + |
| 258 | + return true; |
| 259 | + } |
| 260 | + } |
| 261 | + |
| 262 | + return false; |
| 263 | + } |
| 264 | + |
222 | 265 | static function addDataLink($title) { |
223 | 266 | // get all properties pointing to this page, and if |
224 | 267 | // getAddDataLinkForPage() returns a value with any of |