r20471 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r20470‎ | r20471 | r20472 >
Date:22:57, 14 March 2007
Author:aaron
Status:old
Tags:
Comment:
*Add framework for proper protection cascading
Modified paths:
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.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
@@ -97,7 +97,7 @@
9898 return;
9999 }
100100
101 - $cascadeSources = $this->mTitle->getCascadeProtectionSources();
 101+ list( $cascadeSources, $restrictions ) = $this->mTitle->getCascadeProtectionSources();
102102
103103 if ( "" != $err ) {
104104 $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
Index: trunk/phase3/includes/EditPage.php
@@ -993,7 +993,7 @@
994994 $notice = '';
995995 } else {
996996 # It's either cascading protection or regular protection; work out which
997 - $cascadeSources = $this->mTitle->getCascadeProtectionSources();
 997+ list($cascadeSources, $restrictions) = $this->mTitle->getCascadeProtectionSources();
998998 if( $cascadeSources && count( $cascadeSources ) > 0 ) {
999999 # Cascading protection; explain, and list the titles responsible
10001000 $notice = wfMsg( 'cascadeprotectedwarning' ) . "\n";
Index: trunk/phase3/includes/OutputPage.php
@@ -897,7 +897,7 @@
898898 $this->setPageTitle( wfMsg( 'viewsource' ) );
899899 $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
900900
901 - $cascadeSources = $wgTitle->getCascadeProtectionSources();
 901+ list( $cascadeSources, $restrictions ) = $wgTitle->getCascadeProtectionSources();
902902
903903 # Determine if protection is due to the page being a system message
904904 # and show an appropriate explanation
Index: trunk/phase3/includes/Title.php
@@ -1037,11 +1037,6 @@
10381038 # Special pages have inherent protection
10391039 if( $this->getNamespace() == NS_SPECIAL )
10401040 return true;
1041 -
1042 - # Cascading protection depends on more than
1043 - # this page...
1044 - if( $this->isCascadeProtected() )
1045 - return true;
10461041
10471042 # Check regular protection levels
10481043 if( $action == 'edit' || $action == '' ) {
@@ -1150,17 +1145,27 @@
11511146 return false;
11521147 }
11531148
1154 - if ( $doExpensiveQueries && !$this->isCssJsSubpage() && $this->isCascadeProtected() ) {
 1149+ if ( $doExpensiveQueries && !$this->isCssJsSubpage() ) {
11551150 # We /could/ use the protection level on the source page, but it's fairly ugly
11561151 # as we have to establish a precedence hierarchy for pages included by multiple
11571152 # cascade-protected pages. So just restrict it to people with 'protect' permission,
11581153 # as they could remove the protection anyway.
1159 - if ( !$wgUser->isAllowed('protect') ) {
1160 - wfProfileOut( $fname );
1161 - return false;
 1154+ list( $cascadingSources, $restrictions ) = $this->getCascadeProtectionSources();
 1155+ # Cascading protection depends on more than this page...
 1156+ # Several cascading protected pages may include this page...
 1157+ # Check each cascading level
 1158+ # This is only for protection restrictions, not for all actions
 1159+ if( $cascadingSources > 0 && isset($restrictions[$action]) ) {
 1160+ foreach( $restrictions[$action] as $right ) {
 1161+ $right = ( $right == 'sysop' ) ? 'protect' : $right;
 1162+ if( '' != $right && !$wgUser->isAllowed( $right ) ) {
 1163+ wfProfileOut( $fname );
 1164+ return false;
 1165+ }
 1166+ }
11621167 }
11631168 }
1164 -
 1169+
11651170 foreach( $this->getRestrictions($action) as $right ) {
11661171 // Backwards compatibility, rewrite sysop -> protect
11671172 if ( $right == 'sysop' ) {
@@ -1360,25 +1365,34 @@
13611366 * @access public.
13621367 */
13631368 function isCascadeProtected() {
1364 - return ( $this->getCascadeProtectionSources( false ) );
 1369+ list( $sources, $restrictions ) = $this->getCascadeProtectionSources( false );
 1370+ return ( $sources > 0 );
13651371 }
13661372
13671373 /**
13681374 * Cascading protection: Get the source of any cascading restrictions on this page.
13691375 *
13701376 * @param $get_pages bool Whether or not to retrieve the actual pages that the restrictions have come from.
1371 - * @return mixed Array of the Title objects of the pages from which cascading restrictions have come, false for none, or true if such restrictions exist, but $get_pages was not set.
 1377+ * @return array( mixed title array, restriction array)
 1378+ * Array of the Title objects of the pages from which cascading restrictions have come, false for none, or true if such restrictions exist, but $get_pages was not set.
 1379+ * The restriction array is an array of each type, each of which contains an array of unique groups
13721380 * @access public
13731381 */
13741382 function getCascadeProtectionSources( $get_pages = true ) {
1375 - global $wgEnableCascadingProtection;
 1383+ global $wgEnableCascadingProtection, $wgRestrictionTypes;
 1384+
 1385+ # Define our dimension of restrictions types
 1386+ $pagerestrictions = array();
 1387+ foreach( $wgRestrictionTypes as $action )
 1388+ $pagerestrictions[$action] = array();
 1389+
13761390 if (!$wgEnableCascadingProtection)
1377 - return false;
 1391+ return array( false, $pagerestrictions );
13781392
13791393 if ( isset( $this->mCascadeSources ) && $get_pages ) {
1380 - return $this->mCascadeSources;
 1394+ return array( $this->mCascadeSources, $this->mCascadingRestrictions );
13811395 } else if ( isset( $this->mHasCascadingRestrictions ) && !$get_pages ) {
1382 - return $this->mHasCascadingRestrictions;
 1396+ return array( $this->mHasCascadingRestrictions, $pagerestrictions );
13831397 }
13841398
13851399 wfProfileIn( __METHOD__ );
@@ -1401,7 +1415,7 @@
14021416 }
14031417
14041418 if ( $get_pages ) {
1405 - $cols = array('pr_page', 'page_namespace', 'page_title', 'pr_expiry' );
 1419+ $cols = array('pr_page', 'page_namespace', 'page_title', 'pr_expiry', 'pr_type', 'pr_level' );
14061420 $where_clauses[] = 'page_id=pr_page';
14071421 $tables[] = 'page';
14081422 } else {
@@ -1422,6 +1436,11 @@
14231437 $page_ns = $row->page_namespace;
14241438 $page_title = $row->page_title;
14251439 $sources[$page_id] = Title::makeTitle($page_ns, $page_title);
 1440+ # Add groups needed for each restriction type if its not already there
 1441+ # Make sure this restriction type still exists
 1442+ if ( isset($pagerestrictions[$row->pr_type]) && !in_array($row->pr_level, $pagerestrictions[$row->pr_type]) ) {
 1443+ $pagerestrictions[$row->pr_type][]=$row->pr_level;
 1444+ }
14261445 } else {
14271446 $sources = true;
14281447 }
@@ -1438,11 +1457,12 @@
14391458
14401459 if ( $get_pages ) {
14411460 $this->mCascadeSources = $sources;
 1461+ $this->mCascadingRestrictions = $pagerestrictions;
14421462 } else {
14431463 $this->mHasCascadingRestrictions = $sources;
14441464 }
14451465
1446 - return $sources;
 1466+ return array( $sources, $pagerestrictions );
14471467 }
14481468
14491469 function areRestrictionsCascading() {
@@ -1505,7 +1525,7 @@
15061526 if ( !$expiry || $expiry > $now ) {
15071527 $this->mRestrictionsExpiry = $expiry;
15081528 $this->mRestrictions[$row->pr_type] = explode( ',', trim( $row->pr_level ) );
1509 -
 1529+
15101530 $this->mCascadeRestriction |= $row->pr_cascade;
15111531 } else {
15121532 // Trigger a lazy purge of expired restrictions