From dfedd40ea747501cae18681d625241421fa6df82 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sun, 26 Aug 2007 09:49:28 +0000 Subject: [PATCH] *Generalize function to list UI names for all groups with a permission into OutputPage::getGroupsWithPermission() *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 | 2 ++ includes/Article.php | 38 ++++++++++++++++++++++++++--- includes/OutputPage.php | 40 ++++++++++++++++++++----------- languages/messages/MessagesEn.php | 6 ++++- 4 files changed, 68 insertions(+), 18 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 7e6725cd48..5a7af27c69 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 == diff --git a/includes/Article.php b/includes/Article.php index 21d8697c1e..d3cb1ee093 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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; diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 66fbb8d5d4..bbeb7a3170 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -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. diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 437fdbb040..2119a50328 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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 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', -- 2.20.1