r41355 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41354‎ | r41355 | r41356 >
Date:17:14, 28 September 2008
Author:nikerabbit
Status:old (Comments)
Tags:
Comment:
* Some cleanup
Modified paths:
  • /trunk/phase3/includes/specials/SpecialRestrictUser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialRestrictUser.php
@@ -12,10 +12,7 @@
1313 return;
1414 }
1515 $isIP = User::isIP( $userOrig );
16 - if( $isIP )
17 - $user = $userOrig;
18 - else
19 - $user = User::getCanonicalName( $userOrig );
 16+ $user = $isIP ? $userOrig : User::getCanonicalName( $userOrig );
2017 $uid = User::idFromName( $user );
2118 if( !$uid && !$isIP ) {
2219 $err = '<strong class="error">' . wfMsgHtml( 'restrictuser-notfound' ) . '</strong>';
@@ -30,7 +27,8 @@
3128 RestrictUserForm::pageRestrictionForm( $uid, $user, $old );
3229 RestrictUserForm::namespaceRestrictionForm( $uid, $user, $old );
3330
34 - $old = UserRestriction::fetchForUser( $user, true ); // Renew it after possible changes in previous two functions
 31+ // Renew it after possible changes in previous two functions
 32+ $old = UserRestriction::fetchForUser( $user, true );
3533 if( $old ) {
3634 $wgOut->addHTML( RestrictUserForm::existingRestrictions( $old ) );
3735 }
@@ -39,8 +37,7 @@
4038 class RestrictUserForm {
4139 public static function selectUserForm( $val = null, $error = null ) {
4240 global $wgScript, $wgTitle;
43 - $legend = wfMsgHtml( 'restrictuser-userselect' );
44 - $s = Xml::fieldset( $legend ) . "<form action=\"{$wgScript}\">";
 41+ $s = Xml::fieldset( wfMsg( 'restrictuser-userselect' ) ) . "<form action=\"{$wgScript}\">";
4542 if( $error )
4643 $s .= '<p>' . $error . '</p>';
4744 $s .= Xml::hidden( 'title', $wgTitle->getPrefixedDbKey() );
@@ -51,9 +48,9 @@
5249 }
5350
5451 public static function existingRestrictions( $restrictions ) {
 52+ //TODO: autoload?
5553 require_once( dirname( __FILE__ ) . '/SpecialListUserRestrictions.php' );
56 - $legend = wfMsgHtml( 'restrictuser-existing' );
57 - $s = Xml::fieldset( $legend ) . '<ul>';
 54+ $s = Xml::fieldset( wfMsg( 'restrictuser-existing' ) ) . '<ul>';
5855 foreach( $restrictions as $r )
5956 $s .= UserRestrictionsPager::formatRestriction( $r );
6057 $s .= "</ul></fieldset>";
@@ -66,28 +63,28 @@
6764 $success = false;
6865 if( $wgRequest->wasPosted() && $wgRequest->getVal( 'type' ) == UserRestriction::PAGE &&
6966 $wgUser->matchEditToken( $wgRequest->getVal( 'edittoken' ) ) ) {
70 - $title = Title::newFromText( $wgRequest->getVal( 'page' ) );
71 - if( !$title )
72 - $error = wfMsgExt( 'restrictuser-badtitle', 'parseinline', $wgRequest->getVal( 'page' ) );
73 - elseif( UserRestriction::convertExpiry( $wgRequest->getVal( 'expiry' ) ) === false )
74 - $error = wfMsgExt( 'restrictuser-badexpiry', 'parseinline', $wgRequest->getVal( 'expiry' ) );
75 - else
76 - foreach( $oldRestrictions as $r )
77 - if( $r->isPage() && $r->getPage()->equals( $title ) )
78 - $error = wfMsgExt( 'restrictuser-duptitle', 'parse' );
79 - if( !$error ) {
80 - self::doPageRestriction( $uid, $user );
81 - $success = true;
 67+
 68+ $title = Title::newFromText( $wgRequest->getVal( 'page' ) );
 69+ if( !$title ) {
 70+ $error = array( 'restrictuser-badtitle', $wgRequest->getVal( 'page' ) );
 71+ } elseif( UserRestriction::convertExpiry( $wgRequest->getVal( 'expiry' ) ) === false ) {
 72+ $error = array( 'restrictuser-badexpiry', $wgRequest->getVal( 'expiry' ) );
 73+ } else {
 74+ foreach( $oldRestrictions as $r ) {
 75+ if( $r->isPage() && $r->getPage()->equals( $title ) )
 76+ $error = array( 'restrictuser-duptitle' );
8277 }
 78+ }
 79+ if( !$error ) {
 80+ self::doPageRestriction( $uid, $user );
 81+ $success = array('restrictuser-success', $user);
 82+ }
8383 }
8484 $useRequestValues = $wgRequest->getVal( 'type' ) == UserRestriction::PAGE;
85 - $legend = wfMsgHtml( 'restrictuser-legend-page' );
86 - $wgOut->addHTML( Xml::fieldset( $legend ) );
87 - if( $error )
88 - $wgOut->addHTML( '<strong class="error">' . $error . '</strong>' );
89 - if( $success )
90 - $wgOut->addHTML( '<strong class="success">' . wfMsgExt( 'restrictuser-success',
91 - 'parseinline', $user ) . '</strong>' );
 85+ $wgOut->addHTML( Xml::fieldset( wfMsg( 'restrictuser-legend-page' ) ) );
 86+
 87+ self::printSuccessError( $success, $error );
 88+
9289 $wgOut->addHTML( Xml::openElement( 'form', array( 'action' => $wgTitle->getLocalUrl(),
9390 'method' => 'post' ) ) );
9491 $wgOut->addHTML( Xml::hidden( 'type', UserRestriction::PAGE ) );
@@ -104,6 +101,14 @@
105102 $wgOut->addHTML( "</form></fieldset>" );
106103 }
107104
 105+ public static function printSuccessError( $success, $error ) {
 106+ global $wgOut;
 107+ if ( $error )
 108+ $wgOut->wrapWikiMsg( '<strong class="error">$1</strong>', $error );
 109+ if ( $success )
 110+ $wgOut->wrapWikiMsg( '<strong class="success">$1/strong>', $success );
 111+ }
 112+
108113 public static function doPageRestriction( $uid, $user ) {
109114 global $wgUser, $wgRequest;
110115 $r = new UserRestriction();
@@ -140,17 +145,14 @@
141146 $error = wfMsgExt( 'restrictuser-dupnamespace', 'parse' );
142147 if( !$error ) {
143148 self::doNamespaceRestriction( $uid, $user );
144 - $success = true;
 149+ $success = array('restrictuser-success', $user);
145150 }
146151 }
147152 $useRequestValues = $wgRequest->getVal( 'type' ) == UserRestriction::NAMESPACE;
148 - $legend = wfMsgHtml( 'restrictuser-legend-namespace' );
149 - $wgOut->addHTML( Xml::fieldset( $legend ) );
150 - if( $error )
151 - $wgOut->addHTML( '<strong class="error">' . $error . '</strong>' );
152 - if( $success )
153 - $wgOut->addHTML( '<strong class="success">' . wfMsgExt( 'restrictuser-success',
154 - 'parseinline', $user ) . '</strong>' );
 153+ $wgOut->addHTML( Xml::fieldset( wfMsg( 'restrictuser-legend-namespace' ) ) );
 154+
 155+ self::printSuccessError( $success, $error );
 156+
155157 $wgOut->addHTML( Xml::openElement( 'form', array( 'action' => $wgTitle->getLocalUrl(),
156158 'method' => 'post' ) ) );
157159 $wgOut->addHTML( Xml::hidden( 'type', UserRestriction::NAMESPACE ) );

Comments

#Comment by Brion VIBBER (talk | contribs)   20:41, 30 September 2008

Backed out in r41405: unauthorized schema changes break parser tests, etc

Status & tagging log