Index: trunk/extensions/SemanticForms/specials/SF_FormStart.php |
— | — | @@ -1,27 +1,125 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * Displays a form for entering the title of a page, which then redirects |
5 | | - * to either the form for adding the page, or a form for editing it, |
6 | | - * depending on whether the page already exists. |
| 5 | + * to the form for creating/editing the page. |
7 | 6 | * |
8 | 7 | * @author Yaron Koren |
9 | 8 | * @author Jeffrey Stuckman |
10 | 9 | */ |
11 | 10 | if (!defined('MEDIAWIKI')) die(); |
12 | 11 | |
13 | | -class SFAddPage extends SpecialPage { |
| 12 | +class SFFormStart extends SpecialPage { |
14 | 13 | |
15 | 14 | /** |
16 | 15 | * Constructor |
17 | 16 | */ |
18 | | - function SFAddPage() { |
19 | | - SpecialPage::SpecialPage('AddPage'); |
| 17 | + function SFFormStart() { |
| 18 | + SpecialPage::SpecialPage('FormStart'); |
20 | 19 | wfLoadExtensionMessages('SemanticForms'); |
21 | 20 | } |
22 | 21 | |
23 | 22 | function execute($query) { |
| 23 | + global $wgOut, $wgRequest, $sfgScriptPath; |
| 24 | + |
24 | 25 | $this->setHeaders(); |
25 | | - doSpecialAddPage($query); |
| 26 | + |
| 27 | + wfLoadExtensionMessages('SemanticForms'); |
| 28 | + $form_name = $wgRequest->getVal('form'); |
| 29 | + $target_namespace = $wgRequest->getVal('namespace'); |
| 30 | + $super_page = $wgRequest->getVal('super_page'); |
| 31 | + $params = $wgRequest->getVal('params'); |
| 32 | + |
| 33 | + // if query string did not contain form name, try the URL |
| 34 | + if (! $form_name) { |
| 35 | + $queryparts = explode('/', $query, 2); |
| 36 | + $form_name = isset($queryparts[0]) ? $queryparts[0] : ''; |
| 37 | + // if a target was specified, it means we should |
| 38 | + // redirect to 'FormEdit' for this target page |
| 39 | + if (isset($queryparts[1])) { |
| 40 | + $target_name = $queryparts[1]; |
| 41 | + SFFormStart::doRedirect($form_name, $target_name, $params); |
| 42 | + } |
| 43 | + |
| 44 | + // get namespace from the URL, if it's there |
| 45 | + if ($namespace_label_loc = strpos($form_name, "/Namespace:")) { |
| 46 | + $target_namespace = substr($form_name, $namespace_label_loc + 11); |
| 47 | + $form_name = substr($form_name, 0, $namespace_label_loc); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + // remove forbidden characters from form name |
| 52 | + $forbidden_chars = array('"', "'", '<', '>', '{', '}', '(', ')', '[', ']', '='); |
| 53 | + $form_name = str_replace($forbidden_chars, "", $form_name); |
| 54 | + |
| 55 | + // get title of form |
| 56 | + $form_title = Title::makeTitleSafe(SF_NS_FORM, $form_name); |
| 57 | + |
| 58 | + // handle submission |
| 59 | + $form_submitted = $wgRequest->getCheck('page_name'); |
| 60 | + if ($form_submitted) { |
| 61 | + $page_name = $wgRequest->getVal('page_name'); |
| 62 | + // This form can be used to create a sub-page for an |
| 63 | + // existing page |
| 64 | + if ('' != $super_page) |
| 65 | + { |
| 66 | + $page_name = "$super_page/$page_name"; |
| 67 | + } |
| 68 | + if ('' != $page_name) { |
| 69 | + // Append the namespace prefix to the page name, |
| 70 | + // if a namespace was not already entered. |
| 71 | + if (strpos($page_name,":") === false && $target_namespace != '') |
| 72 | + $page_name = $target_namespace . ":" . $page_name; |
| 73 | + // find out whether this page already exists, |
| 74 | + // and send user to the appropriate form |
| 75 | + $page_title = Title::newFromText($page_name); |
| 76 | + if (! $page_title) { |
| 77 | + // if there was no page title, it's |
| 78 | + // probably an invalid page name, |
| 79 | + // containing forbidden characters |
| 80 | + $error_msg = wfMsg('sf_addpage_badtitle', $page_name); |
| 81 | + $wgOut->addHTML($error_msg); |
| 82 | + return; |
| 83 | + } else { |
| 84 | + SFFormStart::doRedirect($form_name, $page_name, $params); |
| 85 | + return; |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + if ((! $form_title || ! $form_title->exists()) && ($form_name != '')) { |
| 91 | + $text = '<p>' . wfMsg('sf_addpage_badform', SFUtils::linkText(SF_NS_FORM, $form_name)) . ".</p>\n"; |
| 92 | + } else { |
| 93 | + if ($form_name == '') |
| 94 | + $description = wfMsg('sf_addpage_noform_docu', $form_name); |
| 95 | + else |
| 96 | + $description = wfMsg('sf_addpage_docu', $form_name); |
| 97 | + $button_text = wfMsg('addoreditdata'); |
| 98 | + $text =<<<END |
| 99 | + <form action="" method="post"> |
| 100 | + <p>$description</p> |
| 101 | + <p><input type="text" size="40" name="page_name"> |
| 102 | + |
| 103 | +END; |
| 104 | + // if no form was specified, display a dropdown letting |
| 105 | + // the user choose the form |
| 106 | + if ($form_name == '') |
| 107 | + $text .= SFUtils::formDropdownHTML(); |
| 108 | + |
| 109 | + $hidden_target_namespace = htmlspecialchars($target_namespace); |
| 110 | + $hidden_super_page = htmlspecialchars($super_page); |
| 111 | + $hidden_params = htmlspecialchars($params); |
| 112 | + |
| 113 | + $text .=<<<END |
| 114 | + </p> |
| 115 | + <input type="hidden" name="namespace" value="$hidden_target_namespace"> |
| 116 | + <input type="hidden" name="super_page" value="$hidden_super_page"> |
| 117 | + <input type="hidden" name="params" value="$hidden_params"> |
| 118 | + <input type="Submit" value="$button_text"> |
| 119 | + </form> |
| 120 | + |
| 121 | +END; |
| 122 | + } |
| 123 | + $wgOut->addHTML($text); |
26 | 124 | } |
27 | 125 | |
28 | 126 | function doRedirect($form_name, $page_name, $params) { |
— | — | @@ -52,16 +150,15 @@ |
53 | 151 | if ($form_name == $default_form_name) { |
54 | 152 | $redirect_url = $page_title->getLocalURL('action=formedit'); |
55 | 153 | } else { |
56 | | - $ed = SpecialPage::getPage('EditData'); |
57 | | - $redirect_url = $ed->getTitle()->getFullURL() . "/" . $form_name . "/" . SFLinkUtils::titleURLString($page_title); |
| 154 | + $fe = SpecialPage::getPage('FormEdit'); |
| 155 | + $redirect_url = $fe->getTitle()->getFullURL() . "/" . $form_name . "/" . SFLinkUtils::titleURLString($page_title); |
58 | 156 | } |
59 | 157 | } else { |
60 | | - $ad = SpecialPage::getPage('AddData'); |
61 | | - $redirect_url = $ad->getTitle()->getFullURL() . "/" . $form_name . "/" . SFLinkUtils::titleURLString($page_title); |
62 | | - // of all the request values, send on to |
63 | | - // 'AddData' only 'preload' and specific form |
64 | | - // fields - we can tell the latter because |
65 | | - // they show up as 'arrays' |
| 158 | + $fe = SpecialPage::getPage('FormEdit'); |
| 159 | + $redirect_url = $fe->getTitle()->getFullURL() . "/" . $form_name . "/" . SFLinkUtils::titleURLString($page_title); |
| 160 | + // of all the request values, send on to 'FormEdit' |
| 161 | + // only 'preload' and specific form fields - we can |
| 162 | + // tell the latter because they show up as arrays |
66 | 163 | foreach ($_REQUEST as $key => $val) { |
67 | 164 | if (is_array($val)) { |
68 | 165 | $template_name = $key; |
— | — | @@ -96,107 +193,5 @@ |
97 | 194 | $wgOut->addHTML($text); |
98 | 195 | return; |
99 | 196 | } |
100 | | -} |
101 | 197 | |
102 | | -function doSpecialAddPage($query = '') { |
103 | | - global $wgOut, $wgRequest, $sfgScriptPath; |
104 | | - |
105 | | - wfLoadExtensionMessages('SemanticForms'); |
106 | | - |
107 | | - $form_name = $wgRequest->getVal('form'); |
108 | | - $target_namespace = $wgRequest->getVal('namespace'); |
109 | | - $super_page = $wgRequest->getVal('super_page'); |
110 | | - $params = $wgRequest->getVal('params'); |
111 | | - |
112 | | - // if query string did not contain form name, try the URL |
113 | | - if (! $form_name) { |
114 | | - $queryparts = explode('/', $query, 2); |
115 | | - $form_name = isset($queryparts[0]) ? $queryparts[0] : ''; |
116 | | - // if a target was specified, it means we should redirect |
117 | | - // to either 'AddData' or 'EditData' for this target page |
118 | | - if (isset($queryparts[1])) { |
119 | | - $target_name = $queryparts[1]; |
120 | | - SFAddPage::doRedirect($form_name, $target_name, $params); |
121 | | - } |
122 | | - |
123 | | - // get namespace from the URL, if it's there |
124 | | - if ($namespace_label_loc = strpos($form_name, "/Namespace:")) { |
125 | | - $target_namespace = substr($form_name, $namespace_label_loc + 11); |
126 | | - $form_name = substr($form_name, 0, $namespace_label_loc); |
127 | | - } |
128 | | - } |
129 | | - |
130 | | - // remove forbidden characters from form name |
131 | | - $forbidden_chars = array('"', "'", '<', '>', '{', '}', '(', ')', '[', ']', '='); |
132 | | - $form_name = str_replace($forbidden_chars, "", $form_name); |
133 | | - |
134 | | - // get title of form |
135 | | - $form_title = Title::makeTitleSafe(SF_NS_FORM, $form_name); |
136 | | - |
137 | | - // handle submission |
138 | | - $form_submitted = $wgRequest->getCheck('page_name'); |
139 | | - if ($form_submitted) { |
140 | | - $page_name = $wgRequest->getVal('page_name'); |
141 | | - // This form can be used to create a sub-page for an |
142 | | - // existing page |
143 | | - if ('' != $super_page) |
144 | | - { |
145 | | - $page_name = "$super_page/$page_name"; |
146 | | - } |
147 | | - if ('' != $page_name) { |
148 | | - // Append the namespace prefix to the page name, |
149 | | - // if a namespace was not already entered. |
150 | | - if (strpos($page_name,":") === false && $target_namespace != '') |
151 | | - $page_name = $target_namespace . ":" . $page_name; |
152 | | - // find out whether this page already exists, |
153 | | - // and send user to the appropriate form |
154 | | - $page_title = Title::newFromText($page_name); |
155 | | - if (! $page_title) { |
156 | | - // if there was no page title, it's probably |
157 | | - // an invalid page name, containing forbidden |
158 | | - // characters |
159 | | - $error_msg = wfMsg('sf_addpage_badtitle', $page_name); |
160 | | - $wgOut->addHTML($error_msg); |
161 | | - return; |
162 | | - } else { |
163 | | - SFAddPage::doRedirect($form_name, $page_name, $params); |
164 | | - return; |
165 | | - } |
166 | | - } |
167 | | - } |
168 | | - |
169 | | - if ((! $form_title || ! $form_title->exists()) && ($form_name != '')) { |
170 | | - $text = '<p>' . wfMsg('sf_addpage_badform', SFUtils::linkText(SF_NS_FORM, $form_name)) . ".</p>\n"; |
171 | | - } else { |
172 | | - if ($form_name == '') |
173 | | - $description = wfMsg('sf_addpage_noform_docu', $form_name); |
174 | | - else |
175 | | - $description = wfMsg('sf_addpage_docu', $form_name); |
176 | | - $button_text = wfMsg('addoreditdata'); |
177 | | - $text =<<<END |
178 | | - <form action="" method="post"> |
179 | | - <p>$description</p> |
180 | | - <p><input type="text" size="40" name="page_name"> |
181 | | - |
182 | | -END; |
183 | | - // if no form was specified, display a dropdown letting |
184 | | - // the user choose the form |
185 | | - if ($form_name == '') |
186 | | - $text .= SFUtils::formDropdownHTML(); |
187 | | - |
188 | | - $hidden_target_namespace = htmlspecialchars($target_namespace); |
189 | | - $hidden_super_page = htmlspecialchars($super_page); |
190 | | - $hidden_params = htmlspecialchars($params); |
191 | | - |
192 | | - $text .=<<<END |
193 | | - </p> |
194 | | - <input type="hidden" name="namespace" value="$hidden_target_namespace"> |
195 | | - <input type="hidden" name="super_page" value="$hidden_super_page"> |
196 | | - <input type="hidden" name="params" value="$hidden_params"> |
197 | | - <input type="Submit" value="$button_text"> |
198 | | - </form> |
199 | | - |
200 | | -END; |
201 | | - } |
202 | | - $wgOut->addHTML($text); |
203 | 198 | } |