forked from github/kensanata.oddmuse
Compare commits
5 Commits
2.4.0
...
namespaces
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
16053e26d7 | ||
|
|
f0d0942bfb | ||
|
|
cd9246ebed | ||
|
|
f7b23d854f | ||
|
|
104a1395e7 |
@@ -171,6 +171,7 @@ sub NewBanContributorsWriteRcLog {
|
||||
|
||||
package BanContributors;
|
||||
use Net::Whois::Parser qw/parse_whois/;
|
||||
use Net::IP;
|
||||
|
||||
sub get_range {
|
||||
my $ip = shift;
|
||||
@@ -181,7 +182,8 @@ sub get_range {
|
||||
my @result;
|
||||
$_ = $response->{$_};
|
||||
for (ref eq 'ARRAY' ? @$_ : $_) {
|
||||
push(@result, $1, $2) if /($re) *- *($re)/;
|
||||
$ip = Net::IP->new($_);
|
||||
push(@result, $ip->ip, $ip->last_ip) if $ip;
|
||||
}
|
||||
return @result if @result;
|
||||
}
|
||||
|
||||
66
modules/cook-lang.pl
Normal file
66
modules/cook-lang.pl
Normal file
@@ -0,0 +1,66 @@
|
||||
# Copyright (C) 2021 Alex Schroeder <alex@gnu.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use strict;
|
||||
use v5.10;
|
||||
|
||||
AddModuleDescription('cook-lang.pl', 'Cooklang Extension');
|
||||
|
||||
our ($q, $bol, @MyRules);
|
||||
|
||||
push(@MyRules, \&CookLangRule);
|
||||
|
||||
sub CookLangRule {
|
||||
if (/\G#([^\n#\@\{\}]+)\{(?:([^\n%\}]+)(?:%([^\n\}]+))?)?\}/cg) {
|
||||
# #canning funnel{}
|
||||
my $html = "";
|
||||
$html .= $q->strong({-title=>"number"}, $2) if $2;
|
||||
$html .= " " if $2 and $3;
|
||||
$html .= $q->strong({-title=>"unit"}, $3) if $3;
|
||||
$html .= " " if $1 and ($2 or $3);
|
||||
$html .= $q->strong({-title=>"cookware"}, $1);
|
||||
return $html;
|
||||
} elsif (/\G#(\w+)/cg) {
|
||||
# #pot
|
||||
return $q->strong({-title=>"cookware"}, $1);
|
||||
} elsif (/\G\@([^\n#\@\{\}]+)\{(?:([^\n%\}]+)(?:%([^\n\}]+))?)?\}/cg) {
|
||||
# @ground black pepper{}
|
||||
my $html = "";
|
||||
$html .= $q->strong({-title=>"number"}, $2) if $2;
|
||||
$html .= " " if $2 and $3;
|
||||
$html .= $q->strong({-title=>"unit"}, $3) if $3;
|
||||
$html .= " " if $1 and ($2 or $3);
|
||||
$html .= $q->strong({-title=>"ingredient"}, $1);
|
||||
return $html;
|
||||
} elsif (/\G\@(\w+)/cg) {
|
||||
# @salt
|
||||
return $q->strong({-title=>"ingredient"}, $1);
|
||||
} elsif (/\G\~\{([^\n%\}]+)(?:%([^\n\}]+))?\}/cg) {
|
||||
# ~{25%minutes}
|
||||
my $html = $q->strong({-title=>"number"}, $1);
|
||||
$html .= " " if $1 and $2;
|
||||
$html .= $q->strong({-title=>"unit"}, $2) if $2;
|
||||
return $html;
|
||||
} elsif (/\G\/\/\s*(.*)/cg) {
|
||||
# // Don't burn the roux!
|
||||
return $q->em({-title=>"comment"}, $1);
|
||||
} elsif ($bol and /\G>>\s*(.*)/cg) {
|
||||
# // Don't burn the roux!
|
||||
return CloseHtmlEnvironments()
|
||||
. $q->blockquote({-title=>"meta"}, $1)
|
||||
. AddHtmlEnvironment('p');
|
||||
}
|
||||
# no match
|
||||
return;
|
||||
}
|
||||
@@ -55,6 +55,8 @@ our ($NamespacesMain, $NamespacesSelf, $NamespaceCurrent,
|
||||
$NamespaceRoot, $NamespaceSlashing, @NamespaceParameters,
|
||||
%Namespaces, $NamespacesRootDataDir);
|
||||
|
||||
our ($OriginalSiteName, $OriginalInterWikiMoniker, $OriginalDataDir, $OriginalScriptName, $OriginalFullUrl, $OriginalStaticDir, $OriginalStaticUrl, $OriginalWikiDescription);
|
||||
|
||||
$NamespacesMain = 'Main'; # to get back to the main namespace
|
||||
$NamespacesSelf = 'Self'; # for your own namespace
|
||||
$NamespaceCurrent = ''; # the current namespace, if any
|
||||
@@ -104,6 +106,23 @@ sub GetNamespace {
|
||||
}
|
||||
|
||||
sub NamespacesInitVariables {
|
||||
$OriginalSiteName //= $SiteName;
|
||||
$SiteName = $OriginalSiteName;
|
||||
$OriginalInterWikiMoniker //= $InterWikiMoniker;
|
||||
$InterWikiMoniker = $OriginalInterWikiMoniker;
|
||||
$OriginalDataDir //= $DataDir;
|
||||
$DataDir = $OriginalDataDir;
|
||||
$OriginalScriptName //= $ScriptName;
|
||||
$ScriptName = $OriginalScriptName;
|
||||
$OriginalFullUrl //= $FullUrl;
|
||||
$FullUrl = $OriginalFullUrl;
|
||||
$OriginalStaticDir //= $StaticDir;
|
||||
$StaticDir = $OriginalStaticDir;
|
||||
$OriginalStaticUrl //= $StaticUrl;
|
||||
$StaticUrl = $OriginalStaticUrl;
|
||||
$OriginalWikiDescription //= $WikiDescription;
|
||||
$WikiDescription = $OriginalWikiDescription;
|
||||
|
||||
%Namespaces = ();
|
||||
# Do this before changing the $DataDir and $ScriptName
|
||||
if ($UsePathInfo) {
|
||||
@@ -126,23 +145,27 @@ sub NamespacesInitVariables {
|
||||
and $ns ne $NamespacesSelf) {
|
||||
$NamespaceCurrent = $ns;
|
||||
# Change some stuff from the original InitVariables call:
|
||||
$SiteName .= ' ' . $NamespaceCurrent;
|
||||
$SiteName .= ' ' . NormalToFree($NamespaceCurrent);
|
||||
$InterWikiMoniker = $NamespaceCurrent;
|
||||
$DataDir .= '/' . $NamespaceCurrent;
|
||||
$PageDir = "$DataDir/page";
|
||||
$KeepDir = "$DataDir/keep";
|
||||
$RefererDir = "$DataDir/referer";
|
||||
$TempDir = "$DataDir/temp";
|
||||
$LockDir = "$TempDir/lock";
|
||||
$NoEditFile = "$DataDir/noedit";
|
||||
$RcFile = "$DataDir/rc.log";
|
||||
$RcOldFile = "$DataDir/oldrc.log";
|
||||
$IndexFile = "$DataDir/pageidx";
|
||||
$VisitorFile = "$DataDir/visitors.log";
|
||||
$PermanentAnchorsFile = "$DataDir/permanentanchors";
|
||||
# $ConfigFile -- shared
|
||||
# $ModuleDir -- shared
|
||||
# $NearDir -- shared
|
||||
}
|
||||
$PageDir = "$DataDir/page";
|
||||
$KeepDir = "$DataDir/keep";
|
||||
$RefererDir = "$DataDir/referer";
|
||||
$TempDir = "$DataDir/temp";
|
||||
$LockDir = "$TempDir/lock";
|
||||
$NoEditFile = "$DataDir/noedit";
|
||||
$RcFile = "$DataDir/rc.log";
|
||||
$RcOldFile = "$DataDir/oldrc.log";
|
||||
$IndexFile = "$DataDir/pageidx";
|
||||
$VisitorFile = "$DataDir/visitors.log";
|
||||
$PermanentAnchorsFile = "$DataDir/permanentanchors";
|
||||
# $ConfigFile -- shared
|
||||
# $ModuleDir -- shared
|
||||
# $NearDir -- shared
|
||||
if ($ns
|
||||
and $ns ne $NamespacesMain
|
||||
and $ns ne $NamespacesSelf) {
|
||||
$ScriptName .= '/' . UrlEncode($NamespaceCurrent);
|
||||
$FullUrl .= '/' . UrlEncode($NamespaceCurrent);
|
||||
$StaticDir .= '/' . $NamespaceCurrent; # from static-copy.pl
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
require './t/test.pl';
|
||||
package OddMuse;
|
||||
use Test::More;
|
||||
use Net::IP;
|
||||
|
||||
add_module('ban-contributors.pl');
|
||||
|
||||
@@ -43,6 +44,13 @@ is(BanContributors::get_regexp_ip('45.87.2.128', '45.87.2.255'),
|
||||
'^45\.87\.2\.(12[8-9]|1[3-9][0-9]|2[0-4][0-9]|25[0-5])',
|
||||
'45.87.2.128 - 45.87.2.255');
|
||||
|
||||
# 191.101.0.0/16
|
||||
# verify that Net::IP works as intended
|
||||
my $ip = Net::IP->new('191.101.0.0/16');
|
||||
ok($ip, 'Net::IP parsed CIDR');
|
||||
is($ip->ip, '191.101.0.0', 'First IP in range');
|
||||
is($ip->last_ip, '191.101.255.255', 'Last IP in range');
|
||||
|
||||
$localhost = '127.0.0.1';
|
||||
$ENV{'REMOTE_ADDR'} = $localhost;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user