From 283621653b885dea5fc1f3a7e4d23fae3a244a05 Mon Sep 17 00:00:00 2001 From: Andrew Garrett Date: Fri, 12 Jan 2007 04:43:33 +0000 Subject: [PATCH] UI stuff for the cascading protection feature - warnings for sysops editing cascading protected pages (including which page the protection has come from), more useful errors for users (including which page the protection has come from), and a note at the top of the protect page when trying to unprotect a page affected by cascading protection to the effect of 'you can't affect the cascading protection here'. --- includes/EditPage.php | 12 +++++- includes/OutputPage.php | 7 ++++ includes/ProtectionForm.php | 9 ++++ includes/Title.php | 68 +++++++++++++++++++++++-------- languages/messages/MessagesEn.php | 3 ++ 5 files changed, 79 insertions(+), 20 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index a3ed161d0f..cd0fee48cd 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -865,7 +865,7 @@ class EditPage { $this->summary = ''; $this->textbox1 = $this->getContent(); if ( !$this->mArticle->exists() && $this->mArticle->mTitle->getNamespace() == NS_MEDIAWIKI ) - $this->textbox1 = wfMsgWeirdKey( $this->mArticle->mTitle->getText() ) ; + $this->textbox1 = wfMsgWeirdKey( $this->mArticle->mTitle->getText() ); wfProxyCheck(); } @@ -961,7 +961,9 @@ class EditPage { } } } - + + $cascadeSource = $this->mTitle->getCascadeProtectionSource(); + if( $this->mTitle->isProtected( 'edit' ) ) { # Is the protection due to the namespace, e.g. interface text? if( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { @@ -973,6 +975,12 @@ class EditPage { if( wfEmptyMsg( 'semiprotectedpagewarning', $notice ) || $notice == '-' ) { $notice = ''; } + } elseif ($cascadeSource) { + # Cascaded protection: warn the user. + $cascadeSourceTitle = Title::newFromId($cascadeSource); + $cascadeSourceText = $cascadeSourceTitle->getPrefixedText(); + + $notice = wfMsgForContent( 'cascadeprotectedwarning', $cascadeSourceText ); } else { # No; regular protection $notice = wfMsg( 'protectedpagewarning' ); diff --git a/includes/OutputPage.php b/includes/OutputPage.php index de2ccc5081..6668336f3d 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -893,10 +893,17 @@ class OutputPage { $this->setPageTitle( wfMsg( 'viewsource' ) ); $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) ); + $cascadeSource = $wgTitle->getCascadeProtectionSource(); + # Determine if protection is due to the page being a system message # and show an appropriate explanation if( $wgTitle->getNamespace() == NS_MEDIAWIKI ) { $this->addWikiText( wfMsg( 'protectedinterface' ) ); + } if ( $cascadeSource ) { + $cascadeSourceTitle = Title::newFromId( $cascadeSource ); + $cascadeSourceText = $cascadeSourceTitle->getPrefixedText(); + + $this->addWikiText( wfMsgForContent( 'cascadeprotected', $cascadeSourceText ) ); } else { $this->addWikiText( wfMsg( 'protectedpagetext' ) ); } diff --git a/includes/ProtectionForm.php b/includes/ProtectionForm.php index 066054fc4d..e83c38b580 100644 --- a/includes/ProtectionForm.php +++ b/includes/ProtectionForm.php @@ -73,6 +73,15 @@ class ProtectionForm { return; } + $cascadeSource = $this->mTitle->getCascadeProtectionSource(); + + if ( $cascadeSource ) { + $cascadeSourceTitle = Title::newFromId( $cascadeSource ); + $cascadeSourceText = $cascadeSourceTitle->getPrefixedText(); + + $wgOut->addWikiText( wfMsgForContent( 'protect-cascadeon', $cascadeSourceText ) ); + } + if( $this->save() ) { $wgOut->redirect( $this->mTitle->getFullUrl() ); return; diff --git a/includes/Title.php b/includes/Title.php index 11a694096d..4120667e37 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -54,6 +54,7 @@ class Title { var $mLatestID; # ID of most recent revision var $mRestrictions; # Array of groups allowed to edit this article var $mCascadeRestriction; + var $mCascadeRestrictionSource; var $mRestrictionsLoaded; # Boolean for initialisation on demand var $mPrefixedText; # Text form including namespace/interwiki, initialised on demand var $mDefaultNamespace; # Namespace index when there is no namespace @@ -1032,7 +1033,10 @@ class Title { */ function isProtected( $action = '' ) { global $wgRestrictionLevels; + if ( NS_SPECIAL == $this->mNamespace ) { return true; } + + if ( $this->getCascadeProtectionSource() ) { return true; } if( $action == 'edit' || $action == '' ) { $r = $this->getRestrictions( 'edit' ); @@ -1123,8 +1127,7 @@ class Title { return false; } - if ( ( $this->isCascadeProtectedPage() ) || - ($this->getNamespace() == NS_IMAGE && $this->isCascadeProtectedImage() ) ) { + if ( $this->getCascadeProtectionSource() ) { # We /could/ use the protection level on the source page, but it's fairly ugly # as we have to establish a precedence hierarchy for pages included by multiple # cascade-protected pages. So just restrict it to people with 'protect' permission, @@ -1328,12 +1331,37 @@ class Title { } /** - * Cascading protects: Check if the current image is protected due to a cascading restriction - * - * @return bool If the current page is protected due to a cascading restriction. - * @access public - */ - function isCascadeProtectedImage() { + * Cascading protection: Get the source of any cascading restrictions on this page. + * + * @return int The page_id of the page from which cascading restrictions have come, or false for none. + * @access public + */ + function getCascadeProtectionSource() { + + if ( isset( $this->mCascadeSource ) ) { + return $this->mCascadeSource; + } + + $source = NULL; + + if ( $this->getNamespace() == NS_IMAGE ) { + $source = $this->getCascadeProtectedImageSource(); + } else { + $source = $this->getCascadeProtectedPageSource(); + } + + $this->mCascadeSource = $source; + + return $source; + } + + /** + * Cascading protects: Check if the current image is protected due to a cascading restriction + * + * @return int The page_id of the page from which cascading restrictions have come, or false for none. + * @access public + */ + function getCascadeProtectedImageSource() { global $wgEnableCascadingProtection; if (!$wgEnableCascadingProtection) return false; @@ -1342,15 +1370,17 @@ class Title { $dbr =& wfGetDb( DB_SLAVE ); - $cols = array( 'il_to' ); + $cols = array( 'pr_page' ); $tables = array ('imagelinks', 'page_restrictions'); $where_clauses = array( 'il_to' => $this->getDBkey(), 'il_from=pr_page', 'pr_cascade' => 1 ); $res = $dbr->select( $tables, $cols, $where_clauses, __METHOD__); if ($dbr->numRows($res)) { + $row = $dbr->fetchObject($res); + $culprit = $row->pr_page; wfProfileOut(__METHOD__); - return true; + return $culprit; } else { wfProfileOut(__METHOD__); return false; @@ -1358,12 +1388,12 @@ class Title { } /** - * Cascading protects: Check if the current page is protected due to a cascading restriction. - * - * @return bool if the current page is protected due to a cascading restriction - * @access public - */ - function isCascadeProtectedPage() { + * Cascading protects: Check if the current page is protected due to a cascading restriction. + * + * @return int The page_id of the page from which cascading restrictions have come, or false for none. + * @access public + */ + function getCascadeProtectedPageSource() { global $wgEnableCascadingProtection; if (!$wgEnableCascadingProtection) return false; @@ -1372,15 +1402,17 @@ class Title { $dbr =& wfGetDb( DB_SLAVE ); - $cols = array( 'tl_namespace', 'tl_title' ); + $cols = array( 'pr_page' ); $tables = array ('templatelinks', 'page_restrictions'); $where_clauses = array( 'tl_namespace' => $this->getNamespace(), 'tl_title' => $this->getDBkey(), 'tl_from=pr_page', 'pr_cascade' => 1 ); $res = $dbr->select( $tables, $cols, $where_clauses, __METHOD__); if ($dbr->numRows($res)) { + $row = $dbr->fetchObject($res); + $culprit = $row->pr_page; wfProfileOut(__METHOD__); - return true; + return $culprit; } else { wfProfileOut(__METHOD__); return false; diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index e8cb399efc..5dc885bdc7 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -780,6 +780,7 @@ Query: $2', 'protectedinterface' => 'This page provides interface text for the software, and is locked to prevent abuse.', 'editinginterface' => "'''Warning:''' You are editing a page which is used to provide interface text for the software. Changes to this page will affect the appearance of the user interface for other users.", 'sqlhidden' => '(SQL query hidden)', +'cascadeprotected' => 'This page has been protected from editing, because it is included in [[$1]], which has been protected with the "cascading" option turned on.', # Login and logout pages # @@ -1014,6 +1015,7 @@ so you will not be able to save your edits right now. You may wish to cut-n-past the text into a text file and save it for later.', 'protectedpagewarning' => "WARNING: This page has been locked so that only users with sysop privileges can edit it.", 'semiprotectedpagewarning' => "'''Note:''' This page has been locked so that only registered users can edit it.", +'cascadeprotectedwarning' => "WARNING: This page has been locked so that only users with sysop privileges can edit it, because it is included on [[$1]], which is protected with the 'cascading protection' option turned on.", 'templatesused' => 'Templates used on this page:', 'templatesusedpreview' => 'Templates used in this preview:', 'templatesusedsection' => 'Templates used in this section:', @@ -1743,6 +1745,7 @@ Please hit "back" and reload the page you came from, then try again.', 'protect-text' => 'You may view and change the protection level here for the page $1.', 'protect-viewtext' => 'Your account does not have permission to change page protection levels. Here are the current settings for the page $1:', +'protect-cascadeon' => 'This page is currently subject to cascading protection, because it is included in [[$1]], which has been protected with the "cascading protection" option turned on. You can change the protection level for this page here, but it will not affect the cascading protection.', 'protect-default' => '(default)', 'protect-level-autoconfirmed' => 'Block unregistered users', 'protect-level-sysop' => 'Sysops only', -- 2.20.1