/** * Creates a flow board. * Archives any pre-existing wikitext talk page. * * @param array $data Form data * @return Status Status indicating result */ public function onSubmit(array $data) { $page = $data['page']; $title = Title::newFromText($page); if (!$title) { return Status::newFatal('flow-special-enableflow-invalid-title', $page); } // Canonicalize so the error or confirmation message looks nicer (no underscores). $page = $title->getPrefixedText(); if ($this->occupationController->isTalkpageOccupied($title, true)) { return Status::newFatal('flow-special-enableflow-board-already-exists', $page); } $status = Status::newGood(); if ($title->exists(Title::GAID_FOR_UPDATE)) { if (class_exists('LqtDispatch') && \LqtDispatch::isLqtPage($title)) { return Status::newFatal('flow-special-enableflow-page-is-liquidthreads', $page); } $logger = Container::get('default_logger'); $converter = new Converter(wfGetDB(DB_MASTER), Container::get('importer'), $logger, $this->occupationController->getTalkpageManager(), new EnableFlowWikitextConversionStrategy(Container::get('parser'), new NullImportSourceStore(), $logger, array(), $data['header'])); try { $converter->convert($title); } catch (\Exception $e) { \MWExceptionHandler::logException($e); $status->fatal('flow-error-external', $e->getMessage()); } } else { $allowCreationStatus = $this->occupationController->allowCreation($title, $this->getUser(), false); if (!$allowCreationStatus->isGood()) { return Status::newFatal('flow-special-enableflow-board-creation-not-allowed', $page); } $loader = $this->loaderFactory->createWorkflowLoader($title); $blocks = $loader->getBlocks(); $action = 'edit-header'; $params = array('header' => array('content' => $data['header'], 'format' => 'wikitext')); $blocksToCommit = $loader->handleSubmit($this->getContext(), $action, $params); foreach ($blocks as $block) { if ($block->hasErrors()) { $errors = $block->getErrors(); foreach ($errors as $errorKey) { $status->fatal($block->getErrorMessage($errorKey)); } } } $loader->commit($blocksToCommit); } $this->page = $data['page']; return $status; }
/** * @param array $watchlistInfo Watchlisted pages * @return bool */ public static function onWatchlistEditorBeforeFormRender(&$watchlistInfo) { if (!isset($watchlistInfo[NS_TOPIC])) { // No topics watchlisted return true; } $ids = array_keys($watchlistInfo[NS_TOPIC]); // build array of queries to be executed all at once $queries = array(); foreach ($ids as $id) { try { $uuid = WorkflowLoaderFactory::uuidFromTitlePair(NS_TOPIC, $id); $queries[] = array('rev_type_id' => $uuid); } catch (Exception $e) { // invalid id unset($watchlistInfo[NS_TOPIC][$id]); } } /** @var Flow\Data\ManagerGroup $storage */ $storage = Container::get('storage'); /* * Now, finally find all requested topics - this will be stored in * local cache so subsequent calls (in onWatchlistEditorBuildRemoveLine) * will just find these in memory, instead of doing a bunch of network * requests. */ $storage->findMulti('PostRevision', $queries, array('sort' => 'rev_id', 'order' => 'DESC', 'limit' => 1)); return true; }
/** * Imports topics from a data source to a given page. * * @param IImportSource $source * @param Title $targetPage * @param ImportSourceStore $sourceStore * @return bool True When the import completes with no failures */ public function import(IImportSource $source, Title $targetPage, ImportSourceStore $sourceStore) { $operation = new TalkpageImportOperation($source, $this->occupationController); $pageImportState = new PageImportState($this->workflowLoaderFactory->createWorkflowLoader($targetPage)->getWorkflow(), $this->storage, $sourceStore, $this->logger ?: new NullLogger(), $this->cache, $this->dbFactory, $this->postprocessors, $this->deferredQueue, $this->allowUnknownUsernames); return $operation->import($pageImportState); }