r83036 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83035‎ | r83036 | r83037 >
Date:19:21, 1 March 2011
Author:yaron
Status:deferred
Tags:
Comment:
Improved PHP, replaced some hardcoded HTML with calls to the Xml class
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_ParserFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_ParserFunctions.php
@@ -158,29 +158,30 @@
159159 $param_name = trim( $elements[0] );
160160 $value = trim( $parser->recursiveTagParse( $elements[1] ) );
161161 }
162 - if ( $param_name == 'form' )
 162+ if ( $param_name == 'form' ) {
163163 $inFormName = $value;
164 - elseif ( $param_name == 'link text' )
 164+ } elseif ( $param_name == 'link text' ) {
165165 $inLinkStr = $value;
166 - elseif ( $param_name == 'link type' )
 166+ } elseif ( $param_name == 'link type' ) {
167167 $inLinkType = $value;
168 - elseif ( $param_name == 'query string' )
 168+ } elseif ( $param_name == 'query string' ) {
169169 $inQueryStr = $value;
170 - elseif ( $param_name == 'target' )
 170+ } elseif ( $param_name == 'target' ) {
171171 $inTargetName = $value;
172 - elseif ( $param_name == null && $value == 'popup'
 172+ } elseif ( $param_name == null && $value == 'popup'
173173 && version_compare( $wgVersion, '1.16', '>=' )) {
174174 self::loadScriptsForPopupForm( $parser );
175175 $popupClassString = 'class="popupformlink"';
176176 }
177 - elseif ( $i == 0 )
 177+ elseif ( $i == 0 ) {
178178 $inFormName = $param;
179 - elseif ( $i == 1 )
 179+ } elseif ( $i == 1 ) {
180180 $inLinkStr = $param;
181 - elseif ( $i == 2 )
 181+ } elseif ( $i == 2 ) {
182182 $inLinkType = $param;
183 - elseif ( $i == 3 )
 183+ } elseif ( $i == 3 ) {
184184 $inQueryStr = $param;
 185+ }
185186 }
186187
187188 $ad = SpecialPage::getPage( 'FormEdit' );
@@ -203,7 +204,7 @@
204205 $query_component = urldecode( $query_component );
205206 $var_and_val = explode( '=', $query_component );
206207 if ( count( $var_and_val ) == 2 ) {
207 - $hidden_inputs .= '<input type="hidden" name="' . $var_and_val[0] . '" value="' . $var_and_val[1] . '" /> ';
 208+ $hidden_inputs .= Xml::hidden( $var_and_val[0], $var_and_val[1] ) . "\n";
208209 }
209210 }
210211 } else {
@@ -220,9 +221,16 @@
221222 if ( $inLinkType == 'button' ) {
222223 $link_url = html_entity_decode( $link_url, ENT_QUOTES );
223224 $link_url = str_replace( "'", "\'", $link_url );
224 - $str = "<form $popupClassString><input type=\"button\" value=\"$inLinkStr\" onclick=\"window.location.href='$link_url'\"></form>";
 225+ $str = "<form $popupClassString>";
 226+ $str .= Xml::element( 'input', array(
 227+ 'type' => 'button',
 228+ 'value' => $inLinkStr,
 229+ 'onclick' => 'window.location.href=' . $link_url
 230+ ) ) . "</form>";
225231 } elseif ( $inLinkType == 'post button' ) {
226 - $str = "<form action=\"$link_url\" method=\"post\" $popupClassString><input type=\"submit\" value=\"$inLinkStr\" />$hidden_inputs</form>";
 232+ $str = "<form action=\"$link_url\" method=\"post\" $popupClassString>";
 233+ $str .= Xml::element( 'input', array( 'type' => 'submit', 'value' => $inLinkStr ) );
 234+ $str .= "$hidden_inputs</form>";
227235 } else {
228236 $str = "<a href=\"$link_url\" $popupClassString>$inLinkStr</a>";
229237 }
@@ -305,26 +313,37 @@
306314 if ( empty( $inAutocompletionSource ) ) {
307315 $str = <<<END
308316 <form action="$fs_url" method="get" $popupClassString>
309 - <p><input type="text" name="page_name" size="$inSize" value="$inValue" class="formInput" />
 317+ <p>
310318
311319 END;
 320+ $str .= Xml::element( 'input',
 321+ array( 'type' => 'text', 'name' => 'page_name', 'size' => $inSize, 'value' => $inValue, 'class' => 'formInput' ) );
312322 } else {
313323 $str = <<<END
314324 <form name="createbox" action="$fs_url" method="get" $popupClassString>
315 - <p><input type="text" name="page_name" id="input_$input_num" size="$inSize" value="$inValue" class="autocompleteInput createboxInput formInput" autocompletesettings="input_$input_num" />
 325+ <p>
316326
317327 END;
 328+ $str .= Xml::element( 'input', array(
 329+ 'type' => 'text',
 330+ 'name' => 'page_name',
 331+ 'id' => 'input_' . $input_num,
 332+ 'size' => $inSize,
 333+ 'value' => $inValue,
 334+ 'class' => 'autocompleteInput createboxInput formInput',
 335+ 'autocompletesettings' => 'input_' . $input_num
 336+ ) );
318337 }
319338 // if the form start URL looks like "index.php?title=Special:FormStart"
320339 // (i.e., it's in the default URL style), add in the title as a
321340 // hidden value
322341 if ( ( $pos = strpos( $fs_url, "title=" ) ) > - 1 ) {
323 - $str .= ' <input type="hidden" name="title" value="' . urldecode( substr( $fs_url, $pos + 6 ) ) . '">' . "\n";
 342+ $str .= "\t\t\t" . Xml::hidden( "title", urldecode( substr( $fs_url, $pos + 6 ) ) ) . "\n";
324343 }
325344 if ( $inFormName == '' ) {
326345 $str .= SFUtils::formDropdownHTML();
327346 } else {
328 - $str .= ' <input type="hidden" name="form" value="' . $inFormName . '">' . "\n";
 347+ $str .= "\t\t\t" . Xml::hidden( "form", $inFormName ) . "\n";
329348 }
330349 // Recreate the passed-in query string as a set of hidden
331350 // variables.