/**
  * @param Workflow $workflow
  * @param IContextSource $context
  * @param AbstractBlock[] $blocks
  * @param string $action
  * @param array $parameters
  * @return AbstractBlock[]
  * @throws InvalidActionException
  * @throws InvalidDataException
  */
 public function handleSubmit(Workflow $workflow, IContextSource $context, array $blocks, $action, array $parameters)
 {
     // since this is a submit force dbFactory to always return master
     $this->dbFactory->forceMaster();
     /** @var Block[] $interestedBlocks */
     $interestedBlocks = array();
     foreach ($blocks as $block) {
         // This is just a check whether the block understands the action,
         // Doesn't consider permissions
         if ($block->canSubmit($action)) {
             $block->init($context, $action);
             $interestedBlocks[] = $block;
         }
     }
     if (!$interestedBlocks) {
         if (!$blocks) {
             throw new InvalidDataException('No Blocks?!?', 'fail-load-data');
         }
         $type = array();
         foreach ($blocks as $block) {
             $type[] = get_class($block);
         }
         // All blocks returned null, nothing knows how to handle this action
         throw new InvalidActionException("No block accepted the '{$action}' action: " . implode(',', array_unique($type)), 'invalid-action');
     }
     // Check mediawiki core permissions for title protection, blocked
     // status, etc.
     if (!$workflow->userCan('edit', $context->getUser())) {
         reset($interestedBlocks)->addError('block', wfMessage('blockedtitle'));
         return array();
     }
     $success = true;
     foreach ($interestedBlocks as $block) {
         $name = $block->getName();
         $data = isset($parameters[$name]) ? $parameters[$name] : array();
         $success &= $block->onSubmit($data);
     }
     return $success ? $interestedBlocks : array();
 }