r53689 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53688‎ | r53689 | r53690 >
Date:18:00, 23 July 2009
Author:yaron
Status:deferred
Tags:
Comment:
Added createLinkedPage(), called by red-link hooks
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_LinkUtils.inc (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_LinkUtils.inc
@@ -198,6 +198,9 @@
199199 * AKA red-linked) page, for MediaWiki 1.13
200200 */
201201 static function setBrokenLink_1_13(&$linker, $title, $query, &$u, &$style, &$prefix, &$text, &$inside, &$trail) {
 202+ if (self::createLinkedPage($title)) {
 203+ return true;
 204+ }
202205 $link = self::addDataLink($title);
203206 if ($link != '')
204207 $u = $link;
@@ -210,6 +213,9 @@
211214 */
212215 static function setBrokenLink($linker, $target, $options, $text, &$attribs, &$ret) {
213216 if (in_array('broken', $options)) {
 217+ if (self::createLinkedPage($target)) {
 218+ return true;
 219+ }
214220 $link = self::addDataLink($target);
215221 if ($link != '') {
216222 $attribs['href'] = $link;
@@ -218,6 +224,43 @@
219225 return true;
220226 }
221227
 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+
222265 static function addDataLink($title) {
223266 // get all properties pointing to this page, and if
224267 // getAddDataLinkForPage() returns a value with any of

Status & tagging log