Skip to content

Commit

Permalink
Item11587: cleaned up use of deprecated api
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/TopicNameValidationPlugin@16702 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed May 6, 2013
1 parent 0e7df10 commit 171babe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
6 changes: 3 additions & 3 deletions data/System/TopicNameValidationPlugin.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" date="1224862720" format="1.1" version="$Rev$"}%
%META:TOPICINFO{author="BaseUserMapping_999" comment="autosave" date="1356278781" format="1.1" version="1"}%
---+!! %TOPIC%
%SHORTDESCRIPTION%

Expand Down Expand Up @@ -52,11 +52,11 @@ One line description, required for extensions repository catalog.
Sponsored by <a href="http://www.schenck-rotec.net"><img src="%ATTACHURLPATH%/schenck_logo.gif" border="0" title="Schenck-RoTec"/></a>

| Plugin Author(s): | Foswiki:Main/MichaelDaum |
| Copyright &copy;: | 2008-2012, Michael Daum http://michaeldaumconsulting.com |
| Copyright &copy;: | 2008-2013, Michael Daum http://michaeldaumconsulting.com |
| License: | [[http://www.gnu.org/licenses/gpl.html][GPL (Gnu General Public License)]] |
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 06 May 2013 | cleaned up use of deprecated api |
| 07 May 2012 | added german translation |
| 23 Apr 2009 | converted to foswiki plugin |
| 24 Oct 2008 | initial version |
Expand Down
48 changes: 23 additions & 25 deletions lib/Foswiki/Plugins/TopicNameValidationPlugin.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2008-2012 MichaelDaum http://michaeldaumconsulting.com
# Copyright (C) 2008-2013 MichaelDaum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -13,23 +13,24 @@
# GNU General Public License for more details, published at
# http://www.gnu.org/copyleft/gpl.html


package Foswiki::Plugins::TopicNameValidationPlugin;

use strict;
require Foswiki::Func; # The plugins API
require Foswiki::Plugins; # For the API version
require Foswiki::OopsException; # For the API version
use warnings;

use Foswiki::Func();
use Foswiki::Plugins();
use Foswiki::OopsException();

use vars qw(
$VERSION $RELEASE $SHORTDESCRIPTION $NO_PREFS_IN_TOPIC
$baseWeb $baseTopic @ruleSet $doneInit
);
our $VERSION = '1.20';
our $RELEASE = '1.20';
our $SHORTDESCRIPTION = 'Control naming of topics';
our $NO_PREFS_IN_TOPIC = 1;

$VERSION = '$Rev$';
$RELEASE = '1.1';
$SHORTDESCRIPTION = 'Control naming of topics';
$NO_PREFS_IN_TOPIC = 1;
our $baseWeb;
our $baseTopic;
our @ruleSet;
our $doneInit = 0;

use constant DEBUG => 0; # toggle me

Expand All @@ -46,6 +47,7 @@ sub initPlugin {
($baseTopic, $baseWeb) = @_;

$doneInit = 0;
@ruleSet = ();

return 1;
}
Expand All @@ -56,9 +58,7 @@ sub doInit {
return if $doneInit;
$doneInit = 1;

#writeDebug("called doInit()");

@ruleSet = ();
writeDebug("called doInit()");

my $systemWeb = $Foswiki::cfg{SystemWebName};
my $ruleSetTopics = Foswiki::Func::getPreferencesFlag("TOPICVALIDATION_PLUGIN_RULESET")
Expand All @@ -69,18 +69,18 @@ sub doInit {

# get topic name
my ($ruleSetWeb, $ruleSetTopic) = Foswiki::Func::normalizeWebTopicName($baseWeb, $webTopic);
if (!Foswiki::Func::topicExists($ruleSetWeb, $ruleSetTopic)) {
unless (Foswiki::Func::topicExists($ruleSetWeb, $ruleSetTopic)) {
my $msg = "ruleset topic '$webTopic' not found";
#writeDebug($msg);
writeDebug($msg);
Foswiki::Func::writeWarning($msg);
next;
}

# read rules
my $rulesText = Foswiki::Func::readTopicText($ruleSetWeb, $ruleSetTopic);
foreach my $line (split /\n/, $rulesText) {
my ($meta, $text) = Foswiki::Func::readTopic($ruleSetWeb, $ruleSetTopic);
foreach my $line (split /\n/, $text) {
if ($line =~ /^\s*\|\s*(.*?)\s*\|\s*(.*?)\s*\|\s*(.*?)\s*\|\s*$/) {
#writeDebug("line=$line");
writeDebug("line=$line");
next if $1 =~ /^\*.*\*$/o;
next if $3 =~ /disabled/;
my $isAllowed = ($3 =~ /allowed/)?1:0;
Expand All @@ -90,7 +90,7 @@ sub doInit {
error => $2,
isAllowed => $isAllowed,
};
#writeDebug("found pattern='$1', error='$2', isAllowed=$isAllowed");
writeDebug("found pattern='$1', error='$2', isAllowed=$isAllowed");
}
}
}
Expand All @@ -109,7 +109,7 @@ sub checkRules {

if ($webTopicName =~ /$pattern/) {
#writeDebug("$webTopicName matches '$pattern'");
if (!$rule->{isAllowed}) {
unless ($rule->{isAllowed}) {
throw Foswiki::OopsException(
'topicname',
def => $action,
Expand All @@ -132,6 +132,4 @@ sub beforeEditHandler {
checkRules('edit', @_);
}



1;

0 comments on commit 171babe

Please sign in to comment.