*Generalize function to list UI names for all groups with a permission into OutputPag...
authorAaron Schulz <aaron@users.mediawiki.org>
Sun, 26 Aug 2007 09:49:28 +0000 (09:49 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Sun, 26 Aug 2007 09:49:28 +0000 (09:49 +0000)
*Make a separate function in article for showing protection notice thingy on view. List out who can edit/move the page.
*Some messages added for above. Remove annoying html comment from one.
*Fix php array index errors with protection notice

RELEASE-NOTES
includes/Article.php
includes/OutputPage.php
languages/messages/MessagesEn.php

index 7e6725c..5a7af27 100644 (file)
@@ -190,6 +190,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * Add accesskey 's' and tooltip to 'upload file' button at Special:Upload
 * Introduced 'SkinAfterBottomScripts' hook; see docs/hooks.txt for
   more information
+* (bug 10347) Give notice when a page is viewed that is protected. Does not 
+  show for cascade protection however.
 
 == Bugfixes since 1.10 ==
 
index 21d8697..d3cb1ee 100644 (file)
@@ -743,9 +743,7 @@ class Article {
                if ( $this->mTitle->isProtected() ) {
                        $editrestr = $this->mTitle->getRestrictions('edit');
                        $moverestr = $this->mTitle->getRestrictions('move');
-                       $wgOut->setSubtitle($wgOut->getSubtitle() . 
-                               wfMsg( 'protected-subtitle', 
-                                       $editrestr[0], $moverestr[0] ) );
+                       $this->addProtectionNotice( $editrestr, $moverestr );
                }
 
                $outputDone = false;
@@ -894,6 +892,40 @@ class Article {
                wfProfileOut( __METHOD__ );
        }
 
+       /*
+       * Output a notice that a page is protected. Only give details for move/edit
+       * restrictions. Cares only about the first permission in the arrays, which is
+       * part of a larger shitty inconsistency about requiring several permissions...
+       * @param Array $editrestr, edit restrictions
+       * @param Array $moverestr, move restrictions
+       */
+       function addProtectionNotice( $editrestr, $moverestr ) {        
+               global $wgOut;
+               
+               $editGroups = $moveGroups = '';
+               # Get groups that have each right
+               if( !empty( $editrestr ) ) {
+                       $permission = ($editrestr[0]=='sysop') ? 'protect' : $editrestr[0];
+                       $editGroups = $wgOut->getGroupsWithPermission( $permission );
+                       $editGroups = implode( ', ', $editGroups );
+               }
+               if( !empty( $moverestr ) ) {
+                       $permission = ($moverestr[0]=='sysop') ? 'protect' : $moverestr[0];
+                       $moveGroups = $wgOut->getGroupsWithPermission( $permission );
+                       $moveGroups = implode( ', ', $moveGroups );
+               }
+               # Use general messages if no groups found for a type
+               if( !$editGroups || !$moveGroups ) {
+                       $msg = wfMsg( 'protected-subtitle3' );
+               } else if( $editGroups == $moveGroups ) {
+                       $msg = wfMsg( 'protected-subtitle2', $editGroups, $moveGroups );
+               } else {
+                       $msg = wfMsg( 'protected-subtitle', $editGroups, $moveGroups );
+               }
+               
+               $wgOut->setSubtitle( $wgOut->getSubtitle() . $msg );
+       }
+
        function addTrackbacks() {
                global $wgOut, $wgUser;
 
index 66fbb8d..bbeb7a3 100644 (file)
@@ -878,7 +878,7 @@ class OutputPage {
         * @param string $permission key required
         */
        public function permissionRequired( $permission ) {
-               global $wgGroupPermissions, $wgUser;
+               global $wgUser;
 
                $this->setPageTitle( wfMsg( 'badaccess' ) );
                $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
@@ -886,19 +886,7 @@ class OutputPage {
                $this->setArticleRelated( false );
                $this->mBodytext = '';
 
-               $groups = array();
-               foreach( $wgGroupPermissions as $key => $value ) {
-                       if( isset( $value[$permission] ) && $value[$permission] == true ) {
-                               $groupName = User::getGroupName( $key );
-                               $groupPage = User::getGroupPage( $key );
-                               if( $groupPage ) {
-                                       $skin = $wgUser->getSkin();
-                                       $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
-                               } else {
-                                       $groups[] = $groupName;
-                               }
-                       }
-               }
+               $groups = $this->getGroupsWithPermission( $permission );
                $n = count( $groups );
                $groups = implode( ', ', $groups );
                switch( $n ) {
@@ -913,6 +901,30 @@ class OutputPage {
                $this->addHtml( $message );
                $this->returnToMain( false );
        }
+       
+       /**
+        * Return an array of the groups in (UI name form) that have a permission
+        *
+        * @param string $permission key required
+        */     
+       public function getGroupsWithPermission( $permission ) {
+               global $wgUser, $wgGroupPermissions;
+
+               $groups = array();
+               foreach( $wgGroupPermissions as $key => $value ) {
+                       if( isset( $value[$permission] ) && $value[$permission] == true ) {
+                               $groupName = User::getGroupName( $key );
+                               $groupPage = User::getGroupPage( $key );
+                               if( $groupPage ) {
+                                       $skin = $wgUser->getSkin();
+                                       $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
+                               } else {
+                                       $groups[] = $groupName;
+                               }
+                       }
+               }
+               return $groups;
+       }
 
        /**
         * Use permissionRequired.
index 437fdbb..2119a50 100644 (file)
@@ -797,7 +797,9 @@ $2",
 'namespaceprotected'   => "You do not have permission to edit pages in the '''$1''' namespace.",
 'customcssjsprotected' => "You do not have permission to edit this page, because it contains another user's personal settings.",
 'ns-specialprotected'  => "Pages in the {{ns:special}} namespace cannot be edited.",
-'protected-subtitle'   => "<!-- This message will be displayed as the subtitle for pages that are protected. The argument $1 is the level of edit-protection (i.e., sysop or autoconfirmed), and $2 is the level of move-protection. --> (This page is protected.)",
+'protected-subtitle'   => "(This page is protected. Only certain users ($1) can edit and others ($2) can move it.)",
+'protected-subtitle2'  => "(This page is protected. Only certain users ($1) can edit and move it.)",
+'protected-subtitle3'  => "(This page is protected)",
 
 # Login and logout pages
 'logouttitle'                => 'User logout',
@@ -1321,6 +1323,8 @@ Unselected groups will not be changed. You can deselect a group with CTRL + Left
 'group-bureaucrat' => 'Bureaucrats',
 'group-all'        => '(all)',
 
+'group-autoconfirmed' => 'autoconfirmed',
+
 'group-bot-member'        => 'Bot',
 'group-sysop-member'      => 'Sysop',
 'group-bureaucrat-member' => 'Bureaucrat',