/**
  * 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;
 }
 /**
  * @dataProvider decideArchiveTitleProvider
  */
 public function testDecideArchiveTitle($message, $expect, Title $source, array $formats, array $exists)
 {
     // flip so we can use isset
     $existsByKey = array_flip($exists);
     $titleRepo = $this->getMock('Flow\\Repository\\TitleRepository');
     $titleRepo->expects($this->any())->method('exists')->will($this->returnCallback(function (Title $title) use($existsByKey) {
         return isset($existsByKey[$title->getPrefixedText()]);
     }));
     $result = Converter::decideArchiveTitle($source, $formats, $titleRepo);
     $this->assertEquals($expect, $result, $message);
 }
 /**
  * Flow does not support viewing the history of the wikitext pages it takes
  * over, so those need to be moved out the way. This method decides that
  * destination. The archived revisions include the headers displayed with
  * lqt and potentially any pre-lqt wikitext talk page content.
  *
  * @param Title $source
  * @return Title
  */
 public function decideArchiveTitle(Title $source)
 {
     return Converter::decideArchiveTitle($source, array('%s/LQT Archive %d'));
 }
 /**
  * {@inheritDoc}
  */
 public function decideArchiveTitle(Title $source)
 {
     return Converter::decideArchiveTitle($source, $this->archiveTitleSuggestions);
 }