/**
  * 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;
 }
示例#2
0
 /**
  * Perform wikitext parsing to HTML
  */
 public static function wiki2html()
 {
     wfProfileIn(__METHOD__);
     global $wgRequest;
     $wikitext = $wgRequest->getVal('wikitext', '');
     RTE::log(__METHOD__, $wikitext);
     $ret = array('html' => RTE::WikitextToHtml($wikitext), 'instanceId' => RTE::getInstanceId());
     if (RTE::edgeCasesFound()) {
         $ret = array('edgecase' => array('type' => RTE::getEdgeCaseType(), 'info' => array('title' => wfMsg('rte-edgecase-info-title'), 'content' => wfMsg('rte-edgecase-info'))));
     }
     wfProfileOut(__METHOD__);
     return $ret;
 }
 protected function showTextbox1($customAttribs = null, $textoverride = null)
 {
     if (!empty($this->mSpecialPage)) {
         if ($this->mSpecialPage->showOwnTextbox()) {
             return true;
         }
     }
     // MW core says: In an edit conflict bypass the overrideable content form method
     // and fallback to the raw wpTextbox1
     // Wikia: in visual mode we want to show HTML (BugId:5428)
     if ($this->isConflict) {
         $textoverride = $this->getContent();
         // parse it for visual editor (if needed) - BugId:7956
         if ($this->app->wg->Request->wasPosted()) {
             if ($this->app->wg->Request->getVal('RTEMode') == 'wysiwyg') {
                 $textoverride = RTE::WikitextToHtml($textoverride);
             }
         }
     }
     parent::showTextbox1($customAttribs, $textoverride);
 }
示例#4
0
 /**
  * Parse wikitext of edited article, so CK can be provided with HTML
  */
 public static function init2(&$form, OutputPage &$out)
 {
     wfProfileIn(__METHOD__);
     // add hidden edit form field
     $out->addHTML("\n" . Xml::element('input', array('type' => 'hidden', 'value' => '', 'name' => 'RTEMode', 'id' => 'RTEMode')));
     // add fields to perform temporary save
     self::addTemporarySaveFields($out);
     // let's parse wikitext (only for wysiwyg mode)
     if (self::$initMode == 'wysiwyg') {
         $html = RTE::WikitextToHtml($form->textbox1);
     }
     // check for edgecases (found during parsing done above)
     if (RTE::edgeCasesFound()) {
         self::setInitMode('source');
         // get edgecase type and add it to JS variables
         $edgeCaseType = Xml::encodeJsVar(self::getEdgeCaseType());
         $out->addInlineScript("var RTEEdgeCase = {$edgeCaseType}");
     }
     // parse wikitext using RTEParser (only for wysiwyg mode)
     if (self::$initMode == 'wysiwyg') {
         // set editor textarea content
         $form->textbox1 = $html;
     }
     // allow other extensions to add extra HTML to edit form
     wfRunHooks('RTEAddToEditForm', array(&$form, &$out));
     wfProfileOut(__METHOD__);
     return true;
 }