| 1 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | Quiq::MediaWiki::Client - Clientseitiger Zugriff auf ein MediaWiki | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | =head1 BASE CLASS | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | L<Quiq::Hash> | ||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | Diese Klasse implementiert Methoden zur Kommunikation mit einem | ||||||||||||||||||||||||||||||||||||||||||
| 16 | MediaWiki über die sogenannte MediaWiki-API. | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | Die MediaWiki-API wird über api.php (statt index.php) angesprochen. | ||||||||||||||||||||||||||||||||||||||||||
| 19 | Die Doku der API wird angezeigt, wenn api.php ohne Parameter | ||||||||||||||||||||||||||||||||||||||||||
| 20 | oder mit "action=help&recursivesubmodules=1" (alles auf einer Seite) | ||||||||||||||||||||||||||||||||||||||||||
| 21 | aufgerufen wird. | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | Die MediaWiki-API empfängt und liefert alle Daten in UTF-8. | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | Insbesondere implementiert die Klasse die Methode $mw->L<load|"load() - Lade Seite oder Mediendatei ins Wiki">(), mit | ||||||||||||||||||||||||||||||||||||||||||
| 26 | welcher sowohl Seiten als auch Mediendateien (z.B. Bilder) | ||||||||||||||||||||||||||||||||||||||||||
| 27 | "intelligent" geladen werden können. | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | Bei Angabe der Option -debug => 1 bei Aufruf des Konstruktors | ||||||||||||||||||||||||||||||||||||||||||
| 30 | wird die gesamte Kommunikation auf STDERR protokolliert. | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | =over 2 | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | L<API Dokumentation|https://www.mediawiki.org/wiki/API> (www.mediawiki.org) | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | L<API Lowlevel-Dokumentation|https://www.mediawiki.org/w/api.php?action=help&recursivesubmodules=1> | ||||||||||||||||||||||||||||||||||||||||||
| 43 | (www.mediawiki.org) | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | Client-Implementierung: quik-mediawiki | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | =head1 EXAMPLES | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | Beispiele für MediaWiki URLs: | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | =over 2 | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | L<https://www.mediawiki.org/w/api.php> | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | L<http://localhost/mediawiki/api.php> | ||||||||||||||||||||||||||||||||||||||||||
| 64 | (nicht allgemein aufrufbar) | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | L<http://lxv0103.ruv.de:8080/api.php> | ||||||||||||||||||||||||||||||||||||||||||
| 69 | (nicht allgemein aufrufbar) | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | package Quiq::MediaWiki::Client; | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | ▶ | use base qw/Quiq::Hash/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | ▶ | use v5.10; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | our $VERSION = '1.240'; | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | ▶ | use Quiq::AnsiColor; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | ▶ | use LWP::UserAgent (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | ▶ | use Quiq::Option; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | ▶ | use Quiq::Debug; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | ▶ | use Quiq::Hash; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | ▶ | use Quiq::Path; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | ▶ | use Quiq::Record; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | ▶ | use Quiq::Url; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | ▶ | use JSON (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | =head2 Konstruktor | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | =head3 new() - Instantiiere MediaWiki-API Client | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | $mw = $class->new($url,@opt); | ||||||||||||||||||||||||||||||||||||||||||
| 107 | $mw = $class->new($url,$user,$password,@opt); | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | =head4 Arguments | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | =item $url | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | API-URL des MediaWiki, z.B. L<https://en.wikipedia.org/w/api.php>. | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | =item $user | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | Benutzername (für automatisches Login statt explizites Login). | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | =item $password | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | Passwort (für automatisches Login statt explizites Login). | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | =head4 Options | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | =item -color => $bool (Default: 1) | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | Gib die Laufzeitinformation (wird mit -debug=>1 eingeschaltet) | ||||||||||||||||||||||||||||||||||||||||||
| 134 | in Farbe aus. | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | =item -debug => $bool (Default: 0) | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | Gib Laufzeit-Information wie den Kommunikationsverlauf auf STDERR aus. | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | Client-Objekt (Referenz) | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | =head4 Description | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | Instantiiere einen Client für die MediaWiki-API $url und liefere eine | ||||||||||||||||||||||||||||||||||||||||||
| 149 | Referenz auf dieses Objekt zurück. | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | Der Konstruktor-Aufruf löst I<keinen> Server-Request aus. Sind | ||||||||||||||||||||||||||||||||||||||||||
| 152 | $user und $password angegeben, wird der Benutzer erst mit dem | ||||||||||||||||||||||||||||||||||||||||||
| 153 | ersten Token-Request eingeloggt. Er wird also nur eingeloggt, wenn | ||||||||||||||||||||||||||||||||||||||||||
| 154 | es nötig ist. Vorteil: Ein Client, bei dem sich erst im Laufe der | ||||||||||||||||||||||||||||||||||||||||||
| 155 | Ausführung herausstellt, ob er Requests ausführt, muss nicht vorab | ||||||||||||||||||||||||||||||||||||||||||
| 156 | einen - ggf. unnötigen - Login-Request ausführen. (De facto besteht | ||||||||||||||||||||||||||||||||||||||||||
| 157 | ein Login-Request aus zwei Requests, da mit dem ersten Aufruf | ||||||||||||||||||||||||||||||||||||||||||
| 158 | lediglich der Login-Token geliefert wird.) Solange der Client | ||||||||||||||||||||||||||||||||||||||||||
| 159 | Requests ausführt, die kein Login benötigen, werden diese beiden | ||||||||||||||||||||||||||||||||||||||||||
| 160 | Requests ebenfalls gespart. | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | Bei Angabe der Option -debug => 1 bei Aufruf des Konstruktors | ||||||||||||||||||||||||||||||||||||||||||
| 163 | wird die gesamte Kommunikation auf STDERR protokolliert. | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 171 | # @_: $url,@opt -or- $url,$user,$passw,@opt | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | # Optionen und Argumente | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | my $color = 1; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my $debug = 0; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | my $warnings = 0; | |||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | my $argA = $class->parameters(1,3,\@_, | |||||||||||||||||||||||||||||||||||||||||
| 180 | -color => \$color, | ||||||||||||||||||||||||||||||||||||||||||
| 181 | -debug => \$debug, | ||||||||||||||||||||||||||||||||||||||||||
| 182 | -warnings => \$warnings, | ||||||||||||||||||||||||||||||||||||||||||
| 183 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | my ($url,$user,$password) = @$argA; | |||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | # UserAgent instantiieren | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | my $ua = LWP::UserAgent->new( | |||||||||||||||||||||||||||||||||||||||||
| 189 | agent => 'MediaWikiClient', | ||||||||||||||||||||||||||||||||||||||||||
| 190 | cookie_jar => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 191 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | # Objekt instantiieren | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | return $class->SUPER::new( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$user and $password
MC/DC0%0/2
$user and $password
$user
$password
Truth table0%0/3
A and B
A= $userB= $password
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | a => Quiq::AnsiColor->new($color), | ||||||||||||||||||||||||||||||||||||||||||
| 197 | autoLogin => $user && $password? 1: 0, | ||||||||||||||||||||||||||||||||||||||||||
| 198 | color => $color, | ||||||||||||||||||||||||||||||||||||||||||
| 199 | debug => $debug, | ||||||||||||||||||||||||||||||||||||||||||
| 200 | warnings => $warnings, | ||||||||||||||||||||||||||||||||||||||||||
| 201 | ua => $ua, | ||||||||||||||||||||||||||||||||||||||||||
| 202 | url => $url, | ||||||||||||||||||||||||||||||||||||||||||
| 203 | user => $user, | ||||||||||||||||||||||||||||||||||||||||||
| 204 | password => $password, | ||||||||||||||||||||||||||||||||||||||||||
| 205 | tokenH => undef, # memoize | ||||||||||||||||||||||||||||||||||||||||||
| 206 | version => undef, # memoize | ||||||||||||||||||||||||||||||||||||||||||
| 207 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | =head2 Grundlegende Operationen | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | =head3 login() - Logge Nutzer ein | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | $res = $mw->login($user,$password); | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | =head4 Arguments | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | =item $user | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | Name des Nutzers | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | =item $password | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | Passwort des Nutzers | ||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | Response (Hash-Referenz) | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | =head4 Description | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | Melde den Benutzer $user mit Passwort $password auf dem | ||||||||||||||||||||||||||||||||||||||||||
| 241 | MediaWiki-Server an. Alternativ ist ein automatisches Login | ||||||||||||||||||||||||||||||||||||||||||
| 242 | möglich, was eleganter ist. Siehe Konstruktor. | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | =head4 Example | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | $ perl -MQuiq::MediaWiki::Client -E 'Quiq::MediaWiki::Client->new("http://lxv0103.ruv.de:8080/api.php",-debug=>1)->login("XV882JS","<PASSWORD>")' | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | sub login { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
login: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | my ($self,$user,$password) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | # Login-Request | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | my $res = $self->send('POST','login', | |||||||||||||||||||||||||||||||||||||||||
| 258 | lgname => $user, | ||||||||||||||||||||||||||||||||||||||||||
| 259 | lgpassword => $password, | ||||||||||||||||||||||||||||||||||||||||||
| 260 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | if ($res->{'login'}->{'result'} eq 'NeedToken') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | # Der erste Login-Request ist fehlgeschlagen, hat aber ein | ||||||||||||||||||||||||||||||||||||||||||
| 264 | # Login-Token geliefert. Wir wiederholen den Aufruf | ||||||||||||||||||||||||||||||||||||||||||
| 265 | # mit dem Login-Token. | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | $res = $self->send('POST','login', | ||||||||||||||||||||||||||||||||||||||||||
| 268 | lgname => $user, | ||||||||||||||||||||||||||||||||||||||||||
| 269 | lgpassword => $password, | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | lgtoken => $res->{'login'}->{'token'}, | |||||||||||||||||||||||||||||||||||||||||
| 271 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | if ($res->{'login'}->{'result'} ne 'Success') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | $self->throw( | ||||||||||||||||||||||||||||||||||||||||||
| 276 | 'MEDIAWIKI-00099: Login failed', | ||||||||||||||||||||||||||||||||||||||||||
| 277 | User => $user, | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | Reason => $res->{'login'}->{'result'}, | |||||||||||||||||||||||||||||||||||||||||
| 279 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | # Kein automatisches Login mehr | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | $self->autoLogin(0); | |||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | return $res; | |||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | =head3 getToken() - Besorge Token für Operation | ||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | $token = $mw->getToken($action); | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | =head4 Arguments | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | =item $action | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | Operation, für die das Token benötigt wird. | ||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | Token (String) | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | =head4 Description | ||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | Besorge vom Server ein Token zum Ausführen von Operation $action und | ||||||||||||||||||||||||||||||||||||||||||
| 313 | liefere dieses zurück. Da das Token je Session für alle Seiten identisch | ||||||||||||||||||||||||||||||||||||||||||
| 314 | ist, cachen wir die Tokens, so dass nur eine Serveranfrage nötig ist. | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | sub getToken { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getToken: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | my ($self,$action) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | if ($self->autoLogin) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | # Wir loggen uns mit dem ersten Token-Request automatisch ein. | ||||||||||||||||||||||||||||||||||||||||||
| 325 | # Autologin wird in der Methode login() abgestellt, müssen | ||||||||||||||||||||||||||||||||||||||||||
| 326 | # wir hier nicht machen. | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | $self->login($self->user,$self->password); | |||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | my $h = $self->memoize('tokenH',sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | my $res = $self->send('GET','tokens'); | |||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | my %token = %{$res->{'tokens'}}; | |||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | return \%token; | |||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | my $token = $h->{$action.'token'}; | |||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | if (!$token) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | $self->throw( | |||||||||||||||||||||||||||||||||||||||||
| 339 | 'MEDIAWIKI-00099: No token', | ||||||||||||||||||||||||||||||||||||||||||
| 340 | Action => $action, | ||||||||||||||||||||||||||||||||||||||||||
| 341 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | return $token; | |||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | =head3 editPage() - Speichere Seite | ||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | $res = $mw->editPage($pageId,$text); # [1] | ||||||||||||||||||||||||||||||||||||||||||
| 354 | $res = $mw->editPage($title,$text); # [2] | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | =head4 Arguments | ||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | =item $pageId | ||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | Page-Id der Seite. | ||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | =item $title | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | Titel der Seite. | ||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | =item $text | ||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | Text der Seite | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | Response (Hash-Referenz) | ||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | =head4 Description | ||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | Dies ist die Lowlevel-Methode zum Speichern einer Seite oder | ||||||||||||||||||||||||||||||||||||||||||
| 381 | des Contents einer Seite. Eine weitergehende Logik, die auch | ||||||||||||||||||||||||||||||||||||||||||
| 382 | Titelnderungen erlaubt, implementiert die Methode $mw->L<load|"load() - Lade Seite oder Mediendatei ins Wiki">(). | ||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | In Fassung [1] wird der Content der Seite mit der Page-Id $pageId | ||||||||||||||||||||||||||||||||||||||||||
| 385 | auf Text $text gesetzt. Die Seite muss existieren. | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | In Fassung [2] muss die Seite nicht existieren. Der MediaWiki-Server | ||||||||||||||||||||||||||||||||||||||||||
| 388 | implementiert folgende Logik: | ||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | =over 2 | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | Existiert die Seite nicht, wird sie angelegt. | ||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | Existiert die Seite und ist der Text verschieden, wird der | ||||||||||||||||||||||||||||||||||||||||||
| 399 | bestehende Text ersetzt. | ||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | Existiert die Seite und ist der Text identisch, wird der | ||||||||||||||||||||||||||||||||||||||||||
| 404 | Aufruf vom Wiki-Server ignoriert. | ||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | sub editPage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
editPage: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | my ($self,$arg,$text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | # Edit-Token besorgen | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | my $token = $self->getToken('edit'); | |||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | # Seite speichern | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | my $res = $self->send('POST','edit', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | token => $token, | ||||||||||||||||||||||||||||||||||||||||||
| 422 | $arg =~ /^\d+$/? (pageid => $arg): (title => $arg), | ||||||||||||||||||||||||||||||||||||||||||
| 423 | text => $text, | ||||||||||||||||||||||||||||||||||||||||||
| 424 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | # CAPTCHA behandeln. Wir behandeln den CAPTCH-Type "simple" automatisch. | ||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | ▶ | if (my $h = $res->{'edit'}->{'captcha'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | my $captchaType = $h->{'type'}; | |||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | if ($captchaType eq 'simple') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | my $captchaId = $h->{'id'}; | |||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | my $captchaQuestion = $h->{'question'}; | |||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | # Request mit gelöstem CAPTCHA wiederholen | ||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | $res = $self->send('POST','edit', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | captchaid => $captchaId, | ||||||||||||||||||||||||||||||||||||||||||
| 438 | captchaword => eval "$captchaQuestion", | ||||||||||||||||||||||||||||||||||||||||||
| 439 | token => $token, | ||||||||||||||||||||||||||||||||||||||||||
| 440 | $arg =~ /^\d+$/? (pageid => $arg): (title => $arg), | ||||||||||||||||||||||||||||||||||||||||||
| 441 | text => $text, | ||||||||||||||||||||||||||||||||||||||||||
| 442 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||
| 444 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | $self->throw( | |||||||||||||||||||||||||||||||||||||||||
| 446 | 'MEDIAWIKI-00099: Unknown CAPTCHA type', | ||||||||||||||||||||||||||||||||||||||||||
| 447 | CaptchaType => $captchaType, | ||||||||||||||||||||||||||||||||||||||||||
| 448 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | return $res; | |||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||
| 455 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | =head3 getPage() - Liefere Seite | ||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||
| 459 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | $pag = $mw->getPage($pageId,@opt); | ||||||||||||||||||||||||||||||||||||||||||
| 462 | $pag = $mw->getPage($title,@opt); | ||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||
| 464 | =head4 Arguments | ||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||
| 466 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | =item $pageId | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | Page-Id der Seite. | ||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | =item $title | ||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | Titel der Seite. | ||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||
| 478 | =head4 Options | ||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||
| 482 | =item -sloppy => $bool (Default: 0) | ||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | Wirf keine Exception, wenn die Seite nicht gefunden wird, sondern | ||||||||||||||||||||||||||||||||||||||||||
| 485 | liefere undef. | ||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||
| 489 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | Page-Objekt (Hash-Referenz) | ||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||
| 493 | =head4 Description | ||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||
| 495 | Ermittele die Seite mit der Page-Id $pageId bzw. dem Titel $title und | ||||||||||||||||||||||||||||||||||||||||||
| 496 | liefere diese zurück. Die Methode erkennt eine Page-Id daran, dass | ||||||||||||||||||||||||||||||||||||||||||
| 497 | der Wert ausschließlich aus Ziffern besteht. Alles andere wird als | ||||||||||||||||||||||||||||||||||||||||||
| 498 | Seitentitel interpretiert. | ||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | Der geliefere Hash besitzt folgende Komponenten, die auch per | ||||||||||||||||||||||||||||||||||||||||||
| 501 | Accessor-Methode abgefragt werden können: | ||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||
| 503 | =over 2 | ||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||
| 505 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||
| 507 | =over 2 | ||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||
| 511 | (= Inhalt der Seite) | ||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||
| 513 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | comment | ||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | contentformat | ||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||
| 523 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||
| 525 | contentmodel | ||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||
| 527 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | ns | ||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||
| 531 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||
| 533 | pageid | ||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||
| 537 | parentid | ||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||
| 539 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | revid | ||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||
| 543 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||
| 545 | size | ||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||
| 547 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||
| 549 | timestamp | ||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||
| 553 | title | ||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||
| 555 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | user | ||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||
| 559 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||
| 561 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||
| 563 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | ▶ | sub getPage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getPage: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | my ($self,$arg) = splice @_,0,2; | |||||||||||||||||||||||||||||||||||||||||
| 567 | # @_: @opt | ||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||
| 569 | # Optionen | ||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | my $sloppy = 0; | |||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | Quiq::Option->extract(\@_, | |||||||||||||||||||||||||||||||||||||||||
| 574 | -sloppy => \$sloppy, | ||||||||||||||||||||||||||||||||||||||||||
| 575 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||
| 577 | # Request ausführen | ||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | ▶ | my $res = $self->send('GET','query', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 580 | $arg =~ /^\d+$/? (pageids => $arg): (titles => $arg), | ||||||||||||||||||||||||||||||||||||||||||
| 581 | prop => 'revisions', | ||||||||||||||||||||||||||||||||||||||||||
| 582 | rvprop => 'ids|flags|timestamp|user|comment|size|content', | ||||||||||||||||||||||||||||||||||||||||||
| 583 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||
| 585 | # Extrahiere Seite aus Seitenliste | ||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | my $pag = $self->reduceToPage($res,$sloppy); | |||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | ▶ | if (!$pag) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||
| 591 | # Wir bauen die gelieferte Struktur in einen einzelnen Hash um | ||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | my $rev = $pag->{'revisions'}->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | delete $pag->{'revisions'}; | |||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | $pag = {%$pag,%$rev}; | |||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | ▶ | if ($self->debug) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | $self->log('PAGE',Quiq::Debug->dump($pag,colored=>$self->color)); | |||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | return Quiq::Hash->new($pag); | |||||||||||||||||||||||||||||||||||||||||
| 602 | } | ||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||
| 604 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||
| 606 | =head3 movePage() - Benenne Seite um | ||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||
| 608 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||
| 610 | $res = $mw->movePage($pageId,$newTitle,@opt); | ||||||||||||||||||||||||||||||||||||||||||
| 611 | $res = $mw->movePage($oldTitle,$newTitle,@opt); | ||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||
| 613 | =head4 Arguments | ||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||
| 615 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||
| 617 | =item $pageId | ||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||
| 619 | Page-Id der Seite. | ||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||
| 621 | =item $oldTitle | ||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||
| 623 | Titel der Seite. | ||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||
| 625 | =item $newTitle | ||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||
| 627 | Zukünftiger Titel der Seite. | ||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||
| 629 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||
| 631 | =head4 Options | ||||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||
| 633 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||
| 635 | =item -reason => $text | ||||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||
| 637 | Grund für die Umbenennung. | ||||||||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||||||||
| 639 | =item -redirect => $bool (Default: 1) | ||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||
| 641 | Erzeuge ein Redirekt von der alten zur neuen Seite. Wird | ||||||||||||||||||||||||||||||||||||||||||
| 642 | -redirect => 0 gesetzt, unterbleibt dies. | ||||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||
| 644 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||||
| 646 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||
| 648 | Response (Hash-Referenz) | ||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||
| 650 | =head4 Description | ||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||
| 652 | Benenne die Seite mit Page-Id $pageId oder dem Titel $oldTitle | ||||||||||||||||||||||||||||||||||||||||||
| 653 | in $newTitle um. Die alte Seite existiert weiterhin. Das Wiki | ||||||||||||||||||||||||||||||||||||||||||
| 654 | richtet automatisch eine Umleitung von der alten zur neuen | ||||||||||||||||||||||||||||||||||||||||||
| 655 | Seite ein, sofern beim Aufruf nicht -redirect => 0 angegeben wird. | ||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||
| 657 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||
| 659 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||
| 661 | 0 | ▶ | sub movePage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
movePage: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 662 | 0 | my ($self,$arg,$newTitle) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||
| 664 | # Optionen | ||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | my $reason = undef; | |||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | my $redirect = 1; | |||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||
| 669 | 0 | Quiq::Option->extract(\@_, | |||||||||||||||||||||||||||||||||||||||||
| 670 | -reason => \$reason, | ||||||||||||||||||||||||||||||||||||||||||
| 671 | -redirect => \$redirect, | ||||||||||||||||||||||||||||||||||||||||||
| 672 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||
| 674 | # Edit-Token besorgen | ||||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | my $token = $self->getToken('edit'); | |||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||
| 677 | # Seite umbenennen | ||||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | ▶ | return $self->send('POST','move', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 680 | token => $token, | ||||||||||||||||||||||||||||||||||||||||||
| 681 | $arg =~ /^\d+$/? (fromid => $arg): (from => $arg), | ||||||||||||||||||||||||||||||||||||||||||
| 682 | to => $newTitle, | ||||||||||||||||||||||||||||||||||||||||||
| 683 | $reason? (reason => $reason): (), | ||||||||||||||||||||||||||||||||||||||||||
| 684 | !$redirect? (noredirect => ''): (), | ||||||||||||||||||||||||||||||||||||||||||
| 685 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 686 | } | ||||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||
| 688 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||
| 690 | =head3 siteInfo() - Liefere Information über Server | ||||||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||||||
| 692 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||
| 694 | $res = $mw->siteInfo; | ||||||||||||||||||||||||||||||||||||||||||
| 695 | $res = $mw->siteInfo(@properties); | ||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||
| 697 | =head4 Arguments | ||||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||
| 699 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||
| 701 | =item @properties | ||||||||||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||||||||||
| 703 | Liste der Sysinfo-Properties, die abgefragt werden sollen. | ||||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||
| 705 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||
| 707 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||||||||||
| 709 | Response (Hash-Referenz) | ||||||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||||||
| 711 | =head4 Description | ||||||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||||||
| 713 | Ermittele die Server-Eigenschaften (genauer: Eigenschaften-Gruppen) | ||||||||||||||||||||||||||||||||||||||||||
| 714 | @properties und liefere das Resultat zurück. Sind keine | ||||||||||||||||||||||||||||||||||||||||||
| 715 | Properties angegeben, werden I<alle> (zur Zeit der Implementierung | ||||||||||||||||||||||||||||||||||||||||||
| 716 | bekannten) Properties abgefragt. | ||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||
| 718 | =head4 Example | ||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||
| 720 | $ quiq-mediawiki ruv statistics --debug | ||||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||
| 722 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||
| 724 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||||||||||||||||
| 726 | 0 | ▶ | sub siteInfo { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
siteInfo: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 727 | 0 | my ($self,@properties) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | my %property = ( | |||||||||||||||||||||||||||||||||||||||||
| 730 | general => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 731 | namespaces => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 732 | namespacealiases => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 733 | specialpagealiases => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 734 | magicwords => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 735 | statistics => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 736 | interwikimap => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 737 | dbrepllag => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 738 | usergroups => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 739 | extensions => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 740 | fileextensions => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 741 | rightsinfo => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 742 | languages => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 743 | skins => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 744 | extensiontags => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 745 | functionhooks => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 746 | showhooks => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 747 | variables => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 748 | protocols => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 749 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | ▶ | if (!@properties) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 751 | 0 | @properties = keys %property; | |||||||||||||||||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||
| 754 | 0 | return $self->send('GET','query', | |||||||||||||||||||||||||||||||||||||||||
| 755 | meta => 'siteinfo', | ||||||||||||||||||||||||||||||||||||||||||
| 756 | siprop => join('|',@properties), | ||||||||||||||||||||||||||||||||||||||||||
| 757 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 758 | } | ||||||||||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||||||||||
| 760 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||||||||||||||||
| 762 | =head3 uploadFile() - Lade Mediendatei hoch | ||||||||||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||||||||||
| 764 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||
| 766 | $res = $mw->uploadFile($file); | ||||||||||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||||||||
| 768 | =head4 Arguments | ||||||||||||||||||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||||||||||||||||
| 770 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||||||||||||||||
| 772 | =item $file | ||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||
| 774 | Pfad der Datei. | ||||||||||||||||||||||||||||||||||||||||||
| 775 | |||||||||||||||||||||||||||||||||||||||||||
| 776 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||
| 778 | =head4 Options | ||||||||||||||||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||||||||||||||||
| 780 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||||||||||||||||
| 782 | =item -force => $bool (Default: 0) | ||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||
| 784 | Lade die Datei auch im Falle von Warnungen hoch, z.B. dass die Datei | ||||||||||||||||||||||||||||||||||||||||||
| 785 | im Wiki bereits existiert. | ||||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||
| 787 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||
| 789 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||||||
| 790 | |||||||||||||||||||||||||||||||||||||||||||
| 791 | Response | ||||||||||||||||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||||||||||||||||
| 793 | =head4 Description | ||||||||||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||||||||||
| 795 | Lade die lokale Mediendatei $file über die Upload-Schnittstelle ins | ||||||||||||||||||||||||||||||||||||||||||
| 796 | MediaWiki hoch. Dies ist typischerweise eine Bilddatei. | ||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||
| 798 | =head4 See Also | ||||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||
| 800 | =over 2 | ||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||
| 802 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||
| 804 | L<API:Upload|https://www.mediawiki.org/wiki/API:Upload> | ||||||||||||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||||||||||||
| 806 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||||||
| 808 | L<File Upload per LWP|http://lwp.interglacial.com/ch05_07.htm> | ||||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||
| 810 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 811 | |||||||||||||||||||||||||||||||||||||||||||
| 812 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||||||||||||||||
| 814 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||||||||||||||||
| 816 | 0 | ▶ | sub uploadFile { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uploadFile: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 817 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||||||||||||
| 819 | # Optionen und Argumente | ||||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||||
| 821 | 0 | my $force = 0; | |||||||||||||||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||||||||||||||||
| 823 | 0 | my $argA = $self->parameters(1,1,\@_, | |||||||||||||||||||||||||||||||||||||||||
| 824 | -force => \$force, | ||||||||||||||||||||||||||||||||||||||||||
| 825 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 826 | 0 | my $file = Quiq::Path->expandTilde(shift @$argA); | |||||||||||||||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||||||||||||||||
| 828 | # Edit-Token besorgen | ||||||||||||||||||||||||||||||||||||||||||
| 829 | 0 | my $token = $self->getToken('edit'); | |||||||||||||||||||||||||||||||||||||||||
| 830 | |||||||||||||||||||||||||||||||||||||||||||
| 831 | # Datei hochladen ($file wird von LWP gelesen) | ||||||||||||||||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||||||||||||||||
| 833 | 0 | my $filename = Quiq::Path->filename($file); | |||||||||||||||||||||||||||||||||||||||||
| 834 | 0 | return $self->send('POST','upload', | |||||||||||||||||||||||||||||||||||||||||
| 835 | token => $token, | ||||||||||||||||||||||||||||||||||||||||||
| 836 | filename => $filename, | ||||||||||||||||||||||||||||||||||||||||||
| 837 | file => [$file], | ||||||||||||||||||||||||||||||||||||||||||
| 838 | ignorewarnings => $force, | ||||||||||||||||||||||||||||||||||||||||||
| 839 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 840 | |||||||||||||||||||||||||||||||||||||||||||
| 841 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||||||||||||||||
| 843 | # Datei hochladen (wir lesen $file selbst) | ||||||||||||||||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||||||||||||||||
| 845 | my $p = Quiq::Path->new; | ||||||||||||||||||||||||||||||||||||||||||
| 846 | my $data = $p->read($file); | ||||||||||||||||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||||||||||||||||
| 848 | # Datei hochladen | ||||||||||||||||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||||||||||||||||
| 850 | my $filename = $p->filename($file); | ||||||||||||||||||||||||||||||||||||||||||
| 851 | return $self->send('POST','upload', | ||||||||||||||||||||||||||||||||||||||||||
| 852 | token => $token, | ||||||||||||||||||||||||||||||||||||||||||
| 853 | filename => $filename, | ||||||||||||||||||||||||||||||||||||||||||
| 854 | file => [undef,$filename,Content=>$data], | ||||||||||||||||||||||||||||||||||||||||||
| 855 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 856 | |||||||||||||||||||||||||||||||||||||||||||
| 857 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 858 | } | ||||||||||||||||||||||||||||||||||||||||||
| 859 | |||||||||||||||||||||||||||||||||||||||||||
| 860 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 861 | |||||||||||||||||||||||||||||||||||||||||||
| 862 | =head3 version() - Versionsnummer des Servers | ||||||||||||||||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||||||||||||||||
| 864 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||||||||||||||||
| 866 | $version = $mw->version; | ||||||||||||||||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||||||||||||||||
| 868 | =head4 Description | ||||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||
| 870 | Ermittele die Versionsnummer des MediaWiki-Servers und liefere | ||||||||||||||||||||||||||||||||||||||||||
| 871 | diese zurück. Die Information wird im Objekt gecached. | ||||||||||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||||||||||
| 873 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||||||||||||||||
| 875 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||||||
| 877 | 0 | ▶ | sub version { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
version: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 878 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 879 | |||||||||||||||||||||||||||||||||||||||||||
| 880 | 0 | ▶ | return $self->memoize('version',sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 881 | 0 | my $res = $self->siteInfo('general'); | |||||||||||||||||||||||||||||||||||||||||
| 882 | 0 | my $version = $res->{'query'}->{'general'}->{'generator'}; | |||||||||||||||||||||||||||||||||||||||||
| 883 | 0 | $version =~ s/^MediaWiki\s+//; | |||||||||||||||||||||||||||||||||||||||||
| 884 | 0 | return $version; | |||||||||||||||||||||||||||||||||||||||||
| 885 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||
| 886 | } | ||||||||||||||||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||||||||||||||||
| 888 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 889 | |||||||||||||||||||||||||||||||||||||||||||
| 890 | =head2 Höhere Operationen | ||||||||||||||||||||||||||||||||||||||||||
| 891 | |||||||||||||||||||||||||||||||||||||||||||
| 892 | =head3 load() - Lade Seite oder Mediendatei ins Wiki | ||||||||||||||||||||||||||||||||||||||||||
| 893 | |||||||||||||||||||||||||||||||||||||||||||
| 894 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||||||
| 895 | |||||||||||||||||||||||||||||||||||||||||||
| 896 | $mw->load($cacheDir,$file,@opt); | ||||||||||||||||||||||||||||||||||||||||||
| 897 | |||||||||||||||||||||||||||||||||||||||||||
| 898 | =head4 Arguments | ||||||||||||||||||||||||||||||||||||||||||
| 899 | |||||||||||||||||||||||||||||||||||||||||||
| 900 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 901 | |||||||||||||||||||||||||||||||||||||||||||
| 902 | =item $cacheDir | ||||||||||||||||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||||||||||||||||
| 904 | Pfad zum Spiegel-Verzeichnis. Der Inhalt des Spiegel-Verzeichnisses wird | ||||||||||||||||||||||||||||||||||||||||||
| 905 | von der Methode verwaltet. Es enthält Kopien der geladenen Dateien. | ||||||||||||||||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||||||||||||||||
| 907 | =item $file | ||||||||||||||||||||||||||||||||||||||||||
| 908 | |||||||||||||||||||||||||||||||||||||||||||
| 909 | Pfad der Datei, die geladen werden soll. Dies kann eine Seitendatei | ||||||||||||||||||||||||||||||||||||||||||
| 910 | (*.mw) oder eine sonstige Datei sein (*.png, *.jpg, *.gif, ...), | ||||||||||||||||||||||||||||||||||||||||||
| 911 | die über die Upload-Schnittstelle des MediaWiki geladen werden kann. | ||||||||||||||||||||||||||||||||||||||||||
| 912 | |||||||||||||||||||||||||||||||||||||||||||
| 913 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 914 | |||||||||||||||||||||||||||||||||||||||||||
| 915 | =head4 Options | ||||||||||||||||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||||||||||||||||
| 917 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||||||||||||||||
| 919 | =item -force => $bool (Default: 0) | ||||||||||||||||||||||||||||||||||||||||||
| 920 | |||||||||||||||||||||||||||||||||||||||||||
| 921 | Lade die Datei ins Wiki, auch wenn sie sich nicht geändert hat | ||||||||||||||||||||||||||||||||||||||||||
| 922 | (gegenüber dem Cache). | ||||||||||||||||||||||||||||||||||||||||||
| 923 | |||||||||||||||||||||||||||||||||||||||||||
| 924 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 925 | |||||||||||||||||||||||||||||||||||||||||||
| 926 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||||||
| 927 | |||||||||||||||||||||||||||||||||||||||||||
| 928 | nichts | ||||||||||||||||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||||||||||||||||
| 930 | =head4 Description | ||||||||||||||||||||||||||||||||||||||||||
| 931 | |||||||||||||||||||||||||||||||||||||||||||
| 932 | Lade Seite oder Mediendatei $file ins Wiki. Hierbei wird ein | ||||||||||||||||||||||||||||||||||||||||||
| 933 | "intelligentes" Verfahren angewendet, das verschiedene Sonderfälle | ||||||||||||||||||||||||||||||||||||||||||
| 934 | berücksichtigt (siehe unten). Eine Kopie der hochgeladenen Datei | ||||||||||||||||||||||||||||||||||||||||||
| 935 | wird im Cache-Verzeichnis $cacheDir abgelegt. Ist die Cache-Version | ||||||||||||||||||||||||||||||||||||||||||
| 936 | eines früheren Aufrufs identisch zu zur aktuellen Version $file, | ||||||||||||||||||||||||||||||||||||||||||
| 937 | kehrt der Aufruf sofort zurück (außer bei Option -force => 1). | ||||||||||||||||||||||||||||||||||||||||||
| 938 | Den Schlüssel stellt der Dateiname dar. Dieser muss über | ||||||||||||||||||||||||||||||||||||||||||
| 939 | allen Dateien eindeutig sein und darf sich extern nicht ändern. | ||||||||||||||||||||||||||||||||||||||||||
| 940 | |||||||||||||||||||||||||||||||||||||||||||
| 941 | Die Datei einer Seite muss die Endung *.mw besitzen und sowohl den | ||||||||||||||||||||||||||||||||||||||||||
| 942 | Titel als auch den Inhalt der Seite als Record (siehe | ||||||||||||||||||||||||||||||||||||||||||
| 943 | Quiq::Record) enthalten. Eine Mediendatei (*.png, *.jpg, ...) | ||||||||||||||||||||||||||||||||||||||||||
| 944 | wird wie sie ist an die Methode übergeben. | ||||||||||||||||||||||||||||||||||||||||||
| 945 | |||||||||||||||||||||||||||||||||||||||||||
| 946 | In der Cache-Datei einer Seite speichert die Methode die Page-Id | ||||||||||||||||||||||||||||||||||||||||||
| 947 | der Seite. Dadurch kann die Methode auch bei Titeländerungen die | ||||||||||||||||||||||||||||||||||||||||||
| 948 | Seite im Wiki ermitteln und vor dem Speichern eine move-Operation | ||||||||||||||||||||||||||||||||||||||||||
| 949 | ausführen. Die Fälle im Einzelnen: | ||||||||||||||||||||||||||||||||||||||||||
| 950 | |||||||||||||||||||||||||||||||||||||||||||
| 951 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 952 | |||||||||||||||||||||||||||||||||||||||||||
| 953 | =item Aufruf wird ignoriert | ||||||||||||||||||||||||||||||||||||||||||
| 954 | |||||||||||||||||||||||||||||||||||||||||||
| 955 | Die Datei existiert im Cache und ist identisch zu dieser | ||||||||||||||||||||||||||||||||||||||||||
| 956 | und -force ist nicht gesetzt. | ||||||||||||||||||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||||||||||||||||
| 958 | =item Seite oder Mediendatei wird im Wiki gespeichert | ||||||||||||||||||||||||||||||||||||||||||
| 959 | |||||||||||||||||||||||||||||||||||||||||||
| 960 | =over 2 | ||||||||||||||||||||||||||||||||||||||||||
| 961 | |||||||||||||||||||||||||||||||||||||||||||
| 962 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 963 | |||||||||||||||||||||||||||||||||||||||||||
| 964 | Die Datei existiert nicht im Cache | ||||||||||||||||||||||||||||||||||||||||||
| 965 | |||||||||||||||||||||||||||||||||||||||||||
| 966 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 967 | |||||||||||||||||||||||||||||||||||||||||||
| 968 | Die Datei existiert im Cache und ist gegenüber der externen | ||||||||||||||||||||||||||||||||||||||||||
| 969 | Datei verschieden | ||||||||||||||||||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||||||||||||||||
| 971 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 972 | |||||||||||||||||||||||||||||||||||||||||||
| 973 | Option -force ist gesetzt | ||||||||||||||||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||||||||||||||||
| 975 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 976 | |||||||||||||||||||||||||||||||||||||||||||
| 977 | =item Aufruf wird mit Fehlermeldung zurückgewiesen | ||||||||||||||||||||||||||||||||||||||||||
| 978 | |||||||||||||||||||||||||||||||||||||||||||
| 979 | Die Datei ist eine Seite und soll gespeichert werden, wobei ein | ||||||||||||||||||||||||||||||||||||||||||
| 980 | Unterschied zwischen Cache- und Wiki-Datei festgestellt wird. | ||||||||||||||||||||||||||||||||||||||||||
| 981 | Das bedeutet, im Wiki wurde die Datei seit dem letzten Speichern | ||||||||||||||||||||||||||||||||||||||||||
| 982 | geändert. Der Aufruf ist nur durch Setzen der Option -force möglich, | ||||||||||||||||||||||||||||||||||||||||||
| 983 | denn die Änderung muss händisch in die externe Datei eingepflegt | ||||||||||||||||||||||||||||||||||||||||||
| 984 | werden. | ||||||||||||||||||||||||||||||||||||||||||
| 985 | |||||||||||||||||||||||||||||||||||||||||||
| 986 | =item Seite wird vor dem Speichern umbenannt | ||||||||||||||||||||||||||||||||||||||||||
| 987 | |||||||||||||||||||||||||||||||||||||||||||
| 988 | Die Datei ist eine Seite und der Titel der Seite ist zwischen | ||||||||||||||||||||||||||||||||||||||||||
| 989 | Cachedatei und externer Datei unterschiedlich. Die Seite wird | ||||||||||||||||||||||||||||||||||||||||||
| 990 | automatisch im Wiki umbenannt. | ||||||||||||||||||||||||||||||||||||||||||
| 991 | |||||||||||||||||||||||||||||||||||||||||||
| 992 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 993 | |||||||||||||||||||||||||||||||||||||||||||
| 994 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 995 | |||||||||||||||||||||||||||||||||||||||||||
| 996 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 997 | |||||||||||||||||||||||||||||||||||||||||||
| 998 | 0 | ▶ | sub load { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load: not called CC=19 SCAR=59.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 999 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1000 | # @_: $cacheDir,$file,@opt | ||||||||||||||||||||||||||||||||||||||||||
| 1001 | |||||||||||||||||||||||||||||||||||||||||||
| 1002 | # Optionen und Argumente | ||||||||||||||||||||||||||||||||||||||||||
| 1003 | |||||||||||||||||||||||||||||||||||||||||||
| 1004 | 0 | my $force = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1005 | |||||||||||||||||||||||||||||||||||||||||||
| 1006 | 0 | my $argA = $self->parameters(2,2,\@_, | |||||||||||||||||||||||||||||||||||||||||
| 1007 | -force => \$force, | ||||||||||||||||||||||||||||||||||||||||||
| 1008 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1009 | 0 | my ($cacheDir,$file) = @$argA; | |||||||||||||||||||||||||||||||||||||||||
| 1010 | |||||||||||||||||||||||||||||||||||||||||||
| 1011 | # Pfad-Objekt für Pfad-Operationen instantiieren | ||||||||||||||||||||||||||||||||||||||||||
| 1012 | 0 | my $p = Quiq::Path->new; | |||||||||||||||||||||||||||||||||||||||||
| 1013 | |||||||||||||||||||||||||||||||||||||||||||
| 1014 | 0 | my $cacheName = $p->filename($file); | |||||||||||||||||||||||||||||||||||||||||
| 1015 | 0 | my $varFile = sprintf '%s/%s',$cacheDir,$cacheName; | |||||||||||||||||||||||||||||||||||||||||
| 1016 | |||||||||||||||||||||||||||||||||||||||||||
| 1017 | 0 | my $ext = $p->extension($file); | |||||||||||||||||||||||||||||||||||||||||
| 1018 | 0 | ▶ | if ($ext ne 'mw') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1019 | # Datei Upload | ||||||||||||||||||||||||||||||||||||||||||
| 1020 | |||||||||||||||||||||||||||||||||||||||||||
| 1021 | 0 | my $exists = $p->exists($varFile); | |||||||||||||||||||||||||||||||||||||||||
| 1022 | 0 | ▶ | if ($force || !$exists || $p->compare($file,$varFile)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$force or not $exists or $p->compare($file, $varFile)
$force or not $exists
MC/DC0%0/3
$force or not $exists or $p->compare($file, $varFile)
$force
not $exists
$p->compare($file, $varFile)
Truth table0%0/4
A or not(B) or C
A= $forceB= not $existsC= $p->compare($file, $varFile)
| |||||||||||||||||||||||||||||||||||||||||||
| 1023 | 0 | my $res = $self->uploadFile($file,-force=>1); | |||||||||||||||||||||||||||||||||||||||||
| 1024 | 0 | ▶ | printf "File %s: %s\n",$exists? 'updated': 'created', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1025 | ucfirst $cacheName; | ||||||||||||||||||||||||||||||||||||||||||
| 1026 | 0 | $p->copy($file,$varFile); | |||||||||||||||||||||||||||||||||||||||||
| 1027 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1028 | |||||||||||||||||||||||||||||||||||||||||||
| 1029 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1030 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1031 | |||||||||||||||||||||||||||||||||||||||||||
| 1032 | # Externe Seite: Information (Titel, Inhalt) ermitteln | ||||||||||||||||||||||||||||||||||||||||||
| 1033 | |||||||||||||||||||||||||||||||||||||||||||
| 1034 | 0 | my $pageCode = $p->read($file,-decode=>'utf-8'); | |||||||||||||||||||||||||||||||||||||||||
| 1035 | 0 | my $recNew = Quiq::Hash->new(Quiq::Record->fromString($pageCode)); | |||||||||||||||||||||||||||||||||||||||||
| 1036 | 0 | my ($titleNew,$contentNew) = $recNew->get('Title','Content'); | |||||||||||||||||||||||||||||||||||||||||
| 1037 | |||||||||||||||||||||||||||||||||||||||||||
| 1038 | # Cache-Seite: Information (Id, Titel, Inhalt) ermitteln. | ||||||||||||||||||||||||||||||||||||||||||
| 1039 | # Existiert keine Cache-Seite, versuchen wir, die Seite über | ||||||||||||||||||||||||||||||||||||||||||
| 1040 | # den Titel im Wiki zu finden. Falls sie im Wiki existiert, erzeugen | ||||||||||||||||||||||||||||||||||||||||||
| 1041 | # wir aus ihr die Cache-Seite. Falls nicht, legen wir eine leere | ||||||||||||||||||||||||||||||||||||||||||
| 1042 | # Cache-Seite an (die notwendig von der externen Seite differiert). | ||||||||||||||||||||||||||||||||||||||||||
| 1043 | |||||||||||||||||||||||||||||||||||||||||||
| 1044 | 0 | ▶ | if (!$p->exists($varFile)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1045 | 0 | my $pageId = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1046 | 0 | my $title = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1047 | 0 | my $content = ''; | |||||||||||||||||||||||||||||||||||||||||
| 1048 | |||||||||||||||||||||||||||||||||||||||||||
| 1049 | 0 | ▶ | if (my $pag = $self->getPage($titleNew,-sloppy=>1)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1050 | 0 | $pageId = $pag->{'pageid'}; | |||||||||||||||||||||||||||||||||||||||||
| 1051 | 0 | $title = $pag->{'title'}; | |||||||||||||||||||||||||||||||||||||||||
| 1052 | 0 | $content = $pag->{'*'}; | |||||||||||||||||||||||||||||||||||||||||
| 1053 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1054 | |||||||||||||||||||||||||||||||||||||||||||
| 1055 | 0 | my $data = Quiq::Record->toString( | |||||||||||||||||||||||||||||||||||||||||
| 1056 | Id => $pageId, | ||||||||||||||||||||||||||||||||||||||||||
| 1057 | Title => $title, | ||||||||||||||||||||||||||||||||||||||||||
| 1058 | Content => $content, | ||||||||||||||||||||||||||||||||||||||||||
| 1059 | -format => '@', | ||||||||||||||||||||||||||||||||||||||||||
| 1060 | -space => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 1061 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1062 | 0 | $p->write($varFile,$data, | |||||||||||||||||||||||||||||||||||||||||
| 1063 | -recursive => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 1064 | -encode => 'UTF-8', | ||||||||||||||||||||||||||||||||||||||||||
| 1065 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1066 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1067 | |||||||||||||||||||||||||||||||||||||||||||
| 1068 | 0 | my $recOld = Quiq::Hash->new(Quiq::Record->fromFile( | |||||||||||||||||||||||||||||||||||||||||
| 1069 | $varFile,-encoding=>'UTF-8')); | ||||||||||||||||||||||||||||||||||||||||||
| 1070 | 0 | my ($pageId,$titleOld,$contentOld) = $recOld->get('Id','Title','Content'); | |||||||||||||||||||||||||||||||||||||||||
| 1071 | |||||||||||||||||||||||||||||||||||||||||||
| 1072 | 0 | ▶ | if ($pageId) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1073 | # Wiki-Seite existiert bereits | ||||||||||||||||||||||||||||||||||||||||||
| 1074 | |||||||||||||||||||||||||||||||||||||||||||
| 1075 | 0 | ▶ | if (!$force && $titleNew eq $titleOld && $contentNew eq $contentOld) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not $force and $titleNew eq $titleOld and $contentNew eq $contentOld
not $force and $titleNew eq $titleOld
MC/DC0%0/3
not $force and $titleNew eq $titleOld and $contentNew eq $contentOld
not $force
$titleNew eq $titleOld
$contentNew eq $contentOld
Truth table0%0/4
not(A) and B and C
A= not $forceB= $titleNew eq $titleOldC= $contentNew eq $contentOld
| |||||||||||||||||||||||||||||||||||||||||||
| 1076 | # Keine Differenz, es gibt nichts zu tun. | ||||||||||||||||||||||||||||||||||||||||||
| 1077 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1078 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1079 | 0 | ▶ | if ($contentNew ne $contentOld) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1080 | # Der Inhalt zwischen der externen Seite und der Cache-Seite | ||||||||||||||||||||||||||||||||||||||||||
| 1081 | # hat sich geändert. Wir prüfen ob die Wiki-Seite geändert | ||||||||||||||||||||||||||||||||||||||||||
| 1082 | # wurde, also zwischen dem Inhalt der Cache-Seite und | ||||||||||||||||||||||||||||||||||||||||||
| 1083 | # der Wiki-Seite ein Unterschied besteht. | ||||||||||||||||||||||||||||||||||||||||||
| 1084 | |||||||||||||||||||||||||||||||||||||||||||
| 1085 | 0 | ▶ | if (my $pag = $self->getPage($pageId)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1086 | 0 | ▶ | if ($pag->{'*'} ne $contentOld) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1087 | 0 | ▶ | if (!$force) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1088 | printf "ERROR: Page has changed in Wiki: pageId=%s". | ||||||||||||||||||||||||||||||||||||||||||
| 1089 | " '%s'. Update skipped! Use --force to update the". | ||||||||||||||||||||||||||||||||||||||||||
| 1090 | 0 | " page.\n",$pageId,$pag->{'title'}; | |||||||||||||||||||||||||||||||||||||||||
| 1091 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1092 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1093 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1094 | printf "WARNING: Page has changed in Wiki: pageId=%s". | ||||||||||||||||||||||||||||||||||||||||||
| 1095 | 0 | " '%s'\n",$pageId,$pag->{'title'}; | |||||||||||||||||||||||||||||||||||||||||
| 1096 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1097 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1098 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1099 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1100 | 0 | ▶ | if ($titleNew ne $titleOld) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1101 | # Der Titel zwischen der externen Seite und der Cache-Seite | ||||||||||||||||||||||||||||||||||||||||||
| 1102 | # hat sich geändert. Wir benennen die Wiki-Seite um. | ||||||||||||||||||||||||||||||||||||||||||
| 1103 | |||||||||||||||||||||||||||||||||||||||||||
| 1104 | 0 | $self->movePage($pageId,$titleNew); | |||||||||||||||||||||||||||||||||||||||||
| 1105 | 0 | print "Page moved: pageId=$pageId '$titleOld' => '$titleNew'\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1108 | |||||||||||||||||||||||||||||||||||||||||||
| 1109 | # Die Seite ist neu oder hat sich geändert. Wir bringen den | ||||||||||||||||||||||||||||||||||||||||||
| 1110 | # neusten Stand aufs Wiki und speichern ihn im Cache. | ||||||||||||||||||||||||||||||||||||||||||
| 1111 | |||||||||||||||||||||||||||||||||||||||||||
| 1112 | 0 | ▶ | my $op = $pageId? 'update': 'create'; # | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1113 | |||||||||||||||||||||||||||||||||||||||||||
| 1114 | 0 | ▶ | my $res = $self->editPage($pageId || $titleNew,$contentNew); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$pageId || $titleNew
MC/DC0%0/2
$pageId || $titleNew
$pageId
$titleNew
Truth table0%0/3
A || B
A= $pageIdB= $titleNew
| |||||||||||||||||||||||||||||||||||||||||||
| 1115 | 0 | $pageId = $res->{'edit'}->{'pageid'}; | |||||||||||||||||||||||||||||||||||||||||
| 1116 | 0 | my $data = Quiq::Record->toString( | |||||||||||||||||||||||||||||||||||||||||
| 1117 | Id => $pageId, | ||||||||||||||||||||||||||||||||||||||||||
| 1118 | Title => $titleNew, | ||||||||||||||||||||||||||||||||||||||||||
| 1119 | Content => $contentNew, | ||||||||||||||||||||||||||||||||||||||||||
| 1120 | -format => '@', | ||||||||||||||||||||||||||||||||||||||||||
| 1121 | -space => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 1122 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1123 | 0 | $p->write($varFile,$data, | |||||||||||||||||||||||||||||||||||||||||
| 1124 | -encode => 'UTF-8', | ||||||||||||||||||||||||||||||||||||||||||
| 1125 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1126 | |||||||||||||||||||||||||||||||||||||||||||
| 1127 | 0 | printf "Page %sd: pageId=%s '%s'\n",$op,$pageId,$titleNew; | |||||||||||||||||||||||||||||||||||||||||
| 1128 | |||||||||||||||||||||||||||||||||||||||||||
| 1129 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1131 | |||||||||||||||||||||||||||||||||||||||||||
| 1132 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 1133 | |||||||||||||||||||||||||||||||||||||||||||
| 1134 | =head2 Kommunikation | ||||||||||||||||||||||||||||||||||||||||||
| 1135 | |||||||||||||||||||||||||||||||||||||||||||
| 1136 | =head3 send() - Sende Request, empfange Response | ||||||||||||||||||||||||||||||||||||||||||
| 1137 | |||||||||||||||||||||||||||||||||||||||||||
| 1138 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||||||
| 1139 | |||||||||||||||||||||||||||||||||||||||||||
| 1140 | $res = $mw->send($method,$action,@keyVal); | ||||||||||||||||||||||||||||||||||||||||||
| 1141 | |||||||||||||||||||||||||||||||||||||||||||
| 1142 | =head4 Arguments | ||||||||||||||||||||||||||||||||||||||||||
| 1143 | |||||||||||||||||||||||||||||||||||||||||||
| 1144 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 1145 | |||||||||||||||||||||||||||||||||||||||||||
| 1146 | =item $method | ||||||||||||||||||||||||||||||||||||||||||
| 1147 | |||||||||||||||||||||||||||||||||||||||||||
| 1148 | Die HTTP Request-Methode: 'GET' oder 'POST'. | ||||||||||||||||||||||||||||||||||||||||||
| 1149 | |||||||||||||||||||||||||||||||||||||||||||
| 1150 | =item $action | ||||||||||||||||||||||||||||||||||||||||||
| 1151 | |||||||||||||||||||||||||||||||||||||||||||
| 1152 | Die Aktion, die ausgeführt werden soll, z.B. 'query'. | ||||||||||||||||||||||||||||||||||||||||||
| 1153 | |||||||||||||||||||||||||||||||||||||||||||
| 1154 | =item @keyVal | ||||||||||||||||||||||||||||||||||||||||||
| 1155 | |||||||||||||||||||||||||||||||||||||||||||
| 1156 | Die Liste der Schlüssel/Wert-Paare, die an den Server übermittelt werden, | ||||||||||||||||||||||||||||||||||||||||||
| 1157 | entweder als URL-Parameter im Falle von GET oder im Body des Requests | ||||||||||||||||||||||||||||||||||||||||||
| 1158 | im Falle von POST. | ||||||||||||||||||||||||||||||||||||||||||
| 1159 | |||||||||||||||||||||||||||||||||||||||||||
| 1160 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 1161 | |||||||||||||||||||||||||||||||||||||||||||
| 1162 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||||||
| 1163 | |||||||||||||||||||||||||||||||||||||||||||
| 1164 | Dekodiertes JSON in UTF-8 als Perl-Hash | ||||||||||||||||||||||||||||||||||||||||||
| 1165 | |||||||||||||||||||||||||||||||||||||||||||
| 1166 | =head4 Description | ||||||||||||||||||||||||||||||||||||||||||
| 1167 | |||||||||||||||||||||||||||||||||||||||||||
| 1168 | Grundlegende Methode, über die sämtliche Interaktion mit dem | ||||||||||||||||||||||||||||||||||||||||||
| 1169 | MediaWiki-Server läuft. Die Interaktion besteht in einem Austausch | ||||||||||||||||||||||||||||||||||||||||||
| 1170 | von Schlüssel/Wert-Paaren via HTTP mittels GET oder POST. Der Client | ||||||||||||||||||||||||||||||||||||||||||
| 1171 | sendet mit einem Request eine Menge von Schlüssel/Wert-Paaren und erhält | ||||||||||||||||||||||||||||||||||||||||||
| 1172 | vom Server in der Response eine Menge von Schlüssel/Wert-Paaren zurück. | ||||||||||||||||||||||||||||||||||||||||||
| 1173 | In beide Richtungen wird UTF-8 Encoding vorausgesetzt. D.h. die | ||||||||||||||||||||||||||||||||||||||||||
| 1174 | @keyVal-Elemente müssen UTF-8 kodiert sein, die Elemente in der | ||||||||||||||||||||||||||||||||||||||||||
| 1175 | Response $res sind es ebenfalls. | ||||||||||||||||||||||||||||||||||||||||||
| 1176 | |||||||||||||||||||||||||||||||||||||||||||
| 1177 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1178 | |||||||||||||||||||||||||||||||||||||||||||
| 1179 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 1180 | |||||||||||||||||||||||||||||||||||||||||||
| 1181 | 0 | ▶ | sub send { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1182 | 0 | my ($self,$method,$action) = splice @_,0,3; | |||||||||||||||||||||||||||||||||||||||||
| 1183 | # @_: @keyVal | ||||||||||||||||||||||||||||||||||||||||||
| 1184 | |||||||||||||||||||||||||||||||||||||||||||
| 1185 | 0 | my ($ua,$url) = $self->get(qw/ua url/); | |||||||||||||||||||||||||||||||||||||||||
| 1186 | |||||||||||||||||||||||||||||||||||||||||||
| 1187 | # Wir wollen die Antwort in JSON | ||||||||||||||||||||||||||||||||||||||||||
| 1188 | |||||||||||||||||||||||||||||||||||||||||||
| 1189 | # my @keyVal = (action=>$action,formatversion=>2,format=>'json',@_); | ||||||||||||||||||||||||||||||||||||||||||
| 1190 | 0 | my @keyVal = (action=>$action,format=>'json',@_); | |||||||||||||||||||||||||||||||||||||||||
| 1191 | |||||||||||||||||||||||||||||||||||||||||||
| 1192 | # HTTP-Request erzeugen und ausführen (lassen sich die Aufrufe | ||||||||||||||||||||||||||||||||||||||||||
| 1193 | # ohne Fallunterscheidung vereinheitlichen?) | ||||||||||||||||||||||||||||||||||||||||||
| 1194 | |||||||||||||||||||||||||||||||||||||||||||
| 1195 | 0 | my $res; | |||||||||||||||||||||||||||||||||||||||||
| 1196 | 0 | ▶ | if ($action eq 'upload') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1197 | # Im Falle eines File-Upload muss die Liste der Schlüssel/Wert-Paare | ||||||||||||||||||||||||||||||||||||||||||
| 1198 | # per Array-Referenz übergeben werden und die hochzuladende Datei | ||||||||||||||||||||||||||||||||||||||||||
| 1199 | # per file => [undef,$name,Content=>$data] (siehe Methode upload) | ||||||||||||||||||||||||||||||||||||||||||
| 1200 | 0 | $res = $ua->post($url,[@keyVal],Content_Type=>'form-data'); | |||||||||||||||||||||||||||||||||||||||||
| 1201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1202 | elsif ($method eq 'GET') { | ||||||||||||||||||||||||||||||||||||||||||
| 1203 | 0 | my $queryString = Quiq::Url->queryEncode(-separator=>'&',@keyVal); | |||||||||||||||||||||||||||||||||||||||||
| 1204 | 0 | $res = $ua->get("$url?$queryString"); | |||||||||||||||||||||||||||||||||||||||||
| 1205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1206 | elsif ($method eq 'POST') { | ||||||||||||||||||||||||||||||||||||||||||
| 1207 | 0 | $res = $ua->post($url,[@keyVal]); | |||||||||||||||||||||||||||||||||||||||||
| 1208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1209 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1210 | 0 | $self->throw( | |||||||||||||||||||||||||||||||||||||||||
| 1211 | 'MEDIAWIKI-00099: Unknown request method', | ||||||||||||||||||||||||||||||||||||||||||
| 1212 | Method => $method, | ||||||||||||||||||||||||||||||||||||||||||
| 1213 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1215 | |||||||||||||||||||||||||||||||||||||||||||
| 1216 | # Logge Request | ||||||||||||||||||||||||||||||||||||||||||
| 1217 | |||||||||||||||||||||||||||||||||||||||||||
| 1218 | 0 | ▶ | if ($self->debug) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1219 | 0 | $self->log('REQUEST',$res->request->as_string); | |||||||||||||||||||||||||||||||||||||||||
| 1220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1221 | |||||||||||||||||||||||||||||||||||||||||||
| 1222 | 0 | ▶ | if (!$res->is_success) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1223 | 0 | $self->throw( | |||||||||||||||||||||||||||||||||||||||||
| 1224 | 'MEDIAWIKI-00099: HTTP request failed', | ||||||||||||||||||||||||||||||||||||||||||
| 1225 | Request => $res->request->as_string, | ||||||||||||||||||||||||||||||||||||||||||
| 1226 | StatusLine => $res->status_line, | ||||||||||||||||||||||||||||||||||||||||||
| 1227 | Response => $res->content, | ||||||||||||||||||||||||||||||||||||||||||
| 1228 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1230 | |||||||||||||||||||||||||||||||||||||||||||
| 1231 | # Logge Response | ||||||||||||||||||||||||||||||||||||||||||
| 1232 | |||||||||||||||||||||||||||||||||||||||||||
| 1233 | 0 | ▶ | if ($self->debug) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1234 | 0 | $self->log('RESPONSE',$res->as_string); | |||||||||||||||||||||||||||||||||||||||||
| 1235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1236 | |||||||||||||||||||||||||||||||||||||||||||
| 1237 | # Wandele Body von JSON in Perl-Datenstruktur | ||||||||||||||||||||||||||||||||||||||||||
| 1238 | 0 | my $json = JSON::decode_json($res->content); | |||||||||||||||||||||||||||||||||||||||||
| 1239 | |||||||||||||||||||||||||||||||||||||||||||
| 1240 | # Logge JSON | ||||||||||||||||||||||||||||||||||||||||||
| 1241 | |||||||||||||||||||||||||||||||||||||||||||
| 1242 | 0 | ▶ | if ($self->debug) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1243 | 0 | $self->log('JSON',Quiq::Debug->dump($json,colored=>$self->color)); | |||||||||||||||||||||||||||||||||||||||||
| 1244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1245 | |||||||||||||||||||||||||||||||||||||||||||
| 1246 | # Prüfe auf MediaWiki API Error | ||||||||||||||||||||||||||||||||||||||||||
| 1247 | |||||||||||||||||||||||||||||||||||||||||||
| 1248 | 0 | ▶ | if ($res->header('MediaWiki-API-Error')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1249 | $self->throw( | ||||||||||||||||||||||||||||||||||||||||||
| 1250 | 'MEDIAWIKI-00099: API error', | ||||||||||||||||||||||||||||||||||||||||||
| 1251 | Request => $res->request->as_string, | ||||||||||||||||||||||||||||||||||||||||||
| 1252 | Code => $json->{'error'}->{'code'}, | ||||||||||||||||||||||||||||||||||||||||||
| 1253 | 0 | Info => $json->{'error'}->{'info'}, | |||||||||||||||||||||||||||||||||||||||||
| 1254 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1256 | |||||||||||||||||||||||||||||||||||||||||||
| 1257 | # Warnungen schreiben wir nach STDERR | ||||||||||||||||||||||||||||||||||||||||||
| 1258 | |||||||||||||||||||||||||||||||||||||||||||
| 1259 | 0 | ▶ | if ($self->warnings && (my $h = $json->{'warnings'})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->warnings and my $h = $json->{"warnings"}
MC/DC0%0/2
$self->warnings and my $h = $json->{"warnings"}
$self->warnings
my $h = $json->{"warnings"}
Truth table0%0/3
A and B
A= $self->warningsB= my $h = $json->{"warnings"}
| |||||||||||||||||||||||||||||||||||||||||||
| 1260 | 0 | for my $key (keys %$h) { | |||||||||||||||||||||||||||||||||||||||||
| 1261 | 0 | warn "WARNING: $key - $h->{$key}->{'*'}\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1262 | # formatversion=2 | ||||||||||||||||||||||||||||||||||||||||||
| 1263 | # warn "WARNING: $key - $h->{$key}->{'warnings'}\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 1264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1266 | |||||||||||||||||||||||||||||||||||||||||||
| 1267 | 0 | return $json; | |||||||||||||||||||||||||||||||||||||||||
| 1268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1269 | |||||||||||||||||||||||||||||||||||||||||||
| 1270 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 1271 | |||||||||||||||||||||||||||||||||||||||||||
| 1272 | =head2 Response Handling | ||||||||||||||||||||||||||||||||||||||||||
| 1273 | |||||||||||||||||||||||||||||||||||||||||||
| 1274 | =head3 reduceToPage() - Reduziere Antwort auf Einzelseite | ||||||||||||||||||||||||||||||||||||||||||
| 1275 | |||||||||||||||||||||||||||||||||||||||||||
| 1276 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||||||
| 1277 | |||||||||||||||||||||||||||||||||||||||||||
| 1278 | $pag = $mw->reduceToPage($res); | ||||||||||||||||||||||||||||||||||||||||||
| 1279 | $pag = $mw->reduceToPage($res,$sloppy); | ||||||||||||||||||||||||||||||||||||||||||
| 1280 | |||||||||||||||||||||||||||||||||||||||||||
| 1281 | =head4 Arguments | ||||||||||||||||||||||||||||||||||||||||||
| 1282 | |||||||||||||||||||||||||||||||||||||||||||
| 1283 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 1284 | |||||||||||||||||||||||||||||||||||||||||||
| 1285 | =item $res | ||||||||||||||||||||||||||||||||||||||||||
| 1286 | |||||||||||||||||||||||||||||||||||||||||||
| 1287 | Response vom Server mit Seitenliste. | ||||||||||||||||||||||||||||||||||||||||||
| 1288 | |||||||||||||||||||||||||||||||||||||||||||
| 1289 | =item $sloppy | ||||||||||||||||||||||||||||||||||||||||||
| 1290 | |||||||||||||||||||||||||||||||||||||||||||
| 1291 | Wirf keine Exception, wenn keine Seite existiert. | ||||||||||||||||||||||||||||||||||||||||||
| 1292 | |||||||||||||||||||||||||||||||||||||||||||
| 1293 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 1294 | |||||||||||||||||||||||||||||||||||||||||||
| 1295 | =head4 Returns | ||||||||||||||||||||||||||||||||||||||||||
| 1296 | |||||||||||||||||||||||||||||||||||||||||||
| 1297 | Reduzierte Response | ||||||||||||||||||||||||||||||||||||||||||
| 1298 | |||||||||||||||||||||||||||||||||||||||||||
| 1299 | =head4 Description | ||||||||||||||||||||||||||||||||||||||||||
| 1300 | |||||||||||||||||||||||||||||||||||||||||||
| 1301 | Reduziere die Server-Response $res mit einer einelementigen | ||||||||||||||||||||||||||||||||||||||||||
| 1302 | Seitenliste der Art | ||||||||||||||||||||||||||||||||||||||||||
| 1303 | |||||||||||||||||||||||||||||||||||||||||||
| 1304 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1305 | query => { | ||||||||||||||||||||||||||||||||||||||||||
| 1306 | pages => { | ||||||||||||||||||||||||||||||||||||||||||
| 1307 | $pageId => { | ||||||||||||||||||||||||||||||||||||||||||
| 1308 | @keyVal | ||||||||||||||||||||||||||||||||||||||||||
| 1309 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 1310 | ... | ||||||||||||||||||||||||||||||||||||||||||
| 1311 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 1312 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1313 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1314 | |||||||||||||||||||||||||||||||||||||||||||
| 1315 | auf | ||||||||||||||||||||||||||||||||||||||||||
| 1316 | |||||||||||||||||||||||||||||||||||||||||||
| 1317 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1318 | @keyVal | ||||||||||||||||||||||||||||||||||||||||||
| 1319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1320 | |||||||||||||||||||||||||||||||||||||||||||
| 1321 | also auf ein Element und liefere dieses zurück. | ||||||||||||||||||||||||||||||||||||||||||
| 1322 | |||||||||||||||||||||||||||||||||||||||||||
| 1323 | Enthält die Seitenliste mehr als ein Element, oder handelt es sich um | ||||||||||||||||||||||||||||||||||||||||||
| 1324 | ein ungültiges (als "missing" gekennzeichnetes) Element, wird eine | ||||||||||||||||||||||||||||||||||||||||||
| 1325 | Exception geworfen. | ||||||||||||||||||||||||||||||||||||||||||
| 1326 | |||||||||||||||||||||||||||||||||||||||||||
| 1327 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1328 | |||||||||||||||||||||||||||||||||||||||||||
| 1329 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 1330 | |||||||||||||||||||||||||||||||||||||||||||
| 1331 | 0 | ▶ | sub reduceToPage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reduceToPage: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1332 | 0 | my ($self,$res,$sloppy) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1333 | |||||||||||||||||||||||||||||||||||||||||||
| 1334 | # Mehr als ein Element? | ||||||||||||||||||||||||||||||||||||||||||
| 1335 | |||||||||||||||||||||||||||||||||||||||||||
| 1336 | 0 | my @pageIds = keys %{$res->{'query'}->{'pages'}}; | |||||||||||||||||||||||||||||||||||||||||
| 1337 | 0 | ▶ | if (@pageIds > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1338 | 0 | $self->throw( | |||||||||||||||||||||||||||||||||||||||||
| 1339 | 'MEDIAWIKI-00099: More than one page', | ||||||||||||||||||||||||||||||||||||||||||
| 1340 | PageIds => "@pageIds", | ||||||||||||||||||||||||||||||||||||||||||
| 1341 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1342 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1343 | |||||||||||||||||||||||||||||||||||||||||||
| 1344 | # Ungültiges Element? | ||||||||||||||||||||||||||||||||||||||||||
| 1345 | # Existiert die Seite nicht, hat die pageid den Wert -1 oder die | ||||||||||||||||||||||||||||||||||||||||||
| 1346 | # Seiteninformation enthält die Komponente missing (missing => ''), | ||||||||||||||||||||||||||||||||||||||||||
| 1347 | # wirf eine Exception- | ||||||||||||||||||||||||||||||||||||||||||
| 1348 | |||||||||||||||||||||||||||||||||||||||||||
| 1349 | 0 | my $pag = $res->{'query'}->{'pages'}->{$pageIds[0]}; | |||||||||||||||||||||||||||||||||||||||||
| 1350 | 0 | ▶ | if ($pageIds[0] == -1 || exists $pag->{'missing'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$pageIds[0] == -1 or exists $pag->{"missing"}
MC/DC0%0/2
$pageIds[0] == -1 or exists $pag->{"missing"}
$pageIds[0] == -1
exists $pag->{"missing"}
Truth table0%0/3
A or B
A= $pageIds[0] == -1B= exists $pag->{"missing"}
| |||||||||||||||||||||||||||||||||||||||||||
| 1351 | 0 | ▶ | if ($sloppy) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1352 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 1353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1354 | $self->throw( | ||||||||||||||||||||||||||||||||||||||||||
| 1355 | 0 | 'MEDIAWIKI-00099: Page not found', | |||||||||||||||||||||||||||||||||||||||||
| 1356 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1358 | |||||||||||||||||||||||||||||||||||||||||||
| 1359 | 0 | return $pag; | |||||||||||||||||||||||||||||||||||||||||
| 1360 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1361 | |||||||||||||||||||||||||||||||||||||||||||
| 1362 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 1363 | |||||||||||||||||||||||||||||||||||||||||||
| 1364 | =head2 Logging | ||||||||||||||||||||||||||||||||||||||||||
| 1365 | |||||||||||||||||||||||||||||||||||||||||||
| 1366 | =head3 log() - Schreibe Debug Log | ||||||||||||||||||||||||||||||||||||||||||
| 1367 | |||||||||||||||||||||||||||||||||||||||||||
| 1368 | =head4 Synopsis | ||||||||||||||||||||||||||||||||||||||||||
| 1369 | |||||||||||||||||||||||||||||||||||||||||||
| 1370 | $mw->log($title,$text); | ||||||||||||||||||||||||||||||||||||||||||
| 1371 | |||||||||||||||||||||||||||||||||||||||||||
| 1372 | =head4 Description | ||||||||||||||||||||||||||||||||||||||||||
| 1373 | |||||||||||||||||||||||||||||||||||||||||||
| 1374 | Schreibe den Text $text unter der Überschrift $title nach STDERR. | ||||||||||||||||||||||||||||||||||||||||||
| 1375 | |||||||||||||||||||||||||||||||||||||||||||
| 1376 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1377 | |||||||||||||||||||||||||||||||||||||||||||
| 1378 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 1379 | |||||||||||||||||||||||||||||||||||||||||||
| 1380 | 0 | ▶ | sub log { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1381 | 0 | my ($self,$title,$text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1382 | |||||||||||||||||||||||||||||||||||||||||||
| 1383 | 0 | my $a = $self->a; | |||||||||||||||||||||||||||||||||||||||||
| 1384 | 0 | warn $a->str('dark red',"---$title---"),"\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1385 | 0 | $text =~ s/\n+$//; | |||||||||||||||||||||||||||||||||||||||||
| 1386 | 0 | warn $a->str('dark blue',$text),"\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1387 | |||||||||||||||||||||||||||||||||||||||||||
| 1388 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1390 | |||||||||||||||||||||||||||||||||||||||||||
| 1391 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 1392 | |||||||||||||||||||||||||||||||||||||||||||
| 1393 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 1394 | |||||||||||||||||||||||||||||||||||||||||||
| 1395 | 1.240 | ||||||||||||||||||||||||||||||||||||||||||
| 1396 | |||||||||||||||||||||||||||||||||||||||||||
| 1397 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 1398 | |||||||||||||||||||||||||||||||||||||||||||
| 1399 | Frank Seitz, L<http://fseitz.de/> | ||||||||||||||||||||||||||||||||||||||||||
| 1400 | |||||||||||||||||||||||||||||||||||||||||||
| 1401 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||
| 1402 | |||||||||||||||||||||||||||||||||||||||||||
| 1403 | Copyright (C) 2026 Frank Seitz | ||||||||||||||||||||||||||||||||||||||||||
| 1404 | |||||||||||||||||||||||||||||||||||||||||||
| 1405 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 1406 | |||||||||||||||||||||||||||||||||||||||||||
| 1407 | This code is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||
| 1408 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 1409 | |||||||||||||||||||||||||||||||||||||||||||
| 1410 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1411 | |||||||||||||||||||||||||||||||||||||||||||
| 1412 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 1413 | |||||||||||||||||||||||||||||||||||||||||||
| 1414 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 1415 | |||||||||||||||||||||||||||||||||||||||||||
| 1416 | # eof | ||||||||||||||||||||||||||||||||||||||||||