r70690 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70689‎ | r70690 | r70691 >
Date:13:04, 8 August 2010
Author:demon
Status:deferred
Tags:
Comment:
Remove per-user restriction special pages. Never enabled and removed in 1.16 as well
Modified paths:
  • /branches/REL1_15/phase3/includes/specials/SpecialListUserRestrictions.php (deleted) (history)
  • /branches/REL1_15/phase3/includes/specials/SpecialRemoveRestrictions.php (deleted) (history)
  • /branches/REL1_15/phase3/includes/specials/SpecialRestrictUser.php (deleted) (history)

Diff [purge]

Index: branches/REL1_15/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, $wgTitle;
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', $wgTitle->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, $wgTitle, $wgRequest, $wgUser;
64 - $error = '';
65 - $success = false;
66 - if( $wgRequest->wasPosted() && $wgRequest->getVal( 'type' ) == UserRestriction::PAGE &&
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;
86 - $wgOut->addHTML( Xml::fieldset( wfMsg( 'restrictuser-legend-page' ) ) );
87 -
88 - self::printSuccessError( $success, $error );
89 -
90 - $wgOut->addHTML( Xml::openElement( 'form', array( 'action' => $wgTitle->getLocalUrl(),
91 - 'method' => 'post' ) ) );
92 - $wgOut->addHTML( Xml::hidden( 'type', UserRestriction::PAGE ) );
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 );
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, $wgTitle, $wgRequest, $wgUser, $wgContLang;
135 - $error = '';
136 - $success = false;
137 - if( $wgRequest->wasPosted() && $wgRequest->getVal( 'type' ) == UserRestriction::NAMESPACE &&
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;
154 - $wgOut->addHTML( Xml::fieldset( wfMsg( 'restrictuser-legend-namespace' ) ) );
155 -
156 - self::printSuccessError( $success, $error );
157 -
158 - $wgOut->addHTML( Xml::openElement( 'form', array( 'action' => $wgTitle->getLocalUrl(),
159 - 'method' => 'post' ) ) );
160 - $wgOut->addHTML( Xml::hidden( 'type', UserRestriction::NAMESPACE ) );
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 );
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: branches/REL1_15/phase3/includes/specials/SpecialRemoveRestrictions.php
@@ -1,60 +0,0 @@
2 -<?php
3 -
4 -function wfSpecialRemoveRestrictions() {
5 - global $wgOut, $wgRequest, $wgUser, $wgLang, $wgTitle;
6 - $sk = $wgUser->getSkin();
7 -
8 - $id = $wgRequest->getVal( 'id' );
9 - if( !is_numeric( $id ) ) {
10 - $wgOut->addWikiMsg( 'removerestrictions-noid' );
11 - return;
12 - }
13 -
14 - UserRestriction::purgeExpired();
15 - $r = UserRestriction::newFromId( $id, true );
16 - if( !$r ) {
17 - $wgOut->addWikiMsg( 'removerestrictions-wrongid' );
18 - return;
19 - }
20 -
21 - $form = array();
22 - $form['removerestrictions-user'] = $sk->userLink( $r->getSubjectId(), $r->getSubjectText() ) .
23 - $sk->userToolLinks( $r->getSubjectId(), $r->getSubjectText() );
24 - $form['removerestrictions-type'] = UserRestriction::formatType( $r->getType() );
25 - if( $r->isPage() )
26 - $form['removerestrictions-page'] = $sk->link( $r->getPage() );
27 - if( $r->isNamespace() )
28 - $form['removerestrictions-namespace'] = $wgLang->getDisplayNsText( $r->getNamespace() );
29 - $form['removerestrictions-reason'] = Xml::input( 'reason' );
30 -
31 - $result = null;
32 - if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'edittoken' ) ) )
33 - $result = wfSpecialRemoveRestrictionsProcess( $r );
34 -
35 - $wgOut->addWikiMsg( 'removerestrictions-intro' );
36 - $wgOut->addHTML( Xml::fieldset( wfMsgHtml( 'removerestrictions-legend' ) ) );
37 - if( $result )
38 - $wgOut->addHTML( '<strong class="success">' . wfMsgExt( 'removerestrictions-success',
39 - 'parseinline', $r->getSubjectText() ) . '</strong>' );
40 - $wgOut->addHTML( Xml::openElement( 'form', array( 'action' => $wgTitle->getLocalUrl( array( 'id' => $id ) ),
41 - 'method' => 'post' ) ) );
42 - $wgOut->addHTML( Xml::buildForm( $form, 'removerestrictions-submit' ) );
43 - $wgOut->addHTML( Xml::hidden( 'id', $r->getId() ) );
44 - $wgOut->addHTML( Xml::hidden( 'title', $wgTitle->getPrefixedDbKey() ) );
45 - $wgOut->addHTML( Xml::hidden( 'edittoken', $wgUser->editToken() ) );
46 - $wgOut->addHTML( "</form></fieldset>" );
47 -}
48 -
49 -function wfSpecialRemoveRestrictionsProcess( $r ) {
50 - global $wgUser, $wgRequest;
51 - $reason = $wgRequest->getVal( 'reason' );
52 - $result = $r->delete();
53 - $log = new LogPage( 'restrict' );
54 - $params = array( $r->getType() );
55 - if( $r->isPage() )
56 - $params[] = $r->getPage()->getPrefixedDbKey();
57 - if( $r->isNamespace() )
58 - $params[] = $r->getNamespace();
59 - $log->addEntry( 'remove', Title::makeTitle( NS_USER, $r->getSubjectText() ), $reason, $params );
60 - return $result;
61 -}
Index: branches/REL1_15/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, $wgTitle;
28 - $action = htmlspecialchars( $wgScript );
29 - $s = '';
30 - $s .= Xml::fieldset( wfMsg( 'listuserrestrictions-legend' ) );
31 - $s .= "<form action=\"{$action}\">";
32 - $s .= Xml::hidden( 'title', $wgTitle->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 );
53 - $s->addOption( wfMsg( 'userrestrictiontype-namespace' ), UserRestriction::NAMESPACE );
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, UserRestriction::NAMESPACE ) ) )
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 )
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 -}

Status & tagging log