function getIntlRedirect($lang, $pageid) { static $dbr = null; if (!$dbr) { $dbr = wfGetDB(DB_SLAVE); } $sql = 'SELECT rd_title FROM ' . Misc::getLangDB($lang) . '.redirect WHERE rd_from=' . intval($pageid) . ' AND rd_namespace=' . NS_MAIN; $res = $dbr->query($sql, __METHOD__); $row = $res ? $res->fetchObject() : null; return $row ? Misc::getLangBaseURL($lang) . '/' . $row->rd_title : ''; }
} } $dbh = wfGetDB(DB_SLAVE); $lowDate = wfTimestamp(TS_MW, strtotime("-1 day", strtotime(date('Ymd', time())))); $today = date('Ymd', time()); $moved = ""; $redirected = ""; $deleted = ""; if (@$_SERVER['HOSTNAME'] == "doh.wikidiy.com") { $allLangs = array("en", "es"); } else { $allLangs = $wgActiveLanguages; $allLangs[] = "en"; } foreach ($allLangs as $lang) { $langDB = Misc::getLangDB($lang); $sql = "select tl_from_lang, tl_from_aid, tl_to_lang, tl_to_aid FROM " . $langDB . ".daily_edits de JOIN wikidb_112.translation_link tl on (tl.tl_from_aid=de.de_page_id AND tl_from_lang=" . $dbh->addQuotes($lang) . ") or (tl.tl_to_lang=" . $dbh->addQuotes($lang) . " AND tl.tl_to_aid=de.de_page_id) WHERE de_timestamp > " . $dbh->addQuotes($lowDate) . " and de_edit_type=" . DailyEdits::MOVE_TYPE; $res = $dbh->query($sql); $rows = array(); $fromIds = array(); $toIds = array(); while ($row = $dbh->fetchObject($res)) { $fromIds[] = array('lang' => $row->tl_from_lang, 'id' => $row->tl_from_aid); $toIds[] = array('lang' => $row->tl_to_lang, 'id' => $row->tl_to_aid); } if (count($fromIds) > 0) { $fromPages = Misc::getPagesFromLangIds($fromIds); $toPages = Misc::getPagesFromLangIds($toIds); $n = 0; while ($n < count($fromPages)) { $fromPages[$n]->page_id;
/** * Calculate the totals for the stat from the beginning * to the date specified */ function batchCalcTotals(&$dbr, &$users, $endDate) { global $wgIgnoreNamespacesForEditCount, $wgActiveLanguages; $langs = $wgActiveLanguages; $langs[] = 'en'; $ids = $this->getIds($users); $ret = array(); foreach ($langs as $lang) { $db = Misc::getLangDB($lang); $sql = 'select rev_user, ' . $this->getDayQuery('rev_timestamp') . ', count(*) as ct from ' . $db . '.revision join ' . $db . '.page on rev_page=page_id where (not page_namespace in (' . implode(',', $wgIgnoreNamespacesForEditCount) . ')) AND rev_user in (' . implode(',', $ids) . ') AND rev_timestamp<=' . $dbr->addQuotes($endDate) . ' GROUP BY rev_user'; $res = $dbr->query($sql, __METHOD__); foreach ($res as $row) { if (!isset($ret[$endDate][$row->rev_user]['non_user_edit_count'])) { $ret[$endDate][$row->rev_user] = array('nonuser_edit_count' => $row->ct); } else { $ret[$endDate][$row->rev_user]['nonuser_edit_count'] += $row->ct; } } $sql = 'select ar_user,' . $this->getDayQuery('ar_timestamp') . ', count(*) as ct from ' . $db . '.archive where ar_namespace not in (' . implode(',', $wgIgnoreNamespacesForEditCount) . ') AND ar_user in (' . implode(',', $ids) . ') AND ar_timestamp <= ' . $dbr->addQuotes($endDate) . ' GROUP BY ar_user '; $res = $dbr->query($sql, __METHOD__); foreach ($res as $row) { if (!isset($ret[$endDate][$row->ar_user]['nonuser_edit_count'])) { $ret[$endDate][$row->ar_user]['nonuser_edit_count'] = $row->ct; } else { $ret[$endDate][$row->ar_user]['nonuser_edit_count'] += $row->ct; } } } return $ret; }
//In test mode, we just display, but don't actually save $debug = @$argv[0] != "live"; //Number of links added or modified $changes = 0; $dbr = wfGetDB(DB_MASTER); global $wgLanguageCode; if (@$_SERVER['HOSTNAME'] == "doh.wikidiy.com") { $allLangs = array("en", "es", "pt"); } else { $allLangs = $wgActiveLanguages; $allLangs[] = "en"; } //We add interwiki links as the interwiki user global $wgUser; $wgUser = User::newFromName("InterwikiBot"); $ourPageTable = Misc::getLangDB($wgLanguageCode) . ".page"; $lowDate = wfTimestamp(TS_MW, strtotime("-30 day", strtotime(date('Ymd', time())))); $links = TranslationLink::batchGetRemovedLinks($wgLanguageCode, true); TranslationLink::batchPopulateURLs($links); foreach ($links as $link) { if ($link->removeLink(true, $debug)) { print "Removing link between " . $link->fromURL . "(" . $link->fromAID . ") and " . $link->toURL . "(" . $link->toAID . ")\n"; } else { print "Failed to remove link between " . $link->fromURL . "(" . $link->fromAID . ") and " . $link->toURL . "(" . $link->toAID . ")\n"; } } $links = TranslationLink::batchGetRemovedLinks($wgLanguageCode, false); TranslationLink::batchPopulateURLs($links); foreach ($links as $link) { if ($link->removeLink(false, $debug)) { print "Removing link between " . $link->toURL . "(" . $link->toAID . ") and " . $link->fromURL . "(" . $link->fromAID . ")\n";
function resetAdExclusionCache(&$dbr, $languageCode) { global $wgMemc, $wgDBname; $oldDBname = $wgDBname; $wgDBname = Misc::getLangDB($languageCode); $key = wfMemcKey('adExclusions', $languageCode); $wgDBname = $oldDBname; $excludeList = array(); if ($languageCode == "en") { $dbr->selectDB($wgDBname); } else { $dbr->selectDB('wikidb_' . $languageCode); } $res = $dbr->select(AdminAdExclusions::EXCLUSION_TABLE, "ae_page", array(), __METHOD__); foreach ($res as $row) { $excludeList[] = $row->ae_page; } $wgMemc->set($key, $excludeList); }
<?php require_once 'commandLine.inc'; require_once "{$IP}/extensions/wikihow/titus/Titus.class.php"; $dbw = DatabaseBase::factory('mysql'); $dbw->open(TITUS_DB_HOST, WH_DATABASE_MAINTENANCE_USER, WH_DATABASE_MAINTENANCE_PASSWORD, TitusDB::getDBName()); $sql = "delete t.* from " . TitusDB::getDBName() . ".titus_intl t left join " . Misc::getLangDB($wgLanguageCode) . ".page p on ti_page_id = p.page_id WHERE p.page_is_redirect=1 AND ti_language_code='{$wgLanguageCode}'"; $dbw->query($sql); print $dbw->affectedRows() . " rows deleted in {$wgLanguageCode} ";
<?php require_once 'commandLine.inc'; require_once "{$IP}/extensions/wikihow/titus/Titus.class.php"; require_once "{$IP}/extensions/wikihow/DatabaseHelper.class.php"; global $wgLanguageCode; $sql = "select rev_page, max(rev_timestamp) as last_revision, min(rev_timestamp) as first_revision_after, ti_last_patrolled_edit_timestamp as last_patrolled from titusdb.titus_intl ti join " . Misc::getLangDB($wgLanguageCode) . ".revision on ti_page_id = rev_page WHERE rev_timestamp > ti_last_patrolled_edit_timestamp AND ti_language_code='{$wgLanguageCode}' AND not (rev_comment like '%move%') group by rev_page"; $dbr = DatabaseBase::factory('mysql'); $dbr->open(TITUS_DB_HOST, WH_DATABASE_MAINTENANCE_USER, WH_DATABASE_MAINTENANCE_PASSWORD, TitusDB::getDBName()); $res = $dbr->query($sql); $rows = array(); foreach ($res as $row) { $rows[] = $row; } if (sizeof($rows) > 0) { $now = wfTimestampNow(); $msg = "<table><thead><tr><td>Title</td><td>Page Id</td><td>Latest Revision</td><td>First Revision After Patrolled</td><td>Last Patrolled Revision</td></tr></thead>\n<tbody>\n"; foreach ($rows as $row) { $lts = wfTimestamp(TS_MW, $row->first_revision_after); if ($lts < $now - 24 * 60 * 60) { $t = Title::newFromId($row->rev_page); $msg .= "<tr><td>" . $t->getText() . "</td><td>" . $row->rev_page . "</td><td>" . wfTimestamp(TS_DB, $row->last_revision) . "</td><td>" . wfTimestamp(TS_DB, $row->first_revision_after) . "</td><td>" . wfTimestamp(TS_DB, $row->last_patrolled) . "</td></tr>\n"; } } $msg .= "</tbody></table>\n"; if ($msg != "") { $msg = "<p>The following pages on {$wgLanguageCode} have been modified over 24 hours ago, but aren't showing up in Titus</p>\n" . $msg; print $msg; $to = new MailAddress("*****@*****.**"); $from = new MailAddress("*****@*****.**"); $subject = "Out of date fields in titus:\n";
/** * Get pages from language ids * @param langIds List of language ids as an array-hash array('lang'=> ,'id'=>) * */ public static function getPagesFromLangIds($langIds, $cols = array()) { $ll = array(); foreach ($langIds as $li) { $ll[$li['lang']][] = $li['id']; } $dbh = wfGetDB(DB_SLAVE); $startSQL = ""; if (empty($cols)) { $startSQL = "select * from "; } else { $startSQL = "select " . implode(',', $cols) . " from "; } $pages = array(); foreach ($ll as $l => $ids) { $sql = $startSQL . Misc::getLangDB($l) . ".page where page_id in (" . implode(',', $ids) . ")"; $res = $dbh->query($sql, __METHOD__); while ($row = $dbh->fetchObject($res)) { $row = get_object_vars($row); $pages[$l][$row['page_id']] = array_merge($row, array('lang' => $l)); } } $rows = array(); foreach ($langIds as $li) { if (isset($pages[$li['lang']][$li['id']])) { $rows[] = $pages[$li['lang']][$li['id']]; } else { $rows[] = array('page_id' => $li['id'], 'lang' => $li['lang']); } } return $rows; }
/** * Gets all the links between two languages satisfying * various query parameters */ static function getLinks($fromLang, $toLang, $where = array()) { $fromPageTable = Misc::getLangDB($fromLang) . ".page"; $toPageTable = Misc::getLangDB($toLang) . ".page"; $dbr = wfGetDB(DB_SLAVE); $sql = "select tl_from_aid, tl_to_aid, fd.page_title as to_title, d.page_title as from_title FROM " . WH_DATABASE_NAME . ".translation_link LEFT JOIN " . $fromPageTable . " d on tl_from_aid=d.page_id LEFT JOIN " . $toPageTable . " as fd on tl_to_aid = fd.page_id WHERE tl_from_lang=" . $dbr->addQuotes($fromLang) . " AND tl_to_lang=" . $dbr->addQuotes($toLang); if (!empty($where)) { $sql .= " AND " . implode(" AND ", $where); } $res = $dbr->query($sql); $baseURLA = Misc::getLangBaseUrl($fromLang) . '/'; $baseURLB = Misc::getLangBaseUrl($toLang) . '/'; $tls = array(); foreach ($res as $row) { $tl = new TranslationLink(); if ($row->from_title != null) { $tl->fromURL = $baseURLA . $row->from_title; } $tl->fromAID = $row->tl_from_aid; $tl->fromLang = $fromLang; if ($row->to_title != null) { $tl->toURL = $baseURLB . $row->to_title; } $tl->toAID = $row->tl_to_aid; $tl->toLang = $toLang; $tls[] = $tl; } return $tls; }
public function getPageIdsToCalc(&$dbr, $date) { global $wgLanguageCode; $ts = wfTimestamp(TS_UNIX, $date); $d = wfTimestamp(TS_MW, strtotime("-2 day", strtotime(date('Ymd', $ts)))); $langDB = Misc::getLangDB($wgLanguageCode); $sql = "select nap_page FROM " . $langDB . ".newarticlepatrol JOIN " . $langDB . ".page on page_id = nap_page WHERE page_is_redirect = 0 AND nap_patrolled = 1 AND nap_timestamp_ci > " . $dbr->addQuotes($d); $res = $dbr->query($sql, __METHOD__); $pr = array(); foreach ($res as $row) { $pr[$row->nap_page] = 1; } $sql = "select de_page_id FROM " . $langDB . ".daily_edits left join " . $langDB . ".newarticlepatrol on de_page_id = nap_page where nap_patrolled is NULL AND de_edit_type <> " . DailyEdits::DELETE_TYPE . " AND de_timestamp > " . $dbr->addQuotes($d); $res = $dbr->query($sql, __METHOD__); foreach ($res as $row) { $pr[$row->de_page_id] = 1; } $ids = array_keys($pr); return $ids; }