Ejemplo n.º 1
0
 public static function replaceIdxByData($var)
 {
     $data = RTEData::get('data', intval($var[1]));
     if (isset($data['type'])) {
         if (isset($data['wikitextIdx'])) {
             $data['wikitext'] = RTEData::get('wikitext', $data['wikitextIdx']);
             // macbre: correctly handle and unmark entities inside links wikitext (RT #38844)
             $data['wikitext'] = htmlspecialchars_decode($data['wikitext']);
             $data['wikitext'] = RTEParser::unmarkEntities($data['wikitext']);
             unset($data['wikitextIdx']);
             if (strpos($data['wikitext'], '_rte_wikitextidx') !== false) {
                 RTE::$edgeCases[] = 'COMPLEX.01';
             } else {
                 if (strpos($data['wikitext'], '_rte_dataidx') !== false) {
                     RTE::$edgeCases[] = 'COMPLEX.02';
                 } else {
                     if ($data['type'] == 'double-brackets') {
                         if (strrpos($data['wikitext'], '{{') !== 0 && strpos($data['wikitext'], '{{') !== strlen($data['wikitext']) - 2) {
                             RTE::$edgeCases[] = 'COMPLEX.03';
                         }
                     } else {
                         if (strpos($data['wikitext'], "") !== false) {
                             RTE::$edgeCases[] = 'COMPLEX.07';
                         }
                     }
                 }
             }
         }
     }
     return self::convertDataToAttributes($data);
 }
Ejemplo n.º 2
0
 /**
  * Parse provided wikitext to HTML using RTE parser
  */
 public static function rteparse()
 {
     global $wgTitle, $wgRequest, $wgUser;
     wfProfileIn(__METHOD__);
     $wikitext = $wgRequest->getVal('wikitext', '');
     $parserOptions = new ParserOptions();
     // don't show [edit] link for sections
     $parserOptions->setEditSection(false);
     // disable headings numbering
     $parserOptions->setNumberHeadings(false);
     $parser = new RTEParser();
     // call preSaveTransform so signatures, {{subst:foo}}, etc. will work
     $wikitext = $parser->preSaveTransform($wikitext, $wgTitle, $wgUser, $parserOptions);
     // parse wikitext using RTE parser
     $html = $parser->parse($wikitext, $wgTitle, $parserOptions)->getText();
     $res = array('html' => $html);
     wfProfileOut(__METHOD__);
     return $res;
 }
Ejemplo n.º 3
0
 /**
  * Handle row/cell/table
  */
 private function handleTable($node, $textContent)
 {
     wfProfileIn(__METHOD__);
     $out = '';
     // get node attributes
     $attributes = self::getAttributesStr($node);
     switch ($node->nodeName) {
         case 'table':
             // remove row line breaks
             $textContent = trim($textContent, "\n");
             // don't render empty tables (<table ... />)
             if ($textContent == '') {
                 RTE::log(__METHOD__, 'empty table found');
                 $out = '';
                 break;
             }
             $out = "{|{$attributes}\n{$textContent}\n|}\n";
             $out = $this->fixForTableCell($node, $out);
             $out = $this->fixForDiv($node, $out);
             // add \n if previous node is header and table is inside <div> (RT #44119)
             if (self::isChildOf($node, 'div')) {
                 if (!empty($node->previousSibling) && self::isHeadingNode($node->previousSibling)) {
                     $out = "\n{$out}";
                 }
             }
             // add \n if previous node is <div> (RT #54113) or <span> (RT #83859)
             if (self::previousSiblingIs($node, array('div', 'span'))) {
                 $out = "\n{$out}";
             }
             break;
         case 'caption':
             // add pipe after attributes
             if ($attributes != '') {
                 $attributes .= '|';
             }
             $out = "\n|+{$attributes}{$textContent}";
             break;
         case 'tr':
             // remove cell line breaks
             $textContent = trim($textContent, "\n");
             $addRowDelimiter = false;
             if (self::isFirstChild($node)) {
                 // add |- before first table row when table header (caption) is present
                 $tableNode = $node->parentNode->parentNode;
                 if (self::firstChildIs($tableNode, 'thead') || self::firstChildIs($tableNode, 'caption')) {
                     $addRowDelimiter = true;
                 }
             } else {
                 // for next rows always add row delimiter
                 $addRowDelimiter = true;
             }
             // delimiter is needed when <tr> has attributes provided
             if ($attributes != '') {
                 $addRowDelimiter = true;
             }
             // preserve row delimiter from wikitext
             if (self::getEmptyLinesBefore($node)) {
                 $addRowDelimiter = true;
             }
             // add row delimiter and attributes when needed
             if ($addRowDelimiter) {
                 $out = "\n|-{$attributes}";
             }
             $out .= "\n{$textContent}";
             break;
         case 'th':
         case 'td':
             $out = '';
             $char = $node->nodeName == 'td' ? '|' : '!';
             // support cells separated using double pipe
             $shortRowMarkup = $node->hasAttribute(self::DATA_RTE_SHORT_ROW_MARKUP);
             $spacesAfterLastCell = intval($node->getAttribute(self::DATA_RTE_SPACES_AFTER_LAST_CELL));
             if ($shortRowMarkup) {
                 // add trailing spaces from previous cell (RT #33879)
                 if ($spacesAfterLastCell) {
                     $out .= str_repeat(' ', $spacesAfterLastCell);
                 }
                 $out .= "{$char}{$char}";
             } else {
                 $out .= "\n{$char}";
             }
             // add pipe after attributes
             if ($attributes != '') {
                 $attributes .= '|';
             }
             // remove trailing line breaks
             $textContent = rtrim(self::addSpaces($node, $textContent), "\n");
             // add space before + and - (RT #53351)
             if (isset($textContent[0]) && in_array($textContent[0], array('-', '+'))) {
                 $textContent = " {$textContent}";
             } else {
                 if (isset($textContent[0]) && $textContent[0] == '|') {
                     $textContent = RTEParser::markEntities('&#124;') . substr($textContent, 1);
                 }
             }
             $out .= "{$attributes}{$textContent}";
             break;
     }
     wfProfileOut(__METHOD__);
     return $out;
 }
Ejemplo n.º 4
0
 /**
  * Take a tag soup fragment listing an HTML element's attributes
  * and normalize it to well-formed XML, discarding unwanted attributes.
  * Output is safe for further wikitext processing, with escaping of
  * values that could trigger problems.
  *
  * - Normalizes attribute names to lowercase
  * - Discards attributes not on a whitelist for the given element
  * - Turns broken or invalid entities into plaintext
  * - Double-quotes all attribute values
  * - Attributes without values are given the name as attribute
  * - Double attributes are discarded
  * - Unsafe style attributes are discarded
  * - Prepends space if there are attributes.
  *
  * @param $text String
  * @param $element String
  * @return String
  */
 static function fixTagAttributes($text, $element)
 {
     if (trim($text) == '') {
         return '';
     }
     $decoded = Sanitizer::decodeTagAttributes($text);
     $decoded = Sanitizer::fixDeprecatedAttributes($decoded, $element);
     $stripped = Sanitizer::validateTagAttributes($decoded, $element);
     $attribs = array();
     foreach ($stripped as $attribute => $value) {
         $encAttribute = htmlspecialchars($attribute);
         $encValue = Sanitizer::safeEncodeAttribute($value);
         # RTE (Rich Text Editor) - begin
         # @author: Inez Korczyński, macbre
         global $wgRTEParserEnabled;
         if (!empty($wgRTEParserEnabled) && $encAttribute == 'style') {
             // BugId:2462 - remove apostrophes from style attribute
             $encValue = str_replace('&#039;', '', $encValue);
             $attribs[] = "data-rte-style=\"{$encValue}\"";
         }
         # RTE - end
         $attribs[] = "{$encAttribute}=\"{$encValue}\"";
     }
     # RTE (Rich Text Editor) - begin
     # @author: Inez Korczyński
     global $wgRTEParserEnabled;
     if (!empty($wgRTEParserEnabled)) {
         if (strpos($text, "") !== false) {
             RTE::$edgeCases[] = 'COMPLEX.08';
         }
         $attribs[] = RTEParser::encodeAttributesStr($text);
     }
     # RTE - end
     return count($attribs) ? ' ' . implode(' ', $attribs) : '';
 }
Ejemplo n.º 5
0
function ImagePlaceholderMakePlaceholder($file, $frameParams, $handlerParams)
{
    wfProfileIn(__METHOD__);
    global $wgRequest, $wgWikiaImagePlaceholderId, $wgContLang;
    // Shortcuts
    $fp =& $frameParams;
    $hp =& $handlerParams;
    global $wgContLang, $wgUser, $wgThumbLimits, $wgThumbUpright, $wgRTEParserEnabled;
    $plc_tag = '';
    $plc_tag = $wgContLang->getFormattedNsText(NS_FILE) . ':' . wfMsgForContent('imgplc-placeholder');
    isset($hp['options']) && is_string($hp['options']) && '' != $hp['options'] ? $wikitext = '[[' . $plc_tag . '|' . $hp['options'] . ']]' : ($wikitext = '[[' . $plc_tag . ']]');
    $prefix = $postfix = '';
    $thumb = false;
    $frame = false;
    $caption = '';
    $link = '';
    $align = '';
    $isalign = 0;
    $isthumb = 0;
    $iswidth = 0;
    $iscaption = 0;
    $islink = 0;
    if (isset($hp['width']) && 0 != $hp['width']) {
        // FCK takes 0
        $width = $hp['width'];
        // if too small, the box will end up looking... extremely silly
        if ($width < IMG_PLC_MIN_WIDTH) {
            $width = IMG_PLC_MIN_WIDTH;
        }
        $iswidth = $width;
    } else {
        $width = IMG_PLC_DEF_WIDTH;
    }
    $height = $width;
    if (isset($fp['thumbnail'])) {
        $thumb = true;
        $isthumb = 1;
    }
    if (isset($fp['frame'])) {
        $frame = true;
    }
    if (isset($fp['align'])) {
        if ('left' == $fp['align'] || 'right' == $fp['align'] || 'center' == $fp['align']) {
            $align = $fp['align'];
            'left' == $fp['align'] ? $isalign = 1 : ($isalign = 2);
        }
    } else {
        $thumb || $frame ? $align = 'right' : ($align = '');
    }
    // set margin accordingly to alignment, identical to normal Image: -- RT#21368
    // FIXME: this REALLY should be done in a class
    $margin = '';
    if (isset($align)) {
        if ($align == 'right') {
            $margin = 'margin: 0.5em 0 1.2em 1.4em;';
        } else {
            if ($align == 'center') {
                $margin = 'margin: 0.5em auto 1.2em;';
            } else {
                $margin = 'margin: 0.5em 1.4em 1.2em 0;';
            }
        }
    }
    if (isset($fp['caption'])) {
        $caption = $fp['caption'];
        $iscaption = 1;
    }
    if (isset($fp['link'])) {
        $link = $fp['link'];
        $islink = 1;
    }
    $height = $width;
    // this is for positioning the "Add Image" button
    $lmarg = ceil(($width - 90) / 2);
    $tmarg = ceil(($height - 30) / 2);
    // macbre: RTE support for video placeholder
    // TODO: use JSSnippets to load dependencies
    if (empty($wgRTEParserEnabled)) {
        if ($wgRequest->getVal('diff', 0) == 0 && $wgRequest->getVal('oldid', 0) == 0) {
            $onclick = '$.loadYUI( function() {$.getScript(wgExtensionsPath+\'/wikia/WikiaMiniUpload/js/WMU.js\', function() { WMU_show( $.getEvent(), ' . -2 . ', ' . $wgWikiaImagePlaceholderId . ',' . $isalign . ',' . $isthumb . ' ,' . $iswidth . ', \'' . htmlspecialchars($caption) . '\' , \'' . htmlspecialchars($link) . '\' ); mw.loader.load( wgExtensionsPath+\'/wikia/WikiaMiniUpload/css/WMU.css\', "text/css" ) } ) } )';
        } else {
            $onclick = 'alert(' . escapeshellarg(wfMsg('imgplc-notinhistory')) . '); return false;';
        }
    }
    // FIXME: argh! inline styles! Move to classes someday... --TOR
    $margin = '';
    $additionalClass = '';
    if (isset($align)) {
        if ($align == 'right') {
            $margin = 'margin: 0.5em 0 1.2em 1.4em;';
        } else {
            if ($align == 'center') {
                $margin = 'margin: 0.5em auto 1.2em;';
                $additionalClass = ' center';
            } else {
                $margin = 'margin: 0.5em 1.4em 1.2em 0;';
            }
        }
    }
    // render HTML (RT #21087)
    $out = '';
    $wrapperAttribs = array('id' => "WikiaImagePlaceholder{$wgWikiaImagePlaceholderId}", 'class' => "gallerybox wikiaPlaceholder{$additionalClass}", 'style' => 'vertical-align: bottom');
    if (isset($refid)) {
        $wrapperAttribs['refid'] = $refid;
    }
    $out .= Xml::openElement('div', $wrapperAttribs);
    $out .= Xml::openElement('div', array('class' => "thumb t{$align} videobox", 'style' => "height: {$height}px; width: {$width}px; {$margin}"));
    // "Add video" green button
    $out .= Xml::openElement('a', array('id' => "WikiaImagePlaceholderInner{$wgWikiaImagePlaceholderId}", 'class' => 'wikia-button', 'style' => "top: {$tmarg}px;position:relative;", 'href' => '#', 'onclick' => !empty($onclick) ? $onclick : ''));
    $out .= wfMsg('imgplc-create');
    $out .= Xml::closeElement('a');
    // caption (RT #47460)
    if ($caption != '') {
        $out .= Xml::element('span', array('class' => 'thumbcaption'), $caption);
    }
    $out .= Xml::closeElement('div') . Xml::closeElement('div') . Xml::closeElement('td');
    // increase counter
    $wgWikiaImagePlaceholderId++;
    // dirty hack for CK support
    global $wgRTEParserEnabled;
    if (!empty($wgRTEParserEnabled)) {
        $out = RTEParser::renderMediaPlaceholder(array('type' => 'image-placeholder', 'params' => array('width' => $width, 'height' => $height, 'caption' => $caption, 'align' => $align, 'isAlign' => $isalign, 'isThumb' => $isthumb)));
    }
    wfProfileOut(__METHOD__);
    return $out;
}
Ejemplo n.º 6
0
 /**
  * Process [[ ]] wikilinks (RIL)
  * @return LinkHolderArray
  *
  * @private
  */
 function replaceInternalLinks2(&$s)
 {
     wfProfileIn(__METHOD__);
     # RTE (Rich Text Editor) - begin
     # @author: Inez Korczyński
     global $wgRTEParserEnabled;
     # RTE (Rich Text Editor) - end
     wfProfileIn(__METHOD__ . '-setup');
     static $tc = FALSE, $e1, $e1_img;
     # the % is needed to support urlencoded titles as well
     if (!$tc) {
         $tc = Title::legalChars() . '#%';
         # Match a link having the form [[namespace:link|alternate]]trail
         $e1 = "/^([{$tc}]+)(?:\\|(.+?))?]](.*)\$/sD";
         # Match cases where there is no "]]", which might still be images
         $e1_img = "/^([{$tc}]+)\\|(.*)\$/sD";
     }
     $holders = new LinkHolderArray($this);
     # split the entire text string on occurences of [[
     $a = StringUtils::explode('[[', ' ' . $s);
     # get the first element (all text up to first [[), and remove the space we added
     $s = $a->current();
     $a->next();
     $line = $a->current();
     # Workaround for broken ArrayIterator::next() that returns "void"
     $s = substr($s, 1);
     $useLinkPrefixExtension = $this->getTargetLanguage()->linkPrefixExtension();
     $e2 = null;
     if ($useLinkPrefixExtension) {
         # Match the end of a line for a word that's not followed by whitespace,
         # e.g. in the case of 'The Arab al[[Razi]]', 'al' will be matched
         $e2 = wfMsgForContent('linkprefix');
     }
     if (is_null($this->mTitle)) {
         wfProfileOut(__METHOD__ . '-setup');
         wfProfileOut(__METHOD__);
         throw new MWException(__METHOD__ . ": \$this->mTitle is null\n");
     }
     $nottalk = !$this->mTitle->isTalkPage();
     if ($useLinkPrefixExtension) {
         $m = array();
         if (preg_match($e2, $s, $m)) {
             $first_prefix = $m[2];
         } else {
             $first_prefix = false;
         }
     } else {
         $prefix = '';
     }
     if ($this->getConverterLanguage()->hasVariants()) {
         $selflink = $this->getConverterLanguage()->autoConvertToAllVariants($this->mTitle->getPrefixedText());
     } else {
         $selflink = array($this->mTitle->getPrefixedText());
     }
     $useSubpages = $this->areSubpagesAllowed();
     wfProfileOut(__METHOD__ . '-setup');
     # Loop for each link
     for (; $line !== false && $line !== null; $a->next(), $line = $a->current()) {
         # Check for excessive memory usage
         if ($holders->isBig()) {
             # Too big
             # Do the existence check, replace the link holders and clear the array
             $holders->replace($s);
             $holders->clear();
         }
         # RTE (Rich Text Editor) - begin
         # @author: Inez Korczyński
         if (!empty($wgRTEParserEnabled)) {
             $RTE_wikitextIdx = RTEMarker::getDataIdx(RTEMarker::INTERNAL_WIKITEXT, $line);
             // decode entities inside links wikimarkup (RT #38844)
             if ($pos = strpos($line, ']]')) {
                 // unmark entities inside link
                 $link = substr($line, 0, $pos);
                 $link = RTEParser::unmarkEntities($link);
                 // leave the rest of the line untouched
                 $line = $link . substr($line, $pos);
             }
         }
         # RTE - end
         if ($useLinkPrefixExtension) {
             wfProfileIn(__METHOD__ . '-prefixhandling');
             if (preg_match($e2, $s, $m)) {
                 $prefix = $m[2];
                 $s = $m[1];
             } else {
                 $prefix = '';
             }
             # first link
             if ($first_prefix) {
                 $prefix = $first_prefix;
                 $first_prefix = false;
             }
             wfProfileOut(__METHOD__ . '-prefixhandling');
         }
         $might_be_img = false;
         wfProfileIn(__METHOD__ . "-e1");
         if (preg_match($e1, $line, $m)) {
             # page with normal text or alt
             $text = $m[2];
             # If we get a ] at the beginning of $m[3] that means we have a link that's something like:
             # [[Image:Foo.jpg|[http://example.com desc]]] <- having three ] in a row f***s up,
             # the real problem is with the $e1 regex
             # See bug 1300.
             #
             # Still some problems for cases where the ] is meant to be outside punctuation,
             # and no image is in sight. See bug 2095.
             #
             if ($text !== '' && substr($m[3], 0, 1) === ']' && strpos($text, '[') !== false) {
                 $text .= ']';
                 # so that replaceExternalLinks($text) works later
                 $m[3] = substr($m[3], 1);
             }
             # fix up urlencoded title texts
             if (strpos($m[1], '%') !== false) {
                 # Should anchors '#' also be rejected?
                 $m[1] = str_replace(array('<', '>'), array('&lt;', '&gt;'), rawurldecode($m[1]));
             }
             $trail = $m[3];
         } elseif (preg_match($e1_img, $line, $m)) {
             # Invalid, but might be an image with a link in its caption
             $might_be_img = true;
             $text = $m[2];
             if (strpos($m[1], '%') !== false) {
                 $m[1] = rawurldecode($m[1]);
             }
             $trail = "";
         } else {
             # Invalid form; output directly
             $s .= $prefix . '[[' . $line;
             wfProfileOut(__METHOD__ . "-e1");
             continue;
         }
         wfProfileOut(__METHOD__ . "-e1");
         wfProfileIn(__METHOD__ . "-misc");
         # Don't allow internal links to pages containing
         # PROTO: where PROTO is a valid URL protocol; these
         # should be external links.
         if (preg_match('/^(?:' . wfUrlProtocols() . ')/', $m[1])) {
             $s .= $prefix . '[[' . $line;
             wfProfileOut(__METHOD__ . "-misc");
             continue;
         }
         # Make subpage if necessary
         if ($useSubpages) {
             $link = $this->maybeDoSubpageLink($m[1], $text);
         } else {
             $link = $m[1];
         }
         $noforce = substr($m[1], 0, 1) !== ':';
         if (!$noforce) {
             # Strip off leading ':'
             $link = substr($link, 1);
         }
         wfProfileOut(__METHOD__ . "-misc");
         wfProfileIn(__METHOD__ . "-title");
         $nt = Title::newFromText($this->mStripState->unstripNoWiki($link));
         if ($nt === null) {
             $s .= $prefix . '[[' . $line;
             wfProfileOut(__METHOD__ . "-title");
             continue;
         }
         $ns = $nt->getNamespace();
         $iw = $nt->getInterWiki();
         wfProfileOut(__METHOD__ . "-title");
         if ($might_be_img) {
             # if this is actually an invalid link
             wfProfileIn(__METHOD__ . "-might_be_img");
             if ($ns == NS_FILE && $noforce) {
                 # but might be an image
                 $found = false;
                 while (true) {
                     # look at the next 'line' to see if we can close it there
                     $a->next();
                     $next_line = $a->current();
                     if ($next_line === false || $next_line === null) {
                         break;
                     }
                     $m = explode(']]', $next_line, 3);
                     if (count($m) == 3) {
                         # the first ]] closes the inner link, the second the image
                         $found = true;
                         $text .= "[[{$m[0]}]]{$m[1]}";
                         $trail = $m[2];
                         break;
                     } elseif (count($m) == 2) {
                         # if there's exactly one ]] that's fine, we'll keep looking
                         $text .= "[[{$m[0]}]]{$m[1]}";
                     } else {
                         # if $next_line is invalid too, we need look no further
                         $text .= '[[' . $next_line;
                         break;
                     }
                 }
                 if (!$found) {
                     # we couldn't find the end of this imageLink, so output it raw
                     # but don't ignore what might be perfectly normal links in the text we've examined
                     $holders->merge($this->replaceInternalLinks2($text));
                     $s .= "{$prefix}[[{$link}|{$text}";
                     # note: no $trail, because without an end, there *is* no trail
                     wfProfileOut(__METHOD__ . "-might_be_img");
                     continue;
                 }
             } else {
                 # it's not an image, so output it raw
                 $s .= "{$prefix}[[{$link}|{$text}";
                 # note: no $trail, because without an end, there *is* no trail
                 wfProfileOut(__METHOD__ . "-might_be_img");
                 continue;
             }
             wfProfileOut(__METHOD__ . "-might_be_img");
         }
         $wasblank = $text == '';
         if ($wasblank) {
             $text = $link;
         } else {
             # Bug 4598 madness. Handle the quotes only if they come from the alternate part
             # [[Lista d''e paise d''o munno]] -> <a href="...">Lista d''e paise d''o munno</a>
             # [[Criticism of Harry Potter|Criticism of ''Harry Potter'']]
             #    -> <a href="Criticism of Harry Potter">Criticism of <i>Harry Potter</i></a>
             $text = $this->doQuotes($text);
         }
         # Link not escaped by : , create the various objects
         if ($noforce) {
             global $wgContLang;
             # Interwikis
             if (empty($wgRTEParserEnabled)) {
                 # wikia
                 wfProfileIn(__METHOD__ . "-interwiki");
                 if ($iw && $this->mOptions->getInterwikiMagic() && $nottalk && $wgContLang->getLanguageName($iw)) {
                     $this->mOutput->addLanguageLink($nt->getFullText());
                     $s = rtrim($s . $prefix);
                     $s .= trim($trail, "\n") == '' ? '' : $prefix . $trail;
                     wfProfileOut(__METHOD__ . "-interwiki");
                     continue;
                 }
                 wfProfileOut(__METHOD__ . "-interwiki");
             }
             # wikia
             if ($ns == NS_FILE) {
                 wfProfileIn(__METHOD__ . "-image");
                 if (!wfIsBadImage($nt->getDBkey(), $this->mTitle)) {
                     if ($wasblank) {
                         # if no parameters were passed, $text
                         # becomes something like "File:Foo.png",
                         # which we don't want to pass on to the
                         # image generator
                         $text = '';
                     } else {
                         # recursively parse links inside the image caption
                         # actually, this will parse them in any other parameters, too,
                         # but it might be hard to fix that, and it doesn't matter ATM
                         $text = $this->replaceExternalLinks($text);
                         $holders->merge($this->replaceInternalLinks2($text));
                     }
                     # RTE (Rich Text Editor) - begin
                     # @author: Inez Korczyński
                     if (!empty($wgRTEParserEnabled)) {
                         $text = RTEMarker::generate(RTEMarker::IMAGE_DATA, $RTE_wikitextIdx) . $text;
                     }
                     # RTE - end
                     # cloak any absolute URLs inside the image markup, so replaceExternalLinks() won't touch them
                     /** wikia
                     				$s .= $prefix . $this->armorLinks(
                     					$this->makeImage( $nt, $text, $holders ) ) . $trail;
                     				wikia **/
                     # cater for new placeholder-in-template namespace -  Bartek
                     # TODO: Get the hell out with this code from here this can be done in hook handler fired in makeImage function - Inez
                     if ("Template Placeholder" != $nt->getText()) {
                         $s .= $prefix . $this->armorLinks($this->makeImage($nt, $text, $holders)) . $trail;
                     } else {
                         $s .= $prefix . $this->armorLinks(ImagePlaceholder_makeDullImage($nt, $text, $holders)) . $trail;
                     }
                 } else {
                     $s .= $prefix . $trail;
                 }
                 wfProfileOut(__METHOD__ . "-image");
                 continue;
             }
             if ($ns == NS_CATEGORY) {
                 wfProfileIn(__METHOD__ . "-category");
                 # RTE (Rich Text Editor) - begin
                 # @author: Inez Korczyński
                 # Category handling
                 if (!empty($wgRTEParserEnabled)) {
                     $dataIdx = RTEData::put('placeholder', array('type' => 'category', 'wikitextIdx' => $RTE_wikitextIdx));
                     $s .= $prefix . RTEMarker::generate(RTEMarker::PLACEHOLDER, $dataIdx) . $trail;
                 } else {
                     $s = rtrim($s . "\n");
                     # bug 87
                     if ($wasblank) {
                         $sortkey = $this->getDefaultSort();
                     } else {
                         $sortkey = $text;
                     }
                     $sortkey = Sanitizer::decodeCharReferences($sortkey);
                     $sortkey = str_replace("\n", '', $sortkey);
                     $sortkey = $this->getConverterLanguage()->convertCategoryKey($sortkey);
                     $this->mOutput->addCategory($nt->getDBkey(), $sortkey);
                     /**
                      * Strip the whitespace Category links produce, see bug 87
                      * @todo We might want to use trim($tmp, "\n") here.
                      */
                     $s .= trim($prefix . $trail, "\n") == '' ? '' : $prefix . $trail;
                 }
                 wfProfileOut(__METHOD__ . "-category");
                 continue;
             }
             # Wikia change begin
             # @author macbre
             $hookRet = wfRunHooks('ParserReplaceInternalLinks2NoForce', array(&$s, $nt, $prefix, $trail, isset($RTE_wikitextIdx) ? $RTE_wikitextIdx : null));
             if ($hookRet === false) {
                 continue;
             }
             # Wikia change end
         }
         # RTE (Rich Text Editor) - begin
         # @author: Inez Korczyński
         # No special handling for self-linking in RTE mode
         # Self-link checking
         if (empty($wgRTEParserEnabled) && $nt->getFragment() === '' && $ns != NS_SPECIAL) {
             if (in_array($nt->getPrefixedText(), $selflink, true)) {
                 $s .= $prefix . Linker::makeSelfLinkObj($nt, $text, '', $trail);
                 continue;
             }
         }
         # RTE - end
         # NS_MEDIA is a pseudo-namespace for linking directly to a file
         # @todo FIXME: Should do batch file existence checks, see comment below
         if ($ns == NS_MEDIA) {
             # RTE (Rich Text Editor) - begin
             # @author: macbre
             # BugId:1694 - handle [[Media:xxx]] as placeholders
             if (!empty($wgRTEParserEnabled)) {
                 $dataIdx = RTEData::put('placeholder', array('type' => 'media', 'wikitextIdx' => $RTE_wikitextIdx));
                 $s .= $prefix . RTEMarker::generate(RTEMarker::PLACEHOLDER, $dataIdx) . $trail;
                 continue;
             }
             # RTE - end
             wfProfileIn(__METHOD__ . "-media");
             # Give extensions a chance to select the file revision for us
             $options = array();
             $descQuery = false;
             wfRunHooks('BeforeParserFetchFileAndTitle', array($this, $nt, &$options, &$descQuery));
             # Fetch and register the file (file title may be different via hooks)
             list($file, $nt) = $this->fetchFileAndTitle($nt, $options);
             # Cloak with NOPARSE to avoid replacement in replaceExternalLinks
             $s .= $prefix . $this->armorLinks(Linker::makeMediaLinkFile($nt, $file, $text)) . $trail;
             wfProfileOut(__METHOD__ . "-media");
             continue;
         }
         wfProfileIn(__METHOD__ . "-always_known");
         # RTE (Rich Text Editor) - begin
         # @author: Inez Korczyński
         if (!empty($wgRTEParserEnabled)) {
             $text = RTEMarker::generate(RTEMarker::INTERNAL_DATA, RTEData::put('data', array('type' => 'internal', 'wikitextIdx' => $RTE_wikitextIdx, 'text' => $text, 'link' => $link, 'wasblank' => $wasblank, 'noforce' => $noforce))) . $text;
         }
         # RTE - end
         # Some titles, such as valid special pages or files in foreign repos, should
         # be shown as bluelinks even though they're not included in the page table
         #
         # @todo FIXME: isAlwaysKnown() can be expensive for file links; we should really do
         # batch file existence checks for NS_FILE and NS_MEDIA
         if ($iw == '' && $nt->isAlwaysKnown()) {
             $this->mOutput->addLink($nt);
             $s .= $this->makeKnownLinkHolder($nt, $text, array(), $trail, $prefix);
         } else {
             # Links will be added to the output link list after checking
             $s .= $holders->makeHolder($nt, $text, array(), $trail, $prefix);
         }
         wfProfileOut(__METHOD__ . "-always_known");
     }
     wfProfileOut(__METHOD__);
     return $holders;
 }
Ejemplo n.º 7
0
 /**
  * Handle ParserMakeImageParams hook (get parsed image options)
  */
 public static function makeImageParams($title, $file, &$params)
 {
     wfProfileIn(__METHOD__);
     // run only when parsing for RTE
     global $wgRTEParserEnabled;
     if (empty($wgRTEParserEnabled)) {
         wfProfileOut(__METHOD__);
         return true;
     }
     // store image params (to be used in makeImage)
     self::$imageParams = $params;
     wfProfileOut(__METHOD__);
     return true;
 }
Ejemplo n.º 8
0
function ImagePlaceholderMakePlaceholder($file, $frameParams, $handlerParams)
{
    wfProfileIn(__METHOD__);
    global $wgRequest, $wgWikiaImagePlaceholderId, $wgWikiaVideoPlaceholderId, $wgContLang, $wgTitle;
    // Shortcuts
    $fp =& $frameParams;
    $hp =& $handlerParams;
    global $wgContLang, $wgUser, $wgThumbLimits, $wgThumbUpright, $wgRTEParserEnabled;
    $plc_tag = '';
    $plc_tag = $wgContLang->getFormattedNsText(NS_FILE) . ':' . wfMsgForContent('imgplc-placeholder');
    isset($hp['options']) && is_string($hp['options']) && '' != $hp['options'] ? $wikitext = '[[' . $plc_tag . '|' . $hp['options'] . ']]' : ($wikitext = '[[' . $plc_tag . ']]');
    $prefix = $postfix = '';
    $thumb = false;
    $frame = false;
    $caption = '';
    $link = '';
    $align = '';
    $isalign = 0;
    $isthumb = 0;
    $iswidth = 0;
    $iscaption = 0;
    $islink = 0;
    $isvideo = 0;
    if (!empty($hp['isvideo'])) {
        $isvideo = 1;
    }
    if (isset($hp['width']) && 0 != $hp['width']) {
        // FCK takes 0
        $width = $hp['width'];
        // if too small, the box will end up looking... extremely silly
        if ($width < IMG_PLC_MIN_WIDTH) {
            $width = IMG_PLC_MIN_WIDTH;
        }
        $iswidth = $width;
    } else {
        $width = IMG_PLC_DEF_WIDTH;
    }
    $height = $width;
    if (isset($fp['thumbnail'])) {
        $thumb = true;
        $isthumb = 1;
    }
    if (isset($fp['frame'])) {
        $frame = true;
    }
    if (isset($fp['align'])) {
        if ('left' == $fp['align'] || 'right' == $fp['align'] || 'center' == $fp['align']) {
            $align = $fp['align'];
            'left' == $fp['align'] ? $isalign = 1 : ($isalign = 2);
        }
    } else {
        $thumb || $frame ? $align = 'right' : ($align = '');
    }
    // set margin accordingly to alignment, identical to normal Image: -- RT#21368
    // FIXME: this REALLY should be done in a class
    $margin = '';
    if (isset($align)) {
        if ($align == 'right') {
            $margin = 'margin: 0.5em 0 1.2em 1.4em;';
        } else {
            if ($align == 'center') {
                $margin = 'margin: 0.5em auto 1.2em;';
            } else {
                $margin = 'margin: 0.5em 1.4em 1.2em 0;';
            }
        }
    }
    if (isset($fp['caption'])) {
        $caption = $fp['caption'];
        $iscaption = 1;
    }
    if (isset($fp['link'])) {
        $link = $fp['link'];
        $islink = 1;
    }
    $height = $width;
    // this is for positioning the "Add Image" button
    $lmarg = ceil(($width - 90) / 2);
    $tmarg = ceil(($height - 30) / 2);
    $additionalClass = '';
    if ($isvideo) {
        $additionalClass .= ' wikiaVideoPlaceholder';
    } else {
        $additionalClass .= ' wikiaImagePlaceholder';
    }
    // render HTML (RT #21087)
    $out = '';
    $wrapperAttribs = array('class' => "gallerybox wikiaPlaceholder{$additionalClass}");
    // ImagePlaceholders still use id attribute, videos use data-id attribute. Images should be updated to match videos at some point
    if (!$isvideo) {
        $wrapperAttribs['id'] = "WikiaImagePlaceholder{$wgWikiaImagePlaceholderId}";
    }
    if (isset($refid)) {
        $wrapperAttribs['refid'] = $refid;
    }
    $out .= Xml::openElement('div', $wrapperAttribs);
    $out .= Xml::openElement('div', array('class' => "thumb t{$align} videobox", 'style' => "height: {$height}px; width: {$width}px;"));
    $linkAttrs = array('id' => "WikiaImagePlaceholderInner{$wgWikiaImagePlaceholderId}", 'class' => 'wikia-button', 'style' => "top: {$tmarg}px;", 'href' => $wgTitle instanceof Title ? $wgTitle->getLocalUrl(array('action' => 'edit')) : '#', 'data-id' => $isvideo ? $wgWikiaVideoPlaceholderId : $wgWikiaImagePlaceholderId, 'data-align' => $isalign, 'data-thumb' => $isthumb, 'data-caption' => htmlspecialchars($caption), 'data-width' => $width);
    if (!$isvideo) {
        // image placeholder
        $linkAttrs = array_merge($linkAttrs, array('data-link' => htmlspecialchars($link), 'data-width' => $width));
    }
    $out .= Xml::openElement('a', $linkAttrs);
    $out .= $isvideo ? wfMsg('imgplc-add-video') : wfMsg('imgplc-add-image');
    $out .= Xml::closeElement('a');
    // caption (RT #47460)
    if ($caption != '') {
        $out .= Xml::element('span', array('class' => 'thumbcaption'), $caption);
    }
    $out .= Xml::closeElement('div') . Xml::closeElement('div') . Xml::closeElement('td');
    // increase counter
    if ($isvideo) {
        $wgWikiaVideoPlaceholderId++;
    } else {
        $wgWikiaImagePlaceholderId++;
    }
    // dirty hack for CK support
    global $wgRTEParserEnabled;
    if (!empty($wgRTEParserEnabled)) {
        $out = RTEParser::renderMediaPlaceholder(array('type' => $isvideo ? 'video-placeholder' : 'image-placeholder', 'params' => array('width' => $width, 'height' => $height, 'caption' => $caption, 'align' => $align, 'isAlign' => $isalign, 'isThumb' => $isthumb)));
    } else {
        $out .= JSSnippets::addToStack(array('/extensions/wikia/ImagePlaceholder/js/MediaPlaceholder.js'), array(), 'MediaPlaceholder.init');
    }
    wfProfileOut(__METHOD__);
    return $out;
}