/**
  * execute
  *
  * main entry point
  * @author eloy@wikia.com
  *
  * @param string $subpage: subpage of Title
  *
  * @return nothing
  */
 public function execute($subpage)
 {
     global $wgUser, $wgOut, $wgRequest, $wgWikiaBatchTasks;
     if ($wgUser->isBlocked()) {
         throw new UserBlockedError($this->getUser()->mBlock);
     }
     if (wfReadOnly()) {
         $wgOut->readOnlyPage();
         return;
     }
     if (!$wgUser->isAllowed('taskmanager')) {
         $this->displayRestrictionError();
         return;
     }
     $wgOut->setPageTitle(wfMsg('taskmanager_title'));
     $wgOut->setRobotpolicy('noindex,nofollow');
     $wgOut->setArticleRelated(false);
     $this->mTitle = Title::makeTitle(NS_SPECIAL, "TaskManager");
     $this->mAction = $wgRequest->getVal("action");
     if ($this->mAction) {
         switch ($this->mAction) {
             case "task":
                 #--- get task type and class
                 $sClass = $wgRequest->getText("wpType", null);
                 if (is_subclass_of($sClass, "BatchTask")) {
                     $oObject = new $sClass();
                     #--- get form for this class
                     $wgOut->addHTML($oObject->getForm($this->mTitle));
                 }
                 $wgOut->addHTML(XML::element("a", array("href" => $this->mTitle->getLocalUrl(), wfMsg("taskmanager_tasklist"))));
                 break;
             case "save":
                 #--- get task type and class
                 $sType = $wgRequest->getText("wpType", null);
                 $sClass = $wgWikiaBatchTasks[$sType];
                 if (is_subclass_of($sClass, "BatchTask")) {
                     $oObject = new $sClass();
                     $aFormData = $oObject->submitForm();
                     if ($aFormData === true) {
                         #--- all correct, show new task form
                         $this->loadTaskForm();
                     } else {
                         #--- errors, show again form for choosen task
                         $wgOut->addHTML($oObject->getForm($this->mTitle, $aFormData));
                     }
                 }
                 $wgOut->addHTML(Wikia::linkTag($this->mTitle->getLocalUrl(), wfMsg("taskmanager_tasklist")));
                 break;
                 /**
                  * get task form for given id, NOTE - it should check if
                  * task is editable or not
                  */
             /**
              * get task form for given id, NOTE - it should check if
              * task is editable or not
              */
             case "edit":
                 $oTask = $this->loadTaskData($wgRequest->getVal("id"));
                 #--- nothing so far
                 break;
                 /**
                  * remove task from database, carefull - without confirmation
                  * so far
                  */
             /**
              * remove task from database, carefull - without confirmation
              * so far
              */
             case "remove":
                 #--- check if task exists
                 $oTask = $this->loadTaskData($wgRequest->getVal("id"));
                 if (!empty($oTask->task_id)) {
                     $this->removeTask($oTask->task_id);
                     $wgOut->addHTML(Wikia::successbox("Task nr {$oTask->task_id} removed"));
                 } else {
                     $wgOut->addHTML(Wikia::errorbox("Task doesn't exists"));
                 }
                 $this->loadTaskForm();
                 $this->loadPager();
                 break;
                 /**
                  * start task, possible only when task in TASK_WAITING state
                  */
             /**
              * start task, possible only when task in TASK_WAITING state
              */
             case "start":
                 #--- check if task exists
                 $oTask = $this->loadTaskData($wgRequest->getVal("id"));
                 if (!empty($oTask->task_id) && $oTask->task_status == TASK_WAITING) {
                     $this->changeTaskStatus($oTask->task_id, TASK_QUEUED);
                     $wgOut->addHTML(Wikia::successbox("Task nr {$oTask->task_id} queued"));
                 } else {
                     $wgOut->addHTML(Wikia::errorbox("Task doesn't exists"));
                 }
                 $this->loadTaskForm();
                 $this->loadPager();
                 break;
                 /**
                  * stop task, possible only when task in TASK_QUEUED state
                  */
             /**
              * stop task, possible only when task in TASK_QUEUED state
              */
             case "stop":
                 #--- check if task exists
                 $oTask = $this->loadTaskData($wgRequest->getVal("id"));
                 if (!empty($oTask->task_id) && $oTask->task_status == TASK_QUEUED) {
                     $this->changeTaskStatus($oTask->task_id, TASK_WAITING);
                     $wgOut->addHTML(Wikia::successbox("Task nr {$oTask->task_id} paused"));
                 } else {
                     $wgOut->addHTML(Wikia::errorbox("Task doesn't exists"));
                 }
                 $this->loadTaskForm();
                 $this->loadPager();
                 break;
                 /**
                  * terminate running task
                  */
             /**
              * terminate running task
              */
             case "finish":
                 $oTaskData = $this->loadTaskData($wgRequest->getVal("id"));
                 if (!empty($oTaskData->task_id)) {
                     $oTask = BatchTask::newFromData($oTaskData);
                     $oTask->closeTask();
                     $wgOut->addHTML(Wikia::successbox("Task nr {$oTaskData->task_id} stopped"));
                 } else {
                     $wgOut->addHTML(Wikia::errorbox("Task doesn't exists"));
                 }
                 $this->loadTaskForm();
                 $this->loadPager();
                 break;
                 /**
                  * show log for closed task
                  */
             /**
              * show log for closed task
              */
             case "log":
                 #--- check if task exists
                 $oTaskData = $this->loadTaskData($wgRequest->getVal("id"));
                 if (!empty($oTaskData->task_id)) {
                     $oTask = BatchTask::newFromData($oTaskData);
                     $oTmpl = new EasyTemplate(dirname(__FILE__) . "/templates/");
                     $oTmpl->set_vars(array("events" => $oTask->getLog(true)));
                     $wgOut->addHTML($oTmpl->render("log"));
                 }
                 $this->loadTaskForm();
                 $this->loadPager();
                 break;
                 /**
                  * add a restore task for this specific task
                  * currently it works only for COMPLETED MultiDelete tasks
                  */
             /**
              * add a restore task for this specific task
              * currently it works only for COMPLETED MultiDelete tasks
              */
             case "undo":
                 #--- check if task exists
                 $oTaskData = $this->loadTaskData($wgRequest->getVal("id"));
                 if (!empty($oTaskData->task_id)) {
                     $oTask = BatchTask::newFromData($oTaskData);
                     /* add a new restore task here
                     		   todo differentiate between single and multi mode
                     		 */
                     $thisTask = new MultiRestoreTask(true);
                     if (TASK_FINISHED_UNDO != $oTaskData->task_status) {
                         $arguments = unserialize($oTaskData->task_arguments);
                         $thisTask->mArguments = $arguments;
                         $thisTask->mMode = $arguments["mode"];
                         $thisTask->mAdmin = $wgUser->getName();
                         $thisTask->mMotherTask = $oTaskData->task_id;
                         $submit_id = $thisTask->submitForm();
                         $wgOut->addHTML(Wikia::successbox("Task nr {$oTaskData->task_id} was scheduled to be undone"));
                         $this->changeTaskStatus($oTaskData->task_id, TASK_FINISHED_UNDO);
                     } else {
                         $wgOut->addHTML(Wikia::errorbox("Task {$oTaskData->task_id} was already set to undo"));
                     }
                 }
                 $this->loadTaskForm();
                 $this->loadPager();
                 break;
                 /**
                  * default action, just show task form
                  */
             /**
              * default action, just show task form
              */
             default:
                 $this->loadTaskForm();
                 break;
         }
     } else {
         $this->loadTaskForm();
         $this->loadPager();
     }
 }