Пример #1
0
 function testFitBoxWidth()
 {
     $vals = array(array('width' => 50, 'height' => 50, 'tests' => array(50 => 50, 17 => 17, 18 => 18)), array('width' => 366, 'height' => 300, 'tests' => array(50 => 61, 17 => 21, 18 => 22)), array('width' => 300, 'height' => 366, 'tests' => array(50 => 41, 17 => 14, 18 => 15)), array('width' => 100, 'height' => 400, 'tests' => array(50 => 12, 17 => 4, 18 => 4)));
     foreach ($vals as $row) {
         extract($row);
         foreach ($tests as $max => $expected) {
             $y = round($expected * $height / $width);
             $result = wfFitBoxWidth($width, $height, $max);
             $y2 = round($result * $height / $width);
             $this->assertEquals($expected, $result, "({$width}, {$height}, {$max}) wanted: {$expected}x{$y}, got: {$result}x{$y2}");
         }
     }
 }
Пример #2
0
 protected function formatImage($image, $inCitation = false)
 {
     $filename = (string) $image['filename'];
     if (!$filename) {
         return '';
     }
     $caption = (string) $image['caption'];
     $iconWidth = SearchForm::THUMB_WIDTH;
     $iconHeight = 48;
     $t = Title::makeTitle(NS_IMAGE, $filename);
     if (!$t || !$t->exists()) {
         return '';
     }
     $image = new Image($t);
     $maxHoverWidth = 700;
     $maxHoverHeight = 300;
     $width = $image->getWidth();
     $height = $image->getHeight();
     if ($height > 0 && $maxHoverWidth > $width * $maxHoverHeight / $height) {
         $maxHoverWidth = wfFitBoxWidth($width, $height, $maxHoverHeight);
     }
     $imageURL = $image->createThumb($maxHoverWidth, $maxHoverHeight);
     $titleAttr = StructuredData::escapeXml("{$imageURL}|{$maxHoverWidth}");
     if ($inCitation) {
         return "<span class=\"wr-citation-image wr-imagehover inline-block\" title=\"{$titleAttr}\">{$caption} [[Image:{$filename}|{$iconWidth}x{$iconHeight}px]]</span>";
     } else {
         return "<span class=\"wr-imagehover inline-block\"  title=\"{$titleAttr}\">[[Image:{$filename}|thumb|left|{$caption}]]</span>";
     }
     //      return <<<END
     //<div class="inline-block">
     //   <span id="$id">[[Image:$filename|thumb|left|$id. $caption]]</span>
     //</div>
     //END;
 }
Пример #3
0
 /**
  * @param $image File
  * @param  $params
  * @return bool
  */
 function normaliseParams($image, &$params)
 {
     $mimeType = $image->getMimeType();
     if (!isset($params['width'])) {
         return false;
     }
     if (!isset($params['page'])) {
         $params['page'] = 1;
     } else {
         if ($params['page'] > $image->pageCount()) {
             $params['page'] = $image->pageCount();
         }
         if ($params['page'] < 1) {
             $params['page'] = 1;
         }
     }
     $srcWidth = $image->getWidth($params['page']);
     $srcHeight = $image->getHeight($params['page']);
     if (isset($params['height']) && $params['height'] != -1) {
         # Height & width were both set
         if ($params['width'] * $srcHeight > $params['height'] * $srcWidth) {
             # Height is the relative smaller dimension, so scale width accordingly
             $params['width'] = wfFitBoxWidth($srcWidth, $srcHeight, $params['height']);
             if ($params['width'] == 0) {
                 # Very small image, so we need to rely on client side scaling :(
                 $params['width'] = 1;
             }
             $params['physicalWidth'] = $params['width'];
         } else {
             # Height was crap, unset it so that it will be calculated later
             unset($params['height']);
         }
     }
     if (!isset($params['physicalWidth'])) {
         # Passed all validations, so set the physicalWidth
         $params['physicalWidth'] = $params['width'];
     }
     # Because thumbs are only referred to by width, the height always needs
     # to be scaled by the width to keep the thumbnail sizes consistent,
     # even if it was set inside the if block above
     $params['physicalHeight'] = File::scaleHeight($srcWidth, $srcHeight, $params['physicalWidth']);
     # Set the height if it was not validated in the if block higher up
     if (!isset($params['height']) || $params['height'] == -1) {
         $params['height'] = $params['physicalHeight'];
     }
     if (!$this->validateThumbParams($params['physicalWidth'], $params['physicalHeight'], $srcWidth, $srcHeight, $mimeType)) {
         return false;
     }
     return true;
 }
Пример #4
0
    protected function getImageInfo($image, $firstChildClass = '')
    {
        $imageText = '';
        $thumbWidth = SearchForm::THUMB_WIDTH;
        $filename = (string) $image['filename'];
        $t = Title::makeTitle(NS_IMAGE, $filename);
        if ($t && $t->exists()) {
            $img = new Image($t);
            $caption = (string) $image['caption'];
            if (!$caption) {
                $caption = $filename;
            }
            $maxWidth = 700;
            $maxHeight = 300;
            $width = $img->getWidth();
            $height = $img->getHeight();
            if ($maxWidth > $width * $maxHeight / $height) {
                $maxWidth = wfFitBoxWidth($width, $height, $maxHeight);
            }
            $imageURL = $img->createThumb($maxWidth, $maxHeight);
            $caption = str_replace('|', ' ', $caption);
            $titleAttr = StructuredData::escapeXml("{$imageURL}|{$maxWidth}|{$caption}");
            $imageText = <<<END
<td style="width: 1%" class="{$firstChildClass}">
   <div class="wr-infobox-image wr-imagehover" title="{$titleAttr}">[[Image:{$filename}|{$thumbWidth}x{$thumbWidth}px]]</div>
</td>
END;
        }
        return $imageText;
    }
Пример #5
0
 /**
  * As createThumb, but returns a ThumbnailImage object. This can
  * provide access to the actual file, the real size of the thumb,
  * and can produce a convenient <img> tag for you.
  *
  * For non-image formats, this may return a filetype-specific icon.
  *
  * @param integer $width	maximum width of the generated thumbnail
  * @param integer $height	maximum height of the image (optional)
  * @param boolean $render	True to render the thumbnail if it doesn't exist,
  *                       	false to just return the URL
  *
  * @return ThumbnailImage or null on failure
  * @public
  */
 function getThumbnail($width, $height = -1, $render = true, $makeMapIcon = false)
 {
     // WERELATE: makeMapIcon
     wfProfileIn(__METHOD__);
     if ($this->canRender()) {
         if ($height > 0) {
             $this->load();
             if ($width > $this->width * $height / $this->height) {
                 $width = wfFitBoxWidth($this->width, $this->height, $height);
             }
         }
         if ($render) {
             // WERELATE: makeMapIcon
             $thumb = $this->renderThumb($width, true, $makeMapIcon);
         } else {
             // Don't render, just return the URL
             if ($this->validateThumbParams($width, $height)) {
                 if (!$this->mustRender() && $width == $this->width && $height == $this->height) {
                     $url = $this->getURL();
                 } else {
                     // WERELATE: makeMapIcon
                     list($isScriptUrl, $url) = $this->thumbUrl($width, 'thumb', $makeMapIcon);
                 }
                 $thumb = new ThumbnailImage($url, $width, $height);
             } else {
                 $thumb = null;
             }
         }
     } else {
         // not a bitmap or renderable image, don't try.
         $thumb = $this->iconThumb();
     }
     wfProfileOut(__METHOD__);
     return $thumb;
 }
Пример #6
0
 function normaliseParams($image, &$params)
 {
     $mimeType = $image->getMimeType();
     if (!isset($params['width'])) {
         return false;
     }
     if (!isset($params['page'])) {
         $params['page'] = 1;
     }
     $srcWidth = $image->getWidth($params['page']);
     $srcHeight = $image->getHeight($params['page']);
     if (isset($params['height']) && $params['height'] != -1) {
         if ($params['width'] * $srcHeight > $params['height'] * $srcWidth) {
             $params['width'] = wfFitBoxWidth($srcWidth, $srcHeight, $params['height']);
         }
     }
     $params['height'] = File::scaleHeight($srcWidth, $srcHeight, $params['width']);
     if (!$this->validateThumbParams($params['width'], $params['height'], $srcWidth, $srcHeight, $mimeType)) {
         return false;
     }
     return true;
 }
Пример #7
0
    /**
     * Create wiki text from xml property
     */
    protected function toWikiText($parser)
    {
        //        wfDebug("toWikiText=" . $this->xml->asXML() . "\n");
        global $wgESINHandler, $wgOut;
        $result = '';
        if (isset($this->xml)) {
            // check rename needed
            if (!$this->isGedcomPage && mb_strpos($this->titleString, 'Unknown') !== false) {
                $correctTitle = StructuredData::constructName(@$this->xml->name['given'], @$this->xml->name['surname']);
                if (Person::isRenameNeeded($this->titleString, $correctTitle)) {
                    $t = Title::makeTitle(NS_SPECIAL, 'Movepage');
                    $url = $t->getLocalURL('target=' . $this->title->getPrefixedURL() . '&wpNewTitle=' . wfUrlencode("Person:{$correctTitle}") . '&wpReason=' . wfUrlencode('make page title agree with name'));
                    $parser->mOutput->mSubtitle = 'This page can be <a href="' . $url . '">renamed</a>';
                    $wgOut->setSubtitle($parser->mOutput->mSubtitle);
                }
            }
            // add infoboxes
            $gender = (string) $this->xml->gender;
            switch ($gender) {
                case 'M':
                    $genderClass = '-male';
                    break;
                case 'F':
                    $genderClass = '-female';
                    break;
                default:
                    $genderClass = '';
            }
            $image = $wgESINHandler->getPrimaryImage($this->xml);
            $imageText = "<div class=\"wr-infobox-noimage{$genderClass}\"></div>";
            $imageURL = '';
            if (isset($image)) {
                $thumbWidth = SearchForm::THUMB_WIDTH;
                $filename = (string) $image['filename'];
                $t = Title::makeTitle(NS_IMAGE, $filename);
                if ($t && $t->exists()) {
                    $img = new Image($t);
                    $caption = (string) $image['caption'];
                    if (!$caption) {
                        $caption = $filename;
                    }
                    $maxWidth = 700;
                    $maxHeight = 300;
                    $width = $img->getWidth();
                    $height = $img->getHeight();
                    if ($maxWidth > $width * $maxHeight / $height) {
                        $maxWidth = wfFitBoxWidth($width, $height, $maxHeight);
                    }
                    $imageURL = $img->createThumb($maxWidth, $maxHeight);
                    $caption = str_replace('|', ' ', $caption);
                    $titleAttr = StructuredData::escapeXml("{$imageURL}|{$maxWidth}|{$caption}");
                    $imageText = "<span class=\"wr-imagehover\" title=\"{$titleAttr}\">[[Image:{$filename}|{$thumbWidth}x{$thumbWidth}px]]</span>";
                }
            }
            $fullname = StructuredData::getFullname($this->xml->name);
            if (!$fullname) {
                $fullname = '&nbsp;';
            }
            $birthDate = $birthPlace = $deathDate = $deathPlace = '';
            $chrDate = $chrPlace = $burDate = $burPlace = '';
            $birthFound = $deathFound = $chrFound = $burFound = false;
            $birthSource = $deathSource = false;
            if (isset($this->xml->event_fact)) {
                foreach ($this->xml->event_fact as $eventFact) {
                    if ($eventFact['type'] == 'Birth') {
                        $birthFound = true;
                        $birthDate = (string) $eventFact['date'];
                        $birthPlace = (string) $eventFact['place'];
                        $birthSource = (string) $eventFact['sources'];
                    } else {
                        if ($eventFact['type'] == 'Christening' || $eventFact['type'] == 'Baptism') {
                            $chrFound = true;
                            $chrDate = (string) $eventFact['date'];
                            $chrPlace = (string) $eventFact['place'];
                        } else {
                            if ($eventFact['type'] == 'Death') {
                                $deathFound = true;
                                $deathDate = (string) $eventFact['date'];
                                $deathPlace = (string) $eventFact['place'];
                                $deathSource = (string) $eventFact['sources'];
                            } else {
                                if ($eventFact['type'] == 'Burial') {
                                    $burFound = true;
                                    $burDate = (string) $eventFact['date'];
                                    $burPlace = (string) $eventFact['place'];
                                }
                            }
                        }
                    }
                }
            }
            $this->initHistoricalDataPerson($fullname, $gender, $imageURL);
            $birthLabel = '&nbsp;';
            if ($birthFound) {
                $birthLabel = 'b.';
                $this->addHistoricalDataEvent('birth', $birthDate, $birthPlace);
            } else {
                if ($chrFound) {
                    $birthLabel = 'chr.';
                    $this->addHistoricalDataEvent('christening', $chrDate, $chrPlace);
                    $birthDate = $chrDate;
                    $birthPlace = $chrPlace;
                }
            }
            $deathLabel = '&nbsp;';
            if ($deathFound) {
                $deathLabel = 'd.';
                $this->addHistoricalDataEvent('death', $deathDate, $deathPlace);
            } else {
                if ($burFound) {
                    $deathLabel = 'bur.';
                    $this->addHistoricalDataEvent('burial', $burDate, $burPlace);
                    $deathDate = $burDate;
                    $deathPlace = $burPlace;
                }
            }
            $fmtBirthPlace = Person::formatPlace($birthPlace);
            $fmtDeathPlace = Person::formatPlace($deathPlace);
            $familybadges = '';
            $marriageEvents = array();
            $parentFamilies = array();
            foreach ($this->xml->child_of_family as $f) {
                $parentFamilies[] = (string) $f['title'];
            }
            $found = false;
            foreach ($this->xml->child_of_family as $f) {
                list($key, $text) = $this->getFamilyBadge($f, true, $gender, $parentFamilies, $marriageEvents);
                $found = true;
                $familybadges .= $text;
            }
            if (!$found) {
                $familybadges .= $this->getAddFamilyLink(0);
            }
            $sort = array();
            $ix = 0;
            $prevKey = 0;
            $found = false;
            foreach ($this->xml->spouse_of_family as $f) {
                list($key, $text) = $this->getFamilyBadge($f, false, $gender, null, $marriageEvents);
                $found = true;
                if ($key) {
                    $prevKey = $key;
                } else {
                    $key = $prevKey;
                }
                $sort[$key * 50 + $ix] = $text;
                $ix++;
            }
            $result = <<<END
<div class="wr-infobox wr-infobox-person clearfix">
   <div class="wr-infobox-image">
      {$imageText}
   </div>
   <div class="wr-infobox-content">
      <div class="wr-infobox-fullname">{$fullname}</div>
      <div class="wr-infobox-event">{$birthLabel}<span class="wr-infobox-date">{$birthDate}</span> <span class="wr-infobox-place">{$fmtBirthPlace}</span></div>
      <div class="wr-infobox-event">{$deathLabel}<span class="wr-infobox-date">{$deathDate}</span> <span class="wr-infobox-place">{$fmtDeathPlace}</span></div>

   </div>
</div>
<wr_ad></wr_ad>
<div style="margin-top:2px" class="clearfix"><div id="wr_familytreelink" style="float:left">
<span class="wr-familytreelink-text">Family tree</span><span class="wr-familytreelink-arrow">▼</span>
</div><div style="float:right; margin-right:10px;">
</div></div>
END;
            ksort($sort, SORT_NUMERIC);
            foreach ($sort as $key => $text) {
                $familybadges .= $text;
            }
            $familybadges .= $this->getAddFamilyLink(!$found ? 1 : 2, (string) @$this->xml->name['given'], (string) @$this->xml->name['surname']);
            if ($familybadges) {
                $result .= "<div class=\"wr-infobox-familybadges\">{$familybadges}</div>";
            }
            //         $result .= '<div class="visualClearLeft"></div>';
            // add source citations, images, notes
            $result .= $wgESINHandler->addSourcesImagesNotes($this, $parser, $marriageEvents);
            // add categories
            $surnames = array();
            $surnames[] = (string) $this->xml->name['surname'];
            foreach ($this->xml->alt_name as $altName) {
                $surnames[] = (string) $altName['surname'];
            }
            $places = ESINHandler::getPlaces($this->xml);
            $result .= StructuredData::addCategories($surnames, $places, false);
        }
        return $result;
    }