Ignore:
Timestamp:
11/23/08 11:02:43 (4 years ago)
Author:
ArthurClemens
Message:

Item244: generalized the copy subroutine for topic creation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/lib/Foswiki/UI/Manage.pm

    r859 r875  
    6262        _restoreRevision($session); 
    6363    } 
    64     elsif ( $action eq 'copy' ) { 
    65         _copyTopic($session); 
     64    elsif ( $action eq 'create' ) { 
     65        _createTopic($session); 
    6666    } 
    6767    elsif ($action) { 
     
    300300    my $breakLock   = $query->param('breaklock'); 
    301301 
    302     my $confirm          = $query->param('confirm'); 
    303     my $store            = $session->{store}; 
    304  
    305     $newTopic =~ s/\s//go; 
    306     $newTopic =~ s/$Foswiki::cfg{NameFilter}//go; 
    307     $newTopic = ucfirst $newTopic;    # Item3270 
     302    my $confirm = $query->param('confirm'); 
     303    my $store   = $session->{store}; 
    308304 
    309305    $attachment ||= ''; 
     
    327323 
    328324    if ($newTopic) { 
     325        $newTopic = _safeTopicName($newTopic); 
    329326        if ( !_isValidTopicName( $newTopic, $query->param('nonwikiword') ) ) { 
    330327            throw Foswiki::OopsException( 
     
    336333            ); 
    337334        } 
    338         $newTopic = _safeTopicName($newTopic); 
    339335    } 
    340336 
     
    405401        Foswiki::UI::checkAccess( $session, $oldWeb, $oldTopic, 'VIEW', 
    406402            $session->{user} ); 
    407         _newTopicScreen( $session, $oldWeb, $oldTopic, $newWeb, $newTopic, 
    408             $attachment, $confirm ); 
     403        _newTopicScreen( 
     404            $session,  $oldWeb,     $oldTopic, $newWeb, 
     405            $newTopic, $attachment, $confirm 
     406        ); 
    409407        return; 
    410408    } 
     
    513511=pod 
    514512 
    515 ---++ StaticMethod _copyTopic() 
    516  
    517 Copies a topic to new topic with name passed in query param 'newtopic'. 
    518 Redirects to edit screen. 
     513---++ StaticMethod _createTopic() 
     514 
     515Creates a topic to new topic with name passed in query param 'topic'. 
     516Creates an exception when the topic name is not valid; the topic name does not have to be a WikiWord if parameter 'nonwikiword' is set to 'on'. 
     517Redirects to the edit screen. 
     518 
     519Copy an existing topic using: 
     520        <form action="%SCRIPTURL{manage}%/%WEB%/"> 
     521        <input type="text" name="topic" class="twikiInputField" value="%TOPIC%Copy" size="30"> 
     522        <input type="hidden" name="action" value="create" /> 
     523        <input type="hidden" name="templatetopic" value="%TOPIC%" /> 
     524        ... 
     525        </form> 
    519526 
    520527=cut 
    521528 
    522  
    523 sub _copyTopic { 
     529sub _createTopic { 
    524530    my ($session) = @_; 
    525531 
    526532    my $query = $session->{request}; 
    527     my $newTopic = $query->param('newtopic') || ''; 
     533    my $newTopic = $query->param('topic') || ''; 
    528534 
    529535    # topic must not be empty 
     
    538544    } 
    539545 
    540     my $oldWeb           = $session->{webName}; 
    541     my $oldTopic         = $session->{topicName}; 
    542  
    543     if ($newTopic) { 
    544         # topic must be valid 
    545         if ( !_isValidTopicName( $newTopic, $query->param('nonwikiword') ) ) { 
    546             throw Foswiki::OopsException( 
    547                 'attention', 
    548                 web    => $oldWeb, 
    549                 topic  => $oldTopic, 
    550                 def    => 'not_wikiword', 
    551                 params => [$newTopic] 
    552             ); 
    553         } 
    554         $newTopic = _safeTopicName($newTopic); 
    555     } 
    556      
     546    my $oldWeb   = $session->{webName}; 
     547    my $oldTopic = $session->{topicName}; 
     548 
     549    Foswiki::UI::checkAccess( $session, $oldWeb, $newTopic, 'CHANGE', 
     550        $session->{user} ); 
     551 
     552    # topic must be valid 
     553    if ( !_isValidTopicName( $newTopic, $query->param('nonwikiword') ) ) { 
     554        throw Foswiki::OopsException( 
     555            'attention', 
     556            web    => $oldWeb, 
     557            topic  => $oldTopic, 
     558            def    => 'not_wikiword', 
     559            params => [$newTopic] 
     560        ); 
     561    } 
     562    $newTopic = _safeTopicName($newTopic); 
     563 
    557564    # untaint new topic name 
    558565    use Foswiki::Sandbox; 
     
    624631 
    625632    my $newTopic; 
    626     my $lockFailure        = ''; 
    627     my $breakLock          = $query->param('breaklock'); 
    628     my $confirm            = $query->param('confirm') || ''; 
    629     my $store              = $session->{store}; 
     633    my $lockFailure = ''; 
     634    my $breakLock   = $query->param('breaklock'); 
     635    my $confirm     = $query->param('confirm') || ''; 
     636    my $store       = $session->{store}; 
    630637 
    631638    Foswiki::UI::checkWebExists( $session, $oldWeb, 
     
    10081015# Display screen so user can decide on new web and topic. 
    10091016sub _newTopicScreen { 
    1010     my ( $session, $oldWeb, $oldTopic, $newWeb, $newTopic, $attachment, 
    1011         $confirm ) 
    1012       = @_; 
     1017    my ( 
     1018        $session,  $oldWeb,     $oldTopic, $newWeb, 
     1019        $newTopic, $attachment, $confirm 
     1020    ) = @_; 
    10131021 
    10141022    my $query          = $session->{request}; 
Note: See TracChangeset for help on using the changeset viewer.