summaryrefslogtreecommitdiffstats
path: root/colophon/oddmuse/config
blob: 7ff1d54bd21ec3875eec2e2df574fbf2579849ec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# -*- mode: perl -*-
use utf8; # this file contains utf8 strings.
do "$ENV{OMHOME}/omecp.pl";

$CookieName    = 'ECwiki';
$SiteName      = 'EmacsConf';
$HomePage      = 'main';
$RCName        = "recent_changes";
$FullUrl       = 'https://emacsconf.org';
$ScriptName    = "$FullUrl";
# $LogoUrl       = '/s/emacsconf-logo1-64.png';
$StyleSheet    = '/s/ecom.css';
$UploadAllowed = 1;

#$SurgeProtectionTime = 10;
#$SurgeProtectionViews = 50;

# As we're now behind a caching proxy, the environment variable
# REMOTE_ADDR is no longer what we want. We now want
# HTTP_X_FORWARDED_FOR.
$ENV{REMOTE_ADDR} = $ENV{HTTP_X_FORWARDED_FOR};

$HtmlHeaders .= '<link rel="icon" href="/s/emacsconf-logo1-256.png" type="image/png"/>'
  . '<meta name=viewport content="width=device-width, initial-scale=0.86, maximum-scale=3.0, minimum-scale=0.86"/>';

$SmartTitlesBrowserTitle = '%s - %s - %s';
$SmartTitlesBrowserTitleWithoutSubtitle = '%s - %s';

$FooterNote = '<p>Permission is granted to copy, distribute and/or
modify this document under the terms of the
<a href="https://www.gnu.org/licenses/fdl-1.3-standalone.html">GNU Free Documentation License</a>,
Version 1.3 or any later version published by the
<a href="https://www.fsf.org/">Free Software Foundation</a>.</p>
<p style="font-size:70%"><a href="https://emacsconf.org/colophon">Colophon</a></p>';

$UrlProtocols .= "|data|xmpp";

@UserGotoBarPages = ($RCName);
# $UserGotoBar = '<a class="local" href="https://emacsconf.org/2019/">2019</a>';

$UserGotoBarPrev = '<a class="local" href="https://emacsconf.org">EmacsConf</a>';
sub GetGotoBar {
  my $id = shift;
  return $q->span({-class=>'gotobar bar'},
    $UserGotoBarPrev,
    (map { GetPageLink($_) } @UserGotoBarPages),
    $UserGotoBar);
}

# Allow namespaces starting with a digit
# From https://github.com/kensanata/oddmuse/issues/19#issuecomment-503984930
$InterSitePattern = '[\p{Uppercase}\d][\w_  ]*';
# Redefine these as well if you change $InterSitePattern since InitLinkPatterns is called before InitConfig!
$InterLinkPattern = "($InterSitePattern:[-a-zA-Z0-9\x{0080}-\x{fffd}_=!?#\$\@~`\%&*+\\/:;.,]*[-a-zA-Z0-9\x{0080}-\x{fffd}_=#\$\@~`\%&*+\\/])$QDelim";
$FreeInterLinkPattern = "($InterSitePattern:[-a-zA-Z0-9\x{0080}-\x{fffd}_=!?#\$\@~`\%&*+\\/:;.,()' ]+)";

# Link to author page at the root namespace
# From https://github.com/kensanata/oddmuse/issues/20#issuecomment-500402339
sub GetAuthorLink {
  my ($username, $host) = @_;
  $username = FreeToNormal($username);
  $username =~ s/^(?:$InterSitePattern:)?$FreeLinkPattern/$1/;
  my $name = NormalToFree($username);
  if (ValidId($username) ne '') { # ValidId() returns error string
    $username = '';     # Just pretend it isn't there.
  }
  if ($username) {
    local $ScriptName = $NamespacesRoot;
    return ScriptLink(UrlEncode($username), $name, 'author');
  }
  return T('Anonymous') if $host eq 'Anonymous';
  return ColorCode($host);
}

# Fix visiting Main:X if the page doesn't exist but namespace X does.
# Redirect!
# From https://github.com/kensanata/oddmuse/issues/19#issuecomment-513640039
push(@MyInitVariables, \&MyNamespacesFix);
sub MyNamespacesFix {
  if (not GetParam('title', '')
      and GetParam('action', 'browse') eq 'browse') {
    my $id = FreeToNormal(GetId());
    if (not $NamespaceCurrent
        and (not $IndexHash{$id}
             or OpenPage($id) and PageMarkedForDeletion())
        and $Namespaces{$id}) {
      print GetRedirectPage("$id/", NormalToFree($id));
      exit;
    }
  }
};

@QuestionaskerQuestions =
  (['Please say HELLO.' => sub {
      shift =~ /^\s*(hello*|hewo*|hi*|h(i|e)ya*)!*\s*$/i }],
  );

# If enabling Markdown, to allow users to switch between Creole and Markdown
# see https://oddmuse.org/wiki/Creole_or_Markdown

$CommentsPrefix = 'comments_on_';

# Add 'Back to ' prefix to the link back to the article
# with adaptation from https://oddmuse.org/wiki/Comments_on_Comment_Pages
*MyOldGetFooterLinks = *GetFooterLinks;
*GetFooterLinks = *MyNewGetFooterLinks;

sub MyNewGetFooterLinks {
  my $html = MyOldGetFooterLinks(@_);
  my ($id, $rev) = @_;
  if ($id and $rev ne 'history' and $rev ne 'edit'
      and $CommentsPrefix) {
    if ($id =~ /^$CommentsPrefix(.*)/o) {
      my $from = NormalToFree($1);
      my $to = T('Back to ') . $from;
      $html =~ s/>$from</ accesskey="a">$to</;
    } else {
      my $from = NormalToFree($CommentsPrefix);
      my $to = T('Comments on ');
      $html =~ s/$from/$to/;
    }
  }
  # $html =~ s!</div>! <a class="local" href="https://emacsconf.org/colophon">Colophon</a></div>!;
  return $html;
}

# [[vid:addr]] rule for embedding videos
push(@MyRules, \&VidRule);

sub VidRule{
  if (/\G\[\[vid:(\d+\/[a-z0-9-_\.]*)\]\]/cgi) {
    my $vid = $1;
    return qq{
<video controls preload="metadata">
  <source src="/videos/$vid" type="video/mp4">
</video><br/>
<a href="/videos/$vid" download>Download</a>};
  }
  return;
}

# [[vidlink:addr]] rule for linking to videos
push(@MyRules, \&VidLinkRule);

sub VidLinkRule{
  if (/\G\[\[vidlink:(\d+\/[a-z0-9-_\.]*)\|(.*)\]\]/cgi) {
    my ($vid, $cap) = ($1, $2);
    return qq{<a href="/videos/$vid">$cap</a>};
  }
  return;
}