1
# See bottom of file for license and copyright information
2
package Foswiki::Compatibility;
8
---+ package Foswiki::Compatibility
10
Support for compatibility with old versions. Packaged
11
separately because 99.999999% of the time this won't be needed.
15
sub _upgradeCategoryItem {
16
my ( $catitems, $ctext ) = @_;
21
my @cmd = split( /\|/, $catitems );
27
return ( $catname, $catmodifier, $catvalue );
34
# check for CategoryName=CategoryValue parameter
36
my $cvalue = ''; # was$query->param( $cmd[1] );
38
$src = "<!---->$cvalue<!---->";
41
foreach ( split( /\r?\n/, $ctext ) ) {
49
if ( $cmd[0] eq 'select' || $cmd[0] eq 'radio' ) {
53
#$scatname =~ s/[^a-zA-Z0-9]//g;
55
for ( $i = 3 ; $i < $len ; $i++ ) {
58
if ( $src =~ /$value/ ) {
64
elsif ( $cmd[0] eq 'checkbox' ) {
68
#$scatname =~ s/[^a-zA-Z0-9]//g;
69
if ( $cmd[2] eq 'true' || $cmd[2] eq '1' ) {
73
$itemsPerLine = $cmd[3];
74
for ( $i = 4 ; $i < $len ; $i++ ) {
78
# I18N: FIXME - need to look at this, but since it's upgrading
79
# old forms that probably didn't use I18N, it's not a high
81
if ( $src =~ /$value[^a-zA-Z0-9\.]/ ) {
82
$catvalue .= ", " if ($catvalue);
88
elsif ( $cmd[0] eq 'text' ) {
92
#$scatname =~ s/[^a-zA-Z0-9]//g;
93
# SMELL: unchecked implicit untaint?
94
$src =~ /<!---->(.*)<!---->/;
104
return ( $catname, $catmodifier, $catvalue );
109
---++ StaticMethod upgradeCategoryTable( $session, $web, $topic, $meta, $text ) -> $text
111
Upgrade old style category table
113
May throw Foswiki::OopsException
117
sub upgradeCategoryTable {
118
my ( $session, $web, $topic, $meta, $text ) = @_;
120
my $icat = $session->templates->readTemplate('twikicatitems');
125
# extract category section and build category form elements
126
my ( $before, $ctext, $after ) = split( /<!--TWikiCat-->/, $text );
129
$text = $before || '';
130
$text .= $after if ($after);
131
$ctext = '' if ( !$ctext );
134
foreach ( split( /\r?\n/, $icat ) ) {
135
my ( $catname, $catmod, $catvalue ) =
136
_upgradeCategoryItem( $_, $ctext );
138
push @items, ( [ $catname, $catmod, $catvalue ] );
141
my $prefs = $session->{prefs};
142
my $listForms = $prefs->getWebPreferencesValue( 'WEBFORMS', $web );
143
$listForms =~ s/^\s*//go;
144
$listForms =~ s/\s*$//go;
145
my @formTemplates = split( /\s*,\s*/, $listForms );
146
my $defaultFormTemplate = '';
147
$defaultFormTemplate = $formTemplates[0] if (@formTemplates);
149
if ( !$defaultFormTemplate ) {
150
$session->logger->log(
152
"Form: can't get form definition to convert category table "
153
. " for topic $web.$topic" );
154
foreach my $oldCat (@items) {
155
my $name = $oldCat->[0];
156
my $value = $oldCat->[2];
157
$meta->put( 'FORM', { name => '' } );
170
require Foswiki::Form;
171
my $def = new Foswiki::Form( $session, $web, $defaultFormTemplate );
172
$meta->put( 'FORM', { name => $defaultFormTemplate } );
174
foreach my $fieldDef ( @{ $def->getFields() } ) {
176
foreach my $oldCatP (@items) {
177
my @oldCat = @$oldCatP;
178
my $name = $oldCat[0] || '';
179
$name =~ s/[^A-Za-z0-9_\.]//go;
180
if ( $name eq $fieldDef->{name} ) {
188
name => $fieldDef->{name},
189
title => $fieldDef->{title},
197
$session->logger->log('warning',
198
"Form: get find category template twikicatitems for Web $web");
203
#Get file attachment attributes for old html
205
sub _getOldAttachAttr {
206
my ( $session, $atext ) = @_;
212
my $fileComment = '';
216
my $users = $session->{users};
218
( $before, $fileName, $after ) = split( /<(?:\/)*TwkFileName>/, $atext );
219
if ( !$fileName ) { $fileName = ''; }
221
( $before, $filePath, $after ) =
222
split( /<(?:\/)*TwkFilePath>/, $atext );
223
if ( !$filePath ) { $filePath = ''; }
224
# SMELL: unchecked implicit untaint
225
$filePath =~ s/<TwkData value="(.*)">//go;
226
if ($1) { $filePath = $1; }
227
else { $filePath = ''; }
229
s/\%NOP\%//goi; # delete placeholder that prevents WikiLinks
230
( $before, $fileSize, $after ) =
231
split( /<(?:\/)*TwkFileSize>/, $atext );
232
if ( !$fileSize ) { $fileSize = '0'; }
233
( $before, $fileDate, $after ) =
234
split( /<(?:\/)*TwkFileDate>/, $atext );
240
$fileDate =~ s/ / /go;
241
require Foswiki::Time;
242
$fileDate = Foswiki::Time::parseTime($fileDate);
244
( $before, $fileUser, $after ) =
245
split( /<(?:\/)*TwkFileUser>/, $atext );
250
$fileUser = $users->getLoginName($fileUser) if $fileUser;
253
$fileUser =~ s/ //go;
254
( $before, $fileComment, $after ) =
255
split( /<(?:\/)*TwkFileComment>/, $atext );
256
if ( !$fileComment ) { $fileComment = ''; }
259
return ( $fileName, $filePath, $fileSize, $fileDate, $fileUser,
265
---++ migrateToFileAttachmentMacro ( $session, $meta, $text ) -> $text
267
Migrate old HTML format
271
sub migrateToFileAttachmentMacro {
272
my ( $session, $meta, $text ) = @_;
273
ASSERT( $meta->isa('Foswiki::Meta') ) if DEBUG;
275
my ( $before, $atext, $after ) = split( /<!--TWikiAttachment-->/, $text );
276
$text = $before || '';
277
$text .= $after if ($after);
278
$atext = '' if ( !$atext );
280
if ( $atext =~ /<TwkNextItem>/ ) {
282
foreach $line ( split( /<TwkNextItem>/, $atext ) ) {
284
$fileName, $filePath, $fileSize,
285
$fileDate, $fileUser, $fileComment
286
) = _getOldAttachAttr( $session, $line );
298
comment => $fileComment,
307
# Format of macro that came before META:ATTACHMENT
309
require Foswiki::Attrs;
310
foreach $line ( split( /\r?\n/, $atext ) ) {
311
if ( $line =~ /%FILEATTACHMENT{\s"([^"]*)"([^}]*)}%/ ) {
313
my $values = new Foswiki::Attrs($2);
314
$values->{name} = $name;
315
$meta->putKeyed( 'FILEATTACHMENT', $values );
325
---++ upgradeFrom1v0beta ( $session, $meta ) -> $text
329
sub upgradeFrom1v0beta {
330
my ( $session, $meta ) = @_;
331
my $users = $session->{users};
332
require Foswiki::Time;
334
my @attach = $meta->find('FILEATTACHMENT');
335
foreach my $att (@attach) {
336
my $date = $att->{date} || 0;
337
if ( $date =~ /-/ ) {
338
$date =~ s/ / /go;
339
$date = Foswiki::Time::parseTime($date);
341
$att->{date} = $date;
342
$att->{user} = $users->webDotWikiName( $att->{user} );
348
# Module of Foswiki - The Free and Open Source Wiki, http://foswiki.org/
350
# Copyright (C) 2008-2009 Foswiki Contributors. All Rights Reserved.
351
# Foswiki Contributors are listed in the AUTHORS file in the root
352
# of this distribution. NOTE: Please extend that file, not this notice.
354
# Additional copyrights apply to some or all of the code in this
357
# Copyright (C) 1999-2007 TWiki Contributors. All Rights Reserved.
358
# TWiki Contributors are listed in the AUTHORS file in the root
359
# of this distribution. NOTE: Please extend that file, not this notice.
361
# This program is free software; you can redistribute it and/or
362
# modify it under the terms of the GNU General Public License
363
# as published by the Free Software Foundation; either version 2
364
# of the License, or (at your option) any later version. For
365
# more details read LICENSE in the root of this distribution.
367
# This program is distributed in the hope that it will be useful,
368
# but WITHOUT ANY WARRANTY; without even the implied warranty of
369
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
371
# As per the GPL, removal of this notice is prohibited.