Changeset 431
- Timestamp:
- 05/11/08 17:04:41 (4 years ago)
- Location:
- wiki-toolkit/trunk
- Files:
-
- 27 modified
-
Makefile.PL (modified) (10 diffs)
-
bin/wiki-toolkit-delete-node (modified) (8 diffs)
-
bin/wiki-toolkit-rename-node (modified) (6 diffs)
-
bin/wiki-toolkit-revert-to-date (modified) (8 diffs)
-
bin/wiki-toolkit-setupdb (modified) (4 diffs)
-
lib/Wiki/Toolkit.pm (modified) (17 diffs)
-
lib/Wiki/Toolkit/Feed/Atom.pm (modified) (9 diffs)
-
lib/Wiki/Toolkit/Feed/Listing.pm (modified) (3 diffs)
-
lib/Wiki/Toolkit/Feed/RSS.pm (modified) (14 diffs)
-
lib/Wiki/Toolkit/Formatter/Default.pm (modified) (6 diffs)
-
lib/Wiki/Toolkit/Formatter/Multiple.pm (modified) (2 diffs)
-
lib/Wiki/Toolkit/Formatter/WikiLinkFormatterParent.pm (modified) (2 diffs)
-
lib/Wiki/Toolkit/Search/Base.pm (modified) (2 diffs)
-
lib/Wiki/Toolkit/Search/Plucene.pm (modified) (5 diffs)
-
lib/Wiki/Toolkit/Search/SII.pm (modified) (4 diffs)
-
lib/Wiki/Toolkit/Setup/DBIxFTSMySQL.pm (modified) (2 diffs)
-
lib/Wiki/Toolkit/Setup/Database.pm (modified) (3 diffs)
-
lib/Wiki/Toolkit/Setup/MySQL.pm (modified) (9 diffs)
-
lib/Wiki/Toolkit/Setup/Pg.pm (modified) (9 diffs)
-
lib/Wiki/Toolkit/Setup/SII.pm (modified) (2 diffs)
-
lib/Wiki/Toolkit/Setup/SQLite.pm (modified) (8 diffs)
-
lib/Wiki/Toolkit/Store/Database.pm (modified) (59 diffs)
-
lib/Wiki/Toolkit/Store/MySQL.pm (modified) (2 diffs)
-
lib/Wiki/Toolkit/Store/Pg.pm (modified) (3 diffs)
-
lib/Wiki/Toolkit/Store/SQLite.pm (modified) (3 diffs)
-
lib/Wiki/Toolkit/TestConfig/Utilities.pm (modified) (5 diffs)
-
lib/Wiki/Toolkit/TestLib.pm (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wiki-toolkit/trunk/Makefile.PL
r430 r431 15 15 if ($Wiki::Toolkit::TestConfig::configured 16 16 and not (@ARGV and $ARGV[0] eq '-s') 17 and not $ENV{WIKI_TOOLKIT_RERUN_CONFIG} 18 ) { 17 and not $ENV{WIKI_TOOLKIT_RERUN_CONFIG}) { 19 18 print "\nFor the test suite, we use the database and user info\n" 20 19 . "specified during the previous run. If you want to change\n" … … 32 31 . "preferably relevant to the backend(s) you intend to use live.\n" 33 32 . "Running the tests under every possible backend combination is\n" 34 . "recommended. To enter an undefined value, accept the empty\n"33 . "recommended. To enter an undefined value, accept the empty\n" 35 34 . "string or explicitly enter 'undef'.\n\n" 36 35 . "**** THESE TESTS ARE DESTRUCTIVE. ****\n" … … 53 52 foreach my $store (qw(MySQL Pg)) { 54 53 my $dbname = $ENV{"WIKI_TOOLKIT_".uc($store)."_DBNAME"}; 55 if ($dbname and $dbname ne "undef") {56 $config{$store}{dbname} = $dbname;54 if ($dbname and $dbname ne "undef") { 55 $config{$store}{dbname} = $dbname; 57 56 foreach my $var (qw(dbuser dbpass dbhost)) { 58 57 my $value = $ENV{"WIKI_TOOLKIT_".uc($store)."_".uc($var)}; 59 if ($value and $value ne "undef") { $config{$store}{$var} = $value; 60 } elsif ($value eq "undef") { 61 $config{$store}{$var} = undef; 62 } 63 } 64 } elsif ($dbname eq "undef") { 65 $config{$store}{dbname} = undef; 66 } 58 if ($value and $value ne "undef") { 59 $config{$store}{$var} = $value; 60 } elsif ($value eq "undef") { 61 $config{$store}{$var} = undef; 62 } 63 } 64 } elsif ($dbname eq "undef") { 65 $config{$store}{dbname} = undef; 66 } 67 67 } 68 68 … … 76 76 # Finally ask questions; then check the settings work. 77 77 my %driver = ( MySQL => "DBD::mysql", 78 Pg => "DBD::Pg" );78 Pg => "DBD::Pg" ); 79 79 foreach my $store_type (qw(MySQL Pg)) { 80 80 # See whether we have the driver installed. … … 82 82 if ($@) { 83 83 print "\n$driver{$store_type} not installed... skipping...\n"; 84 $config{$store_type}{dbname} = undef;85 next;86 }84 $config{$store_type}{dbname} = undef; 85 next; 86 } 87 87 88 88 # Prompt for the options. … … 90 90 my $pad = ' ' x (7-length $store_type); 91 91 $dbname = prompt "\n${pad}Database name for $store_type: ", 92 $config{$store_type}{dbname};92 $config{$store_type}{dbname}; 93 93 undef $dbname unless ($dbname and $dbname ne "undef"); 94 94 if ($dbname and $dbname ne "undef") { 95 $dbuser = prompt " Database user: ",96 $config{$store_type}{dbuser};95 $dbuser = prompt " Database user: ", 96 $config{$store_type}{dbuser}; 97 97 undef $dbuser unless ($dbuser and $dbuser ne "undef"); 98 $dbpass = prompt " Database password: ",99 $config{$store_type}{dbpass};98 $dbpass = prompt " Database password: ", 99 $config{$store_type}{dbpass}; 100 100 undef $dbpass unless ($dbpass and $dbpass ne "undef"); 101 $dbhost = prompt "Database host (if needed): ",102 $config{$store_type}{dbhost};101 $dbhost = prompt "Database host (if needed): ", 102 $config{$store_type}{dbhost}; 103 103 undef $dbhost unless ($dbhost and $dbhost ne "undef"); 104 104 … … 107 107 $config{$store_type}{dbpass} = $dbpass; 108 108 $config{$store_type}{dbhost} = $dbhost; 109 } else {109 } else { 110 110 print "\nNo database name supplied... skipping...\n"; 111 $config{$store_type}{dbname} = undef;112 }111 $config{$store_type}{dbname} = undef; 112 } 113 113 } 114 114 … … 121 121 # If we have a MySQL store configured, we can test the DBIx::FullTextSearch 122 122 # search backend. 123 eval { require DBIx::FullTextSearch; 124 require Lingua::Stem; 123 eval { 124 require DBIx::FullTextSearch; 125 require Lingua::Stem; 125 126 }; 126 127 my $fts_inst = $@ ? 0 : 1; … … 172 173 # Write out the config for next run. 173 174 open OUT, ">lib/Wiki/Toolkit/TestConfig.pm" 174 or die "Couldn't open lib/Wiki/Toolkit/TestConfig.pm for writing: $!";175 or die "Couldn't open lib/Wiki/Toolkit/TestConfig.pm for writing: $!"; 175 176 # warning - blind copy and paste follows. FIXME. 176 177 print OUT Data::Dumper->new([ \%Wiki::Toolkit::TestConfig::config ], 177 [ '*Wiki::Toolkit::TestConfig::config' ]178 )->Dump,179 "\$Wiki::Toolkit::TestConfig::configured = 1;\n1;\n";178 [ '*Wiki::Toolkit::TestConfig::config' ] 179 )->Dump, 180 "\$Wiki::Toolkit::TestConfig::configured = 1;\n1;\n"; 180 181 close OUT; 181 182 … … 202 203 # Write the Makefile. 203 204 WriteMakefile( NAME => "Wiki::Toolkit", 204 VERSION_FROM => "lib/Wiki/Toolkit.pm", 205 PREREQ_PM => { 'Text::WikiFormat' => '0.78', #earlier's buggy 206 'HTML::PullParser' => 0, 207 'Digest::MD5' => 0, 208 'Test::More' => 0, 209 'Time::Piece' => 0, 210 %extras }, 205 VERSION_FROM => "lib/Wiki/Toolkit.pm", 206 PREREQ_PM => { 'Text::WikiFormat' => '0.78', #earlier's buggy 207 'HTML::PullParser' => 0, 208 'Digest::MD5' => 0, 209 'Test::More' => 0, 210 'Time::Piece' => 0, 211 %extras 212 }, 211 213 EXE_FILES => [ "bin/wiki-toolkit-setupdb", 212 214 "bin/wiki-toolkit-rename-node", 213 215 "bin/wiki-toolkit-delete-node", 214 "bin/wiki-toolkit-revert-to-date" ], 215 clean => { FILES => "Config lib/Wiki/Toolkit/TestConfig.pm " 216 . "t/sqlite-test.db t/sii-db-file-test.db " 216 "bin/wiki-toolkit-revert-to-date" 217 ], 218 clean => { FILES => "Config lib/Wiki/Toolkit/TestConfig.pm " 219 . "t/sqlite-test.db t/sii-db-file-test.db " 217 220 . "t/node.db t/plucene" 218 221 } 219 );222 ); -
wiki-toolkit/trunk/bin/wiki-toolkit-delete-node
r423 r431 14 14 "nodename=s" => \$node_name, 15 15 "version=s" => \$version, 16 );16 ); 17 17 18 18 unless (defined($dbtype)) { … … 29 29 30 30 if(defined($id) and defined($node_name)) { 31 print "You should supply either a node name, or an id, but not both.\n"; 32 print "Further help can be found by typing 'perldoc $0'\n"; 33 exit 1; 34 } 31 print "You should supply either a node name, or an id, but not both.\n"; 32 print "Further help can be found by typing 'perldoc $0'\n"; 33 exit 1; 34 } 35 35 36 if(not defined($id) and not defined($node_name)) { 36 print "You must supply the id of the node with the --id option,\n";37 print " or the node name of the node with the --nodename option.\n";38 print "Further help can be found by typing 'perldoc $0'\n";39 exit 1;37 print "You must supply the id of the node with the --id option,\n"; 38 print " or the node name of the node with the --nodename option.\n"; 39 print "Further help can be found by typing 'perldoc $0'\n"; 40 exit 1; 40 41 } 41 42 … … 46 47 47 48 my %setup_modules = ( postgres => "Wiki::Toolkit::Store::Pg", 48 mysql => "Wiki::Toolkit::Store::MySQL",49 sqlite => "Wiki::Toolkit::Store::SQLite"49 mysql => "Wiki::Toolkit::Store::MySQL", 50 sqlite => "Wiki::Toolkit::Store::SQLite" 50 51 ); 51 52 … … 68 69 my $store; 69 70 my $args = "dbname=>'$dbname', dbuser=>'$dbuser'"; 70 if($dbpass) { $args .= ", dbpass=>'$dbpass'"; } 71 if($dbhost) { $args .= ", dbhost=>'$dbhost'"; } 72 if($dbport) { $args .= ", dbport=>'$dbport'"; } 71 if($dbpass) { 72 $args .= ", dbpass=>'$dbpass'"; 73 } 74 if($dbhost) { 75 $args .= ", dbhost=>'$dbhost'"; 76 } 77 if($dbport) { 78 $args .= ", dbport=>'$dbport'"; 79 } 73 80 eval "\$store = $class->new($args);"; 74 81 … … 78 85 # If they gave the ID, get the name 79 86 if($id) { 80 $node_name = $wiki->store->node_name_for_id($id);81 unless($node_name) {82 die("No node found with id '$id'\n");83 }87 $node_name = $wiki->store->node_name_for_id($id); 88 unless($node_name) { 89 die("No node found with id '$id'\n"); 90 } 84 91 } 85 92 … … 87 94 print "Deleting node with name '$node_name'"; 88 95 if($id) { 89 print " (id $id)";96 print " (id $id)"; 90 97 } 91 98 if($version) { 92 print " at version $version";99 print " at version $version"; 93 100 } 94 101 print "\n"; … … 100 107 print "done.\n"; 101 108 102 103 109 =head1 NAME 104 110 … … 110 116 111 117 wiki-toolkit-delete-node --type postgres 112 --name mywiki \113 --user wiki \114 --pass wiki \115 --host 'db.example.com' \116 --port 1234 \117 --nodename MyNodeName118 --name mywiki \ 119 --user wiki \ 120 --pass wiki \ 121 --host 'db.example.com' \ 122 --port 1234 \ 123 --nodename MyNodeName 118 124 119 125 wiki-toolkit-delete-node --type postgres 120 --name mywiki \121 --user wiki \122 --pass wiki \123 --host 'db.example.com' \124 --port 1234 \125 --id 2 \126 --version 7126 --name mywiki \ 127 --user wiki \ 128 --pass wiki \ 129 --host 'db.example.com' \ 130 --port 1234 \ 131 --id 2 \ 132 --version 7 127 133 128 134 =head1 DESCRIPTION -
wiki-toolkit/trunk/bin/wiki-toolkit-rename-node
r398 r431 13 13 "oldname=s" => \$oldname, 14 14 "newname=s" => \$newname, 15 );15 ); 16 16 17 17 unless (defined($dbtype)) { … … 28 28 29 29 unless (defined($oldname)) { 30 print "You must supply the old node name with the --oldname option.\n";31 print "Further help can be found by typing 'perldoc $0'\n";32 exit 1;30 print "You must supply the old node name with the --oldname option.\n"; 31 print "Further help can be found by typing 'perldoc $0'\n"; 32 exit 1; 33 33 } 34 34 35 35 unless (defined($newname)) { 36 print "You must supply the new node name with the --newname option.\n";37 print "Further help can be found by typing 'perldoc $0'\n";38 exit 1;36 print "You must supply the new node name with the --newname option.\n"; 37 print "Further help can be found by typing 'perldoc $0'\n"; 38 exit 1; 39 39 } 40 40 … … 45 45 46 46 my %setup_modules = ( postgres => "Wiki::Toolkit::Store::Pg", 47 mysql => "Wiki::Toolkit::Store::MySQL",48 sqlite => "Wiki::Toolkit::Store::SQLite"47 mysql => "Wiki::Toolkit::Store::MySQL", 48 sqlite => "Wiki::Toolkit::Store::SQLite" 49 49 ); 50 50 … … 67 67 my $store; 68 68 my $args = "dbname=>'$dbname', dbuser=>'$dbuser'"; 69 if($dbpass) { $args .= ", dbpass=>'$dbpass'"; } 70 if($dbhost) { $args .= ", dbhost=>'$dbhost'"; } 71 if($dbport) { $args .= ", dbport=>'$dbport'"; } 69 if($dbpass) { 70 $args .= ", dbpass=>'$dbpass'"; 71 } 72 if($dbhost) { 73 $args .= ", dbhost=>'$dbhost'"; 74 } 75 if($dbport) { 76 $args .= ", dbport=>'$dbport'"; 77 } 72 78 eval "\$store = $class->new($args);"; 73 79 … … 81 87 print "Renamed '$oldname' to '$newname'\n"; 82 88 83 84 89 =head1 NAME 85 90 … … 92 97 93 98 wiki-toolkit-rename-node --type postgres 94 --name mywiki \95 --user wiki \96 --pass wiki \97 --host 'db.example.com' \98 --port 123499 --oldname MyOldNodeName \100 --nemname FancyNewNodeName99 --name mywiki \ 100 --user wiki \ 101 --pass wiki \ 102 --host 'db.example.com' \ 103 --port 1234 104 --oldname MyOldNodeName \ 105 --nemname FancyNewNodeName 101 106 102 107 =head1 DESCRIPTION -
wiki-toolkit/trunk/bin/wiki-toolkit-revert-to-date
r397 r431 13 13 "date=s" => \$date, 14 14 "time=s" => \$time, 15 );15 ); 16 16 17 17 unless (defined($dbtype)) { … … 28 28 29 29 unless (defined($date)) { 30 print "You must supply the date with the --date option.\n";31 print "Further help can be found by typing 'perldoc $0'\n";32 exit 1;30 print "You must supply the date with the --date option.\n"; 31 print "Further help can be found by typing 'perldoc $0'\n"; 32 exit 1; 33 33 } 34 34 35 35 unless ($date =~ /^\d{4}\-\d{2}\-\d{2}$/) { 36 print "You must supply the date with --date in the format YYYY-MM-DD.\n";37 print "Further help can be found by typing 'perldoc $0'\n";38 exit 1;36 print "You must supply the date with --date in the format YYYY-MM-DD.\n"; 37 print "Further help can be found by typing 'perldoc $0'\n"; 38 exit 1; 39 39 } 40 40 unless (!$time || $time =~ /^\d{2}:\d{2}:\d{2}$/) { 41 print "You must supply either no time, or the time in the format HH:MM:SS.\n";42 print "Further help can be found by typing 'perldoc $0'\n";43 exit 1;41 print "You must supply either no time, or the time in the format HH:MM:SS.\n"; 42 print "Further help can be found by typing 'perldoc $0'\n"; 43 exit 1; 44 44 } 45 45 … … 50 50 51 51 my %setup_modules = ( postgres => "Wiki::Toolkit::Store::Pg", 52 mysql => "Wiki::Toolkit::Store::MySQL",53 sqlite => "Wiki::Toolkit::Store::SQLite"52 mysql => "Wiki::Toolkit::Store::MySQL", 53 sqlite => "Wiki::Toolkit::Store::SQLite" 54 54 ); 55 55 … … 72 72 my $store; 73 73 my $args = "dbname=>'$dbname', dbuser=>'$dbuser'"; 74 if($dbpass) { $args .= ", dbpass=>'$dbpass'"; } 75 if($dbhost) { $args .= ", dbhost=>'$dbhost'"; } 76 if($dbport) { $args .= ", dbport=>'$dbport'"; } 74 if($dbpass) { 75 $args .= ", dbpass=>'$dbpass'"; 76 } 77 if($dbhost) { 78 $args .= ", dbhost=>'$dbhost'"; 79 } 80 if($dbport) { 81 $args .= ", dbport=>'$dbport'"; 82 } 77 83 eval "\$store = $class->new($args);"; 78 84 … … 81 87 82 88 # Grab the state as of then 83 if($time) { $date .= " ".$time; } 89 if($time) { 90 $date .= " ".$time; 91 } 84 92 print "Reverting to the state as of $date\n"; 85 93 86 94 my @nodes = $wiki->list_last_version_before($date); 87 95 foreach my $node (@nodes) { 88 my %newnode = $wiki->retrieve_node($node->{name}); 89 my $thenver = $node->{version}; 90 if($thenver) { $thenver = sprintf("v%02d", $thenver); } 91 else { $thenver = "(d)"; } 92 93 print sprintf(' %03d - %s (now v%02d) - %s', $node->{id}, $thenver, $newnode{version}, $node->{name})."\n"; 96 my %newnode = $wiki->retrieve_node($node->{name}); 97 my $thenver = $node->{version}; 98 if($thenver) { 99 $thenver = sprintf("v%02d", $thenver); } 100 else { 101 $thenver = "(d)"; 102 } 103 104 print sprintf(' %03d - %s (now v%02d) - %s', $node->{id}, $thenver, $newnode{version}, $node->{name})."\n"; 94 105 } 95 106 … … 98 109 chomp $ok; 99 110 unless($ok eq "y") { 100 die("Aborting revert\n");111 die("Aborting revert\n"); 101 112 } 102 113 103 114 # Revert each node 104 115 foreach my $node (@nodes) { 105 if($node->{version}) {106 # Delete versions between now and then107 my %newnode = $wiki->retrieve_node($node->{name});108 for(my $ver=$newnode{version}; $ver>$node->{version}; $ver--) {109 $wiki->delete_node(110 name=>$node->{name},111 version=>$ver,112 wiki=>$wiki113 );114 print sprintf('Deleted node v%02d of %03d - %s',$ver, $node->{id},$node->{name})."\n";115 }116 } else {117 # No version then, delete118 $wiki->delete_node(119 name=>$node->{name},120 wiki=>$wiki121 );122 print sprintf('Deleted node %03d - %s',$node->{id},$node->{name})."\n";123 }116 if($node->{version}) { 117 # Delete versions between now and then 118 my %newnode = $wiki->retrieve_node($node->{name}); 119 for (my $ver=$newnode{version}; $ver>$node->{version}; $ver--) { 120 $wiki->delete_node( 121 name=>$node->{name}, 122 version=>$ver, 123 wiki=>$wiki 124 ); 125 print sprintf('Deleted node v%02d of %03d - %s',$ver, $node->{id},$node->{name})."\n"; 126 } 127 } else { 128 # No version then, delete 129 $wiki->delete_node( 130 name=>$node->{name}, 131 wiki=>$wiki 132 ); 133 print sprintf('Deleted node %03d - %s',$node->{id},$node->{name})."\n"; 134 } 124 135 } 125 136 … … 127 138 print "\nDone revert to $date\n"; 128 139 129 130 140 =head1 NAME 131 141 … … 138 148 139 149 wiki-toolkit-revert-to-date --type postgres 140 --name mywiki \141 --user wiki \142 --pass wiki \143 --host 'db.example.com' \144 --port 1234 \145 --date 2007-01-05 \146 --time 11:23:21150 --name mywiki \ 151 --user wiki \ 152 --pass wiki \ 153 --host 'db.example.com' \ 154 --port 1234 \ 155 --date 2007-01-05 \ 156 --time 11:23:21 147 157 148 158 =head1 DESCRIPTION -
wiki-toolkit/trunk/bin/wiki-toolkit-setupdb
r235 r431 5 5 my ($dbtype, $dbname, $dbuser, $dbpass, $dbhost, $help, $preclear); 6 6 GetOptions( "type=s" => \$dbtype, 7 "name=s" => \$dbname,7 "name=s" => \$dbname, 8 8 "user=s" => \$dbuser, 9 9 "pass=s" => \$dbpass, … … 11 11 "help" => \$help, 12 12 "force-preclear" => \$preclear 13 );13 ); 14 14 15 15 unless (defined($dbtype)) { … … 31 31 32 32 my %setup_modules = ( postgres => "Wiki::Toolkit::Setup::Pg", 33 mysql => "Wiki::Toolkit::Setup::MySQL",34 sqlite => "Wiki::Toolkit::Setup::SQLite"33 mysql => "Wiki::Toolkit::Setup::MySQL", 34 sqlite => "Wiki::Toolkit::Setup::SQLite" 35 35 ); 36 36 … … 69 69 70 70 wiki-toolkit-setupdb --type postgres 71 --name mywiki \72 --user wiki \73 --pass wiki \74 --host 'db.example.com'71 --name mywiki \ 72 --user wiki \ 73 --pass wiki \ 74 --host 'db.example.com' 75 75 76 76 # Clear out any existing data and set up a fresh backend from scratch. 77 77 78 78 wiki-toolkit-setupdb --type postgres 79 --name mywiki \80 --user wiki \81 --pass wiki \82 --force-preclear79 --name mywiki \ 80 --user wiki \ 81 --pass wiki \ 82 --force-preclear 83 83 84 84 =head1 DESCRIPTION -
wiki-toolkit/trunk/lib/Wiki/Toolkit.pm
r424 r431 15 15 my $CAN_USE_ENCODE; 16 16 BEGIN { 17 eval " use Encode "; 18 $CAN_USE_ENCODE = $@ ? 0 : 1; 19 } 20 17 eval " use Encode "; 18 $CAN_USE_ENCODE = $@ ? 0 : 1; 19 } 21 20 22 21 =head1 NAME … … 45 44 46 45 my $wiki = Wiki::Toolkit->new( store => $store, 47 search => $search );46 search => $search ); 48 47 49 48 # Do all the CGI stuff. … … 56 55 my $cooked = $wiki->format($raw); 57 56 print_page(node => $node, 58 content => $cooked);57 content => $cooked); 59 58 } elsif ($action eq 'preview') { 60 59 my $submitted_content = $q->param("content"); 61 60 my $preview_html = $wiki->format($submitted_content); 62 61 print_editform(node => $node, 63 content => $submitted_content,64 preview => $preview_html);62 content => $submitted_content, 63 preview => $preview_html); 65 64 } elsif ($action eq 'commit') { 66 65 my $submitted_content = $q->param("content"); … … 142 141 . "of Wiki::Toolkit - the $obsolete_param parameter is no longer used. " 143 142 . "Please read the documentation with 'perldoc Wiki::Toolkit'" 144 if $args{$obsolete_param};143 if $args{$obsolete_param}; 145 144 } 146 145 … … 158 157 my %config; 159 158 foreach ( qw( extended_links implicit_links allowed_tags 160 macros node_prefix ) ) {159 macros node_prefix ) ) { 161 160 $config{$_} = $args{$_} if defined $args{$_}; 162 }161 } 163 162 $self->{_formatter} = Wiki::Toolkit::Formatter::Default->new( %config ); 164 163 } … … 219 218 my ($self, @rawargs) = @_; 220 219 221 my %args = scalar @rawargs == 1 ? ( name => $rawargs[0] ) : @rawargs;220 my %args = scalar @rawargs == 1 ? ( name => $rawargs[0] ) : @rawargs; 222 221 223 222 my @plugins = $self->get_registered_plugins; … … 243 242 244 243 my $ret = $self->store->moderate_node( %args ); 245 if($ret == -1) { return $ret; }246 return 1;244 if($ret == -1) { return $ret; } 245 return 1; 247 246 } 248 247 … … 278 277 sub rename_node { 279 278 my ($self, @argsarray) = @_; 280 my %args = @argsarray;281 if((scalar @argsarray) == 2 || (scalar @argsarray) == 3) {282 # Missing keys283 %args = (284 old_name => $argsarray[0],285 new_name => $argsarray[1],286 create_new_versions => $argsarray[2]287 );288 }279 my %args = @argsarray; 280 if ((scalar @argsarray) == 2 || (scalar @argsarray) == 3) { 281 # Missing keys 282 %args = ( 283 old_name => $argsarray[0], 284 new_name => $argsarray[1], 285 create_new_versions => $argsarray[2] 286 ); 287 } 289 288 290 289 my @plugins = $self->get_registered_plugins; 291 290 $args{plugins} = \@plugins if scalar @plugins; 292 $args{wiki} = $self;291 $args{wiki} = $self; 293 292 294 293 my $ret = $self->store->rename_node( %args ); 295 294 296 if($ret && $ret == -1) { return $ret; } 297 return 1; 295 if ($ret && $ret == -1) { 296 return $ret; 297 } 298 return 1; 298 299 } 299 300 … … 450 451 my @nodes = $wiki->list_unmoderated_nodes(); 451 452 my @nodes = $wiki->list_unmoderated_nodes( 452 only_where_latest => 1453 );453 only_where_latest => 1 454 ); 454 455 455 456 $nodes[0]->{'name'} # The name of the node … … 502 503 503 504 =item B<list_last_version_before> 504 List the last version of every node before a given date.505 If no version existed before that date, will return undef for version.506 Returns a hash of id, name, version and date507 508 my @nv = $wiki->list_last_version_before('2007-01-02 10:34:11')509 foreach my $data (@nv) {510 511 }505 List the last version of every node before a given date. 506 If no version existed before that date, will return undef for version. 507 Returns a hash of id, name, version and date 508 509 my @nv = $wiki->list_last_version_before('2007-01-02 10:34:11') 510 foreach my $data (@nv) { 511 512 } 512 513 513 514 =cut … … 515 516 sub list_last_version_before { 516 517 my ($self,@argsarray) = @_; 517 518 518 return $self->store->list_last_version_before(@argsarray); 519 519 } … … 557 557 558 558 # Return false if it doesn't exist 559 unless(%node) { return 0; } 560 unless($node{node_requires_moderation}) { return 0; } 559 unless(%node) { 560 return 0; 561 } 562 unless($node{node_requires_moderation}) { 563 return 0; 564 } 561 565 562 566 # Otherwise return the state of the flag … … 587 591 588 592 my @plugins = $self->get_registered_plugins; 589 my $plugins_ref = \@plugins if scalar @plugins;593 my $plugins_ref = \@plugins if scalar @plugins; 590 594 591 595 return 1 unless $self->node_exists( $args{name} ); … … 604 608 if ( $new_current_content ) { 605 609 $search->index_node( $args{name}, $new_current_content ); 606 }610 } 607 611 } 608 612 … … 831 835 832 836 my %data = ( node => $node, 833 content => $content,834 checksum => $checksum,835 metadata => $metadata,836 requires_moderation => $requires_moderation );837 content => $content, 838 checksum => $checksum, 839 metadata => $metadata, 840 requires_moderation => $requires_moderation ); 837 841 $data{links_to} = \@links_to if scalar @links_to; 838 842 my @plugins = $self->get_registered_plugins; … … 841 845 my $store = $self->store; 842 846 my $ret = $store->check_and_write_node( %data ) or return 0; 843 if($ret == -1) { return -1; } 847 if($ret == -1) { 848 return -1; 849 } 844 850 845 851 my $search = $self->{_search}; … … 871 877 # see http://rt.cpan.org/NoAuth/Bug.html?id=7014 872 878 if ($CAN_USE_ENCODE) { 873 if (Encode::is_utf8($raw)) {874 Encode::_utf8_on( $result );875 }879 if (Encode::is_utf8($raw)) { 880 Encode::_utf8_on( $result ); 881 } 876 882 } 877 883 -
wiki-toolkit/trunk/lib/Wiki/Toolkit/Feed/Atom.pm
r425 r431 14 14 @ISA = qw( Wiki::Toolkit::Feed::Listing ); 15 15 16 sub new 17 { 18 my $class = shift; 19 my $self = {}; 20 bless $self, $class; 21 22 my %args = @_; 23 my $wiki = $args{wiki}; 24 25 unless ($wiki && UNIVERSAL::isa($wiki, 'Wiki::Toolkit')) 26 { 27 croak 'No Wiki::Toolkit object supplied'; 28 } 29 30 $self->{wiki} = $wiki; 31 32 # Mandatory arguments. 33 foreach my $arg (qw/site_name site_url make_node_url atom_link/) 34 { 35 croak "No $arg supplied" unless $args{$arg}; 36 $self->{$arg} = $args{$arg}; 37 } 38 39 # Must-supply-one-of arguments 40 my %mustoneof = ( 'html_equiv_link' => ['html_equiv_link','recent_changes_link'] ); 41 $self->handle_supply_one_of(\%mustoneof,\%args); 42 43 # Optional arguments. 44 foreach my $arg (qw/site_description software_name software_version software_homepage encoding/) 45 { 46 $self->{$arg} = $args{$arg} || ''; 47 } 48 49 # Supply some defaults, if a blank string isn't what we want 50 unless($self->{encoding}) { 51 $self->{encoding} = $self->{wiki}->store->{_charset}; 52 } 53 54 $self->{timestamp_fmt} = $Wiki::Toolkit::Store::Database::timestamp_fmt; 55 $self->{utc_offset} = strftime "%z", localtime; 56 $self->{utc_offset} =~ s/(..)(..)$/$1:$2/; 57 58 # Escape any &'s in the urls 59 foreach my $key qw(site_url atom_link) { 60 my @ands = ($self->{$key} =~ /(\&.{1,6})/g); 61 foreach my $and (@ands) { 62 if($and ne "&") { 63 my $new_and = $and; 64 $new_and =~ s/\&/\&/; 65 $self->{$key} =~ s/$and/$new_and/; 16 sub new { 17 my $class = shift; 18 my $self = {}; 19 bless $self, $class; 20 21 my %args = @_; 22 my $wiki = $args{wiki}; 23 24 unless ($wiki && UNIVERSAL::isa($wiki, 'Wiki::Toolkit')) { 25 croak 'No Wiki::Toolkit object supplied'; 26 } 27 28 $self->{wiki} = $wiki; 29 30 # Mandatory arguments. 31 foreach my $arg (qw/site_name site_url make_node_url atom_link/) { 32 croak "No $arg supplied" unless $args{$arg}; 33 $self->{$arg} = $args{$arg}; 34 } 35 36 # Must-supply-one-of arguments 37 my %mustoneof = ( 'html_equiv_link' => ['html_equiv_link','recent_changes_link'] ); 38 $self->handle_supply_one_of(\%mustoneof,\%args); 39 40 # Optional arguments. 41 foreach my $arg (qw/site_description software_name software_version software_homepage encoding/) { 42 $self->{$arg} = $args{$arg} || ''; 43 } 44 45 # Supply some defaults, if a blank string isn't what we want 46 unless($self->{encoding}) { 47 $self->{encoding} = $self->{wiki}->store->{_charset}; 48 } 49 50 $self->{timestamp_fmt} = $Wiki::Toolkit::Store::Database::timestamp_fmt; 51 $self->{utc_offset} = strftime "%z", localtime; 52 $self->{utc_offset} =~ s/(..)(..)$/$1:$2/; 53 54 # Escape any &'s in the urls 55 foreach my $key qw(site_url atom_link) { 56 my @ands = ($self->{$key} =~ /(\&.{1,6})/g); 57 foreach my $and (@ands) { 58 if($and ne "&") { 59 my $new_and = $and; 60 $new_and =~ s/\&/\&/; 61 $self->{$key} =~ s/$and/$new_and/; 62 } 66 63 } 67 } 68 } 69 70 $self; 64 } 65 66 $self; 71 67 } 72 68 … … 79 75 80 76 sub build_feed_start { 81 my ($self,$atom_timestamp) = @_; 82 83 my $generator = ''; 84 85 if ($self->{software_name}) 86 { 87 $generator = ' <generator'; 88 $generator .= ' uri="' . $self->{software_homepage} . '"' if $self->{software_homepage}; 89 $generator .= ' version=' . $self->{software_version} . '"' if $self->{software_version}; 90 $generator .= ">\n"; 91 $generator .= $self->{software_name} . "</generator>\n"; 92 } 93 94 my $subtitle = $self->{site_description} 77 my ($self,$atom_timestamp) = @_; 78 79 my $generator = ''; 80 81 if ($self->{software_name}) { 82 $generator = ' <generator'; 83 $generator .= ' uri="' . $self->{software_homepage} . '"' if $self->{software_homepage}; 84 $generator .= ' version=' . $self->{software_version} . '"' if $self->{software_version}; 85 $generator .= ">\n"; 86 $generator .= $self->{software_name} . "</generator>\n"; 87 } 88 89 my $subtitle = $self->{site_description} 95 90 ? '<subtitle>' . $self->{site_description} . "</subtitle>\n" 96 91 : ''; 97 92 98 $atom_timestamp ||= '';99 100 my $atom = qq{<?xml version="1.0" encoding="} . $self->{encoding} . qq{"?>93 $atom_timestamp ||= ''; 94 95 my $atom = qq{<?xml version="1.0" encoding="} . $self->{encoding} . qq{"?> 101 96 102 97 <feed … … 113 108 $subtitle}; 114 109 115 return $atom;110 return $atom; 116 111 } 117 112 … … 135 130 136 131 sub generate_node_list_feed { 137 my ($self,$atom_timestamp,@nodes) = @_; 138 139 my $atom = $self->build_feed_start($atom_timestamp); 140 141 my (@urls, @items); 142 143 foreach my $node (@nodes) 144 { 145 my $node_name = $node->{name}; 146 147 my $item_timestamp = $node->{last_modified}; 132 my ($self,$atom_timestamp,@nodes) = @_; 133 134 my $atom = $self->build_feed_start($atom_timestamp); 135 136 my (@urls, @items); 137 138 foreach my $node (@nodes) { 139 my $node_name = $node->{name}; 140 141 my $item_timestamp = $node->{last_modified}; 148 142 149 # Make a Time::Piece object.150 my $time = Time::Piece->strptime($item_timestamp, $self->{timestamp_fmt});151 152 my $utc_offset = $self->{utc_offset};143 # Make a Time::Piece object. 144 my $time = Time::Piece->strptime($item_timestamp, $self->{timestamp_fmt}); 145 146 my $utc_offset = $self->{utc_offset}; 153 147 154 $item_timestamp = $time->strftime( "%Y-%m-%dT%H:%M:%S$utc_offset" ); 155 156 my $author = $node->{metadata}{username}[0] || $node->{metadata}{host}[0] || 'Anonymous'; 157 my $description = $node->{metadata}{comment}[0] || 'No description given for node'; 158 159 $description .= " [$author]" if $author; 160 161 my $version = $node->{version}; 162 my $status = (1 == $version) ? 'new' : 'updated'; 163 164 my $major_change = $node->{metadata}{major_change}[0]; 165 $major_change = 1 unless defined $major_change; 166 my $importance = $major_change ? 'major' : 'minor'; 167 168 my $url = $self->{make_node_url}->($node_name, $version); 169 170 # make XML-clean 171 my $title = $node_name; 172 $title =~ s/&/&/g; 173 $title =~ s/</</g; 174 $title =~ s/>/>/g; 175 176 # Pop the categories into atom:category elements (4.2.2) 177 # We can do this because the spec says: 178 # "This specification assigns no meaning to the content (if any) 179 # of this element." 180 # TODO: Decide if we should include the "all categories listing" url 181 # as the scheme (URI) attribute? 182 my $category_atom = ""; 183 if($node->{metadata}->{category}) { 184 foreach my $cat (@{ $node->{metadata}->{category} }) { 185 $category_atom .= " <category term=\"$cat\" />\n"; 148 $item_timestamp = $time->strftime( "%Y-%m-%dT%H:%M:%S$utc_offset" ); 149 150 my $author = $node->{metadata}{username}[0] || $node->{metadata}{host}[0] || 'Anonymous'; 151 my $description = $node->{metadata}{comment}[0] || 'No description given for node'; 152 153 $description .= " [$author]" if $author; 154 155 my $version = $node->{version}; 156 my $status = (1 == $version) ? 'new' : 'updated'; 157 158 my $major_change = $node->{metadata}{major_change}[0]; 159 $major_change = 1 unless defined $major_change; 160 my $importance = $major_change ? 'major' : 'minor'; 161 162 my $url = $self->{make_node_url}->($node_name, $version); 163 164 # make XML-clean 165 my $title = $node_name; 166 $title =~ s/&/&/g; 167 $title =~ s/</</g; 168 $title =~ s/>/>/g; 169 170 # Pop the categories into atom:category elements (4.2.2) 171 # We can do this because the spec says: 172 # "This specification assigns no meaning to the content (if any) 173 # of this element." 174 # TODO: Decide if we should include the "all categories listing" url 175 # as the scheme (URI) attribute? 176 my $category_atom = ""; 177 if ($node->{metadata}->{category}) { 178 foreach my $cat (@{ $node->{metadata}->{category} }) { 179 $category_atom .= " <category term=\"$cat\" />\n"; 180 } 186 181 } 187 } 188 189 # Include geospacial data, if we have it 190 my $geo_atom = $self->format_geo($node->{metadata}); 191 192 # TODO: Find an Atom equivalent of ModWiki, so we can include more info 182 183 # Include geospacial data, if we have it 184 my $geo_atom = $self->format_geo($node->{metadata}); 185 186 # TODO: Find an Atom equivalent of ModWiki, so we can include more info 193 187 194 188 195 push @items, qq{189 push @items, qq{ 196 190 <entry> 197 191 <title>$title</title> … … 206 200 }; 207 201 208 }209 210 $atom .= join('', @items) . "\n";211 $atom .= $self->build_feed_end($atom_timestamp);212 213 return $atom;202 } 203 204 $atom .= join('', @items) . "\n"; 205 $atom .= $self->build_feed_end($atom_timestamp); 206 207 return $atom; 214 208 } 215 209 … … 224 218 225 219 sub generate_node_name_distance_feed { 226 my ($self,$atom_timestamp,@nodes) = @_; 227 228 my $atom = $self->build_feed_start($atom_timestamp); 229 230 my (@urls, @items); 231 232 foreach my $node (@nodes) 233 { 234 my $node_name = $node->{name}; 235 236 my $url = $self->{make_node_url}->($node_name); 237 238 # make XML-clean 239 my $title = $node_name; 240 $title =~ s/&/&/g; 241 $title =~ s/</</g; 242 $title =~ s/>/>/g; 243 244 # What location stuff do we have? 245 my $geo_atom = $self->format_geo($node); 246 247 push @items, qq{ 220 my ($self,$atom_timestamp,@nodes) = @_; 221 222 my $atom = $self->build_feed_start($atom_timestamp); 223 224 my (@urls, @items); 225 226 foreach my $node (@nodes) { 227 my $node_name = $node->{name}; 228 229 my $url = $self->{make_node_url}->($node_name); 230 231 # make XML-clean 232 my $title = $node_name; 233 $title =~ s/&/&/g; 234 $title =~ s/</</g; 235 $title =~ s/>/>/g; 236 237 # What location stuff do we have? 238 my $geo_atom = $self->format_geo($node); 239 240 push @items, qq{ 248 241 <entry> 249 242 <title>$title</title> … … 254 247 }; 255 248 256 }257 258 $atom .= join('', @items) . "\n";259 $atom .= $self->build_feed_end($atom_timestamp);260 261 return $atom;249 } 250 251 $atom .= join('', @items) . "\n"; 252 $atom .= $self->build_feed_end($atom_timestamp); 253 254 return $atom; 262 255 } 263 256 … … 269 262 =cut 270 263 271 sub feed_timestamp 272 { 273 my ($self, $newest_node) = @_; 274 275 my $time; 276 if ($newest_node->{last_modified}) 277 { 278 $time = Time::Piece->strptime( $newest_node->{last_modified}, $self->{timestamp_fmt} ); 279 } else { 280 $time = localtime; 281 } 282 283 my $utc_offset = $self->{utc_offset}; 264 sub feed_timestamp { 265 my ($self, $newest_node) = @_; 266 267 my $time; 268 if ($newest_node->{last_modified}) { 269 $time = Time::Piece->strptime( $newest_node->{last_modified}, $self->{timestamp_fmt} ); 270 } else { 271 $time = localtime; 272 } 273 274 my $utc_offset = $self->{utc_offset}; 284 275 285 return $time->strftime( "%Y-%m-%dT%H:%M:%S$utc_offset" );276 return $time->strftime( "%Y-%m-%dT%H:%M:%S$utc_offset" ); 286 277 } 287 278 … … 416 407 'About This Wiki', 417 408 'blah blah blah', 418 $checksum,419 {420 comment => 'Stub page, please update!',421 username => 'Fred',422 }409 $checksum, 410 { 411 comment => 'Stub page, please update!', 412 username => 'Fred', 413 } 423 414 ); 424 415 -
wiki-toolkit/trunk/lib/Wiki/Toolkit/Feed/Listing.pm
r424 r431 103 103 =cut 104 104 105 sub recent_changes 106 { 105 sub recent_changes { 107 106 my ($self, %args) = @_; 108 107 … … 114 113 my $feed = $self->generate_node_list_feed($feed_timestamp, @changes); 115 114 116 if ($args{'also_return_timestamp'}) {115 if ($args{'also_return_timestamp'}) { 117 116 return ($feed,$feed_timestamp); 118 117 } else { … … 131 130 =cut 132 131 133 sub node_all_versions 134 { 132 sub node_all_versions { 135 133 my ($self, %args) = @_; 136 134 -
wiki-toolkit/trunk/lib/Wiki/Toolkit/Feed/RSS.pm
r425 r431 14 14 @ISA = qw( Wiki::Toolkit::Feed::Listing ); 15 15 16 sub new 17 { 16 sub new { 18 17 my $class = shift; 19 18 my $self = {}; … … 23 22 my $wiki = $args{wiki}; 24 23 25 unless ($wiki && UNIVERSAL::isa($wiki, 'Wiki::Toolkit')) 26 { 24 unless ($wiki && UNIVERSAL::isa($wiki, 'Wiki::Toolkit')) { 27 25 croak 'No Wiki::Toolkit object supplied'; 28 26 } … … 31 29 32 30 # Mandatory arguments. 33 foreach my $arg (qw/site_name site_url make_node_url/) 34 { 31 foreach my $arg (qw/site_name site_url make_node_url/) { 35 32 croak "No $arg supplied" unless $args{$arg}; 36 33 $self->{$arg} = $args{$arg}; … … 42 39 43 40 # Optional arguments. 44 foreach my $arg (qw/site_description interwiki_identifier make_diff_url make_history_url encoding 45 software_name software_version software_homepage/) 46 { 41 foreach my $arg (qw/site_description interwiki_identifier make_diff_url make_history_url encoding software_name software_version software_homepage/) { 47 42 $self->{$arg} = $args{$arg} || ''; 48 43 } … … 68 63 69 64 sub build_feed_start { 70 my ($self,$feed_timestamp) = @_;71 72 #"http://purl.org/rss/1.0/modules/wiki/"73 return qq{<?xml version="1.0" encoding="}. $self->{encoding} .qq{"?>65 my ($self,$feed_timestamp) = @_; 66 67 #"http://purl.org/rss/1.0/modules/wiki/" 68 return qq{<?xml version="1.0" encoding="}. $self->{encoding} .qq{"?> 74 69 75 70 <rdf:RDF … … 98 93 my $rss .= qq{<dc:publisher>} . $self->{site_url} . qq{</dc:publisher>\n}; 99 94 100 if ($self->{software_name}) 101 { 102 $rss .= qq{<foaf:maker> 103 <doap:Project> 104 <doap:name>} . $self->{software_name} . qq{</doap:name>\n}; 105 } 106 107 if ($self->{software_name} && $self->{software_homepage}) 108 { 109 $rss .= qq{ <doap:homepage rdf:resource="} . $self->{software_homepage} . qq{" />\n}; 110 } 111 112 if ($self->{software_name} && $self->{software_version}) 113 { 114 $rss .= qq{ <doap:release> 95 if ($self->{software_name}) { 96 $rss .= qq{<foaf:maker> 97 <doap:Project> 98 <doap:name>} . $self->{software_name} . qq{</doap:name>\n}; 99 } 100 101 if ($self->{software_name} && $self->{software_homepage}) { 102 $rss .= qq{ <doap:homepage rdf:resource="} . $self->{software_homepage} . qq{" />\n}; 103 } 104 105 if ($self->{software_name} && $self->{software_version}) { 106 $rss .= qq{ <doap:release> 115 107 <doap:Version> 116 <doap:revision>} . $self->{software_version} . qq{</doap:revision>108 <doap:revision>} . $self->{software_version} . qq{</doap:revision> 117 109 </doap:Version> 118 110 </doap:release>\n}; 119 } 120 121 if ($self->{software_name}) 122 { 123 $rss .= qq{ </doap:Project> 111 } 112 113 if ($self->{software_name}) { 114 $rss .= qq{ </doap:Project> 124 115 </foaf:maker>\n}; 125 }126 127 $feed_timestamp ||= '';128 129 $rss .= qq{<title>} . $self->{site_name} . qq{</title>116 } 117 118 $feed_timestamp ||= ''; 119 120 $rss .= qq{<title>} . $self->{site_name} . qq{</title> 130 121 <link>} . $self->{html_equiv_link} . qq{</link> 131 122 <description>} . $self->{site_description} . qq{</description> … … 156 147 157 148 sub generate_node_list_feed { 158 my ($self,$feed_timestamp,@nodes) = @_;159 160 # Start our feed161 my $rss = $self->build_feed_start($feed_timestamp);162 $rss .= qq{149 my ($self,$feed_timestamp,@nodes) = @_; 150 151 # Start our feed 152 my $rss = $self->build_feed_start($feed_timestamp); 153 $rss .= qq{ 163 154 164 155 <channel rdf:about=""> 165 156 166 157 }; 167 $rss .= $self->build_feed_mid($feed_timestamp); 168 169 # Generate the items list, and the individiual item entries 170 my (@urls, @items); 171 foreach my $node (@nodes) 172 { 173 my $node_name = $node->{name}; 174 175 my $timestamp = $node->{last_modified}; 158 $rss .= $self->build_feed_mid($feed_timestamp); 159 160 # Generate the items list, and the individiual item entries 161 my (@urls, @items); 162 foreach my $node (@nodes) { 163 my $node_name = $node->{name}; 164 165 my $timestamp = $node->{last_modified}; 176 166 177 # Make a Time::Piece object.178 my $time = Time::Piece->strptime($timestamp, $self->{timestamp_fmt});179 180 my $utc_offset = $self->{utc_offset};167 # Make a Time::Piece object. 168 my $time = Time::Piece->strptime($timestamp, $self->{timestamp_fmt}); 169 170 my $utc_offset = $self->{utc_offset}; 181 171 182 $timestamp = $time->strftime( "%Y-%m-%dT%H:%M:%S$utc_offset" );183 184 my $author = $node->{metadata}{username}[0] || $node->{metadata}{host}[0] || '';185 my $description = $node->{metadata}{comment}[0] || '';186 187 $description .= " [$author]" if $author;188 189 my $version = $node->{version};190 my $status = (1 == $version) ? 'new' : 'updated';191 192 my $major_change = $node->{metadata}{major_change}[0];193 $major_change = 1 unless defined $major_change;194 my $importance = $major_change ? 'major' : 'minor';195 196 my $url = $self->{make_node_url}->($node_name, $version);197 198 push @urls, qq{ <rdf:li rdf:resource="$url" />\n};199 200 my $diff_url = '';172 $timestamp = $time->strftime( "%Y-%m-%dT%H:%M:%S$utc_offset" ); 173 174 my $author = $node->{metadata}{username}[0] || $node->{metadata}{host}[0] || ''; 175 my $description = $node->{metadata}{comment}[0] || ''; 176 177 $description .= " [$author]" if $author; 178 179 my $version = $node->{version}; 180 my $status = (1 == $version) ? 'new' : 'updated'; 181 182 my $major_change = $node->{metadata}{major_change}[0]; 183 $major_change = 1 unless defined $major_change; 184 my $importance = $major_change ? 'major' : 'minor'; 185 186 my $url = $self->{make_node_url}->($node_name, $version); 187 188 push @urls, qq{ <rdf:li rdf:resource="$url" />\n}; 189 190 my $diff_url = ''; 201 191 202 if ($self->{make_diff_url}) 203 { 204 $diff_url = $self->{make_diff_url}->($node_name); 205 } 206 207 my $history_url = ''; 192 if ($self->{make_diff_url}) { 193 $diff_url = $self->{make_diff_url}->($node_name); 194 } 195 196 my $history_url = ''; 208 197 209 if ($self->{make_history_url}) 210 { 211 $history_url = $self->{make_history_url}->($node_name); 212 } 213 214 my $node_url = $self->{make_node_url}->($node_name); 215 216 my $rdf_url = $node_url; 217 $rdf_url =~ s/\?/\?id=/; 218 $rdf_url .= ';format=rdf'; 219 220 # make XML-clean 221 my $title = $node_name; 222 $title =~ s/&/&/g; 223 $title =~ s/</</g; 224 $title =~ s/>/>/g; 225 226 # Pop the categories into dublin core subject elements 227 # (http://dublincore.org/usage/terms/history/#subject-004) 228 # TODO: Decide if we should include the "all categories listing" url 229 # as the scheme (URI) attribute? 230 my $category_rss = ""; 231 if($node->{metadata}->{category}) { 232 foreach my $cat (@{ $node->{metadata}->{category} }) { 233 $category_rss .= " <dc:subject>$cat</dc:subject>\n"; 198 if ($self->{make_history_url}) { 199 $history_url = $self->{make_history_url}->($node_name); 234 200 } 235 } 236 237 # Include geospacial data, if we have it 238 my $geo_rss = $self->format_geo($node->{metadata}); 239 240 push @items, qq{ 201 202 my $node_url = $self->{make_node_url}->($node_name); 203 204 my $rdf_url = $node_url; 205 $rdf_url =~ s/\?/\?id=/; 206 $rdf_url .= ';format=rdf'; 207 208 # make XML-clean 209 my $title = $node_name; 210 $title =~ s/&/&/g; 211 $title =~ s/</</g; 212 $title =~ s/>/>/g; 213 214 # Pop the categories into dublin core subject elements 215 # (http://dublincore.org/usage/terms/history/#subject-004) 216 # TODO: Decide if we should include the "all categories listing" url 217 # as the scheme (URI) attribute? 218 my $category_rss = ""; 219 if($node->{metadata}->{category}) { 220 foreach my $cat (@{ $node->{metadata}->{category} }) { 221 $category_rss .= " <dc:subject>$cat</dc:subject>\n"; 222 } 223 } 224 225 # Include geospacial data, if we have it 226 my $geo_rss = $self->format_geo($node->{metadata}); 227 228 push @items, qq{ 241 229 <item rdf:about="$url"> 242 230 <title>$title</title> … … 255 243 </item> 256 244 }; 257 }245 } 258 246 259 # Output the items list260 $rss .= qq{247 # Output the items list 248 $rss .= qq{ 261 249 262 250 <items> … … 268 256 }; 269 257 270 # Output the individual item entries271 $rss .= join('', @items) . "\n";272 273 # Finish up274 $rss .= $self->build_feed_end($feed_timestamp);258 # Output the individual item entries 259 $rss .= join('', @items) . "\n"; 260 261 # Finish up 262 $rss .= $self->build_feed_end($feed_timestamp); 275 263 276 return $rss;264 return $rss; 277 265 } 278 266 … … 288 276 289 277 sub generate_node_name_distance_feed { 290 my ($self,$feed_timestamp,@nodes) = @_;291 292 # Start our feed293 my $rss = $self->build_feed_start($feed_timestamp);294 $rss .= qq{278 my ($self,$feed_timestamp,@nodes) = @_; 279 280 # Start our feed 281 my $rss = $self->build_feed_start($feed_timestamp); 282 $rss .= qq{ 295 283 296 284 <channel rdf:about=""> 297 285 298 286 }; 299 $rss .= $self->build_feed_mid($feed_timestamp); 300 301 # Generate the items list, and the individiual item entries 302 my (@urls, @items); 303 foreach my $node (@nodes) 304 { 305 my $node_name = $node->{name}; 306 307 my $url = $self->{make_node_url}->($node_name); 308 309 push @urls, qq{ <rdf:li rdf:resource="$url" />\n}; 310 311 my $rdf_url = $url; 312 $rdf_url =~ s/\?/\?id=/; 313 $rdf_url .= ';format=rdf'; 314 315 # make XML-clean 316 my $title = $node_name; 317 $title =~ s/&/&/g; 318 $title =~ s/</</g; 319 $title =~ s/>/>/g; 320 321 # What location stuff do we have? 322 my $geo_rss = $self->format_geo($node); 323 324 push @items, qq{ 287 $rss .= $self->build_feed_mid($feed_timestamp); 288 289 # Generate the items list, and the individiual item entries 290 my (@urls, @items); 291 foreach my $node (@nodes) { 292 my $node_name = $node->{name}; 293 294 my $url = $self->{make_node_url}->($node_name); 295 296 push @urls, qq{ <rdf:li rdf:resource="$url" />\n}; 297 298 my $rdf_url = $url; 299 $rdf_url =~ s/\?/\?id=/; 300 $rdf_url .= ';format=rdf'; 301 302 # make XML-clean 303 my $title = $node_name; 304 $title =~ s/&/&/g; 305 $title =~ s/</</g; 306 $title =~ s/>/>/g; 307 308 # What location stuff do we have? 309 my $geo_rss = $self->format_geo($node); 310 311 push @items, qq{ 325 312 <item rdf:about="$url"> 326 313 <title>$title</title> … … 330 317 </item> 331 318 }; 332 }319 } 333 320 334 # Output the items list335 $rss .= qq{321 # Output the items list 322 $rss .= qq{ 336 323 337 324 <items> … … 343 330 }; 344 331 345 # Output the individual item entries346 $rss .= join('', @items) . "\n";347 348 # Finish up349 $rss .= $self->build_feed_end($feed_timestamp);332 # Output the individual item entries 333 $rss .= join('', @items) . "\n"; 334 335 # Finish up 336 $rss .= $self->build_feed_end($feed_timestamp); 350 337 351 return $rss;338 return $rss; 352 339 } 353 340 … … 363 350 364 351 my $time; 365 if ($newest_node->{last_modified}) 366 { 352 if ($newest_node->{last_modified}) { 367 353 $time = Time::Piece->strptime( $newest_node->{last_modified}, $self->{timestamp_fmt} ); 368 354 } else { … … 522 508 'About This Wiki', 523 509 'blah blah blah', 524 $checksum,525 {526 comment => 'Stub page, please update!',527 username => 'Fred',528 }510 $checksum, 511 { 512 comment => 'Stub page, please update!', 513 username => 'Fred', 514 } 529 515 ); 530 516 -
wiki-toolkit/trunk/lib/Wiki/Toolkit/Formatter/Default.pm
r244 r431 29 29 my $formatter = Wiki::Toolkit::Formatter::Default->new( %config ); 30 30 my $wiki = Wiki::Toolkit->new( store => $store, 31 formatter => $formatter );31 formatter => $formatter ); 32 32 33 33 =head1 METHODS … … 42 42 allowed_tags => [qw(b i)], # defaults to none 43 43 macros => {}, 44 node_prefix => 'wiki.cgi?node=' );44 node_prefix => 'wiki.cgi?node=' ); 45 45 46 46 Parameters will default to the values shown above (apart from … … 58 58 59 59 macros => { qr/(^|\b)\@SEARCHBOX(\b|$)/ => 60 qq(<form action="wiki.cgi" method="get">60 qq(<form action="wiki.cgi" method="get"> 61 61 <input type="hidden" name="action" value="search"> 62 62 <input type="text" size="20" name="terms"> … … 78 78 # Store the parameters or their defaults. 79 79 my %defs = ( extended_links => 0, 80 implicit_links => 1,81 allowed_tags => [],82 macros => {},83 node_prefix => 'wiki.cgi?node=',84 );80 implicit_links => 1, 81 allowed_tags => [], 82 macros => {}, 83 node_prefix => 'wiki.cgi?node=', 84 ); 85 85 86 86 my %collated = (%defs, %args); … … 111 111 if (scalar keys %allowed) { 112 112 # If we are allowing some HTML, parse and get rid of the nasties. 113 my $parser = HTML::PullParser->new(doc => $raw,114 start => '"TAG", tag, text',115 end => '"TAG", tag, text',116 text => '"TEXT", tag, text');117 while (my $token = $parser->get_token) {113 my $parser = HTML::PullParser->new(doc => $raw, 114 start => '"TAG", tag, text', 115 end => '"TAG", tag, text', 116 text => '"TEXT", tag, text'); 117 while (my $token = $parser->get_token) { 118 118 my ($flag, $tag, $text) = @$token; 119 if ($flag eq "TAG" and !defined $allowed{lc($tag)}) {120 $safe .= CGI::escapeHTML($text);121 } else {119 if ($flag eq "TAG" and !defined $allowed{lc($tag)}) { 120 $safe .= CGI::escapeHTML($text); 121 } else { 122 122 $safe .= $text; 123 123 } … … 135 135 136 136 return wikiformat($safe, {}, 137 { extended => $self->{_extended_links},138 prefix => $self->{_node_prefix},139 implicit_links => $self->{_implicit_links} } );137 { extended => $self->{_extended_links}, 138 prefix => $self->{_node_prefix}, 139 implicit_links => $self->{_implicit_links} } ); 140 140 } 141 141 -
wiki-toolkit/trunk/lib/Wiki/Toolkit/Formatter/Multiple.pm
r236 r431 37 37 38 38 my $wiki = Wiki::Toolkit->new( store => ..., 39 formatter => $formatter );39 formatter => $formatter ); 40 40 my $output = $wiki->format( "This is some discussion.", 41 41 { formatter => "discussion" } ); … … 115 115 116 116 sub _formatter { 117 my $self = shift;118 my $metadata = shift;119 my $label = $metadata->{formatter} || "_DEFAULT";120 $label = $label->[0] if ref($label);121 return $self->{formatters}{$label} || $self->{formatters}{_DEFAULT};117 my $self = shift; 118 my $metadata = shift; 119 my $label = $metadata->{formatter} || "_DEFAULT"; 120 $label = $label->[0] if ref($label); 121 return $self->{formatters}{$label} || $self->{formatters}{_DEFAULT}; 122 122 } 123 123 -
wiki-toolkit/trunk/lib/Wiki/Toolkit/Formatter/WikiLinkFormatterParent.pm
r349 r431 40 40 my ($self, $from, $to, $content) = @_; 41 41 42 # If we support extended (square bracket) links, update those43 if($self->{_extended_links}) {44 $content =~ s/\[$from\]/\[$to\]/g;45 $content =~ s/\[$from(\s*|.*?)\]/\[$to$1\]/g;46 }42 # If we support extended (square bracket) links, update those 43 if($self->{_extended_links}) { 44 $content =~ s/\[$from\]/\[$to\]/g; 45 $content =~ s/\[$from(\s*|.*?)\]/\[$to$1\]/g; 46 } 47 47 48 # If we support implicit (camelcase) links, update those49 if($self->{_implicit_links}) {50 $content =~ s/\b$from\b/$to/g;51 $content =~ s/^$from\b/$to/gm;52 $content =~ s/\b$from$/$to/gm;53 }48 # If we support implicit (camelcase) links, update those 49 if($self->{_implicit_links}) { 50 $content =~ s/\b$from\b/$to/g; 51 $content =~ s/^$from\b/$to/gm; 52 $content =~ s/\b$from$/$to/gm; 53 } 54 54 55 return $content;55 return $content; 56 56 } 57 57 … … 72 72 73 73 my $foo = wikiformat($raw, 74 { link => sub {75 my ($link, $opts) = @_;76 $opts ||= {};77 my $title;78 ($link, $title) = split(/\|/, $link, 2)79 if $opts->{extended};80 push @Wiki::Toolkit::Formatter::WikiLinkFormatterParent::_links_found,81 $link;82 return ""; # don't care about output83 }84 },85 {86 extended => $self->{_extended_links},87 prefix => $self->{_node_prefix},88 implicit_links => $self->{_implicit_links}89 }90 );74 { link => sub { 75 my ($link, $opts) = @_; 76 $opts ||= {}; 77 my $title; 78 ($link, $title) = split(/\|/, $link, 2) 79 if $opts->{extended}; 80 push @Wiki::Toolkit::Formatter::WikiLinkFormatterParent::_links_found, 81 $link; 82 return ""; # don't care about output 83 } 84 }, 85 { 86 extended => $self->{_extended_links}, 87 prefix => $self->{_node_prefix}, 88 implicit_links => $self->{_implicit_links} 89 } 90 ); 91 91 92 92 my @links = @_links_found; -
wiki-toolkit/trunk/lib/Wiki/Toolkit/Search/Base.pm
r209 r431 9 9 my $who = (caller(1))[3]; 10 10 croak "$who is an abstract method which the ".(ref shift). 11 " class has not provided";11 " class has not provided"; 12 12 } 13 13 … … 99 99 my ($self, $string) = @_; 100 100 return grep { length > 1 # ignore single characters 101 and ! /^\W*$/ }# and things composed entirely102 # of non-word characters103 split( /\b/,# split at word boundaries101 and ! /^\W*$/ } # and things composed entirely 102 # of non-word characters 103 split( /\b/, # split at word boundaries 104 104 lc($string) # be case-insensitive 105 );105 ); 106 106 } 107 107 -
wiki-toolkit/trunk/lib/Wiki/Toolkit/Search/Plucene.pm
r209 r431 54 54 my ($self, $query, $default) = @_; 55 55 my $parser = Plucene::QueryParser->new({ 56 analyzer => Plucene::Analysis::SimpleAnalyzer->new(),56 analyzer => Plucene::Analysis::SimpleAnalyzer->new(), 57 57 default => $default 58 58 }); … … 77 77 return Plucene::Index::Writer->new( 78 78 $self->_dir, 79 Plucene::Analysis::SimpleAnalyzer->new,79 Plucene::Analysis::SimpleAnalyzer->new, 80 80 -e catfile($self->_dir, "segments") ? 0 : 1 81 81 ); … … 89 89 } 90 90 local $Plucene::QueryParser::DefaultOperator = "AND" 91 unless ( $and_or and lc($and_or) eq "or" );91 unless ( $and_or and lc($and_or) eq "or" ); 92 92 my @docs; 93 93 my $searcher = $self->_searcher; … … 118 118 119 119 sub index_node { 120 my ($self, $node, $content) = @_;121 my $writer = $self->_writer;122 my $doc = Plucene::Document->new;123 my $fuzzy = $self->canonicalise_title( $node );124 $doc->add( Plucene::Document::Field->Text( "content", join( " ", $node, $content ) ) );125 $doc->add( Plucene::Document::Field->Text( "fuzzy", $fuzzy ) );126 $doc->add( Plucene::Document::Field->Text( "title", $node ) );127 $doc->add(Plucene::Document::Field->Keyword(id => $node));128 $doc->add(Plucene::Document::Field->UnStored('text' => join( " ", $node, $content )));129 $writer->add_document($doc);120 my ($self, $node, $content) = @_; 121 my $writer = $self->_writer; 122 my $doc = Plucene::Document->new; 123 my $fuzzy = $self->canonicalise_title( $node ); 124 $doc->add( Plucene::Document::Field->Text( "content", join( " ", $node, $content ) ) ); 125 $doc->add( Plucene::Document::Field->Text( "fuzzy", $fuzzy ) ); 126 $doc->add( Plucene::Document::Field->Text( "title", $node ) ); 127 $doc->add(Plucene::Document::Field->Keyword(id => $node)); 128 $doc->add(Plucene::Document::Field->UnStored('text' => join( " ", $node, $content ))); 129 $writer->add_document($doc); 130 130 } 131 131 … … 133 133 134 134 sub indexed { 135 my ($self, $id) = @_;136 my $term = Plucene::Index::Term->new({ field => 'id', text => $id });137 return $self->_reader->doc_freq($term);135 my ($self, $id) = @_; 136 my $term = Plucene::Index::Term->new({ field => 'id', text => $id }); 137 return $self->_reader->doc_freq($term); 138 138 } 139 139 140 140 sub delete_node { 141 my ($self, $id) = @_;142 my $reader = $self->_reader;143 $reader->delete_term(144 Plucene::Index::Term->new({ field => "id", text => $id }));145 $reader->close;141 my ($self, $id) = @_; 142 my $reader = $self->_reader; 143 $reader->delete_term( 144 Plucene::Index::Term->new({ field => "id", text => $id })); 145 $reader->close; 146 146 } 147 147 -
wiki-toolkit/trunk/lib/Wiki/Toolkit/Search/SII.pm
r209 r431 38 38 -username => $dbuser, 39 39 -password => $dbpass, 40 -hostname => '',40 -hostname => '', 41 41 -table_name => 'siindex', 42 42 -lock_mode => 'EX' ); … … 62 62 63 63 my $map = Search::InvertedIndex->new( -database => $indexdb ) 64 or croak "Couldn't set up Search::InvertedIndex map";64 or croak "Couldn't set up Search::InvertedIndex map"; 65 65 $map->add_group( -group => "nodes" ); 66 66 $map->add_group( -group => "fuzzy_titles" ); … … 93 93 for my $i ( 1 .. $num_results ) { 94 94 my ($index, $data, $ranking) = $result->entry( -number => $i - 1 ); 95 $results{$index} = $ranking;95 $results{$index} = $ranking; 96 96 } 97 97 return %results; … … 112 112 for my $i ( 1 .. $num_results ) { 113 113 my ($index, $data) = $result->entry( -number => $i - 1 ); 114 $results{$data} = $data eq $string ? 2 : 1;114 $results{$data} = $data eq $string ? 2 : 1; 115 115 } 116 116 return %results; -
wiki-toolkit/trunk/lib/Wiki/Toolkit/Setup/DBIxFTSMySQL.pm
r209 r431 37 37 38 38 sub setup { 39 my $dbh = _get_dbh( @_ );39 my $dbh = _get_dbh( @_ ); 40 40 41 # Drop FTS indexes if they already exist.42 my $fts = DBIx::FullTextSearch->open($dbh, "_content_and_title_fts");43 $fts->drop if $fts;44 $fts = DBIx::FullTextSearch->open($dbh, "_title_fts");45 $fts->drop if $fts;41 # Drop FTS indexes if they already exist. 42 my $fts = DBIx::FullTextSearch->open($dbh, "_content_and_title_fts"); 43 $fts->drop if $fts; 44 $fts = DBIx::FullTextSearch->open($dbh, "_title_fts"); 45 $fts->drop if $fts; 46 46 47 # Set up FullText indexes and index anything already extant.48 my $fts_all = DBIx::FullTextSearch->create($dbh, "_content_and_title_fts",49 frontend => "table",50 backend => "phrase",51 table_name => "node",52 column_name => ["name","text"],53 column_id_name => "name",54 stemmer => "en-uk");47 # Set up FullText indexes and index anything already extant. 48 my $fts_all = DBIx::FullTextSearch->create($dbh, "_content_and_title_fts", 49 frontend => "table", 50 backend => "phrase", 51 table_name => "node", 52 column_name => ["name","text"], 53 column_id_name => "name", 54 stemmer => "en-uk"); 55 55 56 my $fts_title = DBIx::FullTextSearch->create($dbh, "_title_fts",57 frontend => "table",58 backend => "phrase",59 table_name => "node",60 column_name => "name",61 column_id_name => "name",62 stemmer => "en-uk");56 my $fts_title = DBIx::FullTextSearch->create($dbh, "_title_fts", 57 frontend => "table", 58 backend => "phrase", 59 table_name => "node", 60 column_name => "name", 61 column_id_name => "name", 62 stemmer => "en-uk"); 63 63 64 my $sql = "SELECT name FROM node";65 my $sth = $dbh->prepare($sql);66 $sth->execute();67 while (my ($name, $version) = $sth->fetchrow_array) {68 $fts_title->index_document($name);69 $fts_all->index_document($name);70 }71 $sth->finish;64 my $sql = "SELECT name FROM node"; 65 my $sth = $dbh->prepare($sql); 66 $sth->execute(); 67 while (my ($name, $version) = $sth->fetchrow_array) { 68 $fts_title->index_document($name); 69 $fts_all->index_document($name); 70 } 71 $sth->finish; 72 72 } 73 73 … … 78 78 $dsn .= ";host=$dbhost" if $dbhost; 79 79 my $dbh = DBI->connect($dsn, $dbuser, $dbpass, 80 { PrintError => 1, RaiseError => 1,81 AutoCommit => 1 } )82 or croak DBI::errstr;80 { PrintError => 1, RaiseError => 1, 81 AutoCommit => 1 } ) 82 or croak DBI::errstr; 83 83 return $dbh; 84 84 } -
wiki-toolkit/trunk/lib/Wiki/Toolkit/Setup/Database.pm
r424 r431 16 16 # Fetch from the old style database, ready for an upgrade to db version 8 17 17 sub fetch_upgrade_old_to_8 { 18 # Compatible with old_to_919 fetch_upgrade_old_to_9(@_);18 # Compatible with old_to_9 19 fetch_upgrade_old_to_9(@_); 20 20 } 21 21 22 22 # Fetch from the old style database, ready for an upgrade to db version 9 23 23 sub fetch_upgrade_old_to_9 { 24 my $dbh = shift;25 my %nodes;26 my %metadatas;27 my %contents;28 my @internal_links;29 my %ids;30 31 print "Grabbing and upgrading old data... ";32 33 # Grab all the nodes, and give them an ID34 my $sth = $dbh->prepare("SELECT name,version,text,modified FROM node");35 $sth->execute;36 my $id = 0;37 while( my($name,$version,$text,$modified) = $sth->fetchrow_array) {38 my %node;39 $id++;40 $node{'name'} = $name;41 $node{'version'} = $version;42 $node{'text'} = $text;43 $node{'modified'} = $modified;44 $node{'id'} = $id;45 $node{'moderate'} = 0;46 $nodes{$name} = \%node;47 $ids{$name} = $id;48 }49 print " read $id nodes... ";50 51 # Grab all the content, and upgrade to ID from name52 $sth = $dbh->prepare("SELECT name,version,text,modified,comment FROM content");53 $sth->execute;54 while ( my($name,$version,$text,$modified,$comment) = $sth->fetchrow_array) {55 my $id = $ids{$name};56 if($id) {57 my %content;58 $content{'node_id'} = $id;59 $content{'version'} = $version;60 $content{'text'} = $text;61 $content{'modified'} = $modified;62 $content{'comment'} = $comment;63 $content{'moderated'} = 1;64 $contents{$id."-".$version} = \%content;65 } else {66 warn("There was no node entry for content with name '$name', unable to migrate it!");67 }68 }69 print " read ".(scalar keys %contents)." contents... ";70 71 # Grab all the metadata, and upgrade to ID from node72 $sth = $dbh->prepare("SELECT node,version,metadata_type,metadata_value FROM metadata");73 $sth->execute;74 my $i = 0;75 while( my($node,$version,$metadata_type,$metadata_value) = $sth->fetchrow_array) {76 my $id = $ids{$node};77 if($id) {78 my %metadata;79 $metadata{'node_id'} = $id;80 $metadata{'version'} = $version;81 $metadata{'metadata_type'} = $metadata_type;82 $metadata{'metadata_value'} = $metadata_value;83 $metadatas{$id."-".($i++)} = \%metadata;84 } else {85 warn("There was no node entry for metadata with name (node) '$node', unable to migrate it!");86 }87 }88 89 # Grab all the internal links90 $sth = $dbh->prepare("SELECT link_from,link_to FROM internal_links");91 $sth->execute;92 while( my($link_from,$link_to) = $sth->fetchrow_array) {93 my %il;94 $il{'link_from'} = $link_from;95 $il{'link_to'} = $link_to;96 push @internal_links, \%il;97 }98 99 print "done\n";100 101 # Return it all102 return (\%nodes,\%contents,\%metadatas,\@internal_links,\%ids);24 my $dbh = shift; 25 my %nodes; 26 my %metadatas; 27 my %contents; 28 my @internal_links; 29 my %ids; 30 31 print "Grabbing and upgrading old data... "; 32 33 # Grab all the nodes, and give them an ID 34 my $sth = $dbh->prepare("SELECT name,version,text,modified FROM node"); 35 $sth->execute; 36 my $id = 0; 37 while( my($name,$version,$text,$modified) = $sth->fetchrow_array) { 38 my %node; 39 $id++; 40 $node{'name'} = $name; 41 $node{'version'} = $version; 42 $node{'text'} = $text; 43 $node{'modified'} = $modified; 44 $node{'id'} = $id; 45 $node{'moderate'} = 0; 46 $nodes{$name} = \%node; 47 $ids{$name} = $id; 48 } 49 print " read $id nodes... "; 50 51 # Grab all the content, and upgrade to ID from name 52 $sth = $dbh->prepare("SELECT name,version,text,modified,comment FROM content"); 53 $sth->execute; 54 while ( my($name,$version,$text,$modified,$comment) = $sth->fetchrow_array) { 55 my $id = $ids{$name}; 56 if($id) { 57 my %content; 58 $content{'node_id'} = $id; 59 $content{'version'} = $version; 60 $content{'text'} = $text; 61 $content{'modified'} = $modified; 62 $content{'comment'} = $comment; 63 $content{'moderated'} = 1; 64 $contents{$id."-".$version} = \%content; 65 } else { 66 warn("There was no node entry for content with name '$name', unable to migrate it!"); 67 } 68 } 69 print " read ".(scalar keys %contents)." contents... "; 70 71 # Grab all the metadata, and upgrade to ID from node 72 $sth = $dbh->prepare("SELECT node,version,metadata_type,metadata_value FROM metadata"); 73 $sth->execute; 74 my $i = 0; 75 while( my($node,$version,$metadata_type,$metadata_value) = $sth->fetchrow_array) { 76 my $id = $ids{$node}; 77 if($id) { 78 my %metadata; 79 $metadata{'node_id'} = $id; 80 $metadata{'version'} = $version; 81 $metadata{'metadata_type'} = $metadata_type; 82 $metadata{'metadata_value'} = $metadata_value; 83 $metadatas{$id."-".($i++)} = \%metadata; 84 } else { 85 warn("There was no node entry for metadata with name (node) '$node', unable to migrate it!"); 86 } 87 } 88 89 # Grab all the internal links 90 $sth = $dbh->prepare("SELECT link_from,link_to FROM internal_links"); 91 $sth->execute; 92 while( my($link_from,$link_to) = $sth->fetchrow_array) { 93 my %il; 94 $il{'link_from'} = $link_from; 95 $il{'link_to'} = $link_to; 96 push @internal_links, \%il; 97 } 98 99 print "done\n"; 100 101 # Return it all 102 return (\%nodes,\%contents,\%metadatas,\@internal_links,\%ids); 103 103 } 104 104 105 105 # Fetch from schema version 8, and upgrade to version 9 106 106 sub fetch_upgrade_8_to_9 { 107 my $dbh = shift;108 my %nodes;109 my %metadatas;110 my %contents;111 my @internal_links;112 113 print "Grabbing and upgrading old data... ";114 115 # Grab all the nodes116 my $sth = $dbh->prepare("SELECT id,name,version,text,modified FROM node");117 $sth->execute;118 while( my($id,$name,$version,$text,$modified) = $sth->fetchrow_array) {119 my %node;120 $node{'name'} = $name;121 $node{'version'} = $version;122 $node{'text'} = $text;123 $node{'modified'} = $modified;124 $node{'id'} = $id;125 $node{'moderate'} = 0;126 $nodes{$name} = \%node;127 }128 129 # Grab all the content130 $sth = $dbh->prepare("SELECT node_id,version,text,modified,comment FROM content");131 $sth->execute;132 while ( my($node_id,$version,$text,$modified,$comment) = $sth->fetchrow_array) {133 my %content;134 $content{'node_id'} = $node_id;135 $content{'version'} = $version;136 $content{'text'} = $text;137 $content{'modified'} = $modified;138 $content{'comment'} = $comment;139 $content{'moderated'} = 1;140 $contents{$node_id."-".$version} = \%content;141 }142 143 # Grab all the metadata144 $sth = $dbh->prepare("SELECT node_id,version,metadata_type,metadata_value FROM metadata");145 $sth->execute;146 my $i = 0;147 while( my($node_id,$version,$metadata_type,$metadata_value) = $sth->fetchrow_array) {148 my %metadata;149 $metadata{'node_id'} = $node_id;150 $metadata{'version'} = $version;151 $metadata{'metadata_type'} = $metadata_type;152 $metadata{'metadata_value'} = $metadata_value;153 $metadatas{$node_id."-".($i++)} = \%metadata;154 }155 156 # Grab all the internal links157 $sth = $dbh->prepare("SELECT link_from,link_to FROM internal_links");158 $sth->execute;159 while( my($link_from,$link_to) = $sth->fetchrow_array) {160 my %il;161 $il{'link_from'} = $link_from;162 $il{'link_to'} = $link_to;163 push @internal_links, \%il;164 }165 166 print "done\n";167 168 # Return it all169 return (\%nodes,\%contents,\%metadatas,\@internal_links);107 my $dbh = shift; 108 my %nodes; 109 my %metadatas; 110 my %contents; 111 my @internal_links; 112 113 print "Grabbing and upgrading old data... "; 114 115 # Grab all the nodes 116 my $sth = $dbh->prepare("SELECT id,name,version,text,modified FROM node"); 117 $sth->execute; 118 while( my($id,$name,$version,$text,$modified) = $sth->fetchrow_array) { 119 my %node; 120 $node{'name'} = $name; 121 $node{'version'} = $version; 122 $node{'text'} = $text; 123 $node{'modified'} = $modified; 124 $node{'id'} = $id; 125 $node{'moderate'} = 0; 126 $nodes{$name} = \%node; 127 } 128 129 # Grab all the content 130 $sth = $dbh->prepare("SELECT node_id,version,text,modified,comment FROM content"); 131 $sth->execute; 132 while ( my($node_id,$version,$text,$modified,$comment) = $sth->fetchrow_array) { 133 my %content; 134 $content{'node_id'} = $node_id; 135 $content{'version'} = $version; 136 $content{'text'} = $text; 137 $content{'modified'} = $modified; 138 $content{'comment'} = $comment; 139 $content{'moderated'} = 1; 140 $contents{$node_id."-".$version} = \%content; 141 } 142 143 # Grab all the metadata 144 $sth = $dbh->prepare("SELECT node_id,version,metadata_type,metadata_value FROM metadata"); 145 $sth->execute; 146 my $i = 0; 147 while( my($node_id,$version,$metadata_type,$metadata_value) = $sth->fetchrow_array) { 148 my %metadata; 149 $metadata{'node_id'} = $node_id; 150 $metadata{'version'} = $version; 151 $metadata{'metadata_type'} = $metadata_type; 152 $metadata{'metadata_value'} = $metadata_value; 153 $metadatas{$node_id."-".($i++)} = \%metadata; 154 } 155 156 # Grab all the internal links 157 $sth = $dbh->prepare("SELECT link_from,link_to FROM internal_links"); 158 $sth->execute; 159 while( my($link_from,$link_to) = $sth->fetchrow_array) { 160 my %il; 161 $il{'link_from'} = $link_from; 162 $il{'link_to'} = $link_to; 163 push @internal_links, \%il; 164 } 165 166 print "done\n"; 167 168 # Return it all 169 return (\%nodes,\%contents,\%metadatas,\@internal_links); 170 170 } 171 171 172 172 # Get the version of the database schema 173 173 sub get_database_version { 174 my $dbh = shift;175 my $sql = "SELECT version FROM schema_info";176 my $sth;177 eval{ $sth = $dbh->prepare($sql) };178 if($@) { return "old"; }179 eval{ $sth->execute };180 if($@) { return "old"; }181 182 my ($cur_schema) = $sth->fetchrow_array;183 unless($cur_schema) { return "old"; }184 185 return $cur_schema;174 my $dbh = shift; 175 my $sql = "SELECT version FROM schema_info"; 176 my $sth; 177 eval{ $sth = $dbh->prepare($sql) }; 178 if($@) { return "old"; } 179 eval{ $sth->execute }; 180 if($@) { return "old"; } 181 182 my ($cur_schema) = $sth->fetchrow_array; 183 unless($cur_schema) { return "old"; } 184 185 return $cur_schema; 186 186 } 187 187 188 188 # Is an upgrade to the database required? 189 189 sub get_database_upgrade_required { 190 my ($dbh,$VERSION) = @_;191 192 # Get the schema version193 my $schema_version = get_database_version($dbh);194 195 # Compare it196 my $new_ver = $VERSION * 100;197 if($schema_version eq $new_ver) {198 # At latest version199 return undef;200 } else {201 return $schema_version."_to_".$new_ver;202 }190 my ($dbh,$VERSION) = @_; 191 192 # Get the schema version 193 my $schema_version = get_database_version($dbh); 194 195 # Compare it 196 my $new_ver = $VERSION * 100; 197 if($schema_version eq $new_ver) { 198 # At latest version 199 return undef; 200 } else { 201 return $schema_version."_to_".$new_ver; 202 } 203 203 } 204 204 205 205 # Put the latest data into the latest database structure 206 206 sub bulk_data_insert { 207 my ($dbh, $nodesref, $contentsref, $metadataref, $internallinksref) = @_;208 209 print "Bulk inserting upgraded data... ";210 211 # Add nodes212 my $sth = $dbh->prepare("INSERT INTO node (id,name,version,text,modified,moderate) VALUES (?,?,?,?,?,?)");213 foreach my $name (keys %$nodesref) {214 my %node = %{$nodesref->{$name}};215 $sth->execute($node{'id'},207 my ($dbh, $nodesref, $contentsref, $metadataref, $internallinksref) = @_; 208 209 print "Bulk inserting upgraded data... "; 210 211 # Add nodes 212 my $sth = $dbh->prepare("INSERT INTO node (id,name,version,text,modified,moderate) VALUES (?,?,?,?,?,?)"); 213 foreach my $name (keys %$nodesref) { 214 my %node = %{$nodesref->{$name}}; 215 $sth->execute($node{'id'}, 216 216 $node{'name'}, 217 217 $node{'version'}, … … 219 219 $node{'modified'}, 220 220 $node{'moderate'}); 221 }222 print "added ".(scalar keys %$nodesref)." nodes... ";223 224 # Add content225 $sth = $dbh->prepare("INSERT INTO content (node_id,version,text,modified,comment,moderated) VALUES (?,?,?,?,?,?)");226 foreach my $key (keys %$contentsref) {227 my %content = %{$contentsref->{$key}};228 $sth->execute($content{'node_id'},221 } 222 print "added ".(scalar keys %$nodesref)." nodes... "; 223 224 # Add content 225 $sth = $dbh->prepare("INSERT INTO content (node_id,version,text,modified,comment,moderated) VALUES (?,?,?,?,?,?)"); 226 foreach my $key (keys %$contentsref) { 227 my %content = %{$contentsref->{$key}}; 228 $sth->execute($content{'node_id'}, 229 229 $content{'version'}, 230 230 $content{'text'}, … … 232 232 $content{'comment'}, 233 233 $content{'moderated'}); 234 }234 } 235 235 236 236 # Add metadata -
wiki-toolkit/trunk/lib/Wiki/Toolkit/Setup/MySQL.pm
r426 r431 14 14 15 15 my %create_sql = ( 16 schema_info => [ qq|16 schema_info => [ qq| 17 17 CREATE TABLE schema_info ( 18 18 version int(10) NOT NULL default 0 … … 117 117 my %tables = fetch_tables_listing($dbh); 118 118 119 # Do we need to upgrade the schema of existing tables?120 # (Don't check if no tables currently exist)121 my $upgrade_schema;122 my @cur_data;123 if(scalar keys %tables > 0) {124 $upgrade_schema = Wiki::Toolkit::Setup::Database::get_database_upgrade_required($dbh,$VERSION);125 }126 if($upgrade_schema) {127 # Grab current data128 print "Upgrading: $upgrade_schema\n";129 @cur_data = eval("&Wiki::Toolkit::Setup::Database::fetch_upgrade_".$upgrade_schema."(\$dbh)");130 if($@) { warn $@; }119 # Do we need to upgrade the schema of existing tables? 120 # (Don't check if no tables currently exist) 121 my $upgrade_schema; 122 my @cur_data; 123 if(scalar keys %tables > 0) { 124 $upgrade_schema = Wiki::Toolkit::Setup::Database::get_database_upgrade_required($dbh,$VERSION); 125 } 126 if($upgrade_schema) { 127 # Grab current data 128 print "Upgrading: $upgrade_schema\n"; 129 @cur_data = eval("&Wiki::Toolkit::Setup::Database::fetch_upgrade_".$upgrade_schema."(\$dbh)"); 130 if($@) { warn $@; } 131 131 132 132 # Check to make sure we can create, index and drop tables … … 137 137 } 138 138 139 # Drop the current tables140 cleardb($dbh);141 142 # Grab new list of tables143 %tables = fetch_tables_listing($dbh);144 }145 146 # Set up tables if not found139 # Drop the current tables 140 cleardb($dbh); 141 142 # Grab new list of tables 143 %tables = fetch_tables_listing($dbh); 144 } 145 146 # Set up tables if not found 147 147 foreach my $required ( keys %create_sql ) { 148 148 if ( $tables{$required} ) { … … 156 156 } 157 157 158 # If upgrading, load in the new data159 if($upgrade_schema) {160 Wiki::Toolkit::Setup::Database::bulk_data_insert($dbh,@cur_data);161 }158 # If upgrading, load in the new data 159 if($upgrade_schema) { 160 Wiki::Toolkit::Setup::Database::bulk_data_insert($dbh,@cur_data); 161 } 162 162 163 163 # Clean up if we made our own dbh. … … 167 167 # Internal method - what Wiki::Toolkit tables are defined? 168 168 sub fetch_tables_listing { 169 my $dbh = shift;169 my $dbh = shift; 170 170 171 171 # Check what tables exist … … 176 176 exists $create_sql{$table} and $tables{$table} = 1; 177 177 } 178 return %tables;178 return %tables; 179 179 } 180 180 … … 234 234 if ( $args{dbh} ) { 235 235 return $args{dbh}; 236 } else {236 } else { 237 237 return _make_dbh( %args ); 238 238 } … … 259 259 if ( $args{dbh} ) { 260 260 return 0; 261 } else {261 } else { 262 262 return 1; 263 263 } … … 273 273 $dsn .= ";host=$args{dbhost}" if $args{dbhost}; 274 274 my $dbh = DBI->connect($dsn, $args{dbuser}, $args{dbpass}, 275 { PrintError => 1, RaiseError => 1,276 AutoCommit => 1 } )277 or croak DBI::errstr;275 { PrintError => 1, RaiseError => 1, 276 AutoCommit => 1 } ) 277 or croak DBI::errstr; 278 278 return $dbh; 279 279 } -
wiki-toolkit/trunk/lib/Wiki/Toolkit/Setup/Pg.pm
r426 r431 14 14 15 15 my %create_sql = ( 16 schema_info => [ qq|16 schema_info => [ qq| 17 17 CREATE TABLE schema_info ( 18 18 version integer NOT NULL default 0 … … 75 75 76 76 my %upgrades = ( 77 old_to_8 => [ qq|77 old_to_8 => [ qq| 78 78 CREATE SEQUENCE node_seq; 79 79 ALTER TABLE node ADD COLUMN id INTEGER; … … 91 91 ALTER TABLE content ADD COLUMN node_id INTEGER; 92 92 UPDATE content SET node_id = 93 (SELECT id FROM node where node.name = content.name)93 (SELECT id FROM node where node.name = content.name) 94 94 |, qq| 95 95 DELETE FROM content WHERE node_id IS NULL; … … 103 103 ALTER TABLE metadata ADD COLUMN node_id INTEGER; 104 104 UPDATE metadata SET node_id = 105 (SELECT id FROM node where node.name = metadata.node)105 (SELECT id FROM node where node.name = metadata.node) 106 106 |, qq| 107 107 DELETE FROM metadata WHERE node_id IS NULL; … … 192 192 } 193 193 194 # Do we need to upgrade the schema of existing tables?195 # (Don't check if no tables currently exist)196 my $upgrade_schema;197 if(scalar keys %tables > 0) {198 $upgrade_schema = Wiki::Toolkit::Setup::Database::get_database_upgrade_required($dbh,$VERSION);199 } else {200 print "Skipping schema upgrade check - no tables found\n";201 }202 203 # Set up tables if not found194 # Do we need to upgrade the schema of existing tables? 195 # (Don't check if no tables currently exist) 196 my $upgrade_schema; 197 if(scalar keys %tables > 0) { 198 $upgrade_schema = Wiki::Toolkit::Setup::Database::get_database_upgrade_required($dbh,$VERSION); 199 } else { 200 print "Skipping schema upgrade check - no tables found\n"; 201 } 202 203 # Set up tables if not found 204 204 foreach my $required ( reverse sort keys %create_sql ) { 205 205 if ( $tables{$required} ) { … … 213 213 } 214 214 215 # Do the upgrade if required216 if($upgrade_schema) {217 print "Upgrading schema: $upgrade_schema\n";218 my @updates = @{$upgrades{$upgrade_schema}};219 foreach my $update (@updates) {220 if(ref($update) eq "CODE") {221 &$update($dbh);222 } elsif(ref($update) eq "ARRAY") {223 foreach my $nupdate (@$update) {224 $dbh->do($nupdate);225 }226 } else {227 $dbh->do($update);228 }229 }230 }215 # Do the upgrade if required 216 if($upgrade_schema) { 217 print "Upgrading schema: $upgrade_schema\n"; 218 my @updates = @{$upgrades{$upgrade_schema}}; 219 foreach my $update (@updates) { 220 if(ref($update) eq "CODE") { 221 &$update($dbh); 222 } elsif(ref($update) eq "ARRAY") { 223 foreach my $nupdate (@$update) { 224 $dbh->do($nupdate); 225 } 226 } else { 227 $dbh->do($update); 228 } 229 } 230 } 231 231 232 232 # Clean up if we made our own dbh. … … 300 300 if ( $args{dbh} ) { 301 301 return $args{dbh}; 302 } else {302 } else { 303 303 return _make_dbh( %args ); 304 304 } … … 325 325 if ( $args{dbh} ) { 326 326 return 0; 327 } else {327 } else { 328 328 return 1; 329 329 } … … 339 339 $dsn .= ";host=$args{dbhost}" if $args{dbhost}; 340 340 my $dbh = DBI->connect($dsn, $args{dbuser}, $args{dbpass}, 341 { PrintError => 1, RaiseError => 1,342 AutoCommit => 1 } )343 or croak DBI::errstr;341 { PrintError => 1, RaiseError => 1, 342 AutoCommit => 1 } ) 343 or croak DBI::errstr; 344 344 return $dbh; 345 345 } -
wiki-toolkit/trunk/lib/Wiki/Toolkit/Setup/SII.pm
r209 r431 22 22 -username => $dbuser, 23 23 -password => $dbpass, 24 -hostname => '',24 -hostname => '', 25 25 -table_name => 'siindex', 26 26 -lock_mode => 'EX' ); … … 54 54 my $store = $args{store}; 55 55 if ( $store ) { 56 my @nodes = $store->list_all_nodes;57 my $search = Wiki::Toolkit::Search::SII->new( indexdb => $indexdb );58 foreach my $node ( @nodes ) {59 my $content = $store->retrieve_node( $node );60 $search->index_node( $node, $content );61 }56 my @nodes = $store->list_all_nodes; 57 my $search = Wiki::Toolkit::Search::SII->new( indexdb => $indexdb ); 58 foreach my $node ( @nodes ) { 59 my $content = $store->retrieve_node( $node ); 60 $search->index_node( $node, $content ); 61 } 62 62 } 63 63 } -
wiki-toolkit/trunk/lib/Wiki/Toolkit/Setup/SQLite.pm
r235 r431 14 14 15 15 my %create_sql = ( 16 schema_info => "16 schema_info => " 17 17 CREATE TABLE schema_info ( 18 18 version integer NOT NULL default 0 … … 104 104 my %tables = fetch_tables_listing($dbh); 105 105 106 # Do we need to upgrade the schema?107 # (Don't check if no tables currently exist)108 my $upgrade_schema;109 my @cur_data;110 if(scalar keys %tables > 0) {111 $upgrade_schema = Wiki::Toolkit::Setup::Database::get_database_upgrade_required($dbh,$VERSION);112 }113 if($upgrade_schema) {114 # Grab current data115 print "Upgrading: $upgrade_schema\n";116 @cur_data = eval("&Wiki::Toolkit::Setup::Database::fetch_upgrade_".$upgrade_schema."(\$dbh)");117 118 # Drop the current tables119 cleardb($dbh);120 121 # Grab new list of tables122 %tables = fetch_tables_listing($dbh);123 }124 125 # Set up tables if not found106 # Do we need to upgrade the schema? 107 # (Don't check if no tables currently exist) 108 my $upgrade_schema; 109 my @cur_data; 110 if(scalar keys %tables > 0) { 111 $upgrade_schema = Wiki::Toolkit::Setup::Database::get_database_upgrade_required($dbh,$VERSION); 112 } 113 if($upgrade_schema) { 114 # Grab current data 115 print "Upgrading: $upgrade_schema\n"; 116 @cur_data = eval("&Wiki::Toolkit::Setup::Database::fetch_upgrade_".$upgrade_schema."(\$dbh)"); 117 118 # Drop the current tables 119 cleardb($dbh); 120 121 # Grab new list of tables 122 %tables = fetch_tables_listing($dbh); 123 } 124 125 # Set up tables if not found 126 126 foreach my $required ( keys %create_sql ) { 127 127 if ( $tables{$required} ) { … … 130 130 print "Creating table $required... done\n"; 131 131 $dbh->do($create_sql{$required}) or croak $dbh->errstr; 132 }133 } 134 135 # Schema version136 $dbh->do("DELETE FROM schema_info");137 $dbh->do("INSERT INTO schema_info VALUES (". ($VERSION*100) .")");138 139 # If upgrading, load in the new data140 if($upgrade_schema) {141 Wiki::Toolkit::Setup::Database::bulk_data_insert($dbh,@cur_data);142 }132 } 133 } 134 135 # Schema version 136 $dbh->do("DELETE FROM schema_info"); 137 $dbh->do("INSERT INTO schema_info VALUES (". ($VERSION*100) .")"); 138 139 # If upgrading, load in the new data 140 if($upgrade_schema) { 141 Wiki::Toolkit::Setup::Database::bulk_data_insert($dbh,@cur_data); 142 } 143 143 144 144 # Clean up if we made our own dbh. … … 148 148 # Internal method - what tables are defined? 149 149 sub fetch_tables_listing { 150 my $dbh = shift;150 my $dbh = shift; 151 151 152 152 # Check whether tables exist, set them up if not. … … 160 160 $tables{$table} = 1; 161 161 } 162 return %tables;162 return %tables; 163 163 } 164 164 … … 216 216 if ( $args{dbh} ) { 217 217 return $args{dbh}; 218 } else {218 } else { 219 219 return _make_dbh( %args ); 220 220 } … … 236 236 if ( $args{dbh} ) { 237 237 return 0; 238 } else {238 } else { 239 239 return 1; 240 240 } … … 248 248 my %args = @_; 249 249 my $dbh = DBI->connect("dbi:SQLite:dbname=$args{dbname}", "", "", 250 { PrintError => 1, RaiseError => 1,251 AutoCommit => 1 } )252 or croak DBI::errstr;250 { PrintError => 1, RaiseError => 1, 251 AutoCommit => 1 } ) 252 or croak DBI::errstr; 253 253 return $dbh; 254 254 } -
wiki-toolkit/trunk/lib/Wiki/Toolkit/Store/Database.pm
r424 r431 21 21 my $CAN_USE_ENCODE; 22 22 BEGIN { 23 eval " use Encode ";24 $CAN_USE_ENCODE = $@ ? 0 : 1;23 eval " use Encode "; 24 $CAN_USE_ENCODE = $@ ? 0 : 1; 25 25 } 26 26 … … 107 107 # Connect to database and store the database handle. 108 108 my ($dbname, $dbuser, $dbpass, $dbhost, $dbport) = 109 @$self{qw(_dbname _dbuser _dbpass _dbhost _dbport)};109 @$self{qw(_dbname _dbuser _dbpass _dbhost _dbport)}; 110 110 my $dsn = $self->_dsn($dbname, $dbhost, $dbport) 111 111 or croak "No data source string provided by class"; 112 112 $self->{_dbh} = DBI->connect( $dsn, $dbuser, $dbpass, 113 { PrintError => 0, RaiseError => 1,114 AutoCommit => 1 } )115 or croak "Can't connect to database $dbname using $dsn: "113 { PrintError => 0, RaiseError => 1, 114 AutoCommit => 1 } ) 115 or croak "Can't connect to database $dbname using $dsn: " 116 116 . DBI->errstr; 117 117 } … … 130 130 # values from pre_ plugins 131 131 sub handle_pre_plugin_ret { 132 my ($running_total_ref,$result) = @_;133 134 if(($result && $result == 0) || !$result) {135 # No opinion, no need to change things136 } elsif($result == -1 || $result == 1) {137 # Increase or decrease as requested138 $$running_total_ref += $result;139 } else {140 # Invalid return code141 warn("Pre_ plugin returned invalid accept/deny value of '$result'");142 }132 my ($running_total_ref,$result) = @_; 133 134 if(($result && $result == 0) || !$result) { 135 # No opinion, no need to change things 136 } elsif($result == -1 || $result == 1) { 137 # Increase or decrease as requested 138 $$running_total_ref += $result; 139 } else { 140 # Invalid return code 141 warn("Pre_ plugin returned invalid accept/deny value of '$result'"); 142 } 143 143 } 144 144 … … 158 158 # Or get an earlier version: 159 159 my %node = $store->retrieve_node(name => "HomePage", 160 version => 2 );160 version => 2 ); 161 161 print $node{content}; 162 162 … … 189 189 my $self = shift; 190 190 my %args = scalar @_ == 1 ? ( name => $_[0] ) : @_; 191 unless($args{'version'}) { $args{'version'} = undef; }191 unless($args{'version'}) { $args{'version'} = undef; } 192 192 193 193 # Call pre_retrieve on any plugins, in case they want to tweak anything … … 196 196 if ( $plugin->can( "pre_retrieve" ) ) { 197 197 $plugin->pre_retrieve( 198 node => \$args{'name'},199 version => \$args{'version'}200 );198 node => \$args{'name'}, 199 version => \$args{'version'} 200 ); 201 201 } 202 202 } 203 203 204 204 # Note _retrieve_node_data is sensitive to calling context. 205 unless(wantarray) {206 # Scalar context, will return just the content207 return $self->_retrieve_node_data( %args );208 }205 unless(wantarray) { 206 # Scalar context, will return just the content 207 return $self->_retrieve_node_data( %args ); 208 } 209 209 210 210 my %data = $self->_retrieve_node_data( %args ); 211 $data{'checksum'} = $self->_checksum(%data);211 $data{'checksum'} = $self->_checksum(%data); 212 212 return %data; 213 213 } … … 217 217 my ($self, %args) = @_; 218 218 my %data = $self->_retrieve_node_content( %args ); 219 unless(wantarray) {220 # Scalar context, return just the content221 return $data{content};222 }219 unless(wantarray) { 220 # Scalar context, return just the content 221 return $data{content}; 222 } 223 223 224 224 # If we want additional data then get it. Note that $data{version} … … 237 237 while ( my ($type, $val) = $self->charset_decode( $sth->fetchrow_array ) ) { 238 238 if ( defined $metadata{$type} ) { 239 push @{$metadata{$type}}, $val;240 } else {239 push @{$metadata{$type}}, $val; 240 } else { 241 241 $metadata{$type} = [ $val ]; 242 242 } … … 256 256 my $sql; 257 257 258 my $version_sql_val;259 my $text_source;258 my $version_sql_val; 259 my $text_source; 260 260 if ( $args{version} ) { 261 # Version given - get that version, and the content for that version262 $version_sql_val = $dbh->quote($self->charset_encode($args{version}));263 $text_source = "content";264 } else {265 # No version given, grab latest version (and content for that)266 $version_sql_val = "node.version";267 $text_source = "node";268 }261 # Version given - get that version, and the content for that version 262 $version_sql_val = $dbh->quote($self->charset_encode($args{version})); 263 $text_source = "content"; 264 } else { 265 # No version given, grab latest version (and content for that) 266 $version_sql_val = "node.version"; 267 $text_source = "node"; 268 } 269 269 $sql = "SELECT " 270 270 . " $text_source.text, content.version, " … … 338 338 my %args = @_; 339 339 return $self->_do_old_node_exists( $args{name} ) 340 unless $args{ignore_case};340 unless $args{ignore_case}; 341 341 my $sql = $self->_get_node_exists_ignore_case_sql; 342 342 my $sth = $self->dbh->prepare( $sql ); … … 485 485 my @links_to = @{ $links_to_ref || [] }; # default to empty array 486 486 my $version; 487 unless($requires_moderation) { $requires_moderation = 0; }487 unless($requires_moderation) { $requires_moderation = 0; } 488 488 489 489 # Call pre_write on any plugins, in case they want to tweak anything 490 490 my @preplugins = @{ $args{plugins} || [ ] }; 491 my $write_allowed = 1;491 my $write_allowed = 1; 492 492 foreach my $plugin (@preplugins) { 493 493 if ( $plugin->can( "pre_write" ) ) { 494 handle_pre_plugin_ret(495 \$write_allowed,496 $plugin->pre_write(497 node => \$node,498 content => \$content,499 metadata => \$metadata_ref )500 );501 } 502 } 503 if($write_allowed < 1) {504 # The plugins didn't want to allow this action505 return -1;506 }494 handle_pre_plugin_ret( 495 \$write_allowed, 496 $plugin->pre_write( 497 node => \$node, 498 content => \$content, 499 metadata => \$metadata_ref ) 500 ); 501 } 502 } 503 if($write_allowed < 1) { 504 # The plugins didn't want to allow this action 505 return -1; 506 } 507 507 508 508 # Either inserting a new page or updating an old one. … … 511 511 512 512 513 # If it doesn't exist, add it right now513 # If it doesn't exist, add it right now 514 514 if(! $exists) { 515 # Add in a new version515 # Add in a new version 516 516 $version = 1; 517 517 518 # Handle initial moderation519 my $node_content = $content;520 if($requires_moderation) {521 $node_content = "=== This page has yet to be moderated. ===";522 }523 524 # Add the node and content518 # Handle initial moderation 519 my $node_content = $content; 520 if($requires_moderation) { 521 $node_content = "=== This page has yet to be moderated. ==="; 522 } 523 524 # Add the node and content 525 525 my $add_sql = 526 "INSERT INTO node "527 ." (name, version, text, modified, moderate) "528 ."VALUES (?, ?, ?, ?, ?)";529 my $add_sth = $dbh->prepare($add_sql);530 $add_sth->execute(531 map{ $self->charset_encode($_) }532 ($node, $version, $node_content, $timestamp, $requires_moderation)533 ) or croak "Error updating database: " . DBI->errstr;526 "INSERT INTO node " 527 ." (name, version, text, modified, moderate) " 528 ."VALUES (?, ?, ?, ?, ?)"; 529 my $add_sth = $dbh->prepare($add_sql); 530 $add_sth->execute( 531 map{ $self->charset_encode($_) } 532 ($node, $version, $node_content, $timestamp, $requires_moderation) 533 ) or croak "Error updating database: " . DBI->errstr; 534 534 } 535 535 536 536 # Get the ID of the node we've added / we're about to update 537 # Also get the moderation status for it537 # Also get the moderation status for it 538 538 $sql = "SELECT id, moderate FROM node WHERE name=" . $dbh->quote($node); 539 539 my ($node_id,$node_requires_moderation) = $dbh->selectrow_array($sql); 540 540 541 # Only update node if it exists, and moderation isn't enabled on the node542 # Whatever happens, if it exists, generate a new version number541 # Only update node if it exists, and moderation isn't enabled on the node 542 # Whatever happens, if it exists, generate a new version number 543 543 if($exists) { 544 # Get the new version number544 # Get the new version number 545 545 $sql = "SELECT max(content.version) FROM node 546 546 INNER JOIN content ON (id = node_id) … … 550 550 $version++; 551 551 552 # Update the node only if node doesn't require moderation553 if(!$node_requires_moderation) {554 $sql = "UPDATE node SET version=" . $dbh->quote($version)555 . ", text=" . $dbh->quote($self->charset_encode($content))556 . ", modified=" . $dbh->quote($timestamp)557 . " WHERE name=" . $dbh->quote($self->charset_encode($node));558 $dbh->do($sql) or croak "Error updating database: " . DBI->errstr;559 }560 561 # You can't use this to enable moderation on an existing node552 # Update the node only if node doesn't require moderation 553 if(!$node_requires_moderation) { 554 $sql = "UPDATE node SET version=" . $dbh->quote($version) 555 . ", text=" . $dbh->quote($self->charset_encode($content)) 556 . ", modified=" . $dbh->quote($timestamp) 557 . " WHERE name=" . $dbh->quote($self->charset_encode($node)); 558 $dbh->do($sql) or croak "Error updating database: " . DBI->errstr; 559 } 560 561 # You can't use this to enable moderation on an existing node 562 562 if($requires_moderation) { 563 563 warn("Moderation not added to existing node '$node', use normal moderation methods instead"); 564 564 } 565 }565 } 566 566 567 567 568 568 # Now node is updated (if required), add to the history 569 569 my $add_sql = 570 "INSERT INTO content "571 ."(node_id, version, text, modified, moderated) "572 ."VALUES (?, ?, ?, ?, ?)";573 my $add_sth = $dbh->prepare($add_sql);574 $add_sth->execute(575 map { $self->charset_encode($_) }576 ($node_id, $version, $content, $timestamp, (1-$node_requires_moderation))570 "INSERT INTO content " 571 ." (node_id, version, text, modified, moderated) " 572 ."VALUES (?, ?, ?, ?, ?)"; 573 my $add_sth = $dbh->prepare($add_sql); 574 $add_sth->execute( 575 map { $self->charset_encode($_) } 576 ($node_id, $version, $content, $timestamp, (1-$node_requires_moderation)) 577 577 ) or croak "Error updating database: " . DBI->errstr; 578 578 … … 621 621 622 622 foreach my $value ( @values ) { 623 $add_sth->execute(623 $add_sth->execute( 624 624 map { $self->charset_encode($_) } 625 625 ( $node_id, $version, $type, $value ) 626 ) or croak $dbh->errstr;626 ) or croak $dbh->errstr; 627 627 } 628 } else {628 } else { 629 629 # Otherwise grab a checksum and store that. 630 630 my $type_to_store = "__" . $type . "__checksum"; … … 634 634 ( $node_id, $version, $type_to_store, $value_to_store ) 635 635 ) or croak $dbh->errstr; 636 }636 } 637 637 } 638 638 … … 642 642 if ( $plugin->can( "post_write" ) ) { 643 643 $plugin->post_write( 644 node => $node,645 node_id => $node_id,646 version => $version,647 content => $content,648 metadata => $metadata_ref );644 node => $node, 645 node_id => $node_id, 646 version => $version, 647 content => $content, 648 metadata => $metadata_ref ); 649 649 } 650 650 } … … 659 659 my $time = shift || localtime; # Overloaded by Time::Piece. 660 660 unless( ref $time ) { 661 $time = localtime($time); # Make it into an object for strftime661 $time = localtime($time); # Make it into an object for strftime 662 662 } 663 663 return $time->strftime($timestamp_fmt); # global … … 684 684 my ($self, %args) = @_; 685 685 my ($old_name,$new_name,$wiki,$create_new_versions) = 686 @args{ qw( old_name new_name wiki create_new_versions ) };686 @args{ qw( old_name new_name wiki create_new_versions ) }; 687 687 my $dbh = $self->dbh; 688 my $formatter = $wiki->{_formatter};688 my $formatter = $wiki->{_formatter}; 689 689 690 690 my $timestamp = $self->_get_timestamp(); … … 692 692 # Call pre_rename on any plugins, in case they want to tweak anything 693 693 my @preplugins = @{ $args{plugins} || [ ] }; 694 my $rename_allowed = 1;694 my $rename_allowed = 1; 695 695 foreach my $plugin (@preplugins) { 696 696 if ( $plugin->can( "pre_rename" ) ) { 697 handle_pre_plugin_ret(698 \$rename_allowed,699 $plugin->pre_rename(700 old_name => \$old_name,701 new_name => \$new_name,702 create_new_versions => \$create_new_versions,703 )704 );705 } 706 } 707 if($rename_allowed < 1) {708 # The plugins didn't want to allow this action709 return -1;710 }711 712 # Get the ID of the node713 my $sql = "SELECT id FROM node WHERE name=?";714 my $sth = $dbh->prepare($sql);715 $sth->execute($old_name);716 my ($node_id) = $sth->fetchrow_array;697 handle_pre_plugin_ret( 698 \$rename_allowed, 699 $plugin->pre_rename( 700 old_name => \$old_name, 701 new_name => \$new_name, 702 create_new_versions => \$create_new_versions, 703 ) 704 ); 705 } 706 } 707 if($rename_allowed < 1) { 708 # The plugins didn't want to allow this action 709 return -1; 710 } 711 712 # Get the ID of the node 713 my $sql = "SELECT id FROM node WHERE name=?"; 714 my $sth = $dbh->prepare($sql); 715 $sth->execute($old_name); 716 my ($node_id) = $sth->fetchrow_array; 717 717 $sth->finish; 718 718 719 719 720 # If the formatter supports it, get a list of the internal721 # links to the page, which will have their links re-written722 # (Do now before we update the name of the node, in case of723 # self links)724 my @links;725 if($formatter->can("rename_links")) {726 # Get a list of the pages that link to the page727 $sql = "SELECT id, name, version "728 ."FROM internal_links "729 ."INNER JOIN node "730 ."ON (link_from = name) "731 ."WHERE link_to = ?";732 $sth = $dbh->prepare($sql);733 $sth->execute($old_name);734 735 # Grab them all, then update, so no locking problems736 while(my @l = $sth->fetchrow_array) { push (@links, \@l); }737 }738 739 740 # Rename the node741 $sql = "UPDATE node SET name=? WHERE id=?";742 $sth = $dbh->prepare($sql);743 $sth->execute($new_name,$node_id);744 745 746 # Fix the internal links from this page747 # (Otherwise write_node will get confused if we rename links later on)748 $sql = "UPDATE internal_links SET link_from=? WHERE link_from=?";749 $sth = $dbh->prepare($sql);750 $sth->execute($new_name,$old_name);751 752 753 # Update the text of internal links, if the formatter supports it754 if($formatter->can("rename_links")) {755 # Update the linked pages (may include renamed page)756 foreach my $l (@links) {757 my ($page_id, $page_name, $page_version) = @$l;758 # Self link special case759 if($page_name eq $old_name) { $page_name = $new_name; }760 761 # Grab the latest version of that page762 my %page = $self->retrieve_node(763 name=>$page_name, version=>$page_version764 );765 766 # Update the content of the page767 my $new_content =768 $formatter->rename_links($old_name,$new_name,$page{'content'});769 770 # Did it change?771 if($new_content ne $page{'content'}) {772 # Write the updated page out773 if($create_new_versions) {774 # Write out as a new version of the node775 # (This will also fix our internal links)776 $wiki->write_node(777 $page_name,778 $new_content,779 $page{checksum},780 $page{metadata}781 );782 } else {783 # Just update the content784 my $update_sql_a = "UPDATE node SET text=? WHERE id=?";785 my $update_sql_b = "UPDATE content SET text=? ".786 "WHERE node_id=? AND version=?";787 788 my $u_sth = $dbh->prepare($update_sql_a);789 $u_sth->execute($new_content,$page_id);790 $u_sth = $dbh->prepare($update_sql_b);791 $u_sth->execute($new_content,$page_id,$page_version);792 }793 }794 }795 796 # Fix the internal links if we didn't create new versions of the node797 if(! $create_new_versions) {798 $sql = "UPDATE internal_links SET link_to=? WHERE link_to=?";799 $sth = $dbh->prepare($sql);800 $sth->execute($new_name,$old_name);801 }802 } else {803 warn("Internal links not updated following node rename - unsupported by formatter");804 }720 # If the formatter supports it, get a list of the internal 721 # links to the page, which will have their links re-written 722 # (Do now before we update the name of the node, in case of 723 # self links) 724 my @links; 725 if($formatter->can("rename_links")) { 726 # Get a list of the pages that link to the page 727 $sql = "SELECT id, name, version " 728 ."FROM internal_links " 729 ."INNER JOIN node " 730 ." ON (link_from = name) " 731 ."WHERE link_to = ?"; 732 $sth = $dbh->prepare($sql); 733 $sth->execute($old_name); 734 735 # Grab them all, then update, so no locking problems 736 while(my @l = $sth->fetchrow_array) { push (@links, \@l); } 737 } 738 739 740 # Rename the node 741 $sql = "UPDATE node SET name=? WHERE id=?"; 742 $sth = $dbh->prepare($sql); 743 $sth->execute($new_name,$node_id); 744 745 746 # Fix the internal links from this page 747 # (Otherwise write_node will get confused if we rename links later on) 748 $sql = "UPDATE internal_links SET link_from=? WHERE link_from=?"; 749 $sth = $dbh->prepare($sql); 750 $sth->execute($new_name,$old_name); 751 752 753 # Update the text of internal links, if the formatter supports it 754 if($formatter->can("rename_links")) { 755 # Update the linked pages (may include renamed page) 756 foreach my $l (@links) { 757 my ($page_id, $page_name, $page_version) = @$l; 758 # Self link special case 759 if($page_name eq $old_name) { $page_name = $new_name; } 760 761 # Grab the latest version of that page 762 my %page = $self->retrieve_node( 763 name=>$page_name, version=>$page_version 764 ); 765 766 # Update the content of the page 767 my $new_content = 768 $formatter->rename_links($old_name,$new_name,$page{'content'}); 769 770 # Did it change? 771 if($new_content ne $page{'content'}) { 772 # Write the updated page out 773 if($create_new_versions) { 774 # Write out as a new version of the node 775 # (This will also fix our internal links) 776 $wiki->write_node( 777 $page_name, 778 $new_content, 779 $page{checksum}, 780 $page{metadata} 781 ); 782 } else { 783 # Just update the content 784 my $update_sql_a = "UPDATE node SET text=? WHERE id=?"; 785 my $update_sql_b = "UPDATE content SET text=? ". 786 "WHERE node_id=? AND version=?"; 787 788 my $u_sth = $dbh->prepare($update_sql_a); 789 $u_sth->execute($new_content,$page_id); 790 $u_sth = $dbh->prepare($update_sql_b); 791 $u_sth->execute($new_content,$page_id,$page_version); 792 } 793 } 794 } 795 796 # Fix the internal links if we didn't create new versions of the node 797 if(! $create_new_versions) { 798 $sql = "UPDATE internal_links SET link_to=? WHERE link_to=?"; 799 $sth = $dbh->prepare($sql); 800 $sth->execute($new_name,$old_name); 801 } 802 } else { 803 warn("Internal links not updated following node rename - unsupported by formatter"); 804 } 805 805 806 806 # Call post_rename on any plugins, in case they want to do anything … … 809 809 if ( $plugin->can( "post_rename" ) ) { 810 810 $plugin->post_rename( 811 old_name => $old_name,812 new_name => $new_name,813 node_id => $node_id,814 );811 old_name => $old_name, 812 new_name => $new_name, 813 node_id => $node_id, 814 ); 815 815 } 816 816 } … … 835 835 my $dbh = $self->dbh; 836 836 837 my ($name,$version) = ($args{name},$args{version});837 my ($name,$version) = ($args{name},$args{version}); 838 838 839 839 # Call pre_moderate on any plugins. 840 840 my @plugins = @{ $args{plugins} || [ ] }; 841 my $moderation_allowed = 1;841 my $moderation_allowed = 1; 842 842 foreach my $plugin (@plugins) { 843 843 if ( $plugin->can( "pre_moderate" ) ) { 844 handle_pre_plugin_ret(845 \$moderation_allowed,846 $plugin->pre_moderate(847 node => \$name,848 version => \$version )849 );850 } 851 } 852 if($moderation_allowed < 1) {853 # The plugins didn't want to allow this action854 return -1;855 }856 857 # Get the ID of this node844 handle_pre_plugin_ret( 845 \$moderation_allowed, 846 $plugin->pre_moderate( 847 node => \$name, 848 version => \$version ) 849 ); 850 } 851 } 852 if($moderation_allowed < 1) { 853 # The plugins didn't want to allow this action 854 return -1; 855 } 856 857 # Get the ID of this node 858 858 my $id_sql = "SELECT id FROM node WHERE name=?"; 859 859 my $id_sth = $dbh->prepare($id_sql); 860 860 $id_sth->execute($name); 861 my ($node_id) = $id_sth->fetchrow_array;861 my ($node_id) = $id_sth->fetchrow_array; 862 862 $id_sth->finish; 863 863 864 # Check what the current highest moderated version is865 my $hv_sql =866 "SELECT max(version) "867 ."FROM content "868 ."WHERE node_id = ? "869 ."AND moderated = ?";870 my $hv_sth = $dbh->prepare($hv_sql);871 $hv_sth->execute($node_id, "1") or croak $dbh->errstr;872 my ($highest_mod_version) = $hv_sth->fetchrow_array;864 # Check what the current highest moderated version is 865 my $hv_sql = 866 "SELECT max(version) " 867 ."FROM content " 868 ."WHERE node_id = ? " 869 ."AND moderated = ?"; 870 my $hv_sth = $dbh->prepare($hv_sql); 871 $hv_sth->execute($node_id, "1") or croak $dbh->errstr; 872 my ($highest_mod_version) = $hv_sth->fetchrow_array; 873 873 $hv_sth->finish; 874 unless($highest_mod_version) { $highest_mod_version = 0; }875 876 # Mark this version as moderated877 my $update_sql =878 "UPDATE content "879 ."SET moderated = ? "880 ."WHERE node_id = ? "881 ."AND version = ?";882 my $update_sth = $dbh->prepare($update_sql);883 $update_sth->execute("1", $node_id, $version) or croak $dbh->errstr;884 885 # Are we now the highest moderated version?886 if(int($version) > int($highest_mod_version)) {887 # Newly moderated version is newer than previous moderated version888 # So, make the current version the latest version889 my %new_data = $self->retrieve_node( name => $name, version => $version );890 891 # Make sure last modified is properly null, if not set892 unless($new_data{last_modified}) { $new_data{last_modified} = undef; }893 894 my $newv_sql =895 "UPDATE node "896 ."SET version=?, text=?, modified=? "897 ."WHERE id = ?";898 my $newv_sth = $dbh->prepare($newv_sql);899 $newv_sth->execute(900 $version, $self->charset_encode($new_data{content}),901 $new_data{last_modified}, $node_id902 ) or croak $dbh->errstr;903 } else {904 # A higher version is already moderated, so don't change node905 }906 907 # TODO: Do something about internal links, if required874 unless($highest_mod_version) { $highest_mod_version = 0; } 875 876 # Mark this version as moderated 877 my $update_sql = 878 "UPDATE content " 879 ."SET moderated = ? " 880 ."WHERE node_id = ? " 881 ."AND version = ?"; 882 my $update_sth = $dbh->prepare($update_sql); 883 $update_sth->execute("1", $node_id, $version) or croak $dbh->errstr; 884 885 # Are we now the highest moderated version? 886 if(int($version) > int($highest_mod_version)) { 887 # Newly moderated version is newer than previous moderated version 888 # So, make the current version the latest version 889 my %new_data = $self->retrieve_node( name => $name, version => $version ); 890 891 # Make sure last modified is properly null, if not set 892 unless($new_data{last_modified}) { $new_data{last_modified} = undef; } 893 894 my $newv_sql = 895 "UPDATE node " 896 ."SET version=?, text=?, modified=? " 897 ."WHERE id = ?"; 898 my $newv_sth = $dbh->prepare($newv_sql); 899 $newv_sth->execute( 900 $version, $self->charset_encode($new_data{content}), 901 $new_data{last_modified}, $node_id 902 ) or croak $dbh->errstr; 903 } else { 904 # A higher version is already moderated, so don't change node 905 } 906 907 # TODO: Do something about internal links, if required 908 908 909 909 # Finally call post_moderate on any plugins. … … 912 912 if ( $plugin->can( "post_moderate" ) ) { 913 913 $plugin->post_moderate( 914 node => $name,915 node_id => $node_id,916 version => $version );917 } 918 } 919 920 return 1;914 node => $name, 915 node_id => $node_id, 916 version => $version ); 917 } 918 } 919 920 return 1; 921 921 } 922 922 … … 937 937 my $dbh = $self->dbh; 938 938 939 my ($name,$required) = ($args{name},$args{required});940 941 # Get the ID of this node939 my ($name,$required) = ($args{name},$args{required}); 940 941 # Get the ID of this node 942 942 my $id_sql = "SELECT id FROM node WHERE name=?"; 943 943 my $id_sth = $dbh->prepare($id_sql); 944 944 $id_sth->execute($name); 945 my ($node_id) = $id_sth->fetchrow_array;945 my ($node_id) = $id_sth->fetchrow_array; 946 946 $id_sth->finish; 947 947 948 # Check we really got an ID948 # Check we really got an ID 949 949 unless($node_id) { 950 950 return 0; 951 951 } 952 952 953 # Mark it as requiring / not requiring moderation954 my $mod_sql =955 "UPDATE node "956 ."SET moderate = ? "957 ."WHERE id = ? ";958 my $mod_sth = $dbh->prepare($mod_sql);959 $mod_sth->execute("$required", $node_id) or croak $dbh->errstr;960 961 return 1;953 # Mark it as requiring / not requiring moderation 954 my $mod_sql = 955 "UPDATE node " 956 ."SET moderate = ? " 957 ."WHERE id = ? "; 958 my $mod_sth = $dbh->prepare($mod_sql); 959 $mod_sth->execute("$required", $node_id) or croak $dbh->errstr; 960 961 return 1; 962 962 } 963 963 … … 999 999 my $id_sth = $dbh->prepare($id_sql); 1000 1000 $id_sth->execute($name); 1001 my ($node_id) = $id_sth->fetchrow_array;1001 my ($node_id) = $id_sth->fetchrow_array; 1002 1002 $id_sth->finish; 1003 1003 … … 1017 1017 1018 1018 # And finish it here. 1019 post_delete_node($name,$node_id,$version,$args{plugins});1019 post_delete_node($name,$node_id,$version,$args{plugins}); 1020 1020 return 1; 1021 1021 } … … 1023 1023 # Skip out early if we're trying to delete a nonexistent version. 1024 1024 my %verdata = $self->retrieve_node( name => $name, version => $version ); 1025 unless($verdata{version}) {1026 warn("Asked to delete non existant version $version of node $node_id ($name)");1027 return 1;1028 }1025 unless($verdata{version}) { 1026 warn("Asked to delete non existant version $version of node $node_id ($name)"); 1027 return 1; 1028 } 1029 1029 1030 1030 # Reduce to trivial case if deleting the only version. … … 1034 1034 my ($count) = $sth->fetchrow_array; 1035 1035 $sth->finish; 1036 if($count == 1) {1037 # Only one version, so can do the non version delete1038 return $self->delete_node( name=>$name, plugins=>$args{plugins} );1039 }1036 if($count == 1) { 1037 # Only one version, so can do the non version delete 1038 return $self->delete_node( name=>$name, plugins=>$args{plugins} ); 1039 } 1040 1040 1041 1041 # Check whether we're deleting the latest (moderated) version. 1042 1042 my %currdata = $self->retrieve_node( name => $name ); 1043 1043 if ( $currdata{version} == $version ) { 1044 # Deleting latest version, so need to update the copy in node1044 # Deleting latest version, so need to update the copy in node 1045 1045 # (Can't just grab version ($version - 1) since it may have been 1046 1046 # deleted itself, or might not be moderated.) … … 1061 1061 my $sth = $dbh->prepare( $sql ); 1062 1062 $sth->execute( @prevdata{ qw( version content last_modified ) }, $name) 1063 or croak "Deletion failed: " . $dbh->errstr;1064 1065 # Remove the current version from content1063 or croak "Deletion failed: " . $dbh->errstr; 1064 1065 # Remove the current version from content 1066 1066 $sql = "DELETE FROM content 1067 1067 WHERE node_id = $node_id … … 1069 1069 $sth = $dbh->prepare( $sql ); 1070 1070 $sth->execute() 1071 or croak "Deletion failed: " . $dbh->errstr;1072 1073 # Update the internal links to reflect the new version1071 or croak "Deletion failed: " . $dbh->errstr; 1072 1073 # Update the internal links to reflect the new version 1074 1074 $sql = "DELETE FROM internal_links WHERE link_from=?"; 1075 1075 $sth = $dbh->prepare( $sql ); … … 1093 1093 } 1094 1094 1095 # Delete the metadata for the old version1095 # Delete the metadata for the old version 1096 1096 $sql = "DELETE FROM metadata 1097 1097 WHERE node_id = $node_id … … 1099 1099 $sth = $dbh->prepare( $sql ); 1100 1100 $sth->execute() 1101 or croak "Deletion failed: " . $dbh->errstr;1102 1103 # All done1104 post_delete_node($name,$node_id,$version,$args{plugins});1101 or croak "Deletion failed: " . $dbh->errstr; 1102 1103 # All done 1104 post_delete_node($name,$node_id,$version,$args{plugins}); 1105 1105 return 1; 1106 1106 } … … 1113 1113 $sth = $dbh->prepare( $sql ); 1114 1114 $sth->execute( $version ) 1115 or croak "Deletion failed: " . $dbh->errstr;1115 or croak "Deletion failed: " . $dbh->errstr; 1116 1116 $sql = "DELETE FROM metadata 1117 1117 WHERE node_id = $node_id … … 1119 1119 $sth = $dbh->prepare( $sql ); 1120 1120 $sth->execute( $version ) 1121 or croak "Deletion failed: " . $dbh->errstr;1122 1123 # All done1124 post_delete_node($name,$node_id,$version,$args{plugins});1121 or croak "Deletion failed: " . $dbh->errstr; 1122 1123 # All done 1124 post_delete_node($name,$node_id,$version,$args{plugins}); 1125 1125 return 1; 1126 1126 } … … 1129 1129 # Not normally used except when doing low-level maintenance 1130 1130 sub node_name_for_id { 1131 my ($self, $node_id) = @_;1131 my ($self, $node_id) = @_; 1132 1132 my $dbh = $self->dbh; 1133 1133 … … 1135 1135 my $name_sth = $dbh->prepare($name_sql); 1136 1136 $name_sth->execute($node_id); 1137 my ($name) = $name_sth->fetchrow_array;1137 my ($name) = $name_sth->fetchrow_array; 1138 1138 $name_sth->finish; 1139 1139 1140 return $name;1140 return $name; 1141 1141 } 1142 1142 1143 1143 # Internal Method 1144 1144 sub post_delete_node { 1145 my ($name,$node_id,$version,$plugins) = @_;1145 my ($name,$node_id,$version,$plugins) = @_; 1146 1146 1147 1147 # Call post_delete on any plugins, having done the delete … … 1150 1150 if ( $plugin->can( "post_delete" ) ) { 1151 1151 $plugin->post_delete( 1152 node => $name,1153 node_id => $node_id,1154 version => $version );1152 node => $name, 1153 node_id => $node_id, 1154 version => $version ); 1155 1155 } 1156 1156 } … … 1272 1272 } elsif ( $args{days} ) { 1273 1273 my $now = localtime; 1274 my $then = $now - ( ONE_DAY * $args{days} );1274 my $then = $now - ( ONE_DAY * $args{days} ); 1275 1275 $args{since} = $then; 1276 1276 delete $args{days}; … … 1280 1280 return $self->_find_recent_changes_by_criteria( %args ); 1281 1281 } else { 1282 croak "Need to supply some criteria to list_recent_changes.";1282 croak "Need to supply some criteria to list_recent_changes."; 1283 1283 } 1284 1284 } … … 1288 1288 my ($since, $limit, $between_days, $ignore_case, $new_only, 1289 1289 $metadata_is, $metadata_isnt, $metadata_was, $metadata_wasnt, 1290 $moderation, $include_all_changes ) =1290 $moderation, $include_all_changes ) = 1291 1291 @args{ qw( since limit between_days ignore_case new_only 1292 1292 metadata_is metadata_isnt metadata_was metadata_wasnt 1293 moderation include_all_changes) };1293 moderation include_all_changes) }; 1294 1294 my $dbh = $self->dbh; 1295 1295 … … 1335 1335 ) 1336 1336 . " )"; 1337 }1337 } 1338 1338 } 1339 1339 … … 1342 1342 my $value = $metadata_isnt->{$type}; 1343 1343 croak "metadata_isnt must have scalar values" if ref $value; 1344 }1344 } 1345 1345 my @omits = $self->_find_recent_changes_by_criteria( 1346 1346 since => $since, … … 1353 1353 . " OR node.version != " . $dbh->quote($omit->{version}) 1354 1354 . ")"; 1355 }1355 } 1356 1356 } 1357 1357 … … 1387 1387 my $value = $metadata_was->{$type}; 1388 1388 croak "metadata_was must have scalar values" if ref $value; 1389 }1389 } 1390 1390 my @omits = $self->_find_recent_changes_by_criteria( 1391 1391 since => $since, … … 1398 1398 . " OR content.version != " . $dbh->quote($omit->{version}) 1399 1399 . ")"; 1400 }1400 } 1401 1401 $use_content_table = 1; 1402 1402 } … … 1453 1453 $sql .= " LIMIT $limit"; 1454 1454 } 1455 #print "\n\n$sql\n\n";1456 1455 my $nodesref = $dbh->selectall_arrayref($sql); 1457 1456 my @finds = map { { name => $_->[0], 1458 version => $_->[1],1459 last_modified => $_->[2] }1460 } @$nodesref;1457 version => $_->[1], 1458 last_modified => $_->[2] } 1459 } @$nodesref; 1461 1460 foreach my $find ( @finds ) { 1462 1461 my %metadata; … … 1464 1463 FROM node 1465 1464 INNER JOIN metadata 1466 ON (id = node_id)1465 ON (id = node_id) 1467 1466 WHERE name=? 1468 1467 AND metadata.version=?" ); 1469 1468 $sth->execute( $find->{name}, $find->{version} ); 1470 1469 while ( my ($type, $value) = $self->charset_decode( $sth->fetchrow_array ) ) { 1471 if ( defined $metadata{$type} ) {1470 if ( defined $metadata{$type} ) { 1472 1471 push @{$metadata{$type}}, $value; 1473 } else {1472 } else { 1474 1473 $metadata{$type} = [ $value ]; 1475 1474 } 1476 }1475 } 1477 1476 $find->{metadata} = \%metadata; 1478 1477 } … … 1498 1497 my ($self,%args) = @_; 1499 1498 my $dbh = $self->dbh; 1500 my @nodes;1501 1502 if($args{with_details}) {1503 my $sql = "SELECT id, name, version, moderate FROM node;";1504 my $sth = $dbh->prepare( $sql );1505 $sth->execute();1506 1507 while(my @results = $sth->fetchrow_array) {1508 my %data;1509 @data{ qw( node_id name version moderate ) } = @results;1510 push @nodes, \%data;1511 }1512 } else {1513 my $sql = "SELECT name FROM node;";1514 my $raw_nodes = $dbh->selectall_arrayref($sql);1515 @nodes = ( map { $self->charset_decode( $_->[0] ) } (@$raw_nodes) );1516 }1517 return @nodes;1499 my @nodes; 1500 1501 if($args{with_details}) { 1502 my $sql = "SELECT id, name, version, moderate FROM node;"; 1503 my $sth = $dbh->prepare( $sql ); 1504 $sth->execute(); 1505 1506 while(my @results = $sth->fetchrow_array) { 1507 my %data; 1508 @data{ qw( node_id name version moderate ) } = @results; 1509 push @nodes, \%data; 1510 } 1511 } else { 1512 my $sql = "SELECT name FROM node;"; 1513 my $raw_nodes = $dbh->selectall_arrayref($sql); 1514 @nodes = ( map { $self->charset_decode( $_->[0] ) } (@$raw_nodes) ); 1515 } 1516 return @nodes; 1518 1517 } 1519 1518 … … 1716 1715 } 1717 1716 1718 my @nodes;1719 1720 # If the don't want to match by value, then we can do it with1721 # a LEFT OUTER JOIN, and either NULL or LENGTH() = 01722 if( ! $value ) {1723 my $sql = $self->_get_list_by_missing_metadata_sql(1724 ignore_case => $args{ignore_case}1725 );1726 my $sth = $dbh->prepare( $sql );1727 $sth->execute( $type );1728 1729 while ( my ($id, $node) = $sth->fetchrow_array ) {1730 push @nodes, $node;1731 }1717 my @nodes; 1718 1719 # If the don't want to match by value, then we can do it with 1720 # a LEFT OUTER JOIN, and either NULL or LENGTH() = 0 1721 if( ! $value ) { 1722 my $sql = $self->_get_list_by_missing_metadata_sql( 1723 ignore_case => $args{ignore_case} 1724 ); 1725 my $sth = $dbh->prepare( $sql ); 1726 $sth->execute( $type ); 1727 1728 while ( my ($id, $node) = $sth->fetchrow_array ) { 1729 push @nodes, $node; 1730 } 1732 1731 } else { 1733 # To find those without the value in this case would involve1734 # some seriously brain hurting SQL.1735 # So, cheat - find those with, and return everything else1736 my @with = $self->list_nodes_by_metadata(%args);1737 my %with_hash;1738 foreach my $node (@with) { $with_hash{$node} = 1; }1739 1740 my @all_nodes = $self->list_all_nodes();1741 foreach my $node (@all_nodes) {1742 unless($with_hash{$node}) {1743 push @nodes, $node;1744 }1745 }1746 }1732 # To find those without the value in this case would involve 1733 # some seriously brain hurting SQL. 1734 # So, cheat - find those with, and return everything else 1735 my @with = $self->list_nodes_by_metadata(%args); 1736 my %with_hash; 1737 foreach my $node (@with) { $with_hash{$node} = 1; } 1738 1739 my @all_nodes = $self->list_all_nodes(); 1740 foreach my $node (@all_nodes) { 1741 unless($with_hash{$node}) { 1742 push @nodes, $node; 1743 } 1744 } 1745 } 1747 1746 1748 1747 return @nodes; … … 1759 1758 1760 1759 sub _get_list_by_metadata_sql { 1761 # SQL 99 version1760 # SQL 99 version 1762 1761 # Can be over-ridden by database-specific subclasses 1763 1762 my ($self, %args) = @_; … … 1791 1790 1792 1791 sub _get_list_by_missing_metadata_sql { 1793 # SQL 99 version1792 # SQL 99 version 1794 1793 # Can be over-ridden by database-specific subclasses 1795 1794 my ($self, %args) = @_; 1796 1795 1797 my $sql = "";1796 my $sql = ""; 1798 1797 if ( $args{ignore_case} ) { 1799 1798 $sql = "SELECT node.id, node.name " … … 1803 1802 . " AND node.version=metadata.version " 1804 1803 . " AND ". $self->_get_lowercase_compare_sql("metadata.metadata_type") 1805 . ")";1804 . ")"; 1806 1805 } else { 1807 1806 $sql = "SELECT node.id, node.name " … … 1814 1813 } 1815 1814 1816 $sql .= "WHERE (metadata.metadata_value IS NULL OR LENGTH(metadata.metadata_value) = 0) ";1817 return $sql;1815 $sql .= "WHERE (metadata.metadata_value IS NULL OR LENGTH(metadata.metadata_value) = 0) "; 1816 return $sql; 1818 1817 } 1819 1818 1820 1819 sub _get_lowercase_compare_sql { 1821 my ($self, $column) = @_;1822 # SQL 99 version1820 my ($self, $column) = @_; 1821 # SQL 99 version 1823 1822 # Can be over-ridden by database-specific subclasses 1824 return "lower($column) = ?";1823 return "lower($column) = ?"; 1825 1824 } 1826 1825 sub _get_casesensitive_compare_sql { 1827 my ($self, $column) = @_;1828 # SQL 99 version1826 my ($self, $column) = @_; 1827 # SQL 99 version 1829 1828 # Can be over-ridden by database-specific subclasses 1830 return "$column = ?";1829 return "$column = ?"; 1831 1830 } 1832 1831 1833 1832 sub _get_comparison_sql { 1834 1833 my ($self, %args) = @_; 1835 # SQL 99 version1834 # SQL 99 version 1836 1835 # Can be over-ridden by database-specific subclasses 1837 1836 return "$args{thing1} = $args{thing2}"; … … 1839 1838 1840 1839 sub _get_node_exists_ignore_case_sql { 1841 # SQL 99 version1840 # SQL 99 version 1842 1841 # Can be over-ridden by database-specific subclasses 1843 1842 return "SELECT name FROM node WHERE name = ? "; … … 1864 1863 1865 1864 sub list_unmoderated_nodes { 1866 my ($self,%args) = @_;1867 1868 my $only_where_lastest = $args{'only_where_latest'};1869 1870 my $sql =1871 "SELECT "1872 ."id, name, "1873 ."node.version AS last_moderated_version, "1874 ."content.version AS version "1875 ."FROM content "1876 ."INNER JOIN node "1877 ."ON (id = node_id) "1878 ."WHERE moderated = ? "1879 ;1880 if($only_where_lastest) {1881 $sql .= "AND node.version = content.version ";1882 }1883 $sql .= "ORDER BY name, content.version ";1884 1885 # Query1865 my ($self,%args) = @_; 1866 1867 my $only_where_lastest = $args{'only_where_latest'}; 1868 1869 my $sql = 1870 "SELECT " 1871 ." id, name, " 1872 ." node.version AS last_moderated_version, " 1873 ." content.version AS version " 1874 ."FROM content " 1875 ."INNER JOIN node " 1876 ." ON (id = node_id) " 1877 ."WHERE moderated = ? " 1878 ; 1879 if($only_where_lastest) { 1880 $sql .= "AND node.version = content.version "; 1881 } 1882 $sql .= "ORDER BY name, content.version "; 1883 1884 # Query 1886 1885 my $dbh = $self->dbh; 1887 1886 my $sth = $dbh->prepare( $sql ); 1888 1887 $sth->execute( "0" ); 1889 1888 1890 my @nodes;1891 while(my @results = $sth->fetchrow_array) {1892 my %data;1893 @data{ qw( node_id name moderated_version version ) } = @results;1894 push @nodes, \%data;1895 }1896 1897 return @nodes;1889 my @nodes; 1890 while(my @results = $sth->fetchrow_array) { 1891 my %data; 1892 @data{ qw( node_id name moderated_version version ) } = @results; 1893 push @nodes, \%data; 1894 } 1895 1896 return @nodes; 1898 1897 } 1899 1898 … … 1906 1905 my @nv = $wiki->list_last_version_before('2007-01-02 10:34:11') 1907 1906 foreach my $data (@nv) { 1908 1907 1909 1908 } 1910 1909 … … 1912 1911 1913 1912 sub list_last_version_before { 1914 my ($self, $date) = @_;1915 1916 my $sql =1917 "SELECT "1918 ."id, name, "1919 ."MAX(content.version) AS version, MAX(content.modified) AS modified "1920 ."FROM node "1921 ."LEFT OUTER JOIN content "1922 ."ON (id = node_id "1923 ." AND content.modified <= ?) "1924 ."GROUP BY id, name "1925 ."ORDER BY id "1926 ;1927 1928 # Query1913 my ($self, $date) = @_; 1914 1915 my $sql = 1916 "SELECT " 1917 ." id, name, " 1918 ."MAX(content.version) AS version, MAX(content.modified) AS modified " 1919 ."FROM node " 1920 ."LEFT OUTER JOIN content " 1921 ." ON (id = node_id " 1922 ." AND content.modified <= ?) " 1923 ."GROUP BY id, name " 1924 ."ORDER BY id " 1925 ; 1926 1927 # Query 1929 1928 my $dbh = $self->dbh; 1930 1929 my $sth = $dbh->prepare( $sql ); 1931 1930 $sth->execute( $date ); 1932 1931 1933 my @nodes;1934 while(my @results = $sth->fetchrow_array) {1935 my %data;1936 @data{ qw( id name version modified ) } = @results;1937 $data{'node_id'} = $data{'id'};1938 unless($data{'version'}) { $data{'version'} = undef; }1939 push @nodes, \%data;1940 }1941 1942 return @nodes;1932 my @nodes; 1933 while(my @results = $sth->fetchrow_array) { 1934 my %data; 1935 @data{ qw( id name version modified ) } = @results; 1936 $data{'node_id'} = $data{'id'}; 1937 unless($data{'version'}) { $data{'version'} = undef; } 1938 push @nodes, \%data; 1939 } 1940 1941 return @nodes; 1943 1942 } 1944 1943 … … 1955 1954 1956 1955 sub list_metadata_by_type { 1957 my ($self, $type) = @_;1958 1959 return 0 unless $type;1956 my ($self, $type) = @_; 1957 1958 return 0 unless $type; 1960 1959 } 1961 1960 … … 2071 2070 # charset parameter we were passed. Takes a list, returns a list. 2072 2071 sub charset_decode { 2073 my $self = shift;2074 my @input = @_;2075 if ($CAN_USE_ENCODE) {2076 my @output;2077 for (@input) {2078 push( @output, Encode::decode( $self->{_charset}, $_ ) );2079 }2080 return @output;2081 }2082 return @input;2072 my $self = shift; 2073 my @input = @_; 2074 if ($CAN_USE_ENCODE) { 2075 my @output; 2076 for (@input) { 2077 push( @output, Encode::decode( $self->{_charset}, $_ ) ); 2078 } 2079 return @output; 2080 } 2081 return @input; 2083 2082 } 2084 2083 … … 2086 2085 # takes a list, returns a list 2087 2086 sub charset_encode { 2088 my $self = shift;2089 my @input = @_;2090 if ($CAN_USE_ENCODE) {2091 my @output;2092 for (@input) {2093 push( @output, Encode::encode( $self->{_charset}, $_ ) );2094 }2095 return @output;2096 }2097 return @input;2087 my $self = shift; 2088 my @input = @_; 2089 if ($CAN_USE_ENCODE) { 2090 my @output; 2091 for (@input) { 2092 push( @output, Encode::encode( $self->{_charset}, $_ ) ); 2093 } 2094 return @output; 2095 } 2096 return @input; 2098 2097 } 2099 2098 -
wiki-toolkit/trunk/lib/Wiki/Toolkit/Store/MySQL.pm
r390 r431 41 41 42 42 $store->check_and_write_node( node => $node, 43 checksum => $checksum,43 checksum => $checksum, 44 44 %other_args ); 45 45 … … 62 62 unless ($ok) { 63 63 $self->_unlock_node($node) or carp "Can't unlock node"; 64 return 0;64 return 0; 65 65 } 66 66 $ok = $self->write_node_post_locking( %args ); -
wiki-toolkit/trunk/lib/Wiki/Toolkit/Store/Pg.pm
r424 r431 41 41 42 42 $store->check_and_write_node( node => $node, 43 checksum => $checksum,43 checksum => $checksum, 44 44 %other_args ); 45 45 … … 66 66 my $error = $@; 67 67 $dbh->rollback; 68 $dbh->{AutoCommit} = 1;69 if ( $error =~ /can't serialize access due to concurrent update/i68 $dbh->{AutoCommit} = 1; 69 if ( $error =~ /can't serialize access due to concurrent update/i 70 70 or $error =~ /could not serialize access due to concurrent update/i 71 71 ) { … … 76 76 } else { 77 77 $dbh->commit; 78 $dbh->{AutoCommit} = 1;79 return $ok;78 $dbh->{AutoCommit} = 1; 79 return $ok; 80 80 } 81 81 } -
wiki-toolkit/trunk/lib/Wiki/Toolkit/Store/SQLite.pm
r338 r431 52 52 53 53 $store->check_and_write_node( node => $node, 54 checksum => $checksum,54 checksum => $checksum, 55 55 %other_args ); 56 56 … … 78 78 my $error = $@; 79 79 $dbh->rollback; 80 $dbh->{AutoCommit} = 1;81 if ($error =~ /database is locked/80 $dbh->{AutoCommit} = 1; 81 if ( $error =~ /database is locked/ 82 82 or $error =~ /DBI connect.+failed/ ) { 83 83 return 0; … … 87 87 } else { 88 88 $dbh->commit; 89 $dbh->{AutoCommit} = 1;90 return $ok;89 $dbh->{AutoCommit} = 1; 90 return $ok; 91 91 } 92 92 } -
wiki-toolkit/trunk/lib/Wiki/Toolkit/TestConfig/Utilities.pm
r209 r431 23 23 if ($Wiki::Toolkit::TestConfig::config{$dbtype}->{dbname}) { 24 24 my %config = %{$Wiki::Toolkit::TestConfig::config{$dbtype}}; 25 my $store_class = "Wiki::Toolkit::Store::$dbtype";26 eval "require $store_class";27 my $store = $store_class->new( dbname => $config{dbname},28 dbuser => $config{dbuser},29 dbpass => $config{dbpass},30 dbhost => $config{dbhost} );31 $stores{$dbtype} = $store;25 my $store_class = "Wiki::Toolkit::Store::$dbtype"; 26 eval "require $store_class"; 27 my $store = $store_class->new( dbname => $config{dbname}, 28 dbuser => $config{dbuser}, 29 dbpass => $config{dbpass}, 30 dbhost => $config{dbhost} ); 31 $stores{$dbtype} = $store; 32 32 } else { 33 $stores{$dbtype} = undef;33 $stores{$dbtype} = undef; 34 34 } 35 35 } … … 57 57 -username => $dbconfig{dbuser}, 58 58 -password => $dbconfig{dbpass}, 59 -hostname => $dbconfig{dbhost} || "",59 -hostname => $dbconfig{dbhost} || "", 60 60 -table_name => 'siindex', 61 61 -lock_mode => 'EX' ); … … 77 77 -username => $dbconfig{dbuser}, 78 78 -password => $dbconfig{dbpass}, 79 -hostname => $dbconfig{dbhost},79 -hostname => $dbconfig{dbhost}, 80 80 -table_name => 'siindex', 81 81 -lock_mode => 'EX' ); … … 99 99 my @combinations; # which searches work with which stores. 100 100 push @combinations, { store_name => "MySQL", 101 store => $stores{MySQL},102 search_name => "DBIxFTSMySQL",103 search => $searches{DBIxFTSMySQL} };101 store => $stores{MySQL}, 102 search_name => "DBIxFTSMySQL", 103 search => $searches{DBIxFTSMySQL} }; 104 104 push @combinations, { store_name => "MySQL", 105 store => $stores{MySQL},106 search_name => "SIIMySQL",107 search => $searches{SIIMySQL} };105 store => $stores{MySQL}, 106 search_name => "SIIMySQL", 107 search => $searches{SIIMySQL} }; 108 108 push @combinations, { store_name => "Pg", 109 store => $stores{Pg},110 search_name => "SIIPg",111 search => $searches{SIIPg} };109 store => $stores{Pg}, 110 search_name => "SIIPg", 111 search => $searches{SIIPg} }; 112 112 113 113 # All stores are compatible with the default S::II search, and with no search. 114 114 foreach my $store_name ( keys %stores ) { 115 115 push @combinations, { store_name => $store_name, 116 store => $stores{$store_name},117 search_name => "SII",118 search => $searches{SII} };116 store => $stores{$store_name}, 117 search_name => "SII", 118 search => $searches{SII} }; 119 119 push @combinations, { store_name => $store_name, 120 store => $stores{$store_name},121 search_name => "undef",122 search => undef };120 store => $stores{$store_name}, 121 search_name => "undef", 122 search => undef }; 123 123 } 124 124 … … 147 147 eval "require $setup_class"; 148 148 { 149 no strict "refs";150 &{"$setup_class\:\:cleardb"}($dbname, $dbuser, $dbpass, $dbhost);151 &{"$setup_class\:\:setup"}($dbname, $dbuser, $dbpass, $dbhost);149 no strict "refs"; 150 &{"$setup_class\:\:cleardb"}($dbname, $dbuser, $dbpass, $dbhost); 151 &{"$setup_class\:\:setup"}($dbname, $dbuser, $dbpass, $dbhost); 152 152 } 153 153 } -
wiki-toolkit/trunk/lib/Wiki/Toolkit/TestLib.pm
r429 r431 52 52 if ( $configured{$dbtype}{dbname} ) { 53 53 my %config = %{ $configured{$dbtype} }; 54 my $store_class = "Wiki::Toolkit::Store::$dbtype";55 my $setup_class = "Wiki::Toolkit::Setup::$dbtype";54 my $store_class = "Wiki::Toolkit::Store::$dbtype"; 55 my $setup_class = "Wiki::Toolkit::Setup::$dbtype"; 56 56 my $dsn = $dsn_prefix{$dbtype}.$config{dbname}; 57 57 my $err; … … 66 66 params => { 67 67 dbname => $config{dbname}, 68 dbuser => $config{dbuser},69 dbpass => $config{dbpass},70 dbhost => $config{dbhost},68 dbuser => $config{dbuser}, 69 dbpass => $config{dbpass}, 70 dbhost => $config{dbhost}, 71 71 }, 72 72 }; … … 81 81 db_params => { 82 82 dbname => $config{dbname}, 83 dbuser => $config{dbuser},84 dbpass => $config{dbpass},85 dbhost => $config{dbhost},83 dbuser => $config{dbuser}, 84 dbpass => $config{dbpass}, 85 dbhost => $config{dbhost}, 86 86 }, 87 87 }; … … 98 98 -username => $config{dbuser}, 99 99 -password => $config{dbpass}, 100 -hostname => $config{dbhost} || "",100 -hostname => $config{dbhost} || "", 101 101 -table_name => 'siindex', 102 102 -lock_mode => 'EX', … … 119 119 -username => $config{dbuser}, 120 120 -password => $config{dbpass}, 121 -hostname => $config{dbhost},121 -hostname => $config{dbhost}, 122 122 -table_name => 'siindex', 123 123 -lock_mode => 'EX', … … 148 148 push @wiki_info, { datastore_info => $datastore_info{MySQL}, 149 149 dbixfts_info => $dbixfts_info{MySQL} } 150 if ( $datastore_info{MySQL} and $dbixfts_info{MySQL} );150 if ( $datastore_info{MySQL} and $dbixfts_info{MySQL} ); 151 151 push @wiki_info, { datastore_info => $datastore_info{MySQL}, 152 152 sii_info => $sii_info{MySQL} } 153 if ( $datastore_info{MySQL} and $sii_info{MySQL} );153 if ( $datastore_info{MySQL} and $sii_info{MySQL} ); 154 154 push @wiki_info, { datastore_info => $datastore_info{Pg}, 155 155 sii_info => $sii_info{Pg} } 156 if ( $datastore_info{Pg} and $sii_info{Pg} );156 if ( $datastore_info{Pg} and $sii_info{Pg} ); 157 157 158 158 # All stores are compatible with the default S::II search, and with Plucene, … … 161 161 push @wiki_info, { datastore_info => $datastore_info{$dbtype}, 162 162 sii_info => $sii_info{DB_File} } 163 if ( $datastore_info{$dbtype} and $sii_info{DB_File} );163 if ( $datastore_info{$dbtype} and $sii_info{DB_File} ); 164 164 push @wiki_info, { datastore_info => $datastore_info{$dbtype}, 165 165 plucene_path => $plucene_path } 166 if ( $datastore_info{$dbtype} and $plucene_path );166 if ( $datastore_info{$dbtype} and $plucene_path ); 167 167 push @wiki_info, { datastore_info => $datastore_info{$dbtype} } 168 if $datastore_info{$dbtype};168 if $datastore_info{$dbtype}; 169 169 } 170 170 … … 235 235 my %dbconfig = %{ $fts_info{db_params} }; 236 236 my $dsn = Wiki::Toolkit::Store::MySQL->_dsn( $dbconfig{dbname}, 237 $dbconfig{dbhost} );237 $dbconfig{dbhost} ); 238 238 my $dbh = DBI->connect( $dsn, $dbconfig{dbuser}, $dbconfig{dbpass}, 239 239 { PrintError => 0, RaiseError => 1, AutoCommit => 1 } ) 240 or croak "Can't connect to $dbconfig{dbname} using $dsn: " . DBI->errstr;240 or croak "Can't connect to $dbconfig{dbname} using $dsn: " . DBI->errstr; 241 241 require Wiki::Toolkit::Setup::DBIxFTSMySQL; 242 242 Wiki::Toolkit::Setup::DBIxFTSMySQL::setup( 243 243 @dbconfig{ qw( dbname dbuser dbpass dbhost ) } 244 );244 ); 245 245 require Wiki::Toolkit::Search::DBIxFTS; 246 246 $wiki_config{search} = Wiki::Toolkit::Search::DBIxFTS->new( dbh => $dbh ); … … 260 260 if ( -d $dir ) { 261 261 rmdir $dir or die $!; 262 }262 } 263 263 mkdir $dir or die $!; 264 264 $wiki_config{search} = Wiki::Toolkit::Search::Plucene->new( path => $dir ); … … 280 280 } 281 281 282 283 282 =back 284 283
