Пример #1
0
function ImagePlaceholderBeforeParserMakeImageLinkObjOptions(Parser $parser, Title $title, $parts, &$params, $time, $descQuery, $options)
{
    // we have to ready the parameters and then fire up makeLink, heh
    // other way parameters are mangled
    if (!ImagePlaceholderIsPlaceholder($title->getText())) {
        return true;
    }
    global $wgContLang;
    $plc_tag = $wgContLang->getFormattedNsText(NS_FILE) . ':' . wfMsgForContent('imgplc-placeholder');
    $ns_img = ImagePlaceholderTranslateNsImage();
    $img_tag = $ns_img . ':' . wfMsgForContent('imgplc-placeholder');
    $params = array('frame' => array(), 'handler' => array(), 'horizAlign' => array(), 'vertAlign' => array());
    $horizAlign = array('left', 'right', 'center', 'none');
    $caption = '';
    $params['handler']['options'] = $options;
    foreach ($parts as $part) {
        if ('thumb' == $part) {
            $params['frame']['thumbnail'] = '';
        } elseif ('frame' == $part) {
            $params['frame']['frame'] = '';
        } elseif (in_array($part, $horizAlign)) {
            $params['frame']['align'] = $part;
            $params['horizAlign'][$part] = '';
        } elseif (0 === strpos($part, 'link=')) {
            $params['frame']['link'] = substr($part, 5);
        } elseif (preg_match('/^([0-9]*)x([0-9]*)\\s*(?:px)?\\s*$/', $part, $m)) {
            // width we have
            $params['handler']['width'] = intval($m[1]);
        } elseif (preg_match('/^[0-9]*\\s*(?:px)?\\s*$/', $part)) {
            $params['handler']['width'] = intval($part);
        } else {
            if (mb_strtolower($plc_tag) != mb_strtolower($part) && $img_tag != $part) {
                $params['frame']['caption'] = $part;
            }
        }
    }
    return false;
}
Пример #2
0
function MediaPlaceholderMatch($text, $box = 0, $isVideo = false)
{
    global $wgContLang;
    // Get the namesapace translations in the content language for files and videos
    $ns = NS_FILE;
    $ns_vid = $wgContLang->getFormattedNsText($ns);
    $ns_img = ImagePlaceholderTranslateNsImage();
    // Get the same as above but for english
    $en_ns_vid = MWNamespace::getCanonicalName($ns);
    $oldWgContLang = $wgContLang;
    $wgContLang = Language::factory('en');
    $en_ns_img = ImagePlaceholderTranslateNsImage();
    $wgContLang = $oldWgContLang;
    // Get the placeholder text in both the content language and in english
    $placeholder_msg = wfMsgForContent('imgplc-placeholder');
    $en_placeholder_msg = wfMsgReal('imgplc-placeholder', array(), true, 'en');
    $placeholder = '(?:' . implode('|', array($ns_vid . ':' . $placeholder_msg, $ns_vid . ':' . $en_placeholder_msg, $ns_img . ':' . $placeholder_msg, $ns_img . ':' . $en_placeholder_msg, $en_ns_vid . ':' . $en_placeholder_msg, $en_ns_vid . ':' . $placeholder_msg, $en_ns_img . ':' . $en_placeholder_msg, $en_ns_img . ':' . $placeholder_msg)) . ')';
    preg_match_all('/\\[\\[' . $placeholder . '[^\\]]*\\]\\]/si', $text, $matches, PREG_OFFSET_CAPTURE);
    // Make sure we have matches and that there exists a match at index $box
    if (is_array($matches)) {
        $matchArr = $matches[0];
        for ($x = 0; $x < count($matchArr); $x++) {
            $match = $matchArr[$x];
            if ($isVideo) {
                if (!preg_match('/\\|video/', $match[0])) {
                    array_splice($matchArr, $x, 1);
                }
            } else {
                if (preg_match('/video/', $match[0])) {
                    array_splice($matchArr, $x, 1);
                }
            }
        }
        if (count($matchArr) > $box) {
            return $matchArr[$box];
        }
    }
    return null;
}
Пример #3
0
 function insertImage()
 {
     global $wgRequest, $wgUser, $wgContLang;
     $type = $wgRequest->getVal('type');
     $name = $wgRequest->getVal('name');
     $mwname = $wgRequest->getVal('mwname');
     $tempid = $wgRequest->getVal('tempid');
     '' != $wgRequest->getVal('gallery') ? $gallery = $wgRequest->getVal('gallery') : ($gallery = '');
     '' != $wgRequest->getVal('article') ? $title_main = urldecode($wgRequest->getVal('article')) : ($title_main = '');
     '' != $wgRequest->getCheck('fck') ? $fck = $wgRequest->getCheck('ns') : ($fck = false);
     '' != $wgRequest->getVal('ns') ? $ns = $wgRequest->getVal('ns') : ($ns = '');
     '' != $wgRequest->getVal('link') ? $link = urldecode($wgRequest->getVal('link')) : ($link = '');
     $extraId = $wgRequest->getVal('extraId');
     $newFile = true;
     if ($name !== NULL) {
         $name = urldecode($name);
         if ($name == '') {
             header('X-screen-type: error');
             return WfMsg('wmu-warn3');
         } else {
             $name = preg_replace("/[^" . Title::legalChars() . "]|:/", '-', $name);
             // did they give no extension at all when they changed the name?
             $ext = explode('.', $name);
             array_shift($ext);
             if (count($ext)) {
                 $finalExt = $ext[count($ext) - 1];
             } else {
                 $finalExt = '';
             }
             if ('' == $finalExt) {
                 header('X-screen-type: error');
                 return wfMsg('wmu-filetype-missing');
             }
             $title = Title::makeTitleSafe(NS_IMAGE, $name);
             if (is_null($title)) {
                 header('X-screen-type: error');
                 return wfMsg('wmu-filetype-incorrect');
             }
             if ($title->exists()) {
                 if ($type == 'overwrite') {
                     $title = Title::newFromText($name, 6);
                     // is the target protected?
                     $permErrors = $title->getUserPermissionsErrors('edit', $wgUser);
                     $permErrorsUpload = $title->getUserPermissionsErrors('upload', $wgUser);
                     $permErrorsCreate = $title->exists() ? array() : $title->getUserPermissionsErrors('create', $wgUser);
                     if ($permErrors || $permErrorsUpload || $permErrorsCreate) {
                         header('X-screen-type: error');
                         return wfMsg('wmu-file-protected');
                     }
                     $file_name = new LocalFile($title, RepoGroup::singleton()->getLocalRepo());
                     $file_mwname = new FakeLocalFile(Title::newFromText($mwname, 6), RepoGroup::singleton()->getLocalRepo());
                     if (!empty($extraId)) {
                         $flickrResult = $this->getFlickrPhotoInfo($extraId);
                         $nsid = $flickrResult['owner']['nsid'];
                         // e.g. 49127042@N00
                         $username = $flickrResult['owner']['username'];
                         // e.g. bossa67
                         $license = $flickrResult['license'];
                         $caption = '{{MediaWiki:Flickr' . intval($license) . '|1=' . wfEscapeWikiText($extraId) . '|2=' . wfEscapeWikiText($nsid) . '|3=' . wfEscapeWikiText($username) . '}}';
                     } else {
                         $caption = '';
                     }
                     $file_name->upload($file_mwname->getPath(), '', $caption);
                     $file_mwname->delete('');
                     $this->tempFileClearInfo($tempid);
                     $newFile = false;
                 } else {
                     if ($type == 'existing') {
                         $file = wfFindFile(Title::newFromText($name, 6));
                         if (!empty($file)) {
                             header('X-screen-type: existing');
                             $props = array();
                             $props['file'] = $file;
                             $props['mwname'] = $name;
                             $props['default_caption'] = Wikia::getProps($file->getTitle()->getArticleID(), 'default_caption');
                             return $this->detailsPage($props);
                         } else {
                             header('X-screen-type: error');
                             return wfMsg('wmu-file-error');
                         }
                     } else {
                         header('X-screen-type: conflict');
                         $tmpl = new EasyTemplate(dirname(__FILE__) . '/templates/');
                         // extensions check
                         list($partname, $ext) = UploadBase::splitExtensions($name);
                         if (count($ext)) {
                             $finalExt = $ext[count($ext) - 1];
                         } else {
                             $finalExt = '';
                         }
                         // for more than one "extension"
                         if (count($ext) > 1) {
                             for ($i = 0; $i < count($ext) - 1; $i++) {
                                 $partname .= '.' . $ext[$i];
                             }
                         }
                         $tmpl->set_vars(array('partname' => $partname, 'extension' => strtolower($finalExt), 'mwname' => $mwname, 'extraId' => $extraId));
                         return $tmpl->render('conflict');
                     }
                 }
             } else {
                 // is the target protected?
                 $permErrors = $title->getUserPermissionsErrors('edit', $wgUser);
                 $permErrorsUpload = $title->getUserPermissionsErrors('upload', $wgUser);
                 $permErrorsCreate = $title->exists() ? array() : $title->getUserPermissionsErrors('create', $wgUser);
                 if ($permErrors || $permErrorsUpload || $permErrorsCreate) {
                     header('X-screen-type: error');
                     wfMsg('wmu-file-protected');
                 }
                 $temp_file = new LocalFile(Title::newFromText($mwname, 6), RepoGroup::singleton()->getLocalRepo());
                 $file = new LocalFile($title, RepoGroup::singleton()->getLocalRepo());
                 if (!empty($extraId)) {
                     $flickrResult = $this->getFlickrPhotoInfo($extraId);
                     $nsid = $flickrResult['owner']['nsid'];
                     // e.g. 49127042@N00
                     $username = $flickrResult['owner']['username'];
                     // e.g. bossa67
                     $license = $flickrResult['license'];
                     $caption = '{{MediaWiki:Flickr' . intval($license) . '|1=' . wfEscapeWikiText($extraId) . '|2=' . wfEscapeWikiText($nsid) . '|3=' . wfEscapeWikiText($username) . '}}';
                 } else {
                     // get the supplied license value
                     $license = $wgRequest->getVal('ImageUploadLicense');
                     if ($license != '') {
                         $caption = '== ' . wfMsgForContent('license') . " ==\n" . '{{' . $license . '}}' . "\n";
                     } else {
                         $caption = "";
                     }
                 }
                 $file->upload($temp_file->getPath(), '', $caption);
                 $temp_file->delete('');
                 $this->tempFileClearInfo($tempid);
             }
             if ($wgUser->getOption('watchdefault') || $newFile && $wgUser->getOption('watchcreations')) {
                 $wgUser->addWatch($title);
             }
             $db =& wfGetDB(DB_MASTER);
             $db->commit();
         }
     } else {
         $title = Title::newFromText($mwname, 6);
     }
     $file = wfFindFile($title);
     if (!is_object($file)) {
         header('X-screen-type: error');
         return 'File was not found!';
     }
     if (-2 == $gallery && !$fck) {
         // this went in from the single placeholder...
         $name = $title->getText();
         $size = $wgRequest->getVal('size');
         $width = $wgRequest->getVal('width');
         $layout = $wgRequest->getVal('layout');
         // clear the old caption for upload
         $caption = $wgRequest->getVal('caption');
         $slider = $wgRequest->getVal('slider');
         $ns_vid = $wgContLang->getFormattedNsText(NS_FILE);
         $ns_img = ImagePlaceholderTranslateNsImage();
         $title_obj = Title::newFromText($title_main, $ns);
         $article_obj = new Article($title_obj);
         $text = $article_obj->getContent();
         wfRunHooks('WikiaMiniUpload::fetchTextForImagePlaceholder', array(&$title_obj, &$text));
         '' != $wgRequest->getVal('box') ? $box = $wgRequest->getVal('box') : ($box = '');
         $placeholder_msg = wfMsgForContent('imgplc-placeholder');
         $transl_v_t = '\\[\\[' . $ns_vid . ':' . $placeholder_msg . '[^\\]]*\\]\\]';
         $transl_i_t = '\\[\\[' . $ns_img . ':' . $placeholder_msg . '[^\\]]*\\]\\]';
         $success = false;
         preg_match_all('/' . $transl_v_t . '|' . $transl_i_t . '/si', $text, $matches, PREG_OFFSET_CAPTURE);
         if (is_array($matches) && $box < count($matches[0])) {
             $our_gallery = $matches[0][$box][0];
             $gallery_split = explode(':', $our_gallery);
             $thumb = false;
             $tag = $gallery_split[0] . ":" . $name;
             if ($size != 'full') {
                 $tag .= '|thumb';
                 $thumb = true;
             }
             if (isset($width)) {
                 $tag .= '|' . $width;
             }
             $tag .= '|' . $layout;
             if ($link != '') {
                 $tag .= '|link=' . $link;
             }
             if ($caption != '') {
                 $tag .= '|' . $caption;
             }
             $tag .= "]]";
             $text = substr_replace($text, $tag, $matches[0][$box][1], strlen($our_gallery));
             // return the proper embed code with all fancies around it
             $embed_code = $this->generateImage($file, $name, $title_obj, $thumb, (int) str_replace('px', '', $width), $layout, $caption);
             $message = wfMsg('wmu-success');
             Wikia::setVar('EditFromViewMode', true);
             $summary = wfMsg('wmu-added-from-plc');
             $success = $article_obj->doEdit($text, $summary);
         }
         if ($success) {
             header('X-screen-type: summary');
         } else {
             // failure signal opens js alert (BugId:4935)
             // header('X-screen-type: error');
         }
     } else {
         header('X-screen-type: summary');
         $size = $wgRequest->getVal('size');
         $width = $wgRequest->getVal('width');
         $layout = $wgRequest->getVal('layout');
         $caption = $wgRequest->getVal('caption');
         $slider = $wgRequest->getVal('slider');
         $ns_img = $wgContLang->getFormattedNsText(NS_IMAGE);
         $tag = '[[' . $ns_img . ':' . $title->getDBkey();
         if ($size != 'full' && ($file->getMediaType() == 'BITMAP' || $file->getMediaType() == 'DRAWING')) {
             $tag .= '|thumb';
             if ($layout != 'right') {
                 $tag .= '|' . $layout;
             }
             if ($slider == 'true') {
                 $tag .= '|' . $width;
             }
         }
         if ($link != '' && $size == 'full') {
             $tag .= '|link=' . $link;
         }
         if ($caption != '') {
             if ($size == 'full') {
                 $tag .= '|frame';
             }
             $tag .= '|' . $caption . ']]';
         } else {
             $tag .= ']]';
         }
     }
     $message = wfMsg('wmu-success');
     if ($wgRequest->getVal('update_caption') == 'on') {
         Wikia::setProps($title->getArticleID(), array('default_caption' => $caption));
     }
     $tmpl = new EasyTemplate(dirname(__FILE__) . '/templates/');
     $tmpl->set_vars(array('tag' => $tag, 'filename' => $ns_img . ':' . $title->getDBkey(), 'message' => $message, 'code' => isset($embed_code) ? $embed_code : ''));
     return $tmpl->render('summary');
 }