Index: trunk/phase3/includes/specials/SpecialRestrictUser.php |
— | — | @@ -12,10 +12,7 @@ |
13 | 13 | return; |
14 | 14 | } |
15 | 15 | $isIP = User::isIP( $userOrig ); |
16 | | - if( $isIP ) |
17 | | - $user = $userOrig; |
18 | | - else |
19 | | - $user = User::getCanonicalName( $userOrig ); |
| 16 | + $user = $isIP ? $userOrig : User::getCanonicalName( $userOrig ); |
20 | 17 | $uid = User::idFromName( $user ); |
21 | 18 | if( !$uid && !$isIP ) { |
22 | 19 | $err = '<strong class="error">' . wfMsgHtml( 'restrictuser-notfound' ) . '</strong>'; |
— | — | @@ -30,7 +27,8 @@ |
31 | 28 | RestrictUserForm::pageRestrictionForm( $uid, $user, $old ); |
32 | 29 | RestrictUserForm::namespaceRestrictionForm( $uid, $user, $old ); |
33 | 30 | |
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 ); |
35 | 33 | if( $old ) { |
36 | 34 | $wgOut->addHTML( RestrictUserForm::existingRestrictions( $old ) ); |
37 | 35 | } |
— | — | @@ -39,8 +37,7 @@ |
40 | 38 | class RestrictUserForm { |
41 | 39 | public static function selectUserForm( $val = null, $error = null ) { |
42 | 40 | 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}\">"; |
45 | 42 | if( $error ) |
46 | 43 | $s .= '<p>' . $error . '</p>'; |
47 | 44 | $s .= Xml::hidden( 'title', $wgTitle->getPrefixedDbKey() ); |
— | — | @@ -51,9 +48,9 @@ |
52 | 49 | } |
53 | 50 | |
54 | 51 | public static function existingRestrictions( $restrictions ) { |
| 52 | + //TODO: autoload? |
55 | 53 | 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>'; |
58 | 55 | foreach( $restrictions as $r ) |
59 | 56 | $s .= UserRestrictionsPager::formatRestriction( $r ); |
60 | 57 | $s .= "</ul></fieldset>"; |
— | — | @@ -66,28 +63,28 @@ |
67 | 64 | $success = false; |
68 | 65 | if( $wgRequest->wasPosted() && $wgRequest->getVal( 'type' ) == UserRestriction::PAGE && |
69 | 66 | $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' ); |
82 | 77 | } |
| 78 | + } |
| 79 | + if( !$error ) { |
| 80 | + self::doPageRestriction( $uid, $user ); |
| 81 | + $success = array('restrictuser-success', $user); |
| 82 | + } |
83 | 83 | } |
84 | 84 | $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 | + |
92 | 89 | $wgOut->addHTML( Xml::openElement( 'form', array( 'action' => $wgTitle->getLocalUrl(), |
93 | 90 | 'method' => 'post' ) ) ); |
94 | 91 | $wgOut->addHTML( Xml::hidden( 'type', UserRestriction::PAGE ) ); |
— | — | @@ -104,6 +101,14 @@ |
105 | 102 | $wgOut->addHTML( "</form></fieldset>" ); |
106 | 103 | } |
107 | 104 | |
| 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 | + |
108 | 113 | public static function doPageRestriction( $uid, $user ) { |
109 | 114 | global $wgUser, $wgRequest; |
110 | 115 | $r = new UserRestriction(); |
— | — | @@ -140,17 +145,14 @@ |
141 | 146 | $error = wfMsgExt( 'restrictuser-dupnamespace', 'parse' ); |
142 | 147 | if( !$error ) { |
143 | 148 | self::doNamespaceRestriction( $uid, $user ); |
144 | | - $success = true; |
| 149 | + $success = array('restrictuser-success', $user); |
145 | 150 | } |
146 | 151 | } |
147 | 152 | $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 | + |
155 | 157 | $wgOut->addHTML( Xml::openElement( 'form', array( 'action' => $wgTitle->getLocalUrl(), |
156 | 158 | 'method' => 'post' ) ) ); |
157 | 159 | $wgOut->addHTML( Xml::hidden( 'type', UserRestriction::NAMESPACE ) ); |