r11984 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r11983‎ | r11984 | r11985 >
Date:23:18, 5 December 2005
Author:hashar
Status:old
Tags:
Comment:
Fix some minor validation issues
Modified paths:
  • /branches/wikidata/phase3/includes/SpecialNamespaces.php (modified) (history)

Diff [purge]

Index: branches/wikidata/phase3/includes/SpecialNamespaces.php
@@ -1,103 +1,102 @@
22 <?php
33 /**
4 - *
5 - * @package MediaWiki
6 - * @subpackage SpecialPage
7 - */
 4+*
 5+* @package MediaWiki
 6+* @subpackage SpecialPage
 7+*/
88
99 /**
10 - * Constructor
11 - */
 10+* Constructor
 11+*/
1212 function wfSpecialNamespaces()
1313 {
14 - global $wgUser, $wgOut, $wgRequest;
 14+global $wgUser, $wgOut, $wgRequest;
1515
16 - $action = $wgRequest->getVal( 'action' );
17 - $f = new NamespaceForm();
 16+$action = $wgRequest->getVal( 'action' );
 17+$f = new NamespaceForm();
1818
19 - if ( $action == 'submit' && $wgRequest->wasPosted() &&
20 - $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
21 - if($wgRequest->getText('nsAction')=='addnamespaces') {
22 - $f->addNamespaces();
23 - } elseif($wgRequest->getText('nsAction')=='changenamespaces') {
24 - $f->changeNamespaces();
25 - }
26 - } elseif($action == 'delete') {
27 -
28 - $f->deleteNamespace();
 19+if ( $action == 'submit' && $wgRequest->wasPosted() &&
 20+ $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
 21+ if($wgRequest->getText('nsAction')=='addnamespaces') {
 22+ $f->addNamespaces();
 23+ } elseif($wgRequest->getText('nsAction')=='changenamespaces') {
 24+ $f->changeNamespaces();
2925 }
30 - else {
31 - $f->showForm();
32 - }
 26+} elseif($action == 'delete') {
 27+
 28+ $f->deleteNamespace();
3329 }
 30+else {
 31+ $f->showForm();
 32+}
 33+}
3434
3535 /**
36 - *
37 - * @package MediaWiki
38 - * @subpackage SpecialPage
39 - */
 36+*
 37+* @package MediaWiki
 38+* @subpackage SpecialPage
 39+*/
4040 class NamespaceForm {
 41+
 42+function showForm( $errorHeader='', $errorBody='' )
 43+{
 44+ global $wgOut, $wgUser, $wgLang, $wgNamespaces,$wgTitle;
4145
42 - function showForm( $errorHeader='', $errorBody='' )
43 - {
44 - global $wgOut, $wgUser, $wgLang, $wgNamespaces,$wgTitle;
45 -
46 - $wgOut->setPagetitle( wfMsg( "namespaces" ) );
 46+ $wgOut->setPagetitle( wfMsg( "namespaces" ) );
4747
48 - /* In case of an error, we generally just show what went wrong
49 - and continue displaying the main form */
50 - if ( '' != $errorHeader ) {
51 - $wgOut->setSubtitle( wfMsg( "transactionerror" ) );
52 - $wgOut->addHTML( "<p class='error'>".htmlspecialchars($errorHeader)."</P>");
53 - if($errorBody) {
54 - $wgOut->addWikiText($errorBody);
55 - }
 48+ /* In case of an error, we generally just show what went wrong
 49+ and continue displaying the main form */
 50+ if ( '' != $errorHeader ) {
 51+ $wgOut->setSubtitle( wfMsg( "transactionerror" ) );
 52+ $wgOut->addHTML( "<p class='error'>".htmlspecialchars($errorHeader)."</P>");
 53+ if($errorBody) {
 54+ $wgOut->addWikiText($errorBody);
5655 }
57 -
58 - # Standard token to avoid remote form submission exploits
59 - $token = $wgUser->editToken();
60 - $action = $wgTitle->escapeLocalURL( "action=submit" );
61 - $talksuffix = wfEscapeJsString(wfMsgForContent("talkpagesuffix"));
62 -
63 - # For the namespace selection box
64 - $name_array= Namespace::getFormattedDefaultNamespaces();
65 - $noparent=wfMsg('no_parent_namespace');
66 - $name_array[key($name_array)-1]=$noparent;
67 - # Sort for foreach loops
68 - ksort($name_array);
 56+ }
 57+
 58+ # Standard token to avoid remote form submission exploits
 59+ $token = $wgUser->editToken();
 60+ $action = $wgTitle->escapeLocalURL( "action=submit" );
 61+ $talksuffix = wfEscapeJsString(wfMsgForContent("talkpagesuffix"));
 62+
 63+ # For the namespace selection box
 64+ $name_array= Namespace::getFormattedDefaultNamespaces();
 65+ $noparent=wfMsg('no_parent_namespace');
 66+ $name_array[key($name_array)-1]=$noparent;
 67+ # Sort for foreach loops
 68+ ksort($name_array);
6969
70 - $wgOut->addWikiText( wfMsg( "add_namespaces_header" ) );
71 - # Prefill talk namespace field, but only for languages
72 - # where it's not disabled
73 - if($talksuffix != '-') {
74 - $talkpagejs=
 70+ $wgOut->addWikiText( wfMsg( "add_namespaces_header" ) );
 71+ # Prefill talk namespace field, but only for languages
 72+ # where it's not disabled
 73+ if($talksuffix != '-') {
 74+ $talkpagejs=
7575 ' onchange="if(!window.document.addnamespaces.nsTalkName.value && window.document.addnamespaces.nsName.value && window.document.addnamespaces.nsCreateTalk.checked) { window.document.addnamespaces.nsTalkName.value=window.document.addnamespaces.nsName.value+\''.$talksuffix.'\'; }"';
7676
77 - } else {
78 - $talkpagejs='';
79 - }
 77+ } else {
 78+ $talkpagejs='';
 79+ }
8080
81 - $addnshtmlform='
82 -<form name="addnamespaces" method="POST" action="'.$action.'">
 81+ $addnshtmlform='
 82+<form name="addnamespaces" method="post" action="'.$action.'">
8383 <table border="0">
8484 <tr valign="top"><td>
8585 '.wfMsg('add_namespace_default_name').'</td>
8686 <td>
87 -<input type="hidden" name="nsAction" value="addnamespaces">
88 -<input type="text" name="nsName" size="20"'.$talkpagejs.'>
 87+<input type="hidden" name="nsAction" value="addnamespaces" />
 88+<input type="text" name="nsName" size="20"'.$talkpagejs.' />
8989 </td>
9090 </tr>
9191 <tr valign="top">
9292 <td>
93 -'.wfMsg('add_namespace_default_talk').'<br>
 93+'.wfMsg('add_namespace_default_talk').'<br />
9494 </td>
95 -<td>
96 -<input type="text" name="nsTalkName" size="20">
 95+<td><input type="text" name="nsTalkName" size="20" />
9796 </td>
9897 </tr>
9998 <tr>
10099 <td colspan="2">
101 -<label><input type="checkbox" name="nsCreateTalk" checked>
 100+<label><input type="checkbox" name="nsCreateTalk" checked />
102101 '.wfMsg('add_namespace_talk_confirm').'
103102 </label>
104103 </td>
@@ -126,8 +125,8 @@
127126 $namespace_save_changes=wfMsg('namespace_save_changes');
128127
129128 $htmlform=<<<END
130 -<form name="changenamespaces" method="POST" action="{$action}">
131 -<input type="hidden" name="nsAction" value="changenamespaces">
 129+<form name="changenamespaces" method="post" action="{$action}">
 130+<input type="hidden" name="nsAction" value="changenamespaces" />
132131 <input type="hidden" name="wpEditToken" value="{$token}" />
133132 END;
134133 foreach ($wgNamespaces as $ns) {
@@ -158,7 +157,7 @@
159158 }
160159 $namespaceselect_html=<<<END
161160 <tr valign="top"><td colspan="2">
162 -{$namespace_child_of}<br>
 161+{$namespace_child_of}<br />
163162 <select name="ns{$index}Parent" size="1">
164163 {$namespaceselect}
165164 </select>
@@ -170,7 +169,7 @@
171170 {$namespace_support_subpages}
172171 </td>
173172 <td align="right">
174 -<input type="checkbox" name="ns{$index}Subpages" {$subpages}>
 173+<input type="checkbox" name="ns{$index}Subpages" {$subpages} />
175174 </td>
176175 </tr>
177176 END;
@@ -179,7 +178,7 @@
180179 {$namespace_search_by_default}
181180 </td>
182181 <td align="right">
183 -<input type="checkbox" name="ns{$index}Search" {$searchdefault}>
 182+<input type="checkbox" name="ns{$index}Search" {$searchdefault} />
184183 </td>
185184 </tr>
186185 END;
@@ -188,7 +187,7 @@
189188 {$namespace_hide_in_lists}
190189 </td>
191190 <td align="right">
192 -<input type="checkbox" name="ns{$index}Hidden" {$hidden}>
 191+<input type="checkbox" name="ns{$index}Hidden" {$hidden} />
193192 </td>
194193 </tr>
195194 END;
@@ -197,7 +196,7 @@
198197 {$namespace_default_link_prefix}
199198 </td>
200199 <td align="right">
201 -<input type="text" size="10" name="ns{$index}Linkprefix" value="{$linkprefix}">
 200+<input type="text" size="10" name="ns{$index}Linkprefix" value="{$linkprefix}" />
202201 </td>
203202 </tr>
204203 END;
@@ -296,13 +295,13 @@
297296 } else {
298297 $dc="";
299298 }
300 - $default = "<input type=\"radio\" name=\"ns{$index}Default\" value=\"{$nsi}\"{$dc}>";
 299+ $default = "<input type=\"radio\" name=\"ns{$index}Default\" value=\"{$nsi}\"{$dc} />";
301300 if (!is_null($ns->getCanonicalNameIndex()) &&$ns->getCanonicalNameIndex()== $nsi) {
302301 $nameinput = $nsname . '<br/><small>'.wfMsg('canonicalname').'</small>';
303302 $delete = 'N/A';
304303 } else {
305 - $nameinput = "<input name=\"ns{$index}Name{$nsi}\" size=\"20\" value=\"{$nsname}\">";
306 - $delete = "<input name=\"ns{$index}Delete{$nsi}\" type=\"checkbox\" value=\"1\">";
 304+ $nameinput = "<input name=\"ns{$index}Name{$nsi}\" size=\"20\" value=\"{$nsname}\" />";
 305+ $delete = "<input name=\"ns{$index}Delete{$nsi}\" type=\"checkbox\" value=\"1\" />";
307306 }
308307 $htmlform.=
309308 <<<END
@@ -333,10 +332,10 @@
334333 <<<END
335334 <tr valign="top">
336335 <td width="300">
337 -<input name="ns{$index}NewName{$i}" size="20" value="">
 336+<input name="ns{$index}NewName{$i}" size="20" value="" />
338337 </td>
339338 <td align="center">
340 -<input type="radio" name="ns{$index}Default" value="{$i}">
 339+<input type="radio" name="ns{$index}Default" value="{$i}" />
341340 </td>
342341 <td align="center">
343342 &nbsp;
@@ -345,12 +344,12 @@
346345 END;
347346 }
348347 $htmlform .= '</table></td></tr>';
349 - $htmlform .= '<tr><td colspan="2"><hr noshade></td></tr>';
 348+ $htmlform .= '<tr><td colspan="2"><hr noshade /></td></tr>';
350349 }
351350 $htmlform.=
352351 <<<END
353352 <tr><td>
354 -<input type="submit" value="{$namespace_save_changes}">
 353+<input type="submit" value="{$namespace_save_changes}" />
355354 </td></tr>
356355 </table>
357356 </form>

Status & tagging log