Index: trunk/tools/rotatebot/rotbot.php |
— | — | @@ -1,24 +1,24 @@ |
2 | | -<?php |
| 2 | +<?php |
3 | 3 | /* Copyright © by Luxo & Saibo, 2011 |
4 | 4 | |
5 | | - This program is free software: you can redistribute it and/or modify |
6 | | - it under the terms of the GNU General Public License as published by |
7 | | - the Free Software Foundation, either version 3 of the License, or |
8 | | - (at your option) any later version. |
| 5 | + This program is free software: you can redistribute it and/or modify |
| 6 | + it under the terms of the GNU General Public License as published by |
| 7 | + the Free Software Foundation, either version 3 of the License, or |
| 8 | + (at your option) any later version. |
9 | 9 | |
10 | | - This program is distributed in the hope that it will be useful, |
11 | | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | | - GNU General Public License for more details. |
| 10 | + This program is distributed in the hope that it will be useful, |
| 11 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + GNU General Public License for more details. |
14 | 14 | |
15 | | - You should have received a copy of the GNU General Public License |
16 | | - along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | + You should have received a copy of the GNU General Public License |
| 16 | + along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | */ |
18 | 18 | |
19 | 19 | $homedir = "/home/luxo/rotbot/"; |
20 | 20 | $myLockfile = $homedir."rotatebotlock"; |
21 | 21 | |
22 | | -ini_set('memory_limit', '100M'); //Speicher auf 100 MBytes hochsetzen |
| 22 | +ini_set('memory_limit', '100M'); //Speicher auf 100 MBytes hochsetzen |
23 | 23 | ini_set('user_agent', ' User:Rotatebot by Luxo on the Toolserver / PHP'); |
24 | 24 | |
25 | 25 | |
— | — | @@ -33,7 +33,7 @@ |
34 | 34 | // Killer bot |
35 | 35 | if ($config['killAllRotatebots'] == "true") { |
36 | 36 | logfile("ATTENTION: Going to killAllRotatebots (also myself)!"); |
37 | | - // "php rotbot/rotbot.php" needs to be the process name |
| 37 | + // "php rotbot/rotbot.php" needs to be the process name |
38 | 38 | logfile("signal 15"); |
39 | 39 | system("pkill -15 -f 'php rotbot/rotbot.php'"); |
40 | 40 | sleep(10); |
— | — | @@ -48,7 +48,7 @@ |
49 | 49 | $dontDieOnLockProblems = true; |
50 | 50 | } |
51 | 51 | getLockOrDie($dontDieOnLockProblems); //check for other concurrently running rotatebot instances. Exit if not alone on the world |
52 | | -// continue ONLY if we are not dead ... |
| 52 | +// continue ONLY if we are not dead ... |
53 | 53 | // after this line only suicide() should be done instead of die()! |
54 | 54 | |
55 | 55 | |
— | — | @@ -57,7 +57,7 @@ |
58 | 58 | $myslink = mysql_connect($databanknames2, $userloginname, $databasepw) or suicide ("Can't connect to MySQL"); |
59 | 59 | $database = "commonswiki_p"; |
60 | 60 | mysql_select_db($database, $myslink) |
61 | | - or suicide ("Konnte $databas nicht öffnen: ".mysql_error()); |
| 61 | + or suicide ("Konnte $databas nicht öffnen: ".mysql_error()); |
62 | 62 | //Datenbank verbunden |
63 | 63 | |
64 | 64 | $wrongfiles = array(); |
— | — | @@ -72,39 +72,39 @@ |
73 | 73 | |
74 | 74 | if(!$contentarray['query']['categorymembers']['0']) |
75 | 75 | { |
76 | | - suicide(logfile("Kategorie leer.")); |
| 76 | + suicide(logfile("Kategorie leer.")); |
77 | 77 | } |
78 | 78 | |
79 | 79 | //NS filter (was disabled on api 10.07.09) |
80 | 80 | |
81 | 81 | foreach($contentarray['query']['categorymembers'] as $temp_img) |
82 | 82 | { |
83 | | - if($temp_img['ns'] == 6) |
84 | | - { |
85 | | - $contentarray['pages'][] = $temp_img; |
86 | | - } |
| 83 | + if($temp_img['ns'] == 6) |
| 84 | + { |
| 85 | + $contentarray['pages'][] = $temp_img; |
| 86 | + } |
87 | 87 | } |
88 | 88 | |
89 | 89 | |
90 | 90 | /* |
91 | 91 | [0] => Array |
92 | 92 | ( |
93 | | - [pageid] => 3830049 |
94 | | - [ns] => 6 |
95 | | - [title] => Image:WTM wikiWhat 074.jpg |
96 | | - [sortkey] => 270 |
97 | | - [timestamp] => 2008-04-06T00:03:01Z |
| 93 | + [pageid] => 3830049 |
| 94 | + [ns] => 6 |
| 95 | + [title] => Image:WTM wikiWhat 074.jpg |
| 96 | + [sortkey] => 270 |
| 97 | + [timestamp] => 2008-04-06T00:03:01Z |
98 | 98 | ) |
99 | 99 | [1] => Array |
100 | | - ( |
101 | | - ... |
| 100 | + ( |
| 101 | + ... |
102 | 102 | */ |
103 | 103 | |
104 | 104 | //noch restliche daten nachladen von api.php |
105 | 105 | |
106 | 106 | foreach($contentarray['pages'] as $picture) |
107 | 107 | { |
108 | | - $urlpageids .= "|".$picture['pageid']; |
| 108 | + $urlpageids .= "|".$picture['pageid']; |
109 | 109 | } |
110 | 110 | $urlpageids = substr($urlpageids,1); //vorderster | wieder wegnehmen (JA, unsauber ;-) |
111 | 111 | |
— | — | @@ -117,36 +117,36 @@ |
118 | 118 | |
119 | 119 | foreach($contentarray['pages'] as $picture) |
120 | 120 | { |
121 | | - $ctidd = $picture['pageid']; |
122 | | - foreach($picture as $contXB => $contXI) |
123 | | - { |
124 | | - $contentarray2['pages'][$ctidd][$contXB] = $contXI; |
125 | | - } |
| 121 | + $ctidd = $picture['pageid']; |
| 122 | + foreach($picture as $contXB => $contXI) |
| 123 | + { |
| 124 | + $contentarray2['pages'][$ctidd][$contXB] = $contXI; |
| 125 | + } |
126 | 126 | } |
127 | 127 | |
128 | 128 | $contentarray = $contentarray2; |
129 | 129 | |
130 | 130 | |
131 | | - |
132 | 131 | $catcontent = array(); |
133 | 132 | $arraykey = 0; |
134 | 133 | foreach($contentarray['pages'] as $picture) |
135 | 134 | { |
136 | | -logfile("-------------"); |
137 | | -logfile("check ".$picture['title']."..."); |
| 135 | + logfile("-------------"); |
| 136 | + logfile("check ".$picture['title']."..."); |
138 | 137 | |
139 | | -//dateiendung bestimmen - gültiges Dateiformat? |
140 | | -if(substr(strtolower($picture['title']),-4) == ".jpg" OR substr(strtolower($picture['title']),-5) == ".jpeg") { $catcontent[$arraykey]['filetype'] = "jpg"; } |
141 | | -else if(substr(strtolower($picture['title']),-4) == ".png") { $catcontent[$arraykey]['filetype'] = "png"; } |
142 | | -else if(substr(strtolower($picture['title']),-4) == ".gif") { $catcontent[$arraykey]['filetype'] = "gif"; } |
143 | | -else { $wrongfile = true; |
144 | | - $wrongfiles[$picture["title"]] = "wrong filetype (".substr(strtolower($picture['title']),-3).")"; |
145 | | - } |
146 | | -//sortkey ab umbruchstelle beschneiden |
147 | | -$picture["sortkey"] = trim(stristr(hexToStr($picture["sortkey"]), "\n", true)); |
148 | | - |
149 | | -// Do not process big images ... |
150 | | -logfile("Size of this picture: ".$picture['imageinfo']['0']["size"]." bytes. Limit set to ".$config['fileSizeLimit']." bytes"); |
| 138 | + //dateiendung bestimmen - gültiges Dateiformat? |
| 139 | + if(substr(strtolower($picture['title']),-4) == ".jpg" OR substr(strtolower($picture['title']),-5) == ".jpeg") { $catcontent[$arraykey]['filetype'] = "jpg"; } |
| 140 | + else if(substr(strtolower($picture['title']),-4) == ".png") { $catcontent[$arraykey]['filetype'] = "png"; } |
| 141 | + else if(substr(strtolower($picture['title']),-4) == ".gif") { $catcontent[$arraykey]['filetype'] = "gif"; } |
| 142 | + else { |
| 143 | + $wrongfile = true; |
| 144 | + $wrongfiles[$picture["title"]] = "wrong filetype (".substr(strtolower($picture['title']),-3).")"; |
| 145 | + } |
| 146 | + //sortkey ab umbruchstelle beschneiden |
| 147 | + $picture["sortkey"] = trim(stristr(hexToStr($picture["sortkey"]), "\n", true)); |
| 148 | + |
| 149 | + // Do not process big images ... |
| 150 | + logfile("Size of this picture: ".$picture['imageinfo']['0']["size"]." bytes. Limit set to ".$config['fileSizeLimit']." bytes"); |
151 | 151 | if($picture['imageinfo']['0']["size"] > $config['fileSizeLimit']) { |
152 | 152 | logfile("File bigger (".$picture['imageinfo']['0']["size"]." B) than limit (".$config['fileSizeLimit']." B)"); |
153 | 153 | $wrongfiles[$picture["title"]] = "File bigger (".$picture['imageinfo']['0']["size"]." B) than limit (".$config['fileSizeLimit']." B). Please wait until someone does a lossless(!) fix by hand."; |
— | — | @@ -154,12 +154,12 @@ |
155 | 155 | } |
156 | 156 | |
157 | 157 | |
158 | | - //Korrekte Grade/Aktion prüfen |
| 158 | + //Korrekte Grade/Aktion prüfen |
159 | 159 | if($picture["sortkey"] != 90 AND $picture["sortkey"] != 180 AND $picture["sortkey"] != 270) { |
160 | | - // exceptions for jpegs... last chance. ;-) |
| 160 | + // exceptions for jpegs... last chance. ;-) |
161 | 161 | if(($catcontent[$arraykey]['filetype'] == "jpg" AND ($picture["sortkey"] == "RESETEXIF" OR $picture["sortkey"] == "0" OR $picture["sortkey"] == "00" OR $picture["sortkey"] == "000" ))) { |
162 | 162 | // okay, jpg AND (reset OR 0°) requested (cannot include in the in comparision since any string would match == 0) - EXIF based orientation should be applied apparently or be resetted |
163 | | - } else { |
| 163 | + } else { |
164 | 164 | logfile("wrong degree-parameter (".$picture["sortkey"]."°)"); |
165 | 165 | $wrongfiles[$picture["title"]] = "wrong degree-parameter (".$picture["sortkey"]."°)"; |
166 | 166 | $wrongfile = true; |
— | — | @@ -170,41 +170,41 @@ |
171 | 171 | //User, der das Template gesetzt hat, identifizieren |
172 | 172 | |
173 | 173 | $revitimestp = trim($picture["timestamp"]); |
174 | | - |
| 174 | + |
175 | 175 | foreach($picture['revisions'] as $key => $revisions) |
176 | 176 | { |
177 | 177 | if(trim($revisions['timestamp']) == $revitimestp) |
178 | 178 | { |
179 | | - $catcontent[$arraykey]['tmplsetter'] = $picture['revisions'][$key]['user']; |
180 | | - logfile("Template by: ".$catcontent[$arraykey]['tmplsetter']); |
| 179 | + $catcontent[$arraykey]['tmplsetter'] = $picture['revisions'][$key]['user']; |
| 180 | + logfile("Template by: ".$catcontent[$arraykey]['tmplsetter']); |
181 | 181 | } |
182 | 182 | else |
183 | 183 | { |
184 | | - logfile("set time($revitimestp) not identical with this rv, ".$revisions['timestamp']."."); |
185 | | - //Rev's nachladen |
186 | | - $ctxctx = file_get_contents("http://commons.wikimedia.org/w/api.php?action=query&prop=revisions&pageids=".$picture['pageid']."&rvlimit=20&rvprop=timestamp|user|comment&format=php") or suicide("api error"); |
187 | | - $totrevs = unserialize($ctxctx); |
188 | | - logfile("ID: ".$picture['pageid']." "); |
189 | | - |
190 | | - if(is_array($totrevs)) |
191 | | - { |
192 | | - foreach($totrevs['query']['pages'] as $cxxx) |
193 | | - { |
194 | | - foreach($cxxx['revisions'] as $cxxxx) |
195 | | - { |
196 | | - if($cxxxx['timestamp'] == $revitimestp) |
197 | | - { |
198 | | - $catcontent[$arraykey]['tmplsetter'] = $cxxxx['user']; |
199 | | - logfile("Older rev, template by: ".$catcontent[$arraykey]['tmplsetter']); |
200 | | - } |
201 | | - } |
202 | | - } |
203 | | - } |
204 | | - else |
205 | | - { |
206 | | - logfile("API: Error: not a array!"); |
207 | | - logfile($totrevs); |
208 | | - } |
| 184 | + logfile("set time($revitimestp) not identical with this rv, ".$revisions['timestamp']."."); |
| 185 | + //Rev's nachladen |
| 186 | + $ctxctx = file_get_contents("http://commons.wikimedia.org/w/api.php?action=query&prop=revisions&pageids=".$picture['pageid']."&rvlimit=20&rvprop=timestamp|user|comment&format=php") or suicide("api error"); |
| 187 | + $totrevs = unserialize($ctxctx); |
| 188 | + logfile("ID: ".$picture['pageid']." "); |
| 189 | + |
| 190 | + if(is_array($totrevs)) |
| 191 | + { |
| 192 | + foreach($totrevs['query']['pages'] as $cxxx) |
| 193 | + { |
| 194 | + foreach($cxxx['revisions'] as $cxxxx) |
| 195 | + { |
| 196 | + if($cxxxx['timestamp'] == $revitimestp) |
| 197 | + { |
| 198 | + $catcontent[$arraykey]['tmplsetter'] = $cxxxx['user']; |
| 199 | + logfile("Older rev, template by: ".$catcontent[$arraykey]['tmplsetter']); |
| 200 | + } |
| 201 | + } |
| 202 | + } |
| 203 | + } |
| 204 | + else |
| 205 | + { |
| 206 | + logfile("API: Error: not a array!"); |
| 207 | + logfile($totrevs); |
| 208 | + } |
209 | 209 | } |
210 | 210 | } |
211 | 211 | |
— | — | @@ -212,118 +212,114 @@ |
213 | 213 | //Benutzer prüfen! ######################################### |
214 | 214 | if($catcontent[$arraykey]['tmplsetter']) //autoconfirmed |
215 | 215 | { |
216 | | - $wgAuthor = $catcontent[$arraykey]['tmplsetter']; |
217 | | - logfile("check user ".$wgAuthor."."); |
218 | | - |
219 | | - //Datenbank abfragen nach status |
220 | | - if(!$cachedbar["$wgAuthor"]) |
221 | | - { |
222 | | - $mysresult = mysql_query( "SELECT * FROM user WHERE user_name='".mysql_real_escape_string($wgAuthor)."'") or suicide("MySQL error"); |
223 | | - $a_row = mysql_fetch_row($mysresult); |
224 | | - $cachedbar[$wgAuthor] = $a_row; |
225 | | - } |
226 | | - else |
227 | | - { |
228 | | - $a_row = $cachedbar["$wgAuthor"]; |
229 | | - } |
230 | | - |
231 | | - |
232 | | - $setuserid = $a_row[0]; |
233 | | - $user_registration = $a_row[2]; |
234 | | - $user_editcount = $a_row[3]; |
235 | | - $chckx = $user_registration;//zum prüfen |
236 | | - |
237 | | - if(!$setuserid){ $setuserid = "-"; } |
238 | | - if(!$user_editcount){ $user_editcount = 0; } |
239 | | - if(!$user_registration){ $user_registration = 20070101000000; $vcx = true; } //alte accounts haben diesen zeitstempel noch nicht |
240 | | - |
241 | | - logfile("Edits: ".$user_editcount); |
242 | | - logfile("Registred at: ".$user_registration); |
243 | | - //Wikizeitstempel in unixzeit umrechnen |
244 | | - |
245 | | - $regiUnix = TsToUnixTime($user_registration); |
246 | | - |
247 | | - $actuUnix = time(); |
248 | | - $registeredtime = $actuUnix - $regiUnix; |
249 | | - $registereddays = number_format($registeredtime / 86400,1,"."," ");//Stunden ausrechnen und runden/formatieren |
250 | | - if($registeredtime < 345600 OR !$chckx AND $setuserid == "-") //345600 sec = 4 Tage |
251 | | - { |
252 | | - logfile($wgAuthor." is not autoconfirmed!"); |
253 | | - //Zu neu, nicht autoconfirmed |
254 | | - if($config['rotatepermission'] == "1") |
255 | | - { |
256 | | - $wrongfile = true; |
257 | | - $wrongfiles[$picture["title"]] = "The account of the user who set the template ([[User:".$catcontent[$arraykey]['tmplsetter']."|]]) is ''not autoconfirmed''.<br />'''Unlock:''' An autoconfirmed user should delete the parameters <code><nowiki>|</nowiki>nobot=true<nowiki>|</nowiki>reason=...</code> in this image. Thank you --~~~~"; |
258 | | - } |
259 | | - $xx = "not "; |
260 | | - } else { |
261 | | - $xx = ""; //autoconfirmed |
262 | | - } |
263 | | - |
264 | | - if($vcx == true) |
265 | | - { |
266 | | - $registereddays = "?"; |
267 | | - } |
268 | | - |
269 | | - $userforlog[$wgAuthor] = "***$wgAuthor, userid $setuserid, $user_editcount edits, registered since $registereddays days, is '''".$xx."autoconfirmed.'''"; |
270 | | - |
271 | | - if($config['mincontribs'] > 0 AND $user_editcount < $config['mincontribs']) //zu wenige edits |
272 | | - { |
273 | | - if($config['rotatepermission'] == "1") |
274 | | - { |
275 | | - logfile($catcontent[$arraykey]['tmplsetter']." has not enough edits!"); |
276 | | - $wrongfile = true; |
277 | | - $wrongfiles[$picture["title"]] = "The account of the user who set the template ([[User:".$wgAuthor."|]]) has under ".$config['mincontribs']." edits.<br />'''Unlock:''' An autoconfirmed user with more than ".$config['mincontribs']." edits should delete the parameters <code><nowiki>|</nowiki>nobot=true<nowiki>|</nowiki>reason=...</code> in this image. Thank you --~~~~"; |
278 | | - } |
279 | | - } |
280 | | -} |
281 | | -//Benutzer geprüft ######################################### |
| 216 | + $wgAuthor = $catcontent[$arraykey]['tmplsetter']; |
| 217 | + logfile("check user ".$wgAuthor."."); |
282 | 218 | |
| 219 | + //Datenbank abfragen nach status |
| 220 | + if(!$cachedbar["$wgAuthor"]) |
| 221 | + { |
| 222 | + $mysresult = mysql_query( "SELECT * FROM user WHERE user_name='".mysql_real_escape_string($wgAuthor)."'") or suicide("MySQL error"); |
| 223 | + $a_row = mysql_fetch_row($mysresult); |
| 224 | + $cachedbar[$wgAuthor] = $a_row; |
| 225 | + } |
| 226 | + else |
| 227 | + { |
| 228 | + $a_row = $cachedbar["$wgAuthor"]; |
| 229 | + } |
283 | 230 | |
284 | 231 | |
| 232 | + $setuserid = $a_row[0]; |
| 233 | + $user_registration = $a_row[2]; |
| 234 | + $user_editcount = $a_row[3]; |
| 235 | + $chckx = $user_registration;//zum prüfen |
285 | 236 | |
| 237 | + if(!$setuserid){ $setuserid = "-"; } |
| 238 | + if(!$user_editcount){ $user_editcount = 0; } |
| 239 | + if(!$user_registration){ $user_registration = 20070101000000; $vcx = true; } //alte accounts haben diesen zeitstempel noch nicht |
| 240 | + |
| 241 | + logfile("Edits: ".$user_editcount); |
| 242 | + logfile("Registred at: ".$user_registration); |
| 243 | + //Wikizeitstempel in unixzeit umrechnen |
| 244 | + |
| 245 | + $regiUnix = TsToUnixTime($user_registration); |
| 246 | + |
| 247 | + $actuUnix = time(); |
| 248 | + $registeredtime = $actuUnix - $regiUnix; |
| 249 | + $registereddays = number_format($registeredtime / 86400,1,"."," ");//Stunden ausrechnen und runden/formatieren |
| 250 | + if($registeredtime < 345600 OR !$chckx AND $setuserid == "-") //345600 sec = 4 Tage |
| 251 | + { |
| 252 | + logfile($wgAuthor." is not autoconfirmed!"); |
| 253 | + //Zu neu, nicht autoconfirmed |
| 254 | + if($config['rotatepermission'] == "1") |
| 255 | + { |
| 256 | + $wrongfile = true; |
| 257 | + $wrongfiles[$picture["title"]] = "The account of the user who set the template ([[User:".$catcontent[$arraykey]['tmplsetter']."|]]) is ''not autoconfirmed''.<br />'''Unlock:''' An autoconfirmed user should delete the parameters <code><nowiki>|</nowiki>nobot=true<nowiki>|</nowiki>reason=...</code> in this image. Thank you --~~~~"; |
| 258 | + } |
| 259 | + $xx = "not "; |
| 260 | + } else { |
| 261 | + $xx = ""; //autoconfirmed |
| 262 | + } |
| 263 | + |
| 264 | + if($vcx == true) |
| 265 | + { |
| 266 | + $registereddays = "?"; |
| 267 | + } |
| 268 | + |
| 269 | + $userforlog[$wgAuthor] = "***$wgAuthor, userid $setuserid, $user_editcount edits, registered since $registereddays days, is '''".$xx."autoconfirmed.'''"; |
| 270 | + |
| 271 | + if($config['mincontribs'] > 0 AND $user_editcount < $config['mincontribs']) //zu wenige edits |
| 272 | + { |
| 273 | + if($config['rotatepermission'] == "1") |
| 274 | + { |
| 275 | + logfile($catcontent[$arraykey]['tmplsetter']." has not enough edits!"); |
| 276 | + $wrongfile = true; |
| 277 | + $wrongfiles[$picture["title"]] = "The account of the user who set the template ([[User:".$wgAuthor."|]]) has under ".$config['mincontribs']." edits.<br />'''Unlock:''' An autoconfirmed user with more than ".$config['mincontribs']." edits should delete the parameters <code><nowiki>|</nowiki>nobot=true<nowiki>|</nowiki>reason=...</code> in this image. Thank you --~~~~"; |
| 278 | + } |
| 279 | + } |
| 280 | +} |
| 281 | +//Benutzer geprüft ######################################### |
| 282 | + |
| 283 | + |
286 | 284 | //per regex auf schlechte dateinamen prüfen |
287 | 285 | $regex = "File:(?:DVC|CIMG|IMGP?|PICT|DSC[FN]?|DUW|JD|MGP|scan|untitled|foto|imagen|img|image|picture|p|BILD)?[0-9_ \-\(\)\{\}\[\]]+\..*"; |
288 | 286 | if(preg_match("/".$regex."/",$picture['title']) == 1) |
289 | 287 | { |
290 | | - //Kann nicht hochgeladen werden, Blacklisted |
291 | | - /*####################### |
292 | | -Im moment deaktiviert |
293 | | -######################*/ |
294 | | - //$wrongfile = true; |
295 | | - //$wrongfiles[$picture["title"]] = "Image can't be rotated by Rotatebot because it has a senseless title. Please rename first."; |
296 | | - $addrename[$picture["title"]] = true; |
297 | | -} else { |
298 | | - $addrename[$picture["title"]] = false; |
| 288 | + //Kann nicht hochgeladen werden, Blacklisted |
| 289 | + /*####################### |
| 290 | + Im moment deaktiviert |
| 291 | + ######################*/ |
| 292 | + //$wrongfile = true; |
| 293 | + //$wrongfiles[$picture["title"]] = "Image can't be rotated by Rotatebot because it has a senseless title. Please rename first."; |
| 294 | + $addrename[$picture["title"]] = true; |
| 295 | +} else { |
| 296 | + $addrename[$picture["title"]] = false; |
299 | 297 | } |
300 | 298 | |
301 | 299 | |
302 | | -if(!$wrongfile) //Bild scheint OK zu sein |
303 | | -{ |
304 | | - logfile("picture and user check finished, sorted for download"); |
305 | | - |
306 | | - $catcontent[$arraykey]['title'] = str_replace(" ", "_", $picture["title"]); |
307 | | - $catcontent[$arraykey]['degree'] = $picture["sortkey"]; |
308 | | - $catcontent[$arraykey]['since'] = $revitimestp; |
309 | | - $catcontent[$arraykey]['pageid'] = $picture['pageid']; |
310 | | - $catcontent[$arraykey]['url'] = $picture['imageinfo']['0']['url']; |
311 | | - $catcontent[$arraykey]['metadata'] = $picture['imageinfo']['0']['metadata']; |
312 | | - $catcontent[$arraykey]['uploader'] = $picture['imageinfo']['0']['user']; |
313 | | - $catcontent[$arraykey]['upltime'] = $picture['imageinfo']['0']['timestamp']; |
314 | | - $catcontent[$arraykey]['size'] = $picture['imageinfo']['0']['width']."x".$picture['imageinfo']['0']['height']; |
315 | | - $catcontent[$arraykey]['exifkey'] = 0; |
316 | | - $catcontent[$arraykey]['exifkeyafter'] = 0; |
317 | | - $catcontent[$arraykey]['exifwriteerr'] = ""; |
318 | | - $arraykey = $arraykey +1; |
319 | | -} |
320 | | -else |
321 | | -{ |
322 | | -//array löschen! |
323 | | -$papierkorb = array_splice($catcontent,$arraykey,1); |
324 | | -} |
| 300 | + if(!$wrongfile) //Bild scheint OK zu sein |
| 301 | + { |
| 302 | + logfile("picture and user check finished, sorted for download"); |
325 | 303 | |
| 304 | + $catcontent[$arraykey]['title'] = str_replace(" ", "_", $picture["title"]); |
| 305 | + $catcontent[$arraykey]['degree'] = $picture["sortkey"]; |
| 306 | + $catcontent[$arraykey]['since'] = $revitimestp; |
| 307 | + $catcontent[$arraykey]['pageid'] = $picture['pageid']; |
| 308 | + $catcontent[$arraykey]['url'] = $picture['imageinfo']['0']['url']; |
| 309 | + $catcontent[$arraykey]['metadata'] = $picture['imageinfo']['0']['metadata']; |
| 310 | + $catcontent[$arraykey]['uploader'] = $picture['imageinfo']['0']['user']; |
| 311 | + $catcontent[$arraykey]['upltime'] = $picture['imageinfo']['0']['timestamp']; |
| 312 | + $catcontent[$arraykey]['size'] = $picture['imageinfo']['0']['width']."x".$picture['imageinfo']['0']['height']; |
| 313 | + $catcontent[$arraykey]['exifkey'] = 0; |
| 314 | + $catcontent[$arraykey]['exifkeyafter'] = 0; |
| 315 | + $catcontent[$arraykey]['exifwriteerr'] = ""; |
| 316 | + $arraykey = $arraykey +1; |
| 317 | + } |
| 318 | + else |
| 319 | + { |
| 320 | + //array löschen! |
| 321 | + $papierkorb = array_splice($catcontent,$arraykey,1); |
| 322 | + } |
326 | 323 | |
327 | | - |
328 | 324 | } |
329 | 325 | |
330 | 326 | $picture = array();//leeren (Speicherplatz) |
— | — | @@ -340,274 +336,273 @@ |
341 | 337 | |
342 | 338 | foreach($catcontent as $filename => $arraycontent) |
343 | 339 | { |
344 | | -logfile("save ".$arraycontent['title']); |
345 | | -$savepath = $homedir."cache/"; |
| 340 | + logfile("save ".$arraycontent['title']); |
| 341 | + $savepath = $homedir."cache/"; |
346 | 342 | |
347 | | -//$fp = fopen($arraycontent['url'], "rb"); |
348 | | -//fpassthru($fp); |
349 | | -//fclose($fp); |
350 | | -//$file = ob_get_contents(); |
351 | | -//ob_clean(); |
352 | | -$file = file_get_contents($arraycontent['url']) or suicide("Kann ".$arraycontent['title']." nicht downloaden! (".$arraycontent['url'].")"); |
| 343 | + //$fp = fopen($arraycontent['url'], "rb"); |
| 344 | + //fpassthru($fp); |
| 345 | + //fclose($fp); |
| 346 | + //$file = ob_get_contents(); |
| 347 | + //ob_clean(); |
| 348 | + $file = file_get_contents($arraycontent['url']) or suicide("Kann ".$arraycontent['title']." nicht downloaden! (".$arraycontent['url'].")"); |
353 | 349 | |
354 | | -$fp = fopen($savepath.$filename.".".$arraycontent['filetype'], "wb+"); |
355 | | -fwrite($fp, $file); |
356 | | -fclose($fp); |
357 | | -//sleep(1); |
| 350 | + $fp = fopen($savepath.$filename.".".$arraycontent['filetype'], "wb+"); |
| 351 | + fwrite($fp, $file); |
| 352 | + fclose($fp); |
| 353 | + //sleep(1); |
358 | 354 | } |
359 | 355 | $file = "";//Datei löschen um Speicherplatz zu bekommen |
360 | | -logfile("Download finished!"); |
| 356 | +logfile("Download finished!"); |
361 | 357 | |
362 | 358 | |
363 | | - |
364 | 359 | /*########## BILDER DREHEN, EXIF ANPASSEN ############# */ |
365 | 360 | $catcontent2 = array(); |
366 | 361 | foreach($catcontent as $filename => $arraycontent) |
367 | 362 | { |
368 | | - $return=0; // reset |
369 | | - if($arraycontent['filetype'] == "jpg") //Für JPEG lossless methode |
370 | | - { |
371 | | - //Exif auslesen |
372 | | - // /home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation -b 1.jpg -a is to get dupe tags, too |
373 | | - $exif = system("/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation -b -a ".$savepath.$filename.".".$arraycontent['filetype'].""); |
374 | | - settype($exif, "integer"); |
375 | | - logfile("EXIF ist auf $exif"); |
376 | | - $arraycontent['exifkey'] = $exif; //for editsummary |
| 363 | + $return=0; // reset |
| 364 | + if($arraycontent['filetype'] == "jpg") //Für JPEG lossless methode |
| 365 | + { |
| 366 | + //Exif auslesen |
| 367 | + // /home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation -b 1.jpg -a is to get dupe tags, too |
| 368 | + $exif = system("/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation -b -a ".$savepath.$filename.".".$arraycontent['filetype'].""); |
| 369 | + settype($exif, "integer"); |
| 370 | + logfile("EXIF ist auf $exif"); |
| 371 | + $arraycontent['exifkey'] = $exif; //for editsummary |
377 | 372 | |
378 | | - if ($arraycontent['degree'] == "RESETEXIF") { // if ignoring EXIF is wished ... |
379 | | - switch($exif) { |
380 | | - case 0: // no Orientation tag existent |
381 | | - case 1: |
382 | | - logfile("reset EXIF Orientation reset requested but it was already 0 or 1"); |
383 | | - $return=1007; // unexpected EXIF was found |
384 | | - break; |
385 | | - default: |
386 | | - $exifR = 0; // ignore any existing EXIF |
387 | | - } |
388 | | - |
389 | | - } else { |
390 | | - if ($exif >= 10) { //do we have duplicate Orientation tags? They get reported by exiftool like "18". |
391 | | - logfile("duplicate Orientation tags!"); |
392 | | - $return=1009; // Duplicate Orientation tags were found |
393 | | - } else { |
394 | | - //Use EXIF Orientation (= roation applied by MediaWiki for displaying) and user input to find the correct rotation |
| 373 | + if ($arraycontent['degree'] == "RESETEXIF") { // if ignoring EXIF is wished ... |
395 | 374 | switch($exif) { |
396 | 375 | case 0: // no Orientation tag existent |
397 | 376 | case 1: |
398 | | - if ($arraycontent['degree'] == 0) { // No rotation requested AND exif normal? |
399 | | - logfile("exif was 0 or 1 and no rotation requested"); |
400 | | - $return=1008; // |
401 | | - } else { |
402 | | - $exifR = 0; |
403 | | - } |
| 377 | + logfile("reset EXIF Orientation reset requested but it was already 0 or 1"); |
| 378 | + $return=1007; // unexpected EXIF was found |
404 | 379 | break; |
405 | | - case 3: |
406 | | - $exifR = 180; |
407 | | - break; |
408 | | - case 6: |
409 | | - $exifR = 90; |
410 | | - break; |
411 | | - case 8: |
412 | | - $exifR = 270; |
413 | | - break; |
414 | 380 | default: |
415 | | - logfile("exif was not 0,1,3,6,8"); |
416 | | - $return=1003; // unexpected EXIF was found |
| 381 | + $exifR = 0; // ignore any existing EXIF |
417 | 382 | } |
418 | | - } |
419 | | - } |
420 | 383 | |
421 | | - if ($return == 0) { // if no unexpected EXIF was found |
422 | | - |
423 | | - if ($arraycontent['degree'] == "RESETEXIF") { // if ignoring EXIF is wished ... |
424 | | - $realrotate = 0; // do not rotate |
425 | | - $arraycontent['realdegree'] = 0; // for editsummary |
426 | | - } else { |
427 | | - $realrotate = $arraycontent['degree'] + $exifR; // Saibo2 formula. user specified rotaation + already applied rotation by MW |
428 | | - logfile("Bild muss um $realrotate Grad gedreht werden."); |
429 | | - $realrotate = (360 + ($realrotate % 360)) % 360; // convert to 0-259 |
430 | | - $arraycontent['realdegree'] = $realrotate; // for editsummary |
431 | | - } |
432 | | - switch($realrotate) |
433 | | - { |
434 | | - case 0: |
435 | | - //kopie erstellen |
436 | | - logfile("just exif correction, picture correct"); |
437 | | - $cmd = "cp ".$savepath.$filename.".".$arraycontent['filetype']." ".$savepath.$filename."_2.".$arraycontent['filetype']; |
438 | | - logfile($cmd); |
439 | | - passthru($cmd); |
440 | | - break; |
441 | | - case 90: |
442 | | - case 180: |
443 | | - case 270: |
444 | | - //rotieren ... |
445 | | - $cmd = "jpegtran -rotate ".$realrotate." -trim -copy all ".$savepath.$filename.".".$arraycontent['filetype']." > ".$savepath.$filename."_2.".$arraycontent['filetype']; |
446 | | - logfile($cmd); |
447 | | - passthru($cmd,$return); |
448 | | - logfile($arraycontent['title']." rotated by ".$realrotate."°."); |
449 | | - break; |
450 | | - |
451 | | - default: |
452 | | - logfile("Bullshit happend: realrotate was $realrotate."); |
453 | | - $return=1004; |
454 | | - } |
455 | | - |
456 | | -//escape shell nicht notwendig, keine Benutzerdaten im cmd verwendet |
| 384 | + } else { |
| 385 | + if ($exif >= 10) { //do we have duplicate Orientation tags? They get reported by exiftool like "18". |
| 386 | + logfile("duplicate Orientation tags!"); |
| 387 | + $return=1009; // Duplicate Orientation tags were found |
| 388 | + } else { |
| 389 | + //Use EXIF Orientation (= roation applied by MediaWiki for displaying) and user input to find the correct rotation |
| 390 | + switch($exif) { |
| 391 | + case 0: // no Orientation tag existent |
| 392 | + case 1: |
| 393 | + if ($arraycontent['degree'] == 0) { // No rotation requested AND exif normal? |
| 394 | + logfile("exif was 0 or 1 and no rotation requested"); |
| 395 | + $return=1008; // |
| 396 | + } else { |
| 397 | + $exifR = 0; |
| 398 | + } |
| 399 | + break; |
| 400 | + case 3: |
| 401 | + $exifR = 180; |
| 402 | + break; |
| 403 | + case 6: |
| 404 | + $exifR = 90; |
| 405 | + break; |
| 406 | + case 8: |
| 407 | + $exifR = 270; |
| 408 | + break; |
| 409 | + default: |
| 410 | + logfile("exif was not 0,1,3,6,8"); |
| 411 | + $return=1003; // unexpected EXIF was found |
| 412 | + } |
| 413 | + } |
| 414 | + } |
457 | 415 | |
458 | | - $doBruteForceClean = false; // init |
459 | | - |
460 | | - if ($return == 0 && !($exif == 0 || $exif == 1)) { // only if no error occured and change necessary |
461 | | - //EXIF-orient-tag auf 1 stellen, nur bei jpeg |
462 | | - // /home/luxo/rotbot/exiftool/exiftool -Orientation=1 -n 1.jpg |
463 | | - if ($exif >= 10) { //dupe Orientation tags? Kill 'em all! |
464 | | - // Needs to be removed because otherwise the duplicate tag stays |
465 | | - // first attempt |
466 | | - $cmd = "/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation= -n ".$savepath.$filename."_2.".$arraycontent['filetype']; |
467 | | - logfile($cmd); |
468 | | - passthru($cmd,$retexifwrite); |
469 | | - |
470 | | - if ($retexifwrite == 0) { // if successful |
471 | | - logfile("No errors on EXIF-to-0"); |
472 | | - $exifwriteerr = ""; // clear - no error since it worked in first attempt |
473 | | - } else { |
474 | | - // second attempt (ignoring minor errors) |
475 | | - $cmd = "/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation= -n -m ".$savepath.$filename."_2.".$arraycontent['filetype']; |
| 416 | + if ($return == 0) { // if no unexpected EXIF was found |
| 417 | + |
| 418 | + if ($arraycontent['degree'] == "RESETEXIF") { // if ignoring EXIF is wished ... |
| 419 | + $realrotate = 0; // do not rotate |
| 420 | + $arraycontent['realdegree'] = 0; // for editsummary |
| 421 | + } else { |
| 422 | + $realrotate = $arraycontent['degree'] + $exifR; // Saibo2 formula. user specified rotaation + already applied rotation by MW |
| 423 | + logfile("Bild muss um $realrotate Grad gedreht werden."); |
| 424 | + $realrotate = (360 + ($realrotate % 360)) % 360; // convert to 0-259 |
| 425 | + $arraycontent['realdegree'] = $realrotate; // for editsummary |
| 426 | + } |
| 427 | + switch($realrotate) |
| 428 | + { |
| 429 | + case 0: |
| 430 | + //kopie erstellen |
| 431 | + logfile("just exif correction, picture correct"); |
| 432 | + $cmd = "cp ".$savepath.$filename.".".$arraycontent['filetype']." ".$savepath.$filename."_2.".$arraycontent['filetype']; |
| 433 | + logfile($cmd); |
| 434 | + passthru($cmd); |
| 435 | + break; |
| 436 | + case 90: |
| 437 | + case 180: |
| 438 | + case 270: |
| 439 | + //rotieren ... |
| 440 | + $cmd = "jpegtran -rotate ".$realrotate." -trim -copy all ".$savepath.$filename.".".$arraycontent['filetype']." > ".$savepath.$filename."_2.".$arraycontent['filetype']; |
| 441 | + logfile($cmd); |
| 442 | + passthru($cmd,$return); |
| 443 | + logfile($arraycontent['title']." rotated by ".$realrotate."°."); |
| 444 | + break; |
| 445 | + |
| 446 | + default: |
| 447 | + logfile("Bullshit happend: realrotate was $realrotate."); |
| 448 | + $return=1004; |
| 449 | + } |
| 450 | + |
| 451 | + //escape shell nicht notwendig, keine Benutzerdaten im cmd verwendet |
| 452 | + |
| 453 | + $doBruteForceClean = false; // init |
| 454 | + |
| 455 | + if ($return == 0 && !($exif == 0 || $exif == 1)) { // only if no error occured and change necessary |
| 456 | + //EXIF-orient-tag auf 1 stellen, nur bei jpeg |
| 457 | + // /home/luxo/rotbot/exiftool/exiftool -Orientation=1 -n 1.jpg |
| 458 | + if ($exif >= 10) { //dupe Orientation tags? Kill 'em all! |
| 459 | + // Needs to be removed because otherwise the duplicate tag stays |
| 460 | + // first attempt |
| 461 | + $cmd = "/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation= -n ".$savepath.$filename."_2.".$arraycontent['filetype']; |
476 | 462 | logfile($cmd); |
477 | 463 | passthru($cmd,$retexifwrite); |
478 | 464 | |
479 | 465 | if ($retexifwrite == 0) { // if successful |
480 | | - logfile("No errors on EXIF-to-0 (second try)"); |
481 | | - $exifwriteerr = " - EXIF had minor errors. Some EXIF could be lost. - "; |
| 466 | + logfile("No errors on EXIF-to-0"); |
| 467 | + $exifwriteerr = ""; // clear - no error since it worked in first attempt |
482 | 468 | } else { |
483 | | - $doBruteForceClean = true; |
| 469 | + // second attempt (ignoring minor errors) |
| 470 | + $cmd = "/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation= -n -m ".$savepath.$filename."_2.".$arraycontent['filetype']; |
| 471 | + logfile($cmd); |
| 472 | + passthru($cmd,$retexifwrite); |
| 473 | + |
| 474 | + if ($retexifwrite == 0) { // if successful |
| 475 | + logfile("No errors on EXIF-to-0 (second try)"); |
| 476 | + $exifwriteerr = " - EXIF had minor errors. Some EXIF could be lost. - "; |
| 477 | + } else { |
| 478 | + $doBruteForceClean = true; |
| 479 | + } |
484 | 480 | } |
485 | | - } |
486 | | - } else { |
487 | | - // first attempt |
488 | | - $cmd = "/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation=1 -n ".$savepath.$filename."_2.".$arraycontent['filetype']; |
489 | | - logfile($cmd); |
490 | | - passthru($cmd,$retexifwrite); |
491 | | - |
492 | | - if ($retexifwrite == 0) { // if successful |
493 | | - logfile("no errors when setting EXIF to 1"); |
494 | | - $exifwriteerr = ""; // clear - no error since it worked in first attempt |
495 | 481 | } else { |
496 | | - // second attempt (ignoring minor errors) |
497 | | - $cmd = "/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation=1 -n -m ".$savepath.$filename."_2.".$arraycontent['filetype']; |
| 482 | + // first attempt |
| 483 | + $cmd = "/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation=1 -n ".$savepath.$filename."_2.".$arraycontent['filetype']; |
498 | 484 | logfile($cmd); |
499 | 485 | passthru($cmd,$retexifwrite); |
500 | | - |
| 486 | + |
501 | 487 | if ($retexifwrite == 0) { // if successful |
502 | | - logfile("no errors when setting EXIF to 1 (second try)"); |
503 | | - $exifwriteerr = " - EXIF had minor errors. Some EXIF could be lost. - "; |
| 488 | + logfile("no errors when setting EXIF to 1"); |
| 489 | + $exifwriteerr = ""; // clear - no error since it worked in first attempt |
504 | 490 | } else { |
505 | | - $doBruteForceClean = true; |
| 491 | + // second attempt (ignoring minor errors) |
| 492 | + $cmd = "/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation=1 -n -m ".$savepath.$filename."_2.".$arraycontent['filetype']; |
| 493 | + logfile($cmd); |
| 494 | + passthru($cmd,$retexifwrite); |
| 495 | + |
| 496 | + if ($retexifwrite == 0) { // if successful |
| 497 | + logfile("no errors when setting EXIF to 1 (second try)"); |
| 498 | + $exifwriteerr = " - EXIF had minor errors. Some EXIF could be lost. - "; |
| 499 | + } else { |
| 500 | + $doBruteForceClean = true; |
| 501 | + } |
506 | 502 | } |
507 | 503 | } |
508 | | - } |
509 | 504 | |
510 | 505 | |
511 | | - if ($doBruteForceClean) { |
512 | | - // third attempt (ignoring nearly all errors) - copy all readable tags but leave the Orientation tag away |
513 | | - $cmd = "/home/luxo/rotbot/exiftool/exiftool -all= -tagsfromfile @ -all:all --IFD0:Orientation ".$savepath.$filename."_2.".$arraycontent['filetype']; |
514 | | - logfile($cmd); |
515 | | - passthru($cmd,$retexifwrite); |
| 506 | + if ($doBruteForceClean) { |
| 507 | + // third attempt (ignoring nearly all errors) - copy all readable tags but leave the Orientation tag away |
| 508 | + $cmd = "/home/luxo/rotbot/exiftool/exiftool -all= -tagsfromfile @ -all:all --IFD0:Orientation ".$savepath.$filename."_2.".$arraycontent['filetype']; |
| 509 | + logfile($cmd); |
| 510 | + passthru($cmd,$retexifwrite); |
516 | 511 | |
517 | | - if ($retexifwrite == 0) { // if successful |
518 | | - logfile("no errors when setting EXIF to 0 (third try)"); |
519 | | - $exifwriteerr = " - EXIF had major errors. Great parts of EXIF could be lost. - "; |
520 | | - } else { |
521 | | - // complete failure |
522 | | - $return = 1005; |
| 512 | + if ($retexifwrite == 0) { // if successful |
| 513 | + logfile("no errors when setting EXIF to 0 (third try)"); |
| 514 | + $exifwriteerr = " - EXIF had major errors. Great parts of EXIF could be lost. - "; |
| 515 | + } else { |
| 516 | + // complete failure |
| 517 | + $return = 1005; |
| 518 | + } |
523 | 519 | } |
524 | | - } |
525 | 520 | |
526 | 521 | |
527 | | - $arraycontent['exifwriteerr'] = $exifwriteerr; //for editsummary |
528 | | - } |
| 522 | + $arraycontent['exifwriteerr'] = $exifwriteerr; //for editsummary |
| 523 | + } |
529 | 524 | |
530 | | - if ($return == 0) { // only if no error occured |
531 | | - //Exif auslesen als Test |
532 | | - // /home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation -b 1.jpg -a is to get dupe tags, too |
533 | | - $exifafter = system("/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation -b -a ".$savepath.$filename."_2.".$arraycontent['filetype'].""); |
534 | | - settype($exifafter, "integer"); |
535 | | - logfile("read EXIF after finish: $exifafter"); |
536 | | - $arraycontent['exifkeyafter'] = $exifafter; //for editsummary |
537 | | - |
538 | | - if (!($exifafter == 0 || $exifafter == 1)) { // if unsuccessful |
539 | | - $return = 1006; |
| 525 | + if ($return == 0) { // only if no error occured |
| 526 | + //Exif auslesen als Test |
| 527 | + // /home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation -b 1.jpg -a is to get dupe tags, too |
| 528 | + $exifafter = system("/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation -b -a ".$savepath.$filename."_2.".$arraycontent['filetype'].""); |
| 529 | + settype($exifafter, "integer"); |
| 530 | + logfile("read EXIF after finish: $exifafter"); |
| 531 | + $arraycontent['exifkeyafter'] = $exifafter; //for editsummary |
| 532 | + |
| 533 | + if (!($exifafter == 0 || $exifafter == 1)) { // if unsuccessful |
| 534 | + $return = 1006; |
| 535 | + } |
540 | 536 | } |
| 537 | + } |
541 | 538 | } |
542 | | - } |
543 | | - } |
544 | | - else //Für png's und gif's |
545 | | - { |
546 | | - passthru("convert ".$savepath.$filename.".".$arraycontent['filetype']." -rotate ".$arraycontent['degree']." ".$savepath.$filename."_2.".$arraycontent['filetype'],$returnP); |
547 | | - logfile($arraycontent['title']." rotated by ".$arraycontent['degree']."°: ".$returnP); |
548 | | - } |
| 539 | + else //Für png's und gif's |
| 540 | + { |
| 541 | + passthru("convert ".$savepath.$filename.".".$arraycontent['filetype']." -rotate ".$arraycontent['degree']." ".$savepath.$filename."_2.".$arraycontent['filetype'],$returnP); |
| 542 | + logfile($arraycontent['title']." rotated by ".$arraycontent['degree']."°: ".$returnP); |
| 543 | + } |
549 | 544 | // TODO: ich bau mal ne Verwendung von $returnP in der Fehlerbehandlung nachfolgend ein.. der Fehlerwert beim PNG/GIF-Drehen wird gar nicht verwendet |
550 | | - |
551 | | - |
| 545 | + |
| 546 | + |
552 | 547 | // sleep(5); //wait 5 sec. between rotating images |
553 | | - |
554 | | - if($return != 0) |
555 | | - { |
556 | | - //Bild aussortieren, da defekt |
557 | | - |
558 | | - $rx = ""; |
559 | | - switch($return) { |
560 | | - case 1: |
561 | | - $rx = " (DCT coefficient out of range)"; |
562 | | - $wrongfiles[$arraycontent["title"]] = "corrupt JPEG file.".$rx; |
563 | | - logfile("sort out; corrupt JPEG file.".$rx); |
564 | | - break; |
565 | | - case 2: |
566 | | - $rx = " (Premature end of JPEG file)"; |
567 | | - $wrongfiles[$arraycontent["title"]] = "corrupt JPEG file.".$rx; |
568 | | - logfile("sort out; corrupt JPEG file.".$rx); |
569 | | - break; |
570 | | - case 1003: |
571 | | - $rx = " ($exif)"; |
572 | | - $wrongfiles[$arraycontent["title"]] = "Unexpected exif orientation: ".$rx; |
573 | | - logfile("unexpected exif orientation.".$rx); |
574 | | - break; |
575 | | - case 1004: |
576 | | - $rx = " ($realrotate)"; |
577 | | - $wrongfiles[$arraycontent["title"]] = "Bullshit happend: realrotate was.".$rx; |
578 | | - logfile("Bullshit happend: realrotate was.".$rx); |
579 | | - break; |
580 | | - case 1005: |
581 | | - $rx = " (ec: $retexifwrite)"; |
582 | | - $wrongfiles[$arraycontent["title"]] = "EXIF had severe errors on write attempt.".$rx; |
583 | | - logfile("EXIF had severe errors on write attempt.".$rx); |
584 | | - break; |
585 | | - case 1006: |
586 | | - $rx = " ($exifafter)"; |
587 | | - $wrongfiles[$arraycontent["title"]] = "EXIF had not 0 or 1 after process.".$rx; |
588 | | - logfile("EXIF had not 0 or 1 after process.".$rx); |
589 | | - break; |
590 | | - case 1007: |
591 | | - $rx = " ($exif)"; |
592 | | - $wrongfiles[$arraycontent["title"]] = "reset EXIF Orientation reset requested but it was already 0 or 1.".$rx; |
593 | | - logfile("reset EXIF Orientation reset requested but it was already 0 or 1.".$rx); |
594 | | - break; |
595 | | - case 1008: |
596 | | - $rx = " ($exif)"; |
597 | | - $wrongfiles[$arraycontent["title"]] = "No rotation requested and no EXIF-based rotation? Sorry, there is nothing I can do!".$rx; |
598 | | - logfile("No rotation requested and no EXIF-based rotation present. Nothing to do.".$rx); |
599 | | - break; |
600 | | - case 1009: |
601 | | - $rx = " ($exif)"; |
602 | | - $wrongfiles[$arraycontent["title"]] = "Duplicate IFD0:Orientation tags were found. MW handles those in a strange way. Use rotate template's parameter 'resetexif' (instead of degree number) to reset the EXIF orientation information of this file.".$rx; |
603 | | - logfile("Duplicate IFD0:Orientation tags were found.".$rx); |
604 | | - break; |
605 | | - } |
606 | | - } |
607 | | - else |
608 | | - { |
609 | | - //Korrekt gedreht, Weiter gehen |
610 | | - $catcontent2[$filename] = $arraycontent; |
611 | | - } |
| 548 | + |
| 549 | + if($return != 0) |
| 550 | + { |
| 551 | + //Bild aussortieren, da defekt |
| 552 | + |
| 553 | + $rx = ""; |
| 554 | + switch($return) { |
| 555 | + case 1: |
| 556 | + $rx = " (DCT coefficient out of range)"; |
| 557 | + $wrongfiles[$arraycontent["title"]] = "corrupt JPEG file.".$rx; |
| 558 | + logfile("sort out; corrupt JPEG file.".$rx); |
| 559 | + break; |
| 560 | + case 2: |
| 561 | + $rx = " (Premature end of JPEG file)"; |
| 562 | + $wrongfiles[$arraycontent["title"]] = "corrupt JPEG file.".$rx; |
| 563 | + logfile("sort out; corrupt JPEG file.".$rx); |
| 564 | + break; |
| 565 | + case 1003: |
| 566 | + $rx = " ($exif)"; |
| 567 | + $wrongfiles[$arraycontent["title"]] = "Unexpected exif orientation: ".$rx; |
| 568 | + logfile("unexpected exif orientation.".$rx); |
| 569 | + break; |
| 570 | + case 1004: |
| 571 | + $rx = " ($realrotate)"; |
| 572 | + $wrongfiles[$arraycontent["title"]] = "Bullshit happend: realrotate was.".$rx; |
| 573 | + logfile("Bullshit happend: realrotate was.".$rx); |
| 574 | + break; |
| 575 | + case 1005: |
| 576 | + $rx = " (ec: $retexifwrite)"; |
| 577 | + $wrongfiles[$arraycontent["title"]] = "EXIF had severe errors on write attempt.".$rx; |
| 578 | + logfile("EXIF had severe errors on write attempt.".$rx); |
| 579 | + break; |
| 580 | + case 1006: |
| 581 | + $rx = " ($exifafter)"; |
| 582 | + $wrongfiles[$arraycontent["title"]] = "EXIF had not 0 or 1 after process.".$rx; |
| 583 | + logfile("EXIF had not 0 or 1 after process.".$rx); |
| 584 | + break; |
| 585 | + case 1007: |
| 586 | + $rx = " ($exif)"; |
| 587 | + $wrongfiles[$arraycontent["title"]] = "reset EXIF Orientation reset requested but it was already 0 or 1.".$rx; |
| 588 | + logfile("reset EXIF Orientation reset requested but it was already 0 or 1.".$rx); |
| 589 | + break; |
| 590 | + case 1008: |
| 591 | + $rx = " ($exif)"; |
| 592 | + $wrongfiles[$arraycontent["title"]] = "No rotation requested and no EXIF-based rotation? Sorry, there is nothing I can do!".$rx; |
| 593 | + logfile("No rotation requested and no EXIF-based rotation present. Nothing to do.".$rx); |
| 594 | + break; |
| 595 | + case 1009: |
| 596 | + $rx = " ($exif)"; |
| 597 | + $wrongfiles[$arraycontent["title"]] = "Duplicate IFD0:Orientation tags were found. MW handles those in a strange way. Use rotate template's parameter 'resetexif' (instead of degree number) to reset the EXIF orientation information of this file.".$rx; |
| 598 | + logfile("Duplicate IFD0:Orientation tags were found.".$rx); |
| 599 | + break; |
| 600 | + } |
| 601 | + } |
| 602 | + else |
| 603 | + { |
| 604 | + //Korrekt gedreht, Weiter gehen |
| 605 | + $catcontent2[$filename] = $arraycontent; |
| 606 | + } |
612 | 607 | } |
613 | 608 | logfile("ALl images turned and exif corrected!\nStart upload..."); |
614 | 609 | |
— | — | @@ -617,12 +612,11 @@ |
618 | 613 | |
619 | 614 | |
620 | 615 | foreach($catcontent2 as $filename => $arraycontent) |
621 | | - { |
622 | | - |
| 616 | +{ |
623 | 617 | //upload summary |
624 | 618 | |
625 | 619 | if ($arraycontent['degree'] == "RESETEXIF") { |
626 | | - $filesum = sprintf($config['resetuploadsummary']." ".$config['exifuploadsum'],$arraycontent['exifkey'],$arraycontent['exifkeyafter'],$arraycontent['exifwriteerr'],$arraycontent['realdegree']); |
| 620 | + $filesum = sprintf($config['resetuploadsummary']." ".$config['exifuploadsum'],$arraycontent['exifkey'],$arraycontent['exifkeyafter'],$arraycontent['exifwriteerr'],$arraycontent['realdegree']); |
627 | 621 | } else { |
628 | 622 | |
629 | 623 | if (!($arraycontent['exifkey'] == 0 || $arraycontent['exifkey'] == 1)) { // if EXIF was not 0 or 1 |
— | — | @@ -631,7 +625,7 @@ |
632 | 626 | $filesum = sprintf($config['uploadsummary'],$arraycontent['degree']); |
633 | 627 | } |
634 | 628 | } |
635 | | - |
| 629 | + |
636 | 630 | //Hochladen |
637 | 631 | Logfile("upload ".$arraycontent['title']." ... intern name: ".$filename."_2.".$arraycontent['filetype']); |
638 | 632 | wikiupload("commons.wikimedia.org",$filename."_2.".$arraycontent['filetype'],substr($arraycontent['title'],5),"",$filesum); |
— | — | @@ -639,48 +633,47 @@ |
640 | 634 | $catcontent2[$filename]['doneat'] = date("Y-m-d\TH:i:s\Z",time());//2007-10-01T10:13:15Z |
641 | 635 | //Quelltext laden |
642 | 636 | $quelltext = file_get_contents("http://commons.wikimedia.org/w/index.php?title=".urlencode(str_replace(" ", "_",$arraycontent['title']))."&action=raw"); |
643 | | - |
| 637 | + |
644 | 638 | //Template erkennen |
645 | 639 | $strabtemp = NULL; |
646 | 640 | $strabtemp = stristr($quelltext, "{{Rotate"); |
647 | 641 | if(!$strabtemp) { $strabtemp = stristr($quelltext, "{{Template:Rotate"); } |
648 | 642 | $upto = strpos($strabtemp,"}}"); |
649 | 643 | $template = substr($strabtemp,0,$upto+2); |
650 | | - |
| 644 | + |
651 | 645 | //löschen |
652 | 646 | $forupload = str_ireplace($template."\n", "", $quelltext, $count); // delete template and a newline directly afterwards |
653 | 647 | $forupload = str_ireplace($template, "", $forupload, $count2); // delete template |
654 | | - |
| 648 | + |
655 | 649 | //Speichern |
656 | 650 | if($count + $count2 > 0) |
657 | 651 | { |
658 | | - logfile("remove template $template"); |
659 | | - |
660 | | - //Editsummary generieren |
661 | | - if($arraycontent['degree'] == "RESETEXIF") { |
662 | | - $edsum = $config['reseteditsummary']; |
663 | | - |
664 | | - } else { |
665 | | - $edsum = sprintf($config['editsummary'],$arraycontent['degree']); |
666 | | - } |
667 | | - |
668 | | - $c = wikiedit("commons.wikimedia.org",$arraycontent['title'],$forupload,$edsum,"1"); |
669 | | - |
670 | | - if($c == true) |
671 | | - { |
672 | | - $nodelete[$arraycontent['title']] = 0; |
| 652 | + logfile("remove template $template"); |
| 653 | + |
| 654 | + //Editsummary generieren |
| 655 | + if($arraycontent['degree'] == "RESETEXIF") { |
| 656 | + $edsum = $config['reseteditsummary']; |
| 657 | + } else { |
| 658 | + $edsum = sprintf($config['editsummary'],$arraycontent['degree']); |
| 659 | + } |
| 660 | + |
| 661 | + $c = wikiedit("commons.wikimedia.org",$arraycontent['title'],$forupload,$edsum,"1"); |
| 662 | + |
| 663 | + if($c == true) |
| 664 | + { |
| 665 | + $nodelete[$arraycontent['title']] = 0; |
| 666 | + } |
| 667 | + else |
| 668 | + { |
| 669 | + $nodelete[$arraycontent['title']] = 1; |
| 670 | + } |
| 671 | + |
673 | 672 | } |
674 | 673 | else |
675 | 674 | { |
676 | | - $nodelete[$arraycontent['title']] = 1; |
| 675 | + logfile("ERROR: TEMPLATE NICHT GEFUNDEN!"); |
| 676 | + $nodelete[$arraycontent['title']] = 1; |
677 | 677 | } |
678 | | - |
679 | | - } |
680 | | - else |
681 | | - { |
682 | | - logfile("ERROR: TEMPLATE NICHT GEFUNDEN!"); |
683 | | - $nodelete[$arraycontent['title']] = 1; |
684 | | - } |
685 | 678 | logfile("\n-------NEXT--------- \n"); |
686 | 679 | // sleep(5); |
687 | 680 | } |
— | — | @@ -688,9 +681,6 @@ |
689 | 682 | |
690 | 683 | |
691 | 684 | |
692 | | - |
693 | | - |
694 | | - |
695 | 685 | //Cache leeren |
696 | 686 | foreach($catcontent2 as $filename => $arraycontent) |
697 | 687 | { |
— | — | @@ -707,43 +697,41 @@ |
708 | 698 | |
709 | 699 | $logfilew = deleteold($logfilew,$somanyrot,$config['logfilesize'],$config['logheader']); |
710 | 700 | |
711 | | -// Fehlerbilder durchgehen |
| 701 | +// Fehlerbilder durchgehen |
712 | 702 | foreach($wrongfiles as $title => $reason) |
713 | 703 | { |
714 | | - |
715 | 704 | |
716 | | - |
717 | | - $quelltext = file_get_contents("http://commons.wikimedia.org/w/index.php?title=".urlencode(str_replace(" ", "_",$title))."&action=raw"); |
718 | | - |
719 | | - $forupload = str_ireplace("{{Rotate", "{{Rotate|nobot=true|reason='''Reason''': $reason", $quelltext, $count); |
720 | | - |
721 | | - if($addrename[$title] == true && !stristr($forupload,"{{rename")) |
722 | | - { |
723 | | - $renametemp = "{{Rename}}\n"; |
724 | | - } |
725 | | - else |
726 | | - { |
727 | | - $renametemp = ""; |
728 | | - } |
729 | | - |
730 | | - $forupload = $renametemp.$forupload; |
731 | | - if($count > 0) |
732 | | - { |
| 705 | + $quelltext = file_get_contents("http://commons.wikimedia.org/w/index.php?title=".urlencode(str_replace(" ", "_",$title))."&action=raw"); |
733 | 706 | |
734 | | - wikiedit("commons.wikimedia.org",str_replace(" ", "_",$title),$forupload,"Bot: Can't rotate image","1"); |
735 | | - $logfilew .= "\n----\n |
736 | | - <span style=\"color:red;text-decoration:blink\">'''Error'''</span> can't rotate [[:$title]]:\n ''$reason''\n"; |
737 | | - |
738 | | - logfile("set template of $title to nobot"); |
739 | | - } |
740 | | - else |
741 | | - { |
742 | | - logfile("Template:Rotate in $title NOT FOUND!"); |
743 | | - $logfilew .= "\n----\n |
744 | | - <span style=\"color:red;text-decoration:blink\">'''Error'''</span> can't rotate [[:$title]]:\n ''$reason''\n"; |
745 | | - $logfilew .= "<big style='color:red;text-decoration:blink;'>'''Warning:''' Template not found, file probably still in the category!!</big>\n"; |
746 | | - } |
| 707 | + $forupload = str_ireplace("{{Rotate", "{{Rotate|nobot=true|reason='''Reason''': $reason", $quelltext, $count); |
747 | 708 | |
| 709 | + if($addrename[$title] == true && !stristr($forupload,"{{rename")) |
| 710 | + { |
| 711 | + $renametemp = "{{Rename}}\n"; |
| 712 | + } |
| 713 | + else |
| 714 | + { |
| 715 | + $renametemp = ""; |
| 716 | + } |
| 717 | + |
| 718 | + $forupload = $renametemp.$forupload; |
| 719 | + if($count > 0) |
| 720 | + { |
| 721 | + |
| 722 | + wikiedit("commons.wikimedia.org",str_replace(" ", "_",$title),$forupload,"Bot: Can't rotate image","1"); |
| 723 | + $logfilew .= "\n----\n |
| 724 | + <span style=\"color:red;text-decoration:blink\">'''Error'''</span> can't rotate [[:$title]]:\n ''$reason''\n"; |
| 725 | + |
| 726 | + logfile("set template of $title to nobot"); |
| 727 | + } |
| 728 | + else |
| 729 | + { |
| 730 | + logfile("Template:Rotate in $title NOT FOUND!"); |
| 731 | + $logfilew .= "\n----\n |
| 732 | + <span style=\"color:red;text-decoration:blink\">'''Error'''</span> can't rotate [[:$title]]:\n ''$reason''\n"; |
| 733 | + $logfilew .= "<big style='color:red;text-decoration:blink;'>'''Warning:''' Template not found, file probably still in the category!!</big>\n"; |
| 734 | + } |
| 735 | + |
748 | 736 | } |
749 | 737 | |
750 | 738 | |
— | — | @@ -751,43 +739,40 @@ |
752 | 740 | |
753 | 741 | foreach($catcontent2 as $arraycontent) |
754 | 742 | { |
755 | | - $logfilew .= "\n----\n"; |
756 | | - $logfilew .= "[[".$arraycontent['title']."|thumb]]\n"; |
757 | | - $logfilew .= "*[[:".$arraycontent['title']."]] (".$arraycontent['size'].")\n"; |
758 | | - |
759 | | - if($nodelete[$arraycontent['title']] == 1) |
760 | | - { |
761 | | - |
762 | | - $logfilew .= "<big style='color:red;text-decoration:blink;'>'''Warning:''' Template not found, file probably still in the category!!</big>\n"; |
763 | | - |
764 | | - } |
765 | | - |
766 | | - |
767 | | - if($arraycontent['metadata']['Make'] and $arraycontent['metadata']['DateTimeDigitized']) |
768 | | - { |
769 | | - $logfilew .= "**Image taken with a [[:en:".trim($arraycontent['metadata']['Make'])."|".ucwords(strtolower(trim($arraycontent['metadata']['Make'])))."]] ".ucwords(strtolower(trim($arraycontent['metadata']['Model'])))." at ".trim($arraycontent['metadata']['DateTimeDigitized']).".\n"; |
770 | | - } |
771 | | - |
772 | | - $logfilew .= "**Last image-version uploaded by [[User:".$arraycontent['uploader']."|]] at ".timestampto($arraycontent['upltime'])." (UTC)\n"; |
773 | | - if($arraycontent['tmplsetter']) |
774 | | - { |
775 | | - $logfilew .= "**{{[[Template:Rotate|]]}} added (or modified) by [[User:".$arraycontent['tmplsetter']."|]] at ".timestampto($arraycontent['since'])." (UTC)\n"; |
776 | | - $logfilew .= $userforlog[$arraycontent['tmplsetter']]."\n"; |
777 | | - } |
778 | | - $logfilew .= "**Rotated by ~~~ through ".$arraycontent['degree']."° at ".timestampto($arraycontent['doneat'])." (UTC) (=".difftime($arraycontent['since'],$arraycontent['doneat'])." later)\n"; |
779 | | - $logfilew .= "<br style=\"clear:both;\" clear=\"all\" />"; |
| 743 | + $logfilew .= "\n----\n"; |
| 744 | + $logfilew .= "[[".$arraycontent['title']."|thumb]]\n"; |
| 745 | + $logfilew .= "*[[:".$arraycontent['title']."]] (".$arraycontent['size'].")\n"; |
| 746 | + |
| 747 | + if($nodelete[$arraycontent['title']] == 1) |
| 748 | + { |
| 749 | + $logfilew .= "<big style='color:red;text-decoration:blink;'>'''Warning:''' Template not found, file probably still in the category!!</big>\n"; |
| 750 | + } |
| 751 | + |
| 752 | + if($arraycontent['metadata']['Make'] and $arraycontent['metadata']['DateTimeDigitized']) |
| 753 | + { |
| 754 | + $logfilew .= "**Image taken with a [[:en:".trim($arraycontent['metadata']['Make'])."|".ucwords(strtolower(trim($arraycontent['metadata']['Make'])))."]] ".ucwords(strtolower(trim($arraycontent['metadata']['Model'])))." at ".trim($arraycontent['metadata']['DateTimeDigitized']).".\n"; |
| 755 | + } |
| 756 | + |
| 757 | + $logfilew .= "**Last image-version uploaded by [[User:".$arraycontent['uploader']."|]] at ".timestampto($arraycontent['upltime'])." (UTC)\n"; |
| 758 | + if($arraycontent['tmplsetter']) |
| 759 | + { |
| 760 | + $logfilew .= "**{{[[Template:Rotate|]]}} added (or modified) by [[User:".$arraycontent['tmplsetter']."|]] at ".timestampto($arraycontent['since'])." (UTC)\n"; |
| 761 | + $logfilew .= $userforlog[$arraycontent['tmplsetter']]."\n"; |
| 762 | + } |
| 763 | + $logfilew .= "**Rotated by ~~~ through ".$arraycontent['degree']."° at ".timestampto($arraycontent['doneat'])." (UTC) (=".difftime($arraycontent['since'],$arraycontent['doneat'])." later)\n"; |
| 764 | + $logfilew .= "<br style=\"clear:both;\" clear=\"all\" />"; |
780 | 765 | } |
781 | 766 | |
782 | 767 | if($somanyrot > 0 OR count($wrongfiles) > 0) |
783 | 768 | { |
784 | | - logfile("write logfile. ($somanyrot pictures)"); |
785 | | - |
786 | | - if(count($wrongfiles) > 0) |
787 | | - { |
788 | | - $msgerr = ", ".count($wrongfiles)." errors"; |
789 | | - } |
790 | | - |
791 | | - wikiedit("commons.wikimedia.org","User:Rotatebot/Log",$logfilew,"Bot: $somanyrot images rotated".$msgerr.".","1"); |
| 769 | + logfile("write logfile. ($somanyrot pictures)"); |
| 770 | + |
| 771 | + if(count($wrongfiles) > 0) |
| 772 | + { |
| 773 | + $msgerr = ", ".count($wrongfiles)." errors"; |
| 774 | + } |
| 775 | + |
| 776 | + wikiedit("commons.wikimedia.org","User:Rotatebot/Log",$logfilew,"Bot: $somanyrot images rotated".$msgerr.".","1"); |
792 | 777 | } |
793 | 778 | |
794 | 779 | mysql_close($myslink); // TODO should/can this be moved to function suicide? - Probably not due to line 33. |
— | — | @@ -795,237 +780,229 @@ |
796 | 781 | // END script |
797 | 782 | |
798 | 783 | |
799 | | - |
800 | | - |
801 | | - |
802 | 784 | // functions start: |
803 | 785 | |
804 | | - |
805 | | - |
806 | | - |
807 | 786 | function logfile($text) |
808 | 787 | { |
809 | | - echo $text."\n"; |
| 788 | + echo $text."\n"; |
810 | 789 | } |
811 | 790 | |
812 | 791 | function timestampto($intime,$unix=false) |
813 | 792 | { |
814 | | -//UNIX-zeit erstellen |
815 | | -//2007-11-20T19:11:17Z |
816 | | -$year = substr($intime,0,4); |
817 | | -$month = substr($intime,5,2); |
818 | | -$day = substr($intime,8,2); |
819 | | -$hour = substr($intime,11,2); |
820 | | -$min = substr($intime,14,2); |
821 | | -$sec = substr($intime,17,2); |
| 793 | + //UNIX-zeit erstellen |
| 794 | + //2007-11-20T19:11:17Z |
| 795 | + $year = substr($intime,0,4); |
| 796 | + $month = substr($intime,5,2); |
| 797 | + $day = substr($intime,8,2); |
| 798 | + $hour = substr($intime,11,2); |
| 799 | + $min = substr($intime,14,2); |
| 800 | + $sec = substr($intime,17,2); |
822 | 801 | |
823 | | -$unixtime = mktime($hour,$min,$sec,$month,$day,$year); |
824 | | -if($unix == true) |
825 | | -{ |
826 | | -return $unixtime; |
827 | | -} |
828 | | -else |
829 | | -{ |
830 | | -return date("H:i, d F Y",$unixtime); |
831 | | -} |
| 802 | + $unixtime = mktime($hour,$min,$sec,$month,$day,$year); |
| 803 | + if($unix == true) |
| 804 | + { |
| 805 | + return $unixtime; |
| 806 | + } |
| 807 | + else |
| 808 | + { |
| 809 | + return date("H:i, d F Y",$unixtime); |
| 810 | + } |
832 | 811 | |
833 | 812 | } |
834 | 813 | |
835 | 814 | function difftime($settime, $rottime) |
836 | 815 | { |
837 | | -$unixset = timestampto($settime,true); |
838 | | -$unixrot = timestampto($rottime,true); |
| 816 | + $unixset = timestampto($settime,true); |
| 817 | + $unixrot = timestampto($rottime,true); |
839 | 818 | |
840 | | -$diff = $unixrot - $unixset; //differenz in sekunden |
| 819 | + $diff = $unixrot - $unixset; //differenz in sekunden |
841 | 820 | |
| 821 | + return tellSeconds($diff); |
842 | 822 | |
843 | | - |
844 | | -return tellSeconds($diff); |
845 | | - |
846 | 823 | } |
847 | 824 | |
848 | | -function tellSeconds($NumberOfSeconds) // function Copyright (C) simplecontent.net |
| 825 | +function tellSeconds($NumberOfSeconds) // function Copyright (C) simplecontent.net |
849 | 826 | { |
850 | 827 | |
851 | | - $time_map = array( |
| 828 | + $time_map = array( |
852 | 829 | |
853 | | - 'Years' => 31536000, # 365 Tage |
854 | | - 'Months' => 2592000, # 30 Tage |
855 | | - 'Weeks' => 604800, # 7 Tage |
856 | | - 'Days' => 86400, |
857 | | - 'Hours' => 3600, |
858 | | - 'Minutes' => 60, |
859 | | - 'Seconds' => 1, |
860 | | - ); |
| 830 | + 'Years' => 31536000, # 365 Tage |
| 831 | + 'Months' => 2592000, # 30 Tage |
| 832 | + 'Weeks' => 604800, # 7 Tage |
| 833 | + 'Days' => 86400, |
| 834 | + 'Hours' => 3600, |
| 835 | + 'Minutes' => 60, |
| 836 | + 'Seconds' => 1, |
| 837 | + ); |
861 | 838 | |
862 | | - $SecondsTotal = $NumberOfSeconds; |
| 839 | + $SecondsTotal = $NumberOfSeconds; |
863 | 840 | |
864 | | - $SecondsLeft = $SecondsTotal; |
| 841 | + $SecondsLeft = $SecondsTotal; |
865 | 842 | |
866 | | - $stack = array(); |
| 843 | + $stack = array(); |
867 | 844 | |
868 | | - foreach ($time_map as $k => $v) { |
| 845 | + foreach ($time_map as $k => $v) { |
869 | 846 | |
870 | | - if ($SecondsLeft < $v || $SecondsLeft == 0) { |
871 | | - continue; |
872 | | - } else { |
873 | | - $amount = floor($SecondsLeft/ $v); |
874 | | - $SecondsLeft = $SecondsLeft % $v; |
| 847 | + if ($SecondsLeft < $v || $SecondsLeft == 0) { |
| 848 | + continue; |
| 849 | + } else { |
| 850 | + $amount = floor($SecondsLeft/ $v); |
| 851 | + $SecondsLeft = $SecondsLeft % $v; |
875 | 852 | |
876 | | - $label = ($amount>1) |
877 | | - ? $k |
878 | | - : substr($k, 0, -1); |
| 853 | + $label = ($amount>1) |
| 854 | + ? $k |
| 855 | + : substr($k, 0, -1); |
879 | 856 | |
880 | | - $stack[] = sprintf("'''%s''' %s", $amount, $label); |
881 | | - } |
882 | | - } |
883 | | - $cnt = count($stack); |
| 857 | + $stack[] = sprintf("'''%s''' %s", $amount, $label); |
| 858 | + } |
| 859 | + } |
| 860 | + $cnt = count($stack); |
884 | 861 | |
885 | | - if ($cnt > 1){ |
886 | | - $tmp1 = array_pop($stack); |
887 | | - $tmp2 = array_pop($stack); |
888 | | - array_push ($stack, $tmp2 . ' and '.$tmp1); |
889 | | - }; |
890 | | - $result = join (', ', $stack); |
891 | | - return $result; |
| 862 | + if ($cnt > 1){ |
| 863 | + $tmp1 = array_pop($stack); |
| 864 | + $tmp2 = array_pop($stack); |
| 865 | + array_push ($stack, $tmp2 . ' and '.$tmp1); |
| 866 | + }; |
| 867 | + $result = join (', ', $stack); |
| 868 | + return $result; |
892 | 869 | |
893 | 870 | } |
894 | 871 | |
895 | 872 | function deleteold($content,$newab,$maxonlog,$logheader) |
896 | 873 | { |
897 | | -//$maxonlog = 20; //Maximale Logfileabschnitte hier einstellen |
| 874 | + //$maxonlog = 20; //Maximale Logfileabschnitte hier einstellen |
898 | 875 | |
899 | | -$beginnat = 0; |
900 | | -$abschnittarray = array("0"); |
901 | | -while($pos = strpos($content,"----",$beginnat)) |
902 | | -{ |
903 | | -$abschnittarray[] = $pos; |
| 876 | + $beginnat = 0; |
| 877 | + $abschnittarray = array("0"); |
| 878 | + while($pos = strpos($content,"----",$beginnat)) |
| 879 | + { |
| 880 | + $abschnittarray[] = $pos; |
904 | 881 | |
905 | | -$beginnat = $pos + 4; |
906 | | -} |
907 | | -$abschnittarray[] = strlen($content);//letzter ist am seitenende |
| 882 | + $beginnat = $pos + 4; |
| 883 | + } |
| 884 | + $abschnittarray[] = strlen($content);//letzter ist am seitenende |
908 | 885 | |
909 | | -$alte = count($abschnittarray) - 2; |
| 886 | + $alte = count($abschnittarray) - 2; |
910 | 887 | |
911 | | -logfile("$alte sections found!"); |
912 | | -$totneu = $newab + $alte; |
913 | | -if($totneu <= $maxonlog) |
914 | | -{ |
915 | | -//Neue Abschnitte nur anhängen KORREKT |
916 | | -logfile("nothing to delete, just add"); |
917 | | -return $content; |
| 888 | + logfile("$alte sections found!"); |
| 889 | + $totneu = $newab + $alte; |
| 890 | + if($totneu <= $maxonlog) |
| 891 | + { |
| 892 | + //Neue Abschnitte nur anhängen KORREKT |
| 893 | + logfile("nothing to delete, just add"); |
| 894 | + return $content; |
918 | 895 | |
919 | | -//COUNTER |
920 | | -$counter = file_get_contents("/home/luxo/rotbot/counter.txt"); |
921 | | -$counter = $counter + $newab; |
922 | | -file_put_contents("/home/luxo/rotbot/counter.txt",$counter); |
923 | | -} |
924 | | -else |
925 | | -{ |
926 | | -//alte löschen |
927 | | -$zuviele = $totneu - $maxonlog ; |
928 | | - |
| 896 | + //COUNTER |
| 897 | + $counter = file_get_contents("/home/luxo/rotbot/counter.txt"); |
| 898 | + $counter = $counter + $newab; |
| 899 | + file_put_contents("/home/luxo/rotbot/counter.txt",$counter); |
| 900 | + } |
| 901 | + else |
| 902 | + { |
| 903 | + //alte löschen |
| 904 | + $zuviele = $totneu - $maxonlog ; |
929 | 905 | |
930 | | -if($zuviele > $alte) //nicht mehr löschen als da sind. |
931 | | -{ |
932 | | -$zuviele = $alte; |
933 | | -} |
934 | 906 | |
935 | | -//zählen wie viele abschnitte neu auf der seite sind |
936 | | -$abschnitteneu = $totneu - $zuviele; |
| 907 | + if($zuviele > $alte) //nicht mehr löschen als da sind. |
| 908 | + { |
| 909 | + $zuviele = $alte; |
| 910 | + } |
937 | 911 | |
| 912 | + //zählen wie viele abschnitte neu auf der seite sind |
| 913 | + $abschnitteneu = $totneu - $zuviele; |
938 | 914 | |
939 | | -logfile("delete $zuviele old sections."); |
940 | 915 | |
| 916 | + logfile("delete $zuviele old sections."); |
941 | 917 | |
942 | | -$bereich = $zuviele+1; |
943 | | -logfile("delete section 1 to $bereich"); |
944 | 918 | |
945 | | -$intro = substr($content,0,$abschnittarray['1']); |
| 919 | + $bereich = $zuviele+1; |
| 920 | + logfile("delete section 1 to $bereich"); |
946 | 921 | |
947 | | -//COUNTER |
948 | | -$counter = file_get_contents("/home/luxo/rotbot/counter.txt"); |
949 | | -$counter = $counter + $newab; |
950 | | -file_put_contents("/home/luxo/rotbot/counter.txt",$counter); |
951 | | -logfile("new counter: $counter."); |
| 922 | + $intro = substr($content,0,$abschnittarray['1']); |
952 | 923 | |
953 | | -$intro = sprintf($logheader."\n",$abschnitteneu,$counter); //NEU in settings definiert: der header vom Log |
954 | | -$deleteabschn = substr($content,$abschnittarray['1'],$abschnittarray[$bereich]-$abschnittarray['1']); |
955 | | -$rest = substr($content,$abschnittarray[$bereich]); |
| 924 | + //COUNTER |
| 925 | + $counter = file_get_contents("/home/luxo/rotbot/counter.txt"); |
| 926 | + $counter = $counter + $newab; |
| 927 | + file_put_contents("/home/luxo/rotbot/counter.txt",$counter); |
| 928 | + logfile("new counter: $counter."); |
956 | 929 | |
957 | | -return $intro.$rest; |
| 930 | + $intro = sprintf($logheader."\n",$abschnitteneu,$counter); //NEU in settings definiert: der header vom Log |
| 931 | + $deleteabschn = substr($content,$abschnittarray['1'],$abschnittarray[$bereich]-$abschnittarray['1']); |
| 932 | + $rest = substr($content,$abschnittarray[$bereich]); |
958 | 933 | |
959 | | -} |
| 934 | + return $intro.$rest; |
960 | 935 | |
| 936 | + } |
| 937 | + |
961 | 938 | } |
962 | 939 | |
963 | 940 | function botsetup() |
964 | 941 | { |
965 | | - $setupraw = file("http://commons.wikimedia.org/w/index.php?title=User:Rotatebot/config.js&action=raw"); |
966 | | - |
967 | | - foreach($setupraw as $line) |
968 | | - { |
969 | | - $line = trim($line); |
970 | | - |
971 | | - if(substr($line,0,2) != "//" AND $line != "") |
972 | | - { |
973 | | - |
974 | | - $gleich = strpos($line, "="); |
975 | | - |
976 | | - $namecon = trim(substr($line,3,$gleich-3)); |
977 | | - |
978 | | - $stripu = strpos($line,";"); |
979 | | - |
980 | | - $content = trim(substr($line,$gleich+1,$stripu - ($gleich + 1))); |
981 | | - |
982 | | - //falls vorhanden "" entfernen |
983 | | - if(substr($content, 0, 1) == '"') |
984 | | - { |
985 | | - $content = substr($content, 1); |
986 | | - } |
987 | | - |
988 | | - if(substr($content, -1) == '"') |
989 | | - { |
990 | | - $content = substr($content, 0, -1); |
991 | | - } |
992 | | - |
993 | | - $content = trim($content); |
994 | | - |
995 | | - $array[$namecon] = $content; |
996 | | - |
997 | | - } |
998 | | - } |
999 | | - return $array; |
| 942 | + $setupraw = file("http://commons.wikimedia.org/w/index.php?title=User:Rotatebot/config.js&action=raw"); |
| 943 | + |
| 944 | + foreach($setupraw as $line) |
| 945 | + { |
| 946 | + $line = trim($line); |
| 947 | + |
| 948 | + if(substr($line,0,2) != "//" AND $line != "") |
| 949 | + { |
| 950 | + |
| 951 | + $gleich = strpos($line, "="); |
| 952 | + |
| 953 | + $namecon = trim(substr($line,3,$gleich-3)); |
| 954 | + |
| 955 | + $stripu = strpos($line,";"); |
| 956 | + |
| 957 | + $content = trim(substr($line,$gleich+1,$stripu - ($gleich + 1))); |
| 958 | + |
| 959 | + //falls vorhanden "" entfernen |
| 960 | + if(substr($content, 0, 1) == '"') |
| 961 | + { |
| 962 | + $content = substr($content, 1); |
| 963 | + } |
| 964 | + |
| 965 | + if(substr($content, -1) == '"') |
| 966 | + { |
| 967 | + $content = substr($content, 0, -1); |
| 968 | + } |
| 969 | + |
| 970 | + $content = trim($content); |
| 971 | + |
| 972 | + $array[$namecon] = $content; |
| 973 | + |
| 974 | + } |
| 975 | + } |
| 976 | + return $array; |
1000 | 977 | } |
1001 | 978 | |
1002 | 979 | function TsToUnixTime($tstime) |
1003 | 980 | { |
1004 | | - $regYear = substr($tstime,0,4); |
1005 | | - $regMonth = substr($tstime,4,2); |
1006 | | - $regDay = substr($tstime,6,2); |
1007 | | - $regHour = substr($tstime,8,2); |
1008 | | - $regMin = substr($tstime,10,2); |
1009 | | - $regSec = substr($tstime,12,2); |
| 981 | + $regYear = substr($tstime,0,4); |
| 982 | + $regMonth = substr($tstime,4,2); |
| 983 | + $regDay = substr($tstime,6,2); |
| 984 | + $regHour = substr($tstime,8,2); |
| 985 | + $regMin = substr($tstime,10,2); |
| 986 | + $regSec = substr($tstime,12,2); |
1010 | 987 | |
1011 | 988 | return mktime($regHour, $regMin, $regSec, $regMonth, $regDay, $regYear); |
1012 | 989 | } |
1013 | 990 | |
1014 | 991 | function hexToStr($hex) |
1015 | 992 | { |
1016 | | - $string=''; |
1017 | | - for ($i=0; $i < strlen($hex)-1; $i+=2) |
1018 | | - { |
1019 | | - $string .= chr(hexdec($hex[$i].$hex[$i+1])); |
1020 | | - } |
1021 | | - return $string; |
| 993 | + $string=''; |
| 994 | + for ($i=0; $i < strlen($hex)-1; $i+=2) |
| 995 | + { |
| 996 | + $string .= chr(hexdec($hex[$i].$hex[$i+1])); |
| 997 | + } |
| 998 | + return $string; |
1022 | 999 | } |
1023 | 1000 | |
1024 | 1001 | |
1025 | 1002 | //checks for other concurrently running rotatebot instances. Exits if not alone on the world |
1026 | | -//Params: |
| 1003 | +//Params: |
1027 | 1004 | // global $myLockfile - String containing a filename to be touched |
1028 | 1005 | // $dontDieOnLockProblems - Boolean for overriding death |
1029 | | -function getLockOrDie($dontDieOnLockProblems) { |
| 1006 | +function getLockOrDie($dontDieOnLockProblems) { |
1030 | 1007 | global $myLockfile; |
1031 | 1008 | |
1032 | 1009 | if (!file_exists($myLockfile)) { |
— | — | @@ -1066,5 +1043,3 @@ |
1067 | 1044 | removeLock(); |
1068 | 1045 | die($exitcodeOrString); |
1069 | 1046 | } |
1070 | | - |
1071 | | -?> |
Index: trunk/tools/rotatebot/upload.php |
— | — | @@ -1,21 +1,21 @@ |
2 | 2 | <?php |
3 | 3 | /* Rotbot © Luxo 2008 |
4 | 4 | |
5 | | - |
6 | | - */ |
7 | | - |
| 5 | + |
| 6 | + */ |
| 7 | + |
8 | 8 | /*$descri = "{{Information |
9 | 9 | |Description=Test-Image for my new rotate-bot. Please do '''not delete''' - I request a speedy deletion if I'm finished with testing. Thank you --~~~~ |
10 | 10 | |Source=self made |
11 | | -|Date=17.11.2007 |
| 11 | +|Date=17.11.2007 |
12 | 12 | |Author=[[User:Luxo]] |
13 | 13 | |Permission= Public Domain |
14 | | -|other_versions= - |
| 14 | +|other_versions= - |
15 | 15 | }} |
16 | 16 | |
17 | 17 | {{PD-self}} |
18 | 18 | "; |
19 | | - |
| 19 | + |
20 | 20 | wikiupload("commons.wikimedia.org","test2.jpg","Test for Rotatebot.jpg","",$descri);*/ |
21 | 21 | |
22 | 22 | // ############### EDIT WIKIPEDIA - FUNCTION ############### |
— | — | @@ -30,31 +30,30 @@ |
31 | 31 | //$cookies |
32 | 32 | if(!$cookies["commonswikiUserName"] OR !$cookies["commonswikiUserID"]) |
33 | 33 | { |
34 | | - $username = "Rotatebot"; |
35 | | - $password = "**removed**"; |
36 | | - logfile("Login to $project!\n"); |
37 | | - wikilogin($username,$password,$project,$useragent); |
38 | | - logfile("logged in to $project!\n"); |
39 | | - print_r($cookies); |
| 34 | + $username = "Rotatebot"; |
| 35 | + $password = "**removed**"; |
| 36 | + logfile("Login to $project!\n"); |
| 37 | + wikilogin($username,$password,$project,$useragent); |
| 38 | + logfile("logged in to $project!\n"); |
| 39 | + print_r($cookies); |
40 | 40 | } |
41 | 41 | else |
42 | 42 | { |
43 | | - logfile("already logged in to $project for upload\n"); |
| 43 | + logfile("already logged in to $project for upload\n"); |
44 | 44 | } |
45 | 45 | |
46 | 46 | |
47 | 47 | if($cookies) { |
48 | | -logfile("Angemeldet in $project!\n"); |
49 | | -} else { |
50 | | -die("Keine Cookies! Abbruch\n$header\n"); |
| 48 | + logfile("Angemeldet in $project!\n"); |
| 49 | +} else { |
| 50 | + die("Keine Cookies! Abbruch\n$header\n"); |
51 | 51 | } |
52 | 52 | |
53 | 53 | //Angemeldet, Cookies formatieren************** |
54 | 54 | |
55 | | - |
56 | | -foreach ($cookies as $key=>$value) |
| 55 | +foreach ($cookies as $key=>$value) |
57 | 56 | { |
58 | | - $cookie .= trim($value).";"; |
| 57 | + $cookie .= trim($value).";"; |
59 | 58 | } |
60 | 59 | $cookie = substr($cookie,0,-1); |
61 | 60 | |
— | — | @@ -66,91 +65,83 @@ |
67 | 66 | /* ########################################### |
68 | 67 | ########## FUNKTIONEN ##################### |
69 | 68 | ########################################### */ |
70 | | - |
| 69 | + |
71 | 70 | function wiki_upload_file ($filename_local,$filename_wiki,$license,$desc,$wiki,$cookies) |
72 | | -{ |
73 | | - $file1 = "";//Löschen wegen Speicherplatz |
74 | | -$file1 = file_get_contents("/home/luxo/rotbot/cache/".$filename_local) or die("Fehler - Datei nicht gefunden! ($filename_local)"); |
| 71 | +{ |
| 72 | + $file1 = "";//Löschen wegen Speicherplatz |
| 73 | + $file1 = file_get_contents("/home/luxo/rotbot/cache/".$filename_local) or die("Fehler - Datei nicht gefunden! ($filename_local)"); |
75 | 74 | |
76 | | - |
77 | | - $data_l = array("file.file" => $file1, |
78 | | - "wpDestFile" => $filename_wiki, |
79 | | - "wpUploadDescription" => str_replace("\\'","'",$desc), |
80 | | - "wpLicense" => $license, |
81 | | - "wpIgnoreWarning" => "1", |
82 | | - "wpUpload" => "Upload file"); |
83 | | - $file1 = "";//Löschen wegen Speicherplatz |
84 | | - wiki_PostToHostFD($wiki, "/wiki/Special:Upload", $data_l, $wiki, $cookies); |
85 | | - |
86 | | - |
87 | | - $data_l = array();//Das auch löschen wegen Speicherplatz |
88 | | - |
| 75 | + $data_l = array("file.file" => $file1, |
| 76 | + "wpDestFile" => $filename_wiki, |
| 77 | + "wpUploadDescription" => str_replace("\\'","'",$desc), |
| 78 | + "wpLicense" => $license, |
| 79 | + "wpIgnoreWarning" => "1", |
| 80 | + "wpUpload" => "Upload file"); |
| 81 | + $file1 = "";//Löschen wegen Speicherplatz |
| 82 | + wiki_PostToHostFD($wiki, "/wiki/Special:Upload", $data_l, $wiki, $cookies); |
| 83 | + |
| 84 | + $data_l = array();//Das auch löschen wegen Speicherplatz |
| 85 | + |
89 | 86 | } |
| 87 | + |
90 | 88 | function wiki_PostToHostFD ($host, $path, $data_l, $wiki, $cookies) //this function was developed by [[:de:User:APPER]] (Christian Thiele) |
91 | 89 | { |
92 | | -logfile("verbinde zu $host ..."); |
93 | | - $useragent = "Luxobot/1.1 (toolserver; php) luxo@ts.wikimedia.org"; |
94 | | - $dc = 0; |
95 | | - $bo="-----------------------------305242850528394"; |
96 | | - $filename=$data_l['wpDestFile']; |
97 | | - $fp = fsockopen($host, 80, $errno, $errstr, 30); |
98 | | - if (!$fp) { echo "$errstr ($errno)<br />\n"; exit; } |
99 | | - |
100 | | - fputs($fp, "POST $path HTTP/1.0\r\n"); |
101 | | - fputs($fp, "Host: $host\r\n"); |
102 | | - fputs($fp, "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*\r\n"); |
103 | | - fputs($fp, "Accept-Charset: iso-8859-1,*,utf-8\r\n"); |
104 | | - fputs($fp, "Cookie: ".$cookies."\r\n"); |
105 | | - fputs($fp, "User-Agent: ".$useragent."\r\n"); |
106 | | - fputs($fp, "Content-type: multipart/form-data; boundary=$bo\r\n"); |
107 | | - |
108 | | - foreach($data_l as $key=>$val) |
109 | | - { |
110 | | - // Hack for attachment |
111 | | - if ($key == "file.file") |
112 | | - { |
113 | | - $ds =sprintf("--%s\r\nContent-Disposition: attachment; name=\"wpUploadFile\"; filename=\"%s\"\r\nContent-type: image/png\r\nContent-Transfer-Encoding: binary\r\n\r\n%s\r\n", $bo, $filename, $val); |
114 | | - } |
115 | | - else |
116 | | - { |
117 | | - $ds =sprintf("--%s\r\nContent-Disposition: form-data; name=\"%s\"\r\n\r\n%s\r\n", $bo, $key, $val); |
118 | | - } |
119 | | - $dc += strlen($ds); |
120 | | - } |
121 | | - $dc += strlen($bo)+3; |
122 | | - fputs($fp, "Content-length: $dc \n"); |
123 | | - fputs($fp, "\n"); |
124 | | - |
125 | | - foreach($data_l as $key=>$val) |
126 | | - { |
127 | | - if ($key == "file.file") |
128 | | - { |
129 | | - $ds =sprintf("--%s\r\nContent-Disposition: attachment; name=\"wpUploadFile\"; filename=\"%s\"\r\nContent-type: image/png\r\nContent-Transfer-Encoding: binary\r\n\r\n%s\r\n", $bo, $filename, $val); |
130 | | - $data_1["file.file"] = "";//löschen |
131 | | - } |
132 | | - else |
133 | | - { |
134 | | - $ds =sprintf("--%s\r\nContent-Disposition: form-data; name=\"%s\"\r\n\r\n%s\r\n", $bo, $key, $val); |
135 | | - } |
136 | | - fputs($fp, $ds ); |
137 | | - } |
138 | | - $ds = "--".$bo."--\n"; |
139 | | - fputs($fp, $ds); |
140 | | - |
141 | | - $res = ""; |
142 | | - while(!feof($fp)) |
143 | | - { |
144 | | - $res .= fread($fp, 1); |
145 | | - } |
146 | | - fclose($fp); |
147 | | - file_put_contents("/home/luxo/rotbot/cache/log.txt",$res); |
148 | | - return $res; |
149 | | - $data_l = array(); |
150 | | -} |
| 90 | + logfile("verbinde zu $host ..."); |
| 91 | + $useragent = "Luxobot/1.1 (toolserver; php) luxo@ts.wikimedia.org"; |
| 92 | + $dc = 0; |
| 93 | + $bo="-----------------------------305242850528394"; |
| 94 | + $filename=$data_l['wpDestFile']; |
| 95 | + $fp = fsockopen($host, 80, $errno, $errstr, 30); |
| 96 | + if (!$fp) { echo "$errstr ($errno)<br />\n"; exit; } |
151 | 97 | |
| 98 | + fputs($fp, "POST $path HTTP/1.0\r\n"); |
| 99 | + fputs($fp, "Host: $host\r\n"); |
| 100 | + fputs($fp, "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*\r\n"); |
| 101 | + fputs($fp, "Accept-Charset: iso-8859-1,*,utf-8\r\n"); |
| 102 | + fputs($fp, "Cookie: ".$cookies."\r\n"); |
| 103 | + fputs($fp, "User-Agent: ".$useragent."\r\n"); |
| 104 | + fputs($fp, "Content-type: multipart/form-data; boundary=$bo\r\n"); |
152 | 105 | |
| 106 | + foreach($data_l as $key=>$val) |
| 107 | + { |
| 108 | + // Hack for attachment |
| 109 | + if ($key == "file.file") |
| 110 | + { |
| 111 | + $ds =sprintf("--%s\r\nContent-Disposition: attachment; name=\"wpUploadFile\"; filename=\"%s\"\r\nContent-type: image/png\r\nContent-Transfer-Encoding: binary\r\n\r\n%s\r\n", $bo, $filename, $val); |
| 112 | + } |
| 113 | + else |
| 114 | + { |
| 115 | + $ds =sprintf("--%s\r\nContent-Disposition: form-data; name=\"%s\"\r\n\r\n%s\r\n", $bo, $key, $val); |
| 116 | + } |
| 117 | + $dc += strlen($ds); |
| 118 | + } |
| 119 | + $dc += strlen($bo)+3; |
| 120 | + fputs($fp, "Content-length: $dc \n"); |
| 121 | + fputs($fp, "\n"); |
153 | 122 | |
| 123 | + foreach($data_l as $key=>$val) |
| 124 | + { |
| 125 | + if ($key == "file.file") |
| 126 | + { |
| 127 | + $ds =sprintf("--%s\r\nContent-Disposition: attachment; name=\"wpUploadFile\"; filename=\"%s\"\r\nContent-type: image/png\r\nContent-Transfer-Encoding: binary\r\n\r\n%s\r\n", $bo, $filename, $val); |
| 128 | + $data_1["file.file"] = "";//löschen |
| 129 | + } |
| 130 | + else |
| 131 | + { |
| 132 | + $ds =sprintf("--%s\r\nContent-Disposition: form-data; name=\"%s\"\r\n\r\n%s\r\n", $bo, $key, $val); |
| 133 | + } |
| 134 | + fputs($fp, $ds ); |
| 135 | + } |
| 136 | + $ds = "--".$bo."--\n"; |
| 137 | + fputs($fp, $ds); |
154 | 138 | |
155 | | - |
156 | | - |
157 | | -?> |
| 139 | + $res = ""; |
| 140 | + while(!feof($fp)) |
| 141 | + { |
| 142 | + $res .= fread($fp, 1); |
| 143 | + } |
| 144 | + fclose($fp); |
| 145 | + file_put_contents("/home/luxo/rotbot/cache/log.txt",$res); |
| 146 | + return $res; |
| 147 | + $data_l = array(); |
| 148 | +} |
Index: trunk/tools/rotatebot/login.php |
— | — | @@ -1,317 +1,298 @@ |
2 | 2 | <?php |
3 | 3 | /* Bilderbot © Luxo 2007 |
4 | 4 | |
5 | | - This file is part of Luxobot. |
| 5 | + This file is part of Luxobot. |
6 | 6 | |
7 | | - Luxobot is free software: you can redistribute it and/or modify |
8 | | - it under the terms of the GNU General Public License as published by |
9 | | - the Free Software Foundation, either version 3 of the License, or |
10 | | - (at your option) any later version. |
| 7 | + Luxobot is free software: you can redistribute it and/or modify |
| 8 | + it under the terms of the GNU General Public License as published by |
| 9 | + the Free Software Foundation, either version 3 of the License, or |
| 10 | + (at your option) any later version. |
11 | 11 | |
12 | | - Foobar is distributed in the hope that it will be useful, |
13 | | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | - GNU General Public License for more details. |
| 12 | + Foobar is distributed in the hope that it will be useful, |
| 13 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + GNU General Public License for more details. |
16 | 16 | |
17 | | - You should have received a copy of the GNU General Public License |
18 | | - along with Foobar. If not, see <http://www.gnu.org/licenses/>. |
19 | | - |
20 | | - */ |
| 17 | + You should have received a copy of the GNU General Public License |
| 18 | + along with Foobar. If not, see <http://www.gnu.org/licenses/>. |
21 | 19 | |
| 20 | + */ |
22 | 21 | |
23 | 22 | |
24 | 23 | // ############### EDIT WIKIPEDIA - FUNCTION ############### |
25 | 24 | function wikiedit($project,$page,$newtext,$description,$minor) |
26 | 25 | { |
27 | | -global $cookies; |
28 | | - logfile("Funktion gestartet..."); |
29 | | - logfile("Schreibe Text am ".date("r",time())." in die Seite '$page'."); |
30 | | - |
31 | | - $useragent = "Luxo (toolserver; php) luxo@ts.wikimedia.org"; |
32 | | - |
33 | | -//$cookies |
34 | | -if(!$cookies["commonswikiUserName"] OR !$cookies["commonswikiUserID"]) |
35 | | -{ |
36 | | - $username = "Rotatebot"; |
37 | | - $password = "**removed**"; |
38 | | - logfile("Login to $project!\n"); |
39 | | - wikilogin($username,$password,$project,$useragent); |
40 | | - logfile("logged in to $project!\n"); |
41 | | - print_r($cookies); |
42 | | -} |
43 | | -else |
44 | | -{ |
45 | | - logfile("already logged in to $project!\n"); |
46 | | -} |
| 26 | + global $cookies; |
| 27 | + logfile("Funktion gestartet..."); |
| 28 | + logfile("Schreibe Text am ".date("r",time())." in die Seite '$page'."); |
47 | 29 | |
| 30 | + $useragent = "Luxo (toolserver; php) luxo@ts.wikimedia.org"; |
48 | 31 | |
49 | | - |
| 32 | + //$cookies |
| 33 | + if(!$cookies["commonswikiUserName"] OR !$cookies["commonswikiUserID"]) |
| 34 | + { |
| 35 | + $username = "Rotatebot"; |
| 36 | + $password = "**removed**"; |
| 37 | + logfile("Login to $project!\n"); |
| 38 | + wikilogin($username,$password,$project,$useragent); |
| 39 | + logfile("logged in to $project!\n"); |
| 40 | + print_r($cookies); |
| 41 | + } |
| 42 | + else |
| 43 | + { |
| 44 | + logfile("already logged in to $project!\n"); |
| 45 | + } |
50 | 46 | |
51 | | -//echo $header."\n\n"; |
| 47 | + //echo $header."\n\n"; |
52 | 48 | |
53 | | -// Response Body auslesen |
54 | | -/*while (!feof($fp)) { |
55 | | -$linew=fgets($fp,255); |
56 | | -$bodyw.=$linew; |
57 | | -} |
58 | | -echo $bodyw;*/ |
59 | | -$header = ""; |
| 49 | + // Response Body auslesen |
| 50 | + /*while (!feof($fp)) { |
| 51 | + $linew=fgets($fp,255); |
| 52 | + $bodyw.=$linew; |
| 53 | + } |
| 54 | + echo $bodyw;*/ |
| 55 | + $header = ""; |
60 | 56 | |
61 | 57 | |
62 | | -//Angemeldet, Cookies ausgelesen, editieren kann beginnen************** |
63 | | -$fpb = fsockopen ($project, 80, $errno, $errstr, 30); |
| 58 | + //Angemeldet, Cookies ausgelesen, editieren kann beginnen************** |
| 59 | + $fpb = fsockopen ($project, 80, $errno, $errstr, 30); |
64 | 60 | |
65 | | -//Bearbeiten-Seite aufrufen, um wpEditToken & cookie zu erhalten *************** |
66 | | -$getrequest = "/w/index.php?title=".urlencode($page)."&action=edit"; |
67 | | -fputs($fpb, "GET $getrequest HTTP/1.1\n"); |
68 | | -fputs($fpb, "Host: $project\n"); |
69 | | -fputs($fpb, "User-Agent: $useragent\n"); |
70 | | -fputs($fpb, "Accept: $accept\n"); |
71 | | -fputs($fpb, "Accept-Language: de\n"); |
| 61 | + //Bearbeiten-Seite aufrufen, um wpEditToken & cookie zu erhalten *************** |
| 62 | + $getrequest = "/w/index.php?title=".urlencode($page)."&action=edit"; |
| 63 | + fputs($fpb, "GET $getrequest HTTP/1.1\n"); |
| 64 | + fputs($fpb, "Host: $project\n"); |
| 65 | + fputs($fpb, "User-Agent: $useragent\n"); |
| 66 | + fputs($fpb, "Accept: $accept\n"); |
| 67 | + fputs($fpb, "Accept-Language: de\n"); |
72 | 68 | |
73 | | -foreach ($cookies as $key=>$value) |
74 | | -{ |
75 | | - $cookie .= trim($value).";"; |
76 | | -} |
77 | | -$cookie = substr($cookie,0,-1); |
78 | | - |
| 69 | + foreach ($cookies as $key=>$value) |
| 70 | + { |
| 71 | + $cookie .= trim($value).";"; |
| 72 | + } |
| 73 | + $cookie = substr($cookie,0,-1); |
79 | 74 | |
80 | 75 | |
81 | | -logfile("Lade Seite; Cookies: $cookie\n"); |
| 76 | + logfile("Lade Seite; Cookies: $cookie\n"); |
82 | 77 | |
83 | | -fputs($fpb, "Cookie: ".$cookie."\n"); |
| 78 | + fputs($fpb, "Cookie: ".$cookie."\n"); |
84 | 79 | |
85 | | -fputs($fpb, "Connection: close\n"); |
86 | | -fputs($fpb, "\n"); |
| 80 | + fputs($fpb, "Connection: close\n"); |
| 81 | + fputs($fpb, "\n"); |
87 | 82 | |
88 | 83 | |
89 | | -//Response Header auslesen forallem cooke******************** |
90 | | -do { |
91 | | -$linex=fgets($fpb,255); |
92 | | -$headerrx.=$linex; |
| 84 | + //Response Header auslesen forallem cooke******************** |
| 85 | + do { |
| 86 | + $linex=fgets($fpb,255); |
| 87 | + $headerrx.=$linex; |
93 | 88 | |
94 | | -//auf cookie prüfen |
95 | | -if(substr($linex,0,11) == "Set-Cookie:") |
96 | | -{ |
97 | | -$rawcookie = substr($line,11,strpos($line,";")-11); //Format: session=DFJ3ASD2S |
98 | | - $cookiename = trim(substr($rawcookie,0,strpos($rawcookie,"="))); |
99 | | -$cookies[$cookiename] = $rawcookie; |
100 | | -} |
| 89 | + //auf cookie prüfen |
| 90 | + if(substr($linex,0,11) == "Set-Cookie:") |
| 91 | + { |
| 92 | + $rawcookie = substr($line,11,strpos($line,";")-11); //Format: session=DFJ3ASD2S |
| 93 | + $cookiename = trim(substr($rawcookie,0,strpos($rawcookie,"="))); |
| 94 | + $cookies[$cookiename] = $rawcookie; |
| 95 | + } |
101 | 96 | |
102 | | -} while (trim($linex)!=""); |
| 97 | + } while (trim($linex)!=""); |
103 | 98 | |
104 | | -//cookie-header erneut generieren |
105 | | -$cookie = ""; |
106 | | -foreach ($cookies as $key=>$value) |
107 | | -{ |
108 | | - $cookie .= trim($value).";"; |
109 | | -} |
110 | | -$cookie = substr($cookie,0,-1); |
| 99 | + //cookie-header erneut generieren |
| 100 | + $cookie = ""; |
| 101 | + foreach ($cookies as $key=>$value) |
| 102 | + { |
| 103 | + $cookie .= trim($value).";"; |
| 104 | + } |
| 105 | + $cookie = substr($cookie,0,-1); |
111 | 106 | |
112 | 107 | |
113 | | -logfile("Neue Cookies: $cookie\n"); |
| 108 | + logfile("Neue Cookies: $cookie\n"); |
114 | 109 | |
115 | | -//echo $headerrx."\n\n"; |
116 | | -// Response Body auslesen********************** |
117 | | -while (!feof($fpb)) { |
118 | | -$line=fgets($fpb,255); |
119 | | -$bodyy.=$line; |
120 | | -//Die verschiedenen form-data's auslesen |
121 | | -if(strstr($line, "wpStarttime")) |
122 | | -{ |
123 | | -$formdata['wpStarttime'] = $line; |
124 | | -} |
125 | | -if(strstr($line, "wpEdittime")) |
126 | | -{ |
127 | | -$formdata['wpEdittime'] = $line; |
128 | | -} |
129 | | -if(strstr($line, "wpScrolltop")) |
130 | | -{ |
131 | | -$formdata['wpScrolltop'] = $line; |
132 | | -} |
133 | | -if(strstr($line, "wpEditToken")) |
134 | | -{ |
135 | | -$formdata['wpEditToken'] = $line; |
136 | | -} |
137 | | -if(strstr($line, "wpAutoSummary")) |
138 | | -{ |
139 | | -$formdata['wpAutoSummary'] = $line; |
140 | | -} |
141 | | -if(strstr($line, "wpSave")) |
142 | | -{ |
143 | | -$formdata['wpSave'] = $line; |
144 | | -} |
145 | | -} |
146 | | -logfile("Seite geladen, Anmeldung prüfen."); |
| 110 | + //echo $headerrx."\n\n"; |
| 111 | + // Response Body auslesen********************** |
| 112 | + while (!feof($fpb)) { |
| 113 | + $line=fgets($fpb,255); |
| 114 | + $bodyy.=$line; |
| 115 | + //Die verschiedenen form-data's auslesen |
| 116 | + if(strstr($line, "wpStarttime")) |
| 117 | + { |
| 118 | + $formdata['wpStarttime'] = $line; |
| 119 | + } |
| 120 | + if(strstr($line, "wpEdittime")) |
| 121 | + { |
| 122 | + $formdata['wpEdittime'] = $line; |
| 123 | + } |
| 124 | + if(strstr($line, "wpScrolltop")) |
| 125 | + { |
| 126 | + $formdata['wpScrolltop'] = $line; |
| 127 | + } |
| 128 | + if(strstr($line, "wpEditToken")) |
| 129 | + { |
| 130 | + $formdata['wpEditToken'] = $line; |
| 131 | + } |
| 132 | + if(strstr($line, "wpAutoSummary")) |
| 133 | + { |
| 134 | + $formdata['wpAutoSummary'] = $line; |
| 135 | + } |
| 136 | + if(strstr($line, "wpSave")) |
| 137 | + { |
| 138 | + $formdata['wpSave'] = $line; |
| 139 | + } |
| 140 | + } |
| 141 | + logfile("Seite geladen, Anmeldung prüfen."); |
147 | 142 | |
148 | | -if(strstr($bodyy,'"wgUserName": "Rotatebot",')) |
149 | | -{ |
150 | | -logfile("Anmeldung erfolgreich!"); |
| 143 | + if(strstr($bodyy,'"wgUserName": "Rotatebot",')) |
| 144 | + { |
| 145 | + logfile("Anmeldung erfolgreich!"); |
151 | 146 | |
152 | | -//ende auslesen, verbindung schliessen |
153 | | -fclose($fpb); |
| 147 | + //ende auslesen, verbindung schliessen |
| 148 | + fclose($fpb); |
154 | 149 | |
155 | | -//aus formdatas nur values nehmen |
| 150 | + //aus formdatas nur values nehmen |
156 | 151 | |
157 | | -foreach($formdata as $type => $formcontent) |
158 | | -{ |
| 152 | + foreach($formdata as $type => $formcontent) |
| 153 | + { |
| 154 | + $t1 = strstr($formcontent,'value="'); |
| 155 | + $t2 = strpos($t1,'"',7); |
| 156 | + $t1 = substr($t1,7,$t2-7); |
159 | 157 | |
160 | | -$t1 = strstr($formcontent,'value="'); |
161 | | -$t2 = strpos($t1,'"',7); |
162 | | -$t1 = substr($t1,7,$t2-7); |
| 158 | + $formdata["$type"] = $t1; |
| 159 | + } |
163 | 160 | |
164 | | -$formdata["$type"] = $t1; |
165 | | -} |
| 161 | + // ########################### POST-CONTENT VORBEREITEN ##################### |
166 | 162 | |
| 163 | + //content vorbereiten |
| 164 | + $content = "wpSection=&wpStarttime=".urlencode($formdata['wpStarttime'])."&wpEdittime=".urlencode($formdata['wpEdittime'])."&wpScrolltop=".urlencode($formdata['wpScrolltop'])."&wpTextbox1=".urlencode($newtext)."&wpSummary=".urlencode($description)."&wpMinoredit=".urlencode($minor)."&wpWatchthis=1&wpSave=".$formdata['wpSave']."&wpEditToken=".urlencode($formdata['wpEditToken'])."&wpAutoSummary=".urlencode($formdata['wpAutoSummary']); |
167 | 165 | |
168 | | -// ########################### POST-CONTENT VORBEREITEN ##################### |
| 166 | + logfile("Content (".strlen($content)." Zeichen) vorbereitet, verbinde zum Speichern!"); |
169 | 167 | |
170 | | -//content vorbereiten |
171 | | -$content = "wpSection=&wpStarttime=".urlencode($formdata['wpStarttime'])."&wpEdittime=".urlencode($formdata['wpEdittime'])."&wpScrolltop=".urlencode($formdata['wpScrolltop'])."&wpTextbox1=".urlencode($newtext)."&wpSummary=".urlencode($description)."&wpMinoredit=".urlencode($minor)."&wpWatchthis=1&wpSave=".$formdata['wpSave']."&wpEditToken=".urlencode($formdata['wpEditToken'])."&wpAutoSummary=".urlencode($formdata['wpAutoSummary']); |
| 168 | + //######## POST-Content vorbereitet, verbinden & POST-header senden ######### |
172 | 169 | |
| 170 | + //zum speichern verbinden |
| 171 | + $fpc = fsockopen ($project, 80, $errno, $errstr, 30); |
| 172 | + //Speichern per Post.. *************** |
173 | 173 | |
| 174 | + $referer = "http://$project/w/index.php?title=".urlencode($page)."&action=edit"; |
174 | 175 | |
175 | | -logfile("Content (".strlen($content)." Zeichen) vorbereitet, verbinde zum Speichern!"); |
| 176 | + fputs($fpc, "POST /w/index.php?title=".urlencode($page)."&action=submit HTTP/1.1\n"); |
| 177 | + fputs($fpc, "Host: $project\n"); |
| 178 | + fputs($fpc, "User-Agent: $useragent\n"); |
| 179 | + fputs($fpc, "Accept: $accept\n"); |
| 180 | + fputs($fpc, "Accept-Language: de\n"); |
| 181 | + //fputs($fpc, "Accept-Encoding: gzip,deflate\n"); //gzip --> seite komprimiert! |
| 182 | + fputs($fpc, "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\n"); |
| 183 | + fputs($fpc, "Keep-Alive: 300\n"); |
| 184 | + fputs($fpc, "Connection: keep-alive\n"); |
| 185 | + fputs($fpc, "Referer: $referer\n"); |
| 186 | + fputs($fpc, "Cookie: ".$cookie."\n"); |
| 187 | + fputs($fpc, "Content-Type: application/x-www-form-urlencoded\n"); |
| 188 | + fputs($fpc, "Content-Length: ".strlen($content)."\n"); |
| 189 | + fputs($fpc, "\n"); |
| 190 | + fputs($fpc, $content); |
| 191 | + logfile("Header gesendet."); |
176 | 192 | |
177 | | -//######## POST-Content vorbereitet, verbinden & POST-header senden ######### |
| 193 | + //Response Header auslesen vorallem cooke******************** |
| 194 | + $xxx = 0; |
| 195 | + do { |
| 196 | + $linex=fgets($fpc,255); |
| 197 | + if($xxx == 0) |
| 198 | + { |
| 199 | + $linexx = $linex; |
| 200 | + } |
| 201 | + $xxx += 1; |
178 | 202 | |
179 | | -//zum speichern verbinden |
180 | | -$fpc = fsockopen ($project, 80, $errno, $errstr, 30); |
181 | | -//Speichern per Post.. *************** |
| 203 | + $headerrx.=$linex; |
182 | 204 | |
183 | | -$referer = "http://$project/w/index.php?title=".urlencode($page)."&action=edit"; |
| 205 | + //auf cookie prüfen |
| 206 | + if(substr($linex,0,11) == "Set-Cookie:") |
| 207 | + { |
| 208 | + $rawcookie = substr($line,11,strpos($line,";")-11); //Format: session=DFJ3ASD2S |
| 209 | + $cookiename = trim(substr($rawcookie,0,strpos($rawcookie,"="))); |
| 210 | + $cookies[$cookiename] = $rawcookie; |
| 211 | + } |
184 | 212 | |
185 | | -fputs($fpc, "POST /w/index.php?title=".urlencode($page)."&action=submit HTTP/1.1\n"); |
186 | | -fputs($fpc, "Host: $project\n"); |
187 | | -fputs($fpc, "User-Agent: $useragent\n"); |
188 | | -fputs($fpc, "Accept: $accept\n"); |
189 | | -fputs($fpc, "Accept-Language: de\n"); |
190 | | -//fputs($fpc, "Accept-Encoding: gzip,deflate\n"); //gzip --> seite komprimiert! |
191 | | -fputs($fpc, "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\n"); |
192 | | -fputs($fpc, "Keep-Alive: 300\n"); |
193 | | -fputs($fpc, "Connection: keep-alive\n"); |
194 | | -fputs($fpc, "Referer: $referer\n"); |
195 | | -fputs($fpc, "Cookie: ".$cookie."\n"); |
196 | | -fputs($fpc, "Content-Type: application/x-www-form-urlencoded\n"); |
197 | | -fputs($fpc, "Content-Length: ".strlen($content)."\n"); |
198 | | -fputs($fpc, "\n"); |
199 | | -fputs($fpc, $content); |
200 | | -logfile("Header gesendet."); |
| 213 | + } while (trim($linex)!=""); |
201 | 214 | |
202 | | -//Response Header auslesen vorallem cooke******************** |
203 | | -$xxx = 0; |
204 | | -do { |
205 | | -$linex=fgets($fpc,255); |
206 | | -if($xxx == 0) |
207 | | -{ |
208 | | - $linexx = $linex; |
209 | | -} |
210 | | -$xxx += 1; |
| 215 | + if(strstr($linexx,"Moved Temporarily")) |
| 216 | + { |
| 217 | + logfile("Bearbeitung Erfolgreich."); |
| 218 | + return true; |
| 219 | + } |
| 220 | + else |
| 221 | + { |
| 222 | + logfile("BEARBEITUNG FEHLGESCHLAGEN!.\nFehler-Header: $line"); |
| 223 | + return false; |
| 224 | + } |
211 | 225 | |
212 | | -$headerrx.=$linex; |
| 226 | + /* |
| 227 | + while (!feof($fpc)) { |
| 228 | + $linew=fgets($fpc,255); |
| 229 | + $bodyw.=$linew; |
| 230 | + } |
| 231 | + logfile("-------\n".$bodyw."----------\n"); */ |
| 232 | + fclose($fpc); |
213 | 233 | |
214 | | -//auf cookie prüfen |
215 | | -if(substr($linex,0,11) == "Set-Cookie:") |
216 | | -{ |
217 | | -$rawcookie = substr($line,11,strpos($line,";")-11); //Format: session=DFJ3ASD2S |
218 | | - $cookiename = trim(substr($rawcookie,0,strpos($rawcookie,"="))); |
219 | | -$cookies[$cookiename] = $rawcookie; |
| 234 | + echo"ende."; |
| 235 | + } |
| 236 | + else |
| 237 | + { |
| 238 | + logfile("ANMELDUNG FEHLGESCHLAGEN, KONNTE NICHT ANMELDEN!\n"); |
| 239 | + die(); |
| 240 | + } |
| 241 | + |
220 | 242 | } |
221 | 243 | |
222 | | -} while (trim($linex)!=""); |
223 | | - |
224 | | - |
225 | | - |
226 | | - |
227 | | -if(strstr($linexx,"Moved Temporarily")) |
| 244 | +function wikilogin($username,$password,$project,$useragent) |
228 | 245 | { |
229 | | -logfile("Bearbeitung Erfolgreich."); |
230 | | -return true; |
231 | | -} |
232 | | -else |
233 | | -{ |
234 | | -logfile("BEARBEITUNG FEHLGESCHLAGEN!.\nFehler-Header: $line"); |
235 | | -return false; |
236 | | -} |
| 246 | + global $cookies; |
237 | 247 | |
| 248 | + $getrequest = (substr($project,-1) == "/") ? "w/api.php?action=login" : "/w/api.php?action=login"; |
| 249 | + $project = (substr($project,0,7) == "http://") ? $project : "http://".$project; |
238 | 250 | |
| 251 | + logfile("Login via API to $project as $username..."); |
239 | 252 | |
| 253 | + $postlogin = "lgname=".urlencode($username)."&lgpassword=".urlencode($password)."&format=php"; |
240 | 254 | |
241 | | -/* |
242 | | -while (!feof($fpc)) { |
243 | | -$linew=fgets($fpc,255); |
244 | | -$bodyw.=$linew; |
245 | | -} |
246 | | -logfile("-------\n".$bodyw."----------\n"); */ |
247 | | -fclose($fpc); |
| 255 | + if(!$useragent) { $useragent = "Luxo (Toolserver; php) luxo@ts.wikimedia.org"; } |
| 256 | + $ch = curl_init($project.$getrequest); |
| 257 | + curl_setopt($ch, CURLOPT_POST, TRUE); |
| 258 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $postlogin); |
| 259 | + curl_setopt($ch, CURLOPT_USERAGENT, $useragent); |
| 260 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 261 | + curl_setopt($ch, CURLOPT_COOKIEJAR, "/home/luxo/cks"); |
248 | 262 | |
249 | | -echo"ende."; |
250 | | -} |
251 | | -else |
252 | | -{ |
253 | | -logfile("ANMELDUNG FEHLGESCHLAGEN, KONNTE NICHT ANMELDEN!\n"); |
254 | | -die(); |
255 | | -} |
| 263 | + $rx = curl_exec($ch); |
256 | 264 | |
257 | | -} |
| 265 | + $data = unserialize($rx); |
258 | 266 | |
259 | | -function wikilogin($username,$password,$project,$useragent) |
260 | | -{ |
261 | | - global $cookies; |
| 267 | + curl_close($ch); |
262 | 268 | |
263 | | - $getrequest = (substr($project,-1) == "/") ? "w/api.php?action=login" : "/w/api.php?action=login"; |
264 | | - $project = (substr($project,0,7) == "http://") ? $project : "http://".$project; |
265 | | - |
266 | | - logfile("Login via API to $project as $username..."); |
| 269 | + if($data['login']['result'] == "NeedToken") |
| 270 | + { |
| 271 | + $postlogin = "lgname=".urlencode($username)."&lgpassword=".urlencode($password)."&lgtoken=".urlencode($data['login']['token'])."&format=php"; |
| 272 | + $ch = curl_init($project.$getrequest); |
| 273 | + curl_setopt($ch, CURLOPT_POST, TRUE); |
| 274 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $postlogin); |
| 275 | + curl_setopt($ch, CURLOPT_USERAGENT, $useragent); |
| 276 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 277 | + curl_setopt($ch, CURLOPT_COOKIEFILE, "/home/luxo/cks"); |
| 278 | + curl_setopt($ch, CURLOPT_COOKIEJAR, "/home/luxo/cks"); |
| 279 | + $ry = curl_exec($ch); |
| 280 | + $data = unserialize($ry); |
267 | 281 | |
268 | | - $postlogin = "lgname=".urlencode($username)."&lgpassword=".urlencode($password)."&format=php"; |
269 | | - |
270 | | - if(!$useragent) { $useragent = "Luxo (Toolserver; php) luxo@ts.wikimedia.org"; } |
271 | | - $ch = curl_init($project.$getrequest); |
272 | | - curl_setopt($ch, CURLOPT_POST, TRUE); |
273 | | - curl_setopt($ch, CURLOPT_POSTFIELDS, $postlogin); |
274 | | - curl_setopt($ch, CURLOPT_USERAGENT, $useragent); |
275 | | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
276 | | - curl_setopt($ch, CURLOPT_COOKIEJAR, "/home/luxo/cks"); |
277 | | - |
278 | | - $rx = curl_exec($ch); |
| 282 | + } |
279 | 283 | |
280 | | - $data = unserialize($rx); |
281 | | - |
282 | | - curl_close($ch); |
283 | | - |
284 | | - if($data['login']['result'] == "NeedToken") |
285 | | - { |
286 | | - $postlogin = "lgname=".urlencode($username)."&lgpassword=".urlencode($password)."&lgtoken=".urlencode($data['login']['token'])."&format=php"; |
287 | | - $ch = curl_init($project.$getrequest); |
288 | | - curl_setopt($ch, CURLOPT_POST, TRUE); |
289 | | - curl_setopt($ch, CURLOPT_POSTFIELDS, $postlogin); |
290 | | - curl_setopt($ch, CURLOPT_USERAGENT, $useragent); |
291 | | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
292 | | - curl_setopt($ch, CURLOPT_COOKIEFILE, "/home/luxo/cks"); |
293 | | - curl_setopt($ch, CURLOPT_COOKIEJAR, "/home/luxo/cks"); |
294 | | - $ry = curl_exec($ch); |
295 | | - $data = unserialize($ry); |
296 | | - |
297 | | - } |
298 | | - |
299 | | - if($data['login']['result'] == "Success") |
300 | | - { |
301 | | - logfile("Login erfolgreich"); |
302 | | - |
303 | | - //Cookie aufbauen |
304 | | - $cookies = array($data['login']['cookieprefix']."_session" => $data['login']['cookieprefix']."_session=".$data['login']['sessionid'], |
305 | | - $data['login']['cookieprefix']."UserID" => $data['login']['cookieprefix']."UserID=".$data['login']['lguserid'], // [commonswikiUserID] => commonswikiUserID=205395 |
306 | | - $data['login']['cookieprefix']."UserName" => $data['login']['cookieprefix']."UserName=".$data['login']['lgusername'], |
307 | | - $data['login']['cookieprefix']."Token" => $data['login']['cookieprefix']."Token=".$data['login']['lgtoken']); |
308 | | - } else { |
309 | | - die("Login nicht erfolgreich! (".$data['login']['result'].")"); |
310 | | - } |
311 | | - |
312 | | - curl_close($ch); |
313 | | - return $cookies; |
314 | | -} |
| 284 | + if($data['login']['result'] == "Success") |
| 285 | + { |
| 286 | + logfile("Login erfolgreich"); |
315 | 287 | |
| 288 | + //Cookie aufbauen |
| 289 | + $cookies = array($data['login']['cookieprefix']."_session" => $data['login']['cookieprefix']."_session=".$data['login']['sessionid'], |
| 290 | + $data['login']['cookieprefix']."UserID" => $data['login']['cookieprefix']."UserID=".$data['login']['lguserid'], // [commonswikiUserID] => commonswikiUserID=205395 |
| 291 | + $data['login']['cookieprefix']."UserName" => $data['login']['cookieprefix']."UserName=".$data['login']['lgusername'], |
| 292 | + $data['login']['cookieprefix']."Token" => $data['login']['cookieprefix']."Token=".$data['login']['lgtoken']); |
| 293 | + } else { |
| 294 | + die("Login nicht erfolgreich! (".$data['login']['result'].")"); |
| 295 | + } |
316 | 296 | |
317 | | - |
318 | | -?> |
| 297 | + curl_close($ch); |
| 298 | + return $cookies; |
| 299 | +} |