function wiki_get_timestamp($widgetName, &$widgetTimestamp, &$smarty_obj) { $widgetTitle = Title::newFromText($widgetName, NS_WIDGET); if ($widgetTitle && $widgetTitle->exists()) { $widgetArticle = new Article($widgetTitle); $widgetTimestamp = $widgetArticle->getTouched(); return true; } else { return false; } }
/** * Retrieve the ParserOutput from ParserCache. * false if not found or outdated. * * @param WikiPage|Article $article * @param ParserOptions $popts * @param bool $useOutdated (default false) * * @return ParserOutput|bool False on failure */ public function get($article, $popts, $useOutdated = false) { global $wgCacheEpoch; $canCache = $article->checkTouched(); if (!$canCache) { // It's a redirect now return false; } $touched = $article->getTouched(); $parserOutputKey = $this->getKey($article, $popts, $useOutdated); if ($parserOutputKey === false) { wfIncrStats('pcache.miss.absent'); return false; } $value = $this->mMemc->get($parserOutputKey); if (!$value) { wfDebug("ParserOutput cache miss.\n"); wfIncrStats("pcache.miss.absent"); return false; } wfDebug("ParserOutput cache found.\n"); // The edit section preference may not be the appropiate one in // the ParserOutput, as we are not storing it in the parsercache // key. Force it here. See bug 31445. $value->setEditSectionTokens($popts->getEditSection()); $wikiPage = method_exists($article, 'getPage') ? $article->getPage() : $article; if (!$useOutdated && $value->expired($touched)) { wfIncrStats("pcache.miss.expired"); $cacheTime = $value->getCacheTime(); wfDebug("ParserOutput key expired, touched {$touched}, " . "epoch {$wgCacheEpoch}, cached {$cacheTime}\n"); $value = false; } elseif ($value->isDifferentRevision($article->getLatest())) { wfIncrStats("pcache.miss.revid"); $revId = $article->getLatest(); $cachedRevId = $value->getCacheRevisionId(); wfDebug("ParserOutput key is for an old revision, latest {$revId}, cached {$cachedRevId}\n"); $value = false; } elseif (Hooks::run('RejectParserCacheValue', array($value, $wikiPage, $popts)) === false) { wfIncrStats('pcache.miss.rejected'); wfDebug("ParserOutput key valid, but rejected by RejectParserCacheValue hook handler.\n"); $value = false; } else { wfIncrStats("pcache.hit"); } return $value; }
<?php $lang = 'meta'; putenv("MW_LANG={$lang}"); // notify MWMultiVersion require '/srv/mediawiki/w/MWVersion.php'; require getMediaWiki('includes/WebStart.php'); $allowed_templates = array('Www.wikimedia.org_template', 'Www.wikipedia.org_template', 'Www.wikinews.org_template', 'Www.wiktionary.org_template', 'Www.wikiquote.org_template', 'Www.wikiversity.org_template', 'Www.wikibooks.org_template', 'Www.wikivoyage.org_template', 'API_listing_template'); $template = $wgRequest->getText('template', 'Www.wikipedia.org_template'); if (!in_array($template, $allowed_templates)) { header('Content-Type: text/plain; charset=utf-8'); echo 'Invalid parameters...'; exit; } $wgTitle = Title::newFromText($template); $wgArticle = new Article($wgTitle); $rawHtml = $wgArticle->getContent(false); $lastmod = gmdate('D, j M Y H:i:s', wfTimestamp(TS_UNIX, $wgArticle->getTouched())) . ' GMT'; header('Content-Type: text/html; charset=utf-8'); header('Cache-Control: s-maxage=3600, must-revalidate, max-age=0'); header("Last-modified: {$lastmod}"); echo $rawHtml;
/** * Send ETag header with article's last modification timestamp and cache buster * * See BAC-1227 for details * * @param WikiPage $article * @param ParserOptions $popts * @param $eTag * @author macbre */ static function onParserCacheGetETag(Article $article, ParserOptions $popts, &$eTag) { global $wgStyleVersion, $wgUser, $wgCacheEpoch; $touched = $article->getTouched(); // don't emit the default touched value set in WikiPage class (see CONN-430) if ($touched === '19700101000000') { $eTag = ''; return true; } // use the same rules as in OutputPage::checkLastModified $timestamps = ['page' => $touched, 'user' => $wgUser->getTouched(), 'epoch' => $wgCacheEpoch]; $eTag = sprintf('%s-%s', max($timestamps), $wgStyleVersion); return true; }
/** * Collects metadata and additional resources for this page * @param Title $oTitle * @param DOMDocument $oPageDOM * @param array $aParams * @return array array( 'meta' => ..., 'resources' => ...); */ private static function collectData($oTitle, $oPageDOM, $aParams) { $aMeta = array(); $aResources = array('ATTACHMENT' => array(), 'STYLESHEET' => array(), 'IMAGE' => array()); // TODO RBV (01.02.12 13:51): Handle oldid $aCategories = array(); if ($oTitle->exists()) { // TODO RBV (27.06.12 11:47): Throws an exception. Maybe better use try ... catch instead of $oTitle->exists() $aAPIParams = new FauxRequest(array('action' => 'parse', 'page' => $oTitle->getPrefixedText(), 'prop' => 'images|categories|links')); $oAPI = new ApiMain($aAPIParams); $oAPI->execute(); if (defined('ApiResult::META_CONTENT')) { $aResult = $oAPI->getResult()->getResultData(null, array('BC' => array(), 'Types' => array(), 'Strip' => 'all')); } else { $aResult = $oAPI->getResultData(); } foreach ($aResult['parse']['categories'] as $aCat) { $aCategories[] = $aCat['*']; } } /* //For future use... foreach($aResult['parse']['images'] as $sFileName ) { $oImage = RepoGroup::singleton()->getLocalRepo()->newFile( Title::newFromText( $sFileName, NS_FILE ) ); if( $oImage->exists() ) { $sAbsoluteFileSystemPath = $oImage->getFullPath(); } } */ //Dublin Core: $aMeta['DC.title'] = $oTitle->getPrefixedText(); $aMeta['DC.date'] = wfTimestamp(TS_ISO_8601); // TODO RBV (14.12.10 14:01): Check for conformity. Maybe there is a better way to acquire than wfTimestamp()? //Custom global $wgLang; $sCurrentTS = $wgLang->userAdjust(wfTimestampNow()); $aMeta['title'] = $oTitle->getPrefixedText(); $aMeta['exportdate'] = $wgLang->sprintfDate('d.m.Y', $sCurrentTS); $aMeta['exporttime'] = $wgLang->sprintfDate('H:i', $sCurrentTS); $aMeta['exporttimeexact'] = $wgLang->sprintfDate('H:i:s', $sCurrentTS); //Custom - Categories->Keywords $aMeta['keywords'] = implode(', ', $aCategories); $oDOMXPath = new DOMXPath($oPageDOM); $oMetadataElements = $oDOMXPath->query("//div[@class='bs-universalexport-meta']"); foreach ($oMetadataElements as $oMetadataElement) { if ($oMetadataElement->hasAttributes()) { foreach ($oMetadataElement->attributes as $oAttribute) { if ($oAttribute->name !== 'class') { $aMeta[$oAttribute->name] = $oAttribute->value; } } } $oMetadataElement->parentNode->removeChild($oMetadataElement); } //If it's a normal article if (!in_array($oTitle->getNamespace(), array(NS_SPECIAL, NS_IMAGE, NS_CATEGORY))) { $oArticle = new Article($oTitle); $aMeta['author'] = $oArticle->getUserText(); // TODO RBV (14.12.10 12:19): Realname/Username -> DisplayName $aMeta['date'] = $wgLang->sprintfDate('d.m.Y', $oArticle->getTouched()); } wfRunHooks('BSUEModulePDFcollectMetaData', array($oTitle, $oPageDOM, &$aParams, $oDOMXPath, &$aMeta)); $aMetaDataOverrides = json_decode(BsConfig::get('MW::UniversalExport::MetadataOverrides'), true); $aMeta = array_merge($aMeta, $aMetaDataOverrides); return array('meta' => $aMeta, 'resources' => $aResources); }
/** * Retrieve the ParserOutput from ParserCache. * false if not found or outdated. * * @param Article $article * @param ParserOptions $popts * @param bool $useOutdated (default false) * * @return ParserOutput|bool False on failure */ public function get($article, $popts, $useOutdated = false) { global $wgCacheEpoch; wfProfileIn(__METHOD__); $canCache = $article->checkTouched(); if (!$canCache) { // It's a redirect now wfProfileOut(__METHOD__); return false; } $touched = $article->getTouched(); $parserOutputKey = $this->getKey($article, $popts, $useOutdated); if ($parserOutputKey === false) { wfIncrStats('pcache_miss_absent'); wfProfileOut(__METHOD__); return false; } $value = $this->mMemc->get($parserOutputKey); if (!$value) { wfDebug("ParserOutput cache miss.\n"); wfIncrStats("pcache_miss_absent"); wfProfileOut(__METHOD__); return false; } wfDebug("ParserOutput cache found.\n"); // The edit section preference may not be the appropiate one in // the ParserOutput, as we are not storing it in the parsercache // key. Force it here. See bug 31445. $value->setEditSectionTokens($popts->getEditSection()); if (!$useOutdated && $value->expired($touched)) { wfIncrStats("pcache_miss_expired"); $cacheTime = $value->getCacheTime(); wfDebug("ParserOutput key expired, touched {$touched}, " . "epoch {$wgCacheEpoch}, cached {$cacheTime}\n"); $value = false; } elseif ($value->isDifferentRevision($article->getLatest())) { wfIncrStats("pcache_miss_revid"); $revId = $article->getLatest(); $cachedRevId = $value->getCacheRevisionId(); wfDebug("ParserOutput key is for an old revision, latest {$revId}, cached {$cachedRevId}\n"); $value = false; } else { wfIncrStats("pcache_hit"); } wfProfileOut(__METHOD__); return $value; }
require_once './MWVersion.php'; require getMediaWiki('includes/WebStart.php'); $wgTitle = Title::newFromText('Mediawiki:robots.txt'); $wgArticle = new Article($wgTitle, 0); header('Content-Type: text/plain; charset=utf-8'); header('X-Article-ID: ' . $wgArticle->getID()); header('X-Language: ' . $lang); header('X-Site: ' . $site); header('Vary: X-Subdomain'); $robotsfile = '/srv/mediawiki/robots.txt'; $robots = fopen($robotsfile, 'rb'); $robotsfilestats = fstat($robots); $mtime = $robotsfilestats['mtime']; $extratext = ''; $zeroRated = isset($_SERVER['HTTP_X_SUBDOMAIN']) && $_SERVER['HTTP_X_SUBDOMAIN'] === 'ZERO'; header('Cache-Control: s-maxage=3600, must-revalidate, max-age=0'); $dontIndex = "User-agent: *\nDisallow: /\n"; if ($zeroRated) { echo $dontIndex; } elseif ($wgArticle->getID() != 0) { $extratext = $wgArticle->getContent(false); // Take last modified timestamp of page into account $mtime = max($mtime, wfTimestamp(TS_UNIX, $wgArticle->getTouched())); } elseif ($wmfRealm == 'labs') { echo $dontIndex; } $lastmod = gmdate('D, j M Y H:i:s', $mtime) . ' GMT'; header("Last-modified: {$lastmod}"); fpassthru($robots); echo "#\n#\n#----------------------------------------------------------#\n#\n#\n#\n"; echo $extratext;