r36519 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36518‎ | r36519 | r36520 >
Date:03:17, 21 June 2008
Author:aaron
Status:old
Tags:
Comment:
* Revert r36478; I don't see the point in this cryptic code
* Restore r36273 as explain on mailing list
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/ProtectionForm.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ProtectionForm.php
@@ -91,7 +91,8 @@
9292 global $wgRequest, $wgOut;
9393 if( $wgRequest->wasPosted() ) {
9494 if( $this->save() ) {
95 - $q = $this->mArticle->isRedirect() ? 'redirect=no' : '';
 95+ $article = new Article( $this->mTitle );
 96+ $q = $article->isRedirect() ? 'redirect=no' : '';
9697 $wgOut->redirect( $this->mTitle->getFullUrl( $q ) );
9798 }
9899 } else {
@@ -189,10 +190,17 @@
190191
191192 }
192193
193 - # NOTE : verification of cascading protection in semi-protection mode
194 - # is in Article::updateRestriction()
 194+ # They shouldn't be able to do this anyway, but just to make sure, ensure that cascading restrictions aren't being applied
 195+ # to a semi-protected page.
 196+ global $wgGroupPermissions;
195197
196 - if( $this->mTitle->exists() ){
 198+ $edit_restriction = $this->mRestrictions['edit'];
 199+
 200+ if ($this->mCascade && ($edit_restriction != 'protect') &&
 201+ !(isset($wgGroupPermissions[$edit_restriction]['protect']) && $wgGroupPermissions[$edit_restriction]['protect'] ) )
 202+ $this->mCascade = false;
 203+
 204+ if ($this->mTitle->exists()) {
197205 $ok = $this->mArticle->updateRestrictions( $this->mRestrictions, $this->mReason, $this->mCascade, $expiry );
198206 } else {
199207 $ok = $this->mTitle->updateTitleProtection( $this->mRestrictions['create'], $this->mReason, $expiry );
@@ -371,15 +379,7 @@
372380 $script = 'var wgCascadeableLevels=';
373381 $CascadeableLevels = array();
374382 foreach( $wgRestrictionLevels as $key ) {
375 - $canCascade = true;
376 - $check = $key == 'sysop' ? 'protect' : $key;
377 - foreach( $wgGroupPermissions as $group => $rights ){
378 - if( isset( $rights[$check] ) && $rights[$check] && !( isset( $rights['protect'] ) && $rights['protect'] ) ){
379 - $canCascade = false;
380 - break;
381 - }
382 - }
383 - if( $key != '' && $canCascade ) {
 383+ if ( (isset($wgGroupPermissions[$key]['protect']) && $wgGroupPermissions[$key]['protect']) || $key == 'protect' ) {
384384 $CascadeableLevels[] = "'" . Xml::escapeJsString( $key ) . "'";
385385 }
386386 }
Index: trunk/phase3/includes/Article.php
@@ -16,26 +16,26 @@
1717 /**@{{
1818 * @private
1919 */
20 - var $mComment; //!<
21 - var $mContent; //!<
22 - var $mContentLoaded; //!<
23 - var $mCounter; //!<
24 - var $mForUpdate; //!<
25 - var $mGoodAdjustment; //!<
26 - var $mLatest; //!<
27 - var $mMinorEdit; //!<
28 - var $mOldId; //!<
29 - var $mRedirectedFrom; //!<
30 - var $mRedirectUrl; //!<
31 - var $mRevIdFetched; //!<
32 - var $mRevision; //!<
33 - var $mTimestamp; //!<
34 - var $mTitle; //!<
35 - var $mTotalAdjustment; //!<
36 - var $mTouched; //!<
37 - var $mUser; //!<
38 - var $mUserText; //!<
39 - var $mRedirectTarget; //!<
 20+ var $mComment; //!<
 21+ var $mContent; //!<
 22+ var $mContentLoaded; //!<
 23+ var $mCounter; //!<
 24+ var $mForUpdate; //!<
 25+ var $mGoodAdjustment; //!<
 26+ var $mLatest; //!<
 27+ var $mMinorEdit; //!<
 28+ var $mOldId; //!<
 29+ var $mRedirectedFrom; //!<
 30+ var $mRedirectUrl; //!<
 31+ var $mRevIdFetched; //!<
 32+ var $mRevision; //!<
 33+ var $mTimestamp; //!<
 34+ var $mTitle; //!<
 35+ var $mTotalAdjustment; //!<
 36+ var $mTouched; //!<
 37+ var $mUser; //!<
 38+ var $mUserText; //!<
 39+ var $mRedirectTarget; //!<
4040 var $mIsRedirect;
4141 /**@}}*/
4242
@@ -543,9 +543,9 @@
544544 */
545545 function isRedirect( $text = false ) {
546546 if ( $text === false ) {
547 - if ( $this->mDataLoaded )
 547+ if ( $this->mDataLoaded )
548548 return $this->mIsRedirect;
549 -
 549+
550550 // Apparently loadPageData was never called
551551 $this->loadContent();
552552 $titleObj = Title::newFromRedirect( $this->fetchContent() );
@@ -924,14 +924,14 @@
925925 $this->viewUpdates();
926926 wfProfileOut( __METHOD__ );
927927 }
928 -
 928+
929929 protected function viewRedirect( $target, $overwriteSubtitle = true, $forceKnown = false ) {
930930 global $wgParser, $wgOut, $wgContLang, $wgStylePath, $wgUser;
931 -
 931+
932932 # Display redirect
933933 $imageDir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
934934 $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
935 -
 935+
936936 if( $overwriteSubtitle ) {
937937 $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) );
938938 }
@@ -943,7 +943,7 @@
944944
945945 $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT " />' .
946946 '<span class="redirectText">'.$link.'</span>' );
947 -
 947+
948948 }
949949
950950 function addTrackbacks() {
@@ -1451,7 +1451,7 @@
14521452
14531453 # Update page
14541454 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
1455 -
 1455+
14561456 wfRunHooks( 'NewRevisionFromEditComplete', array($this, $revision, $baseRevId) );
14571457
14581458 if( !$ok ) {
@@ -1523,7 +1523,7 @@
15241524
15251525 # Update the page record with revision data
15261526 $this->updateRevisionOn( $dbw, $revision, 0 );
1527 -
 1527+
15281528 wfRunHooks( 'NewRevisionFromEditComplete', array($this, $revision, false) );
15291529
15301530 if( !( $flags & EDIT_SUPPRESS_RC ) ) {
@@ -1835,17 +1835,13 @@
18361836 }
18371837 $comment = $wgContLang->ucfirst( wfMsgForContent( $comment_type, $this->mTitle->getPrefixedText() ) );
18381838
1839 - # Check if all groups that have required right to edit also can protect pages
 1839+ # Only restrictions with the 'protect' right can cascade...
18401840 # Otherwise, people who cannot normally protect can "protect" pages via transclusion
1841 - foreach( $limit as $action => $restrictions ) {
1842 - # 'sysop' is checked as 'protect', so it is always allowed
1843 - if ($cascade && ( $restrictions != 'sysop' ) ){
1844 - foreach( $wgGroupPermissions as $group => $rights ){
1845 - if( isset( $rights[$restrictions] ) && $rights[$restrictions] && !( isset( $rights['protect'] ) && $rights['protect'] ) ){
1846 - $cascade = false;
1847 - break( 2 );
1848 - }
1849 - }
 1841+ foreach( $limit as $action => $restriction ) {
 1842+ # FIXME: can $restriction be an array or what? (same as fixme above)
 1843+ if( $restriction != 'protect' && $restriction != 'sysop' ) {
 1844+ $cascade = false;
 1845+ break;
18501846 }
18511847 }
18521848
@@ -1888,16 +1884,17 @@
18891885 'page_latest' => $nullRevId
18901886 ), array( /* WHERE */
18911887 'page_id' => $id
1892 - ), __METHOD__
 1888+ ), 'Article::protect'
18931889 );
1894 -
 1890+
18951891 wfRunHooks( 'NewRevisionFromEditComplete', array($this, $nullRevision, false) );
18961892 wfRunHooks( 'ArticleProtectComplete', array( &$this, &$wgUser, $limit, $reason ) );
18971893
18981894 # Update the protection log
18991895 $log = new LogPage( 'protect' );
19001896 if( $protect ) {
1901 - $log->addEntry( $modified ? 'modify' : 'protect', $this->mTitle, trim( $reason . " [$updated]$cascade_description$expiry_description" ) );
 1897+ $log->addEntry( $modified ? 'modify' : 'protect', $this->mTitle,
 1898+ trim( $reason . " [$updated]$cascade_description$expiry_description" ) );
19021899 } else {
19031900 $log->addEntry( 'unprotect', $this->mTitle, $reason );
19041901 }
@@ -2251,7 +2248,7 @@
22522249 function doDelete( $reason, $suppress = false ) {
22532250 global $wgOut, $wgUser;
22542251 wfDebug( __METHOD__."\n" );
2255 -
 2252+
22562253 $id = $this->getId();
22572254
22582255 if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
@@ -2523,14 +2520,14 @@
25242521 if( empty( $summary ) ){
25252522 $summary = wfMsgForContent( 'revertpage' );
25262523 }
2527 -
 2524+
25282525 # Allow the custom summary to use the same args as the default message
25292526 $args = array(
25302527 $target->getUserText(), $from, $s->rev_id,
25312528 $wgLang->timeanddate(wfTimestamp(TS_MW, $s->rev_timestamp), true),
25322529 $current->getId(), $wgLang->timeanddate($current->getTimestamp())
25332530 );
2534 - $summary = wfMsgReplaceArgs( $summary, $args );
 2531+ $summary = wfMsgReplaceArgs( $summary, $args );
25352532
25362533 # Save
25372534 $flags = EDIT_UPDATE;
@@ -2618,7 +2615,7 @@
26192616 . $wgUser->getSkin()->userToolLinks( $target->getUser(), $target->getUserText() );
26202617 $wgOut->addHtml( wfMsgExt( 'rollback-success', array( 'parse', 'replaceafter' ), $old, $new ) );
26212618 $wgOut->returnToMain( false, $this->mTitle );
2622 -
 2619+
26232620 if( !$wgRequest->getBool( 'hidediff', false ) ) {
26242621 $de = new DifferenceEngine( $this->mTitle, $current->getId(), 'next', false, true );
26252622 $de->showDiff( '', '' );
@@ -2990,7 +2987,7 @@
29912988 $revision->insertOn( $dbw );
29922989 $this->updateRevisionOn( $dbw, $revision );
29932990 $dbw->commit();
2994 -
 2991+
29952992 wfRunHooks( 'NewRevisionFromEditComplete', array($this, $revision, false) );
29962993
29972994 wfProfileOut( __METHOD__ );
Index: trunk/phase3/includes/Title.php
@@ -1219,10 +1219,15 @@
12201220 $right = 'protect';
12211221 }
12221222 if( '' != $right && !$user->isAllowed( $right ) ) {
1223 - // Users with 'editprotected' permission can edit protected
1224 - // pages if protection is not with cascading option turned on.
1225 - if( $action=='edit' && $user->isAllowed( 'editprotected' ) && !$this->areRestrictionsCascading() ) {
1226 - // Nothing, user can edit!
 1223+ //Users with 'editprotected' permission can edit protected pages
 1224+ if( $action=='edit' && $user->isAllowed( 'editprotected' ) ) {
 1225+ //Users with 'editprotected' permission cannot edit protected pages
 1226+ //with cascading option turned on.
 1227+ if($this->mCascadeRestriction) {
 1228+ $errors[] = array( 'protectedpagetext', $right );
 1229+ } else {
 1230+ //Nothing, user can edit!
 1231+ }
12271232 } else {
12281233 $errors[] = array( 'protectedpagetext', $right );
12291234 }
@@ -1621,7 +1626,7 @@
16221627
16231628 wfProfileIn( __METHOD__ );
16241629
1625 - $dbr = wfGetDB( DB_SLAVE );
 1630+ $dbr = wfGetDb( DB_SLAVE );
16261631
16271632 if ( $this->getNamespace() == NS_IMAGE ) {
16281633 $tables = array ('imagelinks', 'page_restrictions');
@@ -1922,7 +1927,7 @@
19231928 if ($this->mLatestID !== false)
19241929 return $this->mLatestID;
19251930
1926 - $db = ($flags & GAID_FOR_UPDATE) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
 1931+ $db = ($flags & GAID_FOR_UPDATE) ? wfGetDB(DB_MASTER) : wfGetDB(DB_SLAVE);
19271932 return $this->mLatestID = $db->selectField( 'revision',
19281933 "max(rev_id)",
19291934 array('rev_page' => $this->getArticleID($flags)),

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r36273* Fix confused code...aaron23:32, 13 June 2008
r36478Note that restrictions are rights, not groups. So now, cascading protection w...ialex20:40, 19 June 2008

Status & tagging log