public function testSortByOption() { $user = User::newFromId(1); $user->setOption('flow-topiclist-sortby', ''); // reset flow state, so everything ($container['permissions']) // uses this particular $user \FlowHooks::resetFlowExtension(); Container::reset(); $container = Container::getContainer(); $container['user'] = $user; $ctx = $this->getMock('IContextSource'); $ctx->expects($this->any())->method('getUser')->will($this->returnValue($user)); $workflow = Workflow::create('discussion', Title::newFromText('Talk:Flow_QA')); $block = new TopicListBlock($workflow, Container::get('storage')); $block->init($ctx, 'view'); $res = $block->renderApi(array()); $this->assertEquals('newest', $res['sortby'], 'With no sortby defaults to newest'); $res = $block->renderApi(array('sortby' => 'foo')); $this->assertEquals('newest', $res['sortby'], 'With invalid sortby defaults to newest'); $res = $block->renderApi(array('sortby' => 'updated')); $this->assertEquals('updated', $res['sortby'], 'With sortby updated output changes to updated'); $res = $block->renderApi(array()); $this->assertEquals('newest', $res['sortby'], 'Sort still defaults to newest'); $res = $block->renderApi(array('sortby' => 'updated', 'savesortby' => '1')); $this->assertEquals('updated', $res['sortby'], 'Request saving sortby option'); $res = $block->renderApi(array()); $this->assertEquals('updated', $res['sortby'], 'Default sortby now changed to updated'); $res = $block->renderApi(array('sortby' => '')); $this->assertEquals('updated', $res['sortby'], 'Default sortby with blank sortby still uses user default'); }
public function setUp() { parent::setUp(); // reset flow state, so everything ($container['permissions']) // uses this particular $user \FlowHooks::resetFlowExtension(); Container::reset(); $container = Container::getContainer(); $container['user'] = User::newFromName('127.0.0.1', false); }
/** * Ensures Flow is reset before passing control on * to parent::doApiRequest. Defaults all requests to * the sysop user if not specified. */ protected function doApiRequest(array $params, array $session = null, $appendModule = false, User $user = null) { if ($user === null) { $user = self::$users['sysop']->user; } // reset flow state before each request FlowHooks::resetFlowExtension(); Container::reset(); $container = Container::getContainer(); $container['user'] = $user; return parent::doApiRequest($params, $session, $appendModule, $user); }
/** * @dataProvider objectManagerKeyProvider */ public function testSomething($key) { $c = Container::getContainer(); $this->assertNotNull($c[$key]); foreach ($c["{$key}.indexes"] as $pos => $index) { $this->assertInstanceOf('Flow\\Data\\Index', $index, "At {$key}.indexes[{$pos}]"); } if (isset($c["{$key}.listeners"])) { foreach ($c["{$key}.listeners"] as $pos => $listener) { $this->assertInstanceOf("Flow\\Data\\LifecycleHandler", $listener, "At {$key}.listeners[{$pos}]"); } } }
protected function doDBUpdates() { $container = Container::getContainer(); $dbFactory = $container['db.factory']; $dbw = $dbFactory->getDb(DB_MASTER); $storage = $container['storage']; $moderationLoggingListener = $container['storage.post.listeners.moderation_logging']; $rowIterator = new EchoBatchRowIterator($dbw, 'flow_revision', 'rev_id', $this->mBatchSize); $rowIterator->setFetchColumns(array('rev_id', 'rev_type')); // Fetch rows that are a moderation action $rowIterator->addConditions(array('rev_change_type' => ModerationLoggingListener::getModerationChangeTypes(), 'rev_user_wiki' => wfWikiID())); $start = $this->getOption('start'); $startId = UUID::create($start); $rowIterator->addConditions(array('rev_id > ' . $dbw->addQuotes($startId->getBinary()))); $stop = $this->getOption('stop'); $stopId = UUID::create($stop); $rowIterator->addConditions(array('rev_id < ' . $dbw->addQuotes($stopId->getBinary()))); $total = $fail = 0; foreach ($rowIterator as $batch) { $dbw->begin(); foreach ($batch as $row) { $total++; $objectManager = $storage->getStorage($row->rev_type); $revId = UUID::create($row->rev_id); $obj = $objectManager->get($revId); if (!$obj) { $this->error('Could not load revision: ' . $revId->getAlphadecimal()); $fail++; continue; } $workflow = $obj->getCollection()->getWorkflow(); $moderationLoggingListener->onAfterInsert($obj, array(), array('workflow' => $workflow)); } $dbw->commit(); $storage->clear(); $dbFactory->waitForSlaves(); } $this->output("Processed a total of {$total} moderation revisions.\n"); if ($fail !== 0) { $this->error("Errors were encountered while processing {$fail} of them.\n"); } return true; }
/** * @param string $action * @param OutputPage|null $output * @throws ErrorPageError * @throws FlowException */ public function showForAction($action, OutputPage $output = null) { $container = Container::getContainer(); $occupationController = \FlowHooks::getOccupationController(); if ($output === null) { $output = $this->context->getOutput(); } // Check if this is actually a Flow page. if (!$this->page instanceof WikiPage && !$this->page instanceof Article) { throw new ErrorPageError('nosuchaction', 'flow-action-unsupported'); } $title = $this->page->getTitle(); if (!$occupationController->isTalkpageOccupied($title)) { throw new ErrorPageError('nosuchaction', 'flow-action-unsupported'); } // @todo much of this seems to duplicate BoardContent::getParserOutput $view = new View($container['url_generator'], $container['lightncandy'], $output, $container['flow_actions']); $request = $this->context->getRequest(); // BC for urls pre july 2014 with workflow query parameter $redirect = $this->getRedirectUrl($request, $title); if ($redirect) { $output->redirect($redirect); return; } $action = $request->getVal('action', 'view'); try { /** @var WorkflowLoaderFactory $factory */ $factory = $container['factory.loader.workflow']; $loader = $factory->createWorkflowLoader($title); if ($title->getNamespace() === NS_TOPIC && $loader->getWorkflow()->getType() !== 'topic') { // @todo better error handling throw new FlowException('Invalid title: uuid is not a topic'); } $view->show($loader, $action); } catch (FlowException $e) { $e->setOutput($output); throw $e; } }
/** * {@inheritDoc} */ public function onSubmit($data) { // Replace $c['memcache'] with a hash bag o stuff. This will look to the // application layer like an empty cache, and as such it will populate this // empty cache with all the cache keys required to reload this page. // We then extract the complete list of keys updated from this hash bag o stuff // and delete them from the real memcache. // The container must be reset prior to this because the TitleSquidURLs hook // will initialize memcache before this is run when UseSquid is enabled. Container::reset(); $container = Container::getContainer(); $container->extend('memcache', function ($memcache, $c) { $c['memcache.purge_backup'] = $memcache; return new HashBagOStuff(); }); $this->hashBag = $container['memcache']; $this->realMemcache = $container['memcache.purge_backup']; if (!parent::onSubmit(array())) { return false; } /** @var WorkflowLoaderFactory $loader */ $loader = $container['factory.loader.workflow']; $workflow = $loader->createWorkflowLoader($this->page->getTitle())->getWorkflow(); switch ($workflow->getType()) { case 'discussion': $this->fetchDiscussion($workflow); break; case 'topic': $this->fetchTopics(array($workflow->getId()->getAlphadecimal() => $workflow->getId())); break; default: throw new \MWException('Unknown workflow type: ' . $workflow->getType()); } // delete all the keys we just visited $this->purgeCache(); return true; }
protected function clearExtraLifecycleHandlers() { $container = Container::getContainer(); foreach (array_unique($container['storage.manager_list']) as $storage) { if (!isset($container["{$storage}.listeners"])) { continue; } $container->extend("{$storage}.listeners", function ($listeners) { unset($listeners['storage.post.listeners.notification'], $listeners['listener.recentchanges'], $listeners['storage.board_history.indexes.primary']); return $listeners; }); } }
/** * @dataProvider onIRCLineUrlProvider */ public function testOnIRCLineUrl($message, $metadataGen, $expectedQuery) { $user = User::newFromName('127.0.0.1', false); // reset flow state, so everything ($container['permissions']) // uses this particular $user \FlowHooks::resetFlowExtension(); Container::reset(); $container = Container::getContainer(); $container['user'] = $user; $rc = new RecentChange(); $rc->mAttribs = array('rc_namespace' => 0, 'rc_title' => 'Main Page', 'rc_source' => RecentChangesListener::SRC_FLOW); $metadata = $metadataGen($user); Container::get('formatter.irclineurl')->associate($rc, $metadata); $url = 'unset'; $query = 'unset'; $this->assertTrue(FlowHooks::onIRCLineURL($url, $query, $rc)); $expectedQuery['title'] = $metadata['workflow']->getArticleTitle()->getPrefixedDBkey(); $parts = parse_url($url); $this->assertArrayHasKey('query', $parts, $url); parse_str($parts['query'], $queryParts); foreach ($expectedQuery as $key => $value) { $this->assertEquals($value, $queryParts[$key], "Query part {$key}"); } $this->assertEquals('', $query, $message); }