function setUp()
 {
     global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList, $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache, $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo, $parserMemc, $wgThumbnailScriptPath, $wgScriptPath, $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
     $wgScript = '/index.php';
     $wgScriptPath = '/';
     $wgArticlePath = '/wiki/$1';
     $wgStyleSheetPath = '/skins';
     $wgStylePath = '/skins';
     $wgThumbnailScriptPath = false;
     $wgLocalFileRepo = array('class' => 'LocalRepo', 'name' => 'local', 'directory' => wfTempDir() . '/test-repo', 'url' => 'http://example.com/images', 'deletedDir' => wfTempDir() . '/test-repo/delete', 'hashLevels' => 2, 'transformVia404' => false);
     $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
     $wgNamespaceAliases['Image'] = NS_FILE;
     $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
     $wgEnableParserCache = false;
     $wgDeferredUpdateList = array();
     $wgMemc = wfGetMainCache();
     $messageMemc = wfGetMessageCacheStorage();
     $parserMemc = wfGetParserCacheStorage();
     // $wgContLang = new StubContLang;
     $wgUser = new User();
     $context = new RequestContext();
     $wgLang = $context->getLang();
     $wgOut = $context->getOutput();
     $wgParser = new StubObject('wgParser', $wgParserConf['class'], array($wgParserConf));
     $wgRequest = new WebRequest();
     if ($wgStyleDirectory === false) {
         $wgStyleDirectory = "{$IP}/skins";
     }
 }
Example #2
0
 function setUp()
 {
     global $wgContLang, $wgNamespaceProtection, $wgNamespaceAliases;
     global $wgHooks, $IP;
     $wgContLang = Language::factory('en');
     //Setup CLI arguments
     if ($this->getCliArg('regex=')) {
         $this->regex = $this->getCliArg('regex=');
     } else {
         # Matches anything
         $this->regex = '';
     }
     $this->keepUploads = $this->getCliArg('keep-uploads');
     $tmpGlobals = array();
     $tmpGlobals['wgScript'] = '/index.php';
     $tmpGlobals['wgScriptPath'] = '/';
     $tmpGlobals['wgArticlePath'] = '/wiki/$1';
     $tmpGlobals['wgStyleSheetPath'] = '/skins';
     $tmpGlobals['wgStylePath'] = '/skins';
     $tmpGlobals['wgThumbnailScriptPath'] = false;
     $tmpGlobals['wgLocalFileRepo'] = array('class' => 'LocalRepo', 'name' => 'local', 'url' => 'http://example.com/images', 'hashLevels' => 2, 'transformVia404' => false, 'backend' => 'local-backend');
     $tmpGlobals['wgForeignFileRepos'] = array();
     $tmpGlobals['wgEnableParserCache'] = false;
     $tmpGlobals['wgHooks'] = $wgHooks;
     $tmpGlobals['wgDeferredUpdateList'] = array();
     $tmpGlobals['wgMemc'] = wfGetMainCache();
     $tmpGlobals['messageMemc'] = wfGetMessageCacheStorage();
     $tmpGlobals['parserMemc'] = wfGetParserCacheStorage();
     // $tmpGlobals['wgContLang'] = new StubContLang;
     $tmpGlobals['wgUser'] = new User();
     $context = new RequestContext();
     $tmpGlobals['wgLang'] = $context->getLanguage();
     $tmpGlobals['wgOut'] = $context->getOutput();
     $tmpGlobals['wgParser'] = new StubObject('wgParser', $GLOBALS['wgParserConf']['class'], array($GLOBALS['wgParserConf']));
     $tmpGlobals['wgRequest'] = $context->getRequest();
     if ($GLOBALS['wgStyleDirectory'] === false) {
         $tmpGlobals['wgStyleDirectory'] = "{$IP}/skins";
     }
     foreach ($tmpGlobals as $var => $val) {
         if (array_key_exists($var, $GLOBALS)) {
             $this->savedInitialGlobals[$var] = $GLOBALS[$var];
         }
         $GLOBALS[$var] = $val;
     }
     $this->savedWeirdGlobals['mw_namespace_protection'] = $wgNamespaceProtection[NS_MEDIAWIKI];
     $this->savedWeirdGlobals['image_alias'] = $wgNamespaceAliases['Image'];
     $this->savedWeirdGlobals['image_talk_alias'] = $wgNamespaceAliases['Image_talk'];
     $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
     $wgNamespaceAliases['Image'] = NS_FILE;
     $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
 }
 public static function suite()
 {
     $suite = new PHPUnit_Framework_TestSuite();
     self::$iter = new TestFileIterator(PARSER_TESTS);
     foreach (self::$iter as $i => $test) {
         $suite->addTest(new ParserUnitTest($i, $test['test']));
         self::$count++;
     }
     unset($tests);
     self::$parser = new PTShell();
     self::$iter->setParser(self::$parser);
     self::$parser->recorder->start();
     self::$parser->setupDatabase();
     self::$iter->rewind();
     /* } */
     /* function setUp() { */
     global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList, $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache, $wgMessageCache, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $parserMemc, $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo, $wgNamespacesWithSubpages, $wgThumbnailScriptPath, $wgScriptPath, $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
     $wgScript = '/index.php';
     $wgScriptPath = '/';
     $wgArticlePath = '/wiki/$1';
     $wgStyleSheetPath = '/skins';
     $wgStylePath = '/skins';
     $wgThumbnailScriptPath = false;
     $wgLocalFileRepo = array('class' => 'LocalRepo', 'name' => 'local', 'directory' => '', 'url' => 'http://example.com/images', 'hashLevels' => 2, 'transformVia404' => false);
     $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
     $wgNamespaceAliases['Image'] = NS_FILE;
     $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
     $wgEnableParserCache = false;
     $wgDeferredUpdateList = array();
     $wgMemc =& wfGetMainCache();
     $messageMemc =& wfGetMessageCacheStorage();
     $parserMemc =& wfGetParserCacheStorage();
     $wgContLang = new StubContLang();
     $wgUser = new StubUser();
     $wgLang = new StubUserLang();
     $wgOut = new StubObject('wgOut', 'OutputPage');
     $wgParser = new StubObject('wgParser', $wgParserConf['class'], array($wgParserConf));
     $wgRequest = new WebRequest();
     $wgMessageCache = new StubObject('wgMessageCache', 'MessageCache', array($messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID()));
     if ($wgStyleDirectory === false) {
         $wgStyleDirectory = "{$IP}/skins";
     }
     return $suite;
 }
 function execute()
 {
     $inputDate = $this->getOption('expiredate');
     $inputAge = $this->getOption('age');
     if ($inputDate !== null) {
         $date = wfTimestamp(TS_MW, strtotime($inputDate));
     } elseif ($inputAge !== null) {
         global $wgParserCacheExpireTime;
         $date = wfTimestamp(TS_MW, time() + $wgParserCacheExpireTime - intval($inputAge));
     } else {
         $this->error("Must specify either --expiredate or --age", 1);
     }
     $english = Language::factory('en');
     $this->output("Deleting objects expiring before " . $english->timeanddate($date) . "\n");
     $pc = wfGetParserCacheStorage();
     $success = $pc->deleteObjectsExpiringBefore($date, array($this, 'showProgress'));
     if (!$success) {
         $this->error("\nCannot purge this kind of parser cache.", 1);
     }
     $this->showProgress(100);
     $this->output("\nDone\n");
 }
 protected function setUp()
 {
     global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgParserCacheType, $wgNamespaceAliases, $wgNamespaceProtection, $parserMemc;
     $tmpDir = $this->getNewTempDirectory();
     $tmpGlobals = [];
     $tmpGlobals['wgScript'] = '/index.php';
     $tmpGlobals['wgScriptPath'] = '/';
     $tmpGlobals['wgArticlePath'] = '/wiki/$1';
     $tmpGlobals['wgStylePath'] = '/skins';
     $tmpGlobals['wgThumbnailScriptPath'] = false;
     $tmpGlobals['wgLocalFileRepo'] = ['class' => 'LocalRepo', 'name' => 'local', 'url' => 'http://example.com/images', 'hashLevels' => 2, 'transformVia404' => false, 'backend' => new FSFileBackend(['name' => 'local-backend', 'wikiId' => wfWikiID(), 'containerPaths' => ['local-public' => "{$tmpDir}/test-repo/public", 'local-thumb' => "{$tmpDir}/test-repo/thumb", 'local-temp' => "{$tmpDir}/test-repo/temp", 'local-deleted' => "{$tmpDir}/test-repo/delete"]])];
     foreach ($tmpGlobals as $var => $val) {
         if (array_key_exists($var, $GLOBALS)) {
             $this->savedGlobals[$var] = $GLOBALS[$var];
         }
         $GLOBALS[$var] = $val;
     }
     $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
     $wgNamespaceAliases['Image'] = NS_FILE;
     $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
     $wgParserCacheType = CACHE_NONE;
     DeferredUpdates::clearPendingUpdates();
     $wgMemc = wfGetMainCache();
     $messageMemc = wfGetMessageCacheStorage();
     $parserMemc = wfGetParserCacheStorage();
     RequestContext::resetMain();
     $context = RequestContext::getMain();
     $wgUser = new User();
     $wgLang = $context->getLanguage();
     $wgOut = $context->getOutput();
     $wgParser = new StubObject('wgParser', $wgParserConf['class'], [$wgParserConf]);
     $wgRequest = $context->getRequest();
     if ($wgStyleDirectory === false) {
         $wgStyleDirectory = "{$IP}/skins";
     }
     RepoGroup::destroySingleton();
     FileBackendGroup::destroySingleton();
 }
Example #6
0
 function execute()
 {
     $inputDate = $this->getOption('expiredate');
     $inputAge = $this->getOption('age');
     if ($inputDate !== null) {
         $date = wfTimestamp(TS_MW, strtotime($inputDate));
     } elseif ($inputAge !== null) {
         global $wgParserCacheExpireTime;
         $date = wfTimestamp(TS_MW, time() + $wgParserCacheExpireTime - intval($inputAge));
     } else {
         echo "Must specify either --expiredate or --age\n";
         exit(1);
     }
     $english = Language::factory('en');
     echo "Deleting objects expiring before " . $english->timeanddate($date) . "\n";
     $pc = wfGetParserCacheStorage();
     $success = $pc->deleteObjectsExpiringBefore($date);
     if (!$success) {
         echo "Cannot purge this kind of parser cache.\n";
         exit(1);
     }
     echo "Done\n";
 }
Example #7
0
    wfDebug("\n\nStart command line script {$self}\n");
} else {
    $debug = "\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n";
    if ($wgDebugPrintHttpHeaders) {
        $debug .= "HTTP HEADERS:\n";
        foreach ($wgRequest->getAllHeaders() as $name => $value) {
            $debug .= "{$name}: {$value}\n";
        }
    }
    wfDebug($debug);
}
Profiler::instance()->scopedProfileOut($ps_misc);
$ps_memcached = Profiler::instance()->scopedProfileIn($fname . '-memcached');
$wgMemc = wfGetMainCache();
$messageMemc = wfGetMessageCacheStorage();
$parserMemc = wfGetParserCacheStorage();
wfDebugLog('caches', 'cluster: ' . get_class($wgMemc) . ', WAN: ' . ($wgMainWANCache === CACHE_NONE ? 'CACHE_NONE' : $wgMainWANCache) . ', stash: ' . $wgMainStash . ', message: ' . get_class($messageMemc) . ', parser: ' . get_class($parserMemc) . ', session: ' . get_class(ObjectCache::getInstance($wgSessionCacheType)));
Profiler::instance()->scopedProfileOut($ps_memcached);
// Most of the config is out, some might want to run hooks here.
Hooks::run('SetupAfterCache');
$ps_globals = Profiler::instance()->scopedProfileIn($fname . '-globals');
/**
 * @var Language $wgContLang
 */
$wgContLang = Language::factory($wgLanguageCode);
$wgContLang->initContLang();
// Now that variant lists may be available...
$wgRequest->interpolateTitle();
if (!is_object($wgAuth)) {
    $wgAuth = new MediaWiki\Auth\AuthManagerAuthPlugin();
    Hooks::run('AuthPluginSetup', [&$wgAuth]);
Example #8
0
 /**
  * Verifies if parser caching is available
  * 
  * @return $result boolean
  */
 protected function verifyParserCache(&$cache = null)
 {
     $cache = wfGetParserCacheStorage();
     return $cache instanceof FakeMemCachedClient ? false : true;
 }
Example #9
0
 function view($usecache = true)
 {
     global $wgUser, $wgOut;
     $fname = 'NewsFeedPage::view';
     wfDebug("{$fname}: start\n");
     $note = '';
     $ims = @$_SERVER['HTTP_IF_MODIFIED_SINCE'];
     //TODO: cache control!
     if ($ims && $usecache) {
         $lastchange = wfTimestamp(TS_UNIX, NewsRenderer::getLastChangeTime());
         wfDebug("{$fname}: checking cache-ok:  IMS {$ims} vs. changed {$lastchange} \n");
         if ($wgOut->checkLastModified($lastchange)) {
             wfDebug("{$fname}: HTTP cache ok, 304 header sent \n");
             return;
             // done, 304 header sent.
         }
     }
     //NOTE: do caching for anon users only, because of user-specific
     //      rendering of textual content
     if ($wgUser->isAnon() && $usecache) {
         $cachekey = $this->getCacheKey();
         $ocache = wfGetParserCacheStorage();
         $e = $ocache ? $ocache->get($cachekey) : null;
         $note .= ' anon;';
         $debug = $e ? "got cached" : "no cached";
         wfDebug("{$fname}: ({$debug}) \n");
     } else {
         if (!$usecache) {
             wfDebug("{$fname}: purge, ignoring cache \n");
             $note .= ' purged;';
         } else {
             wfDebug("{$fname}: logged in, ignoring cache \n");
             $note .= ' user;';
         }
         $cachekey = null;
         $ocache = null;
         $e = null;
         $note .= ' user;';
     }
     $wgOut->disable();
     if ($e) {
         if (!isset($lastchange)) {
             $lastchange = wfTimestamp(TS_UNIX, NewsRenderer::getLastChangeTime());
         }
         $last = wfTimestamp(TS_UNIX, $lastchange);
         if ($last < $e['timestamp']) {
             wfDebug("{$fname}: outputting cached copy ({$cacheKey}): {$last} < " . $e['timestamp'] . " \n");
             header('Content-Type: application/' . $this->mFeedFormat . '+xml; charset=UTF-8');
             print $e['xml'];
             print "\n<!-- cached: {$note} -->\n";
             return;
             //done
         } else {
             wfDebug("{$fname}: found stale cached copy ({$cacheKey}): {$last} <= " . $e['timestamp'] . " \n");
             $note .= " stale: {$last} >= {$e['timestamp']};";
         }
     }
     //TODO: fetch actual news data and check the newest item. re-apply cache checks.
     //      this would still save the cost of rendering if the data didn't change
     global $wgParser;
     //evil global
     $wgParser->startExternalParse($this->mTitle, new ParserOptions(), Parser::OT_HTML, true);
     //FIXME: an EXTREMELY ugly hack to force generation of absolute links.
     //       this is needed because Title::getLocalUrl check wgRequest to see
     //       if absolute urls are requested, instead of it being a parser option.
     $_REQUEST['action'] = 'render';
     $renderer = NewsRenderer::newFromArticle($this, $wgParser);
     if (!$renderer) {
         wfDebug("{$fname}: no feed found on page: " . $this->mTitle->getPrefixedText() . "\n");
         wfHttpError(404, "Not Found", "no feed found on page: " . $this->mTitle->getPrefixedText());
         //TODO: better code & text
         return;
     }
     $description = '';
     //TODO: grab from article content... but what? and how?
     $ts = time();
     //this also sends the right headers
     $xml = $renderer->renderFeed($this->mFeedFormat, $description);
     wfDebug("{$fname}: rendered feed \n");
     $e = array('xml' => $xml, 'timestamp' => $ts);
     if ($ocache) {
         wfDebug("{$fname}: caching feed ({$cachekey}) \n");
         $ocache->set($cachekey, $e, $ts + 24 * 60 * 60);
         //cache for max 24 hours; cached record is discarded when anything turns up in RC anyway.
         $note .= ' updated;';
     }
     wfDebug("{$fname}: outputting fresh feed \n");
     header('Content-Type: application/' . $this->mFeedFormat . '+xml; charset=UTF-8');
     print $xml;
     print "\n<!-- fresh: {$note} -->\n";
 }