Repository navigation
Expand file tree
/
Copy pathupdate_pages.plx
More file actions
executable file
·180 lines (124 loc) · 3.9 KB
/
Copy pathupdate_pages.plx
File metadata and controls
executable file
·180 lines (124 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/local/bin/perl -w
#!/usr/bin/perl -w
## Given a NAR database (in HTML format), this script checks if the
## MetaBase entry for the given database can be 'safely' updated. User
## contributed text is saved, the update performed, and the user
## contributed text is then restored.
use strict;
use Getopt::Long;
## Import the helper functions
use NARDatabase
( "mwLogin",
"parseNarDatabaseHtml",
"tidyTitleForMediaWiki",
"getPage",
"makeTheFucker",
"getPageRevisions",
"updatePage",
);
## Get a connection to the wiki...
my $mw = mwLogin;
## Check the command line for command line arguments
# For debugging
my $force = 0;
my $verbose = 0;
# To tag pages with a version number
my $pageVersion = "2.1.1";
GetOptions( "force" => \$force,
"verbose+" => \$verbose,
)
or die "problem with command line arguments\n";
## First things first...
die "pass me a list of NAR database web pages\n"
unless @ARGV;
for my $file (@ARGV){
warn "$file\n"
if $verbose > 1;
my $data = parseNarDatabaseHtml($file)
or die "failed to parse $file\n";
warn "parsed $file\n"
if $verbose > 1;
## Unwrap the resulting data (for didactic purposes)
my ($title, # The database title.
$titleCode, # The database title code (if any).
$accn_no, # The database accession No.
$url, # The database URL(s).
$author, # The database author(s) (one line).
$authorAdr, # The author address(es) (one line).
$contact, # The database contact email(s).
$H3, # The H3 data.
#
$cat, # The database category data.
$subCat, # The database sub-category data.
#
$abstract, # Abstract URL.
$abstractYear # Abstract year
) = @$data;
## OK
## Take care with the database titles, as they may not be mappable
## onto MW page names!
my $mwTitle = tidyTitleForMediaWiki( $title );
#print "$mwTitle ($titleCode)\n";
## Historical fix up!!!!!
my $rev = getPageRevisions($mwTitle, $mw)
or die "ffffff\n";
if($force ||
#(scalar(@$rev) == 3 &&
# $rev->[0]->{user} eq 'MaintainanceBot' &&
# $rev->[1]->{user} eq 'NARDatabaseBot' &&
# $rev->[2]->{user} eq 'NARDatabaseBot'
#) ||
#(scalar(@$rev) == 4 &&
# $rev->[0]->{user} eq 'MaintainanceBot' &&
# $rev->[1]->{user} eq 'MaintainanceBot' &&
# $rev->[2]->{user} eq 'NARDatabaseBot' &&
# $rev->[3]->{user} eq 'NARDatabaseBot'
#) ||
(scalar(@$rev) == 2 &&
$rev->[0]->{user} eq 'NARDatabaseBot' &&
$rev->[1]->{user} eq 'NARDatabaseBot'
)# ||
#(scalar(@$rev) == 1 &&
# $rev->[0]->{user} eq 'MaintainanceBot'
#)
){
warn "updating!\n"
if $verbose > 0;
my $pageText = makeTheFucker($data)
or die "fuckidy\n";
updatePage($mwTitle, $mw, $pageText,
"Moving to template based system. $pageVersion"
);
}
else {
warn "cuck knwos\n"
if $verbose > 0;
}
# Process the next file
warn "\n"
if $verbose > 0;
my $x = <>;
}
warn "OK\n";
__END__
## Try to grab the user contributed comments...
my $mwTitle = tidyTitleForMediaWiki( $title );
my $page = getPage( $mwTitle, $mw );
my $pageText = $page->{'*'};
if($pageText =~ /NARWebserver transclusion/){
die "phui\n"
}
my $sps = index($page->{'*'}, '<!-- Add your text below -->');
my $spe = index($page->{'*'}, '<!-- Add your text above -->');
die "mcFucker\n"
unless $sps && $spe && $sps < $spe;
my $userText =
substr($page->{'*'}, $sps, $spe-$sps);
print "'$userText'\n";
#my $pageText = makeTheFucker($data, $sps, $spe)
# or die "fuckidy\n";
#updatePage($title, $mw, $pageText,
# 'Moving to template based mayhem! ;-)'
# );
}
warn "OK\n";