r53118 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53117‎ | r53118 | r53119 >
Date:19:07, 11 July 2009
Author:ialex
Status:ok
Tags:
Comment:
follow-up r53116: let's just delete the files since the feature was reverted in r41405 but these files were not deleted
Modified paths:
  • /trunk/phase3/includes/specials/SpecialListUserRestrictions.php (deleted) (history)
  • /trunk/phase3/includes/specials/SpecialRestrictUser.php (deleted) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialRestrictUser.php
@@ -1,190 +0,0 @@
2 -<?php
3 -
4 -function wfSpecialRestrictUser( $par = null ) {
5 - global $wgOut, $wgRequest;
6 - $user = $userOrig = null;
7 - if( $par ) {
8 - $userOrig = $par;
9 - } elseif( $wgRequest->getVal( 'user' ) ) {
10 - $userOrig = $wgRequest->getVal( 'user' );
11 - } else {
12 - $wgOut->addHTML( RestrictUserForm::selectUserForm() );
13 - return;
14 - }
15 - $isIP = User::isIP( $userOrig );
16 - $user = $isIP ? $userOrig : User::getCanonicalName( $userOrig );
17 - $uid = User::idFromName( $user );
18 - if( !$uid && !$isIP ) {
19 - $err = '<strong class="error">' . wfMsgHtml( 'restrictuser-notfound' ) . '</strong>';
20 - $wgOut->addHTML( RestrictUserForm::selectUserForm( $userOrig, $err ) );
21 - return;
22 - }
23 - $wgOut->addHTML( RestrictUserForm::selectUserForm( $user ) );
24 -
25 - UserRestriction::purgeExpired();
26 - $old = UserRestriction::fetchForUser( $user, true );
27 -
28 - RestrictUserForm::pageRestrictionForm( $uid, $user, $old );
29 - RestrictUserForm::namespaceRestrictionForm( $uid, $user, $old );
30 -
31 - // Renew it after possible changes in previous two functions
32 - $old = UserRestriction::fetchForUser( $user, true );
33 - if( $old ) {
34 - $wgOut->addHTML( RestrictUserForm::existingRestrictions( $old ) );
35 - }
36 -}
37 -
38 -class RestrictUserForm {
39 - public static function selectUserForm( $val = null, $error = null ) {
40 - global $wgScript;
41 - $action = htmlspecialchars( $wgScript );
42 - $s = Xml::fieldset( wfMsg( 'restrictuser-userselect' ) ) . "<form action=\"{$action}\">";
43 - if( $error )
44 - $s .= '<p>' . $error . '</p>';
45 - $s .= Xml::hidden( 'title', SpecialPage::getTitleFor( 'RestrictUser' )->getPrefixedDbKey() );
46 - $form = array( 'restrictuser-user' => Xml::input( 'user', false, $val ) );
47 - $s .= Xml::buildForm( $form, 'restrictuser-go' );
48 - $s .= "</form></fieldset>";
49 - return $s;
50 - }
51 -
52 - public static function existingRestrictions( $restrictions ) {
53 - //TODO: autoload?
54 - require_once( dirname( __FILE__ ) . '/SpecialListUserRestrictions.php' );
55 - $s = Xml::fieldset( wfMsg( 'restrictuser-existing' ) ) . '<ul>';
56 - foreach( $restrictions as $r )
57 - $s .= UserRestrictionsPager::formatRestriction( $r );
58 - $s .= "</ul></fieldset>";
59 - return $s;
60 - }
61 -
62 - public static function pageRestrictionForm( $uid, $user, $oldRestrictions ) {
63 - global $wgOut, $wgRequest, $wgUser;
64 - $error = '';
65 - $success = false;
66 - if( $wgRequest->wasPosted() && $wgRequest->getVal( 'type' ) == UserRestriction::PAGE_RESTRICTION &&
67 - $wgUser->matchEditToken( $wgRequest->getVal( 'edittoken' ) ) ) {
68 -
69 - $title = Title::newFromText( $wgRequest->getVal( 'page' ) );
70 - if( !$title ) {
71 - $error = array( 'restrictuser-badtitle', $wgRequest->getVal( 'page' ) );
72 - } elseif( UserRestriction::convertExpiry( $wgRequest->getVal( 'expiry' ) ) === false ) {
73 - $error = array( 'restrictuser-badexpiry', $wgRequest->getVal( 'expiry' ) );
74 - } else {
75 - foreach( $oldRestrictions as $r ) {
76 - if( $r->isPage() && $r->getPage()->equals( $title ) )
77 - $error = array( 'restrictuser-duptitle' );
78 - }
79 - }
80 - if( !$error ) {
81 - self::doPageRestriction( $uid, $user );
82 - $success = array('restrictuser-success', $user);
83 - }
84 - }
85 - $useRequestValues = $wgRequest->getVal( 'type' ) == UserRestriction::PAGE_RESTRICTION;
86 - $wgOut->addHTML( Xml::fieldset( wfMsg( 'restrictuser-legend-page' ) ) );
87 -
88 - self::printSuccessError( $success, $error );
89 -
90 - $wgOut->addHTML( Xml::openElement( 'form', array( 'action' => SpecialPage::getTitleFor( 'RestrictUser' )->getLocalUrl(),
91 - 'method' => 'post' ) ) );
92 - $wgOut->addHTML( Xml::hidden( 'type', UserRestriction::PAGE_RESTRICTION ) );
93 - $wgOut->addHTML( Xml::hidden( 'edittoken', $wgUser->editToken() ) );
94 - $wgOut->addHTML( Xml::hidden( 'user', $user ) );
95 - $form = array();
96 - $form['restrictuser-title'] = Xml::input( 'page', false,
97 - $useRequestValues ? $wgRequest->getVal( 'page' ) : false );
98 - $form['restrictuser-expiry'] = Xml::input( 'expiry', false,
99 - $useRequestValues ? $wgRequest->getVal( 'expiry' ) : false );
100 - $form['restrictuser-reason'] = Xml::input( 'reason', false,
101 - $useRequestValues ? $wgRequest->getVal( 'reason' ) : false );
102 - $wgOut->addHTML( Xml::buildForm( $form, 'restrictuser-submit' ) );
103 - $wgOut->addHTML( "</form></fieldset>" );
104 - }
105 -
106 - public static function printSuccessError( $success, $error ) {
107 - global $wgOut;
108 - if ( $error )
109 - $wgOut->wrapWikiMsg( '<strong class="error">$1</strong>', $error );
110 - if ( $success )
111 - $wgOut->wrapWikiMsg( '<strong class="success">$1</strong>', $success );
112 - }
113 -
114 - public static function doPageRestriction( $uid, $user ) {
115 - global $wgUser, $wgRequest;
116 - $r = new UserRestriction();
117 - $r->setType( UserRestriction::PAGE_RESTRICTION );
118 - $r->setPage( Title::newFromText( $wgRequest->getVal( 'page' ) ) );
119 - $r->setSubjectId( $uid );
120 - $r->setSubjectText( $user );
121 - $r->setBlockerId( $wgUser->getId() );
122 - $r->setBlockerText( $wgUser->getName() );
123 - $r->setReason( $wgRequest->getVal( 'reason' ) );
124 - $r->setExpiry( UserRestriction::convertExpiry( $wgRequest->getVal( 'expiry' ) ) );
125 - $r->setTimestamp( wfTimestampNow( TS_MW ) );
126 - $r->commit();
127 - $logExpiry = $wgRequest->getVal( 'expiry' ) ? $wgRequest->getVal( 'expiry' ) : Block::infinity();
128 - $l = new LogPage( 'restrict' );
129 - $l->addEntry( 'restrict', Title::makeTitle( NS_USER, $user ), $r->getReason(),
130 - array( $r->getType(), $r->getPage()->getFullText(), $logExpiry) );
131 - }
132 -
133 - public static function namespaceRestrictionForm( $uid, $user, $oldRestrictions ) {
134 - global $wgOut, $wgRequest, $wgUser, $wgContLang;
135 - $error = '';
136 - $success = false;
137 - if( $wgRequest->wasPosted() && $wgRequest->getVal( 'type' ) == UserRestriction::NAMESPACE_RESTRICTION &&
138 - $wgUser->matchEditToken( $wgRequest->getVal( 'edittoken' ) ) ) {
139 - $ns = $wgRequest->getVal( 'namespace' );
140 - if( $wgContLang->getNsText( $ns ) === false )
141 - $error = wfMsgExt( 'restrictuser-badnamespace', 'parseinline' );
142 - elseif( UserRestriction::convertExpiry( $wgRequest->getVal( 'expiry' ) ) === false )
143 - $error = wfMsgExt( 'restrictuser-badexpiry', 'parseinline', $wgRequest->getVal( 'expiry' ) );
144 - else
145 - foreach( $oldRestrictions as $r )
146 - if( $r->isNamespace() && $r->getNamespace() == $ns )
147 - $error = wfMsgExt( 'restrictuser-dupnamespace', 'parse' );
148 - if( !$error ) {
149 - self::doNamespaceRestriction( $uid, $user );
150 - $success = array('restrictuser-success', $user);
151 - }
152 - }
153 - $useRequestValues = $wgRequest->getVal( 'type' ) == UserRestriction::NAMESPACE_RESTRICTION;
154 - $wgOut->addHTML( Xml::fieldset( wfMsg( 'restrictuser-legend-namespace' ) ) );
155 -
156 - self::printSuccessError( $success, $error );
157 -
158 - $wgOut->addHTML( Xml::openElement( 'form', array( 'action' => SpecialPage::getTitleFor( 'RestrictUser' )->getLocalUrl(),
159 - 'method' => 'post' ) ) );
160 - $wgOut->addHTML( Xml::hidden( 'type', UserRestriction::NAMESPACE_RESTRICTION ) );
161 - $wgOut->addHTML( Xml::hidden( 'edittoken', $wgUser->editToken() ) );
162 - $wgOut->addHTML( Xml::hidden( 'user', $user ) );
163 - $form = array();
164 - $form['restrictuser-namespace'] = Xml::namespaceSelector( $wgRequest->getVal( 'namespace' ) );
165 - $form['restrictuser-expiry'] = Xml::input( 'expiry', false,
166 - $useRequestValues ? $wgRequest->getVal( 'expiry' ) : false );
167 - $form['restrictuser-reason'] = Xml::input( 'reason', false,
168 - $useRequestValues ? $wgRequest->getVal( 'reason' ) : false );
169 - $wgOut->addHTML( Xml::buildForm( $form, 'restrictuser-submit' ) );
170 - $wgOut->addHTML( "</form></fieldset>" );
171 - }
172 -
173 - public static function doNamespaceRestriction( $uid, $user ) {
174 - global $wgUser, $wgRequest;
175 - $r = new UserRestriction();
176 - $r->setType( UserRestriction::NAMESPACE_RESTRICTION );
177 - $r->setNamespace( $wgRequest->getVal( 'namespace' ) );
178 - $r->setSubjectId( $uid );
179 - $r->setSubjectText( $user );
180 - $r->setBlockerId( $wgUser->getId() );
181 - $r->setBlockerText( $wgUser->getName() );
182 - $r->setReason( $wgRequest->getVal( 'reason' ) );
183 - $r->setExpiry( UserRestriction::convertExpiry( $wgRequest->getVal( 'expiry' ) ) );
184 - $r->setTimestamp( wfTimestampNow( TS_MW ) );
185 - $r->commit();
186 - $logExpiry = $wgRequest->getVal( 'expiry' ) ? $wgRequest->getVal( 'expiry' ) : Block::infinity();
187 - $l = new LogPage( 'restrict' );
188 - $l->addEntry( 'restrict', Title::makeTitle( NS_USER, $user ), $r->getReason(),
189 - array( $r->getType(), $r->getNamespace(), $logExpiry ) );
190 - }
191 -}
Index: trunk/phase3/includes/specials/SpecialListUserRestrictions.php
@@ -1,162 +0,0 @@
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( wfMsgHtml( 'listuserrestrictions-type' ), 'type' ) . '&nbsp;' .
34 - self::typeSelector( 'type', $wgRequest->getVal( 'type' ), 'type' );
35 - $s .= '&nbsp;';
36 - $s .= Xml::inputLabel( wfMsgHtml( 'listuserrestrictions-user' ), 'user', 'user',
37 - false, $wgRequest->getVal( 'user' ) );
38 - $s .= '<p>';
39 - $s .= Xml::label( wfMsgHtml( 'listuserrestrictions-namespace' ), 'namespace' ) . '&nbsp;' .
40 - Xml::namespaceSelector( $wgRequest->getVal( 'namespace' ), '', 'namespace' );
41 - $s .= '&nbsp;';
42 - $s .= Xml::inputLabel( wfMsgHtml( '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_RESTRICTION );
53 - $s->addOption( wfMsg( 'userrestrictiontype-namespace' ), UserRestriction::NAMESPACE_RESTRICTION );
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_RESTRICTION, UserRestriction::NAMESPACE_RESTRICTION ) ) )
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_RESTRICTION )
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 - $wgLang->getDisplayNsText( $r->getNamespace() ), $expiry );
145 - }
146 - if( $r->isPage() ) {
147 - $pagelink = $sk->link( $r->getPage() );
148 - $msg = wfMsgHtml( 'listuserrestrictions-row-page', $subjlink,
149 - $pagelink, $expiry );
150 - }
151 - $reason = $sk->commentBlock( $r->getReason() );
152 - $removelink = '';
153 - if( $wgUser->isAllowed( 'restrict' ) ) {
154 - $removelink = '(' . $sk->link( SpecialPage::getTitleFor( 'RemoveRestrictions' ),
155 - wfMsgHtml( 'listuserrestrictions-remove' ), array(), array( 'id' => $r->getId() ) ) . ')';
156 - }
157 - return "<li>{$timestamp}, {$blockerlink} {$msg} {$reason} {$removelink}</li>\n";
158 - }
159 -
160 - public function getIndexField() {
161 - return 'ur_timestamp';
162 - }
163 -}

Follow-up revisions

RevisionCommit summaryAuthorDate
r63979Unused file. Feature was reverted in r41405. Other files were removed on r53118.platonides14:51, 20 March 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r41405Revert r41352-41355, r41362-41363: unauthorized schema change breaks parser t...brion00:07, 30 September 2008
r53116renamed NAMESPACE constant to NAMESPACE_RESTRICTION (and PAGE to PAGE_RESTRIC...ialex18:09, 11 July 2009

Status & tagging log