[Home]WikiPatches/RestrictPages

UseModWiki | WikiPatches | RecentChanges | Preferences

To allow our documentation space (using usemod) to be restricted read access I created this barely functional patch. It reads from $RestrictFile? ($DataDir/restrict) and sees a regexp it matches against page ids. If not matched, the page is viewed. If the page id is matched, it checks the next part of the line of restrict, and sees if $UserData{'username'} matches what is listed there. If so, the page is viewed. If not->NotFound? page -- TravisB? 8/31/05

Usage:

 WikiPatches  TcB?  Friend
 ^Plans.*  TcB? Ren Stimpy

Bugs/Enhancements?:


*** 50,57 ****
    $NumberDates $EarlyRules $LateRules $NewFS $KeepSize $SlashLinks $BGColor
    $UpperFirst $AdminBar $RepInterMap $DiffColor1 $DiffColor2 $ConfirmDel
    $MaskHosts $LockCrash $ConfigFile $HistoryEdit $OldThinLine 
!   @IsbnNames @IsbnPre @IsbnPost $EmailFile $FavIcon $RssDays $UserHeader
!   $UserBody $StartUID $ParseParas $AuthorFooter $UseUpload $AllUpload
    $UploadDir $UploadUrl $LimitFileUrl $MaintTrimRc $SearchButton 
    $EditNameLink $UseMetaWiki @ImageSites $BracketImg );
  # Note: $NotifyDefault is kept because it was a config variable in 0.90
--- 50,59 ----
    $NumberDates $EarlyRules $LateRules $NewFS $KeepSize $SlashLinks $BGColor
    $UpperFirst $AdminBar $RepInterMap $DiffColor1 $DiffColor2 $ConfirmDel
    $MaskHosts $LockCrash $ConfigFile $HistoryEdit $OldThinLine 
!   @IsbnNames @IsbnPre @IsbnPost $EmailFile $RestrictFile $FavIcon $RssDays 
! $UserHeader
!   $UserBody $StartUID $ParseParas $AuthorFooter $UseUpload 
! $RestrictPages $AllUpload
    $UploadDir $UploadUrl $LimitFileUrl $MaintTrimRc $SearchButton 
    $EditNameLink $UseMetaWiki @ImageSites $BracketImg );
  # Note: $NotifyDefault is kept because it was a config variable in 0.90
***************
*** 132,137 ****
--- 134,141 ----
  $TableSyntax = 1;           # 1 = wiki syntax tables, 0 = no table syntax
  $NewFS       = 0;           # 1 = new multibyte $FS,  0 = old $FS
  $UseUpload   = 0;           # 1 = allow uploads,      0 = no uploads
+ $RestrictPages=0;           # 0 disable, 1 use restrict file for pages
+                                                     
  
  # Minor options:
  $LogoLeft     = 0;      # 1 = logo on left,       0 = logo on right
***************
*** 208,213 ****
--- 212,218 ----
  $RcOldFile   = "$DataDir/oldrclog"; # Old RecentChanges logfile
  $IndexFile   = "$DataDir/pageidx";  # List of all pages
  $EmailFile   = "$DataDir/emails";   # Email notification lists
+ $RestrictFile= "$DataDir/restrict"; # regexps for restricted pgs, and userids
  
  if ($RepInterMap) {
    push @ReplaceableFiles, $InterFile;
***************
*** 491,502 ****
--- 496,524 ----
    }
    return 0;  # Request not handled
  }
+ sub CheckPageAllowed{
+     my ($id)=@_;
+     return 1 unless $RestrictPages;
+     my $data=&ReadFileOrDie($RestrictFile);
+     foreach my $line(split /\n/,$data){
+ 	my ($pattern,@users)=split / /, $line;
+ 	next unless $id =~ m/$pattern/;
+ 	&LoadUserData();
+ 	return 1 if grep {$UserData{'username'} eq $_} @users;
+ 	return 0;
+     }
+    return 1;
+ }
  
  sub BrowsePage {
    my ($id) = @_;
    my ($fullHtml, $oldId, $allDiff, $showDiff, $openKept);
    my ($revision, $goodRevision, $diffRevision, $newText);
  
+   if (! &CheckPageAllowed($id)){
+       $id = $NotFoundPg;
+       $id= $HomePage unless $id;
+   }
    &OpenPage($id);
    &OpenDefaultText();
    $openKept = 0;

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited July 7, 2007 3:25 am by MarkusLude (diff)
Search: