public static function singleton() { if (self::$instance == null) { self::$instance = new self(); } return self::$instance; }
public function testStableFileVersions() { $im = FRInclusionManager::singleton(); $im->setReviewedVersions(array(), array()); $im->setStableVersionCache(self::$inputTemplates, self::$inputFiles); foreach (self::$stableOutputFiles as $triple) { list($test, $dbKey, $expTS, $expSha1) = $triple; $title = Title::makeTitleSafe(NS_FILE, $dbKey); list($actualTS, $actualSha1) = $im->getStableFileVersion($title); $this->assertEquals($expTS, $actualTS, "Timestamp test: {$test}"); $this->assertEquals($expSha1, $actualSha1, "Sha1 test: {$test}"); } }
/** * Get the HTML output of a revision. * @param FlaggedRevision $frev * @param ParserOptions $pOpts * @return ParserOutput|null */ public static function parseStableRevision(FlaggedRevision $frev, ParserOptions $pOpts) { # Notify Parser if includes should be stabilized $resetManager = false; $incManager = FRInclusionManager::singleton(); if ($frev->getRevId() && self::inclusionSetting() != FR_INCLUDES_CURRENT) { # Use FRInclusionManager to do the template/file version query # up front unless the versions are already specified there... if (!$incManager->parserOutputIsStabilized()) { $incManager->stabilizeParserOutput($frev); $resetManager = true; // need to reset when done } } # Parse the new body $content = $frev->getRevision()->getContent(); if ($content === null) { return null; // missing revision } $parserOut = $content->getParserOutput($frev->getTitle(), $frev->getRevId(), $pOpts); # Stable parse done! if ($resetManager) { $incManager->clear(); // reset the FRInclusionManager as needed } return $parserOut; }
/** * Get the HTML output of a revision based on $text. * @param Title $title * @param string $text * @param int $id Source revision Id * @param ParserOptions $pOpts * @return ParserOutput */ public static function parseStableText(Title $title, $text, $id, ParserOptions $pOpts) { global $wgParser; # Notify Parser if includes should be stabilized $resetManager = false; $incManager = FRInclusionManager::singleton(); if ($id && self::inclusionSetting() != FR_INCLUDES_CURRENT) { # Use FRInclusionManager to do the template/file version query # up front unless the versions are already specified there... if (!$incManager->parserOutputIsStabilized()) { $frev = FlaggedRevision::newFromTitle($title, $id); if ($frev) { $incManager->stabilizeParserOutput($frev); $resetManager = true; // need to reset when done } } } # Parse the new body, wikitext -> html $parserOut = $wgParser->parse($text, $title, $pOpts, true, true, $id); # Stable parse done! if ($resetManager) { $incManager->clear(); // reset the FRInclusionManager as needed } return $parserOut; }
/** * Select the desired images based on the selected stable version time/SHA-1 */ public static function parserFetchStableFile($parser, Title $title, &$options, &$query) { if (!$parser instanceof Parser) { return true; // nothing to do } $incManager = FRInclusionManager::singleton(); if (!$incManager->parserOutputIsStabilized()) { return true; // trigger for stable version parsing only } # Normalize NS_MEDIA to NS_FILE if ($title->getNamespace() == NS_MEDIA) { $title = Title::makeTitle(NS_FILE, $title->getDBkey()); $title->resetArticleId($title->getArticleID()); // avoid extra queries } # Check if this file is only on a foreign repo $file = wfFindFile($title); if ($file && !$file->isLocal()) { return true; // just use the current version (bug 41832) } $time = $sha1 = false; // unspecified (defaults to current version) # Check for the version of this file used when reviewed... list($maybeTS, $maybeSha1) = $incManager->getReviewedFileVersion($title); if ($maybeTS !== null) { $time = $maybeTS; // use if specified (even '0') $sha1 = $maybeSha1; } # Check for stable version of file if this feature is enabled... if (FlaggedRevs::inclusionSetting() == FR_INCLUDES_STABLE) { list($maybeTS, $maybeSha1) = $incManager->getStableFileVersion($title); # Take the newest of these two... if ($maybeTS && $maybeTS > $time) { $time = $maybeTS; $sha1 = $maybeSha1; } } # Tell Parser what file version to use if ($time === '0') { $options['broken'] = true; } elseif ($time !== false) { $options['time'] = $time; $options['sha1'] = $sha1; # Stabilize the file link if ($query != '') { $query .= '&'; } $query .= "filetimestamp=" . urlencode(wfTimestamp(TS_MW, $time)); } return true; }