public function getDiff($wikitext, $section = '') { wfProfileIn(__METHOD__); $section = intval($section); // create "fake" EditPage if (function_exists('CategorySelectInitializeHooks')) { CategorySelectInitializeHooks(null, null, $this->mTitle, null, null, null, true); } $article = new Article($this->mTitle); $editPage = new EditPage($article); $editPage->textbox1 = $wikitext; $editPage->edittime = null; $editPage->section = $section > 0 ? $section : ''; // render diff HTML to $wgOut $out = $this->app->getGlobal('wgOut'); $oldHtml = $out->getHTML(); $out->clearHTML(); $editPage->showDiff(); $diff = $out->getHTML(); // restore state of output $out->clearHTML(); $out->addHTML($oldHtml); wfProfileOut(__METHOD__); return $diff; }
public function execute() { global $wgRequest, $wgUser; $wgRequest->setVal('action', 'edit'); // force CategorySelect initialisation if available if (function_exists('CategorySelectInit') && function_exists('CategorySelectInitializeHooks') && $wgUser->getOption('disablecategoryselect', false) == false) { $this->mCategorySelectEnabled = true; $FORCE_INIT = true; CategorySelectInit($FORCE_INIT); CategorySelectInitializeHooks(null, null, $this->mTitle, null, null, null); } }
/** * 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)); // TODO: call appriopriate hook instead of a function if (function_exists('CategorySelectInitializeHooks')) { CategorySelectInitializeHooks($this->out, $this->getEditedArticle(), $this->getEditedArticle()->getTitle(), $this->user, $this->request, null, true); } $pageTitle = $this->getPageTitle(); if (!empty($pageTitle)) { $this->setPageTitle($pageTitle); } // (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); }
public function execute() { global $wgOut, $wgUser, $wgRequest, $wgTitle; if (!$wgUser->isLoggedIn()) { $wgOut->showErrorPage('create-blog-no-login', 'create-blog-login-required', array(wfGetReturntoParam())); return; } if ($wgUser->isBlocked()) { throw new UserBlockedError($this->getUser()->mBlock); } if (wfReadOnly()) { $wgOut->readOnlyPage(); return; } //nAndy: bugId:9804 $pageId = intval($wgRequest->getVal('pageId')); $this->mTitle = $pageId > 0 ? Title::newFromId($pageId) : Title::makeTitle(NS_SPECIAL, 'CreateBlogPage'); // force CategorySelect initialisation if available if (function_exists('CategorySelectInitializeHooks') && $wgUser->getOption('disablecategoryselect', false) == false) { $this->mCategorySelectEnabled = true; $wgRequest->setVal('action', 'edit'); CategorySelectInit(true); CategorySelectInitializeHooks(null, null, $this->mTitle, null, null, null); } $wgOut->setPageTitle(wfMsg("create-blog-post-title")); if ($wgRequest->wasPosted()) { // BugId:954 - check for "show changes" $isShowDiff = !is_null($wgRequest->getVal('wpDiff')); $this->parseFormData(); if (count($this->mFormErrors) > 0 || !empty($this->mPreviewTitle)) { $this->renderForm(); } else { if ($isShowDiff) { // watch out! there be dragons (temporary workaround) $this->mEditPage->diff = true; $this->mEditPage->edittime = null; $this->renderForm(); } else { $this->save(); } } } else { if ($wgRequest->getVal('article') != null) { $this->parseArticle(urldecode($wgRequest->getVal('article'))); } else { if ($wgRequest->getText('preload') != null) { // TOR: added preload functionality $preloadTitle = Title::newFromText($wgRequest->getText('preload')); if (!is_null($preloadTitle)) { $preloadArticle = new Article($preloadTitle); $text = $preloadArticle->getContent(); $this->createEditPage($text); } } else { if ($pageId > 0) { //nAndy: bugId:9804 Owen: bugId:11432 $preloadTitle = Title::newFromId($pageId); if (!is_null($preloadTitle)) { $this->parseArticle($preloadTitle->getDBKey()); } } else { $this->createEditPage(''); } } } $this->renderForm(); } }