Index: trunk/extensions/SemanticForms/specials/SF_AddData.php |
— | — | @@ -52,19 +52,14 @@ |
53 | 53 | $wgOut->addHTML( "<p class='error'>" . wfMsg('sf_adddata_badurl') . '</p>'); |
54 | 54 | return; |
55 | 55 | } elseif ($target_name == '') { |
56 | | - if (count($alt_forms) > 0) { |
57 | | - // if there's just a target and list of alternate |
58 | | - // forms, but no main form, display just a list of |
59 | | - // links on the page |
60 | | - $target_name = $form_name; |
61 | | - $target_title = Title::newFromText($target_name); |
62 | | - $s = wfMsg('sf_adddata_title', "", $target_title->getPrefixedText()); |
63 | | - $wgOut->setPageTitle($s); |
64 | | - $text = '<p>' . wfMsg('sf_adddata_altformsonly') . ' '; |
65 | | - $text .= printAltFormsList($alt_forms, $target_name); |
66 | | - $text .= "</p>\n"; |
67 | | - $wgOut->addHTML($text); |
68 | | - return; |
| 56 | + // parse the form to see if it has a 'page name' value set |
| 57 | + $form_title = Title::newFromText($form_name, SF_NS_FORM); |
| 58 | + $form_article = new Article($form_title); |
| 59 | + $form_definition = $form_article->getContent(); |
| 60 | + $form_definition = StringUtils::delimiterReplace('<noinclude>', '</noinclude>', '', $form_definition); |
| 61 | + $matches; |
| 62 | + if (preg_match('/{{{info.*page name=([^\|}]*)/', $form_definition, $matches)) { |
| 63 | + $page_name_formula = str_replace('_', ' ', $matches[1]); |
69 | 64 | } else { |
70 | 65 | $wgOut->addWikiText( "<p class='error'>" . wfMsg('sf_adddata_badurl') . '</p>'); |
71 | 66 | return; |
— | — | @@ -72,17 +67,19 @@ |
73 | 68 | } |
74 | 69 | |
75 | 70 | $form_title = Title::newFromText($form_name, SF_NS_FORM); |
76 | | - $target_title = Title::newFromText($target_name); |
77 | 71 | |
78 | | - $s = wfMsg('sf_adddata_title', $form_title->getText(), $target_title->getPrefixedText()); |
79 | | - $wgOut->setPageTitle($s); |
| 72 | + if ($target_name != '') { |
| 73 | + $target_title = Title::newFromText($target_name); |
| 74 | + $s = wfMsg('sf_adddata_title', $form_title->getText(), $target_title->getPrefixedText()); |
| 75 | + $wgOut->setPageTitle($s); |
| 76 | + } |
80 | 77 | |
81 | 78 | // target_title should be null - we shouldn't be adding a page that |
82 | 79 | // already exists |
83 | 80 | if ($target_title && $target_title->exists()) { |
84 | 81 | $wgOut->addWikiText( "<p class='error'>" . wfMsg('articleexists') . '</p>'); |
85 | 82 | return; |
86 | | - } else { |
| 83 | + } elseif ($target_name != '') { |
87 | 84 | $page_title = str_replace('_', ' ', $target_name); |
88 | 85 | } |
89 | 86 | |
— | — | @@ -91,11 +88,11 @@ |
92 | 89 | $text = '<p>' . wfMsg('sf_adddata_badurl') . "</p>\n"; |
93 | 90 | else |
94 | 91 | $text = '<p>' . wfMsg('sf_addpage_badform', sffLinkText(SF_NS_FORM, $form_name)) . ".</p>\n"; |
95 | | - } elseif ($target_name == '') { |
| 92 | + } elseif ($target_name == '' && $page_name_formula == '') { |
96 | 93 | $text = '<p>' . wfMsg('sf_adddata_badurl') . "</p>\n"; |
97 | 94 | } else { |
98 | | - $formArticle = new Article($form_title); |
99 | | - $form_definition = $formArticle->getContent(); |
| 95 | + $form_article = new Article($form_title); |
| 96 | + $form_definition = $form_article->getContent(); |
100 | 97 | |
101 | 98 | $save_page = $wgRequest->getCheck('wpSave'); |
102 | 99 | $preview_page = $wgRequest->getCheck('wpPreview'); |
— | — | @@ -109,15 +106,39 @@ |
110 | 107 | $page_is_source = false; |
111 | 108 | $page_contents = null; |
112 | 109 | } |
113 | | - list ($form_text, $javascript_text, $data_text, $form_page_title) = |
114 | | - $sfgFormPrinter->formHTML($form_definition, $form_submitted, $page_is_source, $page_contents, $page_title); |
| 110 | + list ($form_text, $javascript_text, $data_text, $form_page_title, $generated_page_name) = |
| 111 | + $sfgFormPrinter->formHTML($form_definition, $form_submitted, $page_is_source, $page_contents, $page_title, $page_name_formula); |
115 | 112 | if ($form_submitted) { |
| 113 | + if ($page_name_formula != '') { |
| 114 | + // replace "unique number" tag with one that |
| 115 | + // won't get erased by the next line |
| 116 | + $target_name = preg_replace('/<unique number>/', '{num}', $generated_page_name, 1); |
| 117 | + // if any formula stuff is still in the name |
| 118 | + // after the parsing, just remove it |
| 119 | + $target_name = StringUtils::delimiterReplace('<', '>', '', $target_name); |
| 120 | + if (strpos($target_name, '{num}')) { |
| 121 | + // cycle through numbers for this tag |
| 122 | + // until we find one that gives a |
| 123 | + // nonexistent page title |
| 124 | + $title_number = 1; |
| 125 | + do { |
| 126 | + $target_title = Title::newFromText(str_replace('{num}', $title_number, $target_name)); |
| 127 | + $title_number++; |
| 128 | + } while ($target_title->exists()); |
| 129 | + } else { |
| 130 | + $target_title = Title::newFromText($target_name); |
| 131 | + } |
| 132 | + } |
116 | 133 | $text = sffPrintRedirectForm($target_title, $data_text, $wgRequest->getVal('wpSummary'), $save_page, $preview_page, $diff_page, $wgRequest->getCheck('wpMinoredit'), $wgRequest->getCheck('wpWatchthis')); |
117 | 134 | } else { |
118 | 135 | // override the default title for this page if |
119 | 136 | // a title was specified in the form |
120 | 137 | if ($form_page_title != NULL) { |
121 | | - $wgOut->setPageTitle("$form_page_title: {$target_title->getPrefixedText()}"); |
| 138 | + if ($target_name == '') { |
| 139 | + $wgOut->setPageTitle($form_page_title); |
| 140 | + } else { |
| 141 | + $wgOut->setPageTitle("$form_page_title: {$target_title->getPrefixedText()}"); |
| 142 | + } |
122 | 143 | } |
123 | 144 | $text = ""; |
124 | 145 | if (count($alt_forms) > 0) { |