| | 1135 | =item B<show_missing_metadata> |
| | 1136 | Search for nodes which don't have a certain kind of metadata. Optionally |
| | 1137 | also excludes Locales and Categories |
| | 1138 | =cut |
| | 1139 | sub show_missing_metadata { |
| | 1140 | my ($self, %args) = @_; |
| | 1141 | my $return_tt_vars = $args{return_tt_vars} || 0; |
| | 1142 | my $return_output = $args{return_output} || 0; |
| | 1143 | |
| | 1144 | my $wiki = $self->wiki; |
| | 1145 | my $formatter = $self->wiki->formatter; |
| | 1146 | my $script_url = $self->config->script_url; |
| | 1147 | |
| | 1148 | my ($metadata_type, $metadata_value, $exclude_locales, $exclude_categories) |
| | 1149 | = @args{ qw( metadata_type metadata_value exclude_locales exclude_categories ) }; |
| | 1150 | |
| | 1151 | my @nodes; |
| | 1152 | my $done_search = 0; |
| | 1153 | |
| | 1154 | # Only search if they supplied at least a metadata type |
| | 1155 | if($metadata_type) { |
| | 1156 | $done_search = 1; |
| | 1157 | @nodes = $wiki->list_nodes_by_missing_metadata( |
| | 1158 | metadata_type => $metadata_type, |
| | 1159 | metadata_value => $metadata_value, |
| | 1160 | ignore_case => 1, |
| | 1161 | ); |
| | 1162 | |
| | 1163 | # Do we need to filter some nodes out? |
| | 1164 | if($exclude_locales || $exclude_categories) { |
| | 1165 | my @all_nodes = @nodes; |
| | 1166 | @nodes = (); |
| | 1167 | |
| | 1168 | foreach my $node (@all_nodes) { |
| | 1169 | if($exclude_locales && $node =~ /^Locale /) { next; } |
| | 1170 | if($exclude_categories && $node =~ /^Category /) { next; } |
| | 1171 | push @nodes, $node; |
| | 1172 | } |
| | 1173 | } |
| | 1174 | } |
| | 1175 | |
| | 1176 | # Build nice edit etc links for our nodes |
| | 1177 | my @tt_nodes; |
| | 1178 | for my $node (@nodes) { |
| | 1179 | my %n; |
| | 1180 | |
| | 1181 | # Make the URLs |
| | 1182 | my $node_param = uri_escape( $formatter->node_name_to_node_param( $node ) ); |
| | 1183 | |
| | 1184 | # Save into the hash |
| | 1185 | $n{'name'} = $node; |
| | 1186 | $n{'view_url'} = $script_url . "?id=" . $node_param; |
| | 1187 | $n{'edit_url'} = $script_url . "?id=" . $node_param . ";action=edit"; |
| | 1188 | push @tt_nodes, \%n; |
| | 1189 | } |
| | 1190 | |
| | 1191 | # Set up our TT variables, including the search parameters |
| | 1192 | my %tt_vars = ( |
| | 1193 | not_editable => 1, |
| | 1194 | not_deletable => 1, |
| | 1195 | deter_robots => 1, |
| | 1196 | |
| | 1197 | nodes => \@tt_nodes, |
| | 1198 | done_search => $done_search, |
| | 1199 | metadata_type => $metadata_type, |
| | 1200 | metadata_value => $metadata_value, |
| | 1201 | exclude_locales => $exclude_locales, |
| | 1202 | exclude_categories => $exclude_categories |
| | 1203 | ); |
| | 1204 | return %tt_vars if $return_tt_vars; |
| | 1205 | |
| | 1206 | # Render to the page |
| | 1207 | my $output = $self->process_template( |
| | 1208 | id => "", |
| | 1209 | template => "missing_metadata.tt", |
| | 1210 | tt_vars => \%tt_vars, |
| | 1211 | ); |
| | 1212 | return $output if $return_output; |
| | 1213 | print $output; |
| | 1214 | } |
| | 1215 | |