/** * Generates condition for the query used in a batch count visiting watchers. * * @param IDatabase $db * @param array $targetsWithVisitThresholds array of pairs (LinkTarget, last visit threshold) * @return string */ private function getVisitingWatchersCondition(IDatabase $db, array $targetsWithVisitThresholds) { $missingTargets = []; $namespaceConds = []; foreach ($targetsWithVisitThresholds as list($target, $threshold)) { if ($threshold === null) { $missingTargets[] = $target; continue; } /* @var LinkTarget $target */ $namespaceConds[$target->getNamespace()][] = $db->makeList(['wl_title = ' . $db->addQuotes($target->getDBkey()), $db->makeList(['wl_notificationtimestamp >= ' . $db->addQuotes($db->timestamp($threshold)), 'wl_notificationtimestamp IS NULL'], LIST_OR)], LIST_AND); } $conds = []; foreach ($namespaceConds as $namespace => $pageConds) { $conds[] = $db->makeList(['wl_namespace = ' . $namespace, '(' . $db->makeList($pageConds, LIST_OR) . ')'], LIST_AND); } if ($missingTargets) { $lb = new LinkBatch($missingTargets); $conds[] = $lb->constructSet('wl', $db); } return $db->makeList($conds, LIST_OR); }
/** * SQL clause to skip forbidden log types for this user * * @param IDatabase $db * @param string $audience Public/user * @param User $user User to check, or null to use $wgUser * @return string|bool String on success, false on failure. */ public static function getExcludeClause($db, $audience = 'public', User $user = null) { global $wgLogRestrictions; if ($audience != 'public' && $user === null) { global $wgUser; $user = $wgUser; } // Reset the array, clears extra "where" clauses when $par is used $hiddenLogs = array(); // Don't show private logs to unprivileged users foreach ($wgLogRestrictions as $logType => $right) { if ($audience == 'public' || !$user->isAllowed($right)) { $hiddenLogs[] = $logType; } } if (count($hiddenLogs) == 1) { return 'log_type != ' . $db->addQuotes($hiddenLogs[0]); } elseif ($hiddenLogs) { return 'log_type NOT IN (' . $db->makeList($hiddenLogs) . ')'; } return false; }
/** * Creates a query condition part for getting only items before or after the given link target * (while ordering using $sort mode) * * @param IDatabase $db * @param LinkTarget $target * @param string $op comparison operator to use in the conditions * @return string */ private function getFromUntilTargetConds(IDatabase $db, LinkTarget $target, $op) { return $db->makeList(["wl_namespace {$op} " . $target->getNamespace(), $db->makeList(['wl_namespace = ' . $target->getNamespace(), "wl_title {$op}= " . $db->addQuotes($target->getDBkey())], LIST_AND)], LIST_OR); }