r39170 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r39169‎ | r39170 | r39171 >
Date:19:32, 11 August 2008
Author:siebrand
Status:old
Tags:
Comment:
(bug 13056) Fix for missing message (spotted by Lejonel)
* remove eol whitespace
* bump version (also given r39168)

TODO:
* use $wgExtensionAliasesFiles for special page localisation
* delay message loading
Modified paths:
  • /trunk/extensions/SpecialForm/SpecialForm.body.php (modified) (history)
  • /trunk/extensions/SpecialForm/SpecialForm.i18n.php (modified) (history)
  • /trunk/extensions/SpecialForm/SpecialForm.setup.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SpecialForm/SpecialForm.body.php
@@ -38,7 +38,7 @@
3939
4040 # Must have a name, like Special:Form/Nameofform
4141 # XXX: instead of an error, show a list of available forms
42 -
 42+
4343 if (!$par) {
4444 $wgOut->showErrorPage('formnoname', 'formnonametext');
4545 return;
@@ -63,7 +63,7 @@
6464 }
6565
6666 # Load form-related messages, per special-page guidelines
67 -
 67+
6868 function loadMessages() {
6969 static $messagesLoaded = false;
7070 global $wgMessageCache;
@@ -76,7 +76,7 @@
7777 }
7878
7979 # Load and parse a form article from the DB
80 -
 80+
8181 function loadForm($name) {
8282 $nt = Title::makeTitleSafe(NS_MEDIAWIKI, wfMsgForContent('formpattern', $name));
8383
@@ -93,7 +93,7 @@
9494 $text = $article->getContent(true);
9595
9696 # Form constructor does the parsing
97 -
 97+
9898 return new Form($name, $text);
9999 }
100100
@@ -118,7 +118,7 @@
119119 wfCloseElement('div') .
120120 wfElement('br'));
121121 }
122 -
 122+
123123 $wgOut->addHtml(wfOpenElement('form',
124124 array('method' => 'POST',
125125 'action' => $self->getLocalURL())));
@@ -132,7 +132,7 @@
133133 global $recaptcha_public_key; # same as used by Recaptcha plugin
134134 $wgOut->addHtml(recaptcha_get_html($recaptcha_public_key));
135135 }
136 -
 136+
137137 $wgOut->addHtml(wfElement('input', array('type' => 'submit',
138138 'value' => wfMsg('formsave'))));
139139
@@ -146,7 +146,7 @@
147147 # Check recaptcha
148148
149149 if ($wgUser->getId() == 0 && $wgSpecialFormRecaptcha) {
150 -
 150+
151151 require_once('recaptchalib.php');
152152 global $recaptcha_private_key; # same as used by Recaptcha plugin
153153 $resp = recaptcha_check_answer($recaptcha_private_key,
@@ -159,11 +159,11 @@
160160 return;
161161 }
162162 }
163 -
 163+
164164 # Check for required fields
165165
166166 $missedFields = array();
167 -
 167+
168168 foreach ($form->fields as $name => $field) {
169169 $value = $wgRequest->getText($name);
170170 if ($field->isOptionTrue('required') && (is_null($value) || strlen($value) == 0)) {
@@ -172,7 +172,7 @@
173173 }
174174
175175 # On error, show the form again with some error text.
176 -
 176+
177177 if ($missedFields) {
178178 if (count($missedFields) > 1) {
179179 $msg = wfMsg('formrequiredfieldpluralerror', $wgLang->listToText($missedFields));
@@ -186,19 +186,19 @@
187187 # First, we make sure we have all the titles
188188
189189 $nt = array();
190 -
 190+
191191 for ($i = 0; $i < count($form->template); $i++) {
192 -
 192+
193193 $namePattern = $form->namePattern[$i];
194194 $template = $form->template[$i];
195195
196196 if (!$namePattern || !$template) {
197 - $wgOut->showErrorPage('formindexmismatch', 'formindexmismatchtext', array($i));
 197+ $wgOut->showErrorPage('formindexmismatch-title', 'formindexmismatch', array($i));
198198 return;
199199 }
200200
201201 wfDebug("SpecialForm: for index '$i', namePattern = '$namePattern' and template = '$template'.\n");
202 -
 202+
203203 $title = $this->makeTitle($form, $namePattern);
204204
205205 $nt[$i] = Title::newFromText($title);
@@ -207,7 +207,7 @@
208208 $wgOut->showErrorPage('formbadpagename', 'formbadpagenametext', array($title));
209209 return;
210210 }
211 -
 211+
212212 if ($nt[$i]->getArticleID() != 0) {
213213 $wgOut->showErrorPage('formarticleexists', 'formarticleexists', array($title));
214214 return;
@@ -219,7 +219,7 @@
220220 for ($i = 0; $i < count($form->template); $i++) {
221221
222222 $template = $form->template[$i];
223 -
 223+
224224 $text = "{{subst:$template";
225225
226226 foreach ($form->fields as $name => $field) {
@@ -233,14 +233,14 @@
234234 # Just break here; output already sent
235235 return;
236236 }
237 -
 237+
238238 $title = $nt[$i]->GetPrefixedText();
239 -
 239+
240240 wfDebug("SpecialForm: saving article with index '$i' and title '$title'\n");
241241
242242 $article = new Article($nt[$i]);
243243
244 -
 244+
245245 if (!$article->doEdit($text, wfMsg('formsavesummary', $form->name), EDIT_NEW)) {
246246 $wgOut->showErrorPage('formsaveerror', 'formsaveerrortext', array($title));
247247 return; # Don't continue
@@ -248,12 +248,12 @@
249249 }
250250
251251 # Redirect to the first article
252 -
 252+
253253 if ($nt && $nt[0]) {
254254 $wgOut->redirect($nt[0]->getFullURL());
255255 }
256256 }
257 -
 257+
258258 function makeTitle($form, $pattern) {
259259 global $wgRequest;
260260
@@ -267,7 +267,7 @@
268268 }
269269
270270 # Had to crib some checks from EditPage.php, since they're not done in Article.php
271 -
 271+
272272 function checkSave($nt, $text) {
273273 global $wgSpamRegex, $wgFilterCallback, $wgUser, $wgMaxArticleSize, $wgOut;
274274
@@ -275,9 +275,9 @@
276276 $errortext = "";
277277
278278 $editPage = new FakeEditPage($nt);
279 -
 279+
280280 # FIXME: more specific errors, copied from EditPage.php
281 -
 281+
282282 if ($wgSpamRegex && preg_match($wgSpamRegex, $text, $matches)) {
283283 $wgOut->showErrorPage('formsaveerror', 'formsaveerrortext');
284284 return false;
@@ -306,7 +306,7 @@
307307 $wgOut->showErrorPage('formsaveerror', 'formsaveerrortext');
308308 return false;
309309 }
310 -
 310+
311311 return true;
312312 }
313313 }
@@ -316,7 +316,7 @@
317317 class FakeEditPage {
318318
319319 var $mTitle;
320 -
 320+
321321 function FakeEditPage(&$nt) {
322322 $this->mTitle = $nt;
323323 }
@@ -442,7 +442,7 @@
443443 (strcasecmp($value, 'true') == 0) ||
444444 (strcasecmp($value, '1') == 0));
445445 }
446 -
 446+
447447 function render($def = NULL) {
448448 global $wgOut;
449449
@@ -514,4 +514,4 @@
515515 return '';
516516 }
517517 }
518 -}
\ No newline at end of file
 518+}
Index: trunk/extensions/SpecialForm/SpecialForm.i18n.php
@@ -37,6 +37,7 @@
3838 'formtemplatepattern' => '$1', # Do not translate this message
3939 'formtitlepattern' => 'Add new $1',
4040 'formsave' => 'Save',
 41+ 'formindexmismatch-title' => 'Name pattern and template mismatch',
4142 'formindexmismatch' => 'This form has mismatched name patterns and templates starting at index $1.',
4243 'formarticleexists' => 'Page exists',
4344 'formarticleexiststext' => 'The page [[$1]] already exists.',
Index: trunk/extensions/SpecialForm/SpecialForm.setup.php
@@ -25,7 +25,7 @@
2626 exit( 1 );
2727 }
2828
29 -define('SPECIALFORM_VERSION', '0.2');
 29+define('SPECIALFORM_VERSION', '0.3');
3030
3131 $dir = dirname(__FILE__) . '/';
3232 $wgAutoloadClasses['SpecialForm'] = $dir . '/SpecialForm.body.php'; # Tell MediaWiki to load the extension body.

Follow-up revisions

RevisionCommit summaryAuthorDate
r39171(bug 13056) Fix for awkward message usage (patch by Lejonel)...siebrand19:51, 11 August 2008

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r39168Optionally show reCaptcha...evan19:20, 11 August 2008

Status & tagging log