本文整理汇总了PHP中IDatabase::getWikiID方法的典型用法代码示例。如果您正苦于以下问题:PHP IDatabase::getWikiID方法的具体用法?PHP IDatabase::getWikiID怎么用?PHP IDatabase::getWikiID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDatabase
的用法示例。
在下文中一共展示了IDatabase::getWikiID方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: newKnownCurrent
/**
* Load a revision based on a known page ID and current revision ID from the DB
*
* This method allows for the use of caching, though accessing anything that normally
* requires permission checks (aside from the text) will trigger a small DB lookup.
* The title will also be lazy loaded, though setTitle() can be used to preload it.
*
* @param IDatabase $db
* @param int $pageId Page ID
* @param int $revId Known current revision of this page
* @return Revision|bool Returns false if missing
* @since 1.28
*/
public static function newKnownCurrent(IDatabase $db, $pageId, $revId)
{
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
return $cache->getWithSetCallback($cache->makeGlobalKey('revision', $db->getWikiID(), $pageId, $revId), $cache::TTL_WEEK, function ($curValue, &$ttl, array &$setOpts) use($db, $pageId, $revId) {
$setOpts += Database::getCacheSetOptions($db);
$rev = Revision::loadFromPageId($db, $pageId, $revId);
// Reflect revision deletion and user renames
if ($rev) {
$rev->mTitle = null;
// mutable; lazy-load
$rev->mRefreshMutableFields = true;
}
return $rev ?: false;
// don't cache negatives
});
}
示例2: preloadTitleInfo
/**
* @since 1.28
* @param ResourceLoaderContext $context
* @param IDatabase $db
* @param string[] $moduleNames
*/
public static function preloadTitleInfo(ResourceLoaderContext $context, IDatabase $db, array $moduleNames)
{
$rl = $context->getResourceLoader();
// getDB() can be overridden to point to a foreign database.
// For now, only preload local. In the future, we could preload by wikiID.
$allPages = [];
/** @var ResourceLoaderWikiModule[] $wikiModules */
$wikiModules = [];
foreach ($moduleNames as $name) {
$module = $rl->getModule($name);
if ($module instanceof self) {
$mDB = $module->getDB();
// Subclasses may disable getDB and implement getTitleInfo differently
if ($mDB && $mDB->getWikiID() === $db->getWikiID()) {
$wikiModules[] = $module;
$allPages += $module->getPages($context);
}
}
}
$pageNames = array_keys($allPages);
sort($pageNames);
$hash = sha1(implode('|', $pageNames));
// Avoid Zend bug where "static::" does not apply LSB in the closure
$func = [static::class, 'fetchTitleInfo'];
$fname = __METHOD__;
$cache = ObjectCache::getMainWANInstance();
$allInfo = $cache->getWithSetCallback($cache->makeGlobalKey('resourceloader', 'titleinfo', $db->getWikiID(), $hash), $cache::TTL_HOUR, function ($curVal, &$ttl, array &$setOpts) use($func, $pageNames, $db, $fname) {
$setOpts += Database::getCacheSetOptions($db);
return call_user_func($func, $db, $pageNames, $fname);
}, ['checkKeys' => [$cache->makeGlobalKey('resourceloader', 'titleinfo', $db->getWikiID())]]);
foreach ($wikiModules as $wikiModule) {
$pages = $wikiModule->getPages($context);
// Before we intersect, map the names to canonical form (T145673).
$intersect = [];
foreach ($pages as $page => $unused) {
$title = Title::newFromText($page);
if ($title) {
$intersect[$title->getPrefixedText()] = 1;
} else {
// Page name may be invalid if user-provided (e.g. gadgets)
$rl->getLogger()->info('Invalid wiki page title "{title}" in ' . __METHOD__, ['title' => $page]);
}
}
$info = array_intersect_key($allInfo, $intersect);
$pageNames = array_keys($pages);
sort($pageNames);
$key = implode('|', $pageNames);
$wikiModule->setTitleInfo($key, $info);
}
}