本文整理汇总了PHP中WikiFactory::db方法的典型用法代码示例。如果您正苦于以下问题:PHP WikiFactory::db方法的具体用法?PHP WikiFactory::db怎么用?PHP WikiFactory::db使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WikiFactory
的用法示例。
在下文中一共展示了WikiFactory::db方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadData
public static function loadData($forceRefresh = false, $forceLanguage = null)
{
global $wgMemc, $wgStatsDB, $wgContLang, $wgExternalSharedDB, $wgStatsDBEnabled;
wfProfileIn(__METHOD__);
self::$mLanguage = !empty($forceLanguage) ? $forceLanguage : $wgContLang->getCode();
$cacheKey = self::CACHE_KEY_TOKEN . ':' . strtoupper(self::$mLanguage);
self::$mData = $wgMemc->get($cacheKey);
if (empty(self::$mData) || $forceRefresh) {
self::$mData = array();
$wikisIDs = array();
// get all the active wikis selected by the sales team
$wikiFactoryRecommended = WikiFactory::getVarByName(self::WF_VAR_NAME, null);
self::$mData['recommended'] = array();
if (!empty($wikiFactoryRecommended) && !empty($wikiFactoryRecommended->cv_variable_id)) {
$dbr = WikiFactory::db(DB_SLAVE);
$res = $dbr->select(array('city_list', 'city_variables'), 'city_id', array('city_id = cv_city_id', 'city_public' => 1, 'city_lang' => self::$mLanguage, 'cv_variable_id' => $wikiFactoryRecommended->cv_variable_id, 'cv_value' => serialize(true)));
while ($row = $dbr->fetchObject($res)) {
self::$mData['recommended'][] = $row->city_id;
}
$dbr->freeResult($res);
}
$counter = 0;
self::$mData['hubs'] = array();
if (!empty($wgStatsDBEnabled)) {
$langs = array(self::$mLanguage);
$wikis = DataMartService::getTopWikisByPageviews(DataMartService::PERIOD_ID_MONTHLY, 200, $langs, null, 1);
$minPageViews = isset(self::$pageviewsLimits[self::$mLanguage]) ? self::$pageviewsLimits[self::$mLanguage] : self::$pageviewsLimits['default'];
foreach ($wikis as $wikiID => $pvCount) {
if ($pvCount >= $minPageViews) {
$hub = WikiFactoryHub::getInstance();
$cat_id = $hub->getCategoryId($wikiID);
if (!$cat_id) {
continue;
}
if (!isset(self::$mData['hubs'][$cat_id])) {
self::$mData['hubs'][$cat_id] = array();
}
self::$mData['hubs'][$cat_id][] = $wikiID;
$counter++;
}
}
}
// removing entries from hubs that have a match in recommended
if (!empty(self::$mData['recommended']) && !empty(self::$mData['hubs'])) {
$counter = 0;
foreach (self::$mData['hubs'] as $hubID => &$item) {
$item = array_diff($item, self::$mData['recommended']);
$counter += count($item);
}
}
self::$mData['total'] = $counter;
$wgMemc->set($cacheKey, self::$mData, 3600 * self::CACHE_EXPIRY);
}
wfProfileOut(__METHOD__);
}
示例2: getTasksCount
/**
* Get number of items queued in TaskManager
*
* @return int number of items in the queue
*/
private static function getTasksCount()
{
global $wgMemc;
$key = __METHOD__;
$cnt = $wgMemc->get($key);
if (!is_numeric($cnt)) {
$dbr = WikiFactory::db(DB_SLAVE);
$cnt = $dbr->estimateRowCount('wikia_tasks');
$wgMemc->set($key, $cnt, 60 * 1);
}
return $cnt;
}
示例3: submitForm
function submitForm()
{
global $wgRequest, $wgOut, $IP, $wgUser;
$articles = $this->mArguments;
$mode = $this->mMode;
$username = $this->mUsername;
$tempUser = User::newFromName($username);
$sParams = serialize(array('articles' => $articles, 'username' => $username, 'mode' => $mode, 'admin' => $this->mAdmin));
$dbw = WikiFactory::db(DB_MASTER);
$dbw->insert('wikia_tasks', array('task_user_id' => $wgUser->getID(), 'task_type' => $this->mType, 'task_priority' => 1, 'task_status' => 1, 'task_added' => wfTimestampNow(), 'task_started' => '', 'task_finished' => '', 'task_arguments' => $sParams));
$task_id = $dbw->insertId();
$dbw->commit();
return $task_id;
}
示例4: execute
public function execute()
{
// get all closed wikis
$WF_db = WikiFactory::db(DB_SLAVE);
$closedBefore = wfTimestamp(TS_MW, strtotime('-3 months'));
$closedWikis = $WF_db->selectFieldValues('city_list', 'city_id', ['city_public' => WikiFactory::CLOSE_ACTION, sprintf('city_lastdump_timestamp < "%s"', $closedBefore)], __METHOD__);
$batches = array_chunk($closedWikis, self::BATCH);
$this->output(sprintf("Got %d closed wikis (before %s) in %d batches\n", count($closedWikis), $closedBefore, count($batches)));
$this->output("Starting in 5 seconds...\n");
sleep(5);
foreach ($batches as $n => $batch) {
$this->cleanupBatch($batch);
}
$this->output("\nDone\n");
}
示例5: submitForm
function submitForm()
{
global $wgRequest, $wgOut, $IP, $wgUser;
$articles = $this->mArguments;
$mode = $this->mMode;
$username = "Restore page script";
$tempUser = User::newFromName($username);
#--- all should be correct at this point
#--- first prepare serialized info with params
$sel_articles = $articles;
$sParams = serialize(array("articles" => $sel_articles["articles"], "username" => $username, "mode" => $mode, "admin" => $this->mAdmin, "motherTask" => $this->mMotherTask));
$dbw = WikiFactory::db(DB_MASTER);
$dbw->insert("wikia_tasks", array("task_user_id" => $wgUser->getID(), "task_type" => $this->mType, "task_priority" => 10, "task_status" => 1, "task_added" => wfTimestampNow(), "task_started" => "", "task_finished" => "", "task_arguments" => $sParams));
$task_id = $dbw->insertId();
$dbw->commit();
return $task_id;
}
示例6: removeFromVariablesPool
/**
* Remove variable from WikiFactory (delete from city_variables_pool table)
* @param array $varData
* @return Status
*/
function removeFromVariablesPool($varData)
{
$log = WikiaLogger::instance();
$dbw = WikiFactory::db(DB_MASTER);
$dbw->begin();
try {
$dbw->delete("city_variables_pool", array("cv_id" => $varData['cv_id']), __METHOD__);
$log->info("Remove variable from city_variables_pool table.", $varData);
$dbw->commit();
$status = Status::newGood();
} catch (DBQueryError $e) {
$log->error("Database error: Cannot remove variable from city_variables_pool table.", $varData);
$dbw->rollback();
$status = Status::newFatal("Database error: Cannot remove variable from city_variables_pool table (" . $e->getMessage() . ").");
}
return $status;
}
示例7: generateList
function generateList($format)
{
global $wgMemc, $wgExternalSharedDB;
$func = "begin_" . $format;
$res = $func();
$dbr = WikiFactory::db(DB_SLAVE, array(), $wgExternalSharedDB);
$sth = $dbr->select(array("city_list"), array("city_title", "city_lang", "city_url", "city_id"), array("city_public = 1"), __METHOD__);
while ($row = $dbr->fetchObject($sth)) {
$row->category = WikiFactory::getCategory($row->city_id);
$func = "body_" . $format;
$res .= $func($row);
}
$func = "end_" . $format;
$res .= $func();
if (!empty($res)) {
$gz_res = gzdeflate($res, 3);
$wgMemc->set(wfSharedMemcKey("{$format}-city-list"), $gz_res, 3600 * 6);
}
}
示例8: getCityCluster
/**
* @author Federico "Lox" Lucignano
* @param $wikiCityID int the city_id for the wiki
* @return string the name of the cluster the wiki DB belongs to
*
* Retrieves the name of the cluster in which the local DB for the specified wiki is stored
*/
public static function getCityCluster($wikiCityID)
{
wfProfileIn(__METHOD__);
//check for non admitted values
if (empty($wikiCityID) || !is_int($wikiCityID)) {
wfProfileOut(__METHOD__);
return false;
}
wfDebugLog(__CLASS__ . '::' . __METHOD__, "Looking up cluster for wiki with ID {$wikiCityID}");
//WikiFactory implementation
$value = WikiFactory::getVarValueByName('wgDBcluster', $wikiCityID);
//if not found fall back to city_list implementation
if (empty($value)) {
$dbr = WikiFactory::db(DB_SLAVE);
$res = $dbr->selectField('city_list', 'city_cluster', array('city_id' => $wikiCityID));
$value = $res;
}
wfDebugLog(__CLASS__ . '::' . __METHOD__, "Cluster for wiki with ID {$wikiCityID} is '{$value}'" . (empty($value) ? ' (main shared DB)' : null));
wfProfileOut(__METHOD__);
return empty($value) ? self::CLUSTER_DEFAULT : $value;
}
示例9: updateCityDescription
/**
* updateCityDescription
*
* static method called as hook
*
* @static
* @access public
*
* @param WikiPage $article
* @param $user
* @return bool
*/
public static function updateCityDescription(&$article, &$user)
{
global $wgCityId;
if (strtolower($article->getTitle()) == "mediawiki:description") {
$out = trim(strip_tags(wfMsg('description')));
$db = WikiFactory::db(DB_MASTER);
$db->update("city_list", ["city_description" => $out], ["city_id" => $wgCityId], __METHOD__);
}
return true;
}
示例10: axWFactoryDomainQuery
/**
* axWFactoryDomainQuery
*
* used in autocompletion
*
* @return string JSON encoded array
*/
function axWFactoryDomainQuery()
{
global $wgRequest;
$query = $wgRequest->getVal("query", false);
$return = array("query" => $query, "suggestions" => array(), "data" => array());
$exact = array("suggestions" => array(), "data" => array());
$match = array("suggestions" => array(), "data" => array());
// query terms: wik, wiki, wikia take too much memory
// and end up with fatal errors
if (substr("wikia", 0, strlen((string) $query)) === $query) {
$query = false;
}
if ($query) {
/**
* maybe not very effective but used only by staff anyway
*/
$query = strtolower($query);
$dbr = WikiFactory::db(DB_SLAVE);
$sth = $dbr->select(array("city_domains"), array("city_id", "city_domain"), array("city_domain not like 'www.%'", "city_domain not like '%.wikicities.com'", "city_domain like '%{$query}%'"), __METHOD__);
while ($domain = $dbr->fetchObject($sth)) {
$domain->city_domain = strtolower($domain->city_domain);
if (preg_match("/^{$query}/", $domain->city_domain)) {
$exact["suggestions"][] = $domain->city_domain;
$exact["data"][] = $domain->city_id;
} elseif (preg_match("/{$query}/", $domain->city_domain)) {
$match["suggestions"][] = $domain->city_domain;
$match["data"][] = $domain->city_id;
}
}
$return["suggestions"] = array_merge($exact["suggestions"], $match["suggestions"]);
$return["data"] = array_merge($exact["data"], $match["suggestions"]);
}
return json_encode($return);
}
示例11: removeRows
/**
* remove rows stored in archive database
*
* @access private
*/
private function removeRows()
{
wfProfileIn(__METHOD__);
$dbw = WikiFactory::db(DB_MASTER);
foreach ($this->mData as $task) {
if (!empty($task->moved)) {
$dbw->delete("wikia_tasks", array("task_id" => $task->task_id), __METHOD__);
Wikia::log(__METHOD__, "", sprintf("Task id=%d type=%s added=%s removed.", $task->task_id, $task->task_type, $task->task_added));
}
}
wfProfileOut(__METHOD__);
return true;
}
示例12: axQuery
/**
* used in autocompleting form
*
* @access public
* @static
*
* @return String json-ized answer
*/
public static function axQuery()
{
global $wgRequest;
$query = $wgRequest->getVal("query", false);
$return = array("query" => $query, "suggestions" => array(), "data" => array());
if ($query) {
$query = strtolower($query);
$dbr = WikiFactory::db(DB_SLAVE);
$sth = $dbr->select(array("city_tag"), array("id", "name"), array("name like '%{$query}%'"), __METHOD__);
while ($row = $dbr->fetchObject($sth)) {
$return["suggestions"][] = $row->name;
}
}
return json_encode($return);
}
示例13: execute
/**
* 1. go through all wikis which are marked for closing and check which one
* want to have images packed.
*
* 2. pack images, send them via rsync to target server,
*
* 3. mark in city_list.city_flags that images are sent,
*
* 4. remove images
*
* @access public
*/
public function execute()
{
global $wgUploadDirectory, $wgDBname;
if (!isset($this->mOptions['wiki_id'])) {
echo "Wiki Id is not valid";
die(1);
}
$where = array("city_id" => intval($this->mOptions['wiki_id']));
$dbr = WikiFactory::db(DB_SLAVE);
$row = $dbr->selectRow(array("city_list"), array("city_id", "city_flags", "city_dbname", "city_url", "city_public"), $where, __METHOD__);
if (is_object($row)) {
/**
* reasonable defaults for wikis and some presets
*/
$hide = false;
$xdumpok = true;
$newFlags = 0;
$dbname = $row->city_dbname;
$folder = WikiFactory::getVarValueByName("wgUploadDirectory", $row->city_id);
$cluster = WikiFactory::getVarValueByName("wgDBcluster", $row->city_id);
/**
* safety check, if city_dbname is not unique die with message
*/
$check = $dbr->selectRow(array("city_list"), array("count(*) as count"), array("city_dbname" => $dbname), __METHOD__, array("GROUP BY" => "city_dbname"));
if ($check->count > 1) {
echo "{$dbname} is not unique. Check city_list and rerun script";
die(1);
}
Wikia::log(__CLASS__, "info", "city_id={$row->city_id} city_url={$row->city_url} city_dbname={$dbname} city_flags={$row->city_flags} city_public={$row->city_public}");
Wikia::log(__CLASS__, "info", "removing folder {$folder}");
if (is_dir($wgUploadDirectory)) {
/**
* what should we use here?
*/
$cmd = "rm -rf {$folder}";
wfShellExec($cmd, $retval);
if ($retval) {
/**
* info removing folder was not possible
*/
}
}
/**
* clear wikifactory tables, condition for city_public should
* be always true there but better safe than sorry
*/
$dbw = WikiFactory::db(DB_MASTER);
$dbw->delete("city_list", array("city_public" => array(0, -1), "city_id" => $row->city_id), __METHOD__);
Wikia::log(__CLASS__, "info", "{$row->city_id} removed from WikiFactory tables");
/**
* drop database, get db handler for proper cluster
*/
global $wgDBadminuser, $wgDBadminpassword;
$centralDB = empty($cluster) ? "wikicities" : "wikicities_{$cluster}";
/**
* get connection but actually we only need info about host
*/
$local = wfGetDB(DB_MASTER, array(), $centralDB);
$server = $local->getLBInfo('host');
$dbw = new DatabaseMysql($server, $wgDBadminuser, $wgDBadminpassword, $centralDB);
$dbw->begin();
$dbw->query("DROP DATABASE `{$row->city_dbname}`");
$dbw->commit();
Wikia::log(__CLASS__, "info", "{$row->city_dbname} dropped from cluster {$cluster}");
}
}
示例14: updateGlobal
/**
* Processes shared database (wikicities) and makes all needed changes
*/
public function updateGlobal()
{
wfProfileIn(__METHOD__);
global $wgStatsDB, $wgStatsDBEnabled;
// wikicities
$this->addLog("Updating global shared database: wikicities.");
$dbw = WikiFactory::db(DB_MASTER);
$dbw->begin();
$tasks = self::$mGlobalDefaults;
$hookName = 'UserRename::Global';
$this->addLog("Broadcasting hook: {$hookName}");
wfRunHooks($hookName, array($dbw, $this->mUserId, $this->mOldUsername, $this->mNewUsername, $this, &$tasks));
foreach ($tasks as $task) {
$this->addLog("Updating {$task['table']}.{$task['username_column']}.");
$this->renameInTable($dbw, $task['table'], $this->mUserId, $this->mOldUsername, $this->mNewUsername, $task);
}
$hookName = 'UserRename::AfterGlobal';
$this->addLog("Broadcasting hook: {$hookName}");
wfRunHooks($hookName, array($dbw, $this->mUserId, $this->mOldUsername, $this->mNewUsername, $this, &$tasks));
$dbw->commit();
$this->addLog("Finished updating shared database: wikicities.");
wfProfileOut(__METHOD__);
}
示例15: ini_set
<?php
ini_set( "include_path", dirname(__FILE__)."/.." );
require_once( "commandLine.inc" );
$dbr = WikiFactory::db( DB_SLAVE );
$sth = $dbr->select(
array( "city_list" ),
array( "city_dbname", "city_id" ),
array( "city_public" => 1, "city_cluster" => "c3" ),
__METHOD__
);
while( $row = $dbr->fetchObject( $sth ) ) {
if( $row->city_id == 177 ) {
continue;
}
$dbc = wfGetDB( DB_SLAVE, array( ), $row->city_dbname );
# echo "{$row->city_id} {$row->city_dbname}\n";
if( ! $dbc->fieldExists( "logging", "log_user_text" ) ) {
echo "$row->city_id\n";
}
$dbc->close();
}