public function commit()
 {
     switch ($this->action) {
         case 'undo-edit-header':
         case 'edit-header':
             $this->workflow->updateLastModified($this->newRevision->getRevisionId());
             $this->storage->put($this->workflow, array());
             // 'discussion' workflow
             $this->storage->put($this->newRevision, array('workflow' => $this->workflow));
             // Reload $this->header for renderApi() after save
             $this->header = $this->newRevision;
             return array('header-revision-id' => $this->newRevision->getRevisionId());
         default:
             throw new InvalidActionException('Unrecognized commit action', 'invalid-action');
     }
 }
 public static function onIRCLineURLProvider()
 {
     // data providers do not run in the same context as the actual test, as such we
     // can't create Title objects because they can have the wrong wikiID.  Instead we
     // pass closures into the test that create the objects within the correct context.
     $newHeader = function (User $user) {
         $title = Title::newFromText('Talk:Hook_test');
         $workflow = Container::get('factory.loader.workflow')->createWorkflowLoader($title)->getWorkflow();
         $header = Header::create($workflow, $user, 'header content', 'wikitext');
         $metadata = array('workflow' => $workflow, 'revision' => $header);
         /** @var OccupationController $occupationController */
         $occupationController = Container::get('occupation_controller');
         // make sure user has rights to create board
         $user->mRights = array_merge($user->getRights(), array('flow-create-board'));
         $occupationController->allowCreation($title, $user);
         $occupationController->ensureFlowRevision(new \Article($title), $workflow);
         Container::get('storage')->put($workflow, $metadata);
         return $metadata;
     };
     $freshTopic = function (User $user) {
         $title = Title::newFromText('Talk:Hook_test');
         $boardWorkflow = Container::get('factory.loader.workflow')->createWorkflowLoader($title)->getWorkflow();
         $topicWorkflow = Workflow::create('topic', $boardWorkflow->getArticleTitle());
         $topicList = TopicListEntry::create($boardWorkflow, $topicWorkflow);
         $topicTitle = PostRevision::create($topicWorkflow, $user, 'some content', 'wikitext');
         $metadata = array('workflow' => $topicWorkflow, 'board-workflow' => $boardWorkflow, 'topic-title' => $topicTitle, 'revision' => $topicTitle);
         /** @var OccupationController $occupationController */
         $occupationController = Container::get('occupation_controller');
         // make sure user has rights to create board
         $user->mRights = array_merge($user->getRights(), array('flow-create-board'));
         $occupationController->allowCreation($title, $user);
         $occupationController->ensureFlowRevision(new \Article($title), $boardWorkflow);
         $storage = Container::get('storage');
         $storage->put($boardWorkflow, $metadata);
         $storage->put($topicWorkflow, $metadata);
         $storage->put($topicList, $metadata);
         $storage->put($topicTitle, $metadata);
         return $metadata;
     };
     $replyToTopic = function (User $user) use($freshTopic) {
         $metadata = $freshTopic($user);
         $firstPost = $metadata['topic-title']->reply($metadata['workflow'], $user, 'ffuts dna ylper', 'wikitext');
         $metadata = array('first-post' => $firstPost, 'revision' => $firstPost) + $metadata;
         Container::get('storage.post')->put($firstPost, $metadata);
         return $metadata;
     };
     return array(array('Freshly created topic', $freshTopic, array('action' => 'history')), array('Reply to topic', $replyToTopic, array('action' => 'history')), array('Edit topic title', function ($user) use($freshTopic) {
         $metadata = $freshTopic($user);
         $title = $metadata['workflow']->getArticleTitle();
         return array('revision' => $metadata['revision']->newNextRevision($user, 'gnihtemos gnihtemos', 'wikitext', 'edit-title', $title)) + $metadata;
     }, array('action' => 'compare-post-revisions')), array('Edit post', function ($user) use($replyToTopic) {
         $metadata = $replyToTopic($user);
         $title = $metadata['workflow']->getArticleTitle();
         return array('revision' => $metadata['revision']->newNextRevision($user, 'IT\'S CAPS LOCKS DAY!', 'wikitext', 'edit-post', $title)) + $metadata;
     }, array('action' => 'compare-post-revisions')), array('Edit board header', function ($user) use($newHeader) {
         $metadata = $newHeader($user);
         $title = $metadata['workflow']->getArticleTitle();
         return array('revision' => $metadata['revision']->newNextRevision($user, 'STILL CAPS LOCKS DAY!', 'wikitext', 'edit-header', $title)) + $metadata;
     }, array('action' => 'compare-header-revisions')), array('Moderate a post', function ($user) use($replyToTopic) {
         $metadata = $replyToTopic($user);
         return array('revision' => $metadata['revision']->moderate($user, $metadata['revision']::MODERATED_DELETED, 'delete-post', 'something about cruise control')) + $metadata;
     }, array('action' => 'history')), array('Moderate a topic', function ($user) use($freshTopic) {
         $metadata = $freshTopic($user);
         return array('revision' => $metadata['revision']->moderate($user, $metadata['revision']::MODERATED_HIDDEN, 'hide-topic', 'adorable kittens')) + $metadata;
     }, array('action' => 'history')));
 }
 /**
  * @param PageImportState $pageState
  * @param IImportHeader   $importHeader
  */
 public function importHeader(PageImportState $pageState, IImportHeader $importHeader)
 {
     $pageState->logger->info('Importing header');
     if (!$importHeader->getRevisions()->valid()) {
         $pageState->logger->info('no revisions located for header');
         // No revisions
         return;
     }
     $existingId = $pageState->getImportedId($importHeader);
     if ($existingId && $pageState->getTopRevision('Header', $existingId)) {
         $pageState->logger->info('header previously imported');
         return;
     }
     $revisions = $this->importObjectWithHistory($importHeader, function (IObjectRevision $rev) use($pageState) {
         return Header::create($pageState->boardWorkflow, $pageState->createUser($rev->getAuthor()), $rev->getText(), 'wikitext', 'create-header');
     }, 'edit-header', $pageState, $pageState->boardWorkflow->getArticleTitle());
     $pageState->put($revisions, array('workflow' => $pageState->boardWorkflow));
     $pageState->recordAssociation(reset($revisions)->getCollectionId(), $importHeader);
     $pageState->logger->info('Imported ' . count($revisions) . ' revisions for header');
 }