r52678 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52677‎ | r52678 | r52679 >
Date:05:53, 2 July 2009
Author:ashley
Status:deferred
Tags:
Comment:
SpecialForm:
*fix bug which was reported on MediaWiki.org: http://www.mediawiki.org/w/index.php?title=Extension:Form&oldid=263304#Errors
*coding style cleanup in main file
*change "POST" to "post" for XHTML compliance
*remove SPECIALFORM_VERSION constant
*bump version
Modified paths:
  • /trunk/extensions/SpecialForm/SpecialForm.body.php (modified) (history)
  • /trunk/extensions/SpecialForm/SpecialForm.setup.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SpecialForm/SpecialForm.body.php
@@ -17,150 +17,157 @@
1818 * along with this program; if not, write to the Free Software
1919 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2020 *
 21+ * @file
 22+ * @ingroup Extensions
2123 * @author Evan Prodromou <evan@vinismo.com>
22 - * @ingroup Extensions
2324 */
2425
25 -if (!defined('MEDIAWIKI')) {
 26+if( !defined( 'MEDIAWIKI' ) ) {
2627 exit( 1 );
2728 }
2829
2930 require_once('XmlFunctions.php');
3031
3132 class SpecialForm extends SpecialPage {
32 - function SpecialForm() {
33 - SpecialPage::SpecialPage("Form");
 33+
 34+ /**
 35+ * Constructor
 36+ */
 37+ public function __construct() {
 38+ parent::__construct( 'Form' );
3439 }
3540
36 - function execute( $par ) {
 41+ /**
 42+ * Show the special page
 43+ *
 44+ * @param $par Mixed: parameter passed to the page or null
 45+ */
 46+ public function execute( $par ) {
3747 global $wgRequest, $wgOut;
3848
3949 wfLoadExtensionMessages( 'Form' );
4050
4151 # Must have a name, like Special:Form/Nameofform
4252 # XXX: instead of an error, show a list of available forms
43 -
44 - if (!$par) {
45 - $wgOut->showErrorPage('formnoname', 'formnonametext');
 53+ if( !$par ) {
 54+ $wgOut->showErrorPage( 'formnoname', 'formnonametext' );
4655 return;
4756 }
4857
49 - $form = $this->loadForm($par);
 58+ $form = $this->loadForm( $par );
5059
5160 # Bad form
52 -
53 - if (!$form) {
54 - $wgOut->showErrorPage('formbadname', 'formbadnametext');
 61+ if( !$form ) {
 62+ $wgOut->showErrorPage( 'formbadname', 'formbadnametext' );
5563 return;
5664 }
5765
58 - if ($wgRequest->wasPosted()) {
 66+ if( $wgRequest->wasPosted() ) {
5967 # POST is to create an article
60 - $this->createArticle($form);
 68+ $this->createArticle( $form );
6169 } else {
6270 # GET (HEAD?) is to show the form
63 - $this->showForm($form);
 71+ $this->showForm( $form );
6472 }
6573 }
6674
6775 # Load and parse a form article from the DB
 76+ function loadForm( $name ) {
 77+ $nt = Title::makeTitleSafe( NS_MEDIAWIKI, wfMsgForContent( 'formpattern', $name ) );
6878
69 - function loadForm($name) {
70 - $nt = Title::makeTitleSafe(NS_MEDIAWIKI, wfMsgForContent('formpattern', $name));
71 -
7279 # article exists?
73 -
74 - if (!$nt || $nt->getArticleID() == 0) {
 80+ if( !$nt || $nt->getArticleID() == 0 ) {
7581 return NULL;
7682 }
7783
78 - $article = new Article($nt);
 84+ $article = new Article( $nt );
7985
80 - assert($article);
 86+ assert( $article );
8187
82 - $text = $article->getContent(true);
 88+ $text = $article->getContent( true );
8389
8490 # Form constructor does the parsing
85 -
86 - return new Form($name, $text);
 91+ return new Form( $name, $text );
8792 }
8893
89 - function showForm($form, $errmsg = NULL) {
 94+ function showForm( $form, $errmsg = NULL ) {
9095 global $wgOut, $wgRequest, $wgParser, $wgUser, $wgSpecialFormRecaptcha;
9196
92 - $self = SpecialPage::getTitleFor(wfMsgForContent('form') . '/' . $form->name);
 97+ $self = SpecialPage::getTitleFor( wfMsgForContent( 'form' ) . '/' . $form->name );
9398
94 - $wgOut->setPageTitle($form->title);
 99+ $wgOut->setPageTitle( $form->title );
95100
96 - if (!is_null($form->instructions)) {
 101+ if( !is_null( $form->instructions ) ) {
97102
98 - $wgOut->addHTML(Xml::openElement('div', array('class' => 'instructions')) .
99 - $wgOut->parse($form->instructions) .
100 - Xml::closeElement('div') .
101 - Xml::element('br'));
 103+ $wgOut->addHTML( Xml::openElement( 'div', array( 'class' => 'instructions' ) ) .
 104+ $wgOut->parse( $form->instructions ) .
 105+ Xml::closeElement( 'div' ) .
 106+ Xml::element( 'br' ) );
102107 }
103108
104 - if (!is_null($errmsg)) {
105 - $wgOut->addHTML(Xml::openElement('div', array('class' => 'error')) .
106 - $wgOut->parse($errmsg) .
107 - Xml::closeElement('div') .
108 - Xml::element('br'));
 109+ if( !is_null( $errmsg ) ) {
 110+ $wgOut->addHTML( Xml::openElement( 'div', array( 'class' => 'error' ) ) .
 111+ $wgOut->parse( $errmsg ) .
 112+ Xml::closeElement( 'div' ) .
 113+ Xml::element( 'br' ) );
109114 }
110115
111 - $wgOut->addHTML(Xml::openElement('form',
112 - array('method' => 'POST',
113 - 'action' => $self->getLocalURL())));
 116+ $wgOut->addHTML(
 117+ Xml::openElement( 'form', array(
 118+ 'method' => 'post',
 119+ 'action' => $self->getLocalURL()
 120+ )
 121+ )
 122+ );
114123
115 - foreach ($form->fields as $field) {
116 - $wgOut->addHTML($field->render($wgRequest->getText($field->name)) . Xml::element('br') . "\n");
 124+ foreach( $form->fields as $field ) {
 125+ $wgOut->addHTML( $field->render( $wgRequest->getText( $field->name ) ) . Xml::element( 'br' ) . "\n" );
117126 }
118127
119 - if ($wgUser->getId() == 0 && $wgSpecialFormRecaptcha) { # Anonymous user, use recaptcha
120 - require_once('recaptchalib.php');
 128+ # Anonymous user, use recaptcha
 129+ if( $wgUser->getId() == 0 && $wgSpecialFormRecaptcha ) {
 130+ require_once( 'recaptchalib.php' );
121131 global $recaptcha_public_key; # same as used by Recaptcha plugin
122 - $wgOut->addHTML(recaptcha_get_html($recaptcha_public_key));
 132+ $wgOut->addHTML( recaptcha_get_html( $recaptcha_public_key ) );
123133 }
124134
125 - $wgOut->addHTML(Xml::element('input', array('type' => 'submit',
126 - 'value' => wfMsg('formsave'))));
 135+ $wgOut->addHTML( Xml::element( 'input', array( 'type' => 'submit',
 136+ 'value' => wfMsg( 'formsave' ) ) ) );
127137
128 - $wgOut->addHTML(Xml::closeElement('form'));
 138+ $wgOut->addHTML( Xml::closeElement( 'form' ) );
129139 }
130140
131 - function createArticle($form) {
132 -
 141+ function createArticle( $form ) {
133142 global $wgOut, $wgRequest, $wgLang, $wgUser, $wgSpecialFormRecaptcha;
134143
135144 # Check recaptcha
136 -
137 - if ($wgUser->getId() == 0 && $wgSpecialFormRecaptcha) {
138 -
139 - require_once('recaptchalib.php');
 145+ if( $wgUser->getId() == 0 && $wgSpecialFormRecaptcha ) {
 146+ require_once( 'recaptchalib.php' );
140147 global $recaptcha_private_key; # same as used by Recaptcha plugin
141 - $resp = recaptcha_check_answer($recaptcha_private_key,
142 - $_SERVER["REMOTE_ADDR"],
143 - $wgRequest->getText("recaptcha_challenge_field"),
144 - $wgRequest->getText("recaptcha_response_field"));
 148+ $resp = recaptcha_check_answer(
 149+ $recaptcha_private_key,
 150+ $_SERVER['REMOTE_ADDR'],
 151+ $wgRequest->getText( 'recaptcha_challenge_field' ),
 152+ $wgRequest->getText( 'recaptcha_response_field' )
 153+ );
145154
146 - if (!$resp->is_valid) {
147 - $this->showForm($form, wfMsg('formbadrecaptcha'));
 155+ if( !$resp->is_valid ) {
 156+ $this->showForm( $form, wfMsg( 'formbadrecaptcha' ) );
148157 return;
149158 }
150159 }
151160
152161 # Check for required fields
153 -
154162 $missedFields = array();
155163
156 - foreach ($form->fields as $name => $field) {
157 - $value = $wgRequest->getText($name);
158 - if ($field->isOptionTrue('required') && (is_null($value) || strlen($value) == 0)) {
 164+ foreach( $form->fields as $name => $field ) {
 165+ $value = $wgRequest->getText( $name );
 166+ if( $field->isOptionTrue( 'required' ) && ( is_null( $value ) || strlen( $value ) == 0 ) ) {
159167 $missedFields[] = $field->label;
160168 }
161169 }
162170
163171 # On error, show the form again with some error text.
164 -
165172 $missedFieldsCount = count( $missedFields );
166173 if ( $missedFieldsCount > 0 ) {
167174 $msg = wfMsgExt( 'formrequiredfielderror', 'parsemag', $wgLang->listToText( $missedFields ), $missedFieldsCount );
@@ -169,126 +176,121 @@
170177 }
171178
172179 # First, we make sure we have all the titles
173 -
174180 $nt = array();
175181
176 - for ($i = 0; $i < count($form->template); $i++) {
 182+ for( $i = 0; $i < count( $form->template ); $i++ ) {
177183
178184 $namePattern = $form->namePattern[$i];
179185 $template = $form->template[$i];
180186
181 - if (!$namePattern || !$template) {
182 - $wgOut->showErrorPage('formindexmismatch-title', 'formindexmismatch', array($i));
 187+ if( !$namePattern || !$template ) {
 188+ $wgOut->showErrorPage( 'formindexmismatch-title', 'formindexmismatch', array( $i ) );
183189 return;
184190 }
185191
186 - wfDebug("SpecialForm: for index '$i', namePattern = '$namePattern' and template = '$template'.\n");
 192+ wfDebug( __METHOD__ . ": for index '$i', namePattern = '$namePattern' and template = '$template'.\n" );
187193
188 - $title = $this->makeTitle($form, $namePattern);
 194+ $title = $this->makeTitle( $form, $namePattern );
189195
190 - $nt[$i] = Title::newFromText($title);
 196+ $nt[$i] = Title::newFromText( $title );
191197
192 - if (!$nt[$i]) {
193 - $wgOut->showErrorPage('formbadpagename', 'formbadpagenametext', array($title));
 198+ if( !$nt[$i] ) {
 199+ $wgOut->showErrorPage( 'formbadpagename', 'formbadpagenametext', array( $title ) );
194200 return;
195201 }
196202
197 - if ($nt[$i]->getArticleID() != 0) {
198 - $wgOut->showErrorPage('formarticleexists', 'formarticleexists', array($title));
 203+ if( $nt[$i]->getArticleID() != 0 ) {
 204+ $wgOut->showErrorPage( 'formarticleexists', 'formarticleexists', array( $title ) );
199205 return;
200206 }
201207 }
202208
203209 # At this point, all $nt titles should be valid, although we're subject to race conditions.
 210+ for( $i = 0; $i < count( $form->template ); $i++ ) {
204211
205 - for ($i = 0; $i < count($form->template); $i++) {
206 -
207212 $template = $form->template[$i];
208213
209214 $text = "{{subst:$template";
210215
211 - foreach ($form->fields as $name => $field) {
 216+ foreach( $form->fields as $name => $field ) {
212217 # FIXME: strip/escape template-related chars (|, =, }})
213 - $text .= "|$name=" . $wgRequest->getText($name);
 218+ $text .= "|$name=" . $wgRequest->getText( $name );
214219 }
215220
216 - $text .= "}}";
 221+ $text .= '}}';
217222
218 - if (!$this->checkSave($nt[$i], $text)) {
 223+ if( !$this->checkSave( $nt[$i], $text ) ) {
219224 # Just break here; output already sent
220225 return;
221226 }
222227
223228 $title = $nt[$i]->GetPrefixedText();
224229
225 - wfDebug("SpecialForm: saving article with index '$i' and title '$title'\n");
 230+ wfDebug( __METHOD__ . ": saving article with index '$i' and title '$title'\n" );
226231
227 - $article = new Article($nt[$i]);
 232+ $article = new Article( $nt[$i] );
228233
229 - $status = $article->doEdit($text, wfMsg('formsavesummary', $form->name), EDIT_NEW);
 234+ $status = $article->doEdit( $text, wfMsg( 'formsavesummary', $form->name ), EDIT_NEW );
230235 if ( $status === false || ( is_object( $status ) && !$status->isOK() ) ) {
231 - $wgOut->showErrorPage('formsaveerror', 'formsaveerrortext', array($title));
 236+ $wgOut->showErrorPage( 'formsaveerror', 'formsaveerrortext', array( $title ) );
232237 return; # Don't continue
233238 }
234239 }
235240
236241 # Redirect to the first article
237 -
238 - if ($nt && $nt[0]) {
239 - $wgOut->redirect($nt[0]->getFullURL());
 242+ if( $nt && $nt[0] ) {
 243+ $wgOut->redirect( $nt[0]->getFullURL() );
240244 }
241245 }
242246
243 - function makeTitle($form, $pattern) {
 247+ function makeTitle( $form, $pattern ) {
244248 global $wgRequest;
245249
246250 $title = $pattern;
247251
248 - foreach ($form->fields as $name => $field) {
249 - $title = preg_replace("/{{\{$name\}}}/", $wgRequest->getText($name), $title);
 252+ foreach( $form->fields as $name => $field ) {
 253+ $title = preg_replace( "/{{\{$name\}}}/", $wgRequest->getText( $name ), $title );
250254 }
251255
252256 return $title;
253257 }
254258
255259 # Had to crib some checks from EditPage.php, since they're not done in Article.php
256 -
257 - function checkSave($nt, $text) {
 260+ function checkSave( $nt, $text ) {
258261 global $wgSpamRegex, $wgFilterCallback, $wgUser, $wgMaxArticleSize, $wgOut;
259262
260263 $matches = array();
261 - $errortext = "";
 264+ $errortext = '';
262265
263 - $editPage = new FakeEditPage($nt);
 266+ $editPage = new FakeEditPage( $nt );
264267
265268 # FIXME: more specific errors, copied from EditPage.php
266 -
267 - if ($wgSpamRegex && preg_match($wgSpamRegex, $text, $matches)) {
268 - $wgOut->showErrorPage('formsaveerror', 'formsaveerrortext');
 269+ if( $wgSpamRegex && preg_match( $wgSpamRegex, $text, $matches ) ) {
 270+ $wgOut->showErrorPage( 'formsaveerror', 'formsaveerrortext' );
269271 return false;
270 - } else if ($wgFilterCallback && $wgFilterCallback($nt, $text, 0)) {
271 - $wgOut->showErrorPage('formsaveerror', 'formsaveerrortext');
 272+ } else if( $wgFilterCallback && $wgFilterCallback( $nt, $text, 0 ) ) {
 273+ $wgOut->showErrorPage( 'formsaveerror', 'formsaveerrortext' );
272274 return false;
273 - } else if (!wfRunHooks('EditFilter', array($editPage, $text, 0, &$errortext))) {
 275+ } else if( !wfRunHooks( 'EditFilter', array( $editPage, $text, 0, &$errortext ) ) ) {
274276 # Hooks usually print their own error
275277 return false;
276 - } else if ($errortext != '') {
277 - $wgOut->showErrorPage('formsaveerror', 'formsaveerrortext');
 278+ } else if( $errortext != '' ) {
 279+ $wgOut->showErrorPage( 'formsaveerror', 'formsaveerrortext' );
278280 return false;
279 - } else if ($wgUser->isBlockedFrom($nt, false)) {
280 - $wgOut->showErrorPage('formsaveerror', 'formsaveerrortext');
 281+ } else if( $wgUser->isBlockedFrom( $nt, false ) ) {
 282+ $wgOut->showErrorPage( 'formsaveerror', 'formsaveerrortext' );
281283 return false;
282 - } else if ((int)(strlen($text) / 1024) > $wgMaxArticleSize) {
283 - $wgOut->showErrorPage('formsaveerror', 'formsaveerrortext');
 284+ } else if( (int)(strlen($text) / 1024) > $wgMaxArticleSize ) {
 285+ $wgOut->showErrorPage( 'formsaveerror', 'formsaveerrortext' );
284286 return false;
285 - } else if (!$wgUser->isAllowed('edit')) {
286 - $wgOut->showErrorPage('formsaveerror', 'formsaveerrortext');
 287+ } else if( !$wgUser->isAllowed( 'edit' ) ) {
 288+ $wgOut->showErrorPage( 'formsaveerror', 'formsaveerrortext' );
287289 return false;
288 - } else if (wfReadOnly()) {
289 - $wgOut->showErrorPage('formsaveerror', 'formsaveerrortext');
 290+ } else if( wfReadOnly() ) {
 291+ $wgOut->showErrorPage( 'formsaveerror', 'formsaveerrortext' );
290292 return false;
291 - } else if ($wgUser->pingLimiter()) {
292 - $wgOut->showErrorPage('formsaveerror', 'formsaveerrortext');
 293+ } else if( $wgUser->pingLimiter() ) {
 294+ $wgOut->showErrorPage( 'formsaveerror', 'formsaveerrortext' );
293295 return false;
294296 }
295297
@@ -297,12 +299,10 @@
298300 }
299301
300302 # Dummy class for extensions that support EditFilter hook
301 -
302303 class FakeEditPage {
303 -
304304 var $mTitle;
305305
306 - function FakeEditPage(&$nt) {
 306+ function FakeEditPage( &$nt ) {
307307 $this->mTitle = $nt;
308308 }
309309 }
@@ -315,69 +315,66 @@
316316 var $fields;
317317 var $namePattern;
318318
319 - function Form($name, $text) {
320 -
 319+ function Form( $name, $text ) {
321320 $this->name = $name;
322 - $this->title = wfMsgForContent('formtitlepattern', $name);
 321+ $this->title = wfMsgForContent( 'formtitlepattern', $name );
323322 $this->template = array();
324 - $this->template[0] = wfMsgForContent('formtemplatepattern', $name);
 323+ $this->template[0] = wfMsgForContent( 'formtemplatepattern', $name );
325324
326325 $this->fields = array();
327326 $this->namePattern = array();
328327 $this->instructions = NULL;
329328
330329 # XXX: may be some faster ways to do this
 330+ $lines = explode( "\n", $text );
331331
332 - $lines = explode("\n", $text);
 332+ foreach( $lines as $line ) {
333333
334 - foreach ($lines as $line) {
335 -
336 - if (preg_match('/^(\w+)=(.*)$/', $line, $matches)) {
337 - if (strcasecmp($matches[1], 'template') == 0) {
 334+ if( preg_match( '/^(\w+)=(.*)$/', $line, $matches ) ) {
 335+ if( strcasecmp( $matches[1], 'template' ) == 0 ) {
338336 $this->template[0] = $matches[2];
339 - } else if (preg_match('/template(\d+)/i', $matches[1], $tmatches)) {
 337+ } else if( preg_match( '/template(\d+)/i', $matches[1], $tmatches ) ) {
340338 $this->template[intval($tmatches[1])] = $matches[2];
341 - } else if (strcasecmp($matches[1], 'namePattern') == 0) {
 339+ } else if( strcasecmp( $matches[1], 'namePattern' ) == 0 ) {
342340 $this->namePattern[0] = $matches[2];
343 - } else if (preg_match('/namePattern(\d+)/i', $matches[1], $tmatches)) {
 341+ } else if( preg_match( '/namePattern(\d+)/i', $matches[1], $tmatches ) ) {
344342 $this->namePattern[intval($tmatches[1])] = $matches[2];
345 - } else if (strcasecmp($matches[1], 'title') == 0) {
 343+ } else if( strcasecmp( $matches[1], 'title' ) == 0 ) {
346344 $this->title = $matches[2];
347 - } else if (strcasecmp($matches[1], 'instructions') == 0) {
 345+ } else if( strcasecmp( $matches[1], 'instructions' ) == 0 ) {
348346 $this->instructions = $matches[2];
349 - wfDebug("Got instructions: '" . $this->instructions . "'.\n");
 347+ wfDebug( __METHOD__ . ": Got instructions: '" . $this->instructions . "'.\n" );
350348 } else {
351 - wfDebug("SpecialForm: unknown form attribute '$matches[1]'; skipping.\n");
 349+ wfDebug( __METHOD__ . ": unknown form attribute '$matches[1]'; skipping.\n" );
352350 }
353 - } else if (preg_match('/^(\w+)\|([^\|]+)\|(\w+)(\|([^\|]+)(\|(.*))?)?$/', $line, $matches)) {
 351+ } else if( preg_match( '/^(\w+)\|([^\|]+)\|(\w+)(\|([^\|]+)(\|(.*))?)?$/', $line, $matches ) ) {
354352 # XXX: build an inheritance tree for different kinds of fields
355353 $field = new FormField();
356 - $field->setName($matches[1]);
357 - $field->setLabel($matches[2]);
358 - $field->setFieldType($matches[3]);
359 - if (count($matches) > 4 && $matches[4]) {
360 - $field->setDescription($matches[5]);
361 - if (count($matches) > 6 && $matches[6]) {
362 - $rawOptions = explode(',', $matches[7]);
363 - foreach ($rawOptions as $rawOption) {
364 - if (preg_match('/^(\w+)=(.+)/', $rawOption, $optMatches)) {
365 - $field->setOption($optMatches[1], $optMatches[2]);
 354+ $field->setName( $matches[1] );
 355+ $field->setLabel( $matches[2] );
 356+ $field->setFieldType( $matches[3] );
 357+ if( count( $matches ) > 4 && $matches[4] ) {
 358+ $field->setDescription( $matches[5] );
 359+ if( count( $matches ) > 6 && $matches[6] ) {
 360+ $rawOptions = explode( ',', $matches[7] );
 361+ foreach( $rawOptions as $rawOption ) {
 362+ if( preg_match( '/^(\w+)=(.+)/', $rawOption, $optMatches ) ) {
 363+ $field->setOption( $optMatches[1], $optMatches[2] );
366364 } else {
367 - wfDebug("SpecialForm: unrecognized form field option: '$rawOption'; skipping.\n");
 365+ wfDebug( __METHOD__ . ": unrecognized form field option: '$rawOption'; skipping.\n" );
368366 }
369367 }
370368 }
371369 }
372370 $this->fields[$field->name] = $field;
373371 } else {
374 - wfDebug("SpecialForm: unrecognized form line: '$line'; skipping.\n");
 372+ wfDebug( __METHOD__ . ": unrecognized form line: '$line'; skipping.\n" );
375373 }
376374 }
377375 }
378376 }
379377
380378 class FormField {
381 -
382379 var $name;
383380 var $type;
384381 var $label;
@@ -392,111 +389,122 @@
393390 $this->options = array();
394391 }
395392
396 - function setName($name) {
 393+ function setName( $name ) {
397394 $this->name = $name;
398395 }
399396
400 - function setFieldType($type) {
 397+ function setFieldType( $type ) {
401398 $this->type = $type;
402399 }
403400
404 - function setLabel($label) {
 401+ function setLabel( $label ) {
405402 $this->label = $label;
406403 }
407404
408 - function setDescription($description) {
 405+ function setDescription( $description ) {
409406 $this->description = $description;
410407 }
411408
412 - function setOption($key, $value) {
 409+ function setOption( $key, $value ) {
413410 $this->options[$key] = $value;
414411 }
415412
416 - function getOption($key, $default = NULL) {
417 - if (array_key_exists($key, $this->options)) {
 413+ function getOption( $key, $default = NULL ) {
 414+ if( array_key_exists( $key, $this->options ) ) {
418415 return $this->options[$key];
419416 } else {
420417 return $default;
421418 }
422419 }
423420
424 - function isOptionTrue($key, $default = false) {
425 - $value = $this->getOption($key, $default);
426 - return ((strcasecmp($value, 'on') == 0) ||
427 - (strcasecmp($value, 'yes') == 0) ||
428 - (strcasecmp($value, 'true') == 0) ||
429 - (strcasecmp($value, '1') == 0));
 421+ function isOptionTrue( $key, $default = false ) {
 422+ $value = $this->getOption( $key, $default );
 423+ return ( ( strcasecmp( $value, 'on' ) == 0 ) ||
 424+ ( strcasecmp( $value, 'yes' ) == 0 ) ||
 425+ ( strcasecmp( $value, 'true' ) == 0 ) ||
 426+ ( strcasecmp( $value, '1' ) == 0 ) );
430427 }
431428
432 - function render($def = NULL) {
 429+ function render( $def = NULL ) {
433430 global $wgOut;
434431
435 - switch ($this->type) {
436 - case 'textarea':
437 - return Xml::openElement('h2') .
438 - Xml::element('label', array('for' => $this->name), $this->label) .
439 - Xml::closeElement('h2') .
440 - (($this->description) ?
441 - (Xml::openElement('div') . $wgOut->parse($this->description) . Xml::closeElement('div')) : '') .
442 - Xml::openElement('textarea', array('name' => $this->name,
443 - 'id' => $this->name,
444 - 'rows' => $this->getOption('rows', 6),
445 - 'cols' => $this->getOption('cols', 80))) .
446 - ((is_null($def)) ? '' : $def) .
447 - Xml::closeElement('textarea');
 432+ switch( $this->type ) {
 433+ case 'textarea':
 434+ return Xml::openElement( 'h2' ) .
 435+ Xml::element( 'label', array( 'for' => $this->name ), $this->label ) .
 436+ Xml::closeElement( 'h2' ) .
 437+ ( ( $this->description) ?
 438+ ( Xml::openElement( 'div' ) . $wgOut->parse( $this->description ) . Xml::closeElement( 'div' ) ) : '' ) .
 439+ Xml::openElement( 'textarea',
 440+ array(
 441+ 'name' => $this->name,
 442+ 'id' => $this->name,
 443+ 'rows' => $this->getOption( 'rows', 6 ),
 444+ 'cols' => $this->getOption( 'cols', 80 )
 445+ )
 446+ ) .
 447+ ( ( is_null( $def ) ) ? '' : $def ) .
 448+ Xml::closeElement( 'textarea' );
448449 break;
449 - case 'text':
450 - return Xml::element( 'label', array( 'for' => $this->name ), $this->label ) . wfMsg( 'colon-separator' ) .
451 - Xml::element('input', array('type' => 'text',
452 - 'name' => $this->name,
453 - 'id' => $this->name,
454 - 'value' => ((is_null($def)) ? '' : $def),
455 - 'size' => $this->getOption('size', 30)));
 450+ case 'text':
 451+ return Xml::element( 'label', array( 'for' => $this->name ), $this->label ) . wfMsg( 'colon-separator' ) .
 452+ Xml::element( 'input',
 453+ array(
 454+ 'type' => 'text',
 455+ 'name' => $this->name,
 456+ 'id' => $this->name,
 457+ 'value' => ( ( is_null( $def ) ) ? '' : $def ),
 458+ 'size' => $this->getOption( 'size', 30 )
 459+ )
 460+ );
456461 break;
457 - case 'checkbox':
458 - $attrs = array('type' => 'checkbox',
459 - 'name' => $this->name,
460 - 'id' => $this->name);
461 - if ($def == 'checked') {
462 - $attrs['checked'] = 'checked';
463 - }
464 - return Xml::element( 'label', array( 'for' => $this->name ), $this->label ) . wfMsg( 'colon-separator' ) .
465 - Xml::element('input', $attrs);
466 - break;
467 - case 'radio':
468 - $items = array();
469 - $rawitems = explode(';', $this->getOption('items'));
470 - foreach ($rawitems as $item) {
471 - $attrs = array('type' => 'radio',
472 - 'name' => $this->name,
473 - 'value' => $item);
474 - if ($item == $def) {
 462+ case 'checkbox':
 463+ $attrs = array(
 464+ 'type' => 'checkbox',
 465+ 'name' => $this->name,
 466+ 'id' => $this->name
 467+ );
 468+ if( $def == 'checked' ) {
475469 $attrs['checked'] = 'checked';
476470 }
477 - $items[] = Xml::openElement('input', $attrs) .
478 - Xml::element('label', null, $item) .
479 - Xml::closeElement('input');
480 - }
481 - return Xml::element('span', null, $this->label) . Xml::element('br') . implode("", $items);
 471+ return Xml::element( 'label', array( 'for' => $this->name ), $this->label ) . wfMsg( 'colon-separator' ) .
 472+ Xml::element( 'input', $attrs );
482473 break;
483 - case 'select':
484 - $items = array();
485 - $rawitems = explode(';', $this->getOption('items'));
486 - foreach ($rawitems as $item) {
487 - $items[] = Xml::element('option',
488 - ($item == $def) ? array('selected' => 'selected') : null,
489 - $item);
490 - }
 474+ case 'radio':
 475+ $items = array();
 476+ $rawitems = explode( ';', $this->getOption( 'items' ) );
 477+ foreach( $rawitems as $item ) {
 478+ $attrs = array(
 479+ 'type' => 'radio',
 480+ 'name' => $this->name,
 481+ 'value' => $item
 482+ );
 483+ if( $item == $def ) {
 484+ $attrs['checked'] = 'checked';
 485+ }
 486+ $items[] = Xml::openElement( 'input', $attrs ) .
 487+ Xml::element( 'label', null, $item ) .
 488+ Xml::closeElement( 'input' );
 489+ }
 490+ return Xml::element( 'span', null, $this->label ) . Xml::element( 'br' ) . implode( '', $items );
 491+ break;
 492+ case 'select':
 493+ $items = array();
 494+ $rawitems = explode( ';', $this->getOption( 'items' ) );
 495+ foreach( $rawitems as $item ) {
 496+ $items[] = Xml::element( 'option',
 497+ ( $item == $def ) ? array( 'selected' => 'selected' ) : null,
 498+ $item );
 499+ }
491500
492 - return Xml::element( 'label', array( 'for' => $this->name ), $this->label ) . wfMsg( 'colon-separator' ) .
493 - Xml::openElement('select', array('name' => $this->name, 'id' => $this->name)) .
494 - implode("", $items) .
495 - Xml::closeElement('select');
496 -
 501+ return Xml::element( 'label', array( 'for' => $this->name ), $this->label ) . wfMsg( 'colon-separator' ) .
 502+ Xml::openElement( 'select', array( 'name' => $this->name, 'id' => $this->name ) ) .
 503+ implode( '', $items ) .
 504+ Xml::closeElement( 'select' );
497505 break;
498 - default:
499 - wfDebug("SpecialForm: unknown form field type '$this->type', skipping.\n");
500 - return '';
 506+ default:
 507+ wfDebug( __METHOD__ . ": unknown form field type '$this->type', skipping.\n" );
 508+ return '';
501509 }
502510 }
503 -}
 511+}
\ No newline at end of file
Index: trunk/extensions/SpecialForm/SpecialForm.setup.php
@@ -17,26 +17,27 @@
1818 * along with this program; if not, write to the Free Software
1919 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2020 *
 21+ * @file
 22+ * @ingroup Extensions
2123 * @author Evan Prodromou <evan@vinismo.com>
22 - * @ingroup Extensions
2324 */
2425
25 -if (!defined('MEDIAWIKI')) {
 26+if( !defined( 'MEDIAWIKI' ) ) {
2627 exit( 1 );
2728 }
2829
29 -define('SPECIALFORM_VERSION', '0.4');
30 -
31 -$dir = dirname(__FILE__) . '/';
32 -$wgAutoloadClasses['SpecialForm'] = $dir . '/SpecialForm.body.php'; # Tell MediaWiki to load the extension body.
33 -$wgExtensionMessagesFiles['SpecialForm'] = $dir . 'SpecialForm.i18n.php'; #Load internationalization file
 30+// Set up the new special page
 31+$dir = dirname( __FILE__ ) . '/';
 32+$wgAutoloadClasses['SpecialForm'] = $dir . 'SpecialForm.body.php'; # Tell MediaWiki to load the extension body.
 33+$wgExtensionMessagesFiles['Form'] = $dir . 'SpecialForm.i18n.php'; #Load internationalization file
3434 $wgExtensionAliasesFiles['Form'] = $dir . 'SpecialForm.alias.php';
3535 $wgSpecialPages['Form'] = 'SpecialForm'; # Let MediaWiki know about your new special page.
3636
 37+// Extension credits that will show up on Special:Version
3738 $wgExtensionCredits['specialpage'][] = array(
3839 'path' => __FILE__,
3940 'name' => 'Form',
40 - 'version' => SPECIALFORM_VERSION,
 41+ 'version' => '0.4.1',
4142 'author' => 'Evan Prodromou',
4243 'url' => 'http://www.mediawiki.org/wiki/Extension:Form',
4344 'description' => 'A form interface to start new articles',
@@ -44,4 +45,4 @@
4546 );
4647
4748 # Use recaptcha; default to false
48 -$wgSpecialFormRecaptcha = false;
 49+$wgSpecialFormRecaptcha = false;
\ No newline at end of file

Status & tagging log