コード例 #1
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;
}
コード例 #2
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;
}