r53161 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53160‎ | r53161 | r53162 >
Date:10:34, 13 July 2009
Author:nikerabbit
Status:resolved
Tags:
Comment:
Some escaping fixes and related readability changes
Modified paths:
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialAllpages.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialBlockip.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialDeletedContributions.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialFileDuplicateSearch.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialListUserRestrictions.php (added) (history)
  • /trunk/phase3/includes/specials/SpecialMIMEsearch.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialNewimages.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUpload.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SkinTemplate.php
@@ -324,6 +324,7 @@
325325 $out->setSquidMaxage( 0 );
326326 }
327327 } else if( count( $newtalks ) ) {
 328+ // _>" " for BC <= 1.16
328329 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
329330 $msgs = array();
330331 foreach( $newtalks as $newtalk ) {
Index: trunk/phase3/includes/specials/SpecialListUserRestrictions.php
@@ -0,0 +1,164 @@
 2+<?php
 3+
 4+function wfSpecialListUserRestrictions() {
 5+ global $wgOut, $wgRequest;
 6+
 7+ $wgOut->addWikiMsg( 'listuserrestrictions-intro' );
 8+ $f = new SpecialListUserRestrictionsForm();
 9+ $wgOut->addHTML( $f->getHTML() );
 10+
 11+ if( !mt_rand( 0, 10 ) )
 12+ UserRestriction::purgeExpired();
 13+ $pager = new UserRestrictionsPager( $f->getConds() );
 14+ if( $pager->getNumRows() )
 15+ $wgOut->addHTML( $pager->getNavigationBar() .
 16+ Xml::tags( 'ul', null, $pager->getBody() ) .
 17+ $pager->getNavigationBar()
 18+ );
 19+ elseif( $f->getConds() )
 20+ $wgOut->addWikiMsg( 'listuserrestrictions-notfound' );
 21+ else
 22+ $wgOut->addWikiMsg( 'listuserrestrictions-empty' );
 23+}
 24+
 25+class SpecialListUserRestrictionsForm {
 26+ public function getHTML() {
 27+ global $wgRequest, $wgScript;
 28+ $action = htmlspecialchars( $wgScript );
 29+ $s = '';
 30+ $s .= Xml::fieldset( wfMsg( 'listuserrestrictions-legend' ) );
 31+ $s .= "<form action=\"{$action}\">";
 32+ $s .= Xml::hidden( 'title', SpecialPage::getTitleFor('ListUserRestrictions')->getPrefixedDbKey() );
 33+ $s .= Xml::label( wfMsg( 'listuserrestrictions-type' ), 'type' ) . '&nbsp;' .
 34+ self::typeSelector( 'type', $wgRequest->getVal( 'type' ), 'type' );
 35+ $s .= '&nbsp;';
 36+ $s .= Xml::inputLabel( wfMsg( 'listuserrestrictions-user' ), 'user', 'user',
 37+ false, $wgRequest->getVal( 'user' ) );
 38+ $s .= '<p>';
 39+ $s .= Xml::label( wfMsg( 'listuserrestrictions-namespace' ), 'namespace' ) . '&nbsp;' .
 40+ Xml::namespaceSelector( $wgRequest->getVal( 'namespace' ), '', 'namespace' );
 41+ $s .= '&nbsp;';
 42+ $s .= Xml::inputLabel( wfMsg( 'listuserrestrictions-page' ), 'page', 'page',
 43+ false, $wgRequest->getVal( 'page' ) );
 44+ $s .= Xml::submitButton( wfMsg( 'listuserrestrictions-submit' ) );
 45+ $s .= "</p></form></fieldset>";
 46+ return $s;
 47+ }
 48+
 49+ public static function typeSelector( $name = 'type', $value = '', $id = false ) {
 50+ $s = new XmlSelect( $name, $id, $value );
 51+ $s->addOption( wfMsg( 'userrestrictiontype-none' ), '' );
 52+ $s->addOption( wfMsg( 'userrestrictiontype-page' ), UserRestriction::PAGE );
 53+ $s->addOption( wfMsg( 'userrestrictiontype-namespace' ), UserRestriction::NAMESPACE );
 54+ return $s->getHTML();
 55+ }
 56+
 57+ public function getConds() {
 58+ global $wgRequest;
 59+ $conds = array();
 60+
 61+ $type = $wgRequest->getVal( 'type' );
 62+ if( in_array( $type, array( UserRestriction::PAGE, UserRestriction::NAMESPACE ) ) )
 63+ $conds['ur_type'] = $type;
 64+
 65+ $user = $wgRequest->getVal( 'user' );
 66+ if( $user )
 67+ $conds['ur_user_text'] = $user;
 68+
 69+ $namespace = $wgRequest->getVal( 'namespace' );
 70+ if( $namespace || $namespace === '0' )
 71+ $conds['ur_namespace'] = $namespace;
 72+
 73+ $page = $wgRequest->getVal( 'page' );
 74+ $title = Title::newFromText( $page );
 75+ if( $title ) {
 76+ $conds['ur_page_namespace'] = $title->getNamespace();
 77+ $conds['ur_page_title'] = $title->getDBkey();
 78+ }
 79+
 80+ return $conds;
 81+ }
 82+}
 83+
 84+class UserRestrictionsPager extends ReverseChronologicalPager {
 85+ public $mConds;
 86+
 87+ public function __construct( $conds = array() ) {
 88+ $this->mConds = $conds;
 89+ parent::__construct();
 90+ }
 91+
 92+ public function getStartBody() {
 93+ # Copied from Special:Ipblocklist
 94+ wfProfileIn( __METHOD__ );
 95+ # Do a link batch query
 96+ $this->mResult->seek( 0 );
 97+ $lb = new LinkBatch;
 98+
 99+ # Faster way
 100+ # Usernames and titles are in fact related by a simple substitution of space -> underscore
 101+ # The last few lines of Title::secureAndSplit() tell the story.
 102+ foreach( $this->mResult as $row ) {
 103+ $name = str_replace( ' ', '_', $row->ur_by_text );
 104+ $lb->add( NS_USER, $name );
 105+ $lb->add( NS_USER_TALK, $name );
 106+ $name = str_replace( ' ', '_', $row->ur_user_text );
 107+ $lb->add( NS_USER, $name );
 108+ $lb->add( NS_USER_TALK, $name );
 109+ if( $row->ur_type == UserRestriction::PAGE )
 110+ $lb->add( $row->ur_page_namespace, $row->ur_page_title );
 111+ }
 112+ $lb->execute();
 113+ wfProfileOut( __METHOD__ );
 114+ return '';
 115+ }
 116+
 117+ public function getQueryInfo() {
 118+ return array(
 119+ 'tables' => 'user_restrictions',
 120+ 'fields' => '*',
 121+ 'conds' => $this->mConds,
 122+ );
 123+ }
 124+
 125+ public function formatRow( $row ) {
 126+ return self::formatRestriction( UserRestriction::newFromRow( $row ) );
 127+ }
 128+
 129+ // Split off for use on Special:RestrictUser
 130+ public static function formatRestriction( $r ) {
 131+ global $wgUser, $wgLang;
 132+ $sk = $wgUser->getSkin();
 133+ $timestamp = $wgLang->timeanddate( $r->getTimestamp(), true );
 134+ $blockerlink = $sk->userLink( $r->getBlockerId(), $r->getBlockerText() ) .
 135+ $sk->userToolLinks( $r->getBlockerId(), $r->getBlockerText() );
 136+ $subjlink = $sk->userLink( $r->getSubjectId(), $r->getSubjectText() ) .
 137+ $sk->userToolLinks( $r->getSubjectId(), $r->getSubjectText() );
 138+ $expiry = is_numeric( $r->getExpiry() ) ?
 139+ wfMsg( 'listuserrestrictions-row-expiry', $wgLang->timeanddate( $r->getExpiry() ) ) :
 140+ wfMsg( 'ipbinfinite' );
 141+ $msg = '';
 142+ if( $r->isNamespace() ) {
 143+ $msg = wfMsgHtml( 'listuserrestrictions-row-ns', $subjlink,
 144+ htmlspecialchars( $wgLang->getDisplayNsText( $r->getNamespace() ) ),
 145+ htmlspecialchars( $expiry )
 146+ );
 147+ }
 148+ if( $r->isPage() ) {
 149+ $pagelink = $sk->link( $r->getPage() );
 150+ $msg = wfMsgHtml( 'listuserrestrictions-row-page', $subjlink,
 151+ $pagelink, htmlspecialchars( $expiry ) );
 152+ }
 153+ $reason = $sk->commentBlock( $r->getReason() );
 154+ $removelink = '';
 155+ if( $wgUser->isAllowed( 'restrict' ) ) {
 156+ $removelink = '(' . $sk->link( SpecialPage::getTitleFor( 'RemoveRestrictions' ),
 157+ wfMsgHtml( 'listuserrestrictions-remove' ), array(), array( 'id' => $r->getId() ) ) . ')';
 158+ }
 159+ return "<li>{$timestamp}, {$blockerlink} {$msg} {$reason} {$removelink}</li>\n";
 160+ }
 161+
 162+ public function getIndexField() {
 163+ return 'ur_timestamp';
 164+ }
 165+}
Property changes on: trunk/phase3/includes/specials/SpecialListUserRestrictions.php
___________________________________________________________________
Added: svn:eol-style
1166 + native
Index: trunk/phase3/includes/specials/SpecialAllpages.php
@@ -391,7 +391,7 @@
392392
393393 $prevLink = $sk->linkKnown(
394394 $self,
395 - wfMsgHTML( 'prevpage', htmlspecialchars( $pt ) ),
 395+ htmlspecialchars( wfMsg( 'prevpage', $pt ) ),
396396 array(),
397397 $query
398398 );
@@ -408,7 +408,7 @@
409409
410410 $nextLink = $sk->linkKnown(
411411 $self,
412 - wfMsgHtml( 'nextpage', htmlspecialchars( $t->getText() ) ),
 412+ htmlspecialchars( wfMsg( 'nextpage', $t->getText() ) ),
413413 array(),
414414 $query
415415 );
Index: trunk/phase3/includes/specials/SpecialFileDuplicateSearch.php
@@ -125,14 +125,14 @@
126126
127127 # Show a short summary
128128 if( $count == 1 ) {
129 - $wgOut->addHTML( '<p class="mw-fileduplicatesearch-result-1">' .
130 - wfMsgHtml( 'fileduplicatesearch-result-1', $filename ) .
131 - '</p>'
 129+ $wgOut->wrapWikiMsg(
 130+ "<p class='mw-fileduplicatesearch-result-1'>\n$1\n</p>",
 131+ array( 'fileduplicatesearch-result-1', $filename )
132132 );
133133 } elseif ( $count > 1 ) {
134 - $wgOut->addHTML( '<p class="mw-fileduplicatesearch-result-n">' .
135 - wfMsgExt( 'fileduplicatesearch-result-n', array( 'parseinline' ), $filename, $wgLang->formatNum( $count - 1 ) ) .
136 - '</p>'
 134+ $wgOut->wrapWikiMsg(
 135+ "<p class='mw-fileduplicatesearch-result-n'>\n$1\n</p>",
 136+ array( 'fileduplicatesearch-result-n', $filename, $wgLang->formatNum( $count - 1 ) )
137137 );
138138 }
139139 }
Index: trunk/phase3/includes/specials/SpecialNewimages.php
@@ -188,14 +188,11 @@
189189 $searchpar
190190 );
191191
192 - $message = wfMsgHtml(
193 - 'showhidebots',
194 - ( $hidebots ? wfMsgHtml( 'show' ) : wfMsgHtml( 'hide' ) )
195 - );
 192+ $showhide = $hidebots ? wfMsg( 'show' ) : wfMsg( 'hide' );
196193
197194 $botLink = $sk->linkKnown(
198195 $titleObj,
199 - $message,
 196+ htmlspecialchars( wfMsg( 'showhidebots', $showhide ) ),
200197 array(),
201198 $query
202199 );
Index: trunk/phase3/includes/specials/SpecialUpload.php
@@ -545,7 +545,7 @@
546546 $skin = $wgUser->getSkin();
547547 $wsize = $skin->formatSize( $wgUploadSizeWarning );
548548 $asize = $skin->formatSize( $this->mFileSize );
549 - $warning .= '<li>' . wfMsgHtml( 'large-file', $wsize, $asize ) . '</li>';
 549+ $warning .= '<li>' . htmlspecialchars( wfMsg( 'large-file', $wsize, $asize ) ) . '</li>';
550550 }
551551 if ( $this->mFileSize == 0 ) {
552552 $warning .= '<li>'.wfMsgHtml( 'emptyfile' ).'</li>';
Index: trunk/phase3/includes/specials/SpecialMIMEsearch.php
@@ -73,8 +73,10 @@
7474 $download = $skin->makeMediaLinkObj( $nt, wfMsgHtml( 'download' ) );
7575 $bytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape'),
7676 $wgLang->formatNum( $result->img_size ) );
77 - $dimensions = wfMsgHtml( 'widthheight', $wgLang->formatNum( $result->img_width ),
78 - $wgLang->formatNum( $result->img_height ) );
 77+ $dimensions = htmlspecialchars( wfMsg( 'widthheight',
 78+ $wgLang->formatNum( $result->img_width ),
 79+ $wgLang->formatNum( $result->img_height )
 80+ ) );
7981 $user = $skin->link( Title::makeTitle( NS_USER, $result->img_user_text ), htmlspecialchars( $result->img_user_text ) );
8082 $time = htmlspecialchars( $wgLang->timeanddate( $result->img_timestamp ) );
8183
Index: trunk/phase3/includes/specials/SpecialBlockip.php
@@ -671,15 +671,15 @@
672672 $query = array( 'action' => 'unblock' );
673673
674674 if( $this->BlockAddress ) {
675 - $addr = htmlspecialchars( strtr( $this->BlockAddress, '_', ' ' ) );
676 - $message = wfMsgHtml( 'ipb-unblock-addr', $addr );
 675+ $addr = strtr( $this->BlockAddress, '_', ' ' );
 676+ $message = wfMsg( 'ipb-unblock-addr', $addr );
677677 $query['ip'] = $this->BlockAddress;
678678 } else {
679 - $message = wfMsgHtml( 'ipb-unblock' );
 679+ $message = wfMsg( 'ipb-unblock' );
680680 }
681681 return $skin->linkKnown(
682682 $list,
683 - $message,
 683+ htmlspecialchars($message),
684684 array(),
685685 $query
686686 );
@@ -696,16 +696,16 @@
697697 $query = array();
698698
699699 if( $this->BlockAddress ) {
700 - $addr = htmlspecialchars( strtr( $this->BlockAddress, '_', ' ' ) );
701 - $message = wfMsgHtml( 'ipb-blocklist-addr', $addr );
 700+ $addr = strtr( $this->BlockAddress, '_', ' ' );
 701+ $message = wfMsg( 'ipb-blocklist-addr', $addr );
702702 $query['ip'] = $this->BlockAddress;
703703 } else {
704 - $message = wfMsgHtml( 'ipb-blocklist' );
 704+ $message = wfMsg( 'ipb-blocklist' );
705705 }
706706
707707 return $skin->linkKnown(
708708 $list,
709 - $message,
 709+ htmlspecialchars($message),
710710 array(),
711711 $query
712712 );
Index: trunk/phase3/includes/specials/SpecialDeletedContributions.php
@@ -71,9 +71,10 @@
7272 if ( isset( $this->mNavigationBar ) ) {
7373 return $this->mNavigationBar;
7474 }
 75+ $fmtLimit = $wgLang->formatNum( $this->mLimit );
7576 $linkTexts = array(
76 - 'prev' => wfMsgHtml( 'pager-newer-n', $this->mLimit ),
77 - 'next' => wfMsgHtml( 'pager-older-n', $this->mLimit ),
 77+ 'prev' => wfMsgExt( 'pager-newer-n', array( 'escape', 'parsemag' ), $fmtLimit ),
 78+ 'next' => wfMsgExt( 'pager-older-n', array( 'escape', 'parsemag' ), $fmtLimit ),
7879 'first' => wfMsgHtml( 'histlast' ),
7980 'last' => wfMsgHtml( 'histfirst' )
8081 );
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -889,7 +889,7 @@
890890 'newmessageslink' => 'new messages',
891891 'newmessagesdifflink' => 'last change',
892892 'youhavenewmessagesmulti' => 'You have new messages on $1',
893 -'newtalkseparator' => ',_', # do not translate or duplicate this message to other languages
 893+'newtalkseparator' => ',&#32;', # do not translate or duplicate this message to other languages
894894 'editsection' => 'edit',
895895 'editsection-brackets' => '[$1]', # only translate this message to other languages if you have to change it
896896 'editold' => 'edit',

Status & tagging log