/**
  * Convert editor content from one format to another.
  *
  * @param $content The content to convert from the request object or passed in as a string
  * @param $convertToFormat The format to convert to ('richtext' or 'wikitext')
  * @param $response (optional) The response object to add edgeCases to
  */
 public static function convertContent($content = '', $convertToFormat = '', WikiaResponse $response = null)
 {
     if (class_exists('RTE')) {
         // Clear out edge cases to avoid polluting future requests
         RTE::$edgeCases = array();
         if (!empty($content) && !empty($convertToFormat)) {
             if ($convertToFormat == 'richtext') {
                 $html = RTE::WikitextToHtml($content);
                 if (empty(RTE::$edgeCases)) {
                     $content = $html;
                     // Edge cases were found, add them to the response object (if provided)
                 } else {
                     if (!is_null($response)) {
                         $response->setVal('edgeCases', RTE::$edgeCases);
                     }
                 }
             } else {
                 if ($convertToFormat == 'wikitext') {
                     $content = RTE::HtmlToWikitext($content);
                 }
             }
         }
     }
     return $content;
 }
Exemple #2
0
 /**
  * Perform reverse parsing from HTML to wikitext
  */
 public static function html2wiki()
 {
     global $wgRequest;
     $html = $wgRequest->getVal('html', '');
     RTE::log(__METHOD__, $html);
     $wikitext = RTE::HtmlToWikitext($html);
     return array('wikitext' => $wikitext);
 }
 /**
  * Reverse parse wikitext when performing diff for edit conflict
  */
 static function onEditPageBeforeConflictDiff(&$editform, &$out)
 {
     $helper = EditPageLayoutHelper::getInstance();
     if (class_exists('RTE') && $helper->getRequest()->getVal('RTEMode') == 'wysiwyg') {
         $editform->textbox2 = RTE::HtmlToWikitext($editform->textbox2);
     }
     return true;
 }
Exemple #4
0
 /**
  * Perform "reverse" parsing of HTML to wikitext when saving / doing preview from wysiwyg mode
  *
  * @param EditPage $form
  */
 public static function reverse($form, $out = null)
 {
     global $wgRequest;
     wfProfileIn(__METHOD__);
     if ($wgRequest->wasPosted()) {
         if ($wgRequest->getVal('RTEMode') == 'wysiwyg') {
             RTE::log('performing reverse parsing back to wikitext');
             if ($out == null) {
                 $wikitext = RTE::HtmlToWikitext($wgRequest->getText('wpTextbox1'));
                 $wgRequest->setVal('wpTextbox1', $wikitext);
             } else {
                 $form->textbox1 = $form->getContent();
             }
         }
     }
     wfProfileOut(__METHOD__);
     return true;
 }
 /**
  * Return wikitext from given POST request
  */
 protected function getWikitextFromField($fieldName)
 {
     $wikitext = $this->request->getText($fieldName);
     // perform reverse parsing when needed (i.e. convert HTML from RTE to wikitext)
     if (class_exists('RTE') && ($this->request->getVal('RTEMode') == 'wysiwyg' || $this->request->getVal('mode') == 'wysiwyg')) {
         $wikitext = RTE::HtmlToWikitext($wikitext);
         $this->request->setVal('RTEMode', null);
     }
     return $wikitext;
 }
 /**
  * Reverse parse wikitext when performing diff for edit conflict
  */
 function onEditPageBeforeConflictDiff(&$editform, &$out)
 {
     if (class_exists('RTE') && $this->request->getVal('RTEMode') == 'wysiwyg') {
         $editform->textbox2 = RTE::HtmlToWikitext($editform->textbox2);
     }
     return true;
 }