Index: languages/Language.php
===================================================================
--- languages/Language.php (revision 52193)
+++ languages/Language.php (working copy)
@@ -278,6 +278,12 @@
return strtr($ns, '_', ' ');
}
+ function getDisplayNsText( $index ) {
+ if( $index == 0 )
+ return $this->getMessage( 'blanknamespace' );
+ return $this->getFormattedNsText( $index );
+ }
+
/**
* Get a namespace key by value, case insensitive.
* Only matches namespace names for the current language, not the
Index: languages/messages/MessagesEn.php
===================================================================
--- languages/messages/MessagesEn.php (revision 52193)
+++ languages/messages/MessagesEn.php (working copy)
@@ -447,6 +447,9 @@
'LinkSearch' => array( 'LinkSearch' ),
'DeletedContributions' => array( 'DeletedContributions' ),
'Tags' => array( 'Tags' ),
+ 'ListUserRestrictions' => array( 'ListUserRestrictions' ),
+ 'RemoveRestrictions' => array( 'RemoveRestrictions' ),
+ 'RestrictUser' => array( 'RestrictUser' ),
);
/**
@@ -1224,7 +1227,39 @@
'edit-no-change' => 'Your edit was ignored, because no change was made to the text.',
'edit-already-exists' => 'Could not create a new page.
It already exists.',
+'userrestricted-page' => '\'\'\'Your user name or IP address has been restricted from editing page "$1".\'\'\'
+The restriction was set by [[User:$2|$2]].
+The reason given is \'\'$3\'\'.
+
+The restriction was set on $4 at $5 and expires on $6 at $7.
+
+You can contact [[User:$2|$2]] or another [[{{MediaWiki:Grouppage-sysop}}|administrator]] to discuss the restriction.',
+'userrestricted-namespace' => "'''Your user name or IP address has been restricted from editing the $1 namespace.'''
+
+The restriction was put by [[User:$2|$2]].
+The reason given is ''$3''.
+
+Restriction was put on $4 at $5 and expires on $6 at $7.
+
+You can contact [[User:$2|$2]] or another [[{{MediaWiki:Grouppage-sysop}}|administrator]] to discuss the restriction.",
+'userrestricted-page-indef' => '\'\'\'Your user name or IP address has been restricted from editing page "$1".\'\'\'
+
+The restriction was set by [[User:$2|$2]].
+The reason given is \'\'$3\'\'.
+
+The restriction was set on $4 at $5 and will not expire.
+
+You can contact [[User:$2|$2]] or another [[{{MediaWiki:Grouppage-sysop}}|administrator]] to discuss the restriction.',
+'userrestricted-namespace-indef' => "'''Your user name or IP address has been restricted from editing $1 namespace.'''
+
+The restriction was put by [[User:$2|$2]].
+The reason given is ''$3''.
+
+Restriction was put on $4 at $5 and will not expire.
+
+You can contact [[User:$2|$2]] or another [[{{MediaWiki:Grouppage-sysop}}|administrator]] to discuss the restriction.",
+
# Parser/template warnings
'expensive-parserfunction-warning' => "'''Warning:''' This page contains too many expensive parser function calls.
@@ -2704,6 +2739,7 @@
'ipbsubmit' => 'Block this user',
'ipbother' => 'Other time:',
'ipboptions' => '2 hours:2 hours,1 day:1 day,3 days:3 days,1 week:1 week,2 weeks:2 weeks,1 month:1 month,3 months:3 months,6 months:6 months,1 year:1 year,infinite:infinite',
+'ipbinfinite' => 'infinite',
'ipbotheroption' => 'other',
'ipbotherreason' => 'Other/additional reason:',
'ipbhidename' => 'Hide username from edits and lists',
@@ -2789,6 +2825,74 @@
You cannot create an account',
'cant-block-while-blocked' => 'You cannot block other users while you are blocked.',
+# Special:ListUserRestrictions
+'listuserrestrictions' => 'List of user restrictions',
+'listuserrestrictions-intro' => 'This list contains all restrictions from editing certain pages and namespaces put on users.
+[[Special:Ipblocklist|Blocks]] are not listed here.',
+'listuserrestrictions-row-ns' => 'restricted $1 from editing $2 namespace ($3)',
+'listuserrestrictions-row-page' => 'restricted $1 from editing $2 ($3)',
+'listuserrestrictions-row-expiry' => 'expires on $1 at $2',
+'listuserrestrictions-legend' => 'Find a restriction',
+'listuserrestrictions-type' => 'Type:',
+'listuserrestrictions-user' => 'User:',
+'listuserrestrictions-namespace' => 'Namespace:',
+'listuserrestrictions-page' => 'Page:',
+'listuserrestrictions-submit' => 'Go',
+'listuserrestrictions-notfound' => 'There is no restriction that matches specified criteria.',
+'listuserrestrictions-empty' => 'This list is empty.',
+'listuserrestrictions-remove' => 'remove',
+'userrestrictiontype-none' => '(none)',
+'userrestrictiontype-namespace' => 'Namespace',
+'userrestrictiontype-page' => 'Page',
+
+# Special:RemoveRestrictions
+'removerestrictions' => 'Remove the restriction for a user',
+'removerestrictions-intro' => 'Use the form below to remove a restriction from a certain user.',
+'removerestrictions-noid' => 'No restriction ID was specified.',
+'removerestrictions-wrongid' => 'Restriction with that ID not found.
+Most probably someone has removed it or it expired.',
+'removerestrictions-legend' => 'Remove a restriction',
+'removerestrictions-user' => 'Restricted user:',
+'removerestrictions-type' => 'Restriction type:',
+'removerestrictions-page' => 'Page:',
+'removerestrictions-namespace' => 'Namespace:',
+'removerestrictions-reason' => 'Reason:',
+'removerestrictions-submit' => 'Remove the restriction',
+'removerestrictions-success' => "'''Successfully removed the restriction from [[User:$1|$1]].'''
+
+Return to [[Special:ListUserRestrictions|user restrictions list]].",
+
+# Restrict user
+'restrictuser' => 'Restrict user',
+'restrictuser-userselect' => 'Select a user',
+'restrictuser-user' => 'User:',
+'restrictuser-go' => 'Restrict user',
+'restrictuser-notfound' => 'User not found',
+'restrictuser-existing' => 'Existing restrictions',
+'restrictuser-legend' => 'Restrict user from editing',
+'restrictuser-type' => 'Restriction type:',
+'restrictuser-title' => 'Page to restrict:',
+'restrictuser-namespace' => 'Namespace:',
+'restrictuser-expiry' => 'Expires:',
+'restrictuser-reason' => 'Reason:',
+'restrictuser-submit' => 'Restrict user',
+'restrictuser-badtitle' => 'Invalid title specified: $1.',
+'restrictuser-badnamespace' => 'Invalid namespace specified.',
+'restrictuser-badexpiry' => 'Invalid expiry specified: $1.',
+'restrictuser-duptitle' => 'User is already restricted from editing this title.',
+'restrictuser-dupnamespace' => 'User is already restricted from editing this namespace.',
+'restrictuser-success' => 'Successfully restricted user $1.',
+'restrictuser-description' => 'Use the form below to block write access to a specific page or namespace from a specific IP address or username.
+This should be done only in accordance with policy. Fill in a specific reason below.',
+
+# Special:Log/restrict
+'restrictionlog' => 'User restriction log',
+'restrictionlogtext' => 'This log contains all restrictions put on users by administrators.',
+'restrictentry' => 'restricted $1 from editing $2 (expiry set to $3)',
+'restrictremoveentry' => 'removed restriction from $1 for editing $2',
+'restrictlognamespace' => '$1 namespace',
+'restrictlogpage' => '[[$1]]',
+
# Developer tools
'lockdb' => 'Lock database',
'unlockdb' => 'Unlock database',
Index: skins/common/restrict.js
===================================================================
--- skins/common/restrict.js (revision 0)
+++ skins/common/restrict.js (revision 0)
@@ -0,0 +1,22 @@
+addOnloadHook(updateRestrictForm);
+
+function updateRestrictForm() {
+ if (!document.getElementById)
+ return;
+
+ var typeSelect = document.getElementById('mw-restrict-type');
+ if (!typeSelect)
+ return;
+
+ var type = typeSelect.value;
+
+ var pageRow = document.getElementById('mw-restrictuser-title');
+ if( pageRow ) {
+ pageRow.style.display = (type != 'page') ? 'none' : '';
+ }
+
+ var namespaceRow = document.getElementById('mw-restrictuser-namespace');
+ if( namespaceRow ) {
+ namespaceRow.style.display = (type != 'namespace') ? 'none' : '';
+ }
+}
Property changes on: skins/common/restrict.js
___________________________________________________________________
Added: svn:eol-style
+ native
Index: includes/Xml.php
===================================================================
--- includes/Xml.php (revision 52193)
+++ includes/Xml.php (working copy)
@@ -730,6 +730,25 @@
$s .= Xml::closeElement( 'tr' );
return $s;
}
+
+ /**
+ * Build a restriction type selector
+ * @param $name Name of type selector
+ * @param $value Initial value
+ * @param $id ID of tag
+ * @param $hasNone If true, "(none)" is added to selector
+ * @return string
+ */
+ public static function restrictionTypeSelector( $name, $value = '', $id = false, $hasNone = true, $attribs = array() ) {
+ $s = new XmlSelect( $name, $id, $value );
+ if( $hasNone )
+ $s->addOption( wfMsg( 'userrestrictiontype-none' ), '' );
+ $s->addOption( wfMsg( 'userrestrictiontype-page' ), UserRestriction::PAGE );
+ $s->addOption( wfMsg( 'userrestrictiontype-namespace' ), UserRestriction::NAMESPACE );
+ foreach( $attribs as $attrib => $val )
+ $s->setAttribute( $attrib, $val );
+ return $s->getHTML();
+ }
}
class XmlSelect {
Index: includes/User.php
===================================================================
--- includes/User.php (revision 52193)
+++ includes/User.php (working copy)
@@ -164,6 +164,7 @@
'proxyunbannable',
'purge',
'read',
+ 'restrict',
'reupload',
'reupload-shared',
'rollback',
Index: includes/UserRestriction.php
===================================================================
--- includes/UserRestriction.php (revision 0)
+++ includes/UserRestriction.php (revision 0)
@@ -0,0 +1,189 @@
+mId = $row->ur_id;
+ $obj->mType = $row->ur_type;
+ if( $obj->mType == self::PAGE ) {
+ $obj->mPage = Title::makeTitle( $row->ur_page_namespace, $row->ur_page_title );
+ } elseif( $obj->mType == self::NAMESPACE ) {
+ $obj->mNamespace = $row->ur_namespace;
+ } else {
+ throw new MWException( "Unknown user restriction type: {$row->ur_type}" );
+ }
+
+ $obj->mSubjectId = $row->ur_user;
+ $obj->mSubjectText = $row->ur_user_text;
+ $obj->mBlockerId = $row->ur_by;
+ $obj->mBlockerText = $row->ur_by_text;
+ $obj->mReason = $row->ur_reason;
+ $obj->mTimestamp = wfTimestamp( TS_MW, $row->ur_timestamp );
+ $obj->mExpiry = $row->ur_expiry;
+ return $obj;
+ }
+
+ public static function fetchForUser( $user, $forWrite = false ) {
+ $dbr = wfGetDB( $forWrite ? DB_MASTER : DB_SLAVE );
+ if( is_int( $user ) )
+ $query = array( 'ur_user' => $user );
+ else
+ $query = array( 'ur_user_text' => $user );
+ $res = $dbr->select( 'user_restrictions', '*', $query, __METHOD__ );
+ $result = array();
+ foreach( $res as $row ) {
+ $result[] = self::newFromRow( $row );
+ }
+ return $result;
+ }
+
+ public static function fetchForTitle( $user, $title ) {
+ $dbr = wfGetDB( DB_SLAVE );
+ if( $user->isLoggedIn() )
+ $query = array( 'ur_user' => $user->getId() );
+ else
+ $query = array( 'ur_user_text' => $user->getName() );
+ $query['ur_page_namespace'] = $title->getNamespace();
+ $query['ur_page_title'] = $title->getDBKey();
+ $res = $dbr->select( 'user_restrictions', '*', $query, __METHOD__ );
+ $result = array();
+ foreach( $res as $row ) {
+ $result[] = self::newFromRow( $row );
+ }
+ return $result;
+ }
+
+ public static function fetchForNamespace( $user, $ns ) {
+ $dbr = wfGetDB( DB_SLAVE );
+ if( $user->isLoggedIn() )
+ $query = array( 'ur_user' => $user->getId() );
+ else
+ $query = array( 'ur_user_text' => $user->getName() );
+ $query['ur_namespace'] = $ns;
+ $res = $dbr->select( 'user_restrictions', '*', $query, __METHOD__ );
+ $result = array();
+ foreach( $res as $row ) {
+ $result[] = self::newFromRow( $row );
+ }
+ return $result;
+ }
+
+ public static function newFromId( $id, $forWrite = false ) {
+ $dbr = wfGetDB( $forWrite ? DB_MASTER : DB_SLAVE );
+ if( !$id || !is_numeric( $id ) )
+ return null;
+ $res = $dbr->selectRow( 'user_restrictions', '*', array( 'ur_id' => $id ), __METHOD__ );
+ return self::newFromRow( $res );
+ }
+
+ public function getId() { return $this->mId; }
+ public function setId( $v ) { $this->mId = $v; }
+ public function getType() { return $this->mType; }
+ public function setType( $v ) { $this->mType = $v; }
+ public function getNamespace() { return $this->mNamespace; }
+ public function setNamespace( $v ) { $this->mNamespace = $v; }
+ public function getPage() { return $this->mPage; }
+ public function setPage( $v ) { $this->mPage = $v; }
+ public function getSubjectId() { return $this->mSubjectId; }
+ public function setSubjectId( $v ) { $this->mSubjectId = $v; }
+ public function getSubjectText() { return $this->mSubjectText; }
+ public function setSubjectText( $v ) { $this->mSubjectText = $v; }
+ public function getBlockerId() { return $this->mBlockerId; }
+ public function setBlockerId( $v ) { $this->mBlockerId = $v; }
+ public function getBlockerText() { return $this->mBlockerText; }
+ public function setBlockerText( $v ) { $this->mBlockerText = $v; }
+ public function getReason() { return $this->mReason; }
+ public function setReason( $v ) { $this->mReason = $v; }
+ public function getTimestamp() { return $this->mTimestamp; }
+ public function setTimestamp( $v ) { $this->mTimestamp = $v; }
+ public function getExpiry() { return $this->mExpiry; }
+ public function setExpiry( $v ) { $this->mExpiry = $v; }
+
+ public function isPage() {
+ return $this->mType == self::PAGE;
+ }
+ public function isNamespace() {
+ return $this->mType == self::NAMESPACE;
+ }
+
+ public function isExpired() {
+ return is_numeric( $this->mExpiry ) && $this->mExpiry < wfTimestampNow( TS_MW );
+ }
+
+ public function deleteIfExpired() {
+ if( $this->isExpired() ) {
+ $this->delete();
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public function delete() {
+ $dbw = wfGetDB( DB_MASTER );
+ $dbw->delete( 'user_restrictions', array( 'ur_id' => $this->mId ), __METHOD__ );
+ return $dbw->affectedRows();
+ }
+
+ public static function purgeExpired() {
+ $dbw = wfGetDB( DB_MASTER );
+ $dbw->delete( 'user_restrictions', array( 'ur_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ), __METHOD__ );
+ }
+
+ public function commit() {
+ $dbw = wfGetDB( DB_MASTER );
+ $this->setId( $dbw->nextSequenceValue('user_restrictions_ur_id_val') );
+ $row = array(
+ 'ur_id' => $this->mId,
+ 'ur_type' => $this->mType,
+ 'ur_user' => $this->mSubjectId,
+ 'ur_user_text' => $this->mSubjectText,
+ 'ur_by' => $this->mBlockerId,
+ 'ur_by_text' => $this->mBlockerText,
+ 'ur_reason' => $this->mReason,
+ 'ur_timestamp' => $dbw->timestamp( $this->mTimestamp ),
+ 'ur_expiry' => $this->mExpiry,
+ );
+ if( $this->isPage() ) {
+ $row['ur_page_namespace'] = $this->mPage->getNamespace();
+ $row['ur_page_title'] = $this->mPage->getDbKey();
+ }
+ if( $this->isNamespace() ) {
+ $row['ur_namespace'] = $this->mNamespace;
+ }
+ $dbw->insert( 'user_restrictions', $row, __METHOD__ );
+ }
+
+ public static function formatType( $type ) {
+ return wfMsg( 'userrestrictiontype-' . $type );
+ }
+
+ /**
+ * Converts expiry which user input to the internal representation.
+ * Returns false if invalid expiry is set, Block::infinity() on empty value,
+ * Block::infinity() on infinity or 14-symbol timestamp
+ */
+ public static function convertExpiry( $expiry ) {
+ if( !$expiry )
+ return Block::infinity();
+ if( in_array( $expiry, array( 'infinite', 'infinity', 'indefinite' ) ) )
+ return Block::infinity();
+ $unix = @strtotime( $expiry );
+ if( !$unix || $unix === -1 )
+ return false;
+ else
+ return wfTimestamp( TS_MW, $unix );
+ }
+}
Property changes on: includes/UserRestriction.php
___________________________________________________________________
Added: svn:eol-style
+ native
Index: includes/AutoLoader.php
===================================================================
--- includes/AutoLoader.php (revision 52193)
+++ includes/AutoLoader.php (working copy)
@@ -201,6 +201,7 @@
'UserArray' => 'includes/UserArray.php',
'UserArrayFromResult' => 'includes/UserArray.php',
'UserMailer' => 'includes/UserMailer.php',
+ 'UserRestriction' => 'includes/UserRestriction.php',
'UserRightsProxy' => 'includes/UserRightsProxy.php',
'WantedQueryPage' => 'includes/QueryPage.php',
'WatchedItem' => 'includes/WatchedItem.php',
@@ -498,12 +499,15 @@
'SpecialExport' => 'includes/specials/SpecialExport.php',
'SpecialImport' => 'includes/specials/SpecialImport.php',
'SpecialListGroupRights' => 'includes/specials/SpecialListgrouprights.php',
+ 'SpecialListUserRestrictions' => 'includes/specials/SpecialListUserRestrictions.php',
'SpecialMostlinkedtemplates' => 'includes/specials/SpecialMostlinkedtemplates.php',
'SpecialPreferences' => 'includes/specials/SpecialPreferences.php',
'SpecialPrefixindex' => 'includes/specials/SpecialPrefixindex.php',
'SpecialRandomredirect' => 'includes/specials/SpecialRandomredirect.php',
'SpecialRecentchanges' => 'includes/specials/SpecialRecentchanges.php',
'SpecialRecentchangeslinked' => 'includes/specials/SpecialRecentchangeslinked.php',
+ 'SpecialRemoveRestrictions' => 'includes/specials/SpecialRemoveRestrictions.php',
+ 'SpecialRestrictUser' => 'includes/specials/SpecialRestrictUser.php',
'SpecialSearch' => 'includes/specials/SpecialSearch.php',
'SpecialSearchOld' => 'includes/specials/SpecialSearch.php',
'SpecialStatistics' => 'includes/specials/SpecialStatistics.php',
@@ -520,6 +524,7 @@
'UnwatchedpagesPage' => 'includes/specials/SpecialUnwatchedpages.php',
'UploadForm' => 'includes/specials/SpecialUpload.php',
'UploadFormMogile' => 'includes/specials/SpecialUploadMogile.php',
+ 'UserRestrictionsPager' => 'includes/specials/SpecialListUserRestrictions.php',
'UserrightsPage' => 'includes/specials/SpecialUserrights.php',
'UsersPager' => 'includes/specials/SpecialListusers.php',
'WantedCategoriesPage' => 'includes/specials/SpecialWantedcategories.php',
Index: includes/Title.php
===================================================================
--- includes/Title.php (revision 52193)
+++ includes/Title.php (working copy)
@@ -1076,9 +1076,7 @@
}
$errors = $this->getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries );
- global $wgContLang;
- global $wgLang;
- global $wgEmailConfirmToEdit;
+ global $wgContLang, $wgLang, $wgEmailConfirmToEdit;
if ( $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount' ) {
$errors[] = array( 'confirmedittext' );
@@ -1110,20 +1108,7 @@
$blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW, $user->mBlock->mTimestamp ), true );
if ( $blockExpiry == 'infinity' ) {
- // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
- $scBlockExpiryOptions = wfMsg( 'ipboptions' );
-
- foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
- if ( strpos( $option, ':' ) == false )
- continue;
-
- list ($show, $value) = explode( ":", $option );
-
- if ( $value == 'infinite' || $value == 'indefinite' ) {
- $blockExpiry = $show;
- break;
- }
- }
+ $blockExpiry = wfMsg( 'ipbinfinite' );
} else {
$blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW, $blockExpiry ), true );
}
@@ -1133,9 +1118,9 @@
$errors[] = array( ($block->mAuto ? 'autoblockedtext' : 'blockedtext'), $link, $reason, $ip, $name,
$blockid, $blockExpiry, $intended, $blockTimestamp );
}
-
+
// Remove the errors being ignored.
-
+
foreach( $errors as $index => $error ) {
$error_key = is_array($error) ? $error[0] : $error;
@@ -1159,6 +1144,8 @@
* @return \type{\array} Array of arrays of the arguments to wfMsg to explain permissions problems.
*/
private function getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries=true, $short=false ) {
+ global $wgLang;
+
wfProfileIn( __METHOD__ );
$errors = array();
@@ -1374,6 +1361,34 @@
}
}
+ // Check per-user restrictions
+ if( $doExpensiveQueries && $action != 'read' ) {
+ $rs = UserRestriction::fetchForTitle( $user, $this );
+ if( !$rs )
+ $rs = UserRestriction::fetchForNamespace( $user, $this->getNamespace() );
+ if( $rs ) {
+ $r = $rs[0];
+ if( !$r->deleteIfExpired() ) {
+ $error = array();
+ $start = array( $wgLang->date( $r->getTimestamp() ), $wgLang->time( $r->getTimestamp() ) );
+ if( $r->isPage() )
+ $error = array( 'userrestricted-page', $this->getFullText(),
+ $r->getBlockerText(), $r->getReason(), $start[0], $start[1] );
+ elseif( $r->isNamespace() )
+ $error = array( 'userrestricted-namespace', $wgLang->getDisplayNsText( $this->getNamespace() ),
+ $r->getBlockerText(), $r->getReason(), $start[0], $start[1] );
+
+ if( $r->getExpiry() == 'infinity' ) {
+ $error[0] .= '-indef';
+ } else {
+ $error[] = $wgLang->date( $r->getExpiry() );
+ $error[] = $wgLang->time( $r->getExpiry() );
+ }
+ $errors[] = $error;
+ }
+ }
+ }
+
wfProfileOut( __METHOD__ );
return $errors;
}
@@ -2705,6 +2720,12 @@
$log->addEntry( 'move_prot', $nt, $comment, array($this->getPrefixedText()) ); // FIXME: $params?
}
+ # Update user restrictions
+ $dbw->update( 'user_restrictions',
+ array( 'ur_page_namespace' => $nt->getNamespace(), 'ur_page_title' => $nt->getDBKey() ),
+ array( 'ur_page_namespace' => $this->getNamespace(), 'ur_page_title' => $this->getDBKey() ),
+ __METHOD__ );
+
# Update watchlists
$oldnamespace = $this->getNamespace() & ~1;
$newnamespace = $nt->getNamespace() & ~1;
Index: includes/DefaultSettings.php
===================================================================
--- includes/DefaultSettings.php (revision 52193)
+++ includes/DefaultSettings.php (working copy)
@@ -1266,6 +1266,7 @@
$wgGroupPermissions['sysop']['apihighlimits'] = true;
$wgGroupPermissions['sysop']['browsearchive'] = true;
$wgGroupPermissions['sysop']['noratelimit'] = true;
+$wgGroupPermissions['sysop']['restrict'] = true;
$wgGroupPermissions['sysop']['movefile'] = true;
#$wgGroupPermissions['sysop']['mergehistory'] = true;
@@ -2918,6 +2919,7 @@
'patrol',
'merge',
'suppress',
+ 'restrict',
);
/**
@@ -2973,6 +2975,7 @@
'patrol' => 'patrol-log-page',
'merge' => 'mergelog',
'suppress' => 'suppressionlog',
+ 'restrict' => 'restrictionlog',
);
/**
@@ -2993,6 +2996,7 @@
'patrol' => 'patrol-log-header',
'merge' => 'mergelogpagetext',
'suppress' => 'suppressionlogtext',
+ 'restrict' => 'restrictionlogtext',
);
/**
@@ -3028,6 +3032,8 @@
'suppress/delete' => 'suppressedarticle',
'suppress/block' => 'blocklogentry',
'suppress/reblock' => 'reblock-logentry',
+ 'restrict/restrict' => 'restrictentry',
+ 'restrict/remove' => 'restrictremoveentry',
);
/**
@@ -3100,6 +3106,8 @@
'Preferences' => 'users',
'Resetpass' => 'users',
'DeletedContributions' => 'users',
+ 'ListUserRestrictions' => 'users',
+ 'RestrictUser' => 'users',
'Mostlinked' => 'highuse',
'Mostlinkedcategories' => 'highuse',
Index: includes/specials/SpecialRestrictUser.php
===================================================================
--- includes/specials/SpecialRestrictUser.php (revision 52193)
+++ includes/specials/SpecialRestrictUser.php (working copy)
@@ -1,41 +1,54 @@
getVal( 'user' ) ) {
- $userOrig = $wgRequest->getVal( 'user' );
- } else {
- $wgOut->addHTML( RestrictUserForm::selectUserForm() );
- return;
+class SpecialRestrictUser extends SpecialPage {
+ public function __construct() {
+ parent::__construct( 'RestrictUser', 'restrict',
+ /*listed*/ true, /*function*/ false, /*file*/ false );
}
- $isIP = User::isIP( $userOrig );
- $user = $isIP ? $userOrig : User::getCanonicalName( $userOrig );
- $uid = User::idFromName( $user );
- if( !$uid && !$isIP ) {
- $err = '' . wfMsgHtml( 'restrictuser-notfound' ) . ' ';
- $wgOut->addHTML( RestrictUserForm::selectUserForm( $userOrig, $err ) );
- return;
- }
- $wgOut->addHTML( RestrictUserForm::selectUserForm( $user ) );
- UserRestriction::purgeExpired();
- $old = UserRestriction::fetchForUser( $user, true );
+ function execute( $par = null ) {
+ global $wgOut, $wgRequest, $wgUser;
+
+ $this->setHeaders();
+ if( !$this->userCanExecute( $wgUser ) ) {
+ $this->displayRestrictionError();
+ return;
+ }
+
+ $wgOut->addHTML( wfMsgExt( 'restrictuser-description', 'parse' ) );
- RestrictUserForm::pageRestrictionForm( $uid, $user, $old );
- RestrictUserForm::namespaceRestrictionForm( $uid, $user, $old );
+ $user = $userOrig = null;
+ if( $par ) {
+ $userOrig = $par;
+ } elseif( $wgRequest->getVal( 'user' ) ) {
+ $userOrig = $wgRequest->getVal( 'user' );
+ } else {
+ $wgOut->addHTML( $this->selectUserForm() );
+ return;
+ }
+ $isIP = User::isIP( $userOrig );
+ $user = $isIP ? $userOrig : User::getCanonicalName( $userOrig );
+ $uid = User::idFromName( $user );
+ if( !$uid && !$isIP ) {
+ $err = '' . wfMsgHtml( 'restrictuser-notfound' ) . ' ';
+ $wgOut->addHTML( $this->selectUserForm( $userOrig, $err ) );
+ return;
+ }
+ $wgOut->addHTML( $this->selectUserForm( $user ) );
- // Renew it after possible changes in previous two functions
- $old = UserRestriction::fetchForUser( $user, true );
- if( $old ) {
- $wgOut->addHTML( RestrictUserForm::existingRestrictions( $old ) );
+ UserRestriction::purgeExpired();
+ $old = UserRestriction::fetchForUser( $user, true );
+
+ $this->showRestrictionForm( $uid, $user, $old );
+
+ // Renew it after possible changes in previous function
+ $old = UserRestriction::fetchForUser( $user, true );
+ if( $old ) {
+ $wgOut->addHTML( $this->existingRestrictions( $old ) );
+ }
}
-}
-class RestrictUserForm {
- public static function selectUserForm( $val = null, $error = null ) {
+ public function selectUserForm( $val = null, $error = null ) {
global $wgScript;
$action = htmlspecialchars( $wgScript );
$s = Xml::fieldset( wfMsg( 'restrictuser-userselect' ) ) . "" );
}
- public static function printSuccessError( $success, $error ) {
- global $wgOut;
- if ( $error )
- $wgOut->wrapWikiMsg( '$1 ', $error );
- if ( $success )
- $wgOut->wrapWikiMsg( '$1 ', $success );
- }
-
- public static function doPageRestriction( $uid, $user ) {
+ public function doPageRestriction( $uid, $user ) {
global $wgUser, $wgRequest;
$r = new UserRestriction();
$r->setType( UserRestriction::PAGE );
@@ -123,53 +151,14 @@
$r->setExpiry( UserRestriction::convertExpiry( $wgRequest->getVal( 'expiry' ) ) );
$r->setTimestamp( wfTimestampNow( TS_MW ) );
$r->commit();
+
$logExpiry = $wgRequest->getVal( 'expiry' ) ? $wgRequest->getVal( 'expiry' ) : Block::infinity();
$l = new LogPage( 'restrict' );
$l->addEntry( 'restrict', Title::makeTitle( NS_USER, $user ), $r->getReason(),
array( $r->getType(), $r->getPage()->getFullText(), $logExpiry) );
}
- public static function namespaceRestrictionForm( $uid, $user, $oldRestrictions ) {
- global $wgOut, $wgRequest, $wgUser, $wgContLang;
- $error = '';
- $success = false;
- if( $wgRequest->wasPosted() && $wgRequest->getVal( 'type' ) == UserRestriction::NAMESPACE &&
- $wgUser->matchEditToken( $wgRequest->getVal( 'edittoken' ) ) ) {
- $ns = $wgRequest->getVal( 'namespace' );
- if( $wgContLang->getNsText( $ns ) === false )
- $error = wfMsgExt( 'restrictuser-badnamespace', 'parseinline' );
- elseif( UserRestriction::convertExpiry( $wgRequest->getVal( 'expiry' ) ) === false )
- $error = wfMsgExt( 'restrictuser-badexpiry', 'parseinline', $wgRequest->getVal( 'expiry' ) );
- else
- foreach( $oldRestrictions as $r )
- if( $r->isNamespace() && $r->getNamespace() == $ns )
- $error = wfMsgExt( 'restrictuser-dupnamespace', 'parse' );
- if( !$error ) {
- self::doNamespaceRestriction( $uid, $user );
- $success = array('restrictuser-success', $user);
- }
- }
- $useRequestValues = $wgRequest->getVal( 'type' ) == UserRestriction::NAMESPACE;
- $wgOut->addHTML( Xml::fieldset( wfMsg( 'restrictuser-legend-namespace' ) ) );
-
- self::printSuccessError( $success, $error );
-
- $wgOut->addHTML( Xml::openElement( 'form', array( 'action' => SpecialPage::getTitleFor( 'RestrictUser' )->getLocalUrl(),
- 'method' => 'post' ) ) );
- $wgOut->addHTML( Xml::hidden( 'type', UserRestriction::NAMESPACE ) );
- $wgOut->addHTML( Xml::hidden( 'edittoken', $wgUser->editToken() ) );
- $wgOut->addHTML( Xml::hidden( 'user', $user ) );
- $form = array();
- $form['restrictuser-namespace'] = Xml::namespaceSelector( $wgRequest->getVal( 'namespace' ) );
- $form['restrictuser-expiry'] = Xml::input( 'expiry', false,
- $useRequestValues ? $wgRequest->getVal( 'expiry' ) : false );
- $form['restrictuser-reason'] = Xml::input( 'reason', false,
- $useRequestValues ? $wgRequest->getVal( 'reason' ) : false );
- $wgOut->addHTML( Xml::buildForm( $form, 'restrictuser-submit' ) );
- $wgOut->addHTML( "" );
- }
-
- public static function doNamespaceRestriction( $uid, $user ) {
+ public function doNamespaceRestriction( $uid, $user ) {
global $wgUser, $wgRequest;
$r = new UserRestriction();
$r->setType( UserRestriction::NAMESPACE );
@@ -182,6 +171,7 @@
$r->setExpiry( UserRestriction::convertExpiry( $wgRequest->getVal( 'expiry' ) ) );
$r->setTimestamp( wfTimestampNow( TS_MW ) );
$r->commit();
+
$logExpiry = $wgRequest->getVal( 'expiry' ) ? $wgRequest->getVal( 'expiry' ) : Block::infinity();
$l = new LogPage( 'restrict' );
$l->addEntry( 'restrict', Title::makeTitle( NS_USER, $user ), $r->getReason(),
Index: includes/specials/SpecialRemoveRestrictions.php
===================================================================
--- includes/specials/SpecialRemoveRestrictions.php (revision 52193)
+++ includes/specials/SpecialRemoveRestrictions.php (working copy)
@@ -1,60 +1,74 @@
getSkin();
- $title = SpecialPage::getTitleFor( 'RemoveRestrictions' );
- $id = $wgRequest->getVal( 'id' );
- if( !is_numeric( $id ) ) {
- $wgOut->addWikiMsg( 'removerestrictions-noid' );
- return;
+class SpecialRemoveRestrictions extends UnlistedSpecialPage {
+ public function __construct() {
+ parent::__construct( 'RemoveRestrictions', 'restrict',
+ /*listed*/ false, /*function*/ false, /*file*/ false );
}
- UserRestriction::purgeExpired();
- $r = UserRestriction::newFromId( $id, true );
- if( !$r ) {
- $wgOut->addWikiMsg( 'removerestrictions-wrongid' );
- return;
- }
+ function execute( $par ) {
+ global $wgOut, $wgRequest, $wgUser, $wgLang;
+ $this->setHeaders();
+ $sk = $wgUser->getSkin();
+ $title = SpecialPage::getTitleFor( 'RemoveRestrictions' );
+ $id = $wgRequest->getVal( 'id' );
+ if( !is_numeric( $id ) ) {
+ $id = $par;
+ }
+ if( !is_numeric( $id ) ) {
+ $wgOut->addWikiMsg( 'removerestrictions-noid' );
+ return;
+ }
- $form = array();
- $form['removerestrictions-user'] = $sk->userLink( $r->getSubjectId(), $r->getSubjectText() ) .
- $sk->userToolLinks( $r->getSubjectId(), $r->getSubjectText() );
- $form['removerestrictions-type'] = UserRestriction::formatType( $r->getType() );
- if( $r->isPage() )
- $form['removerestrictions-page'] = $sk->link( $r->getPage() );
- if( $r->isNamespace() )
- $form['removerestrictions-namespace'] = $wgLang->getDisplayNsText( $r->getNamespace() );
- $form['removerestrictions-reason'] = Xml::input( 'reason' );
+ UserRestriction::purgeExpired();
+ $r = UserRestriction::newFromId( $id, true );
+ if( !$r ) {
+ $wgOut->addWikiMsg( 'removerestrictions-wrongid' );
+ return;
+ }
- $result = null;
- if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'edittoken' ) ) )
- $result = wfSpecialRemoveRestrictionsProcess( $r );
+ if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'edittoken' ) ) ) {
+ $result = $this->doRemoveRestriction( $r );
+ if( $result ) {
+ $wgOut->addWikiMsg( 'removerestrictions-success', $r->getSubjectText() );
+ return;
+ }
+ }
- $wgOut->addWikiMsg( 'removerestrictions-intro' );
- $wgOut->addHTML( Xml::fieldset( wfMsgHtml( 'removerestrictions-legend' ) ) );
- if( $result )
- $wgOut->addHTML( '' . wfMsgExt( 'removerestrictions-success',
- 'parseinline', $r->getSubjectText() ) . ' ' );
- $wgOut->addHTML( Xml::openElement( 'form', array( 'action' => $title->getLocalUrl( array( 'id' => $id ) ),
- 'method' => 'post' ) ) );
- $wgOut->addHTML( Xml::buildForm( $form, 'removerestrictions-submit' ) );
- $wgOut->addHTML( Xml::hidden( 'id', $r->getId() ) );
- $wgOut->addHTML( Xml::hidden( 'title', $title->getPrefixedDbKey() ) );
- $wgOut->addHTML( Xml::hidden( 'edittoken', $wgUser->editToken() ) );
- $wgOut->addHTML( "" );
-}
+ $form = array();
+ $form['removerestrictions-user'] = $sk->userLink( $r->getSubjectId(), $r->getSubjectText() ) .
+ $sk->userToolLinks( $r->getSubjectId(), $r->getSubjectText() );
+ $form['removerestrictions-type'] = UserRestriction::formatType( $r->getType() );
+ if( $r->isPage() )
+ $form['removerestrictions-page'] = $sk->link( $r->getPage() );
+ if( $r->isNamespace() )
+ $form['removerestrictions-namespace'] = $wgLang->getDisplayNsText( $r->getNamespace() );
+ $form['removerestrictions-reason'] = Xml::input( 'reason' );
-function wfSpecialRemoveRestrictionsProcess( $r ) {
- global $wgRequest;
- $reason = $wgRequest->getVal( 'reason' );
- $result = $r->delete();
- $log = new LogPage( 'restrict' );
- $params = array( $r->getType() );
- if( $r->isPage() )
- $params[] = $r->getPage()->getPrefixedDbKey();
- if( $r->isNamespace() )
- $params[] = $r->getNamespace();
- $log->addEntry( 'remove', Title::makeTitle( NS_USER, $r->getSubjectText() ), $reason, $params );
- return $result;
+ $wgOut->addWikiMsg( 'removerestrictions-intro' );
+ $wgOut->addHTML( Xml::fieldset( wfMsgHtml( 'removerestrictions-legend' ) ) );
+ $wgOut->addHTML( Xml::openElement( 'form', array( 'action' => $title->getLocalUrl( array( 'id' => $id ) ),
+ 'method' => 'post' ) ) );
+ $wgOut->addHTML( Xml::buildForm( $form, 'removerestrictions-submit' ) );
+ $wgOut->addHTML( Xml::hidden( 'id', $r->getId() ) );
+ $wgOut->addHTML( Xml::hidden( 'title', $title->getPrefixedDbKey() ) );
+ $wgOut->addHTML( Xml::hidden( 'edittoken', $wgUser->editToken() ) );
+ $wgOut->addHTML( "" );
+ }
+
+ function doRemoveRestriction( $r ) {
+ global $wgRequest;
+ $reason = $wgRequest->getVal( 'reason' );
+ $result = $r->delete();
+ $log = new LogPage( 'restrict' );
+ $params = array( $r->getType() );
+ if( $r->isPage() )
+ $params[] = $r->getPage()->getPrefixedDbKey();
+ if( $r->isNamespace() )
+ $params[] = $r->getNamespace();
+ $log->addEntry( 'remove', Title::makeTitle( NS_USER, $r->getSubjectText() ), $reason, $params );
+ $userObj = User::newFromName( $r->getSubjectText(), false );
+ $userObj->invalidateCache();
+ return $result;
+ }
}
Index: includes/specials/SpecialListUserRestrictions.php
===================================================================
--- includes/specials/SpecialListUserRestrictions.php (revision 52193)
+++ includes/specials/SpecialListUserRestrictions.php (working copy)
@@ -1,27 +1,32 @@
addWikiMsg( 'listuserrestrictions-intro' );
- $f = new SpecialListUserRestrictionsForm();
- $wgOut->addHTML( $f->getHTML() );
+class SpecialListUserRestrictions extends SpecialPage {
+ public function __construct() {
+ parent::__construct( 'ListUserRestrictions', false,
+ /*listed*/ true, /*function*/ false, /*file*/ false );
+ }
- if( !mt_rand( 0, 10 ) )
- UserRestriction::purgeExpired();
- $pager = new UserRestrictionsPager( $f->getConds() );
- if( $pager->getNumRows() )
- $wgOut->addHTML( $pager->getNavigationBar() .
- Xml::tags( 'ul', null, $pager->getBody() ) .
- $pager->getNavigationBar()
- );
- elseif( $f->getConds() )
- $wgOut->addWikiMsg( 'listuserrestrictions-notfound' );
- else
- $wgOut->addWikiMsg( 'listuserrestrictions-empty' );
-}
+ function execute() {
+ global $wgOut, $wgRequest;
-class SpecialListUserRestrictionsForm {
+ $this->setHeaders();
+ $wgOut->addWikiMsg( 'listuserrestrictions-intro' );
+ $wgOut->addHTML( $this->getHTML() );
+
+ if( !mt_rand( 0, 10 ) )
+ UserRestriction::purgeExpired();
+ $pager = new UserRestrictionsPager( $this->getConds() );
+ if( $pager->getNumRows() )
+ $wgOut->addHTML( $pager->getNavigationBar() .
+ Xml::tags( 'ul', null, $pager->getBody() ) .
+ $pager->getNavigationBar()
+ );
+ elseif( $this->getConds() )
+ $wgOut->addWikiMsg( 'listuserrestrictions-notfound' );
+ else
+ $wgOut->addWikiMsg( 'listuserrestrictions-empty' );
+ }
+
public function getHTML() {
global $wgRequest, $wgScript;
$action = htmlspecialchars( $wgScript );
@@ -30,7 +35,7 @@
$s .= "