Index: trunk/phase3/includes/ProtectionForm.php |
— | — | @@ -97,7 +97,7 @@ |
98 | 98 | return; |
99 | 99 | } |
100 | 100 | |
101 | | - $cascadeSources = $this->mTitle->getCascadeProtectionSources(); |
| 101 | + list( $cascadeSources, $restrictions ) = $this->mTitle->getCascadeProtectionSources(); |
102 | 102 | |
103 | 103 | if ( "" != $err ) { |
104 | 104 | $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) ); |
Index: trunk/phase3/includes/EditPage.php |
— | — | @@ -993,7 +993,7 @@ |
994 | 994 | $notice = ''; |
995 | 995 | } else { |
996 | 996 | # It's either cascading protection or regular protection; work out which |
997 | | - $cascadeSources = $this->mTitle->getCascadeProtectionSources(); |
| 997 | + list($cascadeSources, $restrictions) = $this->mTitle->getCascadeProtectionSources(); |
998 | 998 | if( $cascadeSources && count( $cascadeSources ) > 0 ) { |
999 | 999 | # Cascading protection; explain, and list the titles responsible |
1000 | 1000 | $notice = wfMsg( 'cascadeprotectedwarning' ) . "\n"; |
Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -897,7 +897,7 @@ |
898 | 898 | $this->setPageTitle( wfMsg( 'viewsource' ) ); |
899 | 899 | $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) ); |
900 | 900 | |
901 | | - $cascadeSources = $wgTitle->getCascadeProtectionSources(); |
| 901 | + list( $cascadeSources, $restrictions ) = $wgTitle->getCascadeProtectionSources(); |
902 | 902 | |
903 | 903 | # Determine if protection is due to the page being a system message |
904 | 904 | # and show an appropriate explanation |
Index: trunk/phase3/includes/Title.php |
— | — | @@ -1037,11 +1037,6 @@ |
1038 | 1038 | # Special pages have inherent protection |
1039 | 1039 | if( $this->getNamespace() == NS_SPECIAL ) |
1040 | 1040 | return true; |
1041 | | - |
1042 | | - # Cascading protection depends on more than |
1043 | | - # this page... |
1044 | | - if( $this->isCascadeProtected() ) |
1045 | | - return true; |
1046 | 1041 | |
1047 | 1042 | # Check regular protection levels |
1048 | 1043 | if( $action == 'edit' || $action == '' ) { |
— | — | @@ -1150,17 +1145,27 @@ |
1151 | 1146 | return false; |
1152 | 1147 | } |
1153 | 1148 | |
1154 | | - if ( $doExpensiveQueries && !$this->isCssJsSubpage() && $this->isCascadeProtected() ) { |
| 1149 | + if ( $doExpensiveQueries && !$this->isCssJsSubpage() ) { |
1155 | 1150 | # We /could/ use the protection level on the source page, but it's fairly ugly |
1156 | 1151 | # as we have to establish a precedence hierarchy for pages included by multiple |
1157 | 1152 | # cascade-protected pages. So just restrict it to people with 'protect' permission, |
1158 | 1153 | # 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 | + } |
1162 | 1167 | } |
1163 | 1168 | } |
1164 | | - |
| 1169 | + |
1165 | 1170 | foreach( $this->getRestrictions($action) as $right ) { |
1166 | 1171 | // Backwards compatibility, rewrite sysop -> protect |
1167 | 1172 | if ( $right == 'sysop' ) { |
— | — | @@ -1360,25 +1365,34 @@ |
1361 | 1366 | * @access public. |
1362 | 1367 | */ |
1363 | 1368 | function isCascadeProtected() { |
1364 | | - return ( $this->getCascadeProtectionSources( false ) ); |
| 1369 | + list( $sources, $restrictions ) = $this->getCascadeProtectionSources( false ); |
| 1370 | + return ( $sources > 0 ); |
1365 | 1371 | } |
1366 | 1372 | |
1367 | 1373 | /** |
1368 | 1374 | * Cascading protection: Get the source of any cascading restrictions on this page. |
1369 | 1375 | * |
1370 | 1376 | * @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 |
1372 | 1380 | * @access public |
1373 | 1381 | */ |
1374 | 1382 | 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 | + |
1376 | 1390 | if (!$wgEnableCascadingProtection) |
1377 | | - return false; |
| 1391 | + return array( false, $pagerestrictions ); |
1378 | 1392 | |
1379 | 1393 | if ( isset( $this->mCascadeSources ) && $get_pages ) { |
1380 | | - return $this->mCascadeSources; |
| 1394 | + return array( $this->mCascadeSources, $this->mCascadingRestrictions ); |
1381 | 1395 | } else if ( isset( $this->mHasCascadingRestrictions ) && !$get_pages ) { |
1382 | | - return $this->mHasCascadingRestrictions; |
| 1396 | + return array( $this->mHasCascadingRestrictions, $pagerestrictions ); |
1383 | 1397 | } |
1384 | 1398 | |
1385 | 1399 | wfProfileIn( __METHOD__ ); |
— | — | @@ -1401,7 +1415,7 @@ |
1402 | 1416 | } |
1403 | 1417 | |
1404 | 1418 | 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' ); |
1406 | 1420 | $where_clauses[] = 'page_id=pr_page'; |
1407 | 1421 | $tables[] = 'page'; |
1408 | 1422 | } else { |
— | — | @@ -1422,6 +1436,11 @@ |
1423 | 1437 | $page_ns = $row->page_namespace; |
1424 | 1438 | $page_title = $row->page_title; |
1425 | 1439 | $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 | + } |
1426 | 1445 | } else { |
1427 | 1446 | $sources = true; |
1428 | 1447 | } |
— | — | @@ -1438,11 +1457,12 @@ |
1439 | 1458 | |
1440 | 1459 | if ( $get_pages ) { |
1441 | 1460 | $this->mCascadeSources = $sources; |
| 1461 | + $this->mCascadingRestrictions = $pagerestrictions; |
1442 | 1462 | } else { |
1443 | 1463 | $this->mHasCascadingRestrictions = $sources; |
1444 | 1464 | } |
1445 | 1465 | |
1446 | | - return $sources; |
| 1466 | + return array( $sources, $pagerestrictions ); |
1447 | 1467 | } |
1448 | 1468 | |
1449 | 1469 | function areRestrictionsCascading() { |
— | — | @@ -1505,7 +1525,7 @@ |
1506 | 1526 | if ( !$expiry || $expiry > $now ) { |
1507 | 1527 | $this->mRestrictionsExpiry = $expiry; |
1508 | 1528 | $this->mRestrictions[$row->pr_type] = explode( ',', trim( $row->pr_level ) ); |
1509 | | - |
| 1529 | + |
1510 | 1530 | $this->mCascadeRestriction |= $row->pr_cascade; |
1511 | 1531 | } else { |
1512 | 1532 | // Trigger a lazy purge of expired restrictions |