Example #1
0
 /**
  * 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, $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';
             $oldContent = $this->toEditContent($oldtext);
         } else {
             $oldContent = null;
         }
     } else {
         $oldContent = $this->getCurrentContent();
     }
     $textboxContent = $this->toEditContent($this->textbox1);
     $newContent = $this->mArticle->replaceSectionContent($this->section, $textboxContent, $this->summary, $this->edittime);
     if ($newContent) {
         ContentHandler::runLegacyHooks('EditPageGetDiffText', array($this, &$newContent));
         wfRunHooks('EditPageGetDiffContent', array($this, &$newContent));
         $popts = ParserOptions::newFromUserAndLang($wgUser, $wgContLang);
         $newContent = $newContent->preSaveTransform($this->mTitle, $wgUser, $popts);
     }
     if ($oldContent && !$oldContent->isEmpty() || $newContent && !$newContent->isEmpty()) {
         $oldtitle = wfMessage($oldtitlemsg)->parse();
         $newtitle = wfMessage('yourtext')->parse();
         if (!$oldContent) {
             $oldContent = $newContent->getContentHandler()->makeEmptyContent();
         }
         if (!$newContent) {
             $newContent = $oldContent->getContentHandler()->makeEmptyContent();
         }
         $de = $oldContent->getContentHandler()->createDifferenceEngine($this->mArticle->getContext());
         $de->setContent($oldContent, $newContent);
         $difftext = $de->getDiff($oldtitle, $newtitle);
         $de->showDiffStyle();
     } else {
         $difftext = '';
     }
     $wgOut->addHTML('<div id="wikiDiff">' . $difftext . '</div>');
 }