PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/rfap/index.php

https://github.com/yetanotherx/webtools
PHP | 348 lines | 307 code | 26 blank | 15 comment | 92 complexity | 6cc09a8d02a06bfcf3899b05d8024035 MD5 | raw file
  1. <?php
  2. //error_reporting(E_ALL);
  3. ini_set("display_errors", 1);
  4. $time = microtime( 1 );//Calculate time in microseconds to calculate time taken to execute
  5. include( '/home/soxred93/public_html/common/header.php' );
  6. include( '/home/soxred93/wikibot.classes.php' );
  7. include( '/home/soxred93/stats.php' );
  8. include( '/home/soxred93/public_html/common/rfalib2.php');
  9. $tool = 'RFAP';
  10. $surl = "http://toolserver.org".$_SERVER['REQUEST_URI'];
  11. if (isset($_GET['wiki']) && isset($_GET['lang']) && isset($_GET['name'])) {
  12. addStat( $tool, $surl, $_SERVER['HTTP_REFERER'], $_SERVER['HTTP_USER_AGENT'] );//Stat checking
  13. }
  14. unset($tool, $surl);
  15. //Debugging stuff
  16. //error_reporting(E_ALL);
  17. //ini_set("display_errors", 1);
  18. function pre( $array ) {
  19. echo "<pre>";
  20. print_r( $array );
  21. echo "</pre>";
  22. }
  23. //Output header
  24. echo '<div id="content">
  25. <table class="cont_table" style="width:100%;">
  26. <tr>
  27. <td class="cont_td" style="width:75%;">
  28. <h2 class="table">How did a user vote? (clone of SQL\'s tool)</h2>';
  29. //If there is a failure, do it pretty.
  30. function toDie( $msg ) {
  31. echo $msg;
  32. include( '/home/soxred93/public_html/common/footer.php' );
  33. die();
  34. }
  35. //Tell footer.php to output source
  36. /*function outputSource( $msg ) {
  37. echo "<li>
  38. <a href=\"https://svn.cluenet.org/viewvc/soxred93/trunk/bots/Tools/editsummary/index.php?view=markup\">View source</a>
  39. </li>";
  40. }*/
  41. if( !isset( $_GET['name'] ) ) {
  42. toDie( 'Welcome to the RfA Vote Calculator!<br />Kudos to SQL for the code!<br />
  43. <form action="index.php" method="get">
  44. Username: <input type="text" name="name" /><br />
  45. <input type="submit" />
  46. </form>' );
  47. }
  48. $http = new http;
  49. $wpq = new wikipediaquery;
  50. $wpapi = new wikipediaapi;
  51. $name = mysql_escape_string( ucfirst( ltrim( rtrim( $_GET['name'] ) ) ) );
  52. $oldname = $_GET['name'];
  53. $names_old = array();
  54. //Check if the user is an IP address
  55. if( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $name ) ) {
  56. toDie('Cannot be an IP.');
  57. }
  58. $wlh = $wpapi->backlinks('User:'.$oldname,500,$continue,'redirects',false);
  59. foreach($wlh as $bl) {
  60. $names_old[] = $bl['title'];
  61. }
  62. //Connect to database
  63. require_once( '/home/soxred93/database.inc' );
  64. $mysql = mysql_connect( 'enwiki-p.db.toolserver.org',$toolserver_username,$toolserver_password );
  65. @mysql_select_db( 'enwiki_p', $mysql ) or toDie( "MySQL error, please report to X! using <a href=\"http://en.wikipedia.org/wiki/User:X!/Bugs\">the bug reporter.</a> Be sure to report the following SQL error when reporting:<br /><pre>".mysql_error()."</pre>" );
  66. $tools = mysql_connect("sql",$toolserver_username,$toolserver_password);
  67. @mysql_select_db("u_soxred93", $tools) or toDie( "MySQL error, please report to X! using <a href=\"http://en.wikipedia.org/wiki/User:X!/Bugs\">the bug reporter.</a> Be sure to report the following SQL error when reporting:<br /><pre>".mysql_error()."</pre>" );
  68. unset($toolserver_username, $toolserver_password);
  69. //Done
  70. function updaterfa($title, $name) {
  71. global $wpq;
  72. $results['support']=array();
  73. $results['oppose']=array();
  74. $results['neutral']=array();
  75. $myRFA = new RFA();
  76. $title = stripslashes($title);
  77. if(isset($_GET['debug'])) { echo "title = $title\n<br />\n"; }
  78. $buffer = $wpq->getpage("Wikipedia:$title",false);
  79. $result = $myRFA->analyze($buffer);
  80. $d_support =$myRFA->support;
  81. $d_oppose = $myRFA->oppose;
  82. $d_neutral = $myRFA->neutral;
  83. foreach ( $d_support as $support ) {
  84. array_push($results['support'], $support['name'] );
  85. }
  86. foreach ( $d_neutral as $neutral ) {
  87. array_push($results['neutral'], $neutral['name'] );
  88. }
  89. foreach ( $d_oppose as $oppose ) {
  90. array_push($results['oppose'], $oppose['name'] );
  91. }
  92. return($results);
  93. }
  94. $query = "SELECT user_id,user_editcount FROM user WHERE user_name = '$name';";
  95. $result = mysql_query($query, $mysql);
  96. $uinfo = mysql_fetch_assoc($result);
  97. if($uinfo['user_id'] == "") {
  98. toDie("<br />Invalid user!<br />");
  99. }
  100. if($uinfo['user_editcount'] > 150000) {
  101. toDie("<br />For technical reasons, this tool cannot be used on users with more than 150,000 edits.<br />\n");
  102. }
  103. $query = "SELECT ug_group FROM user_groups JOIN user ON ug_user = user_id WHERE user_name = '$name' AND ug_group = 'bot';";
  104. $result = mysql_query($query, $mysql);
  105. $isbot = mysql_fetch_assoc($result);
  106. if($isbot['ug_group'] == "bot") {
  107. toDie("<br />Why would a bot comment at RFA?<br />Not wasting server time with this query.<br />");
  108. }
  109. $query = "select page_latest,page_title,COUNT(*) from revision join page on page_id = rev_page where
  110. rev_user_text = '$name' AND page_namespace = '4' AND page_title LIKE 'Requests_for_adminship/%' AND page_title NOT LIKE '%$name%' AND page_title !=
  111. 'Requests_for_adminship/RfA_and_RfB_Report' AND page_title != 'Requests_for_adminship/BAG' AND page_title NOT LIKE
  112. 'Requests_for_adminship/Nomination_cabal%' AND page_title != 'Requests_for_adminship/Front_matter' AND page_title !=
  113. 'Requests_for_adminship/RfB_bar' AND page_title NOT LIKE 'Requests_for_adminship/%/%' AND page_title != 'Requests_for_adminship/nominate' AND
  114. page_title != 'Requests_for_adminship/desysop_poll' AND page_title != 'Requests_for_adminship/Draft' AND page_title !=
  115. 'Requests_for_adminship/' AND page_title != 'Requests_for_adminship/Sample_Vote_on_sub-page_for_User:Jimbo_Wales' AND page_title != 'Requests_for_adminship/Promotion_guidelines' AND page_title != 'Wikipedia:Requests_ for_adminship/Standards' GROUP by page_title order by COUNT(*) asc;";
  116. $result = mysql_query($query, $mysql);
  117. $allrfa = 0;
  118. $rfastoupdate = array();
  119. $thisrfas = array();
  120. while ( $rfas = mysql_fetch_assoc($result) ) {
  121. $updated = 0;
  122. $allrfa++;
  123. $count = $rfas['COUNT(*)'];
  124. $title = utf8_decode($rfas['page_title']);
  125. $ts = "SELECT rev_timestamp FROM revision WHERE rev_id = '".$rfas['page_latest']."';";
  126. $resultrts = mysql_query($ts, $mysql);
  127. $rts = mysql_fetch_assoc($resultrts);
  128. $tenagos = time() - 864000;
  129. $tenago = date("YmdHis", $tenagos);
  130. array_push($thisrfas, $title);
  131. $title = mysql_real_escape_string($title);
  132. $indb = "SELECT * FROM rfap WHERE name = '$title';";
  133. $isindb = mysql_query($indb, $tools);
  134. $indb = mysql_fetch_assoc($isindb);
  135. if($indb['id'] == "" && $updated == 0) { array_push($rfastoupdate, $title); $updated = 1; }
  136. if($updated == 0) {
  137. $pullsten = $indb['pulls'] / 10;
  138. $pullsfivehund = $indb['pulls'] / 500;
  139. if($tenago < $rts['rev_timestamp'] && is_int($pullsten)) { array_push($rfastoupdate, $title); $updated = 1; }
  140. if(is_int($pullsfivehund) && $updated == 0) { array_push($rfastoupdate, $title); $updated = 1; }
  141. if($_GET['force'] == "1" && $updated == 0) { array_push($rfastoupdate, $title); $updated = 1; }
  142. if(isset($_GET['debug'])) {
  143. echo "$title - $updated<br />\n";
  144. }
  145. }
  146. }
  147. $upd = "RFAs updated this run:";
  148. $nupd = 0;
  149. foreach ($rfastoupdate as $rfatoup) {
  150. $nupd++;
  151. $title = htmlentities($rfatoup);
  152. $how = updaterfa($title, $name);
  153. $how2db = mysql_real_escape_string(serialize($how));
  154. $md5 = md5($how2db);
  155. $existq = "DELETE FROM u_soxred93.rfap WHERE name = '$rfatoup';";
  156. $existr = mysql_query($existq, $tools);
  157. $insert = "INSERT INTO u_soxred93.rfap (name , md5 , pulls , data ) VALUES ( '$rfatoup' , '$md5', '0' , '$how2db' );";
  158. $foo = mysql_query($insert, $tools);
  159. if(!$foo) toDie("ERROR: No result returned.<br />$insert");
  160. $upd .= " $title";
  161. }
  162. if($nupd == 0) { $upd .= " None!"; }
  163. $ns = 0;
  164. $no = 0;
  165. $nn = 0;
  166. $nu = 0;
  167. $name_s = stripslashes($name);
  168. $name_a = rawurldecode(preg_replace('/ /', '_', $name_s));
  169. $name_b = rawurldecode(preg_replace('/_/', ' ', $name_s));
  170. $query = "SELECT ug_group FROM user_groups JOIN user ON ug_user = user_id WHERE user_name = '$name' AND ug_group = 'bot';";
  171. $result = mysql_query($query, $mysql);
  172. $isbot = mysql_fetch_assoc($result);
  173. if(isset($_GET['debug'])) {
  174. echo "<pre>\n";
  175. echo "user = $name , user_s = $name_s , user_a = $name_a\n";
  176. print_r($thisrfas);
  177. echo "</pre>\n";
  178. }
  179. echo "<h2>Supported:</h2><ol>\n";
  180. foreach ($thisrfas as $key => $arfa) {
  181. $arfa_s = mysql_real_escape_string($arfa);
  182. $query = "SELECT * FROM rfap WHERE name = '$arfa_s';";
  183. $result = mysql_query($query, $tools);
  184. if(!$result) toDie("ERROR: No result returned.");
  185. $rfad = mysql_fetch_assoc($result);
  186. $data = unserialize(stripslashes($rfad['data']));
  187. $views = $rfad['pulls'];
  188. foreach($data['support'] as $od) {
  189. $od = ucfirst($od);
  190. if( preg_match( '/(.*)\#.*/' , $od , $matchme ) > 0 ) { $od = $matchme[1];} //A fix just for keeper :)
  191. if($od == $name_s || $od == $name_a || $od == $name_b || in_array('User:'.$od, $names_old)) {
  192. $stripped_arfa = preg_replace("/Requests_for_adminship\//i", "" ,$arfa);
  193. if(isset($_GET['debug'])) { $viewout = " (Views: $views|Key: $key)"; } else { $viewout = ""; }
  194. echo "<li><a href = \"http://en.wikipedia.org/wiki/Wikipedia:$arfa\">$stripped_arfa</a>$viewout</li>\n";
  195. $pid = $rfad['id'];
  196. $pulls = $rfad['pulls'];
  197. $pullsnew = $pulls + 1;
  198. $ud = "UPDATE rfap SET pulls = '$pullsnew' WHERE id = '$pid';";
  199. $udr = mysql_query($ud, $tools);
  200. if(!$udr) toDie("ERROR: No result returned.");
  201. unset($thisrfas[$key]);
  202. $ns++;
  203. }
  204. }
  205. }
  206. if(isset($_GET['debug'])) {
  207. echo "<pre>\n";
  208. print_r($thisrfas);
  209. echo "</pre>\n";
  210. }
  211. echo "</ol><h2>Neutral:</h2><ol>\n";
  212. foreach ($thisrfas as $key => $arfa) {
  213. $arfa_s = mysql_real_escape_string($arfa);
  214. $query = "SELECT * FROM rfap WHERE name = '$arfa_s';";
  215. $result = mysql_query($query, $tools);
  216. if(!$result) toDie("ERROR: No result returned.");
  217. $rfad = mysql_fetch_assoc($result);
  218. $data = unserialize(stripslashes($rfad['data']));
  219. $views = $rfad['pulls'];
  220. foreach($data['neutral'] as $od) {
  221. $od = ucfirst($od);
  222. if( preg_match( '/(.*)\#.*/' , $od , $matchme ) > 0 ) { $od = $matchme[1]; } //A fix just for keeper :)
  223. if($od == $name_s || $od == $name_a || $od == $name_b || in_array('User:'.$od, $names_old)) {
  224. $stripped_arfa = preg_replace("/Requests_for_adminship\//i", "" ,$arfa);
  225. if(isset($_GET['debug'])) { $viewout = " (Views: $views|Key: $key)"; } else { $viewout = ""; }
  226. echo "<li><a href = \"http://en.wikipedia.org/wiki/Wikipedia:$arfa\">$stripped_arfa</a>$viewout</li>\n";
  227. $pid = $rfad['id'];
  228. $pulls = $rfad['pulls'];
  229. $pullsnew = $pulls + 1;
  230. $ud = "UPDATE rfap SET pulls = '$pullsnew' WHERE id = '$pid';";
  231. $udr = mysql_query($ud, $tools);
  232. if(!$udr) toDie("ERROR: No result returned.");
  233. unset($thisrfas[$key]);
  234. $nn++;
  235. }
  236. }
  237. }
  238. if(isset($_GET['debug'])) {
  239. echo "<pre>\n";
  240. print_r($thisrfas);
  241. echo "</pre>\n";
  242. }
  243. echo "</ol><h2>Opposed:</h2><ol>\n";
  244. foreach ($thisrfas as $key => $arfa) {
  245. $arfa_s = mysql_real_escape_string($arfa);
  246. $query = "SELECT * FROM rfap WHERE name = '$arfa_s';";
  247. $result = mysql_query($query, $tools);
  248. if(!$result) toDie("ERROR: No result returned.");
  249. $rfad = mysql_fetch_assoc($result);
  250. $data = unserialize(stripslashes($rfad['data']));
  251. $views = $rfad['pulls'];
  252. foreach($data['oppose'] as $od) {
  253. $od = ucfirst($od);
  254. if( preg_match( '/(.*)\#.*/' , $od , $matchme ) > 0 ) { $od = $matchme[1]; } //A fix just for keeper :)
  255. if($od == $name_s || $od == $name_a || $od == $name_b || in_array('User:'.$od, $names_old)) {
  256. $stripped_arfa = preg_replace("/Requests_for_adminship\//i", "" ,$arfa);
  257. if(isset($_GET['debug'])) { $viewout = " (Views: $views|Key: $key)"; } else { $viewout = ""; }
  258. echo "<li><a href = \"http://en.wikipedia.org/wiki/Wikipedia:$arfa\">$stripped_arfa</a>$viewout</li>\n";
  259. $pid = $rfad['id'];
  260. $pulls = $rfad['pulls'];
  261. $pullsnew = $pulls + 1;
  262. $ud = "UPDATE rfap SET pulls = '$pullsnew' WHERE id = '$pid';";
  263. $udr = mysql_query($ud, $tools);
  264. if(!$udr) toDie("ERROR: No result returned.");
  265. unset($thisrfas[$key]);
  266. $no++;
  267. }
  268. }
  269. }
  270. if(isset($_GET['debug'])) {
  271. echo "<pre>\n";
  272. print_r($thisrfas);
  273. echo "</pre>\n";
  274. }
  275. echo "</ol><h2>Did not comment / Could not parse:</h2><ol>\n";
  276. foreach ($thisrfas as $key => $arfa) {
  277. $arfa_s = mysql_real_escape_string($arfa);
  278. $query = "SELECT * FROM rfap WHERE name = '$arfa_s';";
  279. $result = mysql_query($query, $tools);
  280. if(!$result) toDie("ERROR: No result returned.");
  281. $rfad = mysql_fetch_assoc($result);
  282. $stripped_arfa = preg_replace("/Requests_for_adminship\//i", "" ,$arfa);
  283. $views = $rfad['pulls'];
  284. if(isset($_GET['debug'])) { $viewout = " (Views: $views|Key: $key)"; } else { $viewout = ""; }
  285. echo "<li><a href = \"http://en.wikipedia.org/wiki/Wikipedia:$arfa\">$stripped_arfa</a>$viewout</li>\n";
  286. $pid = $rfad['id'];
  287. $pulls = $rfad['pulls'];
  288. $pullsnew = $pulls + 1;
  289. $ud = "UPDATE rfap SET pulls = '$pullsnew' WHERE id = '$pid';";
  290. $udr = mysql_query($ud, $tools);
  291. if(!$udr) toDie("ERROR: No result returned.");
  292. $nu++;
  293. }
  294. echo "</ol>\n";
  295. $ar = $ns + $nn + $no;
  296. if($ns > 0) {
  297. $sp = round($ns / $ar, 3) * 100;
  298. } else {
  299. $sp = 0;
  300. }
  301. if($nn > 0) {
  302. $np = round($nn / $ar, 3) * 100;
  303. } else {
  304. $np = 0;
  305. }
  306. if($no > 0) {
  307. $op = round($no / $ar, 3) * 100;
  308. } else {
  309. $op = 0;
  310. }
  311. echo "<br />$name has edited $allrfa RFA's! (Supported: $ns [$sp%], Neutral: $nn [$np%], Opposed: $no [$op%], Unknown $nu)<br />\n<small><center>$upd</small></center>\n";
  312. //Calculate time taken to execute
  313. $exectime = microtime( 1 ) - $time;
  314. echo "<br /><hr><span style=\"font-size:100%;\">Executed in $exectime seconds.</span>";
  315. echo "<br />Taken ".(memory_get_usage() / (1024 * 1024))." megabytes of memory to execute.";
  316. //Output footer
  317. include( '/home/soxred93/public_html/common/footer.php' );
  318. ?>