/** * @covers MWDebug::deprecated */ public function testAvoidNonConsecutivesDuplicateDeprecations() { MWDebug::deprecated('wfOldFunction', '1.0', 'component'); MWDebug::warning('some warning'); MWDebug::log('we could have logged something too'); // Another deprecation MWDebug::deprecated('wfOldFunction', '1.0', 'component'); // assertCount() not available on WMF integration server $this->assertEquals(3, count(MWDebug::getLog()), "Only one deprecated warning per function should be kept"); }
/** * Acquire a Redis connection. * * @access protected * @param string [Optiona] Server group key. * Example: 'cache' would look up $wgRedisServers['cached'] * Default: Uses the first index of $wgRedisServers. * @param array [Optional] Additional options, will merge and overwrite default options. * - connectTimeout : The timeout for new connections, in seconds. * Optional, default is 1 second. * - persistent : Set this to true to allow connections to persist across * multiple web requests. False by default. * - password : The authentication password, will be sent to Redis in clear text. * Optional, if it is unspecified, no AUTH command will be sent. * - serializer : Set to "php", "igbinary", or "none". Default is "php". * @param boolean [Optional] Force a new connection, useful when forking processes. * @return mixed Object RedisConnRef or false on failure. */ public static function getClient($group = null, $options = [], $newConnection = false) { global $wgRedisServers; if (!extension_loaded('redis')) { throw new MWException(__METHOD__ . " - The PHP Redis extension is not available. Please enable it on the server to use RedisCache."); } if (empty($wgRedisServers) || !is_array($wgRedisServers)) { MWDebug::log(__METHOD__ . " - \$wgRedisServers must be configured for RedisCache to function."); return false; } if (empty($group)) { $group = 0; $server = current($wgRedisServers); } else { $server = $wgRedisServers[$group]; } if ($newConnection === false && array_key_exists($group, self::$servers)) { return self::$servers[$group]; } if (empty($server) || !is_array($server)) { throw new MWException(__METHOD__ . " - An invalid server group key was passed."); } $pool = \RedisConnectionPool::singleton(array_merge($server['options'], $options)); $redis = $pool->getConnection($server['host'] . ":" . $server['port']); //Concatenate these together for MediaWiki weirdness so it can split them later. if ($redis instanceof RedisConnRef) { //Set up any extra options. RedisConnectionPool does not handle the prefix automatically. if (!empty($server['options']['prefix'])) { $redis->setOption(Redis::OPT_PREFIX, $server['options']['prefix']); } try { $pong = $redis->ping(); if ($pong === '+PONG') { self::$servers[$group] = $redis; } else { $redis = false; } } catch (RedisException $e) { //People using HAProxy will find it will lie about a Redis cluster being healthy when the master is down, but the slaves are up. Doing a PING will cause an immediate disconnect. self::$lastError = $e->getMessage(); $redis = false; } } return $redis; }
/** * Append the debug info to given ApiResult * * @param $context IContextSource * @param $result ApiResult */ public static function appendDebugInfoToApiResult(IContextSource $context, ApiResult $result) { if (!self::$enabled) { return; } // output errors as debug info, when display_errors is on // this is necessary for all non html output of the api, because that clears all errors first $obContents = ob_get_contents(); if ($obContents) { $obContentArray = explode('<br />', $obContents); foreach ($obContentArray as $obContent) { if (trim($obContent)) { self::debugMsg(Sanitizer::stripAllTags($obContent)); } } } MWDebug::log('MWDebug output complete'); $debugInfo = self::getDebugInfo($context); $result->setIndexedTagName($debugInfo, 'debuginfo'); $result->setIndexedTagName($debugInfo['log'], 'line'); $result->setIndexedTagName($debugInfo['debugLog'], 'msg'); $result->setIndexedTagName($debugInfo['queries'], 'query'); $result->setIndexedTagName($debugInfo['includes'], 'queries'); $result->addValue(null, 'debuginfo', $debugInfo); }
static function getNextArticleToPatrolInner($rcid = null) { global $wgRequest, $wgUser, $wgCookiePrefix; $show_namespace = $wgRequest->getVal('namespace'); $invert = $wgRequest->getVal('invert'); $reverse = $wgRequest->getVal('reverse'); $featured = $wgRequest->getVal('featured'); $title = $wgRequest->getVal('target'); $skiptitle = $wgRequest->getVal('skiptitle'); $rc_user_filter = trim(urldecode($wgRequest->getVal('rc_user_filter'))); // assert that current user is not anon if ($wgUser->isAnon()) { return null; } // In English, when a user rolls back an edit, it gives the edit a comment // like: "Reverted edits by ...", so MediaWiki:rollback_comment_prefix // is set to "Reverted" in English wikiHow. $rollbackCommentPrefix = wfMessage('rollback_comment_prefix')->plain(); if (empty($rollbackCommentPrefix) || strpos($rollbackCommentPrefix, '&') === 0) { die("Cannot use RCPatrol feature until MediaWiki:rollback_comment_prefix is set up properly"); } $t = null; if ($title) { $t = Title::newFromText($title); } $skip = null; if ($skiptitle) { $skip = Title::newFromText($skiptitle); } $dbr = wfGetDB(DB_MASTER); /* DEPRECATED rc_moved_to_ns & rc_moved_to_title columns $sql = "SELECT rc_id, rc_cur_id, rc_moved_to_ns, rc_moved_to_title, rc_new, rc_namespace, rc_title, rc_last_oldid, rc_this_oldid FROM recentchanges LEFT OUTER JOIN page ON rc_cur_id = page_id AND rc_namespace = page_namespace WHERE ";*/ $sql = "SELECT rc_id, rc_cur_id, rc_new, rc_namespace, rc_title, rc_last_oldid, rc_this_oldid \n\t\t\tFROM recentchanges \n\t\t\tLEFT OUTER JOIN page ON rc_cur_id = page_id AND rc_namespace = page_namespace \n\t\t\tWHERE "; if (!$wgRequest->getVal('ignore_rcid') && $rcid) { $sql .= " rc_id " . ($reverse == 1 ? " > " : " < ") . " {$rcid} and "; } // if we filter by user we show both patrolled and non-patrolled edits if ($rc_user_filter) { $sql .= " rc_user_text = " . $dbr->addQuotes($rc_user_filter); if ($rcid) { $sql .= " AND rc_id < " . $rcid; } } else { $sql .= " rc_patrolled = 0 "; } // can't patrol your own edits $sql .= " AND rc_user <> " . $wgUser->getID(); // only featured? if ($featured) { $sql .= " AND page_is_featured = 1 "; } if ($show_namespace) { $sql .= " AND rc_namespace " . ($invert ? '<>' : '=') . $show_namespace; } else { // always ignore video $sql .= " AND rc_namespace <> " . NS_VIDEO; } // log entries have namespace = -1, we don't want to show those, hide bots too $sql .= " AND rc_namespace >= 0 AND rc_bot = 0 "; if ($t) { $sql .= " AND rc_title <> " . $dbr->addQuotes($t->getDBKey()); } if ($skip) { $sql .= " AND rc_title <> " . $dbr->addQuotes($skip->getDBKey()); } $sa = $wgRequest->getVal('sa'); if ($sa) { $sa = Title::newFromText($sa); $sql .= " AND rc_title = " . $dbr->addQuotes($sa->getDBKey()); } // has the user skipped any articles? $cookiename = $wgCookiePrefix . "Rcskip"; $skipids = ""; if (isset($_COOKIE[$cookiename])) { $cookie_ids = array_unique(split(",", $_COOKIE[$cookiename])); $ids = array(); //safety first foreach ($cookie_ids as $id) { $id = intval($id); if ($id > 0) { $ids[] = $id; } } if ($ids) { $skipids = " AND rc_cur_id NOT IN (" . implode(",", $ids) . ") "; } } $sql .= "{$skipids} ORDER BY rc_timestamp " . ($reverse == 1 ? "" : "DESC ") . "LIMIT 1"; $res = $dbr->query($sql, __METHOD__); $row = $res->fetchObject(); /*$show=true; if ($show){ var_dump($_GET); var_dump($_POST); echo $sql; var_dump($row); exit; }*/ if ($row) { $result = array(); $t = Title::makeTitle($row->rc_namespace, $row->rc_title); if ($t->isRedirect()) { $wp = new WikiPage($t); $t = $wp->getRedirectTarget(); } // if title has been deleted set $t to null so we will skip it if (!$t->exists()) { MWDebug::log("{$t} does not exist"); $t = null; } $result['rc_cur_id'] = $row->rc_cur_id; if ($rc_user_filter) { $result['rchi'] = $result['rclo'] = $row->rc_id; $result['new'] = $dbr->selectField('recentchanges', array('rc_this_oldid'), array('rc_id' => $row->rc_id)); } else { // always compare to current version $result['new'] = $dbr->selectField('revision', array('max(rev_id)'), array('rev_page' => $row->rc_cur_id)); $result['rchi'] = $dbr->selectField('recentchanges', array('rc_id'), array('rc_this_oldid' => $result['new'])); $result['rclo'] = $dbr->selectField('recentchanges', array('min(rc_id)'), array('rc_patrolled' => 0, "rc_cur_id" => $row->rc_cur_id)); // do we have a reverted edit caught between these 2? // if so, only show the reversion, because otherwise you get the reversion trapped in the middle // and it shows a weird diff page. $hi = isset($result['rchi']) ? $result['rchi'] : $row->rc_id; if ($hi) { $reverted_id = $dbr->selectField('recentchanges', array('min(rc_id)'), array('rc_comment like ' . $dbr->addQuotes($rollbackCommentPrefix . '%'), "rc_id < {$hi}", "rc_id >= {$result['rclo']}", "rc_cur_id" => $row->rc_cur_id)); if ($reverted_id) { $result['rchi'] = $reverted_id; $result['new'] = $dbr->selectField('recentchanges', array('rc_this_oldid'), array('rc_id' => $reverted_id)); $row->rc_id = $result['rchi']; } //} else { // $email = new MailAddress("*****@*****.**"); // $subject = "Could not find hi variable " . date("r"); // $body = print_r($_SERVER, true) . "\n\n" . $sql . "\n\n" . print_r($result, true) . "\n\n\$hi: " . $hi; // UserMailer::send($email, $email, $subject, $body); } if (!$result['rclo']) { $result['rclo'] = $row->rc_id; } if (!$result['rchi']) { $result['rchi'] = $row->rc_id; } // is the last patrolled edit a rollback? if so, show the diff starting at that edit // makes it more clear when someone has reverted vandalism $result['vandal'] = 0; $comm = $dbr->selectField('recentchanges', array('rc_comment'), array('rc_id' => $result['rclo'])); if (strpos($comm, $rollbackCommentPrefix) === 0) { $row2 = $dbr->selectRow('recentchanges', array('rc_id', 'rc_comment'), array("rc_id < {$result['rclo']}", 'rc_cur_id' => $row->rc_cur_id), __METHOD__, array("ORDER BY" => "rc_id desc", "LIMIT" => 1)); if ($row2) { $result['rclo'] = $row2->rc_id; } $result['vandal'] = 1; } } $result['user'] = $dbr->selectField('recentchanges', array('rc_user_text'), array('rc_this_oldid' => $result['new'])); $result['old'] = $dbr->selectField('recentchanges', array('rc_last_oldid'), array('rc_id' => $result['rclo'])); $result['title'] = $t; $result['rcid'] = $row->rc_id; if ($result['rchi'] == $result['rclo']) { $conds = array('rc_id' => $result['rchi']); } else { $conds = array('rc_id <= ' . $result['rchi'], 'rc_id >= ' . $result['rclo']); } $result['count'] = $dbr->selectField('recentchanges', array('count(*)'), array("rc_id <= " . $result['rchi'], "rc_id >= " . $result['rclo'], "rc_patrolled" => 0, "rc_cur_id" => $row->rc_cur_id)); $result = self::getListofEditors($result); return $result; } else { return null; } }
private function getNextTip($content) { $showCoachTip = $this->showCoachTip(&$content); $coachTip = null; if ($showCoachTip) { $coachTip = $this->getCoachTip(&$content); MWDebug::log("this will be a coach tip"); } if (!$coachTip) { $this->getDBTip(&$content); } }
/** * Returns the HTML to add to the page for the toolbar * * @param $context IContextSource * @return string */ public static function getDebugHTML(IContextSource $context) { if (!self::$enabled) { return ''; } global $wgVersion, $wgRequestTime; MWDebug::log('MWDebug output complete'); $request = $context->getRequest(); $debugInfo = array('mwVersion' => $wgVersion, 'phpVersion' => PHP_VERSION, 'time' => microtime(true) - $wgRequestTime, 'log' => self::$log, 'debugLog' => self::$debug, 'queries' => self::$query, 'request' => array('method' => $_SERVER['REQUEST_METHOD'], 'url' => $request->getRequestURL(), 'headers' => $request->getAllHeaders(), 'params' => $request->getValues()), 'memory' => $context->getLanguage()->formatSize(memory_get_usage()), 'memoryPeak' => $context->getLanguage()->formatSize(memory_get_peak_usage()), 'includes' => self::getFilesIncluded($context)); // Cannot use OutputPage::addJsConfigVars because those are already outputted // by the time this method is called. $html = Html::inlineScript(ResourceLoader::makeLoaderConditionalScript(ResourceLoader::makeConfigSetScript(array('debugInfo' => $debugInfo)))); return $html; }
private static function fileFromRow($row) { MWDebug::log("will look for file: " . $row->uci_image_name); return wfFindFile("User-Completed-Image-" . $row->uci_image_name); }
function getAnonImageFileName($id = null) { global $IP; $images = glob($IP . Avatar::ANON_AVATAR_DIR . '/80x80*'); if ($id === null) { $i = array_rand($images); } else { $i = abs($id) % (count($images) - 1); MWDebug::log("id: {$id}, i: {$i}"); } return basename($images[$i]); }