/** * Return an array of conditions depending of options set in $opts * * @param $opts FormOptions * @return array */ public function buildMainQueryConds(FormOptions $opts) { global $wgUser; $dbr = wfGetDB(DB_SLAVE); $conds = array(); # It makes no sense to hide both anons and logged-in users # Where this occurs, force anons to be shown $forcebot = false; if ($opts['hideanons'] && $opts['hideliu']) { # Check if the user wants to show bots only if ($opts['hidebots']) { $opts['hideanons'] = false; } else { $forcebot = true; $opts['hidebots'] = false; } } // Calculate cutoff $cutoff_unixtime = time() - $opts['days'] * 86400; $cutoff_unixtime = $cutoff_unixtime - $cutoff_unixtime % 86400; $cutoff = $dbr->timestamp($cutoff_unixtime); $fromValid = preg_match('/^[0-9]{14}$/', $opts['from']); if ($fromValid && $opts['from'] > wfTimestamp(TS_MW, $cutoff)) { $cutoff = $dbr->timestamp($opts['from']); } else { $opts->reset('from'); } $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes($cutoff); // Selected product changes $product = addslashes(isset($_GET['product']) ? $_GET['product'] : PonyDocsProduct::GetSelectedProduct()); $conds[] = 'rc_title LIKE "' . $product . '%"'; $hidePatrol = $wgUser->useRCPatrol() && $opts['hidepatrolled']; $hideLoggedInUsers = $opts['hideliu'] && !$forcebot; $hideAnonymousUsers = $opts['hideanons'] && !$forcebot; if ($opts['hideminor']) { $conds['rc_minor'] = 0; } if ($opts['hidebots']) { $conds['rc_bot'] = 0; } if ($hidePatrol) { $conds['rc_patrolled'] = 0; } if ($forcebot) { $conds['rc_bot'] = 1; } if ($hideLoggedInUsers) { $conds[] = 'rc_user = 0'; } if ($hideAnonymousUsers) { $conds[] = 'rc_user != 0'; } if ($opts['hidemyself']) { if ($wgUser->getId()) { $conds[] = 'rc_user != ' . $dbr->addQuotes($wgUser->getId()); } else { $conds[] = 'rc_user_text != ' . $dbr->addQuotes($wgUser->getName()); } } # Namespace filtering if ($opts['namespace'] !== '') { if (!$opts['invert']) { $conds[] = 'rc_namespace = ' . $dbr->addQuotes($opts['namespace']); } else { $conds[] = 'rc_namespace != ' . $dbr->addQuotes($opts['namespace']); } } return $conds; }
/** * Return an array of conditions depending of options set in $opts * * @param FormOptions $opts * @return array */ public function buildMainQueryConds(FormOptions $opts) { $dbr = wfGetDB(DB_SLAVE); $conds = array(); # It makes no sense to hide both anons and logged-in users # Where this occurs, force anons to be shown $forcebot = false; if ($opts['hideanons'] && $opts['hideliu']) { # Check if the user wants to show bots only if ($opts['hidebots']) { $opts['hideanons'] = false; } else { $forcebot = true; $opts['hidebots'] = false; } } // Calculate cutoff $cutoff_unixtime = time() - $opts['days'] * 86400; $cutoff_unixtime = $cutoff_unixtime - $cutoff_unixtime % 86400; $cutoff = $dbr->timestamp($cutoff_unixtime); $fromValid = preg_match('/^[0-9]{14}$/', $opts['from']); if ($fromValid && $opts['from'] > wfTimestamp(TS_MW, $cutoff)) { $cutoff = $dbr->timestamp($opts['from']); } else { $opts->reset('from'); } $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes($cutoff); $hidePatrol = $this->getUser()->useRCPatrol() && $opts['hidepatrolled']; $hideLoggedInUsers = $opts['hideliu'] && !$forcebot; $hideAnonymousUsers = $opts['hideanons'] && !$forcebot; if ($opts['hideminor']) { $conds['rc_minor'] = 0; } if ($opts['hidebots']) { $conds['rc_bot'] = 0; } if ($hidePatrol) { $conds['rc_patrolled'] = 0; } if ($forcebot) { $conds['rc_bot'] = 1; } if ($hideLoggedInUsers) { $conds[] = 'rc_user = 0'; } if ($hideAnonymousUsers) { $conds[] = 'rc_user != 0'; } if ($opts['hidemyself']) { if ($this->getUser()->getId()) { $conds[] = 'rc_user != ' . $dbr->addQuotes($this->getUser()->getId()); } else { $conds[] = 'rc_user_text != ' . $dbr->addQuotes($this->getUser()->getName()); } } # Namespace filtering if ($opts['namespace'] !== '') { $selectedNS = $dbr->addQuotes($opts['namespace']); $operator = $opts['invert'] ? '!=' : '='; $boolean = $opts['invert'] ? 'AND' : 'OR'; # namespace association (bug 2429) if (!$opts['associated']) { $condition = "rc_namespace {$operator} {$selectedNS}"; } else { # Also add the associated namespace $associatedNS = $dbr->addQuotes(MWNamespace::getAssociated($opts['namespace'])); $condition = "(rc_namespace {$operator} {$selectedNS} " . $boolean . " rc_namespace {$operator} {$associatedNS})"; } $conds[] = $condition; } return $conds; }