当前位置: 首页>>代码示例>>PHP>>正文


PHP IDatabase::getWikiID方法代码示例

本文整理汇总了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
     });
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:29,代码来源:Revision.php

示例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);
     }
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:56,代码来源:ResourceLoaderWikiModule.php


注:本文中的IDatabase::getWikiID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。