https://www.mediawiki.org/wiki/Special:Code/MediaWiki/106324

Revision: 106324
Author:   reedy
Date:     2011-12-15 14:21:18 +0000 (Thu, 15 Dec 2011)
Log Message:
-----------
Variablise commonly used paths

Fix some indenting

Modified Paths:
--------------
    trunk/tools/rotatebot/login.php
    trunk/tools/rotatebot/rotbot.php
    trunk/tools/rotatebot/upload.php

Modified: trunk/tools/rotatebot/login.php
===================================================================
--- trunk/tools/rotatebot/login.php     2011-12-15 14:17:58 UTC (rev 106323)
+++ trunk/tools/rotatebot/login.php     2011-12-15 14:21:18 UTC (rev 106324)
@@ -18,6 +18,7 @@
 
        */
 
+$cookies = "/home/lux/cks";
 
 // ############### EDIT WIKIPEDIA - FUNCTION ###############
 function wikiedit($project,$page,$newtext,$description,$minor)
@@ -252,13 +253,14 @@
 
        $postlogin = 
"lgname=".urlencode($username)."&lgpassword=".urlencode($password)."&format=php";
 
+       global $cookies;
        if(!$useragent) { $useragent = "Luxo (Toolserver; php) 
[email protected]";  }
        $ch = curl_init($project.$getrequest);
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postlogin);
        curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-       curl_setopt($ch, CURLOPT_COOKIEJAR, "/home/luxo/cks");
+       curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
 
        $rx = curl_exec($ch);
 
@@ -274,8 +276,8 @@
                curl_setopt($ch, CURLOPT_POSTFIELDS, $postlogin);
                curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-               curl_setopt($ch, CURLOPT_COOKIEFILE, "/home/luxo/cks");
-               curl_setopt($ch, CURLOPT_COOKIEJAR, "/home/luxo/cks");
+               curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
+               curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
                $ry = curl_exec($ch);
                $data = unserialize($ry);
 

Modified: trunk/tools/rotatebot/rotbot.php
===================================================================
--- trunk/tools/rotatebot/rotbot.php    2011-12-15 14:17:58 UTC (rev 106323)
+++ trunk/tools/rotatebot/rotbot.php    2011-12-15 14:21:18 UTC (rev 106324)
@@ -16,6 +16,7 @@
  */
 
 $homedir = "/home/luxo/rotbot/";
+$exiftool = "/home/luxor/rotbot/exiftool/exiftool";
 $myLockfile = $homedir."rotatebotlock";
 
 ini_set('memory_limit', '100M'); //Speicher auf 100 MBytes hochsetzen
@@ -208,7 +209,6 @@
 }
 }
 
-
 //Benutzer prüfen! #########################################
 if($catcontent[$arraykey]['tmplsetter']) //autoconfirmed
 {
@@ -295,29 +295,29 @@
 }
 
 
-       if(!$wrongfile) //Bild scheint OK zu sein
-       {
-               logfile("picture and user check finished, sorted for download");
+if(!$wrongfile) //Bild scheint OK zu sein
+{
+       logfile("picture and user check finished, sorted for download");
 
-               $catcontent[$arraykey]['title']    = str_replace(" ", "_", 
$picture["title"]);
-               $catcontent[$arraykey]['degree']   = $picture["sortkey"];
-               $catcontent[$arraykey]['since']    = $revitimestp;
-               $catcontent[$arraykey]['pageid']   = $picture['pageid'];
-               $catcontent[$arraykey]['url']      = 
$picture['imageinfo']['0']['url'];
-               $catcontent[$arraykey]['metadata']     = 
$picture['imageinfo']['0']['metadata'];
-               $catcontent[$arraykey]['uploader'] = 
$picture['imageinfo']['0']['user'];
-               $catcontent[$arraykey]['upltime']  = 
$picture['imageinfo']['0']['timestamp'];
-               $catcontent[$arraykey]['size']     = 
$picture['imageinfo']['0']['width']."x".$picture['imageinfo']['0']['height'];
-               $catcontent[$arraykey]['exifkey']  = 0;
-               $catcontent[$arraykey]['exifkeyafter']  = 0;
-               $catcontent[$arraykey]['exifwriteerr']  = "";
-               $arraykey = $arraykey +1;
-       }
-       else
-       {
-               //array löschen!
-               $papierkorb = array_splice($catcontent,$arraykey,1);
-       }
+       $catcontent[$arraykey]['title']    = str_replace(" ", "_", 
$picture["title"]);
+       $catcontent[$arraykey]['degree']   = $picture["sortkey"];
+       $catcontent[$arraykey]['since']    = $revitimestp;
+       $catcontent[$arraykey]['pageid']   = $picture['pageid'];
+       $catcontent[$arraykey]['url']      = $picture['imageinfo']['0']['url'];
+       $catcontent[$arraykey]['metadata']     = 
$picture['imageinfo']['0']['metadata'];
+       $catcontent[$arraykey]['uploader'] = $picture['imageinfo']['0']['user'];
+       $catcontent[$arraykey]['upltime']  = 
$picture['imageinfo']['0']['timestamp'];
+       $catcontent[$arraykey]['size']     = 
$picture['imageinfo']['0']['width']."x".$picture['imageinfo']['0']['height'];
+       $catcontent[$arraykey]['exifkey']  = 0;
+       $catcontent[$arraykey]['exifkeyafter']  = 0;
+       $catcontent[$arraykey]['exifwriteerr']  = "";
+       $arraykey = $arraykey +1;
+}
+else
+{
+       //array löschen!
+       $papierkorb = array_splice($catcontent,$arraykey,1);
+}
 
 }
 
@@ -363,7 +363,7 @@
        {
                 //Exif auslesen
                 // /home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation -b 
1.jpg     -a is to get dupe tags, too
-                $exif = system("/home/luxo/rotbot/exiftool/exiftool 
-IFD0:Orientation -b -a ".$savepath.$filename.".".$arraycontent['filetype']."");
+                $exif = system($exiftool . " -IFD0:Orientation -b -a 
".$savepath.$filename.".".$arraycontent['filetype']."");
                 settype($exif, "integer");
                 logfile("EXIF ist auf $exif");
                 $arraycontent['exifkey'] = $exif; //for editsummary
@@ -421,118 +421,118 @@
                        logfile("Bild muss um $realrotate Grad gedreht 
werden.");
                        $realrotate = (360 + ($realrotate % 360)) % 360;    // 
convert to 0-259
                        $arraycontent['realdegree'] = $realrotate;  //    for 
editsummary
-                       }
-                               switch($realrotate)
-                               {
-                                       case 0:
-                                               //kopie erstellen
-                                               logfile("just exif correction, 
picture correct");
-                                               $cmd = "cp 
".$savepath.$filename.".".$arraycontent['filetype']." 
".$savepath.$filename."_2.".$arraycontent['filetype'];
-                                               logfile($cmd);
-                                               passthru($cmd);
-                                               break;
-                                       case 90:
-                                       case 180:
-                                       case 270:
-                                               //rotieren ...
-                                               $cmd = "jpegtran -rotate 
".$realrotate." -trim -copy all 
".$savepath.$filename.".".$arraycontent['filetype']." > 
".$savepath.$filename."_2.".$arraycontent['filetype'];
-                                               logfile($cmd);
-                                               passthru($cmd,$return);
-                                               
logfile($arraycontent['title']." rotated by ".$realrotate."°.");
-                                               break;
+               }
+               switch($realrotate)
+               {
+                       case 0:
+                               //kopie erstellen
+                               logfile("just exif correction, picture 
correct");
+                               $cmd = "cp 
".$savepath.$filename.".".$arraycontent['filetype']." 
".$savepath.$filename."_2.".$arraycontent['filetype'];
+                               logfile($cmd);
+                               passthru($cmd);
+                               break;
+                       case 90:
+                       case 180:
+                       case 270:
+                               //rotieren ...
+                               $cmd = "jpegtran -rotate ".$realrotate." -trim 
-copy all ".$savepath.$filename.".".$arraycontent['filetype']." > 
".$savepath.$filename."_2.".$arraycontent['filetype'];
+                               logfile($cmd);
+                               passthru($cmd,$return);
+                               logfile($arraycontent['title']." rotated by 
".$realrotate."°.");
+                               break;
 
-                                       default:
-                                               logfile("Bullshit happend: 
realrotate was $realrotate.");
-                                               $return=1004;
-                               }
+                       default:
+                               logfile("Bullshit happend: realrotate was 
$realrotate.");
+                               $return=1004;
+               }
 
-       //escape shell nicht notwendig, keine Benutzerdaten im cmd verwendet
+                       //escape shell nicht notwendig, keine Benutzerdaten im 
cmd verwendet
 
-               $doBruteForceClean = false; // init
+                       $doBruteForceClean = false; // init
 
                        if ($return == 0 && !($exif == 0 || $exif == 1)) { // 
only if no error occured and change necessary
-                               //EXIF-orient-tag auf 1 stellen, nur bei jpeg
-                               // /home/luxo/rotbot/exiftool/exiftool 
-Orientation=1 -n  1.jpg
-                       if ($exif >= 10) {  //dupe Orientation tags?   Kill 'em 
all!
-                                               // Needs to be removed because 
otherwise the duplicate tag stays
-                               // first attempt
-                               $cmd = "/home/luxo/rotbot/exiftool/exiftool 
-IFD0:Orientation= -n  ".$savepath.$filename."_2.".$arraycontent['filetype'];
-                               logfile($cmd);
-                               passthru($cmd,$retexifwrite);
-
-                               if ($retexifwrite == 0) {  // if successful
-                                       logfile("No errors on EXIF-to-0");
-                                       $exifwriteerr = ""; // clear - no error 
since it worked in first attempt
-                               } else {
-                                       // second attempt (ignoring minor 
errors)
-                                       $cmd = 
"/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation= -n -m  
".$savepath.$filename."_2.".$arraycontent['filetype'];
+                                       //EXIF-orient-tag auf 1 stellen, nur 
bei jpeg
+                                       // /home/luxo/rotbot/exiftool/exiftool 
-Orientation=1 -n  1.jpg
+                               if ($exif >= 10) {  //dupe Orientation tags?   
Kill 'em all!
+                                                       // Needs to be removed 
because otherwise the duplicate tag stays
+                                       // first attempt
+                                       $cmd = $exiftool . " -IFD0:Orientation= 
-n  ".$savepath.$filename."_2.".$arraycontent['filetype'];
                                        logfile($cmd);
                                        passthru($cmd,$retexifwrite);
 
                                        if ($retexifwrite == 0) {  // if 
successful
-                                               logfile("No errors on EXIF-to-0 
(second try)");
-                                               $exifwriteerr = " - EXIF had 
minor errors. Some EXIF could be lost. - ";
+                                               logfile("No errors on 
EXIF-to-0");
+                                               $exifwriteerr = ""; // clear - 
no error since it worked in first attempt
                                        } else {
-                                               $doBruteForceClean = true;
+                                               // second attempt (ignoring 
minor errors)
+                                               $cmd = $exiftool . " 
-IFD0:Orientation= -n -m  ".$savepath.$filename."_2.".$arraycontent['filetype'];
+                                               logfile($cmd);
+                                               passthru($cmd,$retexifwrite);
+
+                                               if ($retexifwrite == 0) {  // 
if successful
+                                                       logfile("No errors on 
EXIF-to-0 (second try)");
+                                                       $exifwriteerr = " - 
EXIF had minor errors. Some EXIF could be lost. - ";
+                                               } else {
+                                                       $doBruteForceClean = 
true;
+                                               }
                                        }
-                               }
-                       } else {
-                               // first attempt
-                               $cmd = "/home/luxo/rotbot/exiftool/exiftool 
-IFD0:Orientation=1 -n  ".$savepath.$filename."_2.".$arraycontent['filetype'];
-                               logfile($cmd);
-                               passthru($cmd,$retexifwrite);
-
-                               if ($retexifwrite == 0) {  // if successful
-                                       logfile("no errors when setting EXIF to 
1");
-                                       $exifwriteerr = ""; // clear - no error 
since it worked in first attempt
                                } else {
-                                       // second attempt (ignoring minor 
errors)
-                                       $cmd = 
"/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation=1 -n -m  
".$savepath.$filename."_2.".$arraycontent['filetype'];
+                                       // first attempt
+                                       $cmd = $exiftool . " 
-IFD0:Orientation=1 -n  ".$savepath.$filename."_2.".$arraycontent['filetype'];
                                        logfile($cmd);
                                        passthru($cmd,$retexifwrite);
 
                                        if ($retexifwrite == 0) {  // if 
successful
-                                               logfile("no errors when setting 
EXIF to 1 (second try)");
-                                               $exifwriteerr = " - EXIF had 
minor errors. Some EXIF could be lost. - ";
+                                               logfile("no errors when setting 
EXIF to 1");
+                                               $exifwriteerr = ""; // clear - 
no error since it worked in first attempt
                                        } else {
-                                               $doBruteForceClean = true;
+                                               // second attempt (ignoring 
minor errors)
+                                               $cmd = $exiftool . " 
-IFD0:Orientation=1 -n -m  
".$savepath.$filename."_2.".$arraycontent['filetype'];
+                                               logfile($cmd);
+                                               passthru($cmd,$retexifwrite);
+
+                                               if ($retexifwrite == 0) {  // 
if successful
+                                                       logfile("no errors when 
setting EXIF to 1 (second try)");
+                                                       $exifwriteerr = " - 
EXIF had minor errors. Some EXIF could be lost. - ";
+                                               } else {
+                                                       $doBruteForceClean = 
true;
+                                               }
                                        }
                                }
-                       }
 
 
-                       if ($doBruteForceClean) {
-                               // third attempt (ignoring nearly all errors)  
- copy all readable tags but leave the Orientation tag away
-                               $cmd = "/home/luxo/rotbot/exiftool/exiftool 
-all= -tagsfromfile @ -all:all --IFD0:Orientation 
".$savepath.$filename."_2.".$arraycontent['filetype'];
-                               logfile($cmd);
-                               passthru($cmd,$retexifwrite);
+                               if ($doBruteForceClean) {
+                                       // third attempt (ignoring nearly all 
errors)  - copy all readable tags but leave the Orientation tag away
+                                       $cmd = $exiftool . " -all= 
-tagsfromfile @ -all:all --IFD0:Orientation 
".$savepath.$filename."_2.".$arraycontent['filetype'];
+                                       logfile($cmd);
+                                       passthru($cmd,$retexifwrite);
 
-                               if ($retexifwrite == 0) {  // if successful
-                                       logfile("no errors when setting EXIF to 
0 (third try)");
-                                       $exifwriteerr = " - EXIF had major 
errors. Great parts of EXIF could be lost. - ";
-                               } else {
-                                       // complete failure
-                                       $return = 1005;
+                                       if ($retexifwrite == 0) {  // if 
successful
+                                               logfile("no errors when setting 
EXIF to 0 (third try)");
+                                               $exifwriteerr = " - EXIF had 
major errors. Great parts of EXIF could be lost. - ";
+                                       } else {
+                                               // complete failure
+                                               $return = 1005;
+                                       }
                                }
-                       }
 
 
-                       $arraycontent['exifwriteerr'] = $exifwriteerr; //for 
editsummary
+                               $arraycontent['exifwriteerr'] = $exifwriteerr; 
//for editsummary
                        }
 
                        if ($return == 0) { // only if no error occured
-                       //Exif auslesen als Test
-                       // /home/luxo/rotbot/exiftool/exiftool 
-IFD0:Orientation -b 1.jpg    -a is to get dupe tags, too
-                       $exifafter = 
system("/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation -b -a 
".$savepath.$filename."_2.".$arraycontent['filetype']."");
-                       settype($exifafter, "integer");
-                       logfile("read EXIF after finish: $exifafter");
-                       $arraycontent['exifkeyafter'] = $exifafter; //for 
editsummary
+                               //Exif auslesen als Test
+                               // /home/luxo/rotbot/exiftool/exiftool 
-IFD0:Orientation -b 1.jpg    -a is to get dupe tags, too
+                               $exifafter = system($exiftool . " 
-IFD0:Orientation -b -a 
".$savepath.$filename."_2.".$arraycontent['filetype']."");
+                               settype($exifafter, "integer");
+                               logfile("read EXIF after finish: $exifafter");
+                               $arraycontent['exifkeyafter'] = $exifafter; 
//for editsummary
 
-                       if (!($exifafter == 0 || $exifafter == 1)) {  // if 
unsuccessful
-                               $return = 1006;
+                               if (!($exifafter == 0 || $exifafter == 1)) {  
// if unsuccessful
+                                       $return = 1006;
+                               }
                        }
                }
-               }
        }
        else //Für png's und gif's
        {
@@ -683,9 +683,9 @@
 //Cache leeren
 foreach($catcontent2 as $filename => $arraycontent)
 {
-       
unlink("/home/luxo/rotbot/cache/".$filename.".".$arraycontent['filetype']);
-       
unlink("/home/luxo/rotbot/cache/".$filename."_2.".$arraycontent['filetype']);
-       
unlink("/home/luxo/rotbot/cache/".$filename."_2.".$arraycontent['filetype']."_original");
+       unlink($homedir . "cache/".$filename.".".$arraycontent['filetype']);
+       unlink($homedir . "cache/".$filename."_2.".$arraycontent['filetype']);
+       unlink($homedir . 
"cache/".$filename."_2.".$arraycontent['filetype']."_original");
 }
 logfile("cache cleared. Write log now.");
 
@@ -869,6 +869,7 @@
 
 function deleteold($content,$newab,$maxonlog,$logheader)
 {
+       global $homedir;
        //$maxonlog = 20; //Maximale Logfileabschnitte hier einstellen
 
        $beginnat = 0;
@@ -892,9 +893,9 @@
                return $content;
 
                //COUNTER
-               $counter = file_get_contents("/home/luxo/rotbot/counter.txt");
+               $counter = file_get_contents($homedir . "counter.txt");
                $counter = $counter + $newab;
-               file_put_contents("/home/luxo/rotbot/counter.txt",$counter);
+               file_put_contents($homedir . "counter.txt",$counter);
        }
        else
        {
@@ -920,9 +921,9 @@
                $intro = substr($content,0,$abschnittarray['1']);
 
                //COUNTER
-               $counter = file_get_contents("/home/luxo/rotbot/counter.txt");
+               $counter = file_get_contents($homedir . "counter.txt");
                $counter = $counter + $newab;
-               file_put_contents("/home/luxo/rotbot/counter.txt",$counter);
+               file_put_contents($homedir . "counter.txt",$counter);
                logfile("new counter: $counter.");
 
                $intro = sprintf($logheader."\n",$abschnitteneu,$counter); 
//NEU in settings definiert: der header vom Log

Modified: trunk/tools/rotatebot/upload.php
===================================================================
--- trunk/tools/rotatebot/upload.php    2011-12-15 14:17:58 UTC (rev 106323)
+++ trunk/tools/rotatebot/upload.php    2011-12-15 14:21:18 UTC (rev 106324)
@@ -18,6 +18,8 @@
 
 wikiupload("commons.wikimedia.org","test2.jpg","Test for 
Rotatebot.jpg","",$descri);*/
 
+$homedir = "/home/luxo/rotbot/";
+
 // ############### EDIT WIKIPEDIA - FUNCTION ###############
 function wikiupload($project,$filename_local,$filename_wiki,$license,$desc)
 {
@@ -70,7 +72,8 @@
 
 function wiki_upload_file 
($filename_local,$filename_wiki,$license,$desc,$wiki,$cookies)
 {
-       $file1 = file_get_contents("/home/luxo/rotbot/cache/".$filename_local) 
or die("Fehler - Datei nicht gefunden! ($filename_local)");
+       global $homedir;
+       $file1 = file_get_contents($homedir . "cache/".$filename_local) or 
die("Fehler - Datei nicht gefunden! ($filename_local)");
 
        $data_l = array("file.file" => $file1,
        "wpDestFile" => $filename_wiki,
@@ -142,6 +145,7 @@
                $res .= fread($fp, 1);
        }
        fclose($fp);
-       file_put_contents("/home/luxo/rotbot/cache/log.txt",$res);
+       global $homedir;
+       file_put_contents( $homedir . "cache/log.txt",$res);
        return $res;
 }


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to