From: Rob Church Date: Sat, 8 Apr 2006 20:50:08 +0000 (+0000) Subject: (bug 4760) Prevent creation of entries in protection log when protection levels haven... X-Git-Tag: 1.31.0-rc.0~57545 X-Git-Url: http://git.cyclocoop.org//%27%40script%40/%27?a=commitdiff_plain;h=2be674b1bbae774a0bcd3fc14b332cb768eee84f;p=lhc%2Fweb%2Fwiklou.git (bug 4760) Prevent creation of entries in protection log when protection levels haven't changed --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index d790bc6ffa..a8623858d4 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -36,6 +36,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 5344) Fix regression that broke slashes in extension tag parameters * Improve Special:Log performance on big log sets * (bug 5507) Changed mediawiki:logouttext from plain to wikitext +* (bug 4760) Prevent creation of entries in protection log when protection levels haven't changed == Compatibility == diff --git a/includes/Article.php b/includes/Article.php index f844149ed0..2d5dabc4a8 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -1690,47 +1690,51 @@ class Article { * @return bool true on success */ function updateRestrictions( $limit = array(), $reason = '' ) { - global $wgUser; - - if ( !$wgUser->isAllowed( 'protect' ) ) { - return false; - } - - if( wfReadOnly() ) { - return false; - } - + global $wgUser, $wgRestrictionTypes; + $id = $this->mTitle->getArticleID(); - if ( 0 == $id ) { + if( !$wgUser->isAllowed( 'protect' ) || wfReadOnly() || $id == 0 ) { return false; } - $flat = Article::flattenRestrictions( $limit ); - $protecting = ($flat != ''); - - if( wfRunHooks( 'ArticleProtect', array( &$this, &$wgUser, - $limit, $reason ) ) ) { + # FIXME: Same limitations as described in ProtectionForm.php (line 37); + # we expect a single selection, but the schema allows otherwise. + $current = array(); + foreach( $wgRestrictionTypes as $action ) + $current[$action] = implode( '', $this->mTitle->getRestrictions( $action ) ); - $dbw =& wfGetDB( DB_MASTER ); - $dbw->update( 'page', - array( /* SET */ - 'page_touched' => $dbw->timestamp(), - 'page_restrictions' => $flat - ), array( /* WHERE */ - 'page_id' => $id - ), 'Article::protect' - ); - - wfRunHooks( 'ArticleProtectComplete', array( &$this, &$wgUser, - $limit, $reason ) ); - - $log = new LogPage( 'protect' ); - if( $protecting ) { - $log->addEntry( 'protect', $this->mTitle, trim( $reason . " [$flat]" ) ); - } else { - $log->addEntry( 'unprotect', $this->mTitle, $reason ); - } - } + $current = Article::flattenRestrictions( $current ); + $updated = Article::flattenRestrictions( $limit ); + + $changed = ( $current != $updated ); + $protect = ( $updated != '' ); + + # If nothing's changed, do nothing + if( $changed ) { + if( wfRunHooks( 'ArticleProtect', array( &$this, &$wgUser, $limit, $reason ) ) ) { + # Update page record + $dbw =& wfGetDB( DB_MASTER ); + $dbw->update( 'page', + array( /* SET */ + 'page_touched' => $dbw->timestamp(), + 'page_restrictions' => $updated + ), array( /* WHERE */ + 'page_id' => $id + ), 'Article::protect' + ); + wfRunHooks( 'ArticleProtectComplete', array( &$this, &$wgUser, $limit, $reason ) ); + + # Update the protection log + $log = new LogPage( 'protect' ); + if( $protect ) { + $log->addEntry( 'protect', $this->mTitle, trim( $reason . " [$updated]" ) ); + } else { + $log->addEntry( 'unprotect', $this->mTitle, $reason ); + } + + } # End hook + } # End "changed" check + return true; } @@ -1746,6 +1750,7 @@ class Article { wfDebugDieBacktrace( 'Article::flattenRestrictions given non-array restriction set' ); } $bits = array(); + ksort( $limit ); foreach( $limit as $action => $restrictions ) { if( $restrictions != '' ) { $bits[] = "$action=$restrictions";