r106324 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106323‎ | r106324 | r106325 >
Date:14:21, 15 December 2011
Author:reedy
Status:ok
Tags:
Comment:
Variablise commonly used paths

Fix some indenting
Modified paths:
  • /trunk/tools/rotatebot/login.php (modified) (history)
  • /trunk/tools/rotatebot/rotbot.php (modified) (history)
  • /trunk/tools/rotatebot/upload.php (modified) (history)

Diff [purge]

Index: trunk/tools/rotatebot/upload.php
@@ -18,6 +18,8 @@
1919
2020 wikiupload("commons.wikimedia.org","test2.jpg","Test for Rotatebot.jpg","",$descri);*/
2121
 22+$homedir = "/home/luxo/rotbot/";
 23+
2224 // ############### EDIT WIKIPEDIA - FUNCTION ###############
2325 function wikiupload($project,$filename_local,$filename_wiki,$license,$desc)
2426 {
@@ -70,7 +72,8 @@
7173
7274 function wiki_upload_file ($filename_local,$filename_wiki,$license,$desc,$wiki,$cookies)
7375 {
74 - $file1 = file_get_contents("/home/luxo/rotbot/cache/".$filename_local) or die("Fehler - Datei nicht gefunden! ($filename_local)");
 76+ global $homedir;
 77+ $file1 = file_get_contents($homedir . "cache/".$filename_local) or die("Fehler - Datei nicht gefunden! ($filename_local)");
7578
7679 $data_l = array("file.file" => $file1,
7780 "wpDestFile" => $filename_wiki,
@@ -142,6 +145,7 @@
143146 $res .= fread($fp, 1);
144147 }
145148 fclose($fp);
146 - file_put_contents("/home/luxo/rotbot/cache/log.txt",$res);
 149+ global $homedir;
 150+ file_put_contents( $homedir . "cache/log.txt",$res);
147151 return $res;
148152 }
Index: trunk/tools/rotatebot/login.php
@@ -18,6 +18,7 @@
1919
2020 */
2121
 22+$cookies = "/home/lux/cks";
2223
2324 // ############### EDIT WIKIPEDIA - FUNCTION ###############
2425 function wikiedit($project,$page,$newtext,$description,$minor)
@@ -252,13 +253,14 @@
253254
254255 $postlogin = "lgname=".urlencode($username)."&lgpassword=".urlencode($password)."&format=php";
255256
 257+ global $cookies;
256258 if(!$useragent) { $useragent = "Luxo (Toolserver; php) luxo@ts.wikimedia.org"; }
257259 $ch = curl_init($project.$getrequest);
258260 curl_setopt($ch, CURLOPT_POST, TRUE);
259261 curl_setopt($ch, CURLOPT_POSTFIELDS, $postlogin);
260262 curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
261263 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
262 - curl_setopt($ch, CURLOPT_COOKIEJAR, "/home/luxo/cks");
 264+ curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
263265
264266 $rx = curl_exec($ch);
265267
@@ -274,8 +276,8 @@
275277 curl_setopt($ch, CURLOPT_POSTFIELDS, $postlogin);
276278 curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
277279 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
278 - curl_setopt($ch, CURLOPT_COOKIEFILE, "/home/luxo/cks");
279 - curl_setopt($ch, CURLOPT_COOKIEJAR, "/home/luxo/cks");
 280+ curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
 281+ curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
280282 $ry = curl_exec($ch);
281283 $data = unserialize($ry);
282284
Index: trunk/tools/rotatebot/rotbot.php
@@ -16,6 +16,7 @@
1717 */
1818
1919 $homedir = "/home/luxo/rotbot/";
 20+$exiftool = "/home/luxor/rotbot/exiftool/exiftool";
2021 $myLockfile = $homedir."rotatebotlock";
2122
2223 ini_set('memory_limit', '100M'); //Speicher auf 100 MBytes hochsetzen
@@ -208,7 +209,6 @@
209210 }
210211 }
211212
212 -
213213 //Benutzer prüfen! #########################################
214214 if($catcontent[$arraykey]['tmplsetter']) //autoconfirmed
215215 {
@@ -295,29 +295,29 @@
296296 }
297297
298298
299 - if(!$wrongfile) //Bild scheint OK zu sein
300 - {
301 - logfile("picture and user check finished, sorted for download");
 299+if(!$wrongfile) //Bild scheint OK zu sein
 300+{
 301+ logfile("picture and user check finished, sorted for download");
302302
303 - $catcontent[$arraykey]['title'] = str_replace(" ", "_", $picture["title"]);
304 - $catcontent[$arraykey]['degree'] = $picture["sortkey"];
305 - $catcontent[$arraykey]['since'] = $revitimestp;
306 - $catcontent[$arraykey]['pageid'] = $picture['pageid'];
307 - $catcontent[$arraykey]['url'] = $picture['imageinfo']['0']['url'];
308 - $catcontent[$arraykey]['metadata'] = $picture['imageinfo']['0']['metadata'];
309 - $catcontent[$arraykey]['uploader'] = $picture['imageinfo']['0']['user'];
310 - $catcontent[$arraykey]['upltime'] = $picture['imageinfo']['0']['timestamp'];
311 - $catcontent[$arraykey]['size'] = $picture['imageinfo']['0']['width']."x".$picture['imageinfo']['0']['height'];
312 - $catcontent[$arraykey]['exifkey'] = 0;
313 - $catcontent[$arraykey]['exifkeyafter'] = 0;
314 - $catcontent[$arraykey]['exifwriteerr'] = "";
315 - $arraykey = $arraykey +1;
316 - }
317 - else
318 - {
319 - //array löschen!
320 - $papierkorb = array_splice($catcontent,$arraykey,1);
321 - }
 303+ $catcontent[$arraykey]['title'] = str_replace(" ", "_", $picture["title"]);
 304+ $catcontent[$arraykey]['degree'] = $picture["sortkey"];
 305+ $catcontent[$arraykey]['since'] = $revitimestp;
 306+ $catcontent[$arraykey]['pageid'] = $picture['pageid'];
 307+ $catcontent[$arraykey]['url'] = $picture['imageinfo']['0']['url'];
 308+ $catcontent[$arraykey]['metadata'] = $picture['imageinfo']['0']['metadata'];
 309+ $catcontent[$arraykey]['uploader'] = $picture['imageinfo']['0']['user'];
 310+ $catcontent[$arraykey]['upltime'] = $picture['imageinfo']['0']['timestamp'];
 311+ $catcontent[$arraykey]['size'] = $picture['imageinfo']['0']['width']."x".$picture['imageinfo']['0']['height'];
 312+ $catcontent[$arraykey]['exifkey'] = 0;
 313+ $catcontent[$arraykey]['exifkeyafter'] = 0;
 314+ $catcontent[$arraykey]['exifwriteerr'] = "";
 315+ $arraykey = $arraykey +1;
 316+}
 317+else
 318+{
 319+ //array löschen!
 320+ $papierkorb = array_splice($catcontent,$arraykey,1);
 321+}
322322
323323 }
324324
@@ -363,7 +363,7 @@
364364 {
365365 //Exif auslesen
366366 // /home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation -b 1.jpg -a is to get dupe tags, too
367 - $exif = system("/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation -b -a ".$savepath.$filename.".".$arraycontent['filetype']."");
 367+ $exif = system($exiftool . " -IFD0:Orientation -b -a ".$savepath.$filename.".".$arraycontent['filetype']."");
368368 settype($exif, "integer");
369369 logfile("EXIF ist auf $exif");
370370 $arraycontent['exifkey'] = $exif; //for editsummary
@@ -421,118 +421,118 @@
422422 logfile("Bild muss um $realrotate Grad gedreht werden.");
423423 $realrotate = (360 + ($realrotate % 360)) % 360; // convert to 0-259
424424 $arraycontent['realdegree'] = $realrotate; // for editsummary
425 - }
426 - switch($realrotate)
427 - {
428 - case 0:
429 - //kopie erstellen
430 - logfile("just exif correction, picture correct");
431 - $cmd = "cp ".$savepath.$filename.".".$arraycontent['filetype']." ".$savepath.$filename."_2.".$arraycontent['filetype'];
432 - logfile($cmd);
433 - passthru($cmd);
434 - break;
435 - case 90:
436 - case 180:
437 - case 270:
438 - //rotieren ...
439 - $cmd = "jpegtran -rotate ".$realrotate." -trim -copy all ".$savepath.$filename.".".$arraycontent['filetype']." > ".$savepath.$filename."_2.".$arraycontent['filetype'];
440 - logfile($cmd);
441 - passthru($cmd,$return);
442 - logfile($arraycontent['title']." rotated by ".$realrotate."°.");
443 - break;
 425+ }
 426+ switch($realrotate)
 427+ {
 428+ case 0:
 429+ //kopie erstellen
 430+ logfile("just exif correction, picture correct");
 431+ $cmd = "cp ".$savepath.$filename.".".$arraycontent['filetype']." ".$savepath.$filename."_2.".$arraycontent['filetype'];
 432+ logfile($cmd);
 433+ passthru($cmd);
 434+ break;
 435+ case 90:
 436+ case 180:
 437+ case 270:
 438+ //rotieren ...
 439+ $cmd = "jpegtran -rotate ".$realrotate." -trim -copy all ".$savepath.$filename.".".$arraycontent['filetype']." > ".$savepath.$filename."_2.".$arraycontent['filetype'];
 440+ logfile($cmd);
 441+ passthru($cmd,$return);
 442+ logfile($arraycontent['title']." rotated by ".$realrotate."°.");
 443+ break;
444444
445 - default:
446 - logfile("Bullshit happend: realrotate was $realrotate.");
447 - $return=1004;
448 - }
 445+ default:
 446+ logfile("Bullshit happend: realrotate was $realrotate.");
 447+ $return=1004;
 448+ }
449449
450 - //escape shell nicht notwendig, keine Benutzerdaten im cmd verwendet
 450+ //escape shell nicht notwendig, keine Benutzerdaten im cmd verwendet
451451
452 - $doBruteForceClean = false; // init
 452+ $doBruteForceClean = false; // init
453453
454454 if ($return == 0 && !($exif == 0 || $exif == 1)) { // only if no error occured and change necessary
455 - //EXIF-orient-tag auf 1 stellen, nur bei jpeg
456 - // /home/luxo/rotbot/exiftool/exiftool -Orientation=1 -n 1.jpg
457 - if ($exif >= 10) { //dupe Orientation tags? Kill 'em all!
458 - // Needs to be removed because otherwise the duplicate tag stays
459 - // first attempt
460 - $cmd = "/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation= -n ".$savepath.$filename."_2.".$arraycontent['filetype'];
461 - logfile($cmd);
462 - passthru($cmd,$retexifwrite);
463 -
464 - if ($retexifwrite == 0) { // if successful
465 - logfile("No errors on EXIF-to-0");
466 - $exifwriteerr = ""; // clear - no error since it worked in first attempt
467 - } else {
468 - // second attempt (ignoring minor errors)
469 - $cmd = "/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation= -n -m ".$savepath.$filename."_2.".$arraycontent['filetype'];
 455+ //EXIF-orient-tag auf 1 stellen, nur bei jpeg
 456+ // /home/luxo/rotbot/exiftool/exiftool -Orientation=1 -n 1.jpg
 457+ if ($exif >= 10) { //dupe Orientation tags? Kill 'em all!
 458+ // Needs to be removed because otherwise the duplicate tag stays
 459+ // first attempt
 460+ $cmd = $exiftool . " -IFD0:Orientation= -n ".$savepath.$filename."_2.".$arraycontent['filetype'];
470461 logfile($cmd);
471462 passthru($cmd,$retexifwrite);
472463
473464 if ($retexifwrite == 0) { // if successful
474 - logfile("No errors on EXIF-to-0 (second try)");
475 - $exifwriteerr = " - EXIF had minor errors. Some EXIF could be lost. - ";
 465+ logfile("No errors on EXIF-to-0");
 466+ $exifwriteerr = ""; // clear - no error since it worked in first attempt
476467 } else {
477 - $doBruteForceClean = true;
 468+ // second attempt (ignoring minor errors)
 469+ $cmd = $exiftool . " -IFD0:Orientation= -n -m ".$savepath.$filename."_2.".$arraycontent['filetype'];
 470+ logfile($cmd);
 471+ passthru($cmd,$retexifwrite);
 472+
 473+ if ($retexifwrite == 0) { // if successful
 474+ logfile("No errors on EXIF-to-0 (second try)");
 475+ $exifwriteerr = " - EXIF had minor errors. Some EXIF could be lost. - ";
 476+ } else {
 477+ $doBruteForceClean = true;
 478+ }
478479 }
479 - }
480 - } else {
481 - // first attempt
482 - $cmd = "/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation=1 -n ".$savepath.$filename."_2.".$arraycontent['filetype'];
483 - logfile($cmd);
484 - passthru($cmd,$retexifwrite);
485 -
486 - if ($retexifwrite == 0) { // if successful
487 - logfile("no errors when setting EXIF to 1");
488 - $exifwriteerr = ""; // clear - no error since it worked in first attempt
489480 } else {
490 - // second attempt (ignoring minor errors)
491 - $cmd = "/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation=1 -n -m ".$savepath.$filename."_2.".$arraycontent['filetype'];
 481+ // first attempt
 482+ $cmd = $exiftool . " -IFD0:Orientation=1 -n ".$savepath.$filename."_2.".$arraycontent['filetype'];
492483 logfile($cmd);
493484 passthru($cmd,$retexifwrite);
494485
495486 if ($retexifwrite == 0) { // if successful
496 - logfile("no errors when setting EXIF to 1 (second try)");
497 - $exifwriteerr = " - EXIF had minor errors. Some EXIF could be lost. - ";
 487+ logfile("no errors when setting EXIF to 1");
 488+ $exifwriteerr = ""; // clear - no error since it worked in first attempt
498489 } else {
499 - $doBruteForceClean = true;
 490+ // second attempt (ignoring minor errors)
 491+ $cmd = $exiftool . " -IFD0:Orientation=1 -n -m ".$savepath.$filename."_2.".$arraycontent['filetype'];
 492+ logfile($cmd);
 493+ passthru($cmd,$retexifwrite);
 494+
 495+ if ($retexifwrite == 0) { // if successful
 496+ logfile("no errors when setting EXIF to 1 (second try)");
 497+ $exifwriteerr = " - EXIF had minor errors. Some EXIF could be lost. - ";
 498+ } else {
 499+ $doBruteForceClean = true;
 500+ }
500501 }
501502 }
502 - }
503503
504504
505 - if ($doBruteForceClean) {
506 - // third attempt (ignoring nearly all errors) - copy all readable tags but leave the Orientation tag away
507 - $cmd = "/home/luxo/rotbot/exiftool/exiftool -all= -tagsfromfile @ -all:all --IFD0:Orientation ".$savepath.$filename."_2.".$arraycontent['filetype'];
508 - logfile($cmd);
509 - passthru($cmd,$retexifwrite);
 505+ if ($doBruteForceClean) {
 506+ // third attempt (ignoring nearly all errors) - copy all readable tags but leave the Orientation tag away
 507+ $cmd = $exiftool . " -all= -tagsfromfile @ -all:all --IFD0:Orientation ".$savepath.$filename."_2.".$arraycontent['filetype'];
 508+ logfile($cmd);
 509+ passthru($cmd,$retexifwrite);
510510
511 - if ($retexifwrite == 0) { // if successful
512 - logfile("no errors when setting EXIF to 0 (third try)");
513 - $exifwriteerr = " - EXIF had major errors. Great parts of EXIF could be lost. - ";
514 - } else {
515 - // complete failure
516 - $return = 1005;
 511+ if ($retexifwrite == 0) { // if successful
 512+ logfile("no errors when setting EXIF to 0 (third try)");
 513+ $exifwriteerr = " - EXIF had major errors. Great parts of EXIF could be lost. - ";
 514+ } else {
 515+ // complete failure
 516+ $return = 1005;
 517+ }
517518 }
518 - }
519519
520520
521 - $arraycontent['exifwriteerr'] = $exifwriteerr; //for editsummary
 521+ $arraycontent['exifwriteerr'] = $exifwriteerr; //for editsummary
522522 }
523523
524524 if ($return == 0) { // only if no error occured
525 - //Exif auslesen als Test
526 - // /home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation -b 1.jpg -a is to get dupe tags, too
527 - $exifafter = system("/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation -b -a ".$savepath.$filename."_2.".$arraycontent['filetype']."");
528 - settype($exifafter, "integer");
529 - logfile("read EXIF after finish: $exifafter");
530 - $arraycontent['exifkeyafter'] = $exifafter; //for editsummary
 525+ //Exif auslesen als Test
 526+ // /home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation -b 1.jpg -a is to get dupe tags, too
 527+ $exifafter = system($exiftool . " -IFD0:Orientation -b -a ".$savepath.$filename."_2.".$arraycontent['filetype']."");
 528+ settype($exifafter, "integer");
 529+ logfile("read EXIF after finish: $exifafter");
 530+ $arraycontent['exifkeyafter'] = $exifafter; //for editsummary
531531
532 - if (!($exifafter == 0 || $exifafter == 1)) { // if unsuccessful
533 - $return = 1006;
 532+ if (!($exifafter == 0 || $exifafter == 1)) { // if unsuccessful
 533+ $return = 1006;
 534+ }
534535 }
535536 }
536 - }
537537 }
538538 else //Für png's und gif's
539539 {
@@ -683,9 +683,9 @@
684684 //Cache leeren
685685 foreach($catcontent2 as $filename => $arraycontent)
686686 {
687 - unlink("/home/luxo/rotbot/cache/".$filename.".".$arraycontent['filetype']);
688 - unlink("/home/luxo/rotbot/cache/".$filename."_2.".$arraycontent['filetype']);
689 - unlink("/home/luxo/rotbot/cache/".$filename."_2.".$arraycontent['filetype']."_original");
 687+ unlink($homedir . "cache/".$filename.".".$arraycontent['filetype']);
 688+ unlink($homedir . "cache/".$filename."_2.".$arraycontent['filetype']);
 689+ unlink($homedir . "cache/".$filename."_2.".$arraycontent['filetype']."_original");
690690 }
691691 logfile("cache cleared. Write log now.");
692692
@@ -869,6 +869,7 @@
870870
871871 function deleteold($content,$newab,$maxonlog,$logheader)
872872 {
 873+ global $homedir;
873874 //$maxonlog = 20; //Maximale Logfileabschnitte hier einstellen
874875
875876 $beginnat = 0;
@@ -892,9 +893,9 @@
893894 return $content;
894895
895896 //COUNTER
896 - $counter = file_get_contents("/home/luxo/rotbot/counter.txt");
 897+ $counter = file_get_contents($homedir . "counter.txt");
897898 $counter = $counter + $newab;
898 - file_put_contents("/home/luxo/rotbot/counter.txt",$counter);
 899+ file_put_contents($homedir . "counter.txt",$counter);
899900 }
900901 else
901902 {
@@ -920,9 +921,9 @@
921922 $intro = substr($content,0,$abschnittarray['1']);
922923
923924 //COUNTER
924 - $counter = file_get_contents("/home/luxo/rotbot/counter.txt");
 925+ $counter = file_get_contents($homedir . "counter.txt");
925926 $counter = $counter + $newab;
926 - file_put_contents("/home/luxo/rotbot/counter.txt",$counter);
 927+ file_put_contents($homedir . "counter.txt",$counter);
927928 logfile("new counter: $counter.");
928929
929930 $intro = sprintf($logheader."\n",$abschnitteneu,$counter); //NEU in settings definiert: der header vom Log

Status & tagging log