/**
  * Special page's entry point
  */
 public function execute($par)
 {
     //set action to have some value(not empty)
     $this->action = $this->request->getVal('action', 'edit');
     $this->request->setVal('action', $this->action);
     $value = $this->getField($this->titleFieldName);
     if ($this->initializeTitle($value) === false) {
         return;
     }
     $this->addHiddenField(array('name' => $this->pageIdFieldName, 'type' => 'hidden', 'label' => false, 'valuefromrequest' => $this->pageIdFieldName, 'value' => $this->getTitle()->getArticleID(), 'required' => true));
     $pageTitle = $this->getPageTitle();
     if (!empty($pageTitle)) {
         $this->setPageTitle($pageTitle);
     }
     if (class_exists('CategorySelectHooksHelper')) {
         CategorySelectHooksHelper::onMediaWikiPerformAction(null, null, $pageTitle, null, null, null, false);
     }
     // (try to) create instance of custom EditPage class
     $this->mEditPage = $this->initializeEditPage();
     if (!$this->mEditPage instanceof EditPage) {
         return;
     }
     $this->mEditPage->hideTitle = $this->hideTitle;
     $this->afterArticleInitialize($this->mode, $this->getEditedArticle()->getTitle(), $this->getEditedArticle());
     $this->setUpControlButtons();
     // handle POSTed requests as AJAX requests
     if ($this->request->wasPosted()) {
         $method = $this->request->getVal('method');
         // execute processXxxx method
         if (!empty($method)) {
             $this->log(__METHOD__, "post request - '{$method}'");
             $methodName = 'process' . ucfirst($method);
             // use POSTed "title" value
             if (method_exists($this, $methodName)) {
                 $data = $this->{$methodName}();
                 $this->request->response()->header('application/json; charset=utf-8');
                 $this->out->setArticleBodyOnly(true);
                 $this->out->addHtml(json_encode($data));
                 // leave now - just emit JSON
                 return;
             }
         }
         // prepare for MW save
         if ($this->action == 'submit') {
             $this->log(__METHOD__, 'saving...');
             $this->log(__METHOD__, $this->request->getValues());
             $content = trim($this->getWikitextFromRequest());
             $this->request->setVal('wpTextbox1', $content);
             $this->contentStatus = null;
             if ($content == '') {
                 $this->contentStatus = EditPage::AS_BLANK_ARTICLE;
             }
             // perform additional checks
             $this->processSubmit();
             // check for notices
             if (!empty($this->mEditNotices)) {
                 $this->log(__METHOD__, 'preveting');
             }
         }
     }
     // set this special page as a custom handler of save / preview / show changes requests
     $this->mEditPage->setCustomFormHandler(Title::makeTitle(NS_SPECIAL, $this->mName));
     // preload text if
     $preloadedText = $this->getWikitextForPreload();
     if ($preloadedText !== false) {
         $this->mEditPage->setPreloadedText($preloadedText);
     }
     $this->mEditPage->mSpecialPage = $this;
     // render edit form
     $this->mEditPage->lastSaveStatus = null;
     $this->renderHeader($par);
     foreach ($this->editNoticesStack as $editNotice) {
         $this->mEditPage->addEditNotice($editNotice);
     }
     foreach ($this->mHiddenFields as $field) {
         $this->mEditPage->addHiddenField($field);
     }
     // render special page setup method
     $this->mEditPage->submit();
     if (!empty($this->mEditPage->lastSaveStatus)) {
         $this->afterSave($this->mEditPage->lastSaveStatus);
     }
     $this->renderFooter($par);
     // set custom page title
     $this->out->setPageTitle($this->mPageTitle);
 }
 protected function parseFormData()
 {
     global $wgRequest;
     // create EditPage object
     $this->createEditPage($this->mFormData['postBody']);
     if (!count($this->mFormErrors) && $wgRequest->getVal('wpPreview')) {
         // preview mode
         $this->mEditPage->formtype = 'preview';
         $this->mPreviewTitle = Title::newFromText($this->mFormData['postTitle']);
         // simple hack to show correct title in preview mode
         global $wgCustomTitle;
         $wgCustomTitle = $this->mPreviewTitle;
         // CategorySelect compatibility (add categories to article body)
         if ($this->mCategorySelectEnabled) {
             CategorySelectHooksHelper::onEditPageImportFormData($this->mEditPage, $wgRequest);
         }
     }
 }
 protected function save()
 {
     global $wgOut, $wgUser, $wgContLang, $wgRequest;
     // CategorySelect compatibility (add categories to article body)
     if ($this->mCategorySelectEnabled) {
         CategorySelectHooksHelper::onEditPageImportFormData($this->mEditPage, $wgRequest);
     }
     $sPostBody = $this->mEditPage->textbox1;
     $editPage = new EditPage($this->mPostArticle);
     $editPage->initialiseForm();
     $editPage->textbox1 = $sPostBody;
     $editPage->summary = isset($this->mFormData['postEditSummary']) ? $this->mFormData['postEditSummary'] : '';
     $editPage->recreate = true;
     $result = false;
     $status = $editPage->internalAttemptSave($result);
     switch ($status->value) {
         case EditPage::AS_SUCCESS_UPDATE:
         case EditPage::AS_SUCCESS_NEW_ARTICLE:
         case EditPage::AS_ARTICLE_WAS_DELETED:
             $wgOut->redirect($this->mPostArticle->getTitle()->getFullUrl());
             break;
         default:
             /**
              * PLATFORM-1160: Log the entire $status to ELK
              *
              * Recommendation: use $status->value for comparisons and messages rather than $status in the following block.
              */
             Wikia\Logger\WikiaLogger::instance()->warning('PLATFORM-1160', ['method' => __METHOD__, 'status_object' => $status]);
             if ($status->value == EditPage::AS_READ_ONLY_PAGE_LOGGED || $status->value == EditPage::AS_READ_ONLY_PAGE_ANON) {
                 $sMsg = wfMsg('createpage_cant_edit');
             } else {
                 $sMsg = wfMsg('createpage_spam');
             }
             $this->mFormErrors[] = $sMsg . " ({$status->value})";
             global $wgCreatePageCaptchaTriggered;
             // do not display form - there is already one invoked from Captcha [RT#21902] - Marooned
             if (empty($wgCreatePageCaptchaTriggered)) {
                 $this->renderForm();
             }
             break;
     }
 }
 private function parseArticle($sTitle)
 {
     global $wgParser, $wgContLang;
     $oTitle = Title::newFromText($sTitle, NS_BLOG_ARTICLE);
     $oArticle = new Article($oTitle, 0);
     // macbre: RT #37120
     $sArticleBody = $oTitle->exists() ? $oArticle->getContent() : '';
     $aPageProps = BlogArticle::getProps($oArticle->getId());
     $aTitleParts = explode('/', $oTitle->getText(), 2);
     $this->mFormData['postId'] = $oArticle->getId();
     $this->mFormData['postTitle'] = $aTitleParts[1];
     $this->mFormData['postBody'] = trim(preg_replace('/\\[\\[' . $wgContLang->getFormattedNsText(NS_CATEGORY) . ':(.*)\\]\\]/siU', '', $sArticleBody));
     $this->mFormData['postBody'] = $sArticleBody;
     $this->mFormData['isVotingEnabled'] = isset($aPageProps['voting']) ? $aPageProps['voting'] : 0;
     $this->mFormData['isCommentingEnabled'] = isset($aPageProps['commenting']) ? $aPageProps['commenting'] : 0;
     $this->mFormData['isExistingArticleEditAllowed'] = 1;
     //create EditPage object
     $this->createEditPage($this->mFormData['postBody']);
     // CategorySelect compatibility (restore categories from article body)
     if ($this->mCategorySelectEnabled) {
         CategorySelectHooksHelper::onEditPageGetContentEnd($this->mEditPage, $this->mEditPage->textbox1);
     }
     return $oArticle;
 }