Changeset 858
- Timestamp:
- 11/23/08 00:47:55 (3 years ago)
- Location:
- trunk/core
- Files:
-
- 1 added
- 3 edited
-
lib/Foswiki/UI/Manage.pm (modified) (9 diffs)
-
templates/messages.tmpl (modified) (1 diff)
-
templates/oopsmore.tmpl (modified) (1 diff)
-
test/unit/ManageDotPmTests.pm (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/core/lib/Foswiki/UI/Manage.pm
r830 r858 61 61 elsif ( $action eq 'restoreRevision' ) { 62 62 _restoreRevision($session); 63 } 64 elsif ( $action eq 'copy' ) { 65 _copyTopic($session); 63 66 } 64 67 elsif ($action) { … … 297 300 my $breakLock = $query->param('breaklock'); 298 301 299 my $confirm = $query->param('confirm');300 my $ doAllowNonWikiWord= $query->param('nonwikiword') || '';301 my $store = $session->{store};302 my $confirm = $query->param('confirm'); 303 my $nonWikiWordParam = $query->param('nonwikiword') || ''; 304 my $store = $session->{store}; 302 305 303 306 $newTopic =~ s/\s//go; … … 324 327 } 325 328 326 if ( $newTopic && !Foswiki::isValidWikiWord($newTopic)) {327 unless ($doAllowNonWikiWord) {329 if ($newTopic) { 330 if ( !_isValidTopicName( $newTopic, $nonWikiWordParam ) ) { 328 331 throw Foswiki::OopsException( 329 332 'attention', … … 334 337 ); 335 338 } 336 337 # Filter out dangerous characters (. and / may cause 338 # issues with pathnames 339 $newTopic =~ s![./]!_!g; 340 $newTopic =~ s/($Foswiki::cfg{NameFilter})//go; 339 $newTopic = _safeTopicName($newTopic); 341 340 } 342 341 … … 408 407 $session->{user} ); 409 408 _newTopicScreen( $session, $oldWeb, $oldTopic, $newWeb, $newTopic, 410 $attachment, $confirm, $ doAllowNonWikiWord);409 $attachment, $confirm, $nonWikiWordParam ); 411 410 return; 412 411 } … … 468 467 #follow redirectto= 469 468 $session->redirect( $new_url, undef, 1 ); 469 } 470 471 =pod 472 473 ---++ StaticMethod _isValidTopicName( $topic, $nonWikiWordParam ) -> $boolean 474 475 Checks whether a topic name is valid. This may depend on the setting of session param 'nonwikiword'. 476 477 Usage: 478 my $isValidName = _isValidTopicName( $newTopic, $query->param('nonwikiword') ); 479 480 =cut 481 482 sub _isValidTopicName { 483 my ( $topic, $nonWikiWordParam ) = @_; 484 485 my $nonWikiWord = $nonWikiWordParam || 0; 486 my $doAllowNonWikiWord = Foswiki::isTrue($nonWikiWord); 487 488 return 0 if !$topic; 489 return 0 if ( !Foswiki::isValidTopicName($topic) && !$doAllowNonWikiWord ); 490 return 1 if ( Foswiki::isValidTopicName($topic) ); 491 492 return 1; 493 } 494 495 =pod 496 497 ---++ StaticMethod _safeTopicName( $topic ) -> $topic 498 499 Filter out dangerous characters . and / may cause issues with pathnames. 500 501 =cut 502 503 sub _safeTopicName { 504 my ($topic) = @_; 505 506 $topic =~ s/\s//go; 507 $topic = ucfirst $topic; # Item3270 508 $topic =~ s![./]!_!g; 509 $topic =~ s/($Foswiki::cfg{NameFilter})//go; 510 511 return $topic; 512 } 513 514 =pod 515 516 ---++ StaticMethod _copyTopic() 517 518 Copies a topic to new topic with name passed in query param 'newtopic'. 519 Redirects to edit screen. 520 521 =cut 522 523 524 sub _copyTopic { 525 my ($session) = @_; 526 527 my $query = $session->{request}; 528 my $newTopic = $query->param('newtopic') || ''; 529 530 # topic must not be empty 531 if ( !$newTopic ) { 532 throw Foswiki::OopsException( 533 'attention', 534 web => undef, 535 topic => $newTopic, 536 def => 'empty_topic_name', 537 params => undef 538 ); 539 } 540 541 my $oldWeb = $session->{webName}; 542 my $oldTopic = $session->{topicName}; 543 my $nonWikiWordParam = $query->param('nonwikiword') || ''; 544 545 if ($newTopic) { 546 # topic must be valid 547 if ( !_isValidTopicName( $newTopic, $nonWikiWordParam ) ) { 548 throw Foswiki::OopsException( 549 'attention', 550 web => $oldWeb, 551 topic => $oldTopic, 552 def => 'not_wikiword', 553 params => [$newTopic] 554 ); 555 } 556 $newTopic = _safeTopicName($newTopic); 557 } 558 559 # untaint new topic name 560 use Foswiki::Sandbox; 561 $session->{topicName} = Foswiki::Sandbox::untaintUnchecked($newTopic); 562 563 require Foswiki::UI::Edit; 564 Foswiki::UI::Edit::edit($session); 470 565 } 471 566 … … 1225 1320 1226 1321 $tmpl = 1227 $session->handleCommonTags( $tmpl, $oldWeb, $Foswiki::cfg{HomeTopicName} ); 1322 $session->handleCommonTags( $tmpl, $oldWeb, 1323 $Foswiki::cfg{HomeTopicName} ); 1228 1324 $tmpl = 1229 1325 $session->renderer->getRenderedVersion( $tmpl, $oldWeb, … … 1341 1437 \&Foswiki::Render::replaceTopicReferences, $options ); 1342 1438 $meta->forEachSelectedValue( 1343 qw/^(FIELD|FORM|TOPICPARENT)$/, undef,1439 qw/^(FIELD|FORM|TOPICPARENT)$/, undef, 1344 1440 \&Foswiki::Render::replaceTopicReferences, $options 1345 1441 ); … … 1386 1482 \&Foswiki::Render::replaceWebReferences, $options ); 1387 1483 $meta->forEachSelectedValue( 1388 qw/^(FIELD|FORM|TOPICPARENT)$/, undef,1484 qw/^(FIELD|FORM|TOPICPARENT)$/, undef, 1389 1485 \&Foswiki::Render::replaceWebReferences, $options 1390 1486 ); -
trunk/core/templates/messages.tmpl
r758 r858 88 88 %MAKETEXT{"Please go back in your browser and choose a topic name that is a [_1].WikiWord or check the allow non-Wiki Word box" args="%SYSTEMWEB%"}% 89 89 %TMPL:END% 90 91 %TMPL:DEF{"empty_topic_name"}% 92 ---++ %MAKETEXT{"You must pass a topic name."}% 93 %MAKETEXT{"The name of the topic must not be empty." args="%PARAM1%"}% 94 95 %MAKETEXT{"Please go back in your browser and try again."}% 96 %TMPL:END% 97 90 98 %TMPL:DEF{"rename_err"}% 91 99 %MAKETEXT{"During rename of topic [_1] to [_2] an error ([_3]) was found. Please notify your [_4] administrator." args="<nop>%WEB%.<nop>%TOPIC%,<nop>%PARAM2%,%PARAM1%,%WIKITOOLNAME%"}% -
trunk/core/templates/oopsmore.tmpl
r847 r858 20 20 %MAKETEXT{"Copy text and form data to a new topic (no attachments will be copied though)."}% 21 21 22 <form action="%SCRIPTURL{edit}%/%WEB%/"> 23 %MAKETEXT{"Name of copy:"}% <input type="text" name="topic" class="twikiInputField" value="%TOPIC%Copy" size="30"> <input type="submit" class="twikiButton" value="Clone" /> <span class="twikiGrayText">%MAKETEXT{"You will be able to review the copied topic before saving"}%</span> 22 <form action="%SCRIPTURL{manage}%/%WEB%/"> 23 %MAKETEXT{"Name of copy:"}% <input type="text" name="newtopic" class="twikiInputField" value="%TOPIC%Copy" size="30"> <input type="submit" class="twikiButton" value="Clone" /> <span class="twikiGrayText">%MAKETEXT{"You will be able to review the copied topic before saving"}%</span> 24 %TMPL:P{"nonwikiword"}% 25 <input type="hidden" name="action" value="copy" /> 24 26 <input type="hidden" name="onlynewtopic" value="on" /> 25 27 <input type="hidden" name="templatetopic" value="%TOPIC%" />
Note: See TracChangeset
for help on using the changeset viewer.
