Merge "Add 路面 for better word segmentation."
[lhc/web/wiklou.git] / includes / specials / SpecialBlock.php
index f35709f..cd467a8 100644 (file)
@@ -143,7 +143,7 @@ class SpecialBlock extends FormSpecialPage {
                                'required' => true,
                                'tabindex' => '2',
                                'options' => self::getSuggestedDurations(),
-                               'other' => wfMsg( 'ipbother' ),
+                               'other' => $this->msg( 'ipbother' )->text(),
                        ),
                        'Reason' => array(
                                'type' => 'selectandother',
@@ -277,7 +277,7 @@ class SpecialBlock extends FormSpecialPage {
                        }
 
                        $this->alreadyBlocked = true;
-                       $this->preErrors[] = array( 'ipb-needreblock', (string)$block->getTarget() );
+                       $this->preErrors[] = array( 'ipb-needreblock', wfEscapeWikiText( (string)$block->getTarget() ) );
                }
 
                # We always need confirmation to do HideUser
@@ -297,8 +297,11 @@ class SpecialBlock extends FormSpecialPage {
 
        /**
         * Add header elements like block log entries, etc.
+        * @return String
         */
        protected function preText(){
+               $this->getOutput()->addModules( 'mediawiki.special.block' );
+
                $text = $this->msg( 'blockiptext' )->parse();
 
                $otherBlockMessages = array();
@@ -310,7 +313,7 @@ class SpecialBlock extends FormSpecialPage {
                                $s = Html::rawElement(
                                        'h2',
                                        array(),
-                                       wfMsgExt( 'ipb-otherblocks-header', 'parseinline', count( $otherBlockMessages ) )
+                                       $this->msg( 'ipb-otherblocks-header', count( $otherBlockMessages ) )->parse()
                                ) . "\n";
 
                                $list = '';
@@ -334,24 +337,26 @@ class SpecialBlock extends FormSpecialPage {
 
        /**
         * Add footer elements to the form
-        * @return void
+        * @return string
         */
        protected function postText(){
+               $links = array();
+
                # Link to the user's contributions, if applicable
                if( $this->target instanceof User ){
                        $contribsPage = SpecialPage::getTitleFor( 'Contributions', $this->target->getName() );
                        $links[] = Linker::link(
                                $contribsPage,
-                               wfMsgExt( 'ipb-blocklist-contribs', 'escape', $this->target->getName() )
+                               $this->msg( 'ipb-blocklist-contribs', $this->target->getName() )->escaped()
                        );
                }
 
                # Link to unblock the specified user, or to a blank unblock form
                if( $this->target instanceof User ) {
-                       $message = wfMsgExt( 'ipb-unblock-addr', array( 'parseinline' ), $this->target->getName() );
+                       $message = $this->msg( 'ipb-unblock-addr', wfEscapeWikiText( $this->target->getName() ) )->parse();
                        $list = SpecialPage::getTitleFor( 'Unblock', $this->target->getName() );
                } else {
-                       $message = wfMsgExt( 'ipb-unblock', array( 'parseinline' ) );
+                       $message = $this->msg( 'ipb-unblock' )->parse();
                        $list = SpecialPage::getTitleFor( 'Unblock' );
                }
                $links[] = Linker::linkKnown( $list, $message, array() );
@@ -359,7 +364,7 @@ class SpecialBlock extends FormSpecialPage {
                # Link to the block list
                $links[] = Linker::linkKnown(
                        SpecialPage::getTitleFor( 'BlockList' ),
-                       wfMsg( 'ipb-blocklist' )
+                       $this->msg( 'ipb-blocklist' )->escaped()
                );
 
                $user = $this->getUser();
@@ -368,7 +373,7 @@ class SpecialBlock extends FormSpecialPage {
                if ( $user->isAllowed( 'editinterface' ) ) {
                        $links[] = Linker::link(
                                Title::makeTitle( NS_MEDIAWIKI, 'Ipbreason-dropdown' ),
-                               wfMsgHtml( 'ipb-edit-dropdown' ),
+                               $this->msg( 'ipb-edit-dropdown' )->escaped(),
                                array(),
                                array( 'action' => 'edit' )
                        );
@@ -377,22 +382,22 @@ class SpecialBlock extends FormSpecialPage {
                $text =  Html::rawElement(
                        'p',
                        array( 'class' => 'mw-ipb-conveniencelinks' ),
-                       $this->getLang()->pipeList( $links )
+                       $this->getLanguage()->pipeList( $links )
                );
 
-               if( $this->target instanceof User ){
+               $userTitle = self::getTargetUserTitle( $this->target );
+               if( $userTitle ){
                        # Get relevant extracts from the block and suppression logs, if possible
-                       $userpage = $this->target->getUserPage();
                        $out = '';
 
                        LogEventsList::showLogExtract(
                                $out,
                                'block',
-                               $userpage,
+                               $userTitle,
                                '',
                                array(
                                        'lim' => 10,
-                                       'msgKey' => array( 'blocklog-showlog', $userpage->getText() ),
+                                       'msgKey' => array( 'blocklog-showlog', $userTitle->getText() ),
                                        'showIfEmpty' => false
                                )
                        );
@@ -403,12 +408,12 @@ class SpecialBlock extends FormSpecialPage {
                                LogEventsList::showLogExtract(
                                        $out,
                                        'suppress',
-                                       $userpage,
+                                       $userTitle,
                                        '',
                                        array(
                                                'lim' => 10,
                                                'conds' => array( 'log_action' => array( 'block', 'reblock', 'unblock' ) ),
-                                               'msgKey' => array( 'blocklog-showsuppresslog', $userpage->getText() ),
+                                               'msgKey' => array( 'blocklog-showsuppresslog', $userTitle->getText() ),
                                                'showIfEmpty' => false
                                        )
                                );
@@ -420,6 +425,21 @@ class SpecialBlock extends FormSpecialPage {
                return $text;
        }
 
+       /**
+        * Get a user page target for things like logs.
+        * This handles account and IP range targets.
+        * @param $target User|string
+        * @return Title|null
+        */
+       protected static function getTargetUserTitle( $target ) {
+               if( $target instanceof User ) {
+                       return $target->getUserPage();
+               } elseif ( IP::isIPAddress( $target ) ) {
+                       return Title::makeTitleSafe( NS_USER, $target );
+               }
+               return null;
+       }
+
        /**
         * Determine the target of the block, and the type of target
         * TODO: should be in Block.php?
@@ -565,9 +585,13 @@ class SpecialBlock extends FormSpecialPage {
 
                        # Give admins a heads-up before they go and block themselves.  Much messier
                        # to do this for IPs, but it's pretty unlikely they'd ever get the 'block'
-                       # permission anyway, although the code does allow for it
+                       # permission anyway, although the code does allow for it.
+                       # Note: Important to use $target instead of $data['Target']
+                       # since both $data['PreviousTarget'] and $target are normalized
+                       # but $data['target'] gets overriden by (non-normalized) request variable
+                       # from previous request.
                        if( $target === $performer->getName() &&
-                               ( $data['PreviousTarget'] !== $data['Target'] || !$data['Confirm'] ) )
+                               ( $data['PreviousTarget'] !== $target || !$data['Confirm'] ) )
                        {
                                return array( 'ipb-blockingself' );
                        }
@@ -884,7 +908,7 @@ class SpecialBlock extends FormSpecialPage {
        public function onSuccess() {
                $out = $this->getOutput();
                $out->setPageTitle( $this->msg( 'blockipsuccesssub' ) );
-               $out->addWikiMsg( 'blockipsuccesstext',  $this->target );
+               $out->addWikiMsg( 'blockipsuccesstext', wfEscapeWikiText( $this->target ) );
        }
 }