| 991 | | # TODO: Split this off into another function |
| 992 | | # TODO: Don't run this if the node requires moderation (only do it after someone moderates) |
| 993 | | foreach my $type (qw(Category Locale)) { |
| 994 | | my $lctype = lc($type); |
| 995 | | foreach my $index (@{$metadata{$lctype}}) { |
| 996 | | $index =~ s/(.*)/\u$1/; |
| 997 | | my $node = $type . " " . $index; |
| 998 | | # Uppercase the node name before checking for existence |
| 999 | | $node =~ s/ (\S+)/ \u$1/g; |
| 1000 | | unless ( $wiki->node_exists($node) ) { |
| 1001 | | my $category = $type eq "Category" ? "Category" : "Locales"; |
| 1002 | | $wiki->write_node( |
| 1003 | | $node, |
| 1004 | | "\@INDEX_LINK [[$node]]", |
| 1005 | | undef, |
| 1006 | | { |
| 1007 | | username => "Auto Create", |
| 1008 | | comment => "Auto created $lctype stub page", |
| 1009 | | category => $category |
| 1010 | | } |
| 1011 | | ); |
| 1012 | | } |
| 1013 | | } |
| | 991 | # Skip this for nodes needing moderation - this occurs for them once |
| | 992 | # they've been moderated |
| | 993 | unless($wiki->node_required_moderation($node)) { |
| | 994 | $self->_autoCreateCategoryLocale( |
| | 995 | id => $node, |
| | 996 | metadata => \%metadata |
| | 997 | ); |
| | 1044 | } |
| | 1045 | } |
| | 1046 | |
| | 1047 | =item B<_autoCreateCategoryLocale> |
| | 1048 | |
| | 1049 | $guide->_autoCreateCategoryLocale( |
| | 1050 | id => "FAQ", |
| | 1051 | metadata => \%metadata, |
| | 1052 | ); |
| | 1053 | |
| | 1054 | When a new node is added, or a previously un-moderated node is moderated, |
| | 1055 | identifies if any of its Categories or Locales are missing, and creates them. |
| | 1056 | |
| | 1057 | For nodes not requiring moderation, should be called on writing the node |
| | 1058 | For nodes requiring moderation, should only be called on moderation |
| | 1059 | =cut |
| | 1060 | sub _autoCreateCategoryLocale { |
| | 1061 | my ($self, %args) = @_; |
| | 1062 | |
| | 1063 | my $wiki = $self->wiki; |
| | 1064 | my $id = $args{'id'}; |
| | 1065 | my %metadata = %{$args{'metadata'}}; |
| | 1066 | |
| | 1067 | # Check to make sure all the indexable nodes are created |
| | 1068 | foreach my $type (qw(Category Locale)) { |
| | 1069 | my $lctype = lc($type); |
| | 1070 | foreach my $index (@{$metadata{$lctype}}) { |
| | 1071 | $index =~ s/(.*)/\u$1/; |
| | 1072 | my $node = $type . " " . $index; |
| | 1073 | # Uppercase the node name before checking for existence |
| | 1074 | $node =~ s/ (\S+)/ \u$1/g; |
| | 1075 | unless ( $wiki->node_exists($node) ) { |
| | 1076 | my $category = $type eq "Category" ? "Category" : "Locales"; |
| | 1077 | $wiki->write_node( |
| | 1078 | $node, |
| | 1079 | "\@INDEX_LINK [[$node]]", |
| | 1080 | undef, |
| | 1081 | { |
| | 1082 | username => "Auto Create", |
| | 1083 | comment => "Auto created $lctype stub page", |
| | 1084 | category => $category |
| | 1085 | } |
| | 1086 | ); |
| | 1087 | } |
| | 1088 | } |
| | 1243 | =item B<moderate_node> |
| | 1244 | |
| | 1245 | $guide->moderate_node( |
| | 1246 | id => "FAQ", |
| | 1247 | version => 12, |
| | 1248 | password => "beer", |
| | 1249 | ); |
| | 1250 | |
| | 1251 | Marks a version of a node as moderated. Will also auto-create and Locales |
| | 1252 | and Categories for the newly moderated version. |
| | 1253 | |
| | 1254 | If C<password> is not supplied then a form for entering the password |
| | 1255 | will be displayed. |
| | 1256 | =cut |
| | 1257 | sub moderate_node { |
| | 1258 | my ($self, %args) = @_; |
| | 1259 | my $node = $args{id} or croak "No node ID supplied for node moderation"; |
| | 1260 | my $version = $args{version} or croak "No node version supplied for node moderation"; |
| | 1261 | my $return_tt_vars = $args{return_tt_vars} || 0; |
| | 1262 | my $return_output = $args{return_output} || 0; |
| | 1263 | |
| | 1264 | # Set up the TT variables |
| | 1265 | my %tt_vars = ( |
| | 1266 | not_editable => 1, |
| | 1267 | not_deletable => 1, |
| | 1268 | deter_robots => 1, |
| | 1269 | version => $version, |
| | 1270 | moderation_action => 'moderate_node', |
| | 1271 | moderation_url_args => 'action=moderate_node&version='.$version |
| | 1272 | ); |
| | 1273 | |
| | 1274 | my $password = $args{password}; |
| | 1275 | |
| | 1276 | if ($password) { |
| | 1277 | if ($password ne $self->config->admin_pass) { |
| | 1278 | return %tt_vars if $return_tt_vars; |
| | 1279 | my $output = $self->process_template( |
| | 1280 | id => $node, |
| | 1281 | template => "moderate_password_wrong.tt", |
| | 1282 | tt_vars => \%tt_vars, |
| | 1283 | ); |
| | 1284 | return $output if $return_output; |
| | 1285 | print $output; |
| | 1286 | } else { |
| | 1287 | $self->wiki->moderate_node( |
| | 1288 | name => $node, |
| | 1289 | version => $version |
| | 1290 | ); |
| | 1291 | |
| | 1292 | # Create any categories or locales for it |
| | 1293 | my %details = $self->wiki->retrieve_node( |
| | 1294 | name => $node, |
| | 1295 | version => $version |
| | 1296 | ); |
| | 1297 | $self->_autoCreateCategoryLocale( |
| | 1298 | id => $node, |
| | 1299 | metadata => $details{'metadata'} |
| | 1300 | ); |
| | 1301 | |
| | 1302 | # Send back to the admin interface |
| | 1303 | my $script_url = $self->config->script_url; |
| | 1304 | my $script_name = $self->config->script_name; |
| | 1305 | my $q = CGI->new; |
| | 1306 | my $output = $q->redirect( $script_url.$script_name."?action=admin&moderation=moderated" ); |
| | 1307 | return $output if $return_output; |
| | 1308 | print $output; |
| | 1309 | } |
| | 1310 | } else { |
| | 1311 | return %tt_vars if $return_tt_vars; |
| | 1312 | my $output = $self->process_template( |
| | 1313 | id => $node, |
| | 1314 | template => "moderate_confirm.tt", |
| | 1315 | tt_vars => \%tt_vars, |
| | 1316 | ); |
| | 1317 | return $output if $return_output; |
| | 1318 | print $output; |
| | 1319 | } |
| | 1320 | } |
| | 1321 | |