Ignore:
Timestamp:
11/19/08 15:00:00 (4 years ago)
Author:
CrawfordCurrie
Message:

Item175: port a subset of the standard extensions over to the new namespace to make a working system with mixed TWiki and Foswiki plugins

Location:
trunk/MailerContrib/lib/Foswiki
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/MailerContrib/lib/Foswiki/Contrib/MailerContrib.pm

    r781 r811  
    22# 
    33# Copyright (C) 2004 Wind River Systems Inc. 
    4 # Copyright (C) 1999-2006 TWiki Contributors. 
    5 # All Rights Reserved. TWiki Contributors 
     4# Copyright (C) 1999-2006 Foswiki Contributors. 
     5# All Rights Reserved. Foswiki Contributors 
    66# are listed in the AUTHORS file in the root of this distribution. 
    77# NOTE: Please extend that file, not this notice. 
     
    2121=pod 
    2222 
    23 ---+ package TWiki::Contrib::MailerContrib 
     23---+ package Foswiki::Contrib::MailerContrib 
    2424 
    2525Package of support for extended Web<nop>Notify notification, supporting per-topic notification and notification of changes to children. 
     
    2929=cut 
    3030 
    31 package TWiki::Contrib::MailerContrib; 
     31package Foswiki::Contrib::MailerContrib; 
    3232 
    3333use strict; 
     
    3636use CGI qw(-any); 
    3737 
    38 require TWiki; 
    39 require TWiki::Plugins; 
    40 require TWiki::Time; 
    41 require TWiki::Func; 
    42 require TWiki::Contrib::MailerContrib::WebNotify; 
    43 require TWiki::Contrib::MailerContrib::Change; 
    44 require TWiki::Contrib::MailerContrib::UpData; 
     38require Foswiki; 
     39require Foswiki::Plugins; 
     40require Foswiki::Time; 
     41require Foswiki::Func; 
     42require Foswiki::Contrib::MailerContrib::WebNotify; 
     43require Foswiki::Contrib::MailerContrib::Change; 
     44require Foswiki::Contrib::MailerContrib::UpData; 
    4545 
    4646use vars qw ( $VERSION $RELEASE $verbose ); 
     
    5151# PROTECTED STATIC ensure the contrib is initernally initialised 
    5252sub initContrib { 
    53     $TWiki::cfg{MailerContrib}{EmailFilterIn} ||= 
    54       $TWiki::regex{emailAddrRegex}; 
     53    $Foswiki::cfg{MailerContrib}{EmailFilterIn} ||= 
     54      $Foswiki::regex{emailAddrRegex}; 
    5555} 
    5656 
     
    9090 
    9191    if (!defined $twiki) { 
    92         $twiki = new TWiki(); 
    93     } 
    94  
    95     $TWiki::Plugins::SESSION = $twiki; 
    96  
    97     my $context = TWiki::Func::getContext(); 
     92        $twiki = new Foswiki(); 
     93    } 
     94 
     95    $Foswiki::Plugins::SESSION = $twiki; 
     96 
     97    my $context = Foswiki::Func::getContext(); 
    9898 
    9999    $context->{command_line} = 1; 
     
    105105 
    106106    my $report = ''; 
    107     foreach my $web ( TWiki::Func::getListOfWebs( 'user ') ) { 
     107    foreach my $web ( Foswiki::Func::getListOfWebs( 'user ') ) { 
    108108       if ( $web =~ /^($webstr)$/ && $web !~ /^($exwebstr)$/ ) { 
    109109          $report .= _processWeb( $twiki, $web ); 
     
    124124 
    125125    #we can get away with a normalise on a list of topics, so long as the list starts with a topic 
    126     my ($web, $t) = TWiki::Func::normalizeWebTopicName($defaultWeb, $topicList); 
     126    my ($web, $t) = Foswiki::Func::normalizeWebTopicName($defaultWeb, $topicList); 
    127127    #TODO: this limits us to subscribing to one web. 
    128     my $wn = new TWiki::Contrib::MailerContrib::WebNotify( 
    129         $TWiki::Plugins::SESSION, $web, $TWiki::cfg{NotifyTopicName}, 1 ); 
     128    my $wn = new Foswiki::Contrib::MailerContrib::WebNotify( 
     129        $Foswiki::Plugins::SESSION, $web, $Foswiki::cfg{NotifyTopicName}, 1 ); 
    130130    $wn->parsePageSubscriptions( $who, $topicList, $unsubscribe ); 
    131131    $wn->writeWebNotify(); 
     
    151151                    }; 
    152152 
    153     my $ret = TWiki::Contrib::MailerContrib::parsePageList($subscribed, $who, $topicList); 
     153    my $ret = Foswiki::Contrib::MailerContrib::parsePageList($subscribed, $who, $topicList); 
    154154     
    155155    return (!defined($subscribed->{not_subscribed}) || 
     
    159159    my ( $subscribed, $who, $unsubscribe, $topic, $options, $childDepth ) = @_; 
    160160     
    161     require TWiki::Contrib::MailerContrib::WebNotify; 
    162     my ($sweb, $stopic) = TWiki::Func::normalizeWebTopicName($subscribed->{currentWeb}, $topic); 
     161    require Foswiki::Contrib::MailerContrib::WebNotify; 
     162    my ($sweb, $stopic) = Foswiki::Func::normalizeWebTopicName($subscribed->{currentWeb}, $topic); 
    163163 
    164164    #TODO: extract this code so we only create $wn objects for each web once..     
    165     my $wn = new TWiki::Contrib::MailerContrib::WebNotify( $TWiki::Plugins::SESSION, $sweb, $TWiki::cfg{NotifyTopicName} ); 
     165    my $wn = new Foswiki::Contrib::MailerContrib::WebNotify( $Foswiki::Plugins::SESSION, $sweb, $Foswiki::cfg{NotifyTopicName} ); 
    166166    my $subscriber = $wn->getSubscriber($who); 
    167167     
    168     my $db = new TWiki::Contrib::MailerContrib::UpData( $TWiki::Plugins::SESSION, $sweb ); 
     168    my $db = new Foswiki::Contrib::MailerContrib::UpData( $Foswiki::Plugins::SESSION, $sweb ); 
    169169    #TODO: need to check $childDepth topics too (somehow) 
    170170    if ( $subscriber->isSubscribedTo($stopic, $db) && 
     
    207207    my( $twiki, $web) = @_; 
    208208 
    209     if( ! TWiki::Func::webExists( $web ) ) { 
     209    if( ! Foswiki::Func::webExists( $web ) ) { 
    210210#        print STDERR "**** ERROR mailnotifier cannot find web $web\n"; 
    211211        return ''; 
     
    217217 
    218218    # Read the webnotify and load subscriptions 
    219     my $wn = new TWiki::Contrib::MailerContrib::WebNotify( 
    220         $twiki, $web, $TWiki::cfg{NotifyTopicName} ); 
     219    my $wn = new Foswiki::Contrib::MailerContrib::WebNotify( 
     220        $twiki, $web, $Foswiki::cfg{NotifyTopicName} ); 
    221221    if ( $wn->isEmpty() ) { 
    222222        print "\t$web has no subscribers\n" if $verbose; 
     
    224224        # create a DB object for parent pointers 
    225225        print $wn->stringify(1) if $verbose; 
    226         my $db = new TWiki::Contrib::MailerContrib::UpData( $twiki, $web ); 
     226        my $db = new Foswiki::Contrib::MailerContrib::UpData( $twiki, $web ); 
    227227        $report .= _processSubscriptions( $twiki, $web, $wn, $db ); 
    228228    } 
     
    235235    my ( $twiki, $web, $notify, $db ) = @_; 
    236236 
    237     my $metadir = TWiki::Func::getWorkArea('MailerContrib'); 
     237    my $metadir = Foswiki::Func::getWorkArea('MailerContrib'); 
    238238    my $notmeta = $web; 
    239239    $notmeta =~ s#/#.#g; 
     
    249249    if ( $verbose ) { 
    250250        print "\tLast notification was at " . 
    251           TWiki::Time::formatTime( $timeOfLastNotify, 'iso' ). "\n"; 
     251          Foswiki::Time::formatTime( $timeOfLastNotify, 'iso' ). "\n"; 
    252252    } 
    253253 
     
    270270    my %allSet; 
    271271 
    272     if( !defined( &TWiki::Func::eachChangeSince )) { 
    273         require TWiki::Contrib::MailerContrib::CompatibilityHacks; 
     272    if( !defined( &Foswiki::Func::eachChangeSince )) { 
     273        require Foswiki::Contrib::MailerContrib::CompatibilityHacks; 
    274274    } 
    275275 
    276276    # + 1 because the 'since' check is >= 
    277     my $it = TWiki::Func::eachChangeSince( $web, $timeOfLastNotify + 1 ); 
     277    my $it = Foswiki::Func::eachChangeSince( $web, $timeOfLastNotify + 1 ); 
    278278    while( $it->hasNext() ) { 
    279279        my $change = $it->next(); 
    280280        next if $change->{more} && $change->{more} =~ /minor$/; 
    281281 
    282         next unless TWiki::Func::topicExists( $web, $change->{topic} ); 
     282        next unless Foswiki::Func::topicExists( $web, $change->{topic} ); 
    283283 
    284284        $timeOfLastChange = $change->{time} unless( $timeOfLastChange ); 
    285285 
    286286        print "\tChange to $change->{topic} at ". 
    287           TWiki::Time::formatTime( $change->{time}, 'iso' ). 
     287          Foswiki::Time::formatTime( $change->{time}, 'iso' ). 
    288288              ". New revision is $change->{revision}\n" if ( $verbose ); 
    289289 
    290290        # Formulate a change record, irrespective of 
    291291        # whether any subscriber is interested 
    292         $change = new TWiki::Contrib::MailerContrib::Change( 
     292        $change = new Foswiki::Contrib::MailerContrib::Change( 
    293293            $twiki, $web, $change->{topic}, $change->{user}, 
    294294            $change->{time}, $change->{revision} ); 
     
    300300    # For each topic, see if there's a compulsory subscription independent 
    301301    # of the time since last notify 
    302     foreach my $topic (TWiki::Func::getTopicList($web)) { 
     302    foreach my $topic (Foswiki::Func::getTopicList($web)) { 
    303303        $notify->processCompulsory( $topic, $db, \%allSet ); 
    304304    } 
     
    307307    my $report = _sendChangesMails( 
    308308        $twiki, $web, \%changeset, 
    309         TWiki::Time::formatTime($timeOfLastNotify) ); 
     309        Foswiki::Time::formatTime($timeOfLastNotify) ); 
    310310 
    311311    $report .= _sendNewsletterMails( $twiki, $web, \%allSet); 
     
    326326    my $report = ''; 
    327327 
    328     my $skin = TWiki::Func::getSkin(); 
    329     my $template = TWiki::Func::readTemplate( 'mailnotify', $skin ); 
    330  
    331     my $homeTopic = $TWiki::cfg{HomeTopicName}; 
    332  
    333     my $before_html = TWiki::Func::expandTemplate( 'HTML:before' ); 
    334     my $middle_html = TWiki::Func::expandTemplate( 'HTML:middle' ); 
    335     my $after_html = TWiki::Func::expandTemplate( 'HTML:after' ); 
    336  
    337     my $before_plain = TWiki::Func::expandTemplate( 'PLAIN:before' ); 
    338     my $middle_plain = TWiki::Func::expandTemplate( 'PLAIN:middle' ); 
    339     my $after_plain = TWiki::Func::expandTemplate( 'PLAIN:after' ); 
    340  
    341     my $mailtmpl = TWiki::Func::expandTemplate( 'MailNotifyBody' ); 
    342     $mailtmpl = TWiki::Func::expandCommonVariables( 
     328    my $skin = Foswiki::Func::getSkin(); 
     329    my $template = Foswiki::Func::readTemplate( 'mailnotify', $skin ); 
     330 
     331    my $homeTopic = $Foswiki::cfg{HomeTopicName}; 
     332 
     333    my $before_html = Foswiki::Func::expandTemplate( 'HTML:before' ); 
     334    my $middle_html = Foswiki::Func::expandTemplate( 'HTML:middle' ); 
     335    my $after_html = Foswiki::Func::expandTemplate( 'HTML:after' ); 
     336 
     337    my $before_plain = Foswiki::Func::expandTemplate( 'PLAIN:before' ); 
     338    my $middle_plain = Foswiki::Func::expandTemplate( 'PLAIN:middle' ); 
     339    my $after_plain = Foswiki::Func::expandTemplate( 'PLAIN:after' ); 
     340 
     341    my $mailtmpl = Foswiki::Func::expandTemplate( 'MailNotifyBody' ); 
     342    $mailtmpl = Foswiki::Func::expandCommonVariables( 
    343343        $mailtmpl, $homeTopic, $web ); 
    344     if( $TWiki::cfg{RemoveImgInMailnotify} ) { 
     344    if( $Foswiki::cfg{RemoveImgInMailnotify} ) { 
    345345        # change images to [alt] text if there, else remove image 
    346346        $mailtmpl =~ s/<img\s[^>]*\balt=\"([^\"]+)[^>]*>/[$1]/goi; 
     
    360360        } 
    361361 
    362         $plain =~ s/\($TWiki::cfg{UsersWebName}\./\(/go; 
     362        $plain =~ s/\($Foswiki::cfg{UsersWebName}\./\(/go; 
    363363 
    364364        my $mail = $mailtmpl; 
     
    368368        $mail =~ s/%PLAIN_TEXT%/$before_plain$plain$after_plain/go; 
    369369        $mail =~ s/%LASTDATE%/$lastTime/geo; 
    370         $mail = TWiki::Func::expandCommonVariables( $mail, $homeTopic, $web ); 
    371  
    372         my $base = $TWiki::cfg{DefaultUrlHost} . $TWiki::cfg{ScriptUrlPath}; 
     370        $mail = Foswiki::Func::expandCommonVariables( $mail, $homeTopic, $web ); 
     371 
     372        my $base = $Foswiki::cfg{DefaultUrlHost} . $Foswiki::cfg{ScriptUrlPath}; 
    373373        $mail =~ s/(href=\")([^"]+)/$1.relativeURL($base,$2)/goei; 
    374374        $mail =~ s/(action=\")([^"]+)/$1.relativeURL($base,$2)/goei; 
     
    377377        $mail =~ s/( ?) *<\/?(nop|noautolink)\/?>\n?/$1/gois; 
    378378 
    379         my $error = TWiki::Func::sendEmail( $mail, 5 ); 
     379        my $error = Foswiki::Func::sendEmail( $mail, 5 ); 
    380380 
    381381        if ($error) { 
     
    410410sub _sendNewsletterMail { 
    411411    my ($twiki, $web, $topic, $emails) = @_; 
    412     my $wikiName = TWiki::Func::getWikiName(); 
     412    my $wikiName = Foswiki::Func::getWikiName(); 
    413413 
    414414    # SMELL: this code is almost identical to PublishContrib 
    415415 
    416416    # Read topic data. 
    417     my ($meta, $text) = TWiki::Func::readTopic( $web, $topic ); 
    418  
    419     if (!defined( &TWiki::Func::pushTopicContext )) { 
    420         require TWiki::Contrib::MailerContrib::TopicContext; 
    421     } 
    422     TWiki::Func::pushTopicContext( $web, $topic ); 
     417    my ($meta, $text) = Foswiki::Func::readTopic( $web, $topic ); 
     418 
     419    if (!defined( &Foswiki::Func::pushTopicContext )) { 
     420        require Foswiki::Contrib::MailerContrib::TopicContext; 
     421    } 
     422    Foswiki::Func::pushTopicContext( $web, $topic ); 
    423423 
    424424    $twiki->enterContext( 'can_render_meta', $meta ); 
    425425 
    426426    # Get the skin for this topic 
    427     my $skin = TWiki::Func::getSkin(); 
    428     TWiki::Func::readTemplate( 'newsletter', $skin ); 
    429     my $header = TWiki::Func::expandTemplate( 'NEWS:header' ); 
    430     my $body = TWiki::Func::expandTemplate( 'NEWS:body' ); 
    431     my $footer = TWiki::Func::expandTemplate( 'NEWS:footer' ); 
     427    my $skin = Foswiki::Func::getSkin(); 
     428    Foswiki::Func::readTemplate( 'newsletter', $skin ); 
     429    my $header = Foswiki::Func::expandTemplate( 'NEWS:header' ); 
     430    my $body = Foswiki::Func::expandTemplate( 'NEWS:body' ); 
     431    my $footer = Foswiki::Func::expandTemplate( 'NEWS:footer' ); 
    432432 
    433433    my ($revdate, $revuser, $maxrev); 
     
    437437    $body =~ s/%TEXT%/$text/g; 
    438438    # Don't render the header, it is preformatted 
    439     $header = TWiki::Func::expandCommonVariables($header, $topic, $web); 
     439    $header = Foswiki::Func::expandCommonVariables($header, $topic, $web); 
    440440    my $tmpl = "$body\n$footer"; 
    441     $tmpl = TWiki::Func::expandCommonVariables($tmpl, $topic, $web); 
    442     $tmpl = TWiki::Func::renderText($tmpl, "", $meta); 
     441    $tmpl = Foswiki::Func::expandCommonVariables($tmpl, $topic, $web); 
     442    $tmpl = Foswiki::Func::renderText($tmpl, "", $meta); 
    443443    $tmpl = "$header$tmpl"; 
    444444 
     
    475475 
    476476    # Rewrite absolute URLs 
    477     my $base = $TWiki::cfg{DefaultUrlHost} . $TWiki::cfg{ScriptUrlPath}; 
     477    my $base = $Foswiki::cfg{DefaultUrlHost} . $Foswiki::cfg{ScriptUrlPath}; 
    478478    $tmpl =~ s/(href=\")([^"]+)/$1.relativeURL($base,$2)/goei; 
    479479    $tmpl =~ s/(action=\")([^"]+)/$1.relativeURL($base,$2)/goei; 
     
    489489        $mail =~ s/%EMAILTO%/$email/go; 
    490490 
    491         my $base = $TWiki::cfg{DefaultUrlHost} . $TWiki::cfg{ScriptUrlPath}; 
     491        my $base = $Foswiki::cfg{DefaultUrlHost} . $Foswiki::cfg{ScriptUrlPath}; 
    492492        $mail =~ s/(href=\")([^"]+)/$1.relativeURL($base,$2)/goei; 
    493493        $mail =~ s/(action=\")([^"]+)/$1.relativeURL($base,$2)/goei; 
     
    496496        $mail =~ s/( ?) *<\/?(nop|noautolink)\/?>\n?/$1/gois; 
    497497 
    498         my $error = TWiki::Func::sendEmail( $mail, 5 ); 
     498        my $error = Foswiki::Func::sendEmail( $mail, 5 ); 
    499499 
    500500        if ($error) { 
     
    508508    $report .= "\t$sentMails newsletters from $web\n"; 
    509509 
    510     TWiki::Func::popTopicContext(); 
     510    Foswiki::Func::popTopicContext(); 
    511511 
    512512    return $report; 
Note: See TracChangeset for help on using the changeset viewer.