########################################################################### # # MediaWikiPlug.pm -- html plugin with extra facilities for wiki page # # A component of the Greenstone digital library software # from the New Zealand Digital Library Project at the # University of Waikato, New Zealand. # # Copyright (C) 1999 New Zealand Digital Library Project # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # ########################################################################### # This plugin is to process an HTML file where sections are divided by # user-defined headings tags. As it is difficult to predict what user's definition # this plugin allows to detect the user-defined titles up to three levels (level1, level2, level3...) # as well as allows to get rid of user-defined Table of Content (TOC)... # format:e.g. level1 (Abstract_title|ChapterTitle|Referencing Heading) level2(SectionHeading)... package MediaWikiPlug; use HTMLPlug; use ImagePlug; use File::Copy; #use strict; # every perl program should have this! #no strict 'refs'; # make an exception so we can use variables as filehandles sub BEGIN { @MediaWikiPlug::ISA = ('HTMLPlug'); } my $arguments = [ { 'name' => "show_toc", 'desc' => "{MediaWikiPlug.show_toc}", 'type' => "flag", 'reqd' => "no"}, { 'name' => "toc_exp", 'desc' => "{MediaWikiPlug.toc_exp}", 'type' => "regexp", 'reqd' => "no", 'deft' => "" }, { 'name' => "delete_toc", 'desc' => "{MediaWikiPlug.delete_toc}", 'type' => "flag", 'reqd' => "no"}, { 'name' => "delete_nav", 'desc' => "{MediaWikiPlug.delete_nav}", 'type' => "flag", 'reqd' => "no", 'deft' => ""}, { 'name' => "nav_exp", 'desc' => "{MediaWikiPlug.nav_exp}", 'type' => "regexp", 'reqd' => "no", 'deft' => "" }, { 'name' => "tag_sections", 'desc' => "{MediaWikiPlug.tag_sections}", 'type' => "flag", 'reqd' => "no"}, { 'name' => "description_tags", 'desc' => "{HTMLPlug.description_tags}", 'type' => "flag", 'reqd' => "no"} ]; my $options = { 'name' => "MediaWikiPlug", 'desc' => "{MediaWikiPlug.desc}", 'abstract' => "no", 'inherits' => "yes", 'args' => $arguments }; sub new { my ($class) = shift (@_); my ($pluginlist,$inputargs,$hashArgOptLists) = @_; push(@$pluginlist, $class); if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});} if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)}; my $self = new HTMLPlug($pluginlist, $inputargs, $hashArgOptLists); return bless $self, $class; } sub process { my $self = shift (@_); my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_; my $outhandle = $self->{'outhandle'}; print $outhandle "MediaWikiPlug: processing $file\n" if $self->{'verbosity'} > 1; my @head_and_body = split(/(.+)<\/title>/i; my $doctitle = $1 if defined $1; if (defined $self->{'metadata_fields'} && $self->{'metadata_fields'}=~ /\S/) { my @doc_properties = split(//i,$head); my $doc_heading = shift(@doc_properties); my $rest_doc_properties = join(" ", @doc_properties); my @extracted_metadata = split(/<\/xml>/i, $rest_doc_properties); my $extracted_metadata = shift (@extracted_metadata); $self->extract_metadata($extracted_metadata, $metadata, $doc_obj); } # set the title here if we haven't found it yet if (!defined $doc_obj->get_metadata_element ($doc_obj->get_top_section(), "Title")) { if (defined $doctitle && $doctitle =~ /\S/) { $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "Title", $doctitle); } else { $self->title_fallback($doc_obj,$doc_obj->get_top_section(),$file); } } if(defined $base_dir && $base_dir ne ""){ # find and download stylesheet my @css_files; my $css_file_count = 0; # find all the style sheets imported with import statement while($head =~ m"