odd-wiki-hive odd-list-wiki de-odd-Zentrum-wiki en-odd-center-wiki fr-odd-centre-wiki it-odd-centro-wiki Gespräch · talk
bavardage
all wikis all recent changes recent changes local names new page special odd-wiki-hive

config

# -*- mode:cperl -*-

# Banning Replacement for .htaccess which somehow doesn't
# work anymore.
if (GetRemoteHost() =~ /(airtelbroadband\.in
			|tataidc\.co\.in)$/x) {
  exit;
}

$BracketWiki = 1;
$SiteName = 'Odd Wiki';
$RcDefault = 7;
$SisterSiteLogoUrl = "http://oddwiki.org/pics/%s.png";
# make InterMap and friends editable
$StrangeBannedContent = 'BannedRegexps';
%LockOnCreation = ('BannedContent' => 1,
		   'BannedHosts' => 1,
		   'BannedRegexps' => 1, );
# this line is parsed by the maintenance job!
$AdminPass="*secret*";
$MultiUrlLimit=10;

# delete $Action{ln};
$UploadAllowed=1;
$CalendarOnEveryPage = 0;
$InstanceThrottleLimit = 10;
$StaticDir = '/var/www/alex/communitywiki.org/files';
$StaticUrl = '/files/';
$InvisibleCookieParameters{css} = 1;

umask(002); # all users have read (4) and execute (1) permissions

sub MyRules {
  if (m/\G<br>/gc) {
    return '<br />';
  } elsif (pos == 0 and m/\G\#/gc) { # for any sort of script
    my $pos = length($_); # fake matching entire file
    pos = $pos;
    return $q->pre($_);
  # } elsif (m/\G&lt;chat&gt;/gc) {
  #   return '<div id="peekko"></div>';
  }
  return undef;
}

push(@MyAdminCode, \&MyMaintenanceReports);

sub MyMaintenanceReports {
  my ($id, $menuref, $restref) = @_;
  my $ns = $NamespaceCurrent||$NamespacesMain;
  push(@$menuref,
       $q->a({-href=>"/maintenance/$ns.html"},
	     'Maintenance Report'),
       $q->a({-href=>"/maintenance/$ns-despam.html"},
	     'Despamming Report'));
}

push(@MyAdminCode, \&MyCssInstall);

sub MyCssInstall {
  my ($id, $menuref, $restref) = @_;
  push(@$menuref, ScriptLink('action=css', T('Install CSS')))
    if $NamespaceCurrent;
}

*GetCss=*MyGetCss;

sub MyGetCss {
  my $css = GetParam('css', '');
  if ($css) {
    # cookie
    $css =~ s/".*//; # prevent javascript injection
    foreach my $sheet (split(/\s+/, $css)) {
      return qq(<link type="text/css" rel="stylesheet" href="$sheet" />);
    }
  } elsif ($IndexHash{$StyleSheetPage}
	   and GetPageContent($StyleSheetPage) !~ /^\s*$/) {
    # css page exists and has content
    $css = "$ScriptName?action=browse;id=" . UrlEncode($StyleSheetPage);
    return qq(<link type="text/css" rel="stylesheet" href="$css;raw=1;mime-type=text/css" />);
  } else {
    # default
    return qq(<link type="text/css" rel="stylesheet" href="/blue.css" />);
  }
}

push @MyInitVariables, \&InitPageVariables;

sub InitPageVariables {
  my $id = GetId();
  if ($IndexHash{CommentsPrefix}) {
    $CommentsPrefix = GetPageContent('CommentsPrefix');
    $CommentsPrefix =~ s/\n/ /;
    $CommentsPrefix = FreeToNormal($CommentsPrefix);
    $CommentsPrefix .= '_';
    $CommentsPrefix = undef if $CommentsPrefix =~ /^$DeletedPage/;
  }
#   $HtmlHeaders = '<script src="http://peekko.com/chat/ajax/peekko.js"></script>';
#   $HtmlHeaders .= '<link rel="alternate" type="application/rss+xml" title="'
#     . QuoteHtml($SiteName) . '" href="' . $ScriptName . '?action=rss" />';
#   $HtmlHeaders .= '<link rel="alternate" type="application/rss+xml" title="'
#     . QuoteHtml("$SiteName: $id") . '" href="' . $ScriptName . '?action=rss;rcidonly=' . $id . '" />'
#     if $id;
  if ($IndexHash{logo}) {
    my $logo = GetPageContent('logo');
    if (TextIsFile($logo)) {
      $LogoUrl = 'logo';
    } elsif ($logo =~ /^$FullUrlPattern$/) {
      $LogoUrl = $logo;
    }
  }
}

push @MyInitVariables, \&OldWikiWarning;

sub OldWikiWarning {
  my ($status, $data) = ReadFile("/home/alex/oddwiki/page/S/Status.pg");
  if ($status) {
    my %data = ParseData($data);
    my $text = $data{text};
    if ($text =~ /\* $NamespaceCurrent:HomePage .* will be deleted/) {
      $Message .= $q->p("This wiki was last modified more than half a year ago and will be deleted eventually!");
    }
  }
  if ($NamespaceCurrent and not AllPagesList()) {
    $EditAllowed = 1;
  }
}

@Debugging = (sub {
		print GetPageContent('SideBar');
	      });

@QuestionaskerQuestions =
  (["Please say hello." => sub { shift =~ /^\s*(hi|yo|hello|hallo|hoi)\s*$/i }],
  );

push(@MyInitVariables, sub {
       # crypto banning usernames like tbattlet7
       if (GetParam('title') and GetParam('username') =~ /\d$/) {
         SetParam('action', 'browse');
         SetParam('id', GetParam('title'));
       }});

push(@MyInitVariables, \&MyExtraHeaders);

sub MyExtraHeaders {
  my $id = GetId();
  if ($q and $id) {
    my $text;
    if (GetParam('Preview', '')) {
      $text = GetParam('text', '');
    } elsif (GetParam('action', 'browse') eq 'browse') {
      OpenPage($id);
      $text = $Page{text};
    }
    my @fonts;
    while ($text =~ /\[font=([A-Z][^]]*)\]/g) {
      push(@fonts, $1);
    }
    foreach my $font (@fonts) {
      $font =~ s/ +/+/g;
      $HtmlHeaders .= qq{<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=$font">};
    }
  }
}

# global search

*OldNamespaceGrepFiltered = *GrepFiltered;
*GrepFiltered = *NewNamespaceGrepFiltered;

sub NewNamespaceGrepFiltered {
  if (GetParam('global', 0) and not $NamespaceCurrent) {
    return NamespaceGlobalGrepFiltered(@_);
  } else {
    return OldNamespaceGrepFiltered(@_);
  }
}

sub NamespaceGlobalGrepFiltered {
  my ($string, @pages) = @_;
  my $regexp = SearchRegexp($string);
  return @pages unless GetParam('grep', $UseGrep) and $regexp;
  my @result = grep(/$regexp/i, @pages);
  my %found = map {$_ => 1} @result;
  $regexp =~ s/\\n(\)*)$/\$$1/g; # sometimes \n can be replaced with $
  $regexp =~ s/([?+{|()])/\\$1/g; # basic regular expressions from man grep
  # if we know of any remaining grep incompatibilities we should
  # return @pages here!
  $regexp = quotemeta($regexp);
  open(F, '-|:encoding(UTF-8)', "grep --recursive --ignore-case --files-with-matches --regexp=$regexp --include='*.pg' --exclude-dir=keep --exclude-dir=temp '$DataDir' 2>/dev/null");
  while (<F>) {
    push(@result, $1) if m/.*\/(.*)\.pg/ and not $found{$1};
  }
  close(F);
  return sort @result;
}