r106361 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106360‎ | r106361 | r106362 >
Date:19:53, 15 December 2011
Author:reedy
Status:ok
Tags:
Comment:
Variablise database name

Fixup my left fixme
Modified paths:
  • /trunk/tools/rotatebot/login.php (modified) (history)
  • /trunk/tools/rotatebot/rotbot.php (modified) (history)
  • /trunk/tools/rotatebot/settings.php (modified) (history)
  • /trunk/tools/rotatebot/upload.php (modified) (history)

Diff [purge]

Index: trunk/tools/rotatebot/rotbot.php
@@ -19,7 +19,7 @@
2020 $myLockfile = $homedir."rotatebotlock";
2121
2222 ini_set('memory_limit', '100M'); //Speicher auf 100 MBytes hochsetzen
23 -ini_set('user_agent', ' User:Rotatebot by Luxo on the Toolserver / PHP');
 23+ini_set('user_agent', $useragent);
2424
2525
2626 logfile("Starte Bot!");
@@ -55,7 +55,6 @@
5656 logfile("Verbinde zur Datenbank!");
5757
5858 $myslink = mysql_connect($databanknames, $userloginname, $databasepw) or suicide ("Can't connect to MySQL");
59 -$database = "commonswiki_p";
6059 mysql_select_db($database, $myslink)
6160 or suicide ("Konnte $database nicht öffnen: ".mysql_error());
6261 //Datenbank verbunden
@@ -217,7 +216,7 @@
218217 //Datenbank abfragen nach status
219218 if(!$cachedbar["$wgAuthor"])
220219 {
221 - $mysresult = mysql_query( "SELECT * FROM user WHERE user_name='".mysql_real_escape_string($wgAuthor)."'") or suicide("MySQL error");
 220+ $mysresult = mysql_query( "SELECT * FROM user WHERE user_name='".mysql_real_escape_string($wgAuthor)."'", $myslink) or suicide("MySQL error");
222221 $a_row = mysql_fetch_row($mysresult);
223222 $cachedbar[$wgAuthor] = $a_row;
224223 }
@@ -689,7 +688,7 @@
690689
691690 //##################### LOG LOG LOG LOG LOG LOG LOG #########################
692691
693 -$logfilew = file_get_contents("http://commons.wikimedia.org/w/index.php?title=User:Rotatebot/Log&action=raw");
 692+$logfilew = file_get_contents("http://commons.wikimedia.org/w/index.php?title=User:$username/Log&action=raw");
694693 $somanyrot = count($catcontent2);
695694
696695 $logfilew = deleteold($logfilew,$somanyrot,$config['logfilesize'],$config['logheader']);
@@ -769,7 +768,7 @@
770769 $msgerr = ", ".count($wrongfiles)." errors";
771770 }
772771
773 - wikiedit("commons.wikimedia.org","User:Rotatebot/Log",$logfilew,"Bot: $somanyrot images rotated".$msgerr.".","1");
 772+ wikiedit("commons.wikimedia.org","User:$username/Log",$logfilew,"Bot: $somanyrot images rotated".$msgerr.".","1");
774773 }
775774
776775 mysql_close($myslink); // TODO should/can this be moved to function suicide? - Probably not due to line 33.
@@ -936,13 +935,15 @@
937936
938937 function botsetup()
939938 {
940 - $setupraw = file("http://commons.wikimedia.org/w/index.php?title=User:Rotatebot/config.js&action=raw");
 939+ global $username;
 940+ $setupraw = file("http://commons.wikimedia.org/w/index.php?title=User:$username/config.js&action=raw");
941941
 942+ $array = array();
942943 foreach($setupraw as $line)
943944 {
944945 $line = trim($line);
945946
946 - if(substr($line,0,2) != "//" AND $line != "")
 947+ if(substr($line,0,2) != "//" && $line != "")
947948 {
948949
949950 $gleich = strpos($line, "=");
@@ -956,12 +957,12 @@
957958 //falls vorhanden "" entfernen
958959 if(substr($content, 0, 1) == '"')
959960 {
960 - $content = substr($content, 1);
 961+ $content = substr($content, 1);
961962 }
962963
963964 if(substr($content, -1) == '"')
964965 {
965 - $content = substr($content, 0, -1);
 966+ $content = substr($content, 0, -1);
966967 }
967968
968969 $content = trim($content);
Index: trunk/tools/rotatebot/settings.php
@@ -3,10 +3,13 @@
44 $homedir = "/home/luxo/rotbot/";
55 $cookies = "/home/lux/cks";
66 $exiftool = "/home/luxor/rotbot/exiftool/exiftool";
7 -$useragent = "Luxo (Toolserver; php) luxo@ts.wikimedia.org";
 7+$useragent = "Luxo (Toolserver; php) luxo@ts.wikimedia.org"; // ' User:Rotatebot by Luxo on the Toolserver / PHP'
88
99 $databanknames = ""; // server
 10+$database = ""; // database name
1011
1112 $userloginname = ""; // database username
1213 $databasepw = ""; // database password
1314
 15+$username = ""; // Bot username
 16+$password = ""; // Bot password
Index: trunk/tools/rotatebot/upload.php
@@ -30,8 +30,7 @@
3131 //$cookies
3232 if(!$cookies["commonswikiUserName"] || !$cookies["commonswikiUserID"])
3333 {
34 - $username = "Rotatebot";
35 - $password = "**removed**";
 34+ global $username, $password;
3635
3736 logfile("Login to $project!\n");
3837 wikilogin($username,$password,$project,$useragent);
Index: trunk/tools/rotatebot/login.php
@@ -23,15 +23,15 @@
2424 // ############### EDIT WIKIPEDIA - FUNCTION ###############
2525 function wikiedit($project,$page,$newtext,$description,$minor)
2626 {
27 - global $cookies, $useragent;
 27+ global $cookies, $useragent, $username;
2828 logfile("Funktion gestartet...");
2929 logfile("Schreibe Text am ".date("r",time())." in die Seite '$page'.");
3030
3131 //$cookies
3232 if(!$cookies["commonswikiUserName"] || !$cookies["commonswikiUserID"])
3333 {
34 - $username = "Rotatebot";
35 - $password = "**removed**";
 34+ global $password;
 35+
3636 logfile("Login to $project!\n");
3737 wikilogin($username,$password,$project,$useragent);
3838 logfile("logged in to $project!\n");
@@ -87,8 +87,7 @@
8888 //auf cookie prüfen
8989 if(substr($linex,0,11) == "Set-Cookie:")
9090 {
91 - // FIXME: $line is undefined
92 - $rawcookie = substr($line,11,strpos($line,";")-11); //Format: session=DFJ3ASD2S
 91+ $rawcookie = substr($linex,11,strpos($linex,";")-11); //Format: session=DFJ3ASD2S
9392 $cookiename = trim(substr($rawcookie,0,strpos($rawcookie,"=")));
9493 $cookies[$cookiename] = $rawcookie;
9594 }
@@ -139,7 +138,7 @@
140139 }
141140 logfile("Seite geladen, Anmeldung prüfen.");
142141
143 - if(strstr($bodyy,'"wgUserName": "Rotatebot",'))
 142+ if(strstr($bodyy,'"wgUserName": "' . $username . '",'))
144143 {
145144 logfile("Anmeldung erfolgreich!");
146145

Status & tagging log