UI stuff for the cascading protection feature - warnings for sysops editing cascading...
authorAndrew Garrett <werdna@users.mediawiki.org>
Fri, 12 Jan 2007 04:43:33 +0000 (04:43 +0000)
committerAndrew Garrett <werdna@users.mediawiki.org>
Fri, 12 Jan 2007 04:43:33 +0000 (04:43 +0000)
includes/EditPage.php
includes/OutputPage.php
includes/ProtectionForm.php
includes/Title.php
languages/messages/MessagesEn.php

index a3ed161..cd0fee4 100644 (file)
@@ -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' );
index de2ccc5..6668336 100644 (file)
@@ -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' ) );
                        }
index 066054f..e83c38b 100644 (file)
@@ -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;
index 11a6940..4120667 100644 (file)
@@ -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;
index e8cb399..5dc885b 100644 (file)
@@ -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.</strong>',
 'protectedpagewarning' => "<strong>WARNING:  This page has been locked so that only users with sysop privileges can edit it.</strong>",
 'semiprotectedpagewarning' => "'''Note:''' This page has been locked so that only registered users can edit it.",
+'cascadeprotectedwarning' => "<strong>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.</strong>",
 '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 <strong>$1</strong>.',
 'protect-viewtext' => 'Your account does not have permission to change
 page protection levels. Here are the current settings for the page <strong>$1</strong>:',
+'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',