Some escaping fixes and related readability changes
authorNiklas Laxström <nikerabbit@users.mediawiki.org>
Mon, 13 Jul 2009 10:34:31 +0000 (10:34 +0000)
committerNiklas Laxström <nikerabbit@users.mediawiki.org>
Mon, 13 Jul 2009 10:34:31 +0000 (10:34 +0000)
includes/SkinTemplate.php
includes/specials/SpecialAllpages.php
includes/specials/SpecialBlockip.php
includes/specials/SpecialDeletedContributions.php
includes/specials/SpecialFileDuplicateSearch.php
includes/specials/SpecialListUserRestrictions.php [new file with mode: 0644]
includes/specials/SpecialMIMEsearch.php
includes/specials/SpecialNewimages.php
includes/specials/SpecialUpload.php
languages/messages/MessagesEn.php

index 3c48582..edfdf0f 100644 (file)
@@ -324,6 +324,7 @@ class SkinTemplate extends Skin {
                                $out->setSquidMaxage( 0 );
                        }
                } else if( count( $newtalks ) ) {
+                       // _>" " for BC <= 1.16
                        $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
                        $msgs = array();
                        foreach( $newtalks as $newtalk ) {
index 1868935..89f5d34 100644 (file)
@@ -391,7 +391,7 @@ class SpecialAllpages extends IncludableSpecialPage {
 
                                $prevLink = $sk->linkKnown(
                                        $self,
-                                       wfMsgHTML( 'prevpage', htmlspecialchars( $pt ) ),
+                                       htmlspecialchars( wfMsg( 'prevpage', $pt ) ),
                                        array(),
                                        $query
                                );
@@ -408,7 +408,7 @@ class SpecialAllpages extends IncludableSpecialPage {
 
                                $nextLink = $sk->linkKnown(
                                        $self,
-                                       wfMsgHtml( 'nextpage', htmlspecialchars( $t->getText() ) ),
+                                       htmlspecialchars( wfMsg( 'nextpage', $t->getText() ) ),
                                        array(),
                                        $query
                                );
index a816aab..559c688 100644 (file)
@@ -671,15 +671,15 @@ class IPBlockForm {
                $query = array( 'action' => 'unblock' );
 
                if( $this->BlockAddress ) {
-                       $addr = htmlspecialchars( strtr( $this->BlockAddress, '_', ' ' ) );
-                       $message = wfMsgHtml( 'ipb-unblock-addr', $addr );
+                       $addr = strtr( $this->BlockAddress, '_', ' ' );
+                       $message = wfMsg( 'ipb-unblock-addr', $addr );
                        $query['ip'] = $this->BlockAddress;
                } else {
-                       $message = wfMsgHtml( 'ipb-unblock' );
+                       $message = wfMsg( 'ipb-unblock' );
                }
                return $skin->linkKnown(
                        $list,
-                       $message,
+                       htmlspecialchars($message),
                        array(),
                        $query
                );
@@ -696,16 +696,16 @@ class IPBlockForm {
                $query = array();
 
                if( $this->BlockAddress ) {
-                       $addr = htmlspecialchars( strtr( $this->BlockAddress, '_', ' ' ) );
-                       $message = wfMsgHtml( 'ipb-blocklist-addr', $addr );
+                       $addr = strtr( $this->BlockAddress, '_', ' ' );
+                       $message = wfMsg( 'ipb-blocklist-addr', $addr );
                        $query['ip'] = $this->BlockAddress;
                } else {
-                       $message = wfMsgHtml( 'ipb-blocklist' );
+                       $message = wfMsg( 'ipb-blocklist' );
                }
 
                return $skin->linkKnown(
                        $list,
-                       $message,
+                       htmlspecialchars($message),
                        array(),
                        $query
                );
index e0b1161..c57b2d5 100644 (file)
@@ -71,9 +71,10 @@ class DeletedContribsPager extends IndexPager {
                if ( isset( $this->mNavigationBar ) ) {
                        return $this->mNavigationBar;
                }
+               $fmtLimit = $wgLang->formatNum( $this->mLimit );
                $linkTexts = array(
-                       'prev' => wfMsgHtml( 'pager-newer-n', $this->mLimit ),
-                       'next' => wfMsgHtml( 'pager-older-n', $this->mLimit ),
+                       'prev' => wfMsgExt( 'pager-newer-n', array( 'escape', 'parsemag' ), $fmtLimit ),
+                       'next' => wfMsgExt( 'pager-older-n', array( 'escape', 'parsemag' ), $fmtLimit ),
                        'first' => wfMsgHtml( 'histlast' ),
                        'last' => wfMsgHtml( 'histfirst' )
                );
index 7166693..b86fcbe 100644 (file)
@@ -125,14 +125,14 @@ function wfSpecialFileDuplicateSearch( $par = null ) {
 
                # Show a short summary
                if( $count == 1 ) {
-                       $wgOut->addHTML( '<p class="mw-fileduplicatesearch-result-1">' .
-                               wfMsgHtml( 'fileduplicatesearch-result-1', $filename ) .
-                               '</p>'
+                       $wgOut->wrapWikiMsg(
+                               "<p class='mw-fileduplicatesearch-result-1'>\n$1\n</p>",
+                               array( 'fileduplicatesearch-result-1', $filename )
                        );
                } elseif ( $count > 1 ) {
-                       $wgOut->addHTML( '<p class="mw-fileduplicatesearch-result-n">' .
-                               wfMsgExt( 'fileduplicatesearch-result-n', array( 'parseinline' ), $filename, $wgLang->formatNum( $count - 1 ) ) .
-                               '</p>'
+                       $wgOut->wrapWikiMsg(
+                               "<p class='mw-fileduplicatesearch-result-n'>\n$1\n</p>",
+                               array( 'fileduplicatesearch-result-n', $filename, $wgLang->formatNum( $count - 1 ) )
                        );
                }
        }
diff --git a/includes/specials/SpecialListUserRestrictions.php b/includes/specials/SpecialListUserRestrictions.php
new file mode 100644 (file)
index 0000000..e900e98
--- /dev/null
@@ -0,0 +1,164 @@
+<?php
+
+function wfSpecialListUserRestrictions() {
+       global $wgOut, $wgRequest;
+       
+       $wgOut->addWikiMsg( 'listuserrestrictions-intro' );
+       $f = new SpecialListUserRestrictionsForm();
+       $wgOut->addHTML( $f->getHTML() );
+
+       if( !mt_rand( 0, 10 ) )
+               UserRestriction::purgeExpired();
+       $pager = new UserRestrictionsPager( $f->getConds() );
+       if( $pager->getNumRows() ) 
+               $wgOut->addHTML( $pager->getNavigationBar() .
+                       Xml::tags( 'ul', null, $pager->getBody() ) .
+                       $pager->getNavigationBar()
+               );
+       elseif( $f->getConds() )
+               $wgOut->addWikiMsg( 'listuserrestrictions-notfound' );
+       else 
+               $wgOut->addWikiMsg( 'listuserrestrictions-empty' );
+}
+
+class SpecialListUserRestrictionsForm {
+       public function getHTML() {
+               global $wgRequest, $wgScript;
+               $action = htmlspecialchars( $wgScript );
+               $s = '';
+               $s .= Xml::fieldset( wfMsg( 'listuserrestrictions-legend' ) );
+               $s .= "<form action=\"{$action}\">";
+               $s .= Xml::hidden( 'title', SpecialPage::getTitleFor('ListUserRestrictions')->getPrefixedDbKey() );
+               $s .= Xml::label( wfMsg( 'listuserrestrictions-type' ), 'type' ) . '&nbsp;' .
+                       self::typeSelector( 'type', $wgRequest->getVal( 'type' ), 'type' );
+               $s .= '&nbsp;';
+               $s .= Xml::inputLabel( wfMsg( 'listuserrestrictions-user' ), 'user', 'user',
+                       false, $wgRequest->getVal( 'user' ) );
+               $s .= '<p>';
+               $s .= Xml::label( wfMsg( 'listuserrestrictions-namespace' ), 'namespace' ) . '&nbsp;' .
+                       Xml::namespaceSelector( $wgRequest->getVal( 'namespace' ), '', 'namespace' );
+               $s .= '&nbsp;';
+               $s .= Xml::inputLabel( wfMsg( 'listuserrestrictions-page' ), 'page', 'page',
+                       false, $wgRequest->getVal( 'page' ) );
+               $s .= Xml::submitButton( wfMsg( 'listuserrestrictions-submit' ) );
+               $s .= "</p></form></fieldset>";
+               return $s;
+       }
+
+       public static function typeSelector( $name = 'type', $value = '', $id = false ) {
+               $s = new XmlSelect( $name, $id, $value );
+               $s->addOption( wfMsg( 'userrestrictiontype-none' ), '' );
+               $s->addOption( wfMsg( 'userrestrictiontype-page' ), UserRestriction::PAGE );
+               $s->addOption( wfMsg( 'userrestrictiontype-namespace' ), UserRestriction::NAMESPACE );
+               return $s->getHTML();
+       }
+
+       public function getConds() {
+               global $wgRequest;
+               $conds = array();
+
+               $type = $wgRequest->getVal( 'type' );
+               if( in_array( $type, array( UserRestriction::PAGE, UserRestriction::NAMESPACE ) ) )
+                       $conds['ur_type'] = $type;
+
+               $user = $wgRequest->getVal( 'user' );
+               if( $user )
+                       $conds['ur_user_text'] = $user;
+
+               $namespace = $wgRequest->getVal( 'namespace' );
+               if( $namespace || $namespace === '0' )
+                       $conds['ur_namespace'] = $namespace;
+
+               $page = $wgRequest->getVal( 'page' );
+               $title = Title::newFromText( $page );
+               if( $title ) {
+                       $conds['ur_page_namespace'] = $title->getNamespace();
+                       $conds['ur_page_title'] = $title->getDBkey();
+               }
+
+               return $conds;
+       }
+}
+
+class UserRestrictionsPager extends ReverseChronologicalPager {
+       public $mConds;
+
+       public function __construct( $conds = array() ) {
+               $this->mConds = $conds;
+               parent::__construct();
+       }
+
+       public function getStartBody() {
+               # Copied from Special:Ipblocklist
+               wfProfileIn( __METHOD__ );
+               # Do a link batch query
+               $this->mResult->seek( 0 );
+               $lb = new LinkBatch;
+
+               # Faster way
+               # Usernames and titles are in fact related by a simple substitution of space -> underscore
+               # The last few lines of Title::secureAndSplit() tell the story.
+               foreach( $this->mResult as $row ) {
+                       $name = str_replace( ' ', '_', $row->ur_by_text );
+                       $lb->add( NS_USER, $name );
+                       $lb->add( NS_USER_TALK, $name );
+                       $name = str_replace( ' ', '_', $row->ur_user_text );
+                       $lb->add( NS_USER, $name );
+                       $lb->add( NS_USER_TALK, $name );
+                       if( $row->ur_type == UserRestriction::PAGE )
+                               $lb->add( $row->ur_page_namespace, $row->ur_page_title );
+               }
+               $lb->execute();
+               wfProfileOut( __METHOD__ );
+               return '';
+       }
+
+       public function getQueryInfo() {
+               return array(
+                       'tables' => 'user_restrictions',
+                       'fields' => '*',
+                       'conds' => $this->mConds,
+               );
+       }
+
+       public function formatRow( $row ) {
+               return self::formatRestriction( UserRestriction::newFromRow( $row )  );
+       }
+
+       // Split off for use on Special:RestrictUser
+       public static function formatRestriction( $r ) {
+               global $wgUser, $wgLang;
+               $sk = $wgUser->getSkin();
+               $timestamp = $wgLang->timeanddate( $r->getTimestamp(), true );
+               $blockerlink = $sk->userLink( $r->getBlockerId(), $r->getBlockerText() ) .
+                       $sk->userToolLinks( $r->getBlockerId(), $r->getBlockerText() );
+               $subjlink = $sk->userLink( $r->getSubjectId(), $r->getSubjectText() ) .
+                       $sk->userToolLinks( $r->getSubjectId(), $r->getSubjectText() );
+               $expiry = is_numeric( $r->getExpiry() ) ?
+                       wfMsg( 'listuserrestrictions-row-expiry', $wgLang->timeanddate( $r->getExpiry() ) ) :
+                       wfMsg( 'ipbinfinite' );
+               $msg = '';
+               if( $r->isNamespace() ) {
+                       $msg = wfMsgHtml( 'listuserrestrictions-row-ns', $subjlink,
+                               htmlspecialchars( $wgLang->getDisplayNsText( $r->getNamespace() ) ),
+                               htmlspecialchars( $expiry )
+                       );
+               }
+               if( $r->isPage() ) {
+                       $pagelink = $sk->link( $r->getPage() );
+                       $msg = wfMsgHtml( 'listuserrestrictions-row-page', $subjlink,
+                               $pagelink, htmlspecialchars( $expiry ) );
+               }
+               $reason = $sk->commentBlock( $r->getReason() );
+               $removelink = '';
+               if( $wgUser->isAllowed( 'restrict' ) ) {
+                       $removelink = '(' . $sk->link( SpecialPage::getTitleFor( 'RemoveRestrictions' ),
+                               wfMsgHtml( 'listuserrestrictions-remove' ), array(), array( 'id' => $r->getId() ) ) . ')';
+               }
+               return "<li>{$timestamp}, {$blockerlink} {$msg} {$reason} {$removelink}</li>\n";
+       }
+
+       public function getIndexField() {
+               return 'ur_timestamp';
+       }
+}
index 194836e..dafe003 100644 (file)
@@ -73,8 +73,10 @@ class MIMEsearchPage extends QueryPage {
                $download = $skin->makeMediaLinkObj( $nt, wfMsgHtml( 'download' ) );
                $bytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape'),
                        $wgLang->formatNum( $result->img_size ) );
-               $dimensions = wfMsgHtml( 'widthheight', $wgLang->formatNum( $result->img_width ),
-                       $wgLang->formatNum( $result->img_height ) );
+               $dimensions = htmlspecialchars( wfMsg( 'widthheight',
+                       $wgLang->formatNum( $result->img_width ),
+                       $wgLang->formatNum( $result->img_height )
+               ) );
                $user = $skin->link( Title::makeTitle( NS_USER, $result->img_user_text ), htmlspecialchars( $result->img_user_text ) );
                $time = htmlspecialchars( $wgLang->timeanddate( $result->img_timestamp ) );
 
index a874773..96fea66 100644 (file)
@@ -188,14 +188,11 @@ function wfSpecialNewimages( $par, $specialPage ) {
                $searchpar
        );
 
-       $message = wfMsgHtml(
-               'showhidebots',
-               ( $hidebots ? wfMsgHtml( 'show' ) : wfMsgHtml( 'hide' ) )
-       );
+       $showhide = $hidebots ? wfMsg( 'show' ) : wfMsg( 'hide' );
 
        $botLink = $sk->linkKnown(
                $titleObj,
-               $message,
+               htmlspecialchars( wfMsg( 'showhidebots', $showhide ) ),
                array(),
                $query
        );
index b78993b..9b28816 100644 (file)
@@ -545,7 +545,7 @@ class UploadForm {
                                $skin = $wgUser->getSkin();
                                $wsize = $skin->formatSize( $wgUploadSizeWarning );
                                $asize = $skin->formatSize( $this->mFileSize );
-                               $warning .= '<li>' . wfMsgHtml( 'large-file', $wsize, $asize ) . '</li>';
+                               $warning .= '<li>' . htmlspecialchars( wfMsg( 'large-file', $wsize, $asize ) ) . '</li>';
                        }
                        if ( $this->mFileSize == 0 ) {
                                $warning .= '<li>'.wfMsgHtml( 'emptyfile' ).'</li>';
index 084c29c..b2c6350 100644 (file)
@@ -889,7 +889,7 @@ See [[Special:Version|version page]].',
 'newmessageslink'              => 'new messages',
 'newmessagesdifflink'          => 'last change',
 'youhavenewmessagesmulti'      => 'You have new messages on $1',
-'newtalkseparator'             => ',_', # do not translate or duplicate this message to other languages
+'newtalkseparator'             => ',&#32;', # do not translate or duplicate this message to other languages
 'editsection'                  => 'edit',
 'editsection-brackets'         => '[$1]', # only translate this message to other languages if you have to change it
 'editold'                      => 'edit',