| 1 |
package WWW::Mediawiki::Clientscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/; |
| 2 |
|
| 3 |
use warningsscip-perl cpan perl-project 0.0.0 warnings/; |
| 4 |
use strictscip-perl cpan perl-project 0.0.0 strict/; |
| 5 |
use File::Specscip-perl cpan perl-project 0.0.0 File/Spec/; |
| 6 |
use File::Findscip-perl cpan perl-project 0.0.0 File/Find/; |
| 7 |
use LWP::UserAgentscip-perl cpan perl-project 0.0.0 LWP/UserAgent/; |
| 8 |
use HTML::TokeParserscip-perl cpan perl-project 0.0.0 HTML/TokeParser/; |
| 9 |
use HTTP::Requestscip-perl cpan perl-project 0.0.0 HTTP/Request/; |
| 10 |
use HTTP::Request::Commonscip-perl cpan perl-project 0.0.0 HTTP/Request/Common/; |
| 11 |
use HTTP::Cookiesscip-perl cpan perl-project 0.0.0 HTTP/Cookies/; |
| 12 |
use URI::Escapescip-perl cpan perl-project 0.0.0 URI/Escape/; |
| 13 |
use VCS::Litescip-perl cpan perl-project 0.0.0 VCS/Lite/; |
| 14 |
use Data::Dumperscip-perl cpan perl-project 0.0.0 Data/Dumper/; |
| 15 |
use WWW::Mediawiki::Client::Exceptionsscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/Exceptions/; |
| 16 |
use XML::LibXMLscip-perl cpan perl-project 0.0.0 XML/LibXML/ (); |
| 17 |
use HTML::Entitiesscip-perl cpan perl-project 0.0.0 HTML/Entities/ qw(encode_entities); |
| 18 |
use File::Tempscip-perl cpan perl-project 0.0.0 File/Temp/ (); |
| 19 |
use Encodescip-perl cpan perl-project 0.0.0 Encode/; |
| 20 |
use Encode::Guessscip-perl cpan perl-project 0.0.0 Encode/Guess/; |
| 21 |
use utf8scip-perl cpan perl-project 0.0.0 utf8/; |
| 22 |
|
| 23 |
use basescip-perl cpan perl-project 0.0.0 base/ 'Exporter'; |
| 24 |
our %EXPORT_TAGSscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`%EXPORT_TAGS`. = ( |
| 25 |
options => [qw(OPT_YES OPT_NO OPT_DEFAULT OPT_KEEP)], |
| 26 |
); |
| 27 |
our @EXPORT_OKscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@EXPORT_OK`. = mapscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/map(). { @{$EXPORT_TAGSscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`%EXPORT_TAGS`.{$_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/$_.}} } keysscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/keys(). %EXPORT_TAGSscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`%EXPORT_TAGS`.; |
| 28 |
|
| 29 |
=head1 NAME |
| 30 |
|
| •31 |
WWW::Mediawiki::Client - module providing a VCS like to MediaWiki |
| 32 |
|
| 33 |
=cut |
| 34 |
|
| 35 |
=head1 SYNOPSIS |
| 36 |
|
| 37 |
use WWW::Mediawiki::Client; |
| 38 |
|
| 39 |
my $filename = 'Subject.wiki'; |
| 40 |
my $mvs = WWW::Mediawiki::Client->new( |
| 41 |
host => 'www.wikitravel.org' |
| 42 |
); |
| 43 |
|
| 44 |
# like cvs update |
| 45 |
$mvs->do_update($filename); |
| 46 |
|
| 47 |
# like cvs commit |
| 48 |
$mvs->do_commit($filename, $message); |
| 49 |
|
| 50 |
#aliases |
| 51 |
$mvs->do_up($filename); |
| 52 |
$mvs->do_com($filename, $message); |
| 53 |
|
| 54 |
=cut |
| 55 |
|
| 56 |
=head1 DESCRIPTION |
| 57 |
|
| 58 |
WWW::Mediawiki::Client provides a very simple cvs-like interface for |
| 59 |
Mediawiki driven WikiWiki websites, such as |
| 60 |
L<http://www.wikitravel.org|Wikitravel> or |
| 61 |
L<http://www.wikipedia.org|Wikipedia.> |
| 62 |
The interface mimics the two most basic cvs commands: update and commit |
| 63 |
with similarly named methods. Each of these has a shorter alias, as in |
| 64 |
cvs. |
| 65 |
|
| 66 |
=cut |
| 67 |
|
| 68 |
=head1 CONSTANTS |
| 69 |
|
| 70 |
=cut |
| 71 |
|
| 72 |
use constantscip-perl cpan perl-project 0.0.0 constant/ ACTIONscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/ACTION(). => 'action'; |
| 73 |
|
| 74 |
use constantscip-perl cpan perl-project 0.0.0 constant/ TITLEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/TITLE(). => 'title'; |
| 75 |
|
| 76 |
use constantscip-perl cpan perl-project 0.0.0 constant/ SUBMITscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/SUBMIT(). => 'submit'; |
| 77 |
|
| 78 |
use constantscip-perl cpan perl-project 0.0.0 constant/ LOGINscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/LOGIN(). => 'submitlogin'; |
| 79 |
|
| 80 |
use constantscip-perl cpan perl-project 0.0.0 constant/ LOGIN_TITLEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/LOGIN_TITLE(). => 'Special:Userlogin'; |
| 81 |
|
| 82 |
use constantscip-perl cpan perl-project 0.0.0 constant/ EDITscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/EDIT(). => 'edit'; |
| 83 |
|
| 84 |
# defaults for various known Mediawiki installations |
| 85 |
my %DEFAULTS; |
| 86 |
|
| 87 |
$DEFAULTS{'www.wikitravel.org'} = |
| 88 |
{ |
| 89 |
'host' => 'wikitravel.org', |
| 90 |
'protocol' => 'http', |
| 91 |
'space_substitute' => '_', |
| 92 |
'wiki_path' => 'wiki/__LANG__/index.php', |
| 93 |
}; |
| 94 |
$DEFAULTS{'wikitravel.org'} = $DEFAULTS{'www.wikitravel.org'}; |
| 95 |
|
| 96 |
$DEFAULTS{'www.wikipedia.org'} = |
| 97 |
{ |
| 98 |
'host' => '__LANG__.wikipedia.org', |
| 99 |
'protocol' => 'http', |
| 100 |
'space_substitute' => '+', |
| 101 |
'wiki_path' => 'w/wiki.phtml', |
| 102 |
}; |
| 103 |
$DEFAULTS{'wikipedia.org'} = $DEFAULTS{'www.wikipedia.org'}; |
| 104 |
|
| 105 |
$DEFAULTS{'www.wiktionary.org'} = |
| 106 |
{ |
| 107 |
'host' => '__LANG__.wiktionary.org', |
| 108 |
'protocol' => 'http', |
| 109 |
'space_substitute' => '_', |
| 110 |
'wiki_path' => 'w/wiki.phtml', |
| 111 |
}; |
| 112 |
$DEFAULTS{'wiktionary.org'} = $DEFAULTS{'www.wiktionary.org'}; |
| 113 |
|
| 114 |
$DEFAULTS{'www.wikibooks.org'} = |
| 115 |
{ |
| 116 |
'host' => '__LANG__.wikibooks.org', |
| 117 |
'protocol' => 'http', |
| 118 |
'space_substitute' => '_', |
| 119 |
'wiki_path' => 'w/wiki.phtml', |
| 120 |
}; |
| 121 |
$DEFAULTS{'wikibooks.org'} = $DEFAULTS{'www.wikibooks.org'}; |
| 122 |
|
| 123 |
sub DEFAULTSscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/DEFAULTS(). { \%DEFAULTS }; |
| 124 |
|
| 125 |
use constantscip-perl cpan perl-project 0.0.0 constant/ SPACE_SUBSTITUTEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/SPACE_SUBSTITUTE(). => '_'; |
| 126 |
use constantscip-perl cpan perl-project 0.0.0 constant/ WIKI_PATHscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/WIKI_PATH(). => 'wiki/index.php'; |
| 127 |
use constantscip-perl cpan perl-project 0.0.0 constant/ LANGUAGE_CODEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/LANGUAGE_CODE(). => 'en'; |
| 128 |
use constantscip-perl cpan perl-project 0.0.0 constant/ PROTOCOLscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/PROTOCOL(). => 'http'; |
| 129 |
|
| 130 |
use constantscip-perl cpan perl-project 0.0.0 constant/ SPECIAL_EXPORTscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/SPECIAL_EXPORT(). => 'Special:Export'; |
| 131 |
use constantscip-perl cpan perl-project 0.0.0 constant/ SPECIAL_VERSIONscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/SPECIAL_VERSION(). => 'Special:Version'; |
| 132 |
|
| 133 |
|
| 134 |
=head3 $VERSION |
| 135 |
|
| 136 |
=cut |
| 137 |
|
| 138 |
our $VERSIONscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/$VERSION. = 0.31; |
| 139 |
|
| 140 |
=head2 Update Status |
| 141 |
|
| 142 |
=head3 STATUS_UNKNOWN |
| 143 |
|
| 144 |
Indicates that C<WWW::Mediawiki::Client> has no information about the file. |
| 145 |
|
| 146 |
=head3 STATUS_UNCHANGED |
| 147 |
|
| 148 |
Indicates that niether the file nor the server page have changed. |
| 149 |
|
| 150 |
=head3 STATUS_LOCAL_ADDED |
| 151 |
|
| 152 |
Indicates that the file is new locally, and does not exist on the server. |
| 153 |
|
| 154 |
=head3 STATUS_LOCAL_MODIFIED |
| 155 |
|
| 156 |
Indicates that the file has been modified locally. |
| 157 |
|
| 158 |
=head3 STATUS_SERVER_MODIFIED |
| 159 |
|
| 160 |
Indicates that the server page was modified, and that the modifications |
| 161 |
have been successfully merged into the local file. |
| 162 |
|
| 163 |
=head3 STATUS_CONFLICT |
| 164 |
|
| 165 |
Indicates that there are conflicts in the local file resulting from a |
| 166 |
failed merge between the server page and the local file. |
| 167 |
|
| 168 |
=cut |
| 169 |
|
| 170 |
use constantscip-perl cpan perl-project 0.0.0 constant/ STATUS_UNKNOWNscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/STATUS_UNKNOWN(). => '?'; |
| 171 |
use constantscip-perl cpan perl-project 0.0.0 constant/ STATUS_UNCHANGEDscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/STATUS_UNCHANGED(). => '='; |
| 172 |
use constantscip-perl cpan perl-project 0.0.0 constant/ STATUS_LOCAL_ADDEDscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/STATUS_LOCAL_ADDED(). => 'A'; |
| 173 |
use constantscip-perl cpan perl-project 0.0.0 constant/ STATUS_LOCAL_MODIFIEDscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/STATUS_LOCAL_MODIFIED(). => 'M'; |
| 174 |
use constantscip-perl cpan perl-project 0.0.0 constant/ STATUS_SERVER_MODIFIEDscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/STATUS_SERVER_MODIFIED(). => 'U'; |
| 175 |
use constantscip-perl cpan perl-project 0.0.0 constant/ STATUS_CONFLICTscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/STATUS_CONFLICT(). => 'C'; |
| 176 |
|
| 177 |
=head2 Option Settings |
| 178 |
|
| 179 |
=head3 OPT_YES |
| 180 |
|
| 181 |
Indicates that the setting should always be applied. |
| 182 |
|
| 183 |
=head3 OPT_NO |
| 184 |
|
| 185 |
Indicates that the setting should never be applied. |
| 186 |
|
| 187 |
=head3 OPT_DEFAULT |
| 188 |
|
| 189 |
Indicates that the setting should be applied based on the user profile |
| 190 |
default on the Wikimedia server. |
| 191 |
|
| 192 |
=head3 OPT_KEEP |
| 193 |
|
| 194 |
Four-state options only. Indicates that the setting should not be |
| 195 |
changed from its current value on the server. |
| 196 |
|
| 197 |
=cut |
| 198 |
|
| 199 |
# Option values: |
| 200 |
use constantscip-perl cpan perl-project 0.0.0 constant/ OPT_YESscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/OPT_YES(). => 1; |
| 201 |
use constantscip-perl cpan perl-project 0.0.0 constant/ OPT_NOscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/OPT_NO(). => 0; |
| 202 |
use constantscip-perl cpan perl-project 0.0.0 constant/ OPT_DEFAULTscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/OPT_DEFAULT(). => -1; |
| 203 |
use constantscip-perl cpan perl-project 0.0.0 constant/ OPT_KEEPscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/OPT_KEEP(). => -2; # Only for watch. |
| 204 |
|
| 205 |
# Reverse lookup: |
| 206 |
use constantscip-perl cpan perl-project 0.0.0 constant/ OPTION_SETTINGSscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/OPTION_SETTINGS(). => ( |
| 207 |
OPT_YESscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/OPT_YES()., 'OPT_YES', |
| 208 |
OPT_NOscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/OPT_NO()., 'OPT_NO', |
| 209 |
OPT_DEFAULTscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/OPT_DEFAULT()., 'OPT_DEFAULT', |
| 210 |
OPT_KEEPscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/OPT_KEEP()., 'OPT_KEEP', |
| 211 |
); |
| 212 |
|
| 213 |
# Option defaults: |
| 214 |
use constantscip-perl cpan perl-project 0.0.0 constant/ MINOR_DEFAULTscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/MINOR_DEFAULT(). => OPT_DEFAULT; |
| 215 |
use constantscip-perl cpan perl-project 0.0.0 constant/ WATCH_DEFAULTscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/WATCH_DEFAULT(). => OPT_DEFAULT; |
| 216 |
|
| 217 |
=head2 Mediawiki form widgets |
| 218 |
|
| 219 |
=head3 TEXTAREA_NAME |
| 220 |
|
| 221 |
=head3 COMMENT_NAME |
| 222 |
|
| 223 |
=head3 EDIT_SUBMIT_NAME |
| 224 |
|
| 225 |
=head3 EDIT_SUBMIT_VALUE |
| 226 |
|
| 227 |
=head3 EDIT_PREVIEW_NAME |
| 228 |
|
| 229 |
=head3 EDIT_PREVIEW_VALUE |
| 230 |
|
| 231 |
=head3 EDIT_TIME_NAME |
| 232 |
|
| 233 |
=head3 EDIT_TOKEN_NAME |
| 234 |
|
| 235 |
=head3 EDIT_WATCH_NAME |
| 236 |
|
| 237 |
=head3 EDIT_MINOR_NAME |
| 238 |
|
| 239 |
=head3 CHECKED |
| 240 |
|
| 241 |
=head3 UNCHECKED |
| 242 |
|
| 243 |
=head3 USERNAME_NAME |
| 244 |
|
| 245 |
=head3 PASSWORD_NAME |
| 246 |
|
| 247 |
=head3 REMEMBER_NAME |
| 248 |
|
| 249 |
=head3 LOGIN_SUBMIT_NAME |
| 250 |
|
| 251 |
=head3 LOGIN_SUBMIT_VALUE |
| 252 |
|
| 253 |
=cut |
| 254 |
|
| 255 |
use constantscip-perl cpan perl-project 0.0.0 constant/ TEXTAREA_NAMEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/TEXTAREA_NAME(). => 'wpTextbox1'; |
| 256 |
use constantscip-perl cpan perl-project 0.0.0 constant/ COMMENT_NAMEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/COMMENT_NAME(). => 'wpSummary'; |
| 257 |
use constantscip-perl cpan perl-project 0.0.0 constant/ EDIT_SUBMIT_NAMEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/EDIT_SUBMIT_NAME(). => 'wpSave'; |
| 258 |
use constantscip-perl cpan perl-project 0.0.0 constant/ EDIT_SUBMIT_VALUEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/EDIT_SUBMIT_VALUE(). => 'Save Page'; |
| 259 |
use constantscip-perl cpan perl-project 0.0.0 constant/ EDIT_PREVIEW_NAMEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/EDIT_PREVIEW_NAME(). => 'wpPreview'; |
| 260 |
use constantscip-perl cpan perl-project 0.0.0 constant/ EDIT_PREVIEW_VALUEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/EDIT_PREVIEW_VALUE(). => 'Show preview'; |
| •261 |
use constantscip-perl cpan perl-project 0.0.0 constant/ EDIT_START_NAMEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/EDIT_START_NAME(). => 'wpStarttime'; |
| 262 |
use constantscip-perl cpan perl-project 0.0.0 constant/ EDIT_TIME_NAMEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/EDIT_TIME_NAME(). => 'wpEdittime'; |
| 263 |
use constantscip-perl cpan perl-project 0.0.0 constant/ EDIT_TOKEN_NAMEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/EDIT_TOKEN_NAME(). => 'wpEditToken'; |
| 264 |
use constantscip-perl cpan perl-project 0.0.0 constant/ EDIT_WATCH_NAMEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/EDIT_WATCH_NAME(). => 'wpWatchthis'; |
| 265 |
use constantscip-perl cpan perl-project 0.0.0 constant/ EDIT_MINOR_NAMEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/EDIT_MINOR_NAME(). => 'wpMinoredit'; |
| 266 |
use constantscip-perl cpan perl-project 0.0.0 constant/ CHECKEDscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/CHECKED(). => 1; |
| 267 |
use constantscip-perl cpan perl-project 0.0.0 constant/ UNCHECKEDscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/UNCHECKED(). => 0; |
| 268 |
use constantscip-perl cpan perl-project 0.0.0 constant/ USERNAME_NAMEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/USERNAME_NAME(). => 'wpName'; |
| 269 |
use constantscip-perl cpan perl-project 0.0.0 constant/ PASSWORD_NAMEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/PASSWORD_NAME(). => 'wpPassword'; |
| 270 |
use constantscip-perl cpan perl-project 0.0.0 constant/ REMEMBER_NAMEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/REMEMBER_NAME(). => 'wpRemember'; |
| 271 |
use constantscip-perl cpan perl-project 0.0.0 constant/ LOGIN_SUBMIT_NAMEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/LOGIN_SUBMIT_NAME(). => 'wpLoginattempt'; |
| 272 |
use constantscip-perl cpan perl-project 0.0.0 constant/ LOGIN_SUBMIT_VALUEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/LOGIN_SUBMIT_VALUE(). => 'Log In'; |
| 273 |
use constantscip-perl cpan perl-project 0.0.0 constant/ LOGIN_TOKENscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/LOGIN_TOKEN(). => 'wpLoginToken'; |
| •274 |
use constantscip-perl cpan perl-project 0.0.0 constant/ HTTP_AUTHORIZATION_NAMEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/HTTP_AUTHORIZATION_NAME(). => 'Authorization'; |
| 275 |
use constantscip-perl cpan perl-project 0.0.0 constant/ HTTP_AUTHORIZATION_NONEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/HTTP_AUTHORIZATION_NONE(). => 'none'; |
| 276 |
use constantscip-perl cpan perl-project 0.0.0 constant/ HTTP_AUTHORIZATION_BASICscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/HTTP_AUTHORIZATION_BASIC(). => 'Basic'; |
| •277 |
use constantscip-perl cpan perl-project 0.0.0 constant/ HTTP_AUTHORIZATION_DEFAULTscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/HTTP_AUTHORIZATION_DEFAULT(). => HTTP_AUTHORIZATION_NONE; |
| 278 |
|
| 279 |
=head2 Files |
| 280 |
|
| 281 |
=head3 CONFIG_FILE |
| 282 |
|
| 283 |
.mediawiki |
| 284 |
|
| 285 |
=head3 COOKIE_FILE |
| 286 |
|
| 287 |
.mediawiki.cookies |
| 288 |
|
| 289 |
=head3 SAVED_ATTRIBUTES |
| 290 |
|
| 291 |
Controls which attributes get saved out to the config file. |
| 292 |
|
| 293 |
=cut |
| 294 |
|
| •295 |
use constantscip-perl cpan perl-project 0.0.0 constant/ CONFIG_FILEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/CONFIG_FILE(). => './.mediawiki'; |
| 296 |
use constantscip-perl cpan perl-project 0.0.0 constant/ COOKIE_FILEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/COOKIE_FILE(). => '.mediawiki_cookies.dat'; |
| 297 |
use constantscip-perl cpan perl-project 0.0.0 constant/ SAVED_ATTRIBUTESscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/SAVED_ATTRIBUTES(). => ( |
| 298 |
qw(site_url host protocol language_code space_substitute username |
| •299 |
password http_authorization_method wiki_path watch encoding minor_edit escape_filenames) |
| 300 |
); # It's important that host goes first since it has side effects |
| 301 |
|
| 302 |
|
| 303 |
=head1 CONSTRUCTORS |
| 304 |
|
| 305 |
=cut |
| 306 |
|
| 307 |
=head2 new |
| 308 |
|
| 309 |
my $mvs = WWW::Mediawiki::Client->new(host = 'www.wikitravel.org'); |
| 310 |
|
| 311 |
Accepts name-value pairs which will be used as initial values for any of |
| 312 |
the fields which have accessors below. Throws the same execptions as the |
| 313 |
accessor for any field named. |
| 314 |
|
| 315 |
=cut |
| 316 |
|
| 317 |
sub newscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/new(). { |
| 318 |
my $pkg = shiftscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/shift().; |
| 319 |
my %init = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 320 |
my $self = blessscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/bless(). {}; |
| •321 |
$self->{ua} = LWP::UserAgent->newscip-perl cpan perl-project 0.0.0 LWP/UserAgent/new().(); |
| 322 |
$self->load_statescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/load_state().; |
| 323 |
foreach my $attr (SAVED_ATTRIBUTES) { |
| 324 |
next unless $init{$attr}; |
| 325 |
$self->$attrscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/$attr().($init{$attr}); |
| 326 |
} |
| 327 |
pushscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/push(). @{ $self->{ua}->requests_redirectablescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/requests_redirectable(). }, 'POST'; |
| 328 |
my $agent = 'WWW::Mediawiki::Client/' . $VERSIONscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/$VERSION.; |
| 329 |
$self->{ua}->agentscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/agent().($agent); |
| 330 |
$self->{ua}->env_proxyscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/env_proxy().; |
| 331 |
my $cookie_jar = HTTP::Cookies->newscip-perl cpan perl-project 0.0.0 HTTP/Cookies/new().( |
| 332 |
file => COOKIE_FILE, |
| 333 |
autosave => 1, |
| 334 |
); |
| 335 |
$self->{ua}->cookie_jarscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/cookie_jar().($cookie_jar); |
| 336 |
return $self; |
| 337 |
} |
| 338 |
|
| 339 |
=head1 ACCESSORS |
| 340 |
|
| 341 |
=cut |
| 342 |
|
| 343 |
=head2 host |
| 344 |
|
| 345 |
my $url = $mvs->host('www.wikipediea.org'); |
| 346 |
|
| 347 |
my $url = $mvs->host('www.wikitravel.org'); |
| 348 |
|
| 349 |
The C<host> is the name of the Mediawiki server from which you want to |
| 350 |
obtain content, and to which your submissions will be made. There is no |
| 351 |
default. This has to be set before attempting to use any of the methods |
| 352 |
which attempt to access the server. |
| 353 |
|
| 354 |
B<Side Effects:> |
| 355 |
|
| 356 |
=over 4 |
| 357 |
|
| 358 |
=item Server defaults |
| 359 |
|
| 360 |
If WWW::Mediawiki::Client knows about the path settings for the Mediawiki |
| 361 |
installation you are trying to use then the various path fields will also |
| 362 |
be set as a side-effect. |
| 363 |
|
| 364 |
=item Trailing slashes |
| 365 |
|
| 366 |
Any trailing slashes are deleted I<before> the value of C<host> is set. |
| 367 |
|
| 368 |
=back |
| 369 |
|
| 370 |
=cut |
| 371 |
|
| 372 |
sub hostscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/host(). { |
| 373 |
my ($self, $host) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 374 |
if ($host) { |
| 375 |
$host =~ s{/*$}{}; # remove any trailing /s |
| 376 |
$self->{host} = $host; |
| 377 |
my $defaults = $DEFAULTS{$host}; |
| 378 |
foreach my $k (keysscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/keys(). %$defaults) { |
| 379 |
$self->{$k} = $defaults->{$k}; |
| 380 |
} |
| 381 |
} |
| 382 |
return $self->{host}; |
| 383 |
} |
| 384 |
|
| 385 |
=head2 protocol |
| 386 |
|
| 387 |
my $url = $mvs->protocol('www.wikipediea.org'); |
| 388 |
|
| 389 |
my $url = $mvs->protocol('www.wikitravel.org'); |
| 390 |
|
| 391 |
The C<protocol> is the protocol used by the Mediawiki server from which you |
| 392 |
want to obtain content, and to which your submissions will be made. It can |
| 393 |
be one of C<http> or C<https> with the default value being http. |
| 394 |
|
| 395 |
B<Side Effects:> |
| 396 |
|
| 397 |
=over 4 |
| 398 |
|
| 399 |
=item Server defaults |
| 400 |
|
| 401 |
If WWW::Mediawiki::Client knows about the settings for the Mediawiki |
| 402 |
installation you are trying to use then the various path fields will also |
| 403 |
be set as a side-effect. |
| 404 |
|
| 405 |
=back |
| 406 |
|
| 407 |
=cut |
| 408 |
|
| 409 |
sub protocolscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/protocol(). { |
| 410 |
my ($self, $protocol) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 411 |
if ($protocol) { |
| 412 |
WWW::Mediawiki::Client::URLConstructionException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/URLConstructionException/throw().( |
| 413 |
"The protocol must be either 'http' or 'https'." |
| 414 |
. "You specified $protocol." ) |
| 415 |
unless $protocol =~ m/^http(s){0,1}$/; |
| 416 |
$self->{protocol} = $protocol; |
| 417 |
} |
| 418 |
return $self->{protocol} || PROTOCOL; |
| 419 |
} |
| 420 |
|
| 421 |
=head2 language_code |
| 422 |
|
| 423 |
my $lang = $mvs->language_code($lang); |
| 424 |
|
| 425 |
Most Mediawiki projects have multiple language versions. This field can be |
| 426 |
set to target a particular language version of the project the client is |
| 427 |
set up to address. When the C<filename_to_url> and C<pagename_to_url> methods |
| 428 |
encounter the text '__LANG__' in any part of their constructed URL the |
| 429 |
C<language_code> will be substituted. |
| 430 |
|
| 431 |
C<language_code> defaults to 'en'. |
| 432 |
|
| 433 |
=cut |
| 434 |
|
| 435 |
sub language_codescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/language_code(). { |
| 436 |
my ($self, $char) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 437 |
$self->{language_code} = $char if $char; |
| 438 |
$self->{language_code} = LANGUAGE_CODE |
| 439 |
unless $self->{language_code}; |
| 440 |
return $self->{language_code}; |
| 441 |
} |
| 442 |
|
| 443 |
=head2 space_substitute |
| 444 |
|
| 445 |
my $char = $mvs->space_substitute($char); |
| 446 |
|
| 447 |
Mediawiki allows article names to have spaces, for instance the default |
| 448 |
Meidawiki main page is called "Main Page". The spaces need to be converted |
| 449 |
for the URL, and to avoid the normal but somewhat difficult to read URL |
| 450 |
escape the Mediawiki software substitutes some other character. Wikipedia |
| 451 |
uses a '+', as in "Main+Page" and Wikitravel uses a '_' as in "Main_page". |
| 452 |
WWW::Mediawiki::Client always writes wiki files using the '_', but converts |
| 453 |
them to whatever the C<space_substitute> is set to for the URL. |
| 454 |
|
| 455 |
B<Throws:> |
| 456 |
|
| 457 |
=over |
| 458 |
|
| 459 |
=item WWW::Mediawiki::Client::URLConstructionException |
| 460 |
|
| 461 |
=back |
| 462 |
|
| 463 |
=cut |
| 464 |
|
| 465 |
sub space_substitutescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/space_substitute(). { |
| 466 |
my ($self, $char) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 467 |
if ($char) { |
| 468 |
WWW::Mediawiki::Client::URLConstructionException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/URLConstructionException/throw().( |
| 469 |
"Illegal Character in space_substitute $char" ) |
| 470 |
if $char =~ /[\&\?\=\\\/]/; |
| 471 |
$self->{space_substitute} = $char; |
| 472 |
} |
| 473 |
$self->{space_substitute} = SPACE_SUBSTITUTE |
| 474 |
unless $self->{space_substitute}; |
| 475 |
return $self->{space_substitute}; |
| 476 |
} |
| 477 |
|
| 478 |
=head2 escape_filenames |
| 479 |
|
| 480 |
my $char = $mvs->escape_filenames($do_escape); |
| 481 |
|
| 482 |
Mediawiki allows article names to be in UTF-8 and most international |
| 483 |
Wikipedias use this feature. That leads us to UTF-8 encoded file names |
| 484 |
and not all filesystems can handle them. So you can set this option to |
| 485 |
some true value to make all your local file names with wiki articles |
| 486 |
URL-escaped. |
| 487 |
|
| 488 |
=cut |
| 489 |
|
| 490 |
sub escape_filenamesscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/escape_filenames(). { |
| 491 |
my ($self, $do_escape) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 492 |
if ($do_escape) { |
| 493 |
$self->{escape_filenames} = $do_escape; |
| 494 |
} elsif (!definedscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/defined(). $self->{escape_filenames}) { |
| 495 |
$self->{escape_filenames} = 0; |
| 496 |
} |
| 497 |
|
| 498 |
return $self->{escape_filenames}; |
| 499 |
} |
| 500 |
|
| 501 |
=head2 wiki_path |
| 502 |
|
| 503 |
my $path = $mvs->wiki_path($path); |
| 504 |
|
| 505 |
C<wiki_path> is the path to the php page which handles all request to |
| 506 |
edit or submit a page, or to login. If you are using a Mediawiki site |
| 507 |
which WWW::Mediawiki::Client knows about this will be set for you when you |
| 508 |
set the C<host>. Otherwise it defaults to the 'wiki/wiki.phtml' which is |
| 509 |
what you'll get if you follow the installation instructions that some with |
| 510 |
Mediawiki. |
| 511 |
|
| 512 |
B<Side effects> |
| 513 |
|
| 514 |
=over |
| 515 |
|
| 516 |
=item Leading slashes |
| 517 |
|
| 518 |
Leading slashes in any incoming value will be stripped. |
| 519 |
|
| 520 |
=back |
| 521 |
|
| 522 |
=cut |
| 523 |
|
| 524 |
sub wiki_pathscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/wiki_path(). { |
| 525 |
my ($self, $wiki_path) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 526 |
if ($wiki_path) { |
| 527 |
$wiki_path =~ s{^/*}{}; # strip leading slashes |
| 528 |
$self->{wiki_path} = $wiki_path; |
| 529 |
} |
| 530 |
$self->{wiki_path} = WIKI_PATH |
| 531 |
unless $self->{wiki_path}; |
| 532 |
return $self->{wiki_path}; |
| 533 |
} |
| 534 |
|
| 535 |
=head2 encoding |
| 536 |
|
| 537 |
my $encoding = $mvs->encoding($encoding); |
| 538 |
|
| 539 |
C<encoding> is the charset in which the Mediawiki server expects uploaded |
| 540 |
content to be encoded. This should be set the first time you use do_login. |
| 541 |
|
| 542 |
=cut |
| 543 |
|
| 544 |
sub encodingscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/encoding(). { |
| 545 |
my ($self, $encoding) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 546 |
$self->{encoding} = $encoding if $encoding; |
| 547 |
return $self->{encoding}; |
| 548 |
} |
| 549 |
|
| 550 |
=head2 username |
| 551 |
|
| 552 |
my $url = $mvs->username($url); |
| 553 |
|
| 554 |
The username to use if WWW::Mediawiki::Client is to log in to the Mediawiki server as a given |
| 555 |
user. |
| 556 |
|
| 557 |
=cut |
| 558 |
|
| 559 |
sub usernamescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/username(). { |
| 560 |
my ($self, $username) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| •561 |
if ($username) { |
| 562 |
$self->{username} = $username; |
| 563 |
$self->use_http_authorization_methodscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/use_http_authorization_method().; |
| 564 |
} |
| 565 |
return $self->{username}; |
| 566 |
} |
| 567 |
|
| 568 |
=head2 password |
| 569 |
|
| 570 |
my $url = $mvs->password($url); |
| 571 |
|
| 572 |
The password to use if WWW::Mediawiki::Client is to log in to the Mediawiki server as a given |
| 573 |
user. Note that this password is sent I<en clair>, so it's probably not a |
| 574 |
good idea to use an important one. |
| 575 |
|
| 576 |
=cut |
| 577 |
|
| 578 |
sub passwordscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/password(). { |
| 579 |
my ($self, $password) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| •580 |
if ($password) { |
| 581 |
$self->{password} = $password; |
| 582 |
$self->use_http_authorization_methodscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/use_http_authorization_method().; |
| 583 |
} |
| 584 |
return $self->{password}; |
| 585 |
} |
| 586 |
|
| •587 |
|
| 588 |
=head2 http_authorization_method |
| 589 |
|
| 590 |
my $method = $mvs->http_authorization_method($method); |
| 591 |
|
| 592 |
The method used for HTTP access to the web server. |
| 593 |
|
| 594 |
= over |
| 595 |
= item 'none' |
| 596 |
|
| 597 |
(Default) Indicates that the server does not use HTTP Authorization. |
| 598 |
Most mediawiki's web servers use this value, which is to say that |
| 599 |
access to the mediawiki software is available to any client, even if |
| 600 |
the mediawiki software itself may further limit privileges. |
| 601 |
|
| 602 |
= item 'Basic' |
| 603 |
|
| 604 |
Use Basic HTTP Authorization. A mediawiki web server which is set up |
| 605 |
to use this option, will not allow the client to talk to the mediawiki |
| 606 |
software unless the username and password is included in the request. |
| 607 |
The mediawiki software might require an additional log in using the |
| 608 |
same information, or it might take the credentials from the web server |
| 609 |
using, e.g. http://www.mediawiki.org/wiki/Extension:AutomaticREMOTE_USER |
| 610 |
|
| 611 |
Basic HTTP Authorization is considered insecure unless used over a |
| 612 |
secure channel such as https. |
| 613 |
|
| 614 |
=back |
| 615 |
|
| 616 |
B<Throws:> |
| 617 |
|
| 618 |
=over |
| 619 |
|
| 620 |
=item WWW::Mediawiki::Client::URLConstructionException |
| 621 |
|
| 622 |
=back |
| 623 |
|
| 624 |
=cut |
| 625 |
|
| 626 |
sub http_authorization_methodscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/http_authorization_method(). { |
| 627 |
my ($self, $method) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 628 |
if ($method) { |
| 629 |
WWW::Mediawiki::Client::AuthException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/AuthException/throw().( "Unsupported method: $method" ) |
| 630 |
unless $method eq HTTP_AUTHORIZATION_NONE or $method eq HTTP_AUTHORIZATION_BASIC; |
| 631 |
$self->{http_authorization_method} = $method; |
| 632 |
$self->use_http_authorization_methodscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/use_http_authorization_method().; |
| 633 |
} |
| 634 |
$self->{http_authorization_method} = HTTP_AUTHORIZATION_DEFAULT |
| 635 |
unless $self->{http_authorization_method}; |
| 636 |
return $self->{http_authorization_method}; |
| 637 |
} |
| 638 |
|
| 639 |
sub use_http_authorization_methodscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/use_http_authorization_method(). { |
| 640 |
requirescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/require(). MIME::Base64; |
| 641 |
my $self = shiftscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/shift().; |
| 642 |
|
| 643 |
my $headers = $self->{ua}->default_headersscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/default_headers().; |
| 644 |
my $header_name = HTTP_AUTHORIZATION_NAME; |
| 645 |
my $method = $self->http_authorization_methodscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/http_authorization_method().; |
| 646 |
if ($method eq HTTP_AUTHORIZATION_NONE) { |
| 647 |
$headers->remove_headerscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/remove_header().( $header_name ); |
| 648 |
} else { |
| 649 |
$headerscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/header().s->header( $header_name => |
| 650 |
"$method " . |
| 651 |
MIME::Base64::encodescip-perl cpan perl-project 0.0.0 MIME/Base64/encode().($self->usernamescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/username(). . ':' . $self->passwordscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/password()., '') ); |
| 652 |
} |
| 653 |
} |
| 654 |
|
| 655 |
|
| 656 |
=head2 commit_message |
| 657 |
|
| 658 |
my $msg = $mvs->commit_message($msg); |
| 659 |
|
| 660 |
A C<commit_message> must be specified before C<do_commit> can be run. This |
| 661 |
will be used as the comment when submitting pages to the Mediawiki server. |
| 662 |
|
| 663 |
=cut |
| 664 |
|
| 665 |
sub commit_messagescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/commit_message(). { |
| 666 |
my ($self, $msg) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 667 |
$self->{commit_message} = $msg if $msg; |
| 668 |
return $self->{commit_message}; |
| 669 |
} |
| 670 |
|
| 671 |
=head2 watch |
| 672 |
|
| 673 |
my $watch = $mvs->watch($watch); |
| 674 |
|
| 675 |
Mediawiki allows users to add a page to thier watchlist at submit time |
| 676 |
using using the "Watch this page" checkbox. The field C<watch> allows |
| 677 |
commits from this library to add or remove the page in question to/from |
| 678 |
your watchlist. |
| 679 |
|
| 680 |
This is a four-state option: |
| 681 |
|
| 682 |
=over |
| 683 |
|
| 684 |
=item C<OPT_YES> |
| 685 |
|
| 686 |
Always add pages to the watchlist. |
| 687 |
|
| 688 |
=item C<OPT_NO> |
| 689 |
|
| 690 |
Remove pages from the watchlist. |
| 691 |
|
| 692 |
=item C<OPT_KEEP> |
| 693 |
|
| 694 |
Maintain current watched state. |
| 695 |
|
| 696 |
=item C<OPT_DEFAULT> (default) |
| 697 |
|
| 698 |
Adhere to user profile default on the server. Watched pages will |
| 699 |
always remain watched, and all other pages will be watched if the |
| 700 |
"watch all pages by default" option is enabled in the user profile. |
| 701 |
|
| 702 |
=back |
| 703 |
|
| 704 |
B<Throws:> |
| 705 |
|
| 706 |
=over |
| 707 |
|
| 708 |
=item WWW::Mediawiki::Client::InvalidOptionException |
| 709 |
|
| 710 |
=back |
| 711 |
|
| 712 |
=cut |
| 713 |
|
| 714 |
sub watchscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/watch(). { |
| 715 |
my ($self, $watch) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 716 |
if (definedscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/defined().($watch)) { |
| 717 |
$self->_option_verifyscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_option_verify().('watch', $watch, |
| 718 |
[OPT_YES, OPT_NO, OPT_KEEP, OPT_DEFAULT]); |
| 719 |
$self->{watch} = $watch; |
| 720 |
} |
| 721 |
$self->{watch} = WATCH_DEFAULT unless definedscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/defined(). $self->{watch}; |
| 722 |
return $self->{watch}; |
| 723 |
} |
| 724 |
|
| 725 |
=head2 minor_edit |
| 726 |
|
| 727 |
my $minor = $mvs->minor_edit($minor); |
| 728 |
|
| 729 |
Mediawiki allows users to mark some of their edits as minor using the "This |
| 730 |
is a minor edit" checkbox. The field C<minor_edit> allows a commit from |
| 731 |
the mediawiki client to be marked as a minor edit. |
| 732 |
|
| 733 |
This is a three-state option: |
| 734 |
|
| 735 |
=over |
| 736 |
|
| 737 |
=item C<OPT_YES> |
| 738 |
|
| 739 |
Always declare change as minor. |
| 740 |
|
| 741 |
=item C<OPT_NO> |
| 742 |
|
| 743 |
Never declare change as minor. |
| 744 |
|
| 745 |
=item C<OPT_DEFAULT> (default) |
| 746 |
|
| 747 |
Adhere to user profile default on the server. Edits will be marked |
| 748 |
as minor if the "minor changes by default" option is enabled in the |
| 749 |
user profile. |
| 750 |
|
| 751 |
=back |
| 752 |
|
| 753 |
B<Throws:> |
| 754 |
|
| 755 |
=over |
| 756 |
|
| 757 |
=item WWW::Mediawiki::Client::InvalidOptionException |
| 758 |
|
| 759 |
=back |
| 760 |
|
| 761 |
=cut |
| 762 |
|
| 763 |
sub minor_editscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/minor_edit(). { |
| 764 |
my ($self, $minor) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 765 |
if (definedscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/defined().($minor)) { |
| 766 |
$self->_option_verifyscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_option_verify().('minor_edit', $minor, |
| 767 |
[OPT_YES, OPT_NO, OPT_DEFAULT]); |
| 768 |
$self->{minor_edit} = $minor; |
| 769 |
} |
| 770 |
$self->{minor_edit} = MINOR_DEFAULT unless definedscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/defined(). $self->{minor_edit}; |
| 771 |
return $self->{minor_edit}; |
| 772 |
} |
| 773 |
|
| 774 |
=head2 status |
| 775 |
|
| 776 |
my %status = $mvs->status; |
| 777 |
|
| 778 |
This field will be empty until do_update has been called, after which it |
| 779 |
will be set to a hash of C<filename> => C<status> pairs. Each C<status> |
| 780 |
will be one of the following (see CONSTANTS for discriptions): |
| 781 |
|
| •782 |
=over |
| 783 |
|
| 784 |
=item WWW::Mediawiki::Client::STATUS_UNKNOWN; |
| 785 |
|
| 786 |
=item WWW::Mediawiki::Client::STATUS_UNCHANGED; |
| 787 |
|
| 788 |
=item WWW::Mediawiki::Client::STATUS_LOCAL_ADDED; |
| 789 |
|
| 790 |
=item WWW::Mediawiki::Client::STATUS_LOCAL_MODIFIED; |
| 791 |
|
| 792 |
=item WWW::Mediawiki::Client::STATUS_SERVER_MODIFIED; |
| 793 |
|
| 794 |
=item WWW::Mediawiki::Client::STATUS_CONFLICT; |
| 795 |
|
| •796 |
=back |
| 797 |
|
| 798 |
=cut |
| 799 |
|
| 800 |
sub statusscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/status(). { |
| 801 |
my ($self, $arg) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 802 |
WWW::Mediawiki::Client::ReadOnlyFieldException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/ReadOnlyFieldException/throw().( |
| 803 |
"Tried to set read-only field 'status' to $arg.") if $arg; |
| 804 |
return unless definedscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/defined().($self->{status}); |
| 805 |
return $self->{status}; |
| 806 |
} |
| 807 |
|
| 808 |
=head2 site_url DEPRICATED |
| 809 |
|
| 810 |
my $url = $mvs->site_url($url); |
| 811 |
|
| 812 |
The site URL is the base url for reaching the Mediawiki server who's |
| 813 |
content you wish to edit. This field is now depricated in favor of the |
| 814 |
C<host> field which is basically the same thing without the protocol |
| 815 |
string. |
| 816 |
|
| 817 |
|
| 818 |
B<Side Effects:> |
| 819 |
|
| 820 |
=over 4 |
| 821 |
|
| 822 |
=item Server defaults |
| 823 |
|
| 824 |
If WWW::Mediawiki::Client knows about the path settings for the Mediawiki |
| 825 |
installation you are trying to use then the various path fields will also |
| 826 |
be set as a side-effect. |
| 827 |
|
| 828 |
=item Trailing slashes |
| 829 |
|
| 830 |
Any trailing slashes are deleted I<before> the value of C<site_url> is set. |
| 831 |
|
| 832 |
=back |
| 833 |
|
| 834 |
=cut |
| 835 |
|
| 836 |
sub site_urlscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/site_url(). { |
| 837 |
my ($self, $host) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 838 |
my ($pkg, $caller, $line) = callerscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/caller().; |
| 839 |
warnscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/warn(). "Using depricated method 'site_url' at $caller line $line." |
| 840 |
unless $pkg =~ "WWW::Mediawiki::Client"; |
| 841 |
my $protocol = $self->protocolscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/protocol().; |
| 842 |
$host =~ s{^$protocol://}{} if $host; |
| 843 |
$host = $self->hostscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/host().($host); |
| 844 |
return "$protocol://" . $host if $host; |
| 845 |
} |
| 846 |
|
| 847 |
=head1 Instance Methods |
| 848 |
|
| 849 |
=cut |
| 850 |
|
| 851 |
=head2 do_login |
| 852 |
|
| 853 |
$mvs->do_login; |
| 854 |
|
| 855 |
The C<do_login> method operates like the cvs login command. The |
| 856 |
C<host>, C<username>, and C<password> attributes must be set before |
| 857 |
attempting to login. Once C<do_login> has been called successfully any |
| 858 |
successful commit from the same directory will be logged in the Mediawiki |
| 859 |
server as having been done by C<username>. |
| 860 |
|
| 861 |
B<Throws:> |
| 862 |
|
| 863 |
=over |
| 864 |
|
| 865 |
=item WWW::Mediawiki::Client::AuthException |
| 866 |
|
| 867 |
=item WWW::Mediawiki::Client::CookieJarException |
| 868 |
|
| 869 |
=item WWW::Mediawiki::Client::LoginException |
| 870 |
|
| 871 |
=item WWW::Mediawiki::Client::URLConstructionException |
| 872 |
|
| 873 |
=back |
| 874 |
|
| 875 |
=cut |
| 876 |
|
| 877 |
sub do_loginscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/do_login(). { |
| 878 |
my $self = shiftscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/shift().; |
| 879 |
WWW::Mediawiki::Client::URLConstructionException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/URLConstructionException/throw().( |
| 880 |
"No Mediawiki host specified.") |
| 881 |
unless $self->hostscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/host().; |
| 882 |
WWW::Mediawiki::Client::URLConstructionException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/URLConstructionException/throw().( |
| 883 |
"No wiki_path specified.") |
| 884 |
unless $self->wiki_pathscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/wiki_path().; |
| 885 |
WWW::Mediawiki::Client::AuthException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/AuthException/throw().( |
| 886 |
"Must have username and password to login.") |
| 887 |
unless $self->usernamescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/username(). && $self->passwordscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/password().; |
| 888 |
my $host = $self->hostscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/host().; |
| 889 |
my $path = $self->wiki_pathscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/wiki_path().; |
| 890 |
my $lang = $self->language_codescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/language_code().; |
| 891 |
$host =~ s/__LANG__/$lang/; |
| 892 |
$path =~ s/__LANG__/$lang/; |
| •893 |
|
| 894 |
my $protocol = $self->protocolscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/protocol().; |
| 895 |
my $url = "$protocol://$host/$path" |
| 896 |
. "?" . ACTION . "=" . LOGIN |
| 897 |
. "&" . TITLE . "=" . LOGIN_TITLE; |
| 898 |
$self->{ua}->cookie_jarscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/cookie_jar().->clearscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/clear().; |
| 899 |
$self->{ua}->cookie_jarscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/cookie_jar().->savescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/save(). |
| 900 |
or WWW::Mediawiki::Client::CookieJarException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/CookieJarException/throw().( |
| 901 |
"Could not save cookie jar."); |
| •902 |
|
| 903 |
# get login token |
| 904 |
my $res = $self->{ua}->requestscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/request().(GETscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/GET(). $url); |
| 905 |
unless ($res->is_successscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/is_success().) { |
| 906 |
WWW::Mediawiki::Client::LoginException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/LoginException/throw().( |
| 907 |
error => "Could not connect to MediaWiki to get login token.\n", |
| 908 |
res => $res); |
| 909 |
} |
| 910 |
|
| 911 |
my $token; |
| 912 |
$token = $1scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/$1. if $res->contentscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/content().() =~ /input type=['"]hidden['"] name=['"]wpLoginToken['"] value=['"]([a-fA-F0-9]+)['"]/i; |
| 913 |
|
| 914 |
$res = $self->{ua}->requestscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/request().(POSTscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/POST(). $url, |
| 915 |
[ ( |
| 916 |
&USERNAME_NAMEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/USERNAME_NAME(). => $self->usernamescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/username()., |
| 917 |
&PASSWORD_NAMEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/PASSWORD_NAME(). => $self->passwordscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/password()., |
| 918 |
&REMEMBER_NAMEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/REMEMBER_NAME(). => 1, |
| •919 |
&LOGIN_SUBMIT_NAMEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/LOGIN_SUBMIT_NAME(). => &LOGIN_SUBMIT_VALUEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/LOGIN_SUBMIT_VALUE(). |
| 920 |
), definedscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/defined(). $token ? (&LOGIN_TOKENscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/LOGIN_TOKEN(). => $token) : () ] |
| 921 |
); |
| •922 |
|
| 923 |
# success == Mediawiki gave us a Password cookie |
| 924 |
if ($self->{ua}->cookie_jarscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/cookie_jar().->as_stringscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/as_string(). =~ /UserID=/) { |
| 925 |
$self->encodingscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/encoding().($self->_get_server_encodingscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_server_encoding().); |
| 926 |
$self->save_statescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/save_state().; |
| 927 |
$self->{ua}->cookie_jarscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/cookie_jar().->savescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/save(). |
| 928 |
or WWW::Mediawiki::Client::CookieJarException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/CookieJarException/throw().( |
| 929 |
"Could not save cookie jar."); |
| 930 |
return $self; |
| 931 |
} elsif ($res->is_successscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/is_success().) { # got a page, but not what we wanted |
| 932 |
WWW::Mediawiki::Client::LoginException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/LoginException/throw().( |
| 933 |
error => "Login did not work, please check username and password.\n", |
| 934 |
res => $res, |
| 935 |
cookie_jar => $self->{ua}->cookie_jarscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/cookie_jar()., |
| 936 |
); |
| 937 |
} else { # something else went wrong, send all the data in exception |
| 938 |
my $err = "Login to $url failed."; |
| 939 |
WWW::Mediawiki::Client::LoginException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/LoginException/throw().( |
| 940 |
error => $err, |
| 941 |
res => $res, |
| 942 |
cookie_jar => $self->{ua}->cookie_jarscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/cookie_jar()., |
| 943 |
); |
| 944 |
} |
| 945 |
} |
| 946 |
|
| 947 |
=head2 do_li |
| 948 |
|
| 949 |
$mvs->do_li; |
| 950 |
|
| 951 |
An alias for C<do_login>. |
| 952 |
|
| 953 |
=cut |
| 954 |
|
| 955 |
sub do_liscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/do_li(). { |
| 956 |
do_loginscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/do_login().(@_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.); |
| 957 |
} |
| 958 |
|
| 959 |
=head2 do_update |
| 960 |
|
| 961 |
$self->do_update($filename, ...); |
| 962 |
|
| 963 |
The C<do_update> method operates like a much-simplified version of the cvs |
| 964 |
update command. The argument is a list of filenames, whose contents will |
| 965 |
be compared to the version on the WikiMedia server and to a locally stored |
| 966 |
reference copy. Lines which have changed only in the server version will |
| 967 |
be merged into the local version, while lines which have changed in both |
| 968 |
the server and local version will be flagged as possible conflicts, and |
| 969 |
marked as such, somewhate in the manner of cvs (actually this syntax comes |
| 970 |
from the default conflict behavior of VCS::Lite): |
| 971 |
|
| 972 |
********************Start of conflict 1 Insert to Primary, Insert to Secondary ************************************************************ |
| 973 |
|
| 974 |
The line as it appears on the server |
| 975 |
|
| 976 |
**************************************************************************************************** |
| 977 |
|
| 978 |
The line as it appears locally |
| 979 |
********************End of conflict 1******************************************************************************** |
| 980 |
|
| 981 |
After the merging, and conflict marking is complete the server version will |
| 982 |
be copied into the reference version. |
| 983 |
|
| 984 |
If either the reference version or the local version are empty, or if |
| 985 |
either file does not exist they will both be created as a copy of the |
| 986 |
current server version. |
| 987 |
|
| 988 |
B<Throws:> |
| 989 |
|
| 990 |
=over |
| 991 |
|
| 992 |
=item WWW::Mediawiki::Client::URLConstructionException |
| 993 |
|
| 994 |
=item WWW::Mediawiki::Client::FileAccessException |
| 995 |
|
| 996 |
=item WWW::Mediawiki::Client::FileTypeException |
| 997 |
|
| 998 |
=item WWW::Mediawiki::Client::ServerPageException |
| 999 |
|
| 1000 |
=item WWW::Mediawiki::Client::AbsoluteFileNameException |
| 1001 |
|
| 1002 |
=back |
| 1003 |
|
| 1004 |
=cut |
| 1005 |
|
| 1006 |
sub do_updatescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/do_update(). { |
| 1007 |
my ($self, @files) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 1008 |
@files = $self->list_wiki_filesscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/list_wiki_files(). unless @files; |
| 1009 |
WWW::Mediawiki::Client::URLConstructionException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/URLConstructionException/throw().( |
| 1010 |
"No server URL specified.") unless $self->{host}; |
| 1011 |
my %pages; |
| 1012 |
my %dirs; |
| 1013 |
foreach my $filename (@files) { |
| 1014 |
my ($vol, $dirs, $fn) = $self->_check_pathscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_check_path().($filename); |
| 1015 |
my $pagename = $self->filename_to_pagenamescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/filename_to_pagename().($filename); |
| 1016 |
$pages{$filename} = $pagename; |
| 1017 |
$dirs{$filename} = $dirs; |
| 1018 |
} |
| 1019 |
$self->_get_exported_pagesscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_exported_pages().(valuesscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/values(). %pages); |
| 1020 |
foreach my $filename (@files) { |
| 1021 |
my $pagename = $pages{$filename}; |
| 1022 |
my $dirs = $dirs{$filename}; |
| 1023 |
my $status = $self->_update_corescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_update_core().($filename, $pagename, $dirs); |
| 1024 |
$self->{status}->{$filename} = $status; |
| 1025 |
} |
| 1026 |
return $self->statusscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/status().; |
| 1027 |
} |
| 1028 |
|
| 1029 |
sub _update_corescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_update_core(). { |
| 1030 |
my ($self, $filename, $pagename, $dirs) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 1031 |
my $sv = $self->get_server_pagescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/get_server_page().($pagename); |
| 1032 |
my $lv = $self->get_local_pagescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/get_local_page().($filename); |
| 1033 |
my $rv = $self->_get_reference_pagescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_reference_page().($filename); |
| 1034 |
my $nv = $self->_mergescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_merge().($filename, $rv, $sv, $lv); |
| 1035 |
my $status = $self->_get_update_statusscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_update_status().($rv, $sv, $lv, $nv); |
| 1036 |
return unless $status; # nothing changes, nothing to do |
| 1037 |
return $status |
| 1038 |
if $status eq STATUS_LOCAL_ADDED |
| 1039 |
or $status eq STATUS_UNKNOWN |
| 1040 |
or $status eq STATUS_UNCHANGED; |
| 1041 |
# save the newly retrieved and/or merged version as our local copy |
| 1042 |
my @dirs = splitscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/split(). '/', $dirs; |
| 1043 |
for my $d (@dirs) { |
| 1044 |
mkdirscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/mkdir(). $d; |
| 1045 |
chdirscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/chdir(). $d; |
| 1046 |
} |
| 1047 |
for (@dirs) { |
| 1048 |
chdirscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/chdir(). '..'; |
| 1049 |
} |
| 1050 |
openscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/open(). OUT, ">:utf8", $filename or WWW::Mediawiki::Client::FileAccessException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/FileAccessException/throw().( |
| 1051 |
"Cannot open $filename for writing."); |
| 1052 |
print OUT $nv; |
| 1053 |
# save the server version out as the reference file |
| 1054 |
$filename = $self->_get_ref_filenamescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_ref_filename().($filename); |
| 1055 |
openscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/open(). OUT, ">:utf8", $filename or WWW::Mediawiki::Client::FileAccessException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/FileAccessException/throw().( |
| 1056 |
"Cannot open $filename for writing."); |
| 1057 |
print OUT $sv; |
| 1058 |
close OUT; |
| 1059 |
return $status; |
| 1060 |
} |
| 1061 |
|
| 1062 |
=head2 do_up |
| 1063 |
|
| 1064 |
An alias for C<do_update>. |
| 1065 |
|
| 1066 |
=cut |
| 1067 |
|
| 1068 |
sub do_upscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/do_up(). { |
| 1069 |
do_updatescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/do_update().(@_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.); |
| 1070 |
} |
| 1071 |
|
| 1072 |
=head2 do_commit |
| 1073 |
|
| 1074 |
$self->do_commit($filename); |
| 1075 |
|
| 1076 |
As with C<do_update> the C<do_commit> method operates like a much |
| 1077 |
simplified version of the cvs commit command. Again, the argument is a |
| 1078 |
filename. In keeping with the operation of cvs, C<do_commit> does not |
| 1079 |
automatically do an update, but does check the server version against the |
| 1080 |
local reference copy, throwing an error if the server version has changed, |
| 1081 |
thus forcing the user to do an update. A different error is thrown if the |
| 1082 |
conflict pattern sometimes created by C<do_update> is found. |
| 1083 |
|
| 1084 |
After the error checking is done the local copy is submitted to the server, |
| 1085 |
and, if all goes well, copied to the local reference version. |
| 1086 |
|
| 1087 |
B<Throws:> |
| 1088 |
|
| 1089 |
=over |
| 1090 |
|
| 1091 |
=item WWW::Mediawiki::Client::CommitMessageException |
| 1092 |
|
| 1093 |
=item WWW::Mediawiki::Client::ConflictsPresentException |
| 1094 |
|
| 1095 |
=item WWW::Mediawiki::Client::FileAccessException |
| 1096 |
|
| 1097 |
=item WWW::Mediawiki::Client::FileTypeException |
| 1098 |
|
| 1099 |
=item WWW::Mediawiki::Client::URLConstructionException |
| 1100 |
|
| 1101 |
=item WWW::Mediawiki::Client::UpdateNeededException |
| 1102 |
|
| 1103 |
=item WWW::Mediawiki::Client::InvalidOptionException |
| 1104 |
|
| 1105 |
=back |
| 1106 |
|
| 1107 |
=cut |
| 1108 |
|
| 1109 |
sub do_commitscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/do_commit(). { |
| 1110 |
my ($self, $filename) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 1111 |
WWW::Mediawiki::Client::CommitMessageException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/CommitMessageException/throw().( |
| 1112 |
"No commit message specified") |
| 1113 |
unless $self->{commit_message}; |
| 1114 |
# Perform the actual upload: |
| 1115 |
my ($res, $text) = $self->_upload_filescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_upload_file().($filename, 1); |
| 1116 |
# save the local version as the reference version |
| 1117 |
my $refname = $self->_get_ref_filenamescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_ref_filename().($filename); |
| 1118 |
openscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/open(). OUT, ">:utf8", $refname |
| 1119 |
or WWW::Mediawiki::Client::FileAccessException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/FileAccessException/throw().( |
| 1120 |
"Cannot open $refname for writing."); |
| 1121 |
print OUT $text; |
| 1122 |
close OUT; |
| 1123 |
} |
| 1124 |
|
| 1125 |
=head2 do_com |
| 1126 |
|
| 1127 |
This is an alias for C<do_commit>. |
| 1128 |
|
| 1129 |
=cut |
| 1130 |
|
| 1131 |
sub do_comscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/do_com(). { |
| 1132 |
do_commitscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/do_commit().(@_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.); |
| 1133 |
} |
| 1134 |
|
| 1135 |
=head2 do_preview |
| 1136 |
|
| 1137 |
$self->do_preview($filename); |
| 1138 |
|
| 1139 |
The C<do_preview> method is a non-writing version of the C<do_commit> |
| 1140 |
method. It uploads the given filename to test its formatting. Its |
| 1141 |
behaviour and arguments are identical to C<do_commit>. |
| 1142 |
|
| 1143 |
The behaviour of C<do_preview> is currently based on the environment. |
| 1144 |
If C<MVS_BROWSER> is set, this program (typically a web browser) will |
| 1145 |
be launched on a temporary file. Otherwise, the preview will be saved |
| 1146 |
to the file specified by the C<MVS_PREVIEW> variable, or preview.html |
| 1147 |
if this is unset. This behaviour is considered a prototype for future |
| 1148 |
functionality, and is C<subject to change> in the near future. |
| 1149 |
|
| 1150 |
Returns the name of the preview file, or undef if the file was sent to |
| 1151 |
a web browser. |
| 1152 |
|
| 1153 |
B<Throws:> |
| 1154 |
|
| 1155 |
=over |
| 1156 |
|
| 1157 |
=item WWW::Mediawiki::Client::ConflictsPresentException |
| 1158 |
|
| 1159 |
=item WWW::Mediawiki::Client::FileAccessException |
| 1160 |
|
| 1161 |
=item WWW::Mediawiki::Client::FileTypeException |
| 1162 |
|
| 1163 |
=item WWW::Mediawiki::Client::URLConstructionException |
| 1164 |
|
| 1165 |
=item WWW::Mediawiki::Client::UpdateNeededException |
| 1166 |
|
| 1167 |
=back |
| 1168 |
|
| 1169 |
=cut |
| 1170 |
|
| 1171 |
sub do_previewscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/do_preview(). { |
| 1172 |
my ($self, $filename) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 1173 |
my ($response) = $self->_upload_filescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_upload_file().($filename, 0); |
| 1174 |
my $url = encode_entitiesscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/encode_entities().($response->requestscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/request().->uriscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/uri().); |
| 1175 |
my $content = $response->decoded_contentscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/decoded_content().; |
| 1176 |
$content =~ s#<head>#$&<base href="$url"/>#; |
| 1177 |
my $browser = $ENVscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`%ENV`.{MVS_BROWSER}; |
| 1178 |
if (definedscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/defined().($browser)) { |
| 1179 |
my $fh = new File::Temp(UNLINK => 1, SUFFIX => '.html'); |
| 1180 |
printscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/print(). $fh Encode::encode_utf8scip-perl cpan perl-project 0.0.0 Encode/encode_utf8().($content); |
| 1181 |
$fh->closescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/close().; |
| 1182 |
systemscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/system().($browser, $fh->filenamescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/filename().); |
| 1183 |
return undef; |
| 1184 |
} |
| 1185 |
my $preview = $ENVscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`%ENV`.{MVS_PREVIEW}; |
| 1186 |
$preview = 'preview.html' unless definedscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/defined().($preview); |
| 1187 |
openscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/open().(PREVIEW, '>', $preview) |
| 1188 |
or WWW::Mediawiki::Client::FileAccessException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/FileAccessException/throw().( |
| 1189 |
"Cannot open $preview for writing."); |
| 1190 |
print PREVIEW $content; |
| 1191 |
closescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/close().(PREVIEW) or WWW::Mediawiki::Client::FileAccessException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/FileAccessException/throw().( |
| 1192 |
"Cannot close $preview."); |
| 1193 |
print STDERR "Saved preview: $preview\n"; |
| 1194 |
return $preview; |
| 1195 |
} |
| 1196 |
|
| 1197 |
=head2 do_clean |
| 1198 |
|
| 1199 |
$self->do_clean; |
| 1200 |
|
| 1201 |
Removes all reference files under the current directory that have no |
| 1202 |
corresponding Wiki files. |
| 1203 |
|
| 1204 |
B<Throws:> |
| 1205 |
|
| 1206 |
=over |
| 1207 |
|
| 1208 |
=item WWW::Mediawiki::Client::FileAccessException |
| 1209 |
|
| 1210 |
=back |
| 1211 |
|
| 1212 |
=cut |
| 1213 |
|
| 1214 |
sub do_cleanscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/do_clean(). { |
| 1215 |
my ($self) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 1216 |
|
| 1217 |
my $dir = File::Spec->curdirscip-perl cpan perl-project 0.0.0 File/Spec/curdir().(); |
| 1218 |
findscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/find().(sub { |
| 1219 |
return unless m/^\..*\.ref\.wiki\z/s; |
| 1220 |
|
| 1221 |
my $name = $File::Find::namescip-perl cpan perl-project 0.0.0 File/Find/$name.; |
| 1222 |
$name = File::Spec->abs2relscip-perl cpan perl-project 0.0.0 File/Spec/abs2rel().($name); |
| 1223 |
|
| 1224 |
my $wiki = $self->_ref_to_filenamescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_ref_to_filename().($name); |
| 1225 |
return if -e $wiki; |
| 1226 |
|
| 1227 |
warnscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/warn(). "Deleting: $name\n"; |
| 1228 |
unlinkscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/unlink().($name) |
| 1229 |
or WWW::Mediawiki::Client::FileAccessException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/FileAccessException/throw().( |
| 1230 |
"Cannot delete reference file $name"); |
| 1231 |
}, $dir); |
| 1232 |
} |
| 1233 |
|
| 1234 |
=head2 save_state |
| 1235 |
|
| 1236 |
$mvs->save_state; |
| 1237 |
|
| 1238 |
Saves the current state of the wmc object in the current working directory. |
| 1239 |
|
| 1240 |
B<Throws:> |
| 1241 |
|
| 1242 |
=over |
| 1243 |
|
| 1244 |
=item WWW::Mediawiki::Client::FileAccessException |
| 1245 |
|
| 1246 |
=back |
| 1247 |
|
| 1248 |
=cut |
| 1249 |
|
| 1250 |
sub save_statescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/save_state(). { |
| 1251 |
my $self = shiftscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/shift().; |
| 1252 |
my $conf = CONFIG_FILE; |
| 1253 |
my %init; |
| 1254 |
foreach my $attr (SAVED_ATTRIBUTES) { |
| 1255 |
$init{$attr} = $self->$attrscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/$attr().; |
| 1256 |
} |
| 1257 |
openscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/open(). OUT, ">:utf8", $conf or WWW::Mediawiki::Client::FileAccessException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/FileAccessException/throw().( |
| 1258 |
"Cannot write to config file, $conf."); |
| 1259 |
print OUT Dumperscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/Dumper().(\%init); |
| 1260 |
close OUT; |
| 1261 |
} |
| 1262 |
|
| 1263 |
=head2 load_state |
| 1264 |
|
| 1265 |
$mvs = $mvs->load_state; |
| 1266 |
|
| 1267 |
Loads the state of the wmc object from that saved in the current working |
| 1268 |
directory. |
| 1269 |
|
| 1270 |
B<Throws:> |
| 1271 |
|
| 1272 |
=over |
| 1273 |
|
| 1274 |
=item WWW::Mediawiki::Client::CorruptedConfigFileException |
| 1275 |
|
| 1276 |
=back |
| 1277 |
|
| 1278 |
=cut |
| 1279 |
|
| 1280 |
sub load_statescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/load_state(). { |
| 1281 |
my $self = shiftscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/shift().; |
| 1282 |
my $config = CONFIG_FILE; |
| 1283 |
return $self unless -e $config; |
| 1284 |
our $VAR1scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/$VAR1.; |
| 1285 |
do $config or |
| 1286 |
WWW::Mediawiki::Client::CorruptedConfigFileException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/CorruptedConfigFileException/throw().( |
| 1287 |
"Could not read config file: $config."); |
| 1288 |
my %init = %$VAR1scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/$VAR1.; |
| 1289 |
foreach my $attr (SAVED_ATTRIBUTES) { |
| 1290 |
$self->$attrscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/$attr().($init{$attr}); |
| 1291 |
} |
| 1292 |
return $self; |
| 1293 |
} |
| 1294 |
|
| 1295 |
=head2 get_server_page |
| 1296 |
|
| 1297 |
my $wikitext = $mvs->get_server_page($pagename); |
| 1298 |
|
| 1299 |
Returns the wikitext of the given Mediawiki page name. |
| 1300 |
|
| 1301 |
B<Throws:> |
| 1302 |
|
| 1303 |
=over |
| 1304 |
|
| 1305 |
=item WWW::Mediawiki::Client::ServerPageException |
| 1306 |
|
| 1307 |
=back |
| 1308 |
|
| 1309 |
=cut |
| 1310 |
|
| 1311 |
sub get_server_pagescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/get_server_page(). { |
| 1312 |
my ($self, $pagename) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 1313 |
|
| 1314 |
my $export = deletescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/delete(). $self->{export}->{$pagename}; |
| 1315 |
return $export if definedscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/defined().($export); |
| 1316 |
|
| 1317 |
my $url = $self->pagename_to_urlscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/pagename_to_url().($pagename, EDIT); |
| 1318 |
my $res = $self->{ua}->getscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/get().($url); |
| 1319 |
WWW::Mediawiki::Client::ServerPageException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/ServerPageException/throw().( |
| 1320 |
error => "Couldn't fetch \"$pagename\" from the server.", |
| 1321 |
res => $res, |
| 1322 |
) unless $res->is_successscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/is_success().; |
| 1323 |
my $doc = $res->decoded_contentscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/decoded_content().; |
| 1324 |
my $text = $self->_get_wiki_textscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_wiki_text().($doc); |
| •1325 |
$self->{edit}->{start} = $self->_get_start_datescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_start_date().($doc); |
| 1326 |
$self->{edit}->{date} = $self->_get_edit_datescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_edit_date().($doc); |
| 1327 |
$self->{edit}->{token} = $self->_get_edit_tokenscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_edit_token().($doc); |
| 1328 |
$self->{edit}->{watch_now} = $self->_get_edit_is_watchingscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_edit_is_watching().($doc); |
| 1329 |
$self->{edit}->{def_watch} = $self->_get_edit_watch_defaultscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_edit_watch_default().($doc); |
| 1330 |
$self->{edit}->{def_minor} = $self->_get_edit_minor_defaultscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_edit_minor_default().($doc); |
| 1331 |
my $headline = Encode::encodescip-perl cpan perl-project 0.0.0 Encode/encode().("utf8", $self->_get_page_headlinescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_page_headline().($doc)); |
| 1332 |
my $expected = lcscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/lc(). $pagename; |
| •1333 |
my $expectedfile = $expected; |
| 1334 |
$expectedfile =~ s/^image:/file:/; |
| 1335 |
unless (lcscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/lc().($headline) =~ /\Q$expected\E$/ or lcscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/lc().($headline) =~ /\Q$expectedfile\E$/) { |
| 1336 |
WWW::Mediawiki::Client::ServerPageException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/ServerPageException/throw().( |
| 1337 |
error => "The server could not resolve the page name |
| 1338 |
'$pagename', but responded that it was '$headline'.", |
| 1339 |
res => $res, |
| 1340 |
) if ($headline && $headline =~ /^Editing /); |
| 1341 |
WWW::Mediawiki::Client::ServerPageException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/ServerPageException/throw().( |
| 1342 |
error => "Error message from the server: '$headline'.", |
| 1343 |
res => $res, |
| 1344 |
) if ($headline); |
| 1345 |
WWW::Mediawiki::Client::ServerPageException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/ServerPageException/throw().( |
| •1346 |
error => "Could not find page headline.", |
| 1347 |
res => $res, |
| 1348 |
); |
| 1349 |
} |
| 1350 |
chompscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/chomp(). $text; |
| 1351 |
return $text; |
| 1352 |
} |
| 1353 |
|
| 1354 |
=head2 get_local_page |
| 1355 |
|
| 1356 |
my $wikitext = $mvs->get_local_page($filename); |
| 1357 |
|
| 1358 |
Returns the wikitext from the given local file; |
| 1359 |
|
| 1360 |
B<Throws:> |
| 1361 |
|
| 1362 |
=over |
| 1363 |
|
| 1364 |
=item WWW::Mediawiki::Client::FileAccessException |
| 1365 |
|
| 1366 |
=item WWW::Mediawiki::Client::FileTypeException |
| 1367 |
|
| 1368 |
=item WWW::Mediawiki::Client::AbsoluteFileNameException |
| 1369 |
|
| 1370 |
=back |
| 1371 |
|
| 1372 |
=cut |
| 1373 |
|
| 1374 |
sub get_local_pagescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/get_local_page(). { |
| 1375 |
my ($self, $filename) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 1376 |
$self->_check_pathscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_check_path().($filename); |
| 1377 |
return '' unless -e $filename; |
| 1378 |
openscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/open(). IN, "<:utf8", $filename or |
| 1379 |
WWW::Mediawiki::Client::FileAccessException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/FileAccessException/throw().( |
| 1380 |
"Cannot open $filename."); |
| 1381 |
local $/scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`$/`.; |
| 1382 |
my $text = <IN>; |
| 1383 |
close IN; |
| 1384 |
return $text; |
| 1385 |
} |
| 1386 |
|
| 1387 |
=head2 pagename_to_url |
| 1388 |
|
| 1389 |
my $url = $mvs->pagename_to_url($pagename); |
| 1390 |
|
| 1391 |
Returns the url at which a given pagename will be found on the Mediawiki |
| 1392 |
server to which this instance of points. |
| 1393 |
|
| 1394 |
B<Throws:> |
| 1395 |
|
| 1396 |
=over |
| 1397 |
|
| 1398 |
=item WWW::Mediawiki::Client::URLConstructionException; |
| 1399 |
|
| 1400 |
=back |
| 1401 |
|
| 1402 |
=cut |
| 1403 |
|
| 1404 |
sub pagename_to_urlscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/pagename_to_url(). { |
| 1405 |
my ($self, $name, $action) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 1406 |
WWW::Mediawiki::Client::URLConstructionException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/URLConstructionException/throw().( |
| 1407 |
error => 'No action supplied.', |
| 1408 |
) unless $action; |
| 1409 |
WWW::Mediawiki::Client::URLConstructionException->throwscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/URLConstructionException/throw().( |
| 1410 |
error => "Page name $name ends with '.wiki'.", |
| 1411 |
) if $name =~ /.wiki$/; |
| 1412 |
my $char = $self->space_substitutescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/space_substitute().; |
| 1413 |
$name =~ s/ /$char/; |
| •1414 |
|
| 1415 |
# ampersand is escaped in the URL |
| 1416 |
$name =~ s/&/%26/; |
| 1417 |
|
| 1418 |
my $lang = $self->language_codescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/language_code().; |
| 1419 |
my $host = $self->hostscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/host().; |
| 1420 |
$host =~ s/__LANG__/$lang/g; |
| 1421 |
my $wiki_path = $self->wiki_pathscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/wiki_path().; |
| 1422 |
$wiki_path =~ s/__LANG__/$lang/g; |
| 1423 |
my $protocol = $self->protocolscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/protocol().; |
| 1424 |
return "$protocol://$host/$wiki_path?" . ACTION . "=$action&" . TITLE . "=$name"; |
| 1425 |
} |
| 1426 |
|
| 1427 |
=head2 filename_to_pagename |
| 1428 |
|
| 1429 |
my $pagename = $mvs->filname_to_pagename($filename); |
| 1430 |
|
| 1431 |
Returns the cooresponding server page name given a filename. |
| 1432 |
|
| 1433 |
B<Throws:> |
| 1434 |
|
| 1435 |
=over |
| 1436 |
|
| 1437 |
=item WWW::Mediawiki::Client::AbsoluteFileNameException |
| 1438 |
|
| 1439 |
=item WWW::Mediawiki::Client::FileTypeException |
| 1440 |
|
| 1441 |
=back |
| 1442 |
|
| 1443 |
=cut |
| 1444 |
|
| 1445 |
sub filename_to_pagenamescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/filename_to_pagename(). { |
| 1446 |
my ($self, $name) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 1447 |
$self->_check_pathscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_check_path().($name); |
| 1448 |
$name =~ s/.wiki$//; |
| 1449 |
|
| 1450 |
$self->{escape_filenames} and $name = decodescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/decode().('UTF-8', URI::Escape::uri_unescapescip-perl cpan perl-project 0.0.0 URI/Escape/uri_unescape().($name)); |
| 1451 |
|
| 1452 |
$name =~ s/_/ /g; |
| 1453 |
return ucfirstscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/ucfirst(). $name; |
| 1454 |
} |
| 1455 |
|
| 1456 |
=head2 filename_to_url |
| 1457 |
|
| 1458 |
my $pagename = $mvs->filname_to_url($filename); |
| 1459 |
|
| 1460 |
Returns the cooresponding server URL given a filename. |
| 1461 |
|
| 1462 |
B<Throws:> |
| 1463 |
|
| 1464 |
=over |
| 1465 |
|
| 1466 |
=item WWW::Mediawiki::Client::AbsoluteFileNameException |
| 1467 |
|
| 1468 |
=item WWW::Mediawiki::Client::FileTypeException |
| 1469 |
|
| 1470 |
=back |
| 1471 |
|
| 1472 |
=cut |
| 1473 |
|
| 1474 |
sub filename_to_urlscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/filename_to_url(). { |
| 1475 |
my ($self, $name, $action) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 1476 |
$name = $self->filename_to_pagenamescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/filename_to_pagename().($name); |
| 1477 |
return $self->pagename_to_urlscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/pagename_to_url().($name, $action); |
| 1478 |
} |
| 1479 |
|
| 1480 |
=head2 pagename_to_filename |
| 1481 |
|
| 1482 |
my $filename = $mvs->pagename_to_filename($pagename); |
| 1483 |
|
| 1484 |
Returns a local filename which cooresponds to the given Mediawiki page |
| 1485 |
name. |
| 1486 |
|
| 1487 |
=cut |
| 1488 |
|
| 1489 |
sub pagename_to_filenamescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/pagename_to_filename(). { |
| 1490 |
my ($self, $name) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 1491 |
$name =~ s/ /_/; |
| 1492 |
|
| 1493 |
$self->{escape_filenames} and $name = URI::Escape::uri_escape_utf8scip-perl cpan perl-project 0.0.0 URI/Escape/uri_escape_utf8().($name); |
| 1494 |
|
| 1495 |
$name .= '.wiki'; |
| 1496 |
return $name; |
| 1497 |
} |
| 1498 |
|
| 1499 |
=head2 url_to_filename |
| 1500 |
|
| 1501 |
my $filename = $mvs->url_to_filename($url); |
| 1502 |
|
| 1503 |
Returns the local filename which cooresponds to a given URL. |
| 1504 |
|
| 1505 |
=cut |
| 1506 |
|
| 1507 |
sub url_to_filenamescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/url_to_filename(). { |
| 1508 |
my ($self, $url) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 1509 |
my $char = '\\' . $self->space_substitutescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/space_substitute().; |
| 1510 |
$url =~ s/$char/_/g; |
| 1511 |
my $title = TITLE; |
| 1512 |
$url =~ m/&$title=([^&]*)/; |
| 1513 |
return "$1.wiki"; |
| 1514 |
} |
| 1515 |
|
| 1516 |
=head2 list_wiki_files |
| 1517 |
|
| 1518 |
@filenames = $mvs->list_wiki_files; |
| 1519 |
|
| 1520 |
Returns a recursive list of all wikitext files in the local repository. |
| 1521 |
|
| 1522 |
=cut |
| 1523 |
|
| 1524 |
sub list_wiki_filesscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/list_wiki_files(). { |
| 1525 |
my $self = shiftscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/shift().; |
| 1526 |
my @files; |
| 1527 |
my $dir = File::Spec->curdirscip-perl cpan perl-project 0.0.0 File/Spec/curdir().(); |
| 1528 |
findscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/find().(sub { |
| 1529 |
return unless /^[^.].*\.wiki\z/s; |
| 1530 |
my $name = $File::Find::namescip-perl cpan perl-project 0.0.0 File/Find/$name.; |
| 1531 |
$name = File::Spec->abs2relscip-perl cpan perl-project 0.0.0 File/Spec/abs2rel().($name); |
| 1532 |
pushscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/push(). @files, $name; |
| 1533 |
}, $dir); |
| 1534 |
return @files; |
| 1535 |
} |
| 1536 |
|
| 1537 |
=begin comment |
| 1538 |
|
| 1539 |
=head1 Private Methods |
| 1540 |
|
| 1541 |
=cut |
| 1542 |
|
| 1543 |
sub _mergescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_merge(). { |
| 1544 |
my ($self, $filename, $ref, $server, $local) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 1545 |
my $control = { |
| 1546 |
in => $\scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`$\`., |
| 1547 |
out => $/scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`$/`., |
| 1548 |
chomp => 1 |
| 1549 |
}; |
| 1550 |
$ref = VCS::Lite->newscip-perl cpan perl-project 0.0.0 VCS/Lite/new().('ref', "\n", "$ref\n"); |
| 1551 |
$server = VCS::Lite->newscip-perl cpan perl-project 0.0.0 VCS/Lite/new().('server', "\n", "$server\n"); |
| 1552 |
$local = VCS::Lite->newscip-perl cpan perl-project 0.0.0 VCS/Lite/new().('local', "\n", "$local\n"); |
| 1553 |
my $merge = $ref->mergescip-perl cpan perl-project 0.0.0 VCS/Lite/merge().($server, $local); |
| 1554 |
return scalarscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/scalar(). $merge->textscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/text().(); |
| 1555 |
} |
| 1556 |
|
| 1557 |
sub _get_wiki_textscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_wiki_text(). { |
| 1558 |
my ($self, $doc) = @_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.; |
| 1559 |
my $p = HTML::TokeParser->newscip-perl cpan perl-project 0.0.0 HTML/TokeParser/new().(\$doc); |
| 1560 |
$p->get_tagscip-perl cpan perl-project 0.0.0 HTML/TokeParser/get_tag().("textarea"); |
| 1561 |
my $text = $p->get_textscip-perl cpan perl-project 0.0.0 HTML/TokeParser/get_text().; |
| 1562 |
$text =~ s/
//gs; # convert endlines |
| 1563 |
return $text; |
| 1564 |
} |
| 1565 |
|
| 1566 |
sub _get_server_encoding { |
| •1567 |
# Determine the charscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_server_encoding().acter set used by the server. |
| 1568 |
# Assumes the same character set is used on all pages. |
| 1569 |
|
| 1570 |
my ($self) = @_; |
| •1571 |
|
| 1572 |
# Get a sample page |
| 1573 |
my $url = $self->_get_version_url; |
| 1574 |
my $res = $self->{ua}->get($url);scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_version_url(). |
| •1575 |
|
| 1576 |
# Use the character set in the response header, if provided |
| 1577 |
my $contenttypeheader = $res->header( 'content-type' ); |
| 1578 |
# if defined will be like: "text/htmscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/header().l; charset=UTF-8" |
| 1579 |
my $charsetheader = $contenttypeheader; |
| 1580 |
$charsetheader =~ m/charset=(.*)/; |
| 1581 |
$charsetheader = $1; |
| 1582 |
return $charsetheadscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/$1.er if ($charsetheader); |
| 1583 |
|
| 1584 |
# No character set defined in the header. Look instead in the content. |
| 1585 |
my $doc = $res->decoded_content; |
| 1586 |
my $p = HTML::TokeParser->new(\scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/decoded_content().$doc); |
| 1587 |
while ( my $t = $p->get_tag("scip-perl cpan perl-project 0.0.0 HTML/TokeParser/new().meta") ) { |
| 1588 |
next unless defined $t-scip-perl cpan perl-project 0.0.0 HTML/TokeParser/get_tag().>[1]->{'http-equiv'} |
| •1589 |
and ($t->[1]->{'hscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/defined().ttp-equiv'} eq 'Content-Type' |
| 1590 |
or $t->[1]->{'http-equiv'} eq 'Content-type'); |
| 1591 |
my $cont = $t->[1]->{'content'}; |
| 1592 |
$cont =~ m/charset=(.*)/; |
| 1593 |
return $1; |
| 1594 |
} |
| •1595 |
|
| 1596 |
# No character set found anywhere. Return nothing. |
| 1597 |
} |
| 1598 |
|
| 1599 |
sub _get_page_headline { |
| •1600 |
# Find and parse tscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_page_headline().he page's headline. |
| 1601 |
# the headline may be of the form: |
| 1602 |
# <h1 id="firstHeading" class="firstHeading"><span dir="auto">Editing Template:Access Logged/Demo/Access Log</span></h1> |
| 1603 |
|
| 1604 |
my ($self, $doc) = @_; |
| 1605 |
my $p = HTML::TokeParscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.ser->new(\$doc); |
| 1606 |
$p->get_tag("h1"); |
| •1607 |
my $text = scip-perl cpan perl-project 0.0.0 HTML/TokeParser/get_tag().$p->get_text( "/h1" ); |
| 1608 |
$text =~ s/
//gs; scip-perl cpan perl-project 0.0.0 HTML/TokeParser/get_text(). # convert endlines |
| 1609 |
return $text; |
| 1610 |
} |
| 1611 |
|
| •1612 |
sub _get_start_date { |
| 1613 |
my ($self, $doc) = @_; |
| 1614 |
my $p = HTML::Tscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_start_date().okeParser->new(\$doc); |
| 1615 |
my $date; |
| 1616 |
while (my $tag = $p->get_tag(scip-perl cpan perl-project 0.0.0 HTML/TokeParser/new().'input')) { |
| •1617 |
next unless exists $tag->[1]->{type} and $tag->[1]->{type} eq 'hidden'; |
| 1618 |
next unless $tag->[1]->{scip-perl cpan perl-project 0.0.0 HTML/TokeParser/get_tag().name} eq EDIT_START_NAME; |
| 1619 |
$date = $tag->[1]-scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/exists().>{value}; |
| 1620 |
} |
| 1621 |
return $date; |
| 1622 |
} |
| 1623 |
|
| 1624 |
sub _get_edit_date { |
| 1625 |
my ($self, $doc) = @_; |
| 1626 |
my $p = HTML::scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_edit_date().TokeParser->new(\$doc); |
| 1627 |
my $date; |
| 1628 |
while (my $tag = $p->get_tag(scip-perl cpan perl-project 0.0.0 HTML/TokeParser/new().'input')) { |
| •1629 |
next unless exists $tag->[1]->{type} and $tag->[1]->{type} eq 'hidden'; |
| 1630 |
next unless $tag->[1]->{scip-perl cpan perl-project 0.0.0 HTML/TokeParser/get_tag().name} eq EDIT_TIME_NAME; |
| 1631 |
$date = $tag->[1]-scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/exists().>{value}; |
| 1632 |
} |
| 1633 |
return $date; |
| 1634 |
} |
| 1635 |
|
| 1636 |
sub _get_edit_token { |
| 1637 |
my ($self, $doc) = @_; |
| 1638 |
my $p = HTML::Tscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_edit_token().okeParser->new(\$doc); |
| 1639 |
my $token; |
| 1640 |
while (my $tag = $p->get_tag(scip-perl cpan perl-project 0.0.0 HTML/TokeParser/new().'input')) { |
| 1641 |
next unless exists $tag->[1]->{type} and $tag->[1]->{type} eq 'hidden'; |
| 1642 |
next unless $tag->[1]->{scip-perl cpan perl-project 0.0.0 HTML/TokeParser/get_tag().name} eq 'wpEditToken'; |
| 1643 |
$token = $tag->[1]scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/exists().->{value}; |
| 1644 |
} |
| 1645 |
return $token; |
| 1646 |
} |
| 1647 |
|
| 1648 |
sub _get_edit_is_watching { |
| 1649 |
my ($self, $doc, $name) = @_; |
| 1650 |
my $p = HTML::TokeParscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_edit_is_watching().ser->new(\$doc); |
| 1651 |
my $status; |
| 1652 |
while (my $tag = $p->get_tag(scip-perl cpan perl-project 0.0.0 HTML/TokeParser/new().'a')) { |
| 1653 |
next unless $tag->[1]->{href} |
| 1654 |
&& $tag->[1]->{hscip-perl cpan perl-project 0.0.0 HTML/TokeParser/get_tag().ref} =~ m/&action=((?:un)?watch)/; |
| 1655 |
# If 'un'watch, then it's watched; otherwise, it's not. |
| 1656 |
$status = ($1 eq 'unwatch' ? 1 : 0); |
| 1657 |
} |
| 1658 |
return $status; |
| 1659 |
} |
| 1660 |
|
| 1661 |
sub _get_edit_checkbox { |
| 1662 |
my ($self, $doc, $name) = @_; |
| 1663 |
my $p = HTML::Tokescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_edit_checkbox().Parser->new(\$doc); |
| 1664 |
my $status; |
| 1665 |
while (my $tag = $p->get_tag(scip-perl cpan perl-project 0.0.0 HTML/TokeParser/new().'input')) { |
| •1666 |
next unless exists $tag->[1]->{type} and $tag->[1]->{type} eq 'checkbox'; |
| 1667 |
next unless $tag->[1]->{scip-perl cpan perl-project 0.0.0 HTML/TokeParser/get_tag().name} eq $name; |
| 1668 |
$status = ($tag->[scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/exists().1]->{checked} ? 1 : 0); |
| 1669 |
} |
| 1670 |
return $status; |
| 1671 |
} |
| 1672 |
|
| 1673 |
sub _get_edit_watch_default { |
| 1674 |
my ($self, $doc) = @_; |
| 1675 |
return $self->_get_edit_chscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_edit_watch_default().eckbox($doc, EDIT_WATCH_NAME); |
| 1676 |
} |
| 1677 |
|
| 1678 |
sub _get_edit_minor_default { |
| 1679 |
my ($self, $doc) = @_; |
| •1680 |
my $default = $self->_get_scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_edit_minor_default().edit_checkbox($doc, EDIT_MINOR_NAME); |
| 1681 |
$default = OPT_NO unlscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.ess defined($default); |
| 1682 |
return $default; |
| 1683 |
} |
| 1684 |
|
| 1685 |
sub _check_path { |
| 1686 |
my ($self, $filename) = @_; |
| 1687 |
WWW::Mediawscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_check_path().iki::Client::FileTypeException->throw( |
| 1688 |
"'$filename' doesnscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.'t appear to be a wiki file.") |
| 1689 |
unless $filename =~ /\.wiki$/; |
| 1690 |
WWW::Mediawiki::Client::AbsoluteFileNameException->throw( |
| 1691 |
"No absolute filenames allowed!") |
| 1692 |
if File::Spec->file_name_is_absolute($filename);scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/AbsoluteFileNameException/throw(). |
| 1693 |
return File::Spec->splitpath($filename); |
| 1694 |
} |
| 1695 |
|
| 1696 |
sub _get_reference_page { |
| 1697 |
my ($self, $filename) = @_; |
| 1698 |
return '' unless -escip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_reference_page(). $filename; |
| 1699 |
$filename = $self->_get_rescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.f_filename($filename); |
| 1700 |
my $ref = $self->get_local_page($filename); |
| 1701 |
return $ref; |
| 1702 |
} |
| 1703 |
|
| 1704 |
sub _get_ref_filename { |
| 1705 |
my ($self, $filename) = @_; |
| 1706 |
WWW::Mediawiki::Cscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_ref_filename().lient::FileTypeException->throw( |
| 1707 |
"Not a .wiki file.scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.") unless $filename =~ /\.wiki$/; |
| 1708 |
my ($vol, $dirs, $fn) = File::Spec->splitpath($fscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/FileTypeException/throw().ilename); |
| 1709 |
$fn =~ s/(.*)\.wiki/.$1.ref.wiki/; |
| 1710 |
return File::Spec->catfile('.', $dirs, $fn);scip-perl cpan perl-project 0.0.0 File/Spec/splitpath(). |
| 1711 |
} |
| 1712 |
|
| 1713 |
sub _ref_to_filename { |
| 1714 |
my ($self, $ref) = @_; |
| 1715 |
my ($vol, $dirs,scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_ref_to_filename(). $fn) = File::Spec->splitpath($ref); |
| 1716 |
$fn =~ s/^\.(.*)\.refscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.\.wiki$/$1.wiki/ |
| 1717 |
or WWW::Mediawiki::Client::FileTypeExceptscip-perl cpan perl-project 0.0.0 File/Spec/splitpath().ion->throw( |
| 1718 |
"Not a .ref.wiki file."); |
| 1719 |
return File::Spec->catpath($vol, $dirs, $fn); |
| 1720 |
} |
| 1721 |
|
| 1722 |
sub _conflicts_found_in { |
| 1723 |
my ($self, $text) = @_; |
| 1724 |
return 1 if $text =scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_conflicts_found_in().~ /Start of conflict 1/m; |
| 1725 |
return 0; |
| 1726 |
} |
| 1727 |
|
| 1728 |
sub _get_update_status { |
| 1729 |
my ($self, $rv, $sv, $lv, $nv) = @_; |
| 1730 |
chomp ($rv, $sv, $scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_update_status().lv, $nv); # double chomp |
| 1731 |
chomp ($rv, $sv, $lv, $nv); # it's scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.a nasty hack, but necessary until we re-write |
| 1732 |
returscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/chomp().n STATUS_CONFLICT if $self->_conflicts_found_in($nv); |
| 1733 |
returscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/chomp().n STATUS_UNKNOWN unless $sv or $lv; |
| 1734 |
return STATUS_LOCAL_ADDED unless $sv;scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_conflicts_found_in(). |
| 1735 |
return STATUS_UNCHANGED if $sv eq $lv; |
| 1736 |
return STATUS_LOCAL_MODIFIED if $lv ne $rv; |
| 1737 |
return STATUS_SERVER_MODIFIED if $rv ne $sv; |
| 1738 |
return STATUS_UNKNOWN; |
| 1739 |
} |
| 1740 |
|
| 1741 |
sub _get_host_url { |
| 1742 |
my ($self) = @_; |
| 1743 |
my $lang = $selfscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_host_url().->language_code; |
| 1744 |
my $host = $selscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.f->host; |
| 1745 |
$host =~ s/__LANG__/$lang/g;scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/language_code(). |
| 1746 |
my $protocol = scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/host().$self->protocol; |
| 1747 |
return "$protocol://$host/"; |
| 1748 |
} |
| 1749 |
|
| 1750 |
sub _get_version_url { |
| 1751 |
my ($self) = @_; |
| 1752 |
my $lang = $selfscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_version_url().->language_code; |
| 1753 |
my $path = $selscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.f->wiki_path; |
| 1754 |
$path =~ s/__LANG__/$lang/g;scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/language_code(). |
| 1755 |
return $self->_get_host_urlscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/wiki_path(). |
| 1756 |
. $path . '?' . TITLE . '=' . SPECIAL_VERSION; |
| 1757 |
} |
| 1758 |
|
| 1759 |
sub _get_export_url { |
| 1760 |
my ($self) = @_; |
| 1761 |
my $lang = $selscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_export_url().f->language_code; |
| 1762 |
my $path = $selscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.f->wiki_path; |
| 1763 |
$path =~ s/__LANG__/$lang/g;scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/language_code(). |
| 1764 |
return $self->_get_host_urlscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/wiki_path(). |
| 1765 |
. $path . '?' . TITLE . '=' . SPECIAL_EXPORT; |
| 1766 |
} |
| 1767 |
|
| 1768 |
sub _get_exported_pages { |
| 1769 |
my ($self, @pages) = @_; |
| 1770 |
my $count = scalar scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_exported_pages().@pages; |
| 1771 |
my $url = $self->_get_escip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`.xport_url; |
| 1772 |
my $response = $sescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/scalar().lf->{ua}->request(POST $url, [ |
| 1773 |
pages => join("\n", @pagscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_export_url().es), |
| 1774 |
action => 'submit', |
| 1775 |
curonly => 'tscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/join().rue', |
| 1776 |
]); |
| 1777 |
WWW::Mediawiki::Client::ServerPageException->throw( |
| 1778 |
error => "Couldn't fetch $count pages from the server.", |
| 1779 |
res => $response, |
| 1780 |
) unless $response->is_success; |
| 1781 |
my $parser = XML::LibXML->new; |
| 1782 |
my $doc = $parser->parse_string($rscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/is_success().esponse->decoded_content); |
| 1783 |
my %expecting = map {$_ => 1}scip-perl cpan perl-project 0.0.0 XML/LibXML/new(). @pages; |
| 1784 |
my %export = (); |
| 1785 |
my %timestamp = ();scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/map(). |
| 1786 |
foreach my $node ($doc->findnodes('/mediawiki/page')) { |
| 1787 |
my $page = $node->findvalue(TITLE); |
| 1788 |
my $text = $node->findvalue('scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/findnodes().revision/text'); |
| 1789 |
my $time = $node->findvaluescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/findvalue().('revision/timestamp'); |
| 1790 |
WWW::Mediawiki::Client::Serscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/findvalue().verPageException->throw( |
| 1791 |
error => "Server returnscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/findvalue().ed unexpected page '$page'.", |
| 1792 |
res => $response) unless $expecting{$page};scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/ServerPageException/throw(). |
| 1793 |
$export{$page} = $text; |
| 1794 |
$timestamp{$page} = $time; |
| 1795 |
} |
| 1796 |
$self->{export} = \%export; |
| 1797 |
$self->{timestamp} = \%timestamp; |
| 1798 |
} |
| 1799 |
|
| 1800 |
sub _upload_file { |
| 1801 |
my ($self, $filename, $commit) = @_; |
| 1802 |
WWW::Mediawiscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_upload_file().ki::Client::URLConstructionException->throw( |
| 1803 |
"No server URL specified.")scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/`@_`. unless $self->{host}; |
| 1804 |
WWW::Mediawiki::Client::FileAccessException->throw("No scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/URLConstructionException/throw().such file!") |
| 1805 |
unless -e $filename; |
| 1806 |
WWW::Mediawiki::Client::CommitException->throw(scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/FileAccessException/throw(). |
| 1807 |
'Could not determine charset for uploading to this server.' |
| 1808 |
) unless $self->encoding; |
| 1809 |
my $text = $self->get_local_page($filename); |
| 1810 |
my $pagename = $self->filenascip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/encoding().me_to_pagename($filename); |
| 1811 |
my $sp = $self->get_server_page(scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/get_local_page().$pagename); |
| 1812 |
if ($self->{edit}->{date}) {scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/filename_to_pagename(). |
| 1813 |
my $ref = $self->_get_referscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/get_server_page().ence_page($filename); |
| 1814 |
chomp ($sp, $ref); |
| 1815 |
WWW::Mediawiki::Client::UpdateNeededscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_reference_page().Exception->throw( |
| 1816 |
scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/chomp(). error => $self->filename_to_pagename($filename) |
| 1817 |
. " has changed on the server.", |
| 1818 |
) unless $sp eq $ref;scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/filename_to_pagename(). |
| 1819 |
} |
| 1820 |
chomp ($text); |
| 1821 |
WWW::Mediawiki::Client::ConflictsPresentException->throw( |
| 1822 |
scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/chomp(). "$filename appears to have unresolved conflicts") |
| 1823 |
if $self->_conflicts_found_in($text); |
| 1824 |
my @params; |
| 1825 |
push(@params, EDIT_MINOR_NAME, CHscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_conflicts_found_in().ECKED) if $self->_option_check( |
| 1826 |
'minor_edit', $self->{minor_edit}, |
| 1827 |
$self->scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/push().{edit}->{def_minor}); |
| 1828 |
push(@params, EDIT_WATCH_NAME, CHECKED) if $self->_option_check( |
| 1829 |
'watch', $self->{watch}, |
| 1830 |
$self->scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/push().{edit}->{def_watch}, $self->{edit}->{watch_now});scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_option_check(). |
| 1831 |
my $act_name = ($commit ? EDIT_SUBMIT_NAME : EDIT_PREVIEW_NAME ); |
| 1832 |
my $act_value = ($commit ? EDIT_SUBMIT_VALUE : EDIT_PREVIEW_VALUE); |
| 1833 |
my $url = $self->filename_to_url($filename, SUBMIT); |
| •1834 |
my $content_type = 'application/x-www-form-urlencoded;charset=' . |
| 1835 |
$self->encoding; |
| 1836 |
|
| 1837 |
my $res = $sscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/encoding().elf->{ua}->post($url, |
| •1838 |
'Content-type' => $content_type, |
| 1839 |
Content => |
| 1840 |
[ |
| 1841 |
$act_name => $act_value, |
| •1842 |
&TEXTAREA_NAME => $text, |
| 1843 |
&COMMENT_NAME => $self->{commit_message}, |
| •1844 |
&EDIT_START_NAscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/TEXTAREA_NAME().ME => $self->{edit}->{start}, |
| 1845 |
&EDIT_TIME_NAscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/COMMENT_NAME().ME => $self->{edit}->{date}, |
| 1846 |
&EDIT_TOKEN_NAMEscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/EDIT_START_NAME(). => $self->{edit}->{token}, |
| •1847 |
@params, |
| 1848 |
] |
| •1849 |
); |
| 1850 |
|
| •1851 |
my $doc = $res->decoded_content; |
| 1852 |
|
| 1853 |
my $headline = $self->_get_pagescip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/decoded_content()._headline($doc); |
| 1854 |
my $expect = ($commit ? $pagename : "Editing $pagename"); |
| •1855 |
my $pagenamefile = lc($pagename);scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/_get_page_headline(). |
| 1856 |
$pagenamefile =~ s/^image:/file:/; |
| 1857 |
my $expectfile = ($coscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/lc().mmit ? $pagenamefile : "Editing $pagenamefile"); |
| 1858 |
unless (lc($headline) eq lc($expect) or lc($headline) eq lc($expectfile)) { |
| 1859 |
WWW::Mediawiki::Client::CommitException->throw( |
| 1860 |
errorscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/lc(). => "The page youscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/lc(). are trying to scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/lc().commit appears toscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/lc(). contain a link which is associated with Wikispam.", |
| 1861 |
res => $res, |
| 1862 |
) if ($headline eq 'Spam protection filter'); |
| 1863 |
WWW::Mediawiki::Client::CommitException->throw( |
| 1864 |
error => "When we tried to commit '$pagename' the server responded with '$headline'.", |
| 1865 |
res => $res, |
| 1866 |
) if ($headline); |
| 1867 |
} |
| 1868 |
return ($res, $text); |
| 1869 |
} |
| 1870 |
|
| 1871 |
sub _option_verify { |
| 1872 |
my ($self, $name, $value, $r_accept) = @_; |
| 1873 |
|
| 1874 |
foreach my $acc (@{$r_accept}) { |
| 1875 |
return 1 if $acc == $value; |
| 1876 |
} |
| 1877 |
|
| 1878 |
my %opts = OPTION_SETTINGS; |
| 1879 |
my $valstr = $opts{$value}; |
| 1880 |
$valstr = "value '$value'" unless defined($valstr); |
| 1881 |
|
| 1882 |
WWW::Mediawiki::Client::InvalidOptscip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/defined().ionException->throw( |
| 1883 |
error => "Cannot set field $name to $valstr.", |
| 1884 |
field => $name, |
| 1885 |
option => $opts{$value}, |
| 1886 |
value => $value, |
| 1887 |
); |
| 1888 |
} |
| 1889 |
|
| 1890 |
sub _option_check { |
| 1891 |
my ($self, $name, $value, $default, $current) = @_; |
| 1892 |
|
| 1893 |
return 1 if $value == OPT_YES; |
| 1894 |
return 0 if $value == OPT_NO; |
| 1895 |
|
| 1896 |
if ($value == OPT_DEFAULT) { |
| 1897 |
return $default if defined($default); |
| 1898 |
WWW::Mediawiki::Client::InvalidOptionException->throw( |
| 1899 |
error => "Field '$name' scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/defined().cannot use OPT_DEFAULT:" |
| 1900 |
. " Default information could not be determined.scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/InvalidOptionException/throw().", |
| 1901 |
field => $name, |
| 1902 |
option => 'OPT_DEFAULT', |
| 1903 |
value => $value, |
| 1904 |
); |
| 1905 |
} |
| 1906 |
|
| 1907 |
if ($value == OPT_KEEP) { |
| 1908 |
return $current if defined($current); |
| 1909 |
WWW::Mediawiki::Client::InvalidOptionException->throw( |
| 1910 |
error => "Field '$name' scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/defined().cannot use OPT_KEEP:" |
| 1911 |
. " Current information could not be determined.scip-perl cpan perl-project 0.0.0 WWW/Mediawiki/Client/InvalidOptionException/throw().", |
| 1912 |
field => $name, |
| 1913 |
option => 'OPT_DEFAULT', |
| 1914 |
value => $value, |
| 1915 |
); |
| 1916 |
} |
| 1917 |
|
| 1918 |
# Should never happen; these are verified at assignment time. |
| 1919 |
my %opts = OPTION_SETTINGS; |
| 1920 |
WWW::Mediawiki::Client::InvalidOptionException->throw( |
| 1921 |
error => "Field '$name' is in unknown state '$value'.", |
| 1922 |
field => $name, |
| 1923 |
option => $opts{$value}, |
| 1924 |
value => $value |
| 1925 |
); |
| 1926 |
} |
| 1927 |
|
| 1928 |
1; |
| 1929 |
|
| 1930 |
__END__ |
| 1931 |
|
| 1932 |
=end comment |
| 1933 |
|
| 1934 |
=head1 BUGS |
| 1935 |
|
| 1936 |
Please submit bug reports to the CPAN bug tracker at |
| 1937 |
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Mediawiki-Client>. |
| 1938 |
|
| 1939 |
=head1 DISCUSSION |
| 1940 |
|
| 1941 |
There is a discussion list. You can subscribe or read the archives at: |
| 1942 |
L<http://www.geekhive.net/cgi-bin/mailman/listinfo/www-mediawiki-client-l> |
| 1943 |
|
| 1944 |
=head1 AUTHORS |
| 1945 |
|
| 1946 |
=over |
| 1947 |
|
| 1948 |
=item Mark Jaroski <[email protected]> |
| 1949 |
|
| 1950 |
Original author, maintainer |
| 1951 |
|
| 1952 |
=item Mike Wesemann <[email protected]> |
| 1953 |
|
| 1954 |
Added support for Mediawiki 1.3.10+ edit tokens |
| 1955 |
|
| 1956 |
=item Bernhard Kaindl <[email protected]> |
| 1957 |
|
| 1958 |
Improved error messages. |
| 1959 |
|
| 1960 |
=item Oleg Alexandrov <[email protected]>, Thomas Widmann <[email protected]> |
| 1961 |
|
| 1962 |
Bug reports and feedback. |
| 1963 |
|
| 1964 |
=item Adrian Irving-Beer <[email protected]> |
| 1965 |
|
| 1966 |
Preview support, export support for multi-page update, more 'minor' |
| 1967 |
and 'watch' settings, and bug reports. |
| 1968 |
|
| 1969 |
=item Nicolas Brouard <[email protected]> |
| 1970 |
|
| 1971 |
Fixed content-type bug. |
| 1972 |
|
| 1973 |
=item Alex Kapranoff <[email protected]> |
| 1974 |
|
| 1975 |
Added C<escape_filename> in order to support UTF-8 filenames on filesystems |
| 1976 |
lacking UTF-8 support. |
| 1977 |
|
| 1978 |
=back |
| 1979 |
|
| 1980 |
=head1 LICENSE |
| 1981 |
|
| 1982 |
Copyright (c) 2004-2006 Mark Jaroski. |
| 1983 |
|
| 1984 |
This program is free software; you can redistribute it and/or modify it |
| 1985 |
under the same terms as Perl itself. |
| 1986 |
|