function WidgetWikiaPartners($id, $params)
{
    global $wgWikiaPartners;
    if (!isset($wgWikiaPartners)) {
        return '';
    }
    wfProfileIn(__METHOD__);
    $output = "\n<table style='margin: 0 auto; border: 0; background: none'><tr>\n";
    for ($i = 0; $i < count($wgWikiaPartners); $i += 3) {
        $wgWikiaPartners[$i] = htmlspecialchars($wgWikiaPartners[$i]);
        $wgWikiaPartners[$i + 1] = htmlspecialchars($wgWikiaPartners[$i + 1]);
        if ($i != 0 && $i % 6 == 0) {
            $output .= "</tr>\n<tr>\n";
        }
        $output .= "<td><a href='" . $wgWikiaPartners[$i + 1] . "' title='" . $wgWikiaPartners[$i] . "'>\n";
        if ($wgWikiaPartners[$i + 2] != 'text') {
            $img = Image::newFromName($wgWikiaPartners[$i + 2]);
            if (is_object($img)) {
                $thumb = $img->createThumb(75, -1);
                $output .= "<img src='{$thumb}' alt='" . $wgWikiaPartners[$i] . "' />\n";
            } else {
                $output .= $wgWikiaPartners[$i];
            }
        } else {
            $output .= $wgWikiaPartners[$i];
        }
        $output .= "</a></td>\n";
    }
    $output .= "</tr></table>\n";
    wfProfileOut(__METHOD__);
    return $output;
}
Example #2
0
function renderMp3($input)
{
    global $wgScriptPath, $wgUploadPath;
    //$input = "filename.mp3"
    $arr = explode('|', trim($input));
    $addDLlink = isset($arr[1]) && $arr[1] == 'download';
    $input = $arr[0];
    $img = Image::newFromName($input);
    $mp3 = '';
    $bgcolor = 'FFF8DC';
    //You can change it, of course :-)
    //The parameters for object and embed
    # File uploaded or external link ?
    if (!$img->exists()) {
        //Must be http://... URL
        if (substr($input, 0, 7) == 'http://') {
            $mp3 = $input;
        }
    } else {
        $mp3 = $img->getURL();
    }
    if ($mp3 == '') {
        return '<div class="noprint">Fichier manquant : ' . $input . '<br />' . 'Missing ressource: ' . $input . '</div>';
    }
    unset($img);
    $output = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ' . 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" ' . 'width="200" height="20" id="dewplayer" align="middle">' . '<param name="allowScriptAccess" value="sameDomain" />' . '<param name="movie" value="' . $wgScriptPath . '/extensions/dewplayer.swf?son=' . $mp3 . '&amp;bgcolor=' . $bgcolor . '" />' . '<param name="quality" value="high" />' . '<param name="bgcolor" value="FFF8DC" />' . '<embed src="' . $wgScriptPath . '/extensions/dewplayer.swf?son=' . $mp3 . '&amp;bgcolor=' . $bgcolor . '" quality="high" bgcolor="FFF8DC" width="200" height="20" ' . 'name="dewplayer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" ' . 'pluginspage="http://www.macromedia.com/go/getflashplayer">' . '</embed>' . '</object>';
    if ($addDLlink) {
        $output .= '<a href="' . $mp3 . '" title="Download">' . '<img src="' . $wgUploadPath . '/download.gif" alt="Download" />' . '</a>';
    }
    return $output;
}
 /**
  * Outputs the internal image wrapped in a link
  * @param Parser $parser Instance of running Parser.
  * @param String $image Name of image to display.
  * @param String $url External URL to which to link
  * @param String $alt Alternate text for image and link (optional)
  * @return String A parser strip flag which will be later replaced with raw html.
  */
 function imageLink($parser, $image = null, $url = null, $alt = '')
 {
     # Short-circuit if requried params are missing
     if ($image === null || $url === null) {
         return $this->error('missing-params');
     }
     # Prepare incomming params
     $image = trim($image);
     $url = trim($url);
     $alt = trim($alt);
     # Check for bad URLs
     if (!preg_match('/^(' . wfUrlProtocols() . ')/', $url) || preg_match('/\'"/', $url)) {
         $t = Title::newFromText($url);
         if (!$t) {
             return $this->error('bad-url', $url);
         }
         $url = $t->getFullURL();
     }
     # Check to see that the selected image exists
     $imageObj = Image::newFromName($image);
     if (!$imageObj->exists()) {
         return $this->error('no-such-image', $image);
     }
     # Finally, since all checks passed, display it!
     return $parser->insertStripItem($this->msg('embed-clause', htmlentities($url, ENT_COMPAT), $imageObj->getURL(), htmlentities($alt, ENT_COMPAT)), $parser->mStripState);
 }
Example #4
0
function jsxgraph_filter($courseid, $text)
{
    global $CFG;
    // to optimize speed, search for a jsxgraph-tag (avoiding to parse everything on every text)
    if (is_int(strpos($text, '<jsxgraph'))) {
        $jsxgraph_version = '0.1';
        // get every construction
        $count = substr_count($text, '<jsxgraph');
        for ($i = 0; $i < $count; $i++) {
            $start = strpos($text, '<jsxgraph');
            $end = is_int(strpos($text, '</jsxgraph>', $start)) ? strpos($text, '</jsxgraph>', $start) + 11 : strpos($text, '/>', $start) + 2;
            $jxg = substr($text, $start + 10, $end - $start - 21);
            // parse parameters of construction
            $input = split(">", $jxg);
            // fix for javascript construction input
            $input[0] = str_replace("'", '', $input[0]);
            $input[0] = str_replace('"', '', $input[0]);
            $input[0] = str_replace(' ', '&', $input[0]);
            parse_str($input[0], $params);
            $outputDivId = isset($params['box']) ? htmlspecialchars(strip_tags($params['box'])) : 'box' . $i;
            $outputBoardId = isset($params['board']) ? htmlspecialchars(strip_tags($params['board'])) : 'board' . $i;
            $width = isset($params['width']) ? htmlspecialchars(strip_tags($params['width'])) : 500;
            $height = isset($params['height']) ? htmlspecialchars(strip_tags($params['height'])) : 400;
            // Load necessary stylesheet und scripts
            echo $PAGE->requires->js('filter/jsxgraph/jsxgraphcore.js')->asap();
            echo $PAGE->requires->css('filter/jsxgraph/jsxgraph.css')->asap();
            // output div
            $output = "<div id='" . $outputDivId . "' class='jxgbox' style='width:" . $width . "px; height:" . $height . "px;'></div>";
            $output .= "<script type='text/javascript'>";
            // construction by filename
            if (isset($params['filename'])) {
                $gxtBinary = htmlspecialchars(strip_tags($params['filename']));
                $gxtFile = Image::newFromName($gxtBinary);
                if (!$gxtFile->exists()) {
                    $error_message = "File " . $gxtFile . " not found.";
                } else {
                    $gxtURL = $CFG->wwwroot . $gxtFile->getURL();
                }
                $output .= "  var " . $outputBoardId . " = JXG.JSXGraph.loadBoardFromFile('" . $outputDivId . "', '" . $gxtURL . "', 'Geonext');";
            } else {
                if (isset($params['filestring'])) {
                    $tmp = split("filestring=", $text);
                    $tmp[1] = str_replace("'", '"', $tmp[1]);
                    $tmp = split('"', $tmp[1]);
                    $filestring = htmlspecialchars(strip_tags($tmp[1]));
                    $output .= "  var " . $outputBoardId . " = JXG.JSXGraph.loadBoardFromString('" . $outputDivId . "', '" . $filestring . "', 'Geonext');";
                } else {
                    for ($i = 1; $i <= sizeof($input); $i++) {
                        $i == 1 || $i == sizeof($input) ? $output .= $input[$i] : ($output .= ">" . $input[$i]);
                    }
                }
            }
            $output .= "</script>";
            $text = substr_replace($text, $output, $start, $end - $start);
        }
    }
    return $text;
}
Example #5
0
function imageURL(&$parser, $name = '')
{
    $imageObj = Image::newFromName($name);
    if (!$imageObj || !$imageObj->exists()) {
        return wfMsg('respawn:noexist', $name);
    } else {
        return $imageObj->getViewURL();
    }
}
Example #6
0
function wfMsLinksRender(&$parser, $typ = '', $url = '', $beschreibung = '', $align = '')
{
    global $wgOut, $wgScriptPath, $wgFileTypes;
    if (empty($typ)) {
        return 'kein typ angegeben';
    }
    $base = "Media";
    $version = "";
    if ($typ != "dlink") {
        if ($typ != "vlink") {
            #wenn weder d noch v link, dann eins weiterschieben
            $align = $beschreibung;
            $beschreibung = $url;
            $url = $typ;
        }
        $img = Image::newFromName($url);
        if ($img && $img->exists()) {
            #datei existiert
            $base = ":Image";
        }
    }
    //if
    $img = Image::newFromName($url);
    if ($img && $img->exists()) {
        #datei existiert
        $base = ":Image";
    }
    $extension = strtolower(substr(strrchr($url, "."), 1));
    if ($beschreibung == "") {
        #$beschreibung = $file_info['filename'];
        $beschreibung = substr($url, 0, strlen($url) - (strlen($extension) + 1));
        // damit umlaute auch angezeigt werden
    }
    $html = "[[{$base}:{$url}|{$beschreibung}]]";
    $bild = "<img src='{$wgScriptPath}/extensions/MsLinks/images/" . $wgFileTypes['no'] . "'>";
    if (isset($wgFileTypes)) {
        foreach ($wgFileTypes as $key => $value) {
            if ($key == $extension) {
                $bild = "<img title='{$extension}' src='{$wgScriptPath}/extensions/MsLinks/images/{$value}'>";
            }
        }
    }
    //if
    $bild = $parser->insertStripItem($bild, $parser->mStripState);
    if ($typ != "vlink" && $typ != "dlink") {
        $base = "Media";
    }
    $bild = "[[{$base}:{$url}|" . $bild . "]]";
    if ($align == "right") {
        $html = $html . " " . $bild . " " . $version;
    } else {
        #standardausrichtung
        $html = $bild . " " . $html . " " . $version;
    }
    return $html;
}
Example #7
0
function jsxgraph_filter($text)
{
    if (is_int(strpos($text, '<jsxgraph'))) {
        // get every construction
        $count = substr_count($text, '<jsxgraph');
        for ($i = 0; $i < $count; $i++) {
            $start = strpos($text, '<jsxgraph');
            $end = is_int(strpos($text, '</jsxgraph>', $start)) ? strpos($text, '</jsxgraph>', $start) + 11 : strpos($text, '/>', $start) + 2;
            $jxg = substr($text, $start + 10, $end - $start - 21);
            // parse parameters of construction
            $input = split(">", $jxg);
            // fix for javascript construction input
            $input[0] = str_replace("'", '', $input[0]);
            $input[0] = str_replace('"', '', $input[0]);
            $input[0] = str_replace(' ', '&', $input[0]);
            parse_str($input[0], $params);
            $outputDivId = isset($params['box']) ? htmlspecialchars(strip_tags($params['box'])) : 'box' . $i;
            $outputBoardId = isset($params['board']) ? htmlspecialchars(strip_tags($params['board'])) : 'board' . $i;
            $width = isset($params['width']) ? htmlspecialchars(strip_tags($params['width'])) : 500;
            $height = isset($params['height']) ? htmlspecialchars(strip_tags($params['height'])) : 400;
            // output div
            $output = "<div id='" . $outputDivId . "' class='jxgbox' style='width:" . $width . "px; height:" . $height . "px;'></div>";
            $output .= "<script type='text/javascript'>";
            // construction by filename
            if (isset($params['filename'])) {
                $gxtBinary = htmlspecialchars(strip_tags($params['filename']));
                $gxtFile = Image::newFromName($gxtBinary);
                if (!$gxtFile->exists()) {
                    $error_message = "File " . $gxtFile . " not found.";
                } else {
                    $gxtURL = get_bloginfo('wpurl') . $gxtFile->getURL();
                }
                $output .= "  var " . $outputBoardId . " = JXG.JSXGraph.loadBoardFromFile('" . $outputDivId . "', '" . $gxtURL . "', 'Geonext');";
            } else {
                if (isset($params['filestring'])) {
                    $tmp = split("filestring=", $text);
                    $tmp[1] = str_replace("'", '"', $tmp[1]);
                    $tmp = split('"', $tmp[1]);
                    $filestring = htmlspecialchars(strip_tags($tmp[1]));
                    $output .= "  var " . $outputBoardId . " = JXG.JSXGraph.loadBoardFromString('" . $outputDivId . "', '" . $filestring . "', 'Geonext');";
                } else {
                    for ($j = 1; $j <= sizeof($input); $j++) {
                        $j == 1 || $j == sizeof($input) ? $output .= $input[$j] : ($output .= ">" . $input[$j]);
                    }
                }
            }
            $output .= "</script>";
            $text = substr_replace($text, $output, $start, $end - $start);
        }
    }
    return $text;
}
Example #8
0
 function execute($par)
 {
     global $wgOut, $wgRequest;
     global $wgCopyimagesBaseURL, $wgServer;
     wfLoadExtensionMessages('Copyimages');
     $this->setHeaders();
     $target = isset($par) ? $par : $wgRequest->getVal('target');
     $t = Title::newFromText($target);
     if (!$t) {
         $wgOut->addHTML(wfMsg('copyimages_noarticle'));
         return;
     }
     $id = $t->getArticleID();
     if ($wgRequest->wasPosted()) {
         $dbr = wfGetDB(DB_MASTER);
         $res = $dbr->query("select il_to from imagelinks left join page on il_to = page_title where il_from={$id} and page_id is NULL;");
         $images = array();
         while ($row = $dbr->fetchObject($res)) {
             $images[] = $row->il_to;
         }
         foreach ($images as $image) {
             $up = new UploadForm($wgRequest);
             $up->mSourceType = 'web';
         }
         return;
     }
     $dbr = wfGetDB(DB_MASTER);
     $res = $dbr->query("select il_to from imagelinks left join page on il_to = page_title where il_from={$id} and page_id is NULL;");
     $images = array();
     while ($row = $dbr->fetchObject($res)) {
         $images[] = $row->il_to;
     }
     if (sizeof($images) == 0) {
         $wgOut->addHTML(wfMsg('copyimages_nobrokenimages'));
         return;
     }
     $wgOut->addHTML(wfMsg('copyimages_brokenimages'));
     $wgOut->addHTML("<p><form id='copyimages' method='POST'><ul>");
     foreach ($images as $image) {
         $i = Image::newFromName($image);
         $target_url = $wgCopyimagesBaseURL . Image::imageUrl($i->name, $i->fromSharedDirectory);
         $desc = file_get_contents($wgCopyimagesBaseURL . "/index.php?title=Image:{$image}&action=raw");
         $desc = str_replace("\n", " ", $desc);
         $up = Title::makeTitle(NS_SPECIAL, "Upload");
         $url = $up->getFullURL() . "?desturl=" . urlencode($target_url) . "&desc=" . urlencode($desc) . "&destname=" . urlencode($image);
         $wgOut->addHTML("<li><a onclick=\"javascript:window.open('{$url}', 'upload', 'scrollbars=1,status=0,toolbar=0,location=0,menubar=0, height=500,width=800');\">{$image}</a></li>\n");
     }
     $wgOut->addHTML("</ul><br/><br/></p>");
     $dbr->freeResult($res);
 }
function launchExternal($input, $params = array())
{
    global $wgServer;
    global $wgAddServerName_EXT;
    $arrInput = split("::", $input);
    // use a different display then the file reference...
    $reference = $input;
    $display = "";
    $server = "";
    if (count($arrInput) > 1) {
        $reference = $arrInput[0];
        $display = $arrInput[1];
    }
    $reference = str_replace('\\', '/', $reference);
    $reference = str_replace('////', '//', $reference);
    //fix just incase we have "file://\\server"
    if (strpos($reference, "://") !== false) {
        $section1 = explode("/", $reference);
        $section2 = explode(".", $section1[2]);
        //parse the dots (sub-domains)
        if ($wgAddServerName_EXT && strpos($reference, "file://") !== false) {
            $server = " <i>({$section2['0']})</i>";
        }
        if ($display == "") {
            $display = $section1[count($section1) - 1];
        }
        //default the file name
        return "<a href='" . $reference . "' target='new'>" . ($display == "" ? $reference : $display) . "{$server}</a>";
    }
    // wiki uploaded media or image reference
    $img = Image::newFromName($reference);
    if ($img->exists()) {
        return buildLink($wgServer . $img->getURL(), $display == "" ? $reference : $display);
    }
    return $input . " <i>(bad reference)</i>";
}
Example #10
0
 /** 
  * Load metadata from the file itself
  */
 function loadFromFile()
 {
     global $wgUseSharedUploads, $wgSharedUploadDirectory, $wgLang, $wgShowEXIF;
     $fname = 'Image::loadFromFile';
     wfProfileIn($fname);
     $this->imagePath = $this->getFullPath();
     $this->fileExists = file_exists($this->imagePath);
     $this->fromSharedDirectory = false;
     $gis = array();
     if (!$this->fileExists) {
         wfDebug("{$fname}: " . $this->imagePath . " not found locally!\n");
     }
     # If the file is not found, and a shared upload directory is used, look for it there.
     if (!$this->fileExists && $wgUseSharedUploads && $wgSharedUploadDirectory) {
         # In case we're on a wgCapitalLinks=false wiki, we
         # capitalize the first letter of the filename before
         # looking it up in the shared repository.
         $sharedImage = Image::newFromName($wgLang->ucfirst($this->name));
         $this->fileExists = file_exists($sharedImage->getFullPath(true));
         if ($this->fileExists) {
             $this->name = $sharedImage->name;
             $this->imagePath = $this->getFullPath(true);
             $this->fromSharedDirectory = true;
         }
     }
     if ($this->fileExists) {
         $magic =& wfGetMimeMagic();
         $this->mime = $magic->guessMimeType($this->imagePath, true);
         $this->type = $magic->getMediaType($this->imagePath, $this->mime);
         # Get size in bytes
         $this->size = filesize($this->imagePath);
         $magic =& wfGetMimeMagic();
         # Height and width
         if ($this->mime == 'image/svg') {
             wfSuppressWarnings();
             $gis = wfGetSVGsize($this->imagePath);
             wfRestoreWarnings();
         } elseif (!$magic->isPHPImageType($this->mime)) {
             # Don't try to get the width and height of sound and video files, that's bad for performance
             $gis[0] = 0;
             //width
             $gis[1] = 0;
             //height
             $gis[2] = 0;
             //unknown
             $gis[3] = "";
             //width height string
         } else {
             wfSuppressWarnings();
             $gis = getimagesize($this->imagePath);
             wfRestoreWarnings();
         }
         wfDebug("{$fname}: " . $this->imagePath . " loaded, " . $this->size . " bytes, " . $this->mime . ".\n");
     } else {
         $gis[0] = 0;
         //width
         $gis[1] = 0;
         //height
         $gis[2] = 0;
         //unknown
         $gis[3] = "";
         //width height string
         $this->mime = NULL;
         $this->type = MEDIATYPE_UNKNOWN;
         wfDebug("{$fname}: " . $this->imagePath . " NOT FOUND!\n");
     }
     $this->width = $gis[0];
     $this->height = $gis[1];
     #NOTE: $gis[2] contains a code for the image type. This is no longer used.
     #NOTE: we have to set this flag early to avoid load() to be called
     # be some of the functions below. This may lead to recursion or other bad things!
     # as ther's only one thread of execution, this should be safe anyway.
     $this->dataLoaded = true;
     if ($this->fileExists && $wgShowEXIF) {
         $this->metadata = serialize($this->retrieveExifData());
     } else {
         $this->metadata = serialize(array());
     }
     if (isset($gis['bits'])) {
         $this->bits = $gis['bits'];
     } else {
         $this->bits = 0;
     }
     wfProfileOut($fname);
 }
Example #11
0
 /**
  * Load metadata from the file itself
  */
 function loadFromFile()
 {
     global $wgUseSharedUploads, $wgSharedUploadDirectory, $wgContLang;
     wfProfileIn(__METHOD__);
     $this->imagePath = $this->getFullPath();
     $this->fileExists = file_exists($this->imagePath);
     $this->fromSharedDirectory = false;
     $gis = array();
     if (!$this->fileExists) {
         wfDebug(__METHOD__ . ': ' . $this->imagePath . " not found locally!\n");
     }
     # If the file is not found, and a shared upload directory is used, look for it there.
     if (!$this->fileExists && $wgUseSharedUploads && $wgSharedUploadDirectory) {
         # In case we're on a wgCapitalLinks=false wiki, we
         # capitalize the first letter of the filename before
         # looking it up in the shared repository.
         $sharedImage = Image::newFromName($wgContLang->ucfirst($this->name));
         $this->fileExists = $sharedImage && file_exists($sharedImage->getFullPath(true));
         if ($this->fileExists) {
             $this->name = $sharedImage->name;
             $this->imagePath = $this->getFullPath(true);
             $this->fromSharedDirectory = true;
         }
     }
     if ($this->fileExists) {
         $magic =& MimeMagic::singleton();
         $this->mime = $magic->guessMimeType($this->imagePath, true);
         $this->type = $magic->getMediaType($this->imagePath, $this->mime);
         $handler = MediaHandler::getHandler($this->mime);
         # Get size in bytes
         $this->size = filesize($this->imagePath);
         # Height, width and metadata
         if ($handler) {
             $gis = $handler->getImageSize($this, $this->imagePath);
             $this->metadata = $handler->getMetadata($this, $this->imagePath);
         } else {
             $gis = false;
             $this->metadata = '';
         }
         wfDebug(__METHOD__ . ': ' . $this->imagePath . " loaded, " . $this->size . " bytes, " . $this->mime . ".\n");
     } else {
         $this->mime = NULL;
         $this->type = MEDIATYPE_UNKNOWN;
         $this->metadata = '';
         wfDebug(__METHOD__ . ': ' . $this->imagePath . " NOT FOUND!\n");
     }
     if ($gis) {
         $this->width = $gis[0];
         $this->height = $gis[1];
     } else {
         $this->width = 0;
         $this->height = 0;
     }
     #NOTE: $gis[2] contains a code for the image type. This is no longer used.
     #NOTE: we have to set this flag early to avoid load() to be called
     # be some of the functions below. This may lead to recursion or other bad things!
     # as ther's only one thread of execution, this should be safe anyway.
     $this->dataLoaded = true;
     if (isset($gis['bits'])) {
         $this->bits = $gis['bits'];
     } else {
         $this->bits = 0;
     }
     wfProfileOut(__METHOD__);
 }
Example #12
0
function jsxgraphOutput($input, $args, $parser)
{
    global $wgServer;
    // URL of the WIKI's server
    global $jsxgraph_version;
    // see line 9 of this file
    global $markerList;
    global $outputURI;
    $error_message = "no error";
    //will be overwritten, if error occurs
    $CRLF = "\r\n";
    // Look for required parameters
    if (!(isset($args['filename']) || isset($args['filestring']) || isset($input))) {
        $error_message = "Missing parameter (width or height, filename, string or input).";
    }
    $output = "<!-- JSXGraph MediaWiki extension " . $jsxgraph_version . " -->";
    $markercount = count($markerList);
    if ($markercount > 0) {
        $defaultBoard = "brd" . $markercount;
        $defaultBox = "jxgbox" . $markercount;
    } else {
        $defaultBoard = "brd";
        $defaultBox = "jxgbox";
    }
    $outputDivId = isset($args['box']) ? htmlspecialchars(strip_tags($args['box'])) : $defaultBox;
    $outputBoardId = isset($args['board']) ? htmlspecialchars(strip_tags($args['board'])) : $defaultBoard;
    $width = isset($args['width']) ? htmlspecialchars(strip_tags($args['width'])) : 500;
    $height = isset($args['height']) ? htmlspecialchars(strip_tags($args['height'])) : 400;
    // Load necessary stylesheet und scripts
    if ($markercount == 0) {
        $output .= "<link rel='stylesheet' type='text/css' href='" . $outputURI . "/jsxgraph.css' />";
        $output .= "<script src='" . $outputURI . "/jsxgraphcore.js' type='text/javascript'></script>";
    }
    // Output div
    $output .= "<div id='" . $outputDivId . "' class='jxgbox' style='width:" . $width . "px; height:" . $height . "px;'></div>";
    $output .= "<script type='text/javascript'>";
    // construction input method
    if (isset($args['filename'])) {
        // string of url to gxt-file
        // retrieve URL of .gxt file
        $gxtBinary = htmlspecialchars(strip_tags($args['filename']));
        $gxtFile = Image::newFromName($gxtBinary);
        if (!$gxtFile->exists()) {
            $error_message = "File " . $gxtFile . " not found.";
        } else {
            $gxtURL = $wgServer . $gxtFile->getURL();
        }
        $output .= "  var " . $outputBoardId . " = JXG.JSXGraph.loadBoardFromFile('" . $outputDivId . "', '" . $gxtURL . "', 'Geonext');";
    }
    if (isset($args['filestring'])) {
        // binary content of gxt-file
        $output .= "  var " . $outputBoardId . " = JXG.JSXGraph.loadBoardFromString('" . $outputDivId . "', '" . htmlspecialchars(strip_tags($args['filestring'])) . "', 'Geonext');";
    }
    if (isset($input)) {
        // content between <jsxgraph>-tags
        $output .= $input;
    }
    $output .= "</script>";
    // if error occured, discard and output error message
    if ($error_message != "no error") {
        $output = "<p>Error in MediaWiki extension (JSXGraph.php): <em>" . $error_message . "</em></p>" . $CRLF;
    }
    // Send the output to the browser
    $marker = "jsxgraph-marker" . $markercount . "-jsxgraph";
    $markerList[$markercount] = $output;
    return $marker;
}
Example #13
0
 /**
  * Really returns an URL for a given image page.
  */
 protected function getImageURLreal(&$img)
 {
     $ititle = Title::newFromText($img);
     // this really shouldn't happen... not much we can do here.
     if (!is_object($ititle)) {
         return self::codeInvalidTitleImage;
     }
     // check if we are dealing with an InterWiki link
     if ($ititle->isLocal()) {
         $image = Image::newFromName($img);
         if (!$image->exists()) {
             return self::codeImageNotExist;
         }
         $iURL = $image->getURL();
     } else {
         $iURL = $ititle->getFullURL();
     }
     return $iURL;
 }
Example #14
0
 /**
  * Check if there's an overwrite conflict and, if so, if restrictions
  * forbid this user from performing the upload.
  *
  * @return mixed true on success, WikiError on failure
  * @access private
  */
 function checkOverwrite($name)
 {
     $img = Image::newFromName($name);
     if (is_null($img)) {
         // Uh... this shouldn't happen ;)
         // But if it does, fall through to previous behavior
         return false;
     }
     $error = '';
     if ($img->exists()) {
         global $wgUser, $wgOut;
         if ($img->isLocal()) {
             if (!$wgUser->isAllowed('reupload')) {
                 $error = 'fileexists-forbidden';
             }
         } else {
             if (!$wgUser->isAllowed('reupload') || !$wgUser->isAllowed('reupload-shared')) {
                 $error = "fileexists-shared-forbidden";
             }
         }
     }
     if ($error) {
         $errorText = wfMsg($error, wfEscapeWikiText($img->getName()));
         return new WikiError($wgOut->parse($errorText));
     }
     // Rockin', go ahead and upload
     return true;
 }
 /** I BORROWED THIS FUNCTION FROM SpecialUpload.php!! CHECK FOR EACH VERSION OF MEDIAWIKI, IF
  *  THIS FUNCTION STILL MAKES SENSE!
  *
  * Check if there's an overwrite conflict and, if so, if restrictions
  * forbid this user from performing the upload.
  *
  * @return true on success, false on failure
  * @access private
  */
 function userCanOverwrite($name)
 {
     $img = Image::newFromName($name);
     if (is_null($img)) {
         // Uh... this shouldn't happen ;)
         // But if it does, fall through to previous behavior
         return false;
     }
     if ($img->exists()) {
         global $wgUser, $wgOut;
         if ($img->isLocal()) {
             if (!$wgUser->isAllowed('reupload')) {
                 return false;
             }
         } else {
             if (!$wgUser->isAllowed('reupload') || !$wgUser->isAllowed('reupload-shared')) {
                 return false;
             }
         }
     }
     // Rockin', go ahead and upload
     return true;
 }
Example #16
0
function wfAnyWikiDrawParserFunction_Render(&$parser, $name = null, $width = null, $height = null)
{
    global $wgUser, $wgLang, $wgTitle, $wgRightsText, $wgOut, $wgArticlePath, $wgScriptPath, $wgEnableUploads;
    $skin = $wgUser->getSkin();
    wfAnyWikiDrawLoadMessages();
    // Don't cache pages with drawings on it
    $parser->disableCache();
    # Validate parameters
    $error = '';
    if ($name == null || strlen($name) == 0) {
        $error .= '<br>Please specify a name for your drawing.';
    }
    if ($width != null && (!is_numeric($width) || $width < 1 || $width > 2000)) {
        $error .= '<br>Please specify the width as a number between 1 and 2000 or leave it away.';
    }
    if ($height != null && (!is_numeric($height) || $height < 1 || $height > 2000)) {
        $error .= '<br>Please specify the height as a number between 1 and 2000 or leave it away.';
    }
    if (strlen($error) > 0) {
        $error = '<b>Sorry.</b>' . $error . '<br>' . 'Usage: <code>{{#drawing:<i>image.svg</i>|<i>width</i>||<i>height</i>}}</code><br>' . 'Example: <code>{{#drawing:HappyDrawing.svg|400|300}}</code><br>';
        return array($error, 'isHTML' => true, 'noparse' => true);
    }
    # The parser function itself
    # The input parameters are wikitext with templates expanded
    # The output should be wikitext too, but in this case, it is HTML
    #return array("param1 is $param1 and param2 is $param2", 'isHTML');
    # Generate the image HTML as if viewed by a web request
    $image = Image::newFromName($name);
    $isProtected = $parser->getTitle()->isProtected();
    if ($width == null && $image->getWidth() != -1) {
        $width = $image->getWidth();
    }
    if ($height == null && $image->getHeight() != -1) {
        $height = $image->getHeight();
    }
    // render a header
    $output = '<table><tr><td>';
    if ($wgEnableUploads && !$isProtected && key_exists('drawingtitle', $_POST) && $_POST['drawingtitle'] == $name) {
        // edit the drawing using the applet
        global $wgUsePathInfo;
        if ($wgUsePathInfo) {
            $downloadURL = str_replace('$1', 'Special:AnyWikiDraw?image=' . htmlspecialchars($image->getName()), $wgArticlePath);
        } else {
            $downloadURL = str_replace('$1', 'Special:AnyWikiDraw&image=' . htmlspecialchars($image->getName()), $wgArticlePath);
        }
        $uploadURL = str_replace('$1', 'Special:AnyWikiDraw', $wgArticlePath);
        $output .= '<a name="anywikidraw" id="anywikidraw">' . '<applet codebase="/" archive="' . $wgScriptPath . '/extensions/AnyWikiDraw/AnyWikiDrawForMediaWiki.jar"' . ' code="org.anywikidraw.mediawiki.MediaWikiDrawingApplet.class"' . ' width="' . htmlspecialchars(min(max($width + 4, 600), 800)) . '" ' . ' height="' . htmlspecialchars(min(max($height + 140, 480), 600)) . '">' . '<param name="DrawingName" value="' . htmlspecialchars($name) . '">' . '<param name="DrawingWidth" value="' . htmlspecialchars($width) . '">' . '<param name="DrawingHeight" value="' . htmlspecialchars($height) . '">' . ($image->getURL() !== '' ? '<param name="DrawingURL" value="' . $downloadURL . '">' : '') . '<param name="PageURL" value="' . htmlspecialchars($wgTitle->getLocalURL()) . '">' . '<param name="UploadURL" value="' . $uploadURL . '">' . '<param name="Locale" value="' . $wgUser->getOption('language', 'en') . '"/>' . '<param name="codebase_lookup" value="false"/>' . '<param name="classloader_cache" value="false"/>' . '<param name="java_arguments" value="-Djnlp.packEnabled=true"/>' . '<param name="image" value="lib/Splash.gif"/>' . '<param name="boxborder" value="false"/>' . '<param name="centerimage" value="true"/>' . '</applet>' . '</a>';
        $output .= '<div style="' . 'background-color: #C9CDD6; border: 1px solid #ccc; padding: 5px 10px 5px 10px; text-align: left; ' . 'font-size: 12px; line-height: 16px; ' . '">' . wfMsg($image->getURL() == '' ? 'anywikidraw_license_terms_new_work' : 'anywikidraw_license_terms_derived_work', '<a href=' . wfMsgForContent('copyrightpage') . '>' . wfMsg('copyrightpage') . '</a>', '<a href="./Image:' . $name . '">Image:' . $name . '</a>') . '</div>';
    } else {
        // Retrieve the page object of the image to determine, whether the user may edit it
        $filtered = preg_replace("/[^" . Title::legalChars() . "]|:/", '-', $name);
        $nt = Title::newFromText($filtered);
        if (!is_null($nt)) {
            $nt =& Title::makeTitle(NS_IMAGE, $nt->getDBkey());
        }
        // Determine if the user has permission to edit the image
        $userCanEdit = $wgEnableUploads && !$isProtected && (is_null($nt) || $nt->userCanEdit()) && ($image->getURL() == null || $wgUser->isAllowed('reupload'));
        // Determine if the user may edit images using the specified
        // filename extension.
        if ($userCanEdit) {
            $extension = array_pop(explode('.', $filtered));
            global $wgFileExtensions;
            $userCanEdit = in_array($extension, $wgFileExtensions);
        }
        // If the user can edit the image, display an edit link.
        // We do not display the edit link, if the user is already
        // editing a drawing.
        if ($userCanEdit && !key_exists('drawingtitle', $_POST)) {
            $formId = 'Form' . rand();
            global $wgUsePathInfo;
            if ($wgUsePathInfo) {
                $action = $wgTitle->getLocalURL() . '#anywikidraw';
            } else {
                //$action = str_replace('?','#anywikidraw?',$wgTitle->getLocalURL());
                $action = $wgTitle->getLocalURL();
            }
            $output .= '<form name="' . $formId . '" method="post" action="' . $action . '">' . '<input type="hidden" name="drawingtitle" value="' . htmlspecialchars($name) . '">' . '<p align="right">' . '[<a href="javascript:document.' . $formId . '.submit();">' . wfMsg('edit') . '</a>]' . '<noscript><input type="submit" name="submit" value="' . wfMsg('edit') . '"></input></noscript>' . '</p>';
        }
        // render the drawing
        $image->width = $width;
        // FIXME This is an ugly hack to get a view URL
        $viewURL = $image->getViewURL();
        if ($image->getURL() == '') {
            // the drawing does not exist yet, render an empty rectangle
            $output .= '<div style="border:1px solid #000;text-align:center;' . ($width != null ? 'width:' . $width . 'px;' : '') . ($height != null ? 'height:' . $height . 'px;' : '') . '"' . '>' . htmlspecialchars($name) . '</div>';
        } else {
            if (substr($name, -4) == '.svg' && $viewURL == null) {
                // SVG images need an object tag
                $output .= '<object ' . 'type="image/svg+xml" ' . 'data="' . ($viewURL != null ? $viewURL : $image->getURL()) . '" ' . ($width != null ? 'width="' . $width . '" ' : '') . ($height != null ? 'height="' . $height . '" ' : '') . '></object>';
            } else {
                // All other image types need an img tag
                // Render the image map, if it exists
                $thumbnail = $image->getThumbnail($width);
                $isImageMap = $thumbnail != null && file_exists($thumbnail->path . '.map');
                $mapId = 'Map' . rand();
                if ($isImageMap) {
                    $output .= '<map name="' . $mapId . '">' . file_get_contents($thumbnail->path . '.map') . '</map>';
                }
                // Render the image
                if (!$isImageMap) {
                    $output .= '<a href="./Image:' . $name . '">';
                }
                // Note: We append the timestamp of the image to the
                //       view URL as a query string. This way, we ensure,
                //       that the browser always displays the last edited version
                //       of the image
                $output .= '<img ' . 'src="' . ($viewURL != null ? $viewURL : $image->getURL()) . '?version=' . $image->nextHistoryLine()->img_timestamp . '" ' . ($width != null ? 'width="' . $width . '" ' : '') . ($height != null ? 'height="' . $height . '" ' : '') . 'alt="Image:' . $name . '" ' . 'title="Image:' . $name . '" ' . ($isImageMap ? 'usemap="#' . $mapId . '" ' : '') . '></img>';
                if (!$isImageMap) {
                    $output .= '</a>';
                }
            }
        }
        // If the user can edit the image, display an edit link.
        // We do not display the edit link, if the user is already
        // editing a drawing.
        if ($userCanEdit && !key_exists('drawingtitle', $_POST)) {
            $output .= '</form>';
        }
    }
    // render a footer
    $output .= '</tr></td></table>';
    return array($output, 'isHTML' => true, 'noparse' => true);
}
Example #17
0
 function displayListDB()
 {
     global $wgUser;
     global $wgLang;
     global $wgContLang;
     global $wgTitle;
     global $wgOut;
     $sk =& $wgUser->getSkin();
     $dbr =& wfGetDB(DB_SLAVE);
     //echo $this->buildSQL();
     $res = $dbr->query($this->buildSQL());
     if ($dbr->numRows($res) == 0) {
         return htmlspecialchars("No pages found.");
     }
     $output = "";
     $output .= "<div id=\"ListPages" . $this->listid . "\">";
     $output .= "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td>" . "\n";
     $ListCount = 0;
     $ListCountShow = 0;
     while ($row = $dbr->fetchObject($res)) {
         if ($ListCountShow < $this->ShowCount - 1) {
             $title = Title::makeTitle($row->page_namespace, $row->page_title);
             $output .= "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"listpageItem\">";
             // ** MAIN ROW
             // Picture (optional) + Title
             $output .= "<tr>";
             if ($this->ShowPic == 1) {
                 $PageImage = $this->getPageImage($row->page_id);
                 if ($PageImage) {
                     $output .= "<td class=\"listpage\" rowspan=\"5\" valign=\"top\" style='padding-right:20px'>";
                     $img = Image::newFromName($PageImage);
                     $img_tag = '<img src="' . $img->getURL() . '" alt="' . $PageImage . '" width="65"/>';
                     $output .= $img_tag;
                     //str_replace("</p>","",str_replace("<p>","",$img->getText()));
                     $output .= "</td>";
                 }
             }
             if ($this->ShowVoteBox == 1) {
                 $output .= "<td width=\"30\">" . $this->getVoteBox($row->vote_count) . "</td><td width=\"8\"></td>";
             }
             if ($this->ShowCommentBox == 1) {
                 $output .= "<td width=\"30\">" . $this->getCommentBox($row->comment_count) . "</td><td width=\"8\"></td>";
             }
             if ($this->ShowDetails == 1) {
                 $output .= '<td class="showdetails" ' . ($this->ShowVoteBox == 1 || $this->ShowCommentBox == 1 ? 'valign="top"' : '') . '>';
             } else {
                 $output .= '<td class="hidedetails" ' . ($this->ShowVoteBox == 1 || $this->ShowCommentBox == 1 ? 'valign="top"' : '') . '>';
             }
             // ** Display Link
             if ($row->page_namespace != 6) {
                 //$output .= $sk->makeKnownLinkObj($title, $wgContLang->convertHtml($title->getText()));
                 $output .= '<a href="' . $title->getFullURL() . '" title="' . $title->getText() . '">' . $title->getText() . '</a>';
             } else {
                 $CommentParser = new Parser();
                 $img = $CommentParser->parse("[[Image:" . $row->page_title . "|75px]]", $wgTitle, $wgOut->mParserOptions, true);
                 $output .= $img->getText();
             }
             $output .= "</td>";
             $output .= "</tr>";
             // ** END Main Row
             // ** Display Create Date
             if ($this->ShowDate == 1) {
                 $output .= "<tr>";
                 $output .= '<td class="listdate">';
                 $output .= "(created " . $this->getTimeStr($row->page_id) . " ago)";
                 //date("D m/d/y, g:i a T",$this->getCreateDate($row->page_id) - (60 * 60 * 1));
                 $output .= '</td>';
                 $output .= "</tr>";
             }
             // ** Display Average Score + Stars Graphics
             if ($this->ShowRating == 1) {
                 $Vote = new VoteStars($row->page_id);
                 $output .= "<tr>";
                 $output .= '<td class="listrating">';
                 $output .= "<table cellpadding=\"0\" cellspacing=\"0\"><tr><td><span class=\"listrating-score-title\">Score:</span> <span class=\"listrating-score\">" . number_format($row->vote_avg, 2) . "</span></td><td>" . $Vote->displayRating($row->vote_avg) . "</td></tr></table>";
                 $output .= "</td>";
                 $output .= "</tr>";
             }
             // ** Display Blurb of N Characters (stored in ShowBlurb)
             if ($this->ShowBlurb > 0) {
                 $output .= "<tr>";
                 $output .= "<td class=\"listblurb\">";
                 $output .= $this->getBlurb($row->page_title);
                 $output .= '</td>';
                 $output .= "</tr>";
             }
             // ** Show most popular categories for current page
             if ($this->ShowCtg == 1) {
                 $output .= "<tr>";
                 $output .= "<td class=\"categorylinks\">";
                 $output .= $this->getCategoryLinks($row->page_id, 3);
                 $output .= '</td>';
                 $output .= "</tr>";
             }
             // ** Show Stats for page
             if ($this->ShowStats == 1) {
                 $output .= "<tr>";
                 $output .= '<td class="liststats"><span class="liststatstitle">stats</span>: ';
                 if ($this->Order != 'VOTES') {
                     $output .= '<img src="images/voteIcon.gif" alt="v" /> ' . $row->vote_count . ' votes';
                 }
                 if ($this->Order == 'PAGEVIEWS') {
                     $output .= ' [' . $row->page_counter . ' Views]';
                 }
                 if ($this->Order == 'VOTES') {
                     $output .= '<img src="images/voteIcon.gif" alt="v" /> ' . $row->vote_count . ' votes';
                 }
                 if ($this->Order == 'EDITS') {
                     $output .= ' [' . $row->Num_Edits . ' Edits]';
                 }
                 if ($this->Order == 'LATEST') {
                     $output .= ' [Updated ' . wfTimestamp(TS_RFC2822, $row->page_touched) . ']';
                 }
                 if ($this->ShowRating == 1) {
                     $CommentLabel = "reviews";
                 } else {
                     $CommentLabel = "comments";
                 }
                 $output .= ' <img src="images/commentIcon.gif" alt="c" /> ' . $row->comment_count . ' ' . $CommentLabel . '</td>';
                 $output .= "</tr>";
             }
             $ListCountShow++;
             $output .= "</table>";
         }
         $ListCount++;
     }
     if ($this->ShowNav == 1) {
         $output .= "<div id=\"listpagesnav\">";
         if ($this->PageNo == 1) {
             $output .= $this->getNavLink("Prev", 0);
         } else {
             $output .= $this->getNavLink("Prev", -1);
         }
         $output .= "&nbsp;";
         if ($ListCount > $ListCountShow) {
             $output .= $this->getNavLink("Next", 1);
         } else {
             $output .= $this->getNavLink("Next", 0);
         }
         $output .= "</div>";
     }
     $output .= "</td></tr></table>";
     $output .= "</div>";
     return $output;
 }
Example #18
0
 function html()
 {
     // gory html output
     global $wgScriptPath;
     global $wgUploadPath;
     global $bibtexArray;
     global $wbib_allowdivpopup;
     global $wbib_allowbibpopup;
     global $wbib_usejavascript;
     global $wbib_pdficon;
     global $wbib_psicon;
     $entry = $this->entry;
     //$entry->parse(); // needed ?
     $output = '';
     // for things only needed once
     if (count($bibtexArray) == 0 && $wbib_allowdivpopup) {
         $output .= '<link rel="stylesheet" type="text/css" href="' . $wgScriptPath . '/extensions/BibTex/bibtex.css" />' . "\n";
     }
     // Writing the beginning of the entry
     if ($entry->get_field('author') != '') {
         $output .= "<i>" . $entry->get_field('author') . "</i> - ";
     } else {
         $output .= "<i>" . $entry->get_field('editor') . "</i> - ";
     }
     $output .= "<b>" . $entry->get_field('title') . "</b><br/>";
     $output .= '<dl><dd>' . $entry->get_where_published() . ' ';
     $output .= $entry->get_publishing_details() . "</dd><dd>";
     // Checking if pdf file is there
     if ('' != $entry->get_field('pdf')) {
         $im = Image::newfromName($entry->get_field('pdf'));
         $im2 = Image::newFromName($wbib_pdficon);
         if ($this->allowed($im->getTitle())) {
             $output .= '<a href="' . $im->getUrl() . '"><img src="' . $im2->getURL() . '">Pdf</a> ';
             array_push($bibtexArray, $entry->get_field('pdf'));
         }
     }
     // Checking if ps file is there
     if ('' != $entry->get_field('ps')) {
         $im = Image::newfromName($entry->get_field('ps'));
         $im2 = Image::newFromName($wbib_psicon);
         if ($this->allowed($im->getTitle())) {
             $output .= '<a href="' . $im->getUrl() . '"><img src="' . $im2->getURL() . '">Postscript</a> ';
             array_push($bibtexArray, $entry->get_field('ps'));
         }
     }
     // Checking for url
     if ('' != $entry->get_field('url')) {
         $url = $entry->get_field('url');
         $output .= '<a href="' . $url . '">' . $url . '</a><br>';
     }
     global $wbibauthor, $wbibtitle, $wbibin, $wbibaddress, $wbibdate;
     //$output .= "<a class=\"bibtex\">".$entry->get_shortName();
     // This for a div popup demonstration
     $shouldlink = $wbib_allowdivpopup || $wbib_allowbibpopup && $wbib_usejavascript;
     if ($shouldlink) {
         $output .= '<a class="bibtex" href="';
         if ($wbib_allowbibpopup && $wbib_usejavascript) {
             $output .= "javascript:bibpopup('" . $entry->get_content() . "')\">Bibtex";
         } else {
             $output .= '#">Bibtex';
         }
         if ($wbib_allowdivpopup) {
             $output .= "<div>";
             $output .= "<b>{$wbibauthor} : </b>" . $entry->get_field('author') . "<br/>";
             $output .= "<b>{$wbibtitle} : </b>" . $entry->get_field('title') . "<br/>";
             $output .= "<b>{$wbibin} : </b>" . $entry->get_where_published() . " - " . $entry->get_field('page') . "<br/>";
             $output .= "<b>{$wbibaddress} : </b>" . $entry->get_field('address') . "<br/>";
             $output .= "<b>{$wbibdate} : </b>" . $entry->get_field('month') . " " . $entry->get_field('year') . "<br/>";
             $output .= "</div>";
         }
         $output .= "</a>";
     }
     $output .= "</dd></dl>";
     return $output;
 }
Example #19
0
 function revert()
 {
     global $wgOut, $wgRequest, $wgUser;
     $oldimage = $wgRequest->getText('oldimage');
     if (strlen($oldimage) < 16) {
         $wgOut->showUnexpectedValueError('oldimage', htmlspecialchars($oldimage));
         return;
     }
     if (strstr($oldimage, "/") || strstr($oldimage, "\\")) {
         $wgOut->showUnexpectedValueError('oldimage', htmlspecialchars($oldimage));
         return;
     }
     if (wfReadOnly()) {
         $wgOut->readOnlyPage();
         return;
     }
     if ($wgUser->isAnon()) {
         $wgOut->showErrorPage('uploadnologin', 'uploadnologintext');
         return;
     }
     if (!$this->mTitle->userCanEdit()) {
         $wgOut->sysopRequired();
         return;
     }
     if ($wgUser->isBlocked()) {
         return $this->blockedIPpage();
     }
     if (!$wgUser->matchEditToken($wgRequest->getVal('wpEditToken'), $oldimage)) {
         $wgOut->showErrorPage('internalerror', 'sessionfailure');
         return;
     }
     $name = substr($oldimage, 15);
     $dest = wfImageDir($name);
     $archive = wfImageArchiveDir($name);
     $curfile = "{$dest}/{$name}";
     if (!is_dir($dest)) {
         wfMkdirParents($dest);
     }
     if (!is_dir($archive)) {
         wfMkdirParents($archive);
     }
     if (!is_file($curfile)) {
         $wgOut->showFileNotFoundError(htmlspecialchars($curfile));
         return;
     }
     $oldver = wfTimestampNow() . "!{$name}";
     $dbr =& wfGetDB(DB_SLAVE);
     $size = $dbr->selectField('oldimage', 'oi_size', array('oi_archive_name' => $oldimage));
     if (!rename($curfile, "{$archive}/{$oldver}")) {
         $wgOut->showFileRenameError($curfile, "{$archive}/{$oldver}");
         return;
     }
     if (!copy("{$archive}/{$oldimage}", $curfile)) {
         $wgOut->showFileCopyError("{$archive}/{$oldimage}", $curfile);
         return;
     }
     # Record upload and update metadata cache
     $img = Image::newFromName($name);
     $img->recordUpload($oldver, wfMsg("reverted"));
     $wgOut->setPagetitle(wfMsg('actioncomplete'));
     $wgOut->setRobotpolicy('noindex,nofollow');
     $wgOut->addHTML(wfMsg('imagereverted'));
     $descTitle = $img->getTitle();
     $wgOut->returnToMain(false, $descTitle->getPrefixedText());
 }
Example #20
0
 function recordUpload($oldver, $desc, $copyStatus = '', $source = '', $watch = false)
 {
     global $wgUser, $wgLang, $wgTitle, $wgDeferredUpdateList;
     global $wgUseCopyrightUpload, $wgUseSquid, $wgPostCommitUpdateList;
     $img = Image::newFromName($this->mUploadSaveName);
     $fname = 'Image::recordUpload';
     $dbw =& wfGetDB(DB_MASTER);
     Image::checkDBSchema($dbw);
     // Delete thumbnails and refresh the metadata cache
     $img->purgeCache();
     // Fail now if the image isn't there
     if (!$img->fileExists || $img->fromSharedDirectory) {
         wfDebug("Image::recordUpload: File " . $img->imagePath . " went missing!\n");
         return false;
     }
     if ($wgUseCopyrightUpload) {
         $textdesc = '== ' . wfMsg('filedesc') . " ==\n" . $desc . "\n" . '== ' . wfMsg('filestatus') . " ==\n" . $copyStatus . "\n" . '== ' . wfMsg('filesource') . " ==\n" . $source;
     } else {
         $textdesc = $desc;
     }
     $now = $dbw->timestamp();
     #split mime type
     if (strpos($img->mime, '/') !== false) {
         list($major, $minor) = explode('/', $img->mime, 2);
     } else {
         $major = $img->mime;
         $minor = "unknown";
     }
     # Test to see if the row exists using INSERT IGNORE
     # This avoids race conditions by locking the row until the commit, and also
     # doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition.
     $dbw->insert('image', array('img_name' => $img->name, 'img_size' => $img->size, 'img_width' => IntVal($img->width), 'img_height' => IntVal($img->height), 'img_bits' => $img->bits, 'img_media_type' => $img->type, 'img_major_mime' => $major, 'img_minor_mime' => $minor, 'img_timestamp' => $now, 'img_description' => $desc, 'img_user' => $wgUser->getID(), 'img_user_text' => $wgUser->getName(), 'img_metadata' => $img->metadata), $fname, 'IGNORE');
     $descTitle = $img->getTitle();
     $purgeURLs = array();
     $article = new Article($descTitle);
     $minor = false;
     $watch = $watch || $wgUser->isWatched($descTitle);
     $suppressRC = true;
     // There's already a log entry, so don't double the RC load
     if ($descTitle->exists()) {
         // TODO: insert a null revision into the page history for this update.
         if ($watch) {
             $wgUser->addWatch($descTitle);
         }
         # Invalidate the cache for the description page
         $descTitle->invalidateCache();
         $purgeURLs[] = $descTitle->getInternalURL();
     } else {
         $this->insertNewArticle($article, $textdesc, $desc, $minor, $watch, $suppressRC);
     }
     # Invalidate cache for all pages using this image
     $linksTo = $img->getLinksTo();
     if ($wgUseSquid) {
         $u = SquidUpdate::newFromTitles($linksTo, $purgeURLs);
         array_push($wgPostCommitUpdateList, $u);
     }
     Title::touchArray($linksTo);
     $log = new LogPage('upload');
     $log->addEntry('upload', $descTitle, $desc);
     return true;
 }
Example #21
0
 private function tryImageURL($imgName)
 {
     $image = Image::newFromName($imgName);
     if (!$image->exists()) {
         return null;
     }
     return $image->getURL();
 }
 /**
  * Really do the upload
  * Checks are made in SpecialUpload::execute()
  * @access private
  */
 function processUpload()
 {
     global $wgUser, $wgOut, $wgLang, $wgContLang;
     global $wgUploadDirectory;
     global $wgUseCopyrightUpload, $wgCheckCopyrightUpload;
     /**
      * If there was no filename or a zero size given, give up quick.
      */
     if (trim($this->mOname) == '' || empty($this->mUploadSize)) {
         return $this->mainUploadForm('<li>' . wfMsg('emptyfile') . '</li>');
     }
     # Chop off any directories in the given filename
     if ($this->mDestFile) {
         $basename = basename($this->mDestFile);
     } else {
         $basename = basename($this->mOname);
     }
     /**
      * We'll want to blacklist against *any* 'extension', and use
      * only the final one for the whitelist.
      */
     list($partname, $ext) = $this->splitExtensions($basename);
     if (count($ext)) {
         $finalExt = $ext[count($ext) - 1];
     } else {
         $finalExt = '';
     }
     $fullExt = implode('.', $ext);
     if (strlen($partname) < 3) {
         $this->mainUploadForm(wfMsg('minlength'));
         return;
     }
     /**
      * Filter out illegal characters, and try to make a legible name
      * out of it. We'll strip some silently that Title would die on.
      */
     $filtered = preg_replace("/[^" . Title::legalChars() . "]|:/", '-', $basename);
     $nt = Title::newFromText($filtered);
     if (is_null($nt)) {
         return $this->uploadError(wfMsg('illegalfilename', htmlspecialchars($filtered)));
     }
     $nt =& Title::makeTitle(NS_IMAGE, $nt->getDBkey());
     $this->mUploadSaveName = $nt->getDBkey();
     /**
      * If the image is protected, non-sysop users won't be able
      * to modify it by uploading a new revision.
      */
     if (!$nt->userCanEdit()) {
         return $this->uploadError(wfMsg('protectedpage'));
     }
     /* Don't allow users to override the blacklist (check file extension) */
     global $wgStrictFileExtensions;
     global $wgFileExtensions, $wgFileBlacklist;
     if ($this->checkFileExtensionList($ext, $wgFileBlacklist) || $wgStrictFileExtensions && !$this->checkFileExtension($finalExt, $wgFileExtensions)) {
         return $this->uploadError(wfMsg('badfiletype', htmlspecialchars($fullExt)));
     }
     /**
      * Look at the contents of the file; if we can recognize the
      * type but it's corrupt or data of the wrong type, we should
      * probably not accept it.
      */
     if (!$this->mStashed) {
         $veri = $this->verify($this->mUploadTempName, $finalExt);
         if ($veri !== true) {
             //it's a wiki error...
             return $this->uploadError($veri->toString());
         }
     }
     /**
      * Check for non-fatal conditions
      */
     if (!$this->mIgnoreWarning) {
         $warning = '';
         if ($this->mUploadSaveName != ucfirst($filtered)) {
             $warning .= '<li>' . wfMsg('badfilename', htmlspecialchars($this->mUploadSaveName)) . '</li>';
         }
         global $wgCheckFileExtensions;
         if ($wgCheckFileExtensions) {
             if (!$this->checkFileExtension($finalExt, $wgFileExtensions)) {
                 $warning .= '<li>' . wfMsg('badfiletype', htmlspecialchars($fullExt)) . '</li>';
             }
         }
         global $wgUploadSizeWarning;
         if ($wgUploadSizeWarning && $this->mUploadSize > $wgUploadSizeWarning) {
             # TODO: Format $wgUploadSizeWarning to something that looks better than the raw byte
             # value, perhaps add GB,MB and KB suffixes?
             $warning .= '<li>' . wfMsg('largefile', $wgUploadSizeWarning, $this->mUploadSize) . '</li>';
         }
         if ($this->mUploadSize == 0) {
             $warning .= '<li>' . wfMsg('emptyfile') . '</li>';
         }
         if ($nt->getArticleID()) {
             global $wgUser;
             $sk = $wgUser->getSkin();
             $dlink = $sk->makeKnownLinkObj($nt);
             $warning .= '<li>' . wfMsg('fileexists', $dlink) . '</li>';
         }
         if ($warning != '') {
             /**
              * Stash the file in a temporary location; the user can choose
              * to let it through and we'll complete the upload then.
              */
             return $this->uploadWarning($warning);
         }
     }
     /**
      * Try actually saving the thing...
      * It will show an error form on failure.
      */
     if ($this->saveUploadedFile($this->mUploadSaveName, $this->mUploadTempName, !empty($this->mSessionKey))) {
         /**
          * Update the upload log and create the description page
          * if it's a new file.
          */
         $img = Image::newFromName($this->mUploadSaveName);
         $success = $img->recordUpload($this->mUploadOldVersion, $this->mUploadDescription, $this->mUploadCopyStatus, $this->mUploadSource);
         if ($success) {
             $this->showSuccess();
         } else {
             // Image::recordUpload() fails if the image went missing, which is
             // unlikely, hence the lack of a specialised message
             $wgOut->fileNotFoundError($this->mUploadSaveName);
         }
     }
 }
Example #23
0
 function execute($par)
 {
     global $wgUser, $wgOut, $wgScriptPath, $wgRequest, $wgLang, $wgIFI_FlickrAPIKey, $wgTmpDirectory;
     global $wgIFI_ResultsPerPage, $wgIFI_FlickrSort, $wgIFI_FlickrLicense, $wgIFI_ResultsPerRow, $wgIFI_CreditsTemplate;
     global $wgIFI_GetOriginal, $wgIFI_PromptForFilename, $wgIFI_AppendRandomNumber, $wgIFI_FlickrSearchBy, $wgIFI_ThumbType;
     global $wgIFI_CheckForExistingFile, $wgIFI_ValidDomains, $wgIFI_ValidLicenses;
     global $wgIFI_UseAjax, $wgIFI_AjaxKey, $wgIFI_AjaxDomain, $wgIFI_AjaxTemplate;
     require_once "phpFlickr-2.0.0/phpFlickr.php";
     wfLoadExtensionMessages('ImportFreeImages');
     $this->setHeaders();
     $fname = "wfSpecialImportFreeImages";
     $importPage = Title::makeTitle(NS_SPECIAL, "ImportFreeImages");
     if ($wgUser->isAnon()) {
         $wgOut->errorpage('uploadnologin', 'uploadnologintext');
         return;
     }
     if (empty($wgIFI_FlickrAPIKey)) {
         // error - need to set $wgIFI_FlickrAPIKey to use this extension
         $wgOut->errorpage('error', 'importfreeimages_noapikey');
         return;
     }
     $q = '';
     if (isset($_GET['q']) && !$wgRequest->wasPosted()) {
         $q = $_GET['q'];
     }
     $import = '';
     if ($wgRequest->wasPosted() && isset($_POST['url'])) {
         $import = $_POST['url'];
         $parts = parse_url($import);
         preg_match("/[^.]+\\.[^.]+\$/", $parts['host'], $domain_only);
         $domain = $domain_only[0];
         if (!isset($wgIFI_ValidDomains[$domain])) {
             $wgOut->addHTML(wfMsg('importfreeimages_invalidurl', $import));
             return;
         }
         if ($wgIFI_CheckForExistingFile && $wgRequest->getVal('override', null) == null) {
             $title = urldecode($wgRequest->getVal('ititle'));
             $id = $wgRequest->getVal('id');
             $x = Title::newFromText($title);
             if ($x) {
                 $dbr = wfGetDB(DB_SLAVE);
                 $res = $dbr->select("image", array("img_name", "img_description"), array("img_name like '" . $dbr->strencode($x->getDBKey()) . "%'"));
                 $found = false;
                 $wt = "";
                 while ($row = $dbr->fetchObject($res)) {
                     if (strpos($row->img_description, $id) !== false) {
                         $img = Image::newFromName($row->img_name);
                         $t = Title::makeTitle(NS_IMAGE, $row->img_name);
                         $wt .= "<tr><td>[[Image:{$img->getName()}|thumb|center|{$t->getText()}]]</td>\n\t\t\t\t\t\t\t<td valign='top'>" . wfMsg('image_instructions', $t->getFullText()) . "</td></tr>";
                         $found = true;
                     }
                 }
                 $dbr->freeResult($res);
             }
             if ($found) {
                 $wgOut->addHTML(wfMsg('importfreeimages_similarphotosfound') . "<table>");
                 $wgOut->addWikiText($wt);
                 $wgOut->addHTML("</table><br clear='all'/><form method='POST'>");
                 $vals = $wgRequest->getValues();
                 foreach ($vals as $key => $value) {
                     $wgOut->addHTML("<input type='hidden' name='{$key}' value='" . htmlspecialchars($value) . "'/>");
                 }
                 $wgOut->addHTML("<input type='hidden' name='override' value='true'/>");
                 $wgOut->addHTML("<input type='button' onclick='window.location=\"{$importPage->getFullURL()}\";' class='guided-button' value='" . wfMsg('importfreeimages_dontimportduplicate') . "'/>&nbsp;&nbsp;&nbsp; <input class='guided-button' type='submit' value='" . wfMsg('importfreeimages_importduplicate') . "'/></form>");
                 return;
             }
         }
         if ($wgIFI_GetOriginal && ($domain = "flickr.com")) {
             // get URL of original :1
             $sizes = $f->photos_getSizes($_POST['id']);
             $original = '';
             foreach ($sizes as $size) {
                 if ($size['label'] == 'Original') {
                     $original = $size['source'];
                     $import = $size['source'];
                 } else {
                     if ($size['label'] == 'Large') {
                         $large = $size['source'];
                     }
                 }
             }
             //somtimes Large is returned but no Original!
             if ($original == '' && $large != '') {
                 $import = $large;
             }
         }
         // store the contents of the file
         $pageContents = file_get_contents($import);
         $name = $wgTmpDirectory . "/flickr-" . rand(0, 999999);
         $r = fopen($name, "w");
         $size = fwrite($r, $pageContents);
         fclose($r);
         chmod($name, 0777);
         if ($domain == $wgIFI_AjaxDomain) {
             $caption = "{{{$wgIFI_AjaxTemplate}|{$import}}}";
             $id = $wgRequest->getVal('id');
             if ($domain == "wikimedia.org") {
                 //maybe we can grab the licnese
                 $yy = str_replace("http://upload.wikimedia.org/", "", $import);
                 $parts = split("/", $yy);
                 $img_title = "";
                 if (sizeof($parts) == 7) {
                     $img_title = $parts[5];
                 } else {
                     if (sizeof($parts) == 5) {
                         $img_title = $parts[4];
                     }
                 }
                 if ($img_title != "") {
                     $url = "http://commons.wikimedia.org/wiki/Image:{$img_title}";
                     $license = "unknown";
                     $contents = file_get_contents("http://commons.wikimedia.org/w/index.php?title=Image:{$img_title}&action=raw");
                     foreach ($wgIFI_ValidLicenses as $lic) {
                         if (strpos($contents, "{{$lic}") !== false || strpos($contents, "{{self|{$lic}") !== false || strpos($contents, "{{self2|{$lic}") !== false) {
                             $license = $lic;
                             break;
                         }
                     }
                     $caption = "{{{$wgIFI_AjaxTemplate}|{$import}|{$url}|{$license}}}";
                 }
             }
         } else {
             if (!empty($wgIFI_CreditsTemplate)) {
                 $f = new phpFlickr($wgIFI_FlickrAPIKey);
                 $info = $f->photos_getInfo($_POST['id']);
                 $caption = "{{" . $wgIFI_CreditsTemplate . $info['license'] . "|{$_POST['id']}|" . urldecode($_POST['owner']) . "|" . urldecode($_POST['name']) . "}}";
             } else {
                 $caption = wfMsg('importfreeimages_filefromflickr', $_POST['t'], "http://www.flickr.com/people/" . urlencode($_POST['owner']) . " " . $_POST['name']) . " <nowiki>{$import}</nowiki>. {{CC by 2.0}} ";
             }
         }
         $caption = trim($caption);
         $t = $_POST['ititle'];
         // handle duplicate filenames
         $i = strrpos($import, "/");
         if ($i !== false) {
             $import = substr($import, $i + 1);
         }
         // pretty dumb way to make sure we're not overwriting previously uploaded images
         $c = 0;
         $nt =& Title::makeTitle(NS_IMAGE, $import);
         $fname = $import;
         while ($nt->getArticleID() && $c < 20) {
             $fname = $c . "_" . $import;
             $nt =& Title::makeTitle(NS_IMAGE, $fname);
             $c++;
         }
         $import = $fname;
         /*
         			$arr = array ( "size" => $size, "tempname" => $name, 
         					"caption" => $caption,
         					"url" => $import, "title" => $_POST['t'] );
         */
         $filename = trim(urldecode($wgRequest->getVal('ititle', null)));
         if ($filename == "undefined") {
             $filename = wfTimestampNow();
         }
         $filename .= "_";
         if ($wgIFI_AppendRandomNumber) {
             $filename .= rand(0, 100000);
         }
         $parts = parse_url($wgRequest->getVal('url'));
         $ux = $wgRequest->getVal('url');
         $ext = strtolower(substr($ux, strrpos($ux, ".")));
         switch ($ext) {
             case ".png":
             case ".jpeg":
             case ".jpg":
             case ".gif":
                 $filename .= $ext;
                 break;
             default:
                 $filename .= ".jpg";
         }
         $filename = str_replace("?", "", $filename);
         $filename = str_replace(":", "", $filename);
         $filename = preg_replace('/ [ ]*/', ' ', $filename);
         if (!class_exists("UploadForm")) {
             require_once 'includes/SpecialUpload.php';
         }
         $u = new UploadForm($wgRequest);
         //MW 1.12+
         $u->mTempPath = $name;
         $u->mFileSize = $size;
         $u->mComment = $caption;
         $u->mSrcName = $filename;
         $u->mUploadTempName = $name;
         $u->mUploadSize = $size;
         $u->mUploadDescription = $caption;
         $u->mRemoveTempFile = true;
         $u->mIgnoreWarning = true;
         $u->mOname = $filename;
         $t = Title::newFromText($filename, NS_IMAGE);
         if (!$t) {
             $wgOut->addHTML("Error - could not create title from filename \"{$filename}\"");
             return;
         }
         if ($t->getArticleID() > 0) {
             $sk = $wgUser->getSkin();
             $dlink = $sk->makeKnownLinkObj($t);
             $warning .= '<li>' . wfMsgHtml('fileexists', $dlink) . '</li>';
             // use our own upload warning as we dont have a 'reupload' feature
             $this->uploadWarning($u);
             return;
         } else {
             $u->execute();
         }
     }
     $wgOut->addHTML(wfMsg('importfreeimages_description') . "<br/><br/>\n\t\t\t<form method=GET action='" . $importPage->getFullURL() . "'>" . wfMsg('search') . ": <input type=text name=q value='" . htmlspecialchars($q) . "'><input type=submit value=" . wfMsg('search') . ">\n\t\t\t</form>");
     if ($q != '') {
         $page = $_GET['p'];
         if ($page == '') {
             $page = 1;
         }
         $f = new phpFlickr($wgIFI_FlickrAPIKey);
         $q = $_GET['q'];
         // TODO: get the right licenses
         $photos = $f->photos_search(array("{$wgIFI_FlickrSearchBy}" => "{$q}", "tag_mode" => "any", "page" => $page, "per_page" => $wgIFI_ResultsPerPage, "license" => $wgIFI_FlickrLicense, "sort" => $wgIFI_FlickrSort));
         $i = 0;
         if ($photos == null || !is_array($photos) || sizeof($photos) == 0 || !isset($photos['photo'])) {
             $wgOut->addHTML(wfMsg("importfreeimages_nophotosfound", $q));
             return;
         }
         $sk = $wgUser->getSkin();
         $wgOut->addHTML("\n\t\t\t\t<style type='text/css' media='all'>/*<![CDATA[*/ @import '/extensions/ImportFreeImages/ifi.css'; /*]]>*/</style>\n\t\t\t\t<div id='photo_results'> " . wfMsg('importfreeimages_results', 'Flickr') . "\n\t\t\t\t<center>\n\t\t\t\t<table cellpadding='4' class='ifi_table'>\n\t\t\t\t<form method='POST' name='uploadphotoform' action='" . $importPage->getFullURL() . "'>\n\t\t\t\t\t<input type='hidden' name='url' value=''/>\n\t\t\t\t\t<input type='hidden' name='id' value=''/>\n\t\t\t\t\t<input type='hidden' name='action' value='submit'/>\n\t\t\t\t\t<input type='hidden' name='owner' value=''/>\n\t\t\t\t\t<input type='hidden' name='name' value=''/>\n\t\t\t\t\t<input type='hidden' name='ititle' value=''/>\n\t\t\t\t</form>\t\n\t\t<script type=\"text/javascript\">\n\t\n\t\t\tfunction s2 (url, id, owner, name, ititle) {\n\t\t\t\tresults = document.getElementById('photo_results');\n\t\t\t\tdocument.uploadphotoform.url.value = url;\n\t\t\t\tdocument.uploadphotoform.id.value = id;\n\t\t\t\tdocument.uploadphotoform.owner.value = owner;\n\t\t\t\tdocument.uploadphotoform.name.value = name;\n\t\t\t\tdocument.uploadphotoform.ititle.value = ititle;\n\t\t\t\tif (" . ($wgIFI_PromptForFilename ? "true" : "false") . ") {\n\t\t\t\t\tititle = ititle.replace(/\\+/g, ' ');\n\t\t\t\t\tdocument.uploadphotoform.ititle.value = prompt('" . wfMsg('importfreeimages_promptuserforfilename') . "', unescape(ititle));\n\t\t\t\t\tif (document.uploadphotoform.ititle.value == '') {\n\t\t\t\t\t\tdocument.uploadphotoform.ititle.value = ititle;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdocument.uploadphotoform.submit();\n\t\t\t\tresults.innerHTML = '" . wfMsg('importfreeimages_uploadingphoto') . "';\n\t\t\t}\n\t\n\t\t</script>\n\t\t\t\t");
         $count = 0;
         foreach ($photos['photo'] as $photo) {
             $count++;
             if ($i % $wgIFI_ResultsPerRow == 0) {
                 $wgOut->addHTML("<tr>");
             }
             $owner = $f->people_getInfo($photo['owner']);
             $wgOut->addHTML("<td><a href='http://www.flickr.com/photos/" . $photo['owner'] . "/" . $photo['id'] . "/'>");
             $wgOut->addHTML($photo['title']);
             $wgOut->addHTML("</a><br/>" . wfMsg('importfreeimages_owner') . ": ");
             $wgOut->addHTML("<a href='http://www.flickr.com/people/" . $photo['owner'] . "/'>");
             $wgOut->addHTML($owner['username']);
             $wgOut->addHTML("</a><br/>");
             //$wgOut->addHTML( "<img  src=http://static.flickr.com/" . $photo['server'] . "/" . $photo['id'] . "_" . $photo['secret'] . "." . "jpg>" );
             $url = "http://farm{$photo['farm']}.static.flickr.com/{$photo['server']}/{$photo['id']}_{$photo['secret']}.jpg";
             $wgOut->addHTML("<img src=\"http://farm{$photo['farm']}.static.flickr.com/{$photo['server']}/{$photo['id']}_{$photo['secret']}_{$wgIFI_ThumbType}.jpg\">");
             $wgOut->addHTML("<br/>(<a href='#' onclick=\"s2('{$url}', '{$photo['id']}','{$photo['owner']}', '" . urlencode($owner['username']) . "', '" . urlencode($photo['title']) . "');\">" . wfMsg('importfreeimages_importthis') . "</a>)\n");
             $wgOut->addHTML("</td>");
             if ($i % $wgIFI_ResultsPerRow == $wgIFI_ResultsPerRow - 1) {
                 $wgOut->addHTML("</tr>");
             }
             $i++;
         }
         if ($count == 0) {
             $wgOut->addHTML(wfMsg('importfreeimages_noresults'));
         }
         $wgOut->addHTML("</table></center>");
         if ($wgIFI_UseAjax) {
             $s = htmlspecialchars($wgRequest->getVal('q'));
             $gPage = ($page - 1) * 2;
             $importjs = HtmlSnips::makeUrlTags('js', array('importfreeimages.js'), '/extensions/ImportFreeImages/', false);
             $wgOut->addHTML("<br/><br/>" . wfMsg('importfreeimages_results', $wgIFI_AjaxDomain) . "\n\t\t\t\t\t<script type='text/javascript'>\t\t\t\n\t\t\t\t\t\tvar gAjaxDomain = '{$wgIFI_AjaxDomain}';\n\t\t\t\t\t\tvar gInitialSearch = '{$s}';\n\t\t\t\t\t\tvar gPage = {$gPage};\n\t\t\t\t\t\tvar gImportMsg = '" . wfMsg('importfreeimages_importthis') . "';\n\t\t\t\t\t\tvar gImportMsgManual = '" . wfMsg('importfreeimages_importmanual') . "';\n\t\t\t\t\t\tvar gManualURL= '" . Title::makeTitle(NS_PROJECT, 'Manual Import')->getFullURL() . "';\n\t\t\t\t\t\tvar gMoreInfo='" . wfMsg('importfreeimages_moreinfo') . "';\n\t\t\t\t\t</script>\n\t\t\t\t   <script src='http://www.google.com/jsapi?key={$wgIFI_AjaxKey}' type='text/javascript'></script>\n\t\t\t\t\t{$importjs}\n\t\t\t\t \t<div id='searchform' style='width:200px; display:none;'>Loading...</div>\n\t    \t\t\t<div id='ajax_results'></div>\n\t\t\t\t");
         }
         $page = $page + 1;
         $wgOut->addHTML("</form>");
         $wgOut->addHTML("<br/>" . $sk->makeLinkObj($importPage, wfMsg('importfreeimages_next', $wgIFI_ResultsPerPage), "p={$page}&q=" . urlencode($q)));
         $wgOut->addHTML("</div>");
     }
 }
Example #24
0
    $thumbName = 'page' . $page . '-' . $thumbName;
}
if ($pre_render) {
    $thumbName .= '.png';
}
$thumbPath = wfImageThumbDir($fileName) . '/' . $thumbName;
if (is_file($thumbPath) && filemtime($thumbPath) >= filemtime($imagePath)) {
    wfStreamFile($thumbPath);
    // Can't log profiling data with no Setup.php
    exit;
}
// OK, no valid thumbnail, time to get out the heavy machinery
wfProfileOut('thumb.php-start');
require_once 'Setup.php';
wfProfileIn('thumb.php-render');
$img = Image::newFromName($fileName);
try {
    if ($img) {
        if (!is_null($page)) {
            $img->selectPage($page);
        }
        $thumb = $img->renderThumb($width, false);
    } else {
        $thumb = false;
    }
} catch (Exception $ex) {
    // Tried to select a page on a non-paged file?
    $thumb = false;
}
if ($thumb && $thumb->path) {
    wfStreamFile($thumb->path);
Example #25
0
 function getImageURLPF(&$parser, $name = '', $arg = 'abs')
 {
     $img = Image::newFromName($name);
     if ($img !== NULL) {
         return (trim($arg === 'abs') ? $GLOBALS['wgServer'] : '') . $img->getURL();
     }
     return '';
 }