r25152 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25151‎ | r25152 | r25153 >
Date:09:49, 26 August 2007
Author:aaron
Status:old
Tags:
Comment:
*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
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -743,9 +743,7 @@
744744 if ( $this->mTitle->isProtected() ) {
745745 $editrestr = $this->mTitle->getRestrictions('edit');
746746 $moverestr = $this->mTitle->getRestrictions('move');
747 - $wgOut->setSubtitle($wgOut->getSubtitle() .
748 - wfMsg( 'protected-subtitle',
749 - $editrestr[0], $moverestr[0] ) );
 747+ $this->addProtectionNotice( $editrestr, $moverestr );
750748 }
751749
752750 $outputDone = false;
@@ -894,6 +892,40 @@
895893 wfProfileOut( __METHOD__ );
896894 }
897895
 896+ /*
 897+ * Output a notice that a page is protected. Only give details for move/edit
 898+ * restrictions. Cares only about the first permission in the arrays, which is
 899+ * part of a larger shitty inconsistency about requiring several permissions...
 900+ * @param Array $editrestr, edit restrictions
 901+ * @param Array $moverestr, move restrictions
 902+ */
 903+ function addProtectionNotice( $editrestr, $moverestr ) {
 904+ global $wgOut;
 905+
 906+ $editGroups = $moveGroups = '';
 907+ # Get groups that have each right
 908+ if( !empty( $editrestr ) ) {
 909+ $permission = ($editrestr[0]=='sysop') ? 'protect' : $editrestr[0];
 910+ $editGroups = $wgOut->getGroupsWithPermission( $permission );
 911+ $editGroups = implode( ', ', $editGroups );
 912+ }
 913+ if( !empty( $moverestr ) ) {
 914+ $permission = ($moverestr[0]=='sysop') ? 'protect' : $moverestr[0];
 915+ $moveGroups = $wgOut->getGroupsWithPermission( $permission );
 916+ $moveGroups = implode( ', ', $moveGroups );
 917+ }
 918+ # Use general messages if no groups found for a type
 919+ if( !$editGroups || !$moveGroups ) {
 920+ $msg = wfMsg( 'protected-subtitle3' );
 921+ } else if( $editGroups == $moveGroups ) {
 922+ $msg = wfMsg( 'protected-subtitle2', $editGroups, $moveGroups );
 923+ } else {
 924+ $msg = wfMsg( 'protected-subtitle', $editGroups, $moveGroups );
 925+ }
 926+
 927+ $wgOut->setSubtitle( $wgOut->getSubtitle() . $msg );
 928+ }
 929+
898930 function addTrackbacks() {
899931 global $wgOut, $wgUser;
900932
Index: trunk/phase3/includes/OutputPage.php
@@ -878,7 +878,7 @@
879879 * @param string $permission key required
880880 */
881881 public function permissionRequired( $permission ) {
882 - global $wgGroupPermissions, $wgUser;
 882+ global $wgUser;
883883
884884 $this->setPageTitle( wfMsg( 'badaccess' ) );
885885 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
@@ -886,19 +886,7 @@
887887 $this->setArticleRelated( false );
888888 $this->mBodytext = '';
889889
890 - $groups = array();
891 - foreach( $wgGroupPermissions as $key => $value ) {
892 - if( isset( $value[$permission] ) && $value[$permission] == true ) {
893 - $groupName = User::getGroupName( $key );
894 - $groupPage = User::getGroupPage( $key );
895 - if( $groupPage ) {
896 - $skin = $wgUser->getSkin();
897 - $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
898 - } else {
899 - $groups[] = $groupName;
900 - }
901 - }
902 - }
 890+ $groups = $this->getGroupsWithPermission( $permission );
903891 $n = count( $groups );
904892 $groups = implode( ', ', $groups );
905893 switch( $n ) {
@@ -913,7 +901,31 @@
914902 $this->addHtml( $message );
915903 $this->returnToMain( false );
916904 }
 905+
 906+ /**
 907+ * Return an array of the groups in (UI name form) that have a permission
 908+ *
 909+ * @param string $permission key required
 910+ */
 911+ public function getGroupsWithPermission( $permission ) {
 912+ global $wgUser, $wgGroupPermissions;
917913
 914+ $groups = array();
 915+ foreach( $wgGroupPermissions as $key => $value ) {
 916+ if( isset( $value[$permission] ) && $value[$permission] == true ) {
 917+ $groupName = User::getGroupName( $key );
 918+ $groupPage = User::getGroupPage( $key );
 919+ if( $groupPage ) {
 920+ $skin = $wgUser->getSkin();
 921+ $groups[] = $skin->makeLinkObj( $groupPage, $groupName );
 922+ } else {
 923+ $groups[] = $groupName;
 924+ }
 925+ }
 926+ }
 927+ return $groups;
 928+ }
 929+
918930 /**
919931 * Use permissionRequired.
920932 * @deprecated
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -797,7 +797,9 @@
798798 'namespaceprotected' => "You do not have permission to edit pages in the '''$1''' namespace.",
799799 'customcssjsprotected' => "You do not have permission to edit this page, because it contains another user's personal settings.",
800800 'ns-specialprotected' => "Pages in the {{ns:special}} namespace cannot be edited.",
801 -'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.)",
 801+'protected-subtitle' => "(This page is protected. Only certain users ($1) can edit and others ($2) can move it.)",
 802+'protected-subtitle2' => "(This page is protected. Only certain users ($1) can edit and move it.)",
 803+'protected-subtitle3' => "(This page is protected)",
802804
803805 # Login and logout pages
804806 'logouttitle' => 'User logout',
@@ -1321,6 +1323,8 @@
13221324 'group-bureaucrat' => 'Bureaucrats',
13231325 'group-all' => '(all)',
13241326
 1327+'group-autoconfirmed' => 'autoconfirmed',
 1328+
13251329 'group-bot-member' => 'Bot',
13261330 'group-sysop-member' => 'Sysop',
13271331 'group-bureaucrat-member' => 'Bureaucrat',
Index: trunk/phase3/RELEASE-NOTES
@@ -190,6 +190,8 @@
191191 * Add accesskey 's' and tooltip to 'upload file' button at Special:Upload
192192 * Introduced 'SkinAfterBottomScripts' hook; see docs/hooks.txt for
193193 more information
 194+* (bug 10347) Give notice when a page is viewed that is protected. Does not
 195+ show for cascade protection however.
194196
195197 == Bugfixes since 1.10 ==
196198

Follow-up revisions

RevisionCommit summaryAuthorDate
r25223Merged revisions 25126-25214 via svnmerge from...david07:39, 28 August 2007

Status & tagging log