/** * Get a diff between the current contents of the edit box and the * version of the page we're editing from. * * If this is a section edit, we'll replace the section as for final * save and then make a comparison. */ function showDiff() { $oldtext = $this->mArticle->fetchContent(); $newtext = $this->mArticle->replaceSection($this->section, $this->textbox1, $this->summary, $this->edittime); wfRunHooks('EditPageGetDiffText', array($this, &$newtext)); $newtext = $this->mArticle->preSaveTransform($newtext); $oldtitle = wfMsgExt('currentrev', array('parseinline')); $newtitle = wfMsgExt('yourtext', array('parseinline')); if ($oldtext !== false || $newtext != '') { $de = new DifferenceEngine($this->mTitle); $de->setText($oldtext, $newtext); $difftext = $de->getDiff($oldtitle, $newtitle); $de->showDiffStyle(); } else { $difftext = ''; } global $wgOut; $wgOut->addHTML('<div id="wikiDiff">' . $difftext . '</div>'); }
function upload() { $details = null; $this->content = 'error'; $up = new UploadFromFile(); $up->initializeFromRequest($this->wg->request); $permErrors = $up->verifyPermissions($this->wg->user); if ($permErrors !== true) { $this->status = self::UPLOAD_PERMISSION_ERROR; $this->statusMessage = $this->uploadMessage($this->status, null); } else { if (empty($this->wg->EnableUploads)) { // BugId:6122 $this->statusMessage = wfMsg('uploaddisabled'); } else { $details = $up->verifyUpload(); $this->status = is_array($details) ? $details['status'] : UploadBase::UPLOAD_VERIFICATION_ERROR; $this->statusMessage = ''; if ($this->status > 0) { $this->statusMessage = $this->uploadMessage($this->status, $details); } else { $titleText = $this->request->getVal('title'); $sectionNumber = $this->request->getVal('section', 0); $this->status = $up->performUpload('', '', '', $this->wg->user); $mainArticle = new Article(Title::newFromText($titleText)); if ($sectionNumber == 0) { $mainArticle->updateArticle($this->getWikiText($up->getTitle()->getText(), self::LEFT) . $mainArticle->getRawText(), '', false, false); } else { $firstSectionText = $mainArticle->getSection($mainArticle->getRawText(), $sectionNumber); $matches = array(); if (preg_match('/={2,3}[^=]+={2,3}/', $firstSectionText, $matches)) { $firstSectionText = trim(str_replace($matches[0], '', $firstSectionText)); $newSectionText = $mainArticle->replaceSection($sectionNumber, $matches[0] . "\n" . $this->getWikiText($up->getTitle()->getText(), self::LEFT) . $firstSectionText); $mainArticle->updateArticle($newSectionText, '', false, false); } } $this->content = $this->renderImage($up->getTitle()->getText(), self::LEFT); } } } }
public function addRelated($t1, $t2, $summary = "Adding related wikihow from NAB", $top = false, $linkedtext = null) { #echo "putting a link in '{$t1->getText()}' to '{$t2->getText()}'\n\n"; if ($linkedtext) { $link = "*[[{$t2->getText()}|" . wfMsg('howto', $linkedtext) . "]]"; } else { $link = "*[[{$t2->getText()}|" . wfMsg('howto', $t2->getText()) . "]]"; } $article = new Article($t1); $wikitext = $article->getContent(true); for ($i = 0; $i < 30; $i++) { $s = $article->getSection($wikitext, $i); if (preg_match("@^==[ ]*" . wfMsg('relatedwikihows') . "@m", $s)) { if (preg_match("@{$t2->getText()}@m", $s)) { $found = true; break; } if ($top) { $s = preg_replace("@==\n@", "==\n{$link}\n", $s); } else { $s .= "\n{$link}\n"; } $wikitext = $article->replaceSection($i, $s); $found = true; break; } else { if (preg_match("@^==[ ]*(" . wfMsg('sources') . ")@m", $s)) { // we have gone too far $s = "\n== " . wfMsg('relatedwikihows') . " ==\n{$link}\n\n" . $s; $wikitext = $article->replaceSection($i, $s); $found = true; break; } } } if (!$found) { $wikitext .= "\n\n== " . wfMsg('relatedwikihows') . " ==\n{$link}\n"; } if (!$article->doEdit($wikitext, $summary)) { echo "Didn't save\n"; } }
/** * PW(25.03.2015) TODO: Use API * @global User $wgUser * @global Language $wgLang * @return string */ public static function doSaveArticle() { $aResult = $aOutput = array('saveresult' => 'fail', 'message' => '', 'edittime' => '', 'summary' => '', 'starttime' => wfTimestamp(TS_MW, time() + 2)); if (BsCore::checkAccessAdmission('read') === false) { $aResult['message'] = wfMessage('bs-permissionerror')->plain(); return FormatJson::encode($aResult); } global $wgLang, $wgRequest; $sArticleId = $wgRequest->getInt('articleId', 0); $sText = $wgRequest->getVal('text', ''); $sPageName = $wgRequest->getVal('pageName', ''); $sSummary = $wgRequest->getVal('summary', ''); $iSection = $wgRequest->getInt('editsection', 0); $sReturnEditTime = wfTimestampNow(); if ($sSummary == 'false') { $sSummary = '/* ' . wfMessage('bs-visualeditor-no-summary')->plain() . ' */'; } //PW(25.03.2015) TODO: Use Wikipage $oArticle = Article::newFromID($sArticleId); if (is_null($oArticle)) { $oTitle = Title::newFromText($sPageName); if (is_null($oTitle) || !$oTitle->exists()) { $aResult['message'] = wfMessage('badtitle')->plain(); return FormatJson::encode($aResult); } $oArticle = new Article($oTitle); } if ($iSection) { $sText = $oArticle->replaceSection($iSection, $sText); } //PW(25.03.2015) TODO: Deprecated since MW 1.21 use //Wikipage::doEditContent instead $oSaveResult = $oArticle->doEdit($sText, $sSummary); if ($oSaveResult->isGood()) { $sTime = $wgLang->timeanddate($sReturnEditTime, true); $aResult['edittime'] = $sReturnEditTime; $aResult['saveresult'] = 'ok'; $aResult['message'] = wfMessage('bs-visualeditor-save-message', $sTime, $sSummary)->plain(); $aResult['summary'] = $sSummary; } else { $aResult['message'] = $oSaveResult->getMessage()->plain(); } return FormatJson::encode($aResult); }
function rollbackChange($qcid) { // remove the intro image from this article $t = self::getTitleFromQCID($qcid); $r = Revision::newFromTitle($t); if (!$r) { return false; } $text = $r->getText(); $intro = Article::getSection($text, 0); //make sure the image is still in there preg_match("@\\[\\[Image:[^\\]]*\\]\\]@im", $intro, $matches); if (sizeof($matches) > 0) { $old_rev = self::getRevFromQCID($qcid); $old_intro = Article::getSection($old_rev->getText(), 0); //make sure the it's not a different image if (stripos($old_intro, $matches[0]) === false) { return false; } $newintro = preg_replace("@\\[\\[Image:[^\\]]*\\]\\]@", "", $intro); $a = new Article($t); $newtext = $a->replaceSection($intro, $newintro); if ($a->doEdit($newtext, wfMsg('qc_editsummary_introimage'))) { return true; } } return false; }
/** * Get a diff between the current contents of the edit box and the * version of the page we're editing from. * * If this is a section edit, we'll replace the section as for final * save and then make a comparison. */ function showDiff() { global $wgUser, $wgContLang, $wgParser, $wgOut; $oldtitlemsg = 'currentrev'; # if message does not exist, show diff against the preloaded default if ($this->mTitle->getNamespace() == NS_MEDIAWIKI && !$this->mTitle->exists()) { $oldtext = $this->mTitle->getDefaultMessageText(); if ($oldtext !== false) { $oldtitlemsg = 'defaultmessagetext'; } } else { $oldtext = $this->mArticle->getRawText(); } $newtext = $this->mArticle->replaceSection($this->section, $this->textbox1, $this->summary, $this->edittime); wfRunHooks('EditPageGetDiffText', array($this, &$newtext)); $popts = ParserOptions::newFromUserAndLang($wgUser, $wgContLang); $newtext = $wgParser->preSaveTransform($newtext, $this->mTitle, $wgUser, $popts); if ($oldtext !== false || $newtext != '') { $oldtitle = wfMessage($oldtitlemsg)->parse(); $newtitle = wfMessage('yourtext')->parse(); $de = new DifferenceEngine($this->mArticle->getContext()); $de->setText($oldtext, $newtext); $difftext = $de->getDiff($oldtitle, $newtitle); $de->showDiffStyle(); } else { $difftext = ''; } $wgOut->addHTML('<div id="wikiDiff">' . $difftext . '</div>'); }