function __construct($conf, $type, $key)
 {
     parent::__construct($conf, $type, $key);
     if (!self::$manager) {
         global $wgPoolCountClientConf;
         self::$manager = new PoolCounter_ConnectionManager($wgPoolCountClientConf);
     }
 }
 function __construct($conf, $type, $key)
 {
     parent::__construct($conf, $type, $key);
     $this->serversByLabel = $conf['servers'];
     $this->ring = new HashRing(array_fill_keys(array_keys($conf['servers']), 100));
     $conf['redisConfig']['serializer'] = 'none';
     // for use with Lua
     $this->pool = RedisConnectionPool::singleton($conf['redisConfig']);
     $this->keySha1 = sha1($this->key);
     $met = ini_get('max_execution_time');
     // usually 0 in CLI mode
     $this->lockTTL = $met ? 2 * $met : 3600;
     if (self::$active === null) {
         self::$active = array();
         register_shutdown_function(array(__CLASS__, 'releaseAll'));
     }
 }
示例#3
0
 function __construct($type, $key)
 {
     $this->poolCounter = PoolCounter::factory($type, $key);
 }
示例#4
0
 /**
  * This is the default action of the index.php entry point: just view the
  * page of the given title.
  */
 public function view()
 {
     global $wgUser, $wgOut, $wgRequest, $wgContLang;
     global $wgEnableParserCache, $wgStylePath, $wgParser;
     global $wgUseTrackbacks, $wgUseFileCache;
     wfProfileIn(__METHOD__);
     # Get variables from query string
     $oldid = $this->getOldID();
     $parserCache = ParserCache::singleton();
     $parserOptions = clone $this->getParserOptions();
     # Render printable version, use printable version cache
     if ($wgOut->isPrintable()) {
         $parserOptions->setIsPrintable(true);
     }
     # Try client and file cache
     if ($oldid === 0 && $this->checkTouched()) {
         global $wgUseETag;
         if ($wgUseETag) {
             $wgOut->setETag($parserCache->getETag($this, $parserOptions));
         }
         # Is is client cached?
         if ($wgOut->checkLastModified($this->getTouched())) {
             wfDebug(__METHOD__ . ": done 304\n");
             wfProfileOut(__METHOD__);
             return;
             # Try file cache
         } else {
             if ($wgUseFileCache && $this->tryFileCache()) {
                 wfDebug(__METHOD__ . ": done file cache\n");
                 # tell wgOut that output is taken care of
                 $wgOut->disable();
                 $this->viewUpdates();
                 wfProfileOut(__METHOD__);
                 return;
             }
         }
     }
     $sk = $wgUser->getSkin();
     # getOldID may want us to redirect somewhere else
     if ($this->mRedirectUrl) {
         $wgOut->redirect($this->mRedirectUrl);
         wfDebug(__METHOD__ . ": redirecting due to oldid\n");
         wfProfileOut(__METHOD__);
         return;
     }
     $wgOut->setArticleFlag(true);
     # Set page title (may be overridden by DISPLAYTITLE)
     $wgOut->setPageTitle($this->mTitle->getPrefixedText());
     # If we got diff in the query, we want to see a diff page instead of the article.
     if (!is_null($wgRequest->getVal('diff'))) {
         wfDebug(__METHOD__ . ": showing diff page\n");
         $this->showDiffPage();
         wfProfileOut(__METHOD__);
         return;
     }
     # Should the parser cache be used?
     $useParserCache = $this->useParserCache($oldid);
     wfDebug('Article::view using parser cache: ' . ($useParserCache ? 'yes' : 'no') . "\n");
     if ($wgUser->getOption('stubthreshold')) {
         wfIncrStats('pcache_miss_stub');
     }
     $wasRedirected = $this->showRedirectedFromHeader();
     $this->showNamespaceHeader();
     # Iterate through the possible ways of constructing the output text.
     # Keep going until $outputDone is set, or we run out of things to do.
     $pass = 0;
     $outputDone = false;
     $this->mParserOutput = false;
     while (!$outputDone && ++$pass) {
         switch ($pass) {
             case 1:
                 wfRunHooks('ArticleViewHeader', array(&$this, &$outputDone, &$useParserCache));
                 break;
             case 2:
                 # Try the parser cache
                 if ($useParserCache) {
                     $this->mParserOutput = $parserCache->get($this, $parserOptions);
                     if ($this->mParserOutput !== false) {
                         wfDebug(__METHOD__ . ": showing parser cache contents\n");
                         $wgOut->addParserOutput($this->mParserOutput);
                         # Ensure that UI elements requiring revision ID have
                         # the correct version information.
                         $wgOut->setRevisionId($this->mLatest);
                         $outputDone = true;
                     }
                 }
                 break;
             case 3:
                 $text = $this->getContent();
                 if ($text === false || $this->getID() == 0) {
                     wfDebug(__METHOD__ . ": showing missing article\n");
                     $this->showMissingArticle();
                     wfProfileOut(__METHOD__);
                     return;
                 }
                 # Another whitelist check in case oldid is altering the title
                 if (!$this->mTitle->userCanRead()) {
                     wfDebug(__METHOD__ . ": denied on secondary read check\n");
                     $wgOut->loginToUse();
                     $wgOut->output();
                     $wgOut->disable();
                     wfProfileOut(__METHOD__);
                     return;
                 }
                 # Are we looking at an old revision
                 if ($oldid && !is_null($this->mRevision)) {
                     $this->setOldSubtitle($oldid);
                     if (!$this->showDeletedRevisionHeader()) {
                         wfDebug(__METHOD__ . ": cannot view deleted revision\n");
                         wfProfileOut(__METHOD__);
                         return;
                     }
                     # If this "old" version is the current, then try the parser cache...
                     if ($oldid === $this->getLatest() && $this->useParserCache(false)) {
                         $this->mParserOutput = $parserCache->get($this, $parserOptions);
                         if ($this->mParserOutput) {
                             wfDebug(__METHOD__ . ": showing parser cache for current rev permalink\n");
                             $wgOut->addParserOutput($this->mParserOutput);
                             $wgOut->setRevisionId($this->mLatest);
                             $this->showViewFooter();
                             $this->viewUpdates();
                             wfProfileOut(__METHOD__);
                             return;
                         }
                     }
                 }
                 # Ensure that UI elements requiring revision ID have
                 # the correct version information.
                 $wgOut->setRevisionId($this->getRevIdFetched());
                 # Pages containing custom CSS or JavaScript get special treatment
                 if ($this->mTitle->isCssOrJsPage() || $this->mTitle->isCssJsSubpage()) {
                     wfDebug(__METHOD__ . ": showing CSS/JS source\n");
                     $this->showCssOrJsPage();
                     $outputDone = true;
                 } else {
                     if ($rt = Title::newFromRedirectArray($text)) {
                         wfDebug(__METHOD__ . ": showing redirect=no page\n");
                         # Viewing a redirect page (e.g. with parameter redirect=no)
                         # Don't append the subtitle if this was an old revision
                         $wgOut->addHTML($this->viewRedirect($rt, !$wasRedirected && $this->isCurrent()));
                         # Parse just to get categories, displaytitle, etc.
                         $this->mParserOutput = $wgParser->parse($text, $this->mTitle, $parserOptions);
                         $wgOut->addParserOutputNoText($this->mParserOutput);
                         $outputDone = true;
                     }
                 }
                 break;
             case 4:
                 # Run the parse, protected by a pool counter
                 wfDebug(__METHOD__ . ": doing uncached parse\n");
                 $key = $parserCache->getKey($this, $parserOptions);
                 $poolCounter = PoolCounter::factory('Article::view', $key);
                 $dirtyCallback = $useParserCache ? array($this, 'tryDirtyCache') : false;
                 $status = $poolCounter->executeProtected(array($this, 'doViewParse'), $dirtyCallback);
                 if (!$status->isOK()) {
                     # Connection or timeout error
                     $this->showPoolError($status);
                     wfProfileOut(__METHOD__);
                     return;
                 } else {
                     $outputDone = true;
                 }
                 break;
                 # Should be unreachable, but just in case...
             # Should be unreachable, but just in case...
             default:
                 break 2;
         }
     }
     # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
     if ($this->mParserOutput) {
         $titleText = $this->mParserOutput->getTitleText();
         if (strval($titleText) !== '') {
             $wgOut->setPageTitle($titleText);
         }
     }
     # For the main page, overwrite the <title> element with the con-
     # tents of 'pagetitle-view-mainpage' instead of the default (if
     # that's not empty).
     if ($this->mTitle->equals(Title::newMainPage()) && ($m = wfMsgForContent('pagetitle-view-mainpage')) !== '') {
         $wgOut->setHTMLTitle($m);
     }
     # Now that we've filled $this->mParserOutput, we know whether
     # there are any __NOINDEX__ tags on the page
     $policy = $this->getRobotPolicy('view');
     $wgOut->setIndexPolicy($policy['index']);
     $wgOut->setFollowPolicy($policy['follow']);
     $this->showViewFooter();
     $this->viewUpdates();
     wfProfileOut(__METHOD__);
 }