From 2190984466b0fd136f0fca0ed2df1ac5cc0dc02a Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 31 Dec 2008 18:56:16 +0000 Subject: [PATCH] Revert r45231, r45235 "* (bug 674) Allow users to be blocked from editing a specific article" Unexpected schema changes in the middle of code review and run-up to 1.14 freeze --- includes/Article.php | 7 +- includes/AutoLoader.php | 2 - includes/DefaultSettings.php | 8 - includes/LogPage.php | 14 -- includes/SpecialPage.php | 3 - includes/Title.php | 59 ++---- includes/User.php | 3 +- includes/UserRestriction.php | 189 ------------------ .../specials/SpecialListUserRestrictions.php | 2 +- .../specials/SpecialRemoveRestrictions.php | 2 - includes/specials/SpecialRestrictUser.php | 17 +- languages/messages/MessagesEn.php | 102 ---------- .../archives/patch-user_restrictions.sql | 41 ---- maintenance/language/messages.inc | 72 ------- maintenance/parserTests.inc | 2 +- maintenance/tables.sql | 43 ---- maintenance/updaters.inc | 5 +- 17 files changed, 30 insertions(+), 541 deletions(-) delete mode 100644 includes/UserRestriction.php delete mode 100644 maintenance/archives/patch-user_restrictions.sql diff --git a/includes/Article.php b/includes/Article.php index 8c9366b871..b0bf080da4 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -2435,12 +2435,7 @@ class Article { ); # Delete restrictions for it - $dbw->delete( 'page_restrictions', array( 'pr_page' => $id ), __METHOD__ ); - $dbw->delete( 'user_restrictions', - array( - 'ur_page_namespace' => $this->mTitle->getNamespace(), - 'ur_page_title' => $this->mTitle->getDBKey() - ), __METHOD__ ); + $dbw->delete( 'page_restrictions', array ( 'pr_page' => $id ), __METHOD__ ); # Now that it's safely backed up, delete it $dbw->delete( 'page', array( 'page_id' => $id ), __METHOD__); diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 5b4f2a9675..ce1912ea65 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -201,8 +201,6 @@ $wgAutoloadLocalClasses = array( 'UserArray' => 'includes/UserArray.php', 'UserArrayFromResult' => 'includes/UserArray.php', 'UserMailer' => 'includes/UserMailer.php', - 'UserRestriction' => 'includes/UserRestriction.php', - 'UserRestrictionsPager' => 'includes/specials/SpecialListUserRestrictions.php', 'UserRightsProxy' => 'includes/UserRightsProxy.php', 'WatchedItem' => 'includes/WatchedItem.php', 'WatchlistEditor' => 'includes/WatchlistEditor.php', diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 87d6e3dad7..695e38c28d 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1232,7 +1232,6 @@ $wgGroupPermissions['sysop']['markbotedits'] = true; $wgGroupPermissions['sysop']['apihighlimits'] = true; $wgGroupPermissions['sysop']['browsearchive'] = true; $wgGroupPermissions['sysop']['noratelimit'] = true; -$wgGroupPermissions['sysop']['restrict'] = true; $wgGroupPermissions['sysop']['movefile'] = true; #$wgGroupPermissions['sysop']['mergehistory'] = true; @@ -2797,7 +2796,6 @@ $wgLogTypes = array( '', 'patrol', 'merge', 'suppress', - 'restrict', ); /** @@ -2852,7 +2850,6 @@ $wgLogNames = array( 'patrol' => 'patrol-log-page', 'merge' => 'mergelog', 'suppress' => 'suppressionlog', - 'restrict' => 'restrictionlog', ); /** @@ -2873,7 +2870,6 @@ $wgLogHeaders = array( 'patrol' => 'patrol-log-header', 'merge' => 'mergelogpagetext', 'suppress' => 'suppressionlogtext', - 'restrict' => 'restrictionlogtext', ); /** @@ -2909,8 +2905,6 @@ $wgLogActions = array( 'suppress/delete' => 'suppressedarticle', 'suppress/block' => 'blocklogentry', 'suppress/reblock' => 'reblock-logentry', - 'restrict/restrict' => 'restrictentry', - 'restrict/remove' => 'restrictremoveentry', ); /** @@ -2982,8 +2976,6 @@ $wgSpecialPageGroups = array( 'Preferences' => 'users', 'Resetpass' => 'users', 'DeletedContributions' => 'users', - 'ListUserRestrictions' => 'users', - 'RestrictUser' => 'users', 'Mostlinked' => 'highuse', 'Mostlinkedcategories' => 'highuse', diff --git a/includes/LogPage.php b/includes/LogPage.php index 5003576d7a..50a9a23264 100644 --- a/includes/LogPage.php +++ b/includes/LogPage.php @@ -193,19 +193,6 @@ class LogPage { } else { $rv = wfMsgForContent( $wgLogActions[$key], $titleLink ); } - } elseif( $type == 'restrict' ) { - if( $params[0] == UserRestriction::PAGE ) - $subj = wfMsgExt( 'restrictlogpage', 'parseinline', $params[1] ); - if( $params[0] == UserRestriction::NAMESPACE ) - $subj = wfMsgExt( 'restrictlognamespace', 'parseinline', $wgLang->getDisplayNsText( $params[1] ) ); - $expiry = ''; - if( $key == 'restrict/restrict' ) - $expiry = $wgLang->translateBlockExpiry( $params[2] ); - if ( $skin ) { - $rv = wfMsg( $wgLogActions[$key], $titleLink, $subj, $expiry ); - } else { - $rv = wfMsgForContent( $wgLogActions[$key], $titleLink, $subj, $expiry ); - } } else { $details = ''; array_unshift( $params, $titleLink ); @@ -277,7 +264,6 @@ class LogPage { } break; case 'rights': - case 'restrict': $text = $wgContLang->ucfirst( $title->getText() ); $titleLink = $skin->makeLinkObj( Title::makeTitle( NS_USER, $text ) ); break; diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index 6df071ef8e..812ad53888 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -129,9 +129,6 @@ class SpecialPage 'Allpages' => 'SpecialAllpages', 'Prefixindex' => 'SpecialPrefixindex', 'Ipblocklist' => array( 'SpecialPage', 'Ipblocklist' ), - 'ListUserRestrictions' => array( 'SpecialPage', 'ListUserRestrictions' ), - 'RemoveRestrictions' => array( 'UnlistedSpecialPage', 'RemoveRestrictions', 'restrict' ), - 'RestrictUser' => array( 'SpecialPage', 'RestrictUser', 'restrict' ), 'Specialpages' => array( 'UnlistedSpecialPage', 'Specialpages' ), 'Contributions' => 'SpecialContributions', 'Emailuser' => array( 'UnlistedSpecialPage', 'Emailuser' ), diff --git a/includes/Title.php b/includes/Title.php index 593b11c42d..bc042210c0 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1009,7 +1009,9 @@ class Title { } $errors = $this->getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries ); - global $wgContLang, $wgLang, $wgEmailConfirmToEdit; + global $wgContLang; + global $wgLang; + global $wgEmailConfirmToEdit; if ( $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount' ) { $errors[] = array( 'confirmedittext' ); @@ -1041,7 +1043,20 @@ class Title { $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW, $user->mBlock->mTimestamp ), true ); if ( $blockExpiry == 'infinity' ) { - $blockExpiry = wfMsg( 'ipbinfinite' ); + // 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; + } + } } else { $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW, $blockExpiry ), true ); } @@ -1051,9 +1066,9 @@ class Title { $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; @@ -1076,8 +1091,6 @@ class Title { * @return \type{\array} Array of arrays of the arguments to wfMsg to explain permissions problems. */ private function getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries = true ) { - global $wgLang; - wfProfileIn( __METHOD__ ); $errors = array(); @@ -1249,34 +1262,6 @@ class Title { $errors[] = $return; } - // 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; } @@ -2573,12 +2558,6 @@ class Title { $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; diff --git a/includes/User.php b/includes/User.php index d73836d526..4f36d14138 100644 --- a/includes/User.php +++ b/includes/User.php @@ -151,7 +151,7 @@ class User { 'markbotedits', 'minoredit', 'move', - 'movefile', + 'movepage', 'move-rootuserpages', 'move-subpages', 'nominornewtalk', @@ -161,7 +161,6 @@ class User { 'proxyunbannable', 'purge', 'read', - 'restrict', 'reupload', 'reupload-shared', 'rollback', diff --git a/includes/UserRestriction.php b/includes/UserRestriction.php deleted file mode 100644 index 05152cce36..0000000000 --- a/includes/UserRestriction.php +++ /dev/null @@ -1,189 +0,0 @@ -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 ); - } -} diff --git a/includes/specials/SpecialListUserRestrictions.php b/includes/specials/SpecialListUserRestrictions.php index 86aef62571..27b2429822 100644 --- a/includes/specials/SpecialListUserRestrictions.php +++ b/includes/specials/SpecialListUserRestrictions.php @@ -134,7 +134,7 @@ class UserRestrictionsPager extends ReverseChronologicalPager { $subjlink = $sk->userLink( $r->getSubjectId(), $r->getSubjectText() ) . $sk->userToolLinks( $r->getSubjectId(), $r->getSubjectText() ); $expiry = is_numeric( $r->getExpiry() ) ? - wfMsg( 'listuserrestrictions-row-expiry', $wgLang->date( $r->getExpiry() ), $wgLang->time( $r->getExpiry() ) ) : + wfMsg( 'listuserrestrictions-row-expiry', $wgLang->timeanddate( $r->getExpiry() ) ) : wfMsg( 'ipbinfinite' ); $msg = ''; if( $r->isNamespace() ) { diff --git a/includes/specials/SpecialRemoveRestrictions.php b/includes/specials/SpecialRemoveRestrictions.php index 5ad21ddb9b..ded6cbe3d7 100644 --- a/includes/specials/SpecialRemoveRestrictions.php +++ b/includes/specials/SpecialRemoveRestrictions.php @@ -56,7 +56,5 @@ function wfSpecialRemoveRestrictionsProcess( $r ) { 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; } diff --git a/includes/specials/SpecialRestrictUser.php b/includes/specials/SpecialRestrictUser.php index 6c3a82abb8..761e0cd6e1 100644 --- a/includes/specials/SpecialRestrictUser.php +++ b/includes/specials/SpecialRestrictUser.php @@ -2,8 +2,6 @@ function wfSpecialRestrictUser( $par = null ) { global $wgOut, $wgRequest; - $wgOut->addHTML( wfMsgExt( 'restrictuser-description', 'parse' ) ); - $user = $userOrig = null; if( $par ) { $userOrig = $par; @@ -50,6 +48,8 @@ class RestrictUserForm { } public static function existingRestrictions( $restrictions ) { + //TODO: autoload? + require_once( dirname( __FILE__ ) . '/SpecialListUserRestrictions.php' ); $s = Xml::fieldset( wfMsg( 'restrictuser-existing' ) ) . '