r9555 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r9554‎ | r9555 | r9556 >
Date:21:35, 21 June 2005
Author:vibber
Status:old
Tags:
Comment:
Make an attempt to fix some more problems:
* incorrect escaping of URL components
* missing escaping of URLs in <a href> tags
* don't try to place HTML-formatted wikitext into a single-quoted attribute value
* an odd str_replace
* some other XHTML bits
Modified paths:
  • /trunk/phase3/includes/SpecialValidate.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialValidate.php
@@ -52,7 +52,7 @@
5353 function getVersionLink( &$article, $revision, $text = "" ) {
5454 $t = $article->getTitle();
5555 if( $text == "" ) $text = wfMsg("val_view_version");
56 - $ret = "<a href=\"" . $t->getLocalURL( htmlspecialchars("oldid={$revision}" )) . "\">" . $this->getParsedWiki($text) . "</a>";
 56+ $ret = "<a href=\"" . $t->escapeLocalURL( "oldid={$revision}" ) . "\">" . $this->getParsedWiki($text) . "</a>";
5757 return $ret;
5858 }
5959
@@ -281,7 +281,7 @@
282282 $user = $wgUser->GetName();
283283 }
284284 $nt = Title::newFromText( "Special:Validate" );
285 - $url = $nt->getLocalURL( "mode=userstats&user=" . htmlspecialchars ( $user ) );
 285+ $url = $nt->escapeLocalURL( "mode=userstats&user=" . urlencode( $user ) );
286286 return "<a href=\"{$url}\">{$text}</a>";
287287 }
288288
@@ -315,29 +315,32 @@
316316 $u->setId( $x->rev_user );
317317 $u->setName( $x->rev_user_text );
318318 $nt = $u->getUserPage();
319 - $url = "<a href='" . $nt->getLocalUrl() . "'>" . $nt->getText() . "</a>";
 319+ # FIXME: Why doesn't this use standard linking code?
 320+ $url = "<a href='" . $nt->escapeLocalUrl() . "'>" . htmlspecialchars( $nt->getText() ) . "</a>";
320321 $metadata .= $url;
321322 }
 323+ # FIXME: Why doesn't this use standard comment formatting?
322324 $metadata .= " : <small>\"" . $this->getParsedWiki( $x->rev_comment ) . "\"</small>";
323325 return $metadata;
324326 }
325327
326328 # Generates a link to the topic description
327329 function linkTopic ( $s ) {
 330+ # FIXME: Why doesn't this use standard linking code?
328331 $t = Title::newFromText ( wfMsg ( 'val_topic_desc_page' ) ) ;
329332 $r = "<a href=\"" ;
330 - $r .= $t->getLocalURL () ;
 333+ $r .= $t->escapeLocalURL () ;
331334 $r .= "#" . urlencode ( $s ) ;
332335 $r .= "\">{$s}</a>" ;
333336 return $r ;
334 - }
 337+ }
335338
336339 # Generates HTML from a wiki text, e.g., a wfMsg
337340 function getParsedWiki ( $text ) {
338341 global $wgOut , $wgTitle, $wgParser ;
339342 $parserOutput = $wgParser->parse( $text , $wgTitle, $wgOut->mParserOptions,false);
340343 return $parserOutput->getText() ;
341 - }
 344+ }
342345
343346 # Generates a form for a single revision
344347 function getRevisionForm( &$article, $idx, &$data, $focus = false ) {
@@ -381,9 +384,9 @@
382385 }
383386 $vote .= "<input type='radio' name='re_v{$idx}' value='{$a}'";
384387 if( $a == $y->value ) {
385 - $vote .= " checked";
 388+ $vote .= " checked='checked'";
386389 }
387 - $vote .= "/>";
 390+ $vote .= " />";
388391 if( $max == 2 && $a == 1 ) {
389392 $vote .= wfMsg( "val_no" ) . " ";
390393 } elseif( $max == 2 && $a == 2 ) {
@@ -402,9 +405,9 @@
403406 }
404407 $checked = $focus ? " checked='checked'" : "";
405408 $ret .= "<tr><td colspan='3' valign='center'>\n";
406 - $ret .= "<input type='checkbox' name='re_merge_{$revision}' value='1'{$checked}/>" . $this->getParsedWiki( wfMsg( 'val_merge_old' ) ) . " \n";
407 - $ret .= "<input type='checkbox' name='re_clear_{$revision}' value='1'{$checked}/>" . $this->getParsedWiki( wfMsg( 'val_clear_old' ) ) . " \n";
408 - $ret .= "<input type='submit' name='re_submit[{$revision}]' value='" . $this->getParsedWiki( wfMsg("ok") ) . "'/>\n";
 409+ $ret .= "<input type='checkbox' name='re_merge_{$revision}' value='1'{$checked} />" . $this->getParsedWiki( wfMsg( 'val_merge_old' ) ) . " \n";
 410+ $ret .= "<input type='checkbox' name='re_clear_{$revision}' value='1'{$checked} />" . $this->getParsedWiki( wfMsg( 'val_clear_old' ) ) . " \n";
 411+ $ret .= "<input type='submit' name='re_submit[{$revision}]' value=\"" . wfMsgHtml( "ok" ) . "\" />\n";
409412
410413 if( $focus ) {
411414 $ret .= "<br/>\n<small>" . $this->getParsedWiki ( wfMsg( "val_form_note" ) ) . "</small>";
@@ -440,7 +443,7 @@
441444 }
442445 $ret .= "<p class='revision_saved'>" . $this->getParsedWiki( wfMsg( 'val_revision_changes_ok' ) ) . "</p>";
443446 }
444 - else $ret .= wfMsg ( 'val_votepage_intro' ) ;
 447+ else $ret .= wfMsgHtml ( 'val_votepage_intro' ) ;
445448
446449 # Make sure the requested revision exists
447450 $ts = $this->rev2date[$revision]->rev_timestamp;
@@ -454,7 +457,7 @@
455458 # Output
456459 $title = $article->getTitle();
457460 $title = $title->getPrefixedText();
458 - $wgOut->setPageTitle( str_replace ( '$1' , $title , wfMsg( 'val_rev_for' ) ) );
 461+ $wgOut->setPageTitle( wfMsg( 'val_rev_for', $title ) );
459462 foreach( $this->voteCache as $x => $y ) {
460463 $ret .= $this->getRevisionForm( $article, $x, $y, $x == $ts );
461464 $ret .= "<br/>\n";

Status & tagging log