/** * Returns HTML of the banlog. If there were no records of the key being disabled/enabled it will * also return HTML which indicates that there were no records found. */ public function getBanLogHtml() { $html = ""; if ($this->loadNextBanLogFromMaster) { $db = ApiGate_Config::getMasterDb(); $this->loadNextBanLogFromMaster = false; } else { $db = ApiGate_Config::getSlaveDb(); } $queryString = "SELECT createdOn,action,username,reason FROM " . ApiGate::TABLE_BANLOG . " WHERE apiKey='{$this->getApiKeySqlSafe()}'"; $queryString .= " ORDER BY createdOn DESC"; if ($result = mysql_query($queryString, $db)) { if (($numRows = mysql_num_rows($result)) && $numRows > 0) { $html .= "<ul>\n"; for ($cnt = 0; $cnt < $numRows; $cnt++) { $createdOn = mysql_result($result, $cnt, "createdOn"); $action = mysql_result($result, $cnt, "action"); $username = mysql_result($result, $cnt, "username"); $reason = mysql_result($result, $cnt, "reason"); $username = $username == "" ? "<em>[no username recorded]</em>" : $username; $date = date("Y/m/d H:i:s", strtotime($createdOn)); $html .= "<li>{$date} - {$username} - <strong>{$action}</strong> - <em>{$reason}</em></li>\n"; } $html .= "</ul>\n"; } } else { $html .= ApiGate::queryError($queryString, $db, true); } if ($html == "") { $html .= i18n('apigate-keyinfo-banlog-empty'); } return $html; }
/** * Returns the result of a READ-ONLY mySQL query that only has one result (one column and one row) * * NOTE: for READ-ONLY operations */ public static function simpleQuery($queryString) { wfProfileIn(__METHOD__); $dbr = ApiGate_Config::getSlaveDb(); $retVal = ""; if ($result = mysql_query($queryString, $dbr)) { if (mysql_num_rows($result) > 0) { if ($myRow = mysql_fetch_row($result)) { $retVal = $myRow[0]; } } } else { ApiGate::queryError($queryString, $dbr); } wfProfileOut(__METHOD__); return $retVal; }