Index: trunk/extensions/SpecialForm/SpecialForm.body.php |
— | — | @@ -38,7 +38,7 @@ |
39 | 39 | |
40 | 40 | # Must have a name, like Special:Form/Nameofform |
41 | 41 | # XXX: instead of an error, show a list of available forms |
42 | | - |
| 42 | + |
43 | 43 | if (!$par) { |
44 | 44 | $wgOut->showErrorPage('formnoname', 'formnonametext'); |
45 | 45 | return; |
— | — | @@ -63,7 +63,7 @@ |
64 | 64 | } |
65 | 65 | |
66 | 66 | # Load form-related messages, per special-page guidelines |
67 | | - |
| 67 | + |
68 | 68 | function loadMessages() { |
69 | 69 | static $messagesLoaded = false; |
70 | 70 | global $wgMessageCache; |
— | — | @@ -76,7 +76,7 @@ |
77 | 77 | } |
78 | 78 | |
79 | 79 | # Load and parse a form article from the DB |
80 | | - |
| 80 | + |
81 | 81 | function loadForm($name) { |
82 | 82 | $nt = Title::makeTitleSafe(NS_MEDIAWIKI, wfMsgForContent('formpattern', $name)); |
83 | 83 | |
— | — | @@ -93,7 +93,7 @@ |
94 | 94 | $text = $article->getContent(true); |
95 | 95 | |
96 | 96 | # Form constructor does the parsing |
97 | | - |
| 97 | + |
98 | 98 | return new Form($name, $text); |
99 | 99 | } |
100 | 100 | |
— | — | @@ -118,7 +118,7 @@ |
119 | 119 | wfCloseElement('div') . |
120 | 120 | wfElement('br')); |
121 | 121 | } |
122 | | - |
| 122 | + |
123 | 123 | $wgOut->addHtml(wfOpenElement('form', |
124 | 124 | array('method' => 'POST', |
125 | 125 | 'action' => $self->getLocalURL()))); |
— | — | @@ -132,7 +132,7 @@ |
133 | 133 | global $recaptcha_public_key; # same as used by Recaptcha plugin |
134 | 134 | $wgOut->addHtml(recaptcha_get_html($recaptcha_public_key)); |
135 | 135 | } |
136 | | - |
| 136 | + |
137 | 137 | $wgOut->addHtml(wfElement('input', array('type' => 'submit', |
138 | 138 | 'value' => wfMsg('formsave')))); |
139 | 139 | |
— | — | @@ -146,7 +146,7 @@ |
147 | 147 | # Check recaptcha |
148 | 148 | |
149 | 149 | if ($wgUser->getId() == 0 && $wgSpecialFormRecaptcha) { |
150 | | - |
| 150 | + |
151 | 151 | require_once('recaptchalib.php'); |
152 | 152 | global $recaptcha_private_key; # same as used by Recaptcha plugin |
153 | 153 | $resp = recaptcha_check_answer($recaptcha_private_key, |
— | — | @@ -159,11 +159,11 @@ |
160 | 160 | return; |
161 | 161 | } |
162 | 162 | } |
163 | | - |
| 163 | + |
164 | 164 | # Check for required fields |
165 | 165 | |
166 | 166 | $missedFields = array(); |
167 | | - |
| 167 | + |
168 | 168 | foreach ($form->fields as $name => $field) { |
169 | 169 | $value = $wgRequest->getText($name); |
170 | 170 | if ($field->isOptionTrue('required') && (is_null($value) || strlen($value) == 0)) { |
— | — | @@ -172,7 +172,7 @@ |
173 | 173 | } |
174 | 174 | |
175 | 175 | # On error, show the form again with some error text. |
176 | | - |
| 176 | + |
177 | 177 | if ($missedFields) { |
178 | 178 | if (count($missedFields) > 1) { |
179 | 179 | $msg = wfMsg('formrequiredfieldpluralerror', $wgLang->listToText($missedFields)); |
— | — | @@ -186,19 +186,19 @@ |
187 | 187 | # First, we make sure we have all the titles |
188 | 188 | |
189 | 189 | $nt = array(); |
190 | | - |
| 190 | + |
191 | 191 | for ($i = 0; $i < count($form->template); $i++) { |
192 | | - |
| 192 | + |
193 | 193 | $namePattern = $form->namePattern[$i]; |
194 | 194 | $template = $form->template[$i]; |
195 | 195 | |
196 | 196 | if (!$namePattern || !$template) { |
197 | | - $wgOut->showErrorPage('formindexmismatch', 'formindexmismatchtext', array($i)); |
| 197 | + $wgOut->showErrorPage('formindexmismatch-title', 'formindexmismatch', array($i)); |
198 | 198 | return; |
199 | 199 | } |
200 | 200 | |
201 | 201 | wfDebug("SpecialForm: for index '$i', namePattern = '$namePattern' and template = '$template'.\n"); |
202 | | - |
| 202 | + |
203 | 203 | $title = $this->makeTitle($form, $namePattern); |
204 | 204 | |
205 | 205 | $nt[$i] = Title::newFromText($title); |
— | — | @@ -207,7 +207,7 @@ |
208 | 208 | $wgOut->showErrorPage('formbadpagename', 'formbadpagenametext', array($title)); |
209 | 209 | return; |
210 | 210 | } |
211 | | - |
| 211 | + |
212 | 212 | if ($nt[$i]->getArticleID() != 0) { |
213 | 213 | $wgOut->showErrorPage('formarticleexists', 'formarticleexists', array($title)); |
214 | 214 | return; |
— | — | @@ -219,7 +219,7 @@ |
220 | 220 | for ($i = 0; $i < count($form->template); $i++) { |
221 | 221 | |
222 | 222 | $template = $form->template[$i]; |
223 | | - |
| 223 | + |
224 | 224 | $text = "{{subst:$template"; |
225 | 225 | |
226 | 226 | foreach ($form->fields as $name => $field) { |
— | — | @@ -233,14 +233,14 @@ |
234 | 234 | # Just break here; output already sent |
235 | 235 | return; |
236 | 236 | } |
237 | | - |
| 237 | + |
238 | 238 | $title = $nt[$i]->GetPrefixedText(); |
239 | | - |
| 239 | + |
240 | 240 | wfDebug("SpecialForm: saving article with index '$i' and title '$title'\n"); |
241 | 241 | |
242 | 242 | $article = new Article($nt[$i]); |
243 | 243 | |
244 | | - |
| 244 | + |
245 | 245 | if (!$article->doEdit($text, wfMsg('formsavesummary', $form->name), EDIT_NEW)) { |
246 | 246 | $wgOut->showErrorPage('formsaveerror', 'formsaveerrortext', array($title)); |
247 | 247 | return; # Don't continue |
— | — | @@ -248,12 +248,12 @@ |
249 | 249 | } |
250 | 250 | |
251 | 251 | # Redirect to the first article |
252 | | - |
| 252 | + |
253 | 253 | if ($nt && $nt[0]) { |
254 | 254 | $wgOut->redirect($nt[0]->getFullURL()); |
255 | 255 | } |
256 | 256 | } |
257 | | - |
| 257 | + |
258 | 258 | function makeTitle($form, $pattern) { |
259 | 259 | global $wgRequest; |
260 | 260 | |
— | — | @@ -267,7 +267,7 @@ |
268 | 268 | } |
269 | 269 | |
270 | 270 | # Had to crib some checks from EditPage.php, since they're not done in Article.php |
271 | | - |
| 271 | + |
272 | 272 | function checkSave($nt, $text) { |
273 | 273 | global $wgSpamRegex, $wgFilterCallback, $wgUser, $wgMaxArticleSize, $wgOut; |
274 | 274 | |
— | — | @@ -275,9 +275,9 @@ |
276 | 276 | $errortext = ""; |
277 | 277 | |
278 | 278 | $editPage = new FakeEditPage($nt); |
279 | | - |
| 279 | + |
280 | 280 | # FIXME: more specific errors, copied from EditPage.php |
281 | | - |
| 281 | + |
282 | 282 | if ($wgSpamRegex && preg_match($wgSpamRegex, $text, $matches)) { |
283 | 283 | $wgOut->showErrorPage('formsaveerror', 'formsaveerrortext'); |
284 | 284 | return false; |
— | — | @@ -306,7 +306,7 @@ |
307 | 307 | $wgOut->showErrorPage('formsaveerror', 'formsaveerrortext'); |
308 | 308 | return false; |
309 | 309 | } |
310 | | - |
| 310 | + |
311 | 311 | return true; |
312 | 312 | } |
313 | 313 | } |
— | — | @@ -316,7 +316,7 @@ |
317 | 317 | class FakeEditPage { |
318 | 318 | |
319 | 319 | var $mTitle; |
320 | | - |
| 320 | + |
321 | 321 | function FakeEditPage(&$nt) { |
322 | 322 | $this->mTitle = $nt; |
323 | 323 | } |
— | — | @@ -442,7 +442,7 @@ |
443 | 443 | (strcasecmp($value, 'true') == 0) || |
444 | 444 | (strcasecmp($value, '1') == 0)); |
445 | 445 | } |
446 | | - |
| 446 | + |
447 | 447 | function render($def = NULL) { |
448 | 448 | global $wgOut; |
449 | 449 | |
— | — | @@ -514,4 +514,4 @@ |
515 | 515 | return ''; |
516 | 516 | } |
517 | 517 | } |
518 | | -} |
\ No newline at end of file |
| 518 | +} |
Index: trunk/extensions/SpecialForm/SpecialForm.i18n.php |
— | — | @@ -37,6 +37,7 @@ |
38 | 38 | 'formtemplatepattern' => '$1', # Do not translate this message |
39 | 39 | 'formtitlepattern' => 'Add new $1', |
40 | 40 | 'formsave' => 'Save', |
| 41 | + 'formindexmismatch-title' => 'Name pattern and template mismatch', |
41 | 42 | 'formindexmismatch' => 'This form has mismatched name patterns and templates starting at index $1.', |
42 | 43 | 'formarticleexists' => 'Page exists', |
43 | 44 | 'formarticleexiststext' => 'The page [[$1]] already exists.', |
Index: trunk/extensions/SpecialForm/SpecialForm.setup.php |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | exit( 1 ); |
27 | 27 | } |
28 | 28 | |
29 | | -define('SPECIALFORM_VERSION', '0.2'); |
| 29 | +define('SPECIALFORM_VERSION', '0.3'); |
30 | 30 | |
31 | 31 | $dir = dirname(__FILE__) . '/'; |
32 | 32 | $wgAutoloadClasses['SpecialForm'] = $dir . '/SpecialForm.body.php'; # Tell MediaWiki to load the extension body. |