r74995 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74994‎ | r74995 | r74996 >
Date:03:27, 19 October 2010
Author:tstarling
Status:deferred
Tags:
Comment:
Script for adding people to the core access list.
Modified paths:
  • /trunk/tools/subversion (added) (history)
  • /trunk/tools/subversion/set-core-access (added) (history)

Diff [purge]

Index: trunk/tools/subversion/set-core-access
@@ -0,0 +1,83 @@
 2+#!/usr/bin/perl -w
 3+
 4+if ( $#ARGV < 1 || ( $ARGV[0] ne "add" && $ARGV[0] ne "delete" ) ) {
 5+ print "Usage: $0 {add|delete} <user>\n";
 6+ exit 1;
 7+}
 8+my $action = $ARGV[0];
 9+my $user = $ARGV[1];
 10+my $fileName = "/svnroot/mediawiki/conf/authz";
 11+if ( !open( AUTHZ, "<", $fileName ) ) {
 12+ print "Unable to open authz\n";
 13+ exit 1;
 14+}
 15+
 16+# Find the [groups] section
 17+my $found = 0;
 18+my $before = '', $after = '';
 19+while ( <AUTHZ> ) {
 20+ $before .= $_;
 21+ if ( $_ =~ /^\[groups\]/ ) {
 22+ $found = 1;
 23+ last;
 24+ }
 25+}
 26+
 27+if ( !$found ) {
 28+ print "Unable to find [groups] section\n";
 29+ exit 1;
 30+}
 31+
 32+# Find the core group
 33+$found = 0;
 34+my $memberString;
 35+while ( <AUTHZ> ) {
 36+ if ( $_ =~ /^core *= *(.*)\n$/ ) {
 37+ $memberString = $1;
 38+ $found = 1;
 39+ last;
 40+ } else {
 41+ $before .= $_;
 42+ }
 43+}
 44+if ( !$found ) {
 45+ print "Unable to find core group\n";
 46+ exit 1;
 47+}
 48+
 49+# Load the rest of the file into a string
 50+while ( <AUTHZ> ) {
 51+ $after .= $_;
 52+}
 53+close AUTHZ;
 54+
 55+# Do the add/remove operation
 56+
 57+my @members = split( /, */, $memberString );
 58+if ( $action eq "add" ) {
 59+ if ( grep( $_ eq $user, @members ) ) {
 60+ print "$user already has core access\n";
 61+ exit 1;
 62+ }
 63+ push( @members, $user );
 64+} else { # if action == delete
 65+ if ( !grep( $_ eq $user, @members ) ) {
 66+ print "$user does not have core access\n";
 67+ exit 1;
 68+ }
 69+ @members = grep( $_ ne $user, @members );
 70+}
 71+
 72+@members = sort( @members );
 73+$memberString = join( ', ', @members );
 74+
 75+# Move the file to a backup location
 76+rename( $fileName, "$fileName~" );
 77+
 78+# Write the new file
 79+open( AUTHZ, ">", $fileName );
 80+print AUTHZ $before;
 81+print AUTHZ "core = $memberString\n";
 82+print AUTHZ $after;
 83+close AUTHZ;
 84+
Property changes on: trunk/tools/subversion/set-core-access
___________________________________________________________________
Added: svn:eol-style
185 + native
Added: svn:executable
286 + *

Status & tagging log