/**
  * @param ResultWrapper $res
  * @param DatabaseBase $dbw
  * @return null|int
  */
 function convertOptionBatch($res, $dbw)
 {
     $id = null;
     foreach ($res as $row) {
         $this->mConversionCount++;
         $insertRows = array();
         foreach (explode("\n", $row->user_options) as $s) {
             $m = array();
             if (!preg_match("/^(.[^=]*)=(.*)\$/", $s, $m)) {
                 continue;
             }
             // MW < 1.16 would save even default values. Filter them out
             // here (as in User) to avoid adding many unnecessary rows.
             $defaultOption = User::getDefaultOption($m[1]);
             if (is_null($defaultOption) || $m[2] != $defaultOption) {
                 $insertRows[] = array('up_user' => $row->user_id, 'up_property' => $m[1], 'up_value' => $m[2]);
             }
         }
         if (count($insertRows)) {
             $dbw->insert('user_properties', $insertRows, __METHOD__, array('IGNORE'));
         }
         $dbw->update('user', array('user_options' => ''), array('user_id' => $row->user_id), __METHOD__);
         $id = $row->user_id;
     }
     return $id;
 }
Example #2
0
 /**
  * Returns the default gender option in this wiki.
  * @return String
  */
 protected function getDefault()
 {
     if ($this->default === null) {
         $this->default = User::getDefaultOption('gender');
     }
     return $this->default;
 }
	/**
	 * Run a thumbnail job on a given PDF file.
	 * @return bool true
	 */
	public function run() {
		if ( !isset( $this->params['page'] ) ) {
			wfDebugLog('thumbnails', 'A page for thumbnails job of ' . $this->title->getText() . ' was not specified! That should never happen!');
			return true; // no page set? that should never happen
		}

		$file = wfLocalFile( $this->title ); // we just want a local file
		if ( !$file ) {
			return true; // Just silently fail, perhaps the file was already deleted, don't bother
		}

		switch ($this->params['jobtype']) {
			case self::BIG_THUMB:
				global $wgImageLimits;
				// Ignore user preferences, do default thumbnails
				// everything here shamelessy copied and reused from includes/ImagePage.php
				$sizeSel = User::getDefaultOption( 'imagesize' );

				// The user offset might still be incorrect, specially if
				// $wgImageLimits got changed (see bug #8858).
				if ( !isset( $wgImageLimits[$sizeSel] ) ) {
					// Default to the first offset in $wgImageLimits
					$sizeSel = 0;
				}
				$max = $wgImageLimits[$sizeSel];
				$maxWidth = $max[0];
				$maxHeight = $max[1];
				
				$width_orig = $file->getWidth( $this->params['page'] );
				$width = $width_orig;
				$height_orig = $file->getHeight( $this->params['page'] );
				$height = $height_orig;
				if ( $width > $maxWidth || $height > $maxHeight ) {
					# Calculate the thumbnail size.
					# First case, the limiting factor is the width, not the height.
					if ( $width / $height >= $maxWidth / $maxHeight ) {
						$height = round( $height * $maxWidth / $width );
						$width = $maxWidth;
						# Note that $height <= $maxHeight now.
					} else {
						$newwidth = floor( $width * $maxHeight / $height );
						$height = round( $height * $newwidth / $width );
						$width = $newwidth;
						# Note that $height <= $maxHeight now, but might not be identical
						# because of rounding.
					}
					$transformParams = array( 'page' => $this->params['page'], 'width' => $width );
					$file->transform( $transformParams );
				}
				break;

			case self::SMALL_THUMB:
				global $wgUser;
				$sk = $wgUser->getSkin();
				$sk->makeThumbLinkObj( $this->title, $file, '', '', 'none', array( 'page' => $this->params['page'] ) );
				break;
		}

		return true;
	}
Example #4
0
 private function getShowImageParameters()
 {
     global $wgUser, $wgImageLimits, $wgUseImageResize, $wgGenerateThumbnailOnParse;
     $url = '';
     $width = 0;
     $height = 0;
     if ($wgUser->getOption('imagesize') == '') {
         $sizeSel = User::getDefaultOption('imagesize');
     } else {
         $sizeSel = intval($wgUser->getOption('imagesize'));
     }
     if (!isset($wgImageLimits[$sizeSel])) {
         $sizeSel = User::getDefaultOption('imagesize');
     }
     $max = $wgImageLimits[$sizeSel];
     $maxWidth = $max[0];
     $maxHeight = $max[1];
     if ($this->img->exists()) {
         # image
         $width = $this->img->getWidth();
         $height = $this->img->getHeight();
         if ($this->img->allowInlineDisplay() and $width and $height) {
             # image
             # We'll show a thumbnail of this image
             if ($width > $maxWidth || $height > $maxHeight) {
                 # Calculate the thumbnail size.
                 # First case, the limiting factor is the width, not the height.
                 if ($width / $height >= $maxWidth / $maxHeight) {
                     $height = round($height * $maxWidth / $width);
                     $width = $maxWidth;
                     # Note that $height <= $maxHeight now.
                 } else {
                     $newwidth = floor($width * $maxHeight / $height);
                     $height = round($height * $newwidth / $width);
                     $width = $newwidth;
                     # Note that $height <= $maxHeight now, but might not be identical
                     # because of rounding.
                 }
                 if ($wgUseImageResize) {
                     $thumbnail = $this->img->getThumbnail($width, -1, $wgGenerateThumbnailOnParse);
                     if ($thumbnail == null) {
                         $url = $this->img->getViewURL();
                     } else {
                         $url = $thumbnail->getURL();
                     }
                 } else {
                     # No resize ability? Show the full image, but scale
                     # it down in the browser so it fits on the page.
                     $url = $this->img->getViewURL();
                 }
             } else {
                 $url = $this->img->getViewURL();
             }
         }
     }
     return array($url, $width, $height);
 }
 /**
  * Decide whether to bother showing the wikitext editor at all.
  * If not, we expect the VE initialisation JS to activate.
  * @param $article Article
  * @param $user User
  * @return bool Whether to show the wikitext editor or not.
  */
 public static function onCustomEditor(Article $article, User $user)
 {
     $req = RequestContext::getMain()->getRequest();
     $veConfig = ConfigFactory::getDefaultInstance()->makeConfig('visualeditor');
     if (!$user->getOption('visualeditor-enable') || $user->getOption('visualeditor-betatempdisable') || $user->getOption('visualeditor-autodisable') || $user->getOption('visualeditor-tabs') === 'prefer-wt' || $veConfig->get('VisualEditorDisableForAnons') && $user->isAnon() || false) {
         return true;
     }
     $title = $article->getTitle();
     $availableNamespaces = $veConfig->get('VisualEditorAvailableNamespaces');
     $params = $req->getValueNames();
     if ($user->isAnon()) {
         $editor = $req->getCookie('VEE', '', User::getDefaultOption('visualeditor-editor'));
     } else {
         $editor = $user->getOption('visualeditor-editor');
     }
     return $req->getVal('action') !== 'edit' || !$veConfig->get('VisualEditorUseSingleEditTab') || $editor === 'wikitext' || !$title->inNamespaces(array_keys(array_filter($availableNamespaces))) || $title->getContentModel() !== CONTENT_MODEL_WIKITEXT || in_array('undo', $params) || in_array('undoafter', $params) || in_array('editintro', $params) || in_array('preload', $params) || in_array('preloadtitle', $params) || in_array('preloadparams', $params);
     // Known-good parameters: edit, veaction, section, vesection, veswitched
 }
 private function fixUser($i)
 {
     global $wgDontSwitchMeOverPrefs;
     $user = User::newFromId($i);
     // If the user doesn't exist or doesn't have our preference enabled, skip
     if ($user->isAnon() || !$user->getOption('dontswitchmeover')) {
         return;
     }
     $changed = false;
     foreach ($wgDontSwitchMeOverPrefs as $pref => $oldVal) {
         if ($user->getOption($pref) == User::getDefaultOption($pref)) {
             $user->setOption($pref, $oldVal);
             $changed = true;
         }
     }
     if ($changed) {
         $user->saveSettings();
     }
 }
 static function gender($parser, $user)
 {
     $forms = array_slice(func_get_args(), 2);
     // default
     $gender = User::getDefaultOption('gender');
     // allow prefix.
     $title = Title::newFromText($user);
     if (is_object($title) && $title->getNamespace() == NS_USER) {
         $user = $title->getText();
     }
     // check parameter, or use $wgUser if in interface message
     $user = User::newFromName($user);
     if ($user) {
         $gender = $user->getOption('gender');
     } elseif ($parser->mOptions->getInterfaceMessage()) {
         global $wgUser;
         $gender = $wgUser->getOption('gender');
     }
     return $parser->getFunctionLang()->gender($gender, $forms);
 }
 /**
  * Returns geolocation button params
  */
 private function getGeolocationButtonParams($refreshCache = false)
 {
     $sMemcKey = wfMemcKey($this->app->wg->title->getText(), $this->app->wg->title->getNamespace(), 'GeolocationButtonParams');
     // use user default
     if (empty($iWidth)) {
         $wopt = $this->app->wg->user->getGlobalPreference('thumbsize');
         if (!isset($this->app->wg->thumbLimits[$wopt])) {
             $wopt = User::getDefaultOption('thumbsize');
         }
         $iWidth = $this->app->wg->thumbLimits[$wopt];
     }
     $aResult = array('align' => 'right', 'width' => $iWidth);
     $aMemcResult = $this->app->wg->memc->get($sMemcKey);
     $refreshCache = true;
     // FIXME
     if ($refreshCache || empty($aMemcResult)) {
         $oArticle = new Article($this->app->wg->title);
         $sRawText = $oArticle->getRawText();
         $aMatches = array();
         $string = $this->app->wg->contLang->getNsText(NS_IMAGE) . '|' . MWNamespace::getCanonicalName(NS_IMAGE);
         $iFound = preg_match('#\\[\\[(' . $string . '):[^\\]]*|thumb[^\\]]*\\]\\]#', $sRawText, $aMatches);
         if (!empty($iFound)) {
             reset($aMatches);
             $sMatch = current($aMatches);
             $sMatch = str_replace('[[', '', $sMatch);
             $sMatch = str_replace(']]', '', $sMatch);
             $aMatch = explode('|', $sMatch);
             foreach ($aMatch as $element) {
                 if ($element == 'left') {
                     $aResult['align'] = $element;
                 }
                 if (substr($element, -2) == 'px' && (int) substr($element, 0, -2) > 0) {
                     $aResult['width'] = (int) substr($element, 0, -2);
                 }
             }
         }
         $iExpires = 60 * 60 * 24;
         $this->app->wg->memc->set($sMemcKey, $aResult, $iExpires);
     } else {
         $aResult['align'] = $aMemcResult['align'];
         if (!empty($aMemcResult['width'])) {
             $aResult['width'] = $aMemcResult['width'];
         }
     }
     // get default image width
     return $aResult;
 }
 /**
  * gender handler
  */
 function gender($lang, $args)
 {
     $this->checkType('gender', 1, $args[0], 'string');
     $username = trim(array_shift($args));
     if (is_array($args[0])) {
         $args = $args[0];
     }
     $forms = array_values(array_map('strval', $args));
     // Shortcuts
     if (count($forms) === 0) {
         return '';
     } elseif (count($forms) === 1) {
         return $forms[0];
     }
     if ($username === 'male' || $username === 'female') {
         $gender = $username;
     } else {
         // default
         $gender = User::getDefaultOption('gender');
         // Check for "User:" prefix
         $title = Title::newFromText($username);
         if ($title && $title->getNamespace() == NS_USER) {
             $username = $title->getText();
         }
         // check parameter, or use the ParserOptions if in interface message
         $user = User::newFromName($username);
         if ($user) {
             $gender = GenderCache::singleton()->getGenderOf($user, __METHOD__);
         } elseif ($username === '') {
             $parserOptions = $this->getParserOptions();
             if ($parserOptions->getInterfaceMessage()) {
                 $gender = GenderCache::singleton()->getGenderOf($parserOptions->getUser(), __METHOD__);
             }
         }
     }
     return array($lang->gender($gender, $forms));
 }
Example #10
0
 function body_ondblclick()
 {
     global $wgUser;
     if ($this->isEditable() && $wgUser->getOption("editondblclick")) {
         $js = 'document.location = "' . $this->getEditUrl() . '";';
     } else {
         $js = '';
     }
     if (User::getDefaultOption('editondblclick')) {
         return cbt_value($js, 'user', 'title');
     } else {
         // Optimise away for logged-out users
         return cbt_value($js, 'loggedin dynamic');
     }
 }
Example #11
0
 /**
  * Given parameters derived from [[Image:Foo|options...]], generate the
  * HTML that that syntax inserts in the page.
  *
  * @param Title $title Title object
  * @param File $file File object, or false if it doesn't exist
  *
  * @param array $frameParams Associative array of parameters external to the media handler.
  *     Boolean parameters are indicated by presence or absence, the value is arbitrary and
  *     will often be false.
  *          thumbnail       If present, downscale and frame
  *          manualthumb     Image name to use as a thumbnail, instead of automatic scaling
  *          framed          Shows image in original size in a frame
  *          frameless       Downscale but don't frame
  *          upright         If present, tweak default sizes for portrait orientation
  *          upright_factor  Fudge factor for "upright" tweak (default 0.75)
  *          border          If present, show a border around the image
  *          align           Horizontal alignment (left, right, center, none)
  *          valign          Vertical alignment (baseline, sub, super, top, text-top, middle,
  *                          bottom, text-bottom)
  *          alt             Alternate text for image (i.e. alt attribute). Plain text.
  *          caption         HTML for image caption.
  *          link-url        URL to link to
  *          link-title      Title object to link to
  *          no-link         Boolean, suppress description link
  *
  * @param array $handlerParams Associative array of media handler parameters, to be passed
  *       to transform(). Typical keys are "width" and "page".
  * @param string $time, timestamp of the file, set as false for current
  * @param string $query, query params for desc url
  * @return string HTML for an image, with links, wrappers, etc.
  */
 function makeImageLink2(Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "")
 {
     $res = null;
     if (!wfRunHooks('ImageBeforeProduceHTML', array(&$this, &$title, &$file, &$frameParams, &$handlerParams, &$time, &$res))) {
         return $res;
     }
     global $wgContLang, $wgUser, $wgThumbLimits, $wgThumbUpright;
     if ($file && !$file->allowInlineDisplay()) {
         wfDebug(__METHOD__ . ': ' . $title->getPrefixedDBkey() . " does not allow inline display\n");
         return $this->link($title);
     }
     // Shortcuts
     $fp =& $frameParams;
     $hp =& $handlerParams;
     // Clean up parameters
     $page = isset($hp['page']) ? $hp['page'] : false;
     if (!isset($fp['align'])) {
         $fp['align'] = '';
     }
     if (!isset($fp['alt'])) {
         $fp['alt'] = '';
     }
     # Backward compatibility, title used to always be equal to alt text
     if (!isset($fp['title'])) {
         $fp['title'] = $fp['alt'];
     }
     $prefix = $postfix = '';
     if ('center' == $fp['align']) {
         $prefix = '<div class="center">';
         $postfix = '</div>';
         $fp['align'] = 'none';
     }
     if ($file && !isset($hp['width'])) {
         $hp['width'] = $file->getWidth($page);
         if (isset($fp['thumbnail']) || isset($fp['framed']) || isset($fp['frameless']) || !$hp['width']) {
             $wopt = $wgUser->getOption('thumbsize');
             if (!isset($wgThumbLimits[$wopt])) {
                 $wopt = User::getDefaultOption('thumbsize');
             }
             // Reduce width for upright images when parameter 'upright' is used
             if (isset($fp['upright']) && $fp['upright'] == 0) {
                 $fp['upright'] = $wgThumbUpright;
             }
             // Use width which is smaller: real image width or user preference width
             // For caching health: If width scaled down due to upright parameter, round to full __0 pixel to avoid the creation of a lot of odd thumbs
             $prefWidth = isset($fp['upright']) ? round($wgThumbLimits[$wopt] * $fp['upright'], -1) : $wgThumbLimits[$wopt];
             if ($hp['width'] <= 0 || $prefWidth < $hp['width']) {
                 $hp['width'] = $prefWidth;
             }
         }
     }
     if (isset($fp['thumbnail']) || isset($fp['manualthumb']) || isset($fp['framed'])) {
         # Create a thumbnail. Alignment depends on language
         # writing direction, # right aligned for left-to-right-
         # languages ("Western languages"), left-aligned
         # for right-to-left-languages ("Semitic languages")
         #
         # If  thumbnail width has not been provided, it is set
         # to the default user option as specified in Language*.php
         if ($fp['align'] == '') {
             $fp['align'] = $wgContLang->isRTL() ? 'left' : 'right';
         }
         return $prefix . $this->makeThumbLink2($title, $file, $fp, $hp, $time, $query) . $postfix;
     }
     if ($file && isset($fp['frameless'])) {
         $srcWidth = $file->getWidth($page);
         # For "frameless" option: do not present an image bigger than the source (for bitmap-style images)
         # This is the same behaviour as the "thumb" option does it already.
         if ($srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth) {
             $hp['width'] = $srcWidth;
         }
     }
     if ($file && $hp['width']) {
         # Create a resized image, without the additional thumbnail features
         $thumb = $file->transform($hp);
     } else {
         $thumb = false;
     }
     if (!$thumb) {
         $s = $this->makeBrokenImageLinkObj($title, '', '', '', '', $time == true);
     } else {
         $params = array('alt' => $fp['alt'], 'title' => $fp['title'], 'valign' => isset($fp['valign']) ? $fp['valign'] : false, 'img-class' => isset($fp['border']) ? 'thumbborder' : false);
         if (!empty($fp['link-url'])) {
             $params['custom-url-link'] = $fp['link-url'];
         } elseif (!empty($fp['link-title'])) {
             $params['custom-title-link'] = $fp['link-title'];
         } elseif (!empty($fp['no-link'])) {
             // No link
         } else {
             $params['desc-link'] = true;
             $params['desc-query'] = $query;
         }
         $s = $thumb->toHtml($params);
     }
     if ('' != $fp['align']) {
         $s = "<div class=\"float{$fp['align']}\">{$s}</div>";
     }
     return str_replace("\n", ' ', $prefix . $s . $postfix);
 }
    function modifiedImagePageOpenShowImage()
    {
        global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgEnableUploads;
        wfProfileIn(__METHOD__);
        $full_url = $this->getFile()->getURL();
        $anchoropen = '';
        $anchorclose = '';
        if ($wgUser->getOption('imagesize') == '') {
            $sizeSel = User::getDefaultOption('imagesize');
        } else {
            $sizeSel = intval($wgUser->getOption('imagesize'));
        }
        if (!isset($wgImageLimits[$sizeSel])) {
            $sizeSel = User::getDefaultOption('imagesize');
        }
        $max = $wgImageLimits[$sizeSel];
        $maxWidth = $max[0];
        $maxHeight = $max[1];
        $maxWidth = 600;
        $maxHeight = 460;
        $sk = $wgUser->getSkin();
        if ($this->getFile()->exists()) {
            # image
            $width = $this->getFile()->getWidth();
            $height = $this->getFile()->getHeight();
            $showLink = false;
            if ($this->getFile()->allowInlineDisplay() && $width && $height) {
                # image
                # "Download high res version" link below the image
                $msg = wfMsgHtml('show-big-image', $width, $height, intval($this->getFile()->getSize() / 1024));
                # We'll show a thumbnail of this image
                if ($width > $maxWidth || $height > $maxHeight) {
                    # Calculate the thumbnail size.
                    # First case, the limiting factor is the width, not the height.
                    if ($width / $height >= $maxWidth / $maxHeight) {
                        $height = round($height * $maxWidth / $width);
                        $width = $maxWidth;
                        # Note that $height <= $maxHeight now.
                    } else {
                        $newwidth = floor($width * $maxHeight / $height);
                        $height = round($height * $newwidth / $width);
                        $width = $newwidth;
                        # Note that $height <= $maxHeight now, but might not be identical
                        # because of rounding.
                    }
                    $thumbnail = $this->getFile()->transform(array('width' => $width), 0);
                    if ($thumbnail == null) {
                        $url = $this->getFile()->getViewURL();
                    } else {
                        $url = $thumbnail->getURL();
                    }
                    $anchoropen = "<a href=\"{$full_url}\">";
                    $anchorclose = "</a><br />";
                    if ($this->getFile()->mustRender()) {
                        $showLink = true;
                    } else {
                        $anchorclose .= "\n{$anchoropen}{$msg}</a>";
                    }
                } else {
                    $url = $this->getFile()->getViewURL();
                    $showLink = true;
                }
                //$anchoropen = '';
                //$anchorclose = '';
                //			$width = 'auto'; //'100%';
                //			$height = 'auto'; //'100%';
                $wgOut->addHTML('<div class="fullImageLink" id="file">' . "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" style=\"max-width: {$maxWidth}px;\" alt=\"" . htmlspecialchars($wgRequest->getVal('image')) . '" />' . $anchoropen . $anchorclose . '</div>');
            } else {
                # if direct link is allowed but it's not a renderable image, show an icon.
                if ($this->getFile()->isSafeFile()) {
                    $icon = $this->getFile()->iconThumb();
                    $wgOut->addHTML('<div class="fullImageLink" id="file"><a href="' . $full_url . '">' . $icon->toHtml() . '</a></div>');
                }
                $showLink = true;
            }
            if ($showLink) {
                $filename = wfEscapeWikiText($this->getFile()->getName());
                $info = wfMsg('file-info', $sk->formatSize($this->getFile()->getSize()), $this->getFile()->getMimeType());
                if (!$this->getFile()->isSafeFile()) {
                    $warning = wfMsg('mediawarning');
                    $wgOut->addWikiText(<<<END
<div class="fullMedia">
<span class="dangerousLink">[[Media:{$filename}|{$filename}]]</span>
<span class="fileInfo"> ({$info})</span>
</div>

<div class="mediaWarning">{$warning}</div>
END
);
                } else {
                    $wgOut->addWikiText(<<<END
<div class="fullMedia">
[[Media:{$filename}|{$filename}]] <span class="fileInfo"> ({$info})</span>
</div>
END
);
                }
            }
            if ($this->getFile()->fromSharedDirectory) {
                $this->printSharedImageText();
            }
        } else {
            # Image does not exist
            $nofile = wfMsgHtml('filepage-nofile');
            if ($wgEnableUploads && $wgUser->isAllowed('upload')) {
                // Only show an upload link if the user can upload
                $nofile .= ' ' . $sk->makeKnownLinkObj(SpecialPage::getTitleFor('Upload'), wfMsgHtml('filepage-nofile-link'), 'wpDestFile=' . urlencode($this->displayImg->getName()));
            }
            $wgOut->setRobotPolicy('noindex,nofollow');
            $wgOut->addHTML('<div id="mw-imagepage-nofile">' . $nofile . '</div>');
        }
        wfProfileOut(__METHOD__);
    }
Example #13
0
    protected function openShowImage()
    {
        global $wgImageLimits, $wgEnableUploads, $wgSend404Code;
        $this->loadFile();
        $out = $this->getContext()->getOutput();
        $user = $this->getContext()->getUser();
        $lang = $this->getContext()->getLanguage();
        $dirmark = $lang->getDirMarkEntity();
        $request = $this->getContext()->getRequest();
        $sizeSel = intval($user->getOption('imagesize'));
        if (!isset($wgImageLimits[$sizeSel])) {
            $sizeSel = User::getDefaultOption('imagesize');
            // The user offset might still be incorrect, specially if
            // $wgImageLimits got changed (see bug #8858).
            if (!isset($wgImageLimits[$sizeSel])) {
                // Default to the first offset in $wgImageLimits
                $sizeSel = 0;
            }
        }
        $max = $wgImageLimits[$sizeSel];
        $maxWidth = $max[0];
        $maxHeight = $max[1];
        if ($this->displayImg->exists()) {
            # image
            $page = $request->getIntOrNull('page');
            if (is_null($page)) {
                $params = array();
                $page = 1;
            } else {
                $params = array('page' => $page);
            }
            $width_orig = $this->displayImg->getWidth($page);
            $width = $width_orig;
            $height_orig = $this->displayImg->getHeight($page);
            $height = $height_orig;
            $longDesc = wfMessage('parentheses', $this->displayImg->getLongDesc())->text();
            wfRunHooks('ImageOpenShowImageInlineBefore', array(&$this, &$out));
            if ($this->displayImg->allowInlineDisplay()) {
                # image
                # "Download high res version" link below the image
                # $msgsize = wfMessage( 'file-info-size', $width_orig, $height_orig, Linker::formatSize( $this->displayImg->getSize() ), $mime )->escaped();
                # We'll show a thumbnail of this image
                if ($width > $maxWidth || $height > $maxHeight) {
                    # Calculate the thumbnail size.
                    # First case, the limiting factor is the width, not the height.
                    if ($width / $height >= $maxWidth / $maxHeight) {
                        $height = round($height * $maxWidth / $width);
                        $width = $maxWidth;
                        # Note that $height <= $maxHeight now.
                    } else {
                        $newwidth = floor($width * $maxHeight / $height);
                        $height = round($height * $newwidth / $width);
                        $width = $newwidth;
                        # Note that $height <= $maxHeight now, but might not be identical
                        # because of rounding.
                    }
                    $msgbig = wfMessage('show-big-image')->escaped();
                    if ($this->displayImg->getRepo()->canTransformVia404()) {
                        $thumbSizes = $wgImageLimits;
                    } else {
                        # Creating thumb links triggers thumbnail generation.
                        # Just generate the thumb for the current users prefs.
                        $thumbOption = $user->getOption('thumbsize');
                        $thumbSizes = array(isset($wgImageLimits[$thumbOption]) ? $wgImageLimits[$thumbOption] : $wgImageLimits[User::getDefaultOption('thumbsize')]);
                    }
                    # Generate thumbnails or thumbnail links as needed...
                    $otherSizes = array();
                    foreach ($thumbSizes as $size) {
                        if ($size[0] < $width_orig && $size[1] < $height_orig && $size[0] != $width && $size[1] != $height) {
                            $otherSizes[] = $this->makeSizeLink($params, $size[0], $size[1]);
                        }
                    }
                    $msgsmall = wfMessage('show-big-image-preview')->rawParams($this->makeSizeLink($params, $width, $height))->parse();
                    if (count($otherSizes)) {
                        $msgsmall .= ' ' . Html::rawElement('span', array('class' => 'mw-filepage-other-resolutions'), wfMessage('show-big-image-other')->rawParams($lang->pipeList($otherSizes))->params(count($otherSizes))->parse());
                    }
                } elseif ($width == 0 && $height == 0) {
                    # Some sort of audio file that doesn't have dimensions
                    # Don't output a no hi res message for such a file
                    $msgsmall = '';
                } elseif ($this->displayImg->isVectorized()) {
                    # For vectorized images, full size is just the frame size
                    $msgsmall = '';
                } else {
                    # Image is small enough to show full size on image page
                    $msgsmall = wfMessage('file-nohires')->parse();
                }
                $params['width'] = $width;
                $params['height'] = $height;
                $thumbnail = $this->displayImg->transform($params);
                $showLink = true;
                $anchorclose = Html::rawElement('div', array('class' => 'mw-filepage-resolutioninfo'), $msgsmall);
                $isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1;
                if ($isMulti) {
                    $out->addHTML('<table class="multipageimage"><tr><td>');
                }
                if ($thumbnail) {
                    $options = array('alt' => $this->displayImg->getTitle()->getPrefixedText(), 'file-link' => true);
                    $out->addHTML('<div class="fullImageLink" id="file">' . $thumbnail->toHtml($options) . $anchorclose . "</div>\n");
                }
                if ($isMulti) {
                    $count = $this->displayImg->pageCount();
                    if ($page > 1) {
                        $label = $out->parse(wfMessage('imgmultipageprev')->text(), false);
                        $link = Linker::linkKnown($this->getTitle(), $label, array(), array('page' => $page - 1));
                        $thumb1 = Linker::makeThumbLinkObj($this->getTitle(), $this->displayImg, $link, $label, 'none', array('page' => $page - 1));
                    } else {
                        $thumb1 = '';
                    }
                    if ($page < $count) {
                        $label = wfMessage('imgmultipagenext')->text();
                        $link = Linker::linkKnown($this->getTitle(), $label, array(), array('page' => $page + 1));
                        $thumb2 = Linker::makeThumbLinkObj($this->getTitle(), $this->displayImg, $link, $label, 'none', array('page' => $page + 1));
                    } else {
                        $thumb2 = '';
                    }
                    global $wgScript;
                    $formParams = array('name' => 'pageselector', 'action' => $wgScript, 'onchange' => 'document.pageselector.submit();');
                    $options = array();
                    for ($i = 1; $i <= $count; $i++) {
                        $options[] = Xml::option($lang->formatNum($i), $i, $i == $page);
                    }
                    $select = Xml::tags('select', array('id' => 'pageselector', 'name' => 'page'), implode("\n", $options));
                    $out->addHTML('</td><td><div class="multipageimagenavbox">' . Xml::openElement('form', $formParams) . Html::hidden('title', $this->getTitle()->getPrefixedDBkey()) . wfMessage('imgmultigoto')->rawParams($select)->parse() . Xml::submitButton(wfMessage('imgmultigo')->text()) . Xml::closeElement('form') . "<hr />{$thumb1}\n{$thumb2}<br style=\"clear: both\" /></div></td></tr></table>");
                }
            } else {
                # if direct link is allowed but it's not a renderable image, show an icon.
                if ($this->displayImg->isSafeFile()) {
                    $icon = $this->displayImg->iconThumb();
                    $out->addHTML('<div class="fullImageLink" id="file">' . $icon->toHtml(array('file-link' => true)) . "</div>\n");
                }
                $showLink = true;
            }
            if ($showLink) {
                $filename = wfEscapeWikiText($this->displayImg->getName());
                $linktext = $filename;
                if (isset($msgbig)) {
                    $linktext = wfEscapeWikiText($msgbig);
                }
                $medialink = "[[Media:{$filename}|{$linktext}]]";
                if (!$this->displayImg->isSafeFile()) {
                    $warning = wfMessage('mediawarning')->plain();
                    // dirmark is needed here to separate the file name, which
                    // most likely ends in Latin characters, from the description,
                    // which may begin with the file type. In RTL environment
                    // this will get messy.
                    // The dirmark, however, must not be immediately adjacent
                    // to the filename, because it can get copied with it.
                    // See bug 25277.
                    $out->addWikiText(<<<EOT
<div class="fullMedia"><span class="dangerousLink">{$medialink}</span> {$dirmark}<span class="fileInfo">{$longDesc}</span></div>
<div class="mediaWarning">{$warning}</div>
EOT
);
                } else {
                    $out->addWikiText(<<<EOT
<div class="fullMedia">{$medialink} {$dirmark}<span class="fileInfo">{$longDesc}</span>
</div>
EOT
);
                }
            }
            // Add cannot animate thumbnail warning
            if (!$this->displayImg->canAnimateThumbIfAppropriate()) {
                // Include the extension so wiki admins can
                // customize it on a per file-type basis
                // (aka say things like use format X instead).
                // additionally have a specific message for
                // file-no-thumb-animation-gif
                $ext = $this->displayImg->getExtension();
                $noAnimMesg = wfMessageFallback('file-no-thumb-animation-' . $ext, 'file-no-thumb-animation')->plain();
                $out->addWikiText(<<<EOT
<div class="mw-noanimatethumb">{$noAnimMesg}</div>
EOT
);
            }
            if (!$this->displayImg->isLocal()) {
                $this->printSharedImageText();
            }
        } else {
            # Image does not exist
            if (!$this->getID()) {
                # No article exists either
                # Show deletion log to be consistent with normal articles
                LogEventsList::showLogExtract($out, array('delete', 'move'), $this->getTitle()->getPrefixedText(), '', array('lim' => 10, 'conds' => array("log_action != 'revision'"), 'showIfEmpty' => false, 'msgKey' => array('moveddeleted-notice')));
            }
            if ($wgEnableUploads && $user->isAllowed('upload')) {
                // Only show an upload link if the user can upload
                $uploadTitle = SpecialPage::getTitleFor('Upload');
                $nofile = array('filepage-nofile-link', $uploadTitle->getFullURL(array('wpDestFile' => $this->mPage->getFile()->getName())));
            } else {
                $nofile = 'filepage-nofile';
            }
            // Note, if there is an image description page, but
            // no image, then this setRobotPolicy is overriden
            // by Article::View().
            $out->setRobotPolicy('noindex,nofollow');
            $out->wrapWikiMsg("<div id='mw-imagepage-nofile' class='plainlinks'>\n\$1\n</div>", $nofile);
            if (!$this->getID() && $wgSend404Code) {
                // If there is no image, no shared image, and no description page,
                // output a 404, to be consistent with articles.
                $request->response()->header('HTTP/1.1 404 Not Found');
            }
        }
        $out->setFileVersion($this->displayImg);
    }
Example #14
0
    function openShowImage()
    {
        global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang;
        $full_url = $this->img->getURL();
        $linkAttribs = false;
        $sizeSel = intval($wgUser->getOption('imagesize'));
        if (!isset($wgImageLimits[$sizeSel])) {
            $sizeSel = User::getDefaultOption('imagesize');
            // The user offset might still be incorrect, specially if
            // $wgImageLimits got changed (see bug #8858).
            if (!isset($wgImageLimits[$sizeSel])) {
                // Default to the first offset in $wgImageLimits
                $sizeSel = 0;
            }
        }
        $max = $wgImageLimits[$sizeSel];
        $maxWidth = $max[0];
        //XXMOD for fixed width new layout.  eventhough 800x600 is default 679 is max article width
        if ($maxWidth > 679) {
            $maxWidth = 629;
        }
        $maxHeight = $max[1];
        $sk = $wgUser->getSkin();
        $dirmark = $wgContLang->getDirMark();
        if ($this->img->exists()) {
            # image
            $page = $wgRequest->getIntOrNull('page');
            if (is_null($page)) {
                $params = array();
                $page = 1;
            } else {
                $params = array('page' => $page);
            }
            $width_orig = $this->img->getWidth();
            $width = $width_orig;
            $height_orig = $this->img->getHeight();
            $height = $height_orig;
            $mime = $this->img->getMimeType();
            $showLink = false;
            $linkAttribs = array('href' => $full_url);
            $longDesc = $this->img->getLongDesc();
            wfRunHooks('ImageOpenShowImageInlineBefore', array(&$this, &$wgOut));
            if ($this->img->allowInlineDisplay()) {
                # image
                # "Download high res version" link below the image
                #$msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->img->getSize() ), $mime );
                # We'll show a thumbnail of this image
                if ($width > $maxWidth || $height > $maxHeight) {
                    # Calculate the thumbnail size.
                    # First case, the limiting factor is the width, not the height.
                    if ($width / $height >= $maxWidth / $maxHeight) {
                        $height = round($height * $maxWidth / $width);
                        $width = $maxWidth;
                        # Note that $height <= $maxHeight now.
                    } else {
                        $newwidth = floor($width * $maxHeight / $height);
                        $height = round($height * $newwidth / $width);
                        $width = $newwidth;
                        # Note that $height <= $maxHeight now, but might not be identical
                        # because of rounding.
                    }
                    $msgbig = wfMsgHtml('show-big-image');
                    $msgsmall = wfMsgExt('show-big-image-thumb', array('parseinline'), $wgLang->formatNum($width), $wgLang->formatNum($height));
                } else {
                    # Image is small enough to show full size on image page
                    $msgbig = htmlspecialchars($this->img->getName());
                    $msgsmall = wfMsgExt('file-nohires', array('parseinline'));
                }
                $params['width'] = $width;
                $thumbnail = $this->img->transform($params);
                $anchorclose = "<br />";
                if ($this->img->mustRender()) {
                    $showLink = true;
                } else {
                    $anchorclose .= $msgsmall . '<br />' . Xml::tags('a', $linkAttribs, $msgbig) . "{$dirmark} " . $longDesc;
                }
                if ($this->img->isMultipage()) {
                    $wgOut->addHTML('<table class="multipageimage"><tr><td>');
                }
                if ($thumbnail) {
                    $options = array('alt' => $this->img->getTitle()->getPrefixedText(), 'file-link' => true);
                    $thumb = $thumbnail->toHtml($options);
                    $recent = wfTimestamp(TS_MW, time() - 3600);
                    //XXXCHANGED: Due to the CDN works, don't show the CDN image on the image
                    // page if it's been changed within the past hour, it needs some time
                    // to update
                    if ($this->img->timestamp > $recent) {
                        $thumb = preg_replace("@http://[a-z0-9]*.wikihow.com@im", "", $thumb);
                    }
                    $wgOut->addHTML('<div class="fullImageLink minor_section" id="file">' . $thumb . '</div>');
                }
                if ($this->img->isMultipage()) {
                    $count = $this->img->pageCount();
                    if ($page > 1) {
                        $label = $wgOut->parse(wfMsg('imgmultipageprev'), false);
                        $link = $sk->makeKnownLinkObj($this->mTitle, $label, 'page=' . ($page - 1));
                        $thumb1 = $sk->makeThumbLinkObj($this->mTitle, $this->img, $link, $label, 'none', array('page' => $page - 1));
                    } else {
                        $thumb1 = '';
                    }
                    if ($page < $count) {
                        $label = wfMsg('imgmultipagenext');
                        $link = $sk->makeKnownLinkObj($this->mTitle, $label, 'page=' . ($page + 1));
                        $thumb2 = $sk->makeThumbLinkObj($this->mTitle, $this->img, $link, $label, 'none', array('page' => $page + 1));
                    } else {
                        $thumb2 = '';
                    }
                    global $wgScript;
                    $select = '<form name="pageselector" action="' . htmlspecialchars($wgScript) . '" method="get" onchange="document.pageselector.submit();">' . Xml::hidden('title', $this->getTitle()->getPrefixedDbKey());
                    $select .= $wgOut->parse(wfMsg('imgmultigotopre'), false) . ' <select id="pageselector" name="page">';
                    for ($i = 1; $i <= $count; $i++) {
                        $select .= Xml::option($wgLang->formatNum($i), $i, $i == $page);
                    }
                    $select .= '</select>' . $wgOut->parse(wfMsg('imgmultigotopost'), false) . '<input type="submit" value="' . htmlspecialchars(wfMsg('imgmultigo')) . '"></form>';
                    $wgOut->addHTML('</td><td><div class="multipageimagenavbox">' . "{$select}<hr />{$thumb1}\n{$thumb2}<br clear=\"all\" /></div></td></tr></table>");
                }
            } else {
                #if direct link is allowed but it's not a renderable image, show an icon.
                if ($this->img->isSafeFile()) {
                    $icon = $this->img->iconThumb();
                    $wgOut->addHTML('<div class="fullImageLink minor_section" id="file">' . $icon->toHtml(array('desc-link' => true)) . '</div>');
                }
                $showLink = true;
            }
            if ($showLink) {
                $filename = wfEscapeWikiText($this->img->getName());
                if (!$this->img->isSafeFile()) {
                    $warning = wfMsgNoTrans('mediawarning');
                    $wgOut->addWikiText(<<<EOT
<div class="fullMedia">
<span class="dangerousLink">[[Media:{$filename}|{$filename}]]</span>{$dirmark}
<span class="fileInfo"> {$longDesc}</span>
</div>

<div class="mediaWarning">{$warning}</div>
EOT
);
                } else {
                    $wgOut->addWikiText(<<<EOT
<div class="fullMedia">
[[Media:{$filename}|{$filename}]]{$dirmark} <span class="fileInfo"> {$longDesc}</span>
</div>
EOT
);
                }
            }
            if (!$this->img->isLocal()) {
                $this->printSharedImageText();
            }
        } else {
            # Image does not exist
            $title = SpecialPage::getTitleFor('Upload');
            $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'), 'wpDestFile=' . urlencode($this->img->getName()));
            $wgOut->addHTML(wfMsgWikiHtml('noimage', $link));
        }
    }
Example #15
0
 /** @todo document */
 function makeImageLinkObj($nt, $label, $alt, $align = '', $width = false, $height = false, $framed = false, $thumb = false, $manual_thumb = '')
 {
     global $wgContLang, $wgUser, $wgThumbLimits;
     $img = new Image($nt);
     $url = $img->getViewURL();
     $prefix = $postfix = '';
     wfDebug("makeImageLinkObj: '{$width}'x'{$height}'\n");
     if ('center' == $align) {
         $prefix = '<div class="center">';
         $postfix = '</div>';
         $align = 'none';
     }
     if ($thumb || $framed) {
         # Create a thumbnail. Alignment depends on language
         # writing direction, # right aligned for left-to-right-
         # languages ("Western languages"), left-aligned
         # for right-to-left-languages ("Semitic languages")
         #
         # If  thumbnail width has not been provided, it is set
         # to the default user option as specified in Language*.php
         if ($align == '') {
             $align = $wgContLang->isRTL() ? 'left' : 'right';
         }
         if ($width === false) {
             $wopt = $wgUser->getOption('thumbsize');
             if (!isset($wgThumbLimits[$wopt])) {
                 $wopt = User::getDefaultOption('thumbsize');
             }
             $width = $wgThumbLimits[$wopt];
         }
         return $prefix . $this->makeThumbLinkObj($img, $label, $alt, $align, $width, $height, $framed, $manual_thumb) . $postfix;
     } elseif ($width) {
         # Create a resized image, without the additional thumbnail
         # features
         if ($height !== false && $img->getHeight() * $width / $img->getWidth() > $height) {
             $width = $img->getWidth() * $height / $img->getHeight();
         }
         if ($manual_thumb == '') {
             $thumb = $img->getThumbnail($width);
             if ($thumb) {
                 if ($width > $thumb->width) {
                     // Requested a display size larger than the actual image;
                     // fake it up!
                     $height = floor($thumb->height * $width / $thumb->width);
                     wfDebug("makeImageLinkObj: client-size height set to '{$height}'\n");
                 } else {
                     $height = $thumb->height;
                     wfDebug("makeImageLinkObj: thumb height set to '{$height}'\n");
                 }
                 $url = $thumb->getUrl();
             }
         }
     } else {
         $width = $img->width;
         $height = $img->height;
     }
     wfDebug("makeImageLinkObj2: '{$width}'x'{$height}'\n");
     $u = $nt->escapeLocalURL();
     if ($url == '') {
         $s = $this->makeBrokenImageLinkObj($img->getTitle());
         //$s .= "<br />{$alt}<br />{$url}<br />\n";
     } else {
         $s = '<a href="' . $u . '" class="image" title="' . $alt . '">' . '<img src="' . $url . '" alt="' . $alt . '" ' . ($width ? 'width="' . $width . '" height="' . $height . '" ' : '') . 'longdesc="' . $u . '" /></a>';
     }
     if ('' != $align) {
         $s = "<div class=\"float{$align}\"><span>{$s}</span></div>";
     }
     return str_replace("\n", ' ', $prefix . $s . $postfix);
 }
 /**
  * Write a user_message_state for each user who is watching the thread.
  * If the thread is on a user's talkpage, set that user's newtalk.
  */
 static function writeMessageStateForUpdatedThread($t, $type, $changeUser)
 {
     wfDebugLog('LiquidThreads', 'Doing notifications');
     wfProfileIn(__METHOD__);
     // Pull users to update the message state for, including whether or not a
     //  user_message_state row exists for them, and whether or not to send an email
     //  notification.
     $userIds = array();
     $notifyUsers = array();
     $res = self::getRowsObject($t);
     foreach ($res as $row) {
         // Don't notify yourself
         if ($changeUser->getId() == $row->wl_user) {
             continue;
         }
         if (!$row->ums_user || $row->ums_read_timestamp) {
             $userIds[] = $row->wl_user;
             NewMessages::recacheMessageCount($row->wl_user);
         }
         $wantsTalkNotification = true;
         $wantsTalkNotification = $wantsTalkNotification && User::getDefaultOption('lqtnotifytalk');
         if ($wantsTalkNotification || $row->up_value) {
             $notifyUsers[] = $row->wl_user;
         }
     }
     // Add user talk notification
     if ($t->getTitle()->getNamespace() == NS_USER_TALK) {
         $name = $t->getTitle()->getText();
         $user = User::newFromName($name);
         if ($user && $user->getName() != $changeUser->getName()) {
             $user->setNewtalk(true);
             $userIds[] = $user->getId();
             if ($user->getOption('enotifusertalkpages')) {
                 $notifyUsers[] = $user->getId();
             }
         }
     }
     // Do the actual updates
     if (count($userIds)) {
         foreach ($userIds as $u) {
             $insertRows[] = array('ums_user' => $u, 'ums_thread' => $t->id(), 'ums_read_timestamp' => null, 'ums_conversation' => $t->topmostThread()->id());
         }
         $dbw = wfGetDB(DB_MASTER);
         $dbw->replace('user_message_state', array(array('ums_user', 'ums_thread')), $insertRows, __METHOD__);
     }
     global $wgLqtEnotif;
     if (count($notifyUsers) && $wgLqtEnotif) {
         self::notifyUsersByMail($t, $notifyUsers, wfTimestampNow(), $type);
     }
     wfProfileOut(__METHOD__);
 }
 /**
  * Check whether the user's preferences are such that a UI reload is
  * recommended.
  * @param User $user User
  * @return bool
  */
 public static function isUIReloadRecommended(User $user)
 {
     global $wgCentralAuthPrefsForUIReload;
     foreach ($wgCentralAuthPrefsForUIReload as $pref) {
         if ($user->getOption($pref) !== User::getDefaultOption($pref)) {
             return true;
         }
     }
     $recommendReload = false;
     Hooks::run('CentralAuthIsUIReloadRecommended', array($user, &$recommendReload));
     return $recommendReload;
 }
 /**
  * @param $parser Parser
  * @param $username string
  * @return
  */
 static function gender($parser, $username)
 {
     wfProfileIn(__METHOD__);
     $forms = array_slice(func_get_args(), 2);
     $username = trim($username);
     // default
     $gender = User::getDefaultOption('gender');
     // allow prefix.
     $title = Title::newFromText($username);
     if ($title && $title->getNamespace() == NS_USER) {
         $username = $title->getText();
     }
     // check parameter, or use the ParserOptions if in interface message
     $user = User::newFromName($username);
     if ($user) {
         $gender = $user->getOption('gender');
     } elseif ($username === '' && $parser->getOptions()->getInterfaceMessage()) {
         $gender = $parser->getOptions()->getUser()->getOption('gender');
     }
     $ret = $parser->getFunctionLang()->gender($gender, $forms);
     wfProfileOut(__METHOD__);
     return $ret;
 }
Example #19
0
 /**
  * Make an image link
  * @param Title $title Title object
  * @param File $file File object, or false if it doesn't exist
  *
  * @param array $frameParams Associative array of parameters external to the media handler.
  *     Boolean parameters are indicated by presence or absence, the value is arbitrary and 
  *     will often be false.
  *          thumbnail       If present, downscale and frame
  *          manualthumb     Image name to use as a thumbnail, instead of automatic scaling
  *          framed          Shows image in original size in a frame
  *          frameless       Downscale but don't frame
  *          upright         If present, tweak default sizes for portrait orientation
  *          upright_factor  Fudge factor for "upright" tweak (default 0.75)
  *          border          If present, show a border around the image
  *          align           Horizontal alignment (left, right, center, none)
  *          valign          Vertical alignment (baseline, sub, super, top, text-top, middle, 
  *                          bottom, text-bottom)
  *          alt             Alternate text for image (i.e. alt attribute). Plain text.
  *          caption         HTML for image caption.
  *
  * @param array $handlerParams Associative array of media handler parameters, to be passed 
  *       to transform(). Typical keys are "width" and "page". 
  * @param string $time, timestamp of the file, set as false for current
  */
 function makeImageLink2(Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false)
 {
     global $wgContLang, $wgUser, $wgThumbLimits, $wgThumbUpright;
     if ($file && !$file->allowInlineDisplay()) {
         wfDebug(__METHOD__ . ': ' . $title->getPrefixedDBkey() . " does not allow inline display\n");
         return $this->makeKnownLinkObj($title);
     }
     if (!$file) {
         return;
     }
     // Shortcuts
     $fp =& $frameParams;
     $hp =& $handlerParams;
     $section = WikihowArticleEditor::getImageSection($file->getName());
     // Clean up parameters
     $page = isset($hp['page']) ? $hp['page'] : false;
     if (!isset($fp['align'])) {
         $fp['align'] = '';
     }
     if (!isset($fp['alt'])) {
         $fp['alt'] = '';
     }
     $imageClass = "";
     $prefix = $postfix = '';
     $isPortrait = false;
     $isLarge = false;
     $sourceWidth = $file->getWidth();
     $sourceHeight = $file->getHeight();
     if ($sourceHeight > $sourceWidth) {
         if ($sourceWidth > 200) {
             $isPortrait = true;
             $isLarge = true;
         }
     } else {
         //landscape
         if ($sourceWidth > 400) {
             $isLarge = true;
         }
     }
     if ($section != "summary" && $section != "steps") {
         $isLarge = false;
     }
     if ($section == "summary") {
         //for intro they must specify 625 and center to have it shown
         if ($hp['width'] >= 625) {
             $imageClass .= " introimage ";
         }
     }
     if ($file && !isset($hp['width'])) {
         $hp['width'] = $file->getWidth($page);
         if (isset($fp['thumbnail']) || isset($fp['framed']) || isset($fp['frameless']) || !$hp['width']) {
             $wopt = $wgUser->getOption('thumbsize');
             if (!isset($wgThumbLimits[$wopt])) {
                 $wopt = User::getDefaultOption('thumbsize');
             }
             // Reduce width for upright images when parameter 'upright' is used
             if (isset($fp['upright']) && $fp['upright'] == 0) {
                 $fp['upright'] = $wgThumbUpright;
             }
             // Use width which is smaller: real image width or user preference width
             // For caching health: If width scaled down due to upright parameter, round to full __0 pixel to avoid the creation of a lot of odd thumbs
             $prefWidth = isset($fp['upright']) ? round($wgThumbLimits[$wopt] * $fp['upright'], -1) : $wgThumbLimits[$wopt];
             if ($hp['width'] <= 0 || $prefWidth < $hp['width']) {
                 $hp['width'] = $prefWidth;
             }
         }
     }
     //not using thumbs on large images anymore
     if (!$isLarge && isset($fp['thumbnail']) || isset($fp['manualthumb']) || isset($fp['framed'])) {
         # Create a thumbnail. Alignment depends on language
         # writing direction, # right aligned for left-to-right-
         # languages ("Western languages"), left-aligned
         # for right-to-left-languages ("Semitic languages")
         #
         # If  thumbnail width has not been provided, it is set
         # to the default user option as specified in Language*.php
         if ($fp['align'] == '') {
             $fp['align'] = $wgContLang->isRTL() ? 'left' : 'right';
         }
         return $prefix . $this->makeThumbLink2($title, $file, $fp, $hp, $time) . $postfix;
     }
     if ($file && isset($fp['frameless'])) {
         # For "frameless" option: do not present an image bigger than the source (for bitmap-style images)
         # This is the same behaviour as the "thumb" option does it already.
         if ($sourceWidth && !$file->mustRender() && $hp['width'] > $sourceWidth) {
             $hp['width'] = $sourceWidth;
         }
     }
     if ($file && $hp['width']) {
         # Create a resized image, without the additional thumbnail features
         if ($isLarge) {
             if ($isPortrait) {
                 //it's a portrait image
                 $height = min(550, $sourceHeight);
                 $hp['width'] = $sourceWidth * $height / $sourceHeight;
                 $imageClass .= " largeimage portrait";
             } else {
                 if ($isLarge) {
                     //this is our low threshold, so show it as big as possible
                     $hp['width'] = min(670, $sourceWidth);
                     //now make sure it's not too tall.
                     $newHeight = $sourceHeight * $hp['width'] / $sourceWidth;
                     if ($newHeight > 550) {
                         //limit all images to 550
                         $hp['width'] = $sourceWidth * 525 / $sourceHeight;
                     }
                     $imageClass .= " largeimage ";
                 }
             }
             if ($hp['width'] < 670) {
                 $imageClass .= " underwidth ";
             }
         }
         $thumb = $file->transform($hp);
     } else {
         $thumb = false;
     }
     if (!$isLarge) {
         $imageClass .= " t{$fp['align']}";
     }
     if (!$thumb) {
         $s = $this->makeBrokenImageLinkObj($title, '', '', '', '', $time == true);
     } else {
         $s = $thumb->toHtml(array('desc-link' => true, 'href' => '', 'onclick' => 'return loadimg("' . $thumb->path . '", "' . $thumb->url . '" );', 'alt' => $fp['alt'], 'valign' => isset($fp['valign']) ? $fp['valign'] : false, 'img-class' => isset($fp['border']) ? 'thumbborder' : false));
         $h = $thumb->getHeight();
         $w = $thumb->getWidth();
         /*$s = "<div class='rounders' style='width:{$w}px;height:{$h}px;'>$s
         	 <div class='corner top_left'></div><div class='corner top_right'></div><div class='corner bottom_left'></div><div class='corner bottom_right'></div>
                        </div>";*/
     }
     if ('' == $fp['align']) {
         $fp['align'] = 'right';
     }
     $imageClass .= " float{$fp['align']} ";
     if (isset($fp['thumbnail'])) {
         $imageClass .= " mthumb ";
     }
     //for mobile thumb
     $rptLink = class_exists('InaccurateImages') ? InaccurateImages::getReportImageLink() : "";
     $s = "<div class='mwimg {$imageClass}' style='max-width:{$hp['width']}px'>{$rptLink}{$s}</div>";
     return str_replace("\n", ' ', $prefix . $s . $postfix);
 }
Example #20
0
 private function _handleUpdateOption($raProperties, $option, $value, &$raSetProperties, &$raDelProperties)
 {
     $default = User::getDefaultOption($option);
     $raProp = $this->raPropertyName($option);
     // normalize default-value:
     if (is_int($default) || is_double($default)) {
         $default = (string) $default;
     } elseif (is_bool($default)) {
         if ($default === true) {
             $default = '1';
         } else {
             $default = '0';
         }
     } elseif (is_null($default)) {
         // some default values translate differently, depending on what
         // the form sends:
         // * with checkboxes $value === true|false, never null
         if (is_bool($value)) {
             $default = '0';
         } else {
             $default = '';
         }
     }
     // normalize the new value:
     if (is_int($value) || is_double($value)) {
         $value = (string) $value;
     } elseif (is_bool($value)) {
         if ($value === true) {
             $value = '1';
         } else {
             $value = '0';
         }
     }
     if (array_key_exists($raProp, $raProperties)) {
         // setting already in RestAuth
         if ($default === $value) {
             // Set back to default --> remove from RestAuth
             $raDelProperties[] = $raProp;
         } elseif ($raProperties[$raProp] != $value) {
             // RestAuth value different from local --> save to RestAuth
             $raSetProperties[$raProp] = $value;
         }
     } else {
         // setting not (yet) in RestAuth
         if ($default != $value) {
             // new value is not just default --> save to RestAuth
             $raSetProperties[$raProp] = $value;
         }
     }
 }
Example #21
0
    function openShowImage()
    {
        global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang;
        global $wgUseImageResize, $wgGenerateThumbnailOnParse;
        $full_url = $this->img->getURL();
        $anchoropen = '';
        $anchorclose = '';
        if ($wgUser->getOption('imagesize') == '') {
            $sizeSel = User::getDefaultOption('imagesize');
        } else {
            $sizeSel = intval($wgUser->getOption('imagesize'));
        }
        if (!isset($wgImageLimits[$sizeSel])) {
            $sizeSel = User::getDefaultOption('imagesize');
        }
        $max = $wgImageLimits[$sizeSel];
        $maxWidth = $max[0];
        $maxHeight = $max[1];
        $sk = $wgUser->getSkin();
        if ($this->img->exists()) {
            # image
            $page = $wgRequest->getIntOrNull('page');
            if (!is_null($page)) {
                $this->img->selectPage($page);
            } else {
                $page = 1;
            }
            $width = $this->img->getWidth();
            $height = $this->img->getHeight();
            $showLink = false;
            if ($this->img->allowInlineDisplay() and $width and $height) {
                # image
                # "Download high res version" link below the image
                $msg = wfMsgHtml('showbigimage', $width, $height, intval($this->img->getSize() / 1024));
                # We'll show a thumbnail of this image
                if ($width > $maxWidth || $height > $maxHeight) {
                    # Calculate the thumbnail size.
                    # First case, the limiting factor is the width, not the height.
                    if ($width / $height >= $maxWidth / $maxHeight) {
                        $height = round($height * $maxWidth / $width);
                        $width = $maxWidth;
                        # Note that $height <= $maxHeight now.
                    } else {
                        $newwidth = floor($width * $maxHeight / $height);
                        $height = round($height * $newwidth / $width);
                        $width = $newwidth;
                        # Note that $height <= $maxHeight now, but might not be identical
                        # because of rounding.
                    }
                    if ($wgUseImageResize) {
                        $thumbnail = $this->img->getThumbnail($width, -1, $wgGenerateThumbnailOnParse);
                        if ($thumbnail == null) {
                            $url = $this->img->getViewURL();
                        } else {
                            $url = $thumbnail->getURL();
                        }
                    } else {
                        # No resize ability? Show the full image, but scale
                        # it down in the browser so it fits on the page.
                        $url = $this->img->getViewURL();
                    }
                    $anchoropen = "<a href=\"{$full_url}\">";
                    $anchorclose = "</a><br />";
                    if ($this->img->mustRender()) {
                        $showLink = true;
                    } else {
                        $anchorclose .= "\n{$anchoropen}{$msg}</a>";
                    }
                } else {
                    $url = $this->img->getViewURL();
                    $showLink = true;
                }
                if ($this->img->isMultipage()) {
                    $wgOut->addHTML('<table class="multipageimage"><tr><td>');
                }
                $wgOut->addHTML('<div class="fullImageLink" id="file">' . $anchoropen . "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" . htmlspecialchars($wgRequest->getVal('image')) . '" />' . $anchorclose . '</div>');
                if ($this->img->isMultipage()) {
                    $count = $this->img->pageCount();
                    if ($page > 1) {
                        $label = $wgOut->parse(wfMsg('imgmultipageprev'), false);
                        $link = $sk->makeLinkObj($this->mTitle, $label, 'page=' . ($page - 1));
                        $this->img->selectPage($page - 1);
                        $thumb1 = $sk->makeThumbLinkObj($this->img, $link, $label, 'none');
                    } else {
                        $thumb1 = '';
                    }
                    if ($page < $count) {
                        $label = wfMsg('imgmultipagenext');
                        $this->img->selectPage($page + 1);
                        $link = $sk->makeLinkObj($this->mTitle, $label, 'page=' . ($page + 1));
                        $thumb2 = $sk->makeThumbLinkObj($this->img, $link, $label, 'none');
                    } else {
                        $thumb2 = '';
                    }
                    $select = '<form name="pageselector" action="' . $this->img->getEscapeLocalUrl('') . '" method="GET" onchange="document.pageselector.submit();">';
                    $select .= $wgOut->parse(wfMsg('imgmultigotopre'), false) . ' <select id="pageselector" name="page">';
                    for ($i = 1; $i <= $count; $i++) {
                        $select .= Xml::option($wgLang->formatNum($i), $i, $i == $page);
                    }
                    $select .= '</select>' . $wgOut->parse(wfMsg('imgmultigotopost'), false) . '<input type="submit" value="' . htmlspecialchars(wfMsg('imgmultigo')) . '"></form>';
                    $wgOut->addHTML('</td><td><div class="multipageimagenavbox">' . "{$select}<hr />{$thumb1}\n{$thumb2}<br clear=\"all\" /></div></td></tr></table>");
                }
            } else {
                #if direct link is allowed but it's not a renderable image, show an icon.
                if ($this->img->isSafeFile()) {
                    $icon = $this->img->iconThumb();
                    $wgOut->addHTML('<div class="fullImageLink" id="file"><a href="' . $full_url . '">' . $icon->toHtml() . '</a></div>');
                }
                $showLink = true;
            }
            if ($showLink) {
                $filename = wfEscapeWikiText($this->img->getName());
                $info = wfMsg('fileinfo', ceil($this->img->getSize() / 1024.0), $this->img->getMimeType());
                global $wgContLang;
                $dirmark = $wgContLang->getDirMark();
                if (!$this->img->isSafeFile()) {
                    $warning = wfMsg('mediawarning');
                    $wgOut->addWikiText(<<<END
<div class="fullMedia">
<span class="dangerousLink">[[Media:{$filename}|{$filename}]]</span>{$dirmark}
<span class="fileInfo"> ({$info})</span>
</div>

<div class="mediaWarning">{$warning}</div>
END
);
                } else {
                    $wgOut->addWikiText(<<<END
<div class="fullMedia">
[[Media:{$filename}|{$filename}]]{$dirmark} <span class="fileInfo"> ({$info})</span>
</div>
END
);
                }
            }
            if ($this->img->fromSharedDirectory) {
                $this->printSharedImageText();
            }
        } else {
            # Image does not exist
            $title = Title::makeTitle(NS_SPECIAL, 'Upload');
            $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'), 'wpDestFile=' . urlencode($this->img->getName()));
            $wgOut->addHTML(wfMsgWikiHtml('noimage', $link));
        }
    }
Example #22
0
 /**
  * Returns the corresponding $wgImageLimits entry for the selected user option
  *
  * @param $user User
  * @param string $optionName Name of a option to check, typically imagesize or thumbsize
  * @return array
  * @since 1.21
  */
 public function getImageLimitsFromOption($user, $optionName)
 {
     global $wgImageLimits;
     $option = $user->getIntOption($optionName);
     if (!isset($wgImageLimits[$option])) {
         $option = User::getDefaultOption($optionName);
     }
     // The user offset might still be incorrect, specially if
     // $wgImageLimits got changed (see bug #8858).
     if (!isset($wgImageLimits[$option])) {
         // Default to the first offset in $wgImageLimits
         $option = 0;
     }
     return isset($wgImageLimits[$option]) ? $wgImageLimits[$option] : array(800, 600);
     // if nothing is set, fallback to a hardcoded default
 }
Example #23
0
    protected function openShowImage()
    {
        global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang, $wgEnableUploads;
        $this->loadFile();
        $sizeSel = intval($wgUser->getOption('imagesize'));
        if (!isset($wgImageLimits[$sizeSel])) {
            $sizeSel = User::getDefaultOption('imagesize');
            // The user offset might still be incorrect, specially if
            // $wgImageLimits got changed (see bug #8858).
            if (!isset($wgImageLimits[$sizeSel])) {
                // Default to the first offset in $wgImageLimits
                $sizeSel = 0;
            }
        }
        $max = $wgImageLimits[$sizeSel];
        $maxWidth = $max[0];
        $maxHeight = $max[1];
        $sk = $wgUser->getSkin();
        $dirmark = $wgContLang->getDirMark();
        if ($this->displayImg->exists()) {
            # image
            $page = $wgRequest->getIntOrNull('page');
            if (is_null($page)) {
                $params = array();
                $page = 1;
            } else {
                $params = array('page' => $page);
            }
            $width_orig = $this->displayImg->getWidth($page);
            $width = $width_orig;
            $height_orig = $this->displayImg->getHeight($page);
            $height = $height_orig;
            $longDesc = wfMsg('parentheses', $this->displayImg->getLongDesc());
            wfRunHooks('ImageOpenShowImageInlineBefore', array(&$this, &$wgOut));
            if ($this->displayImg->allowInlineDisplay()) {
                # image
                # "Download high res version" link below the image
                # $msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->displayImg->getSize() ), $mime );
                # We'll show a thumbnail of this image
                if ($width > $maxWidth || $height > $maxHeight) {
                    # Calculate the thumbnail size.
                    # First case, the limiting factor is the width, not the height.
                    if ($width / $height >= $maxWidth / $maxHeight) {
                        $height = round($height * $maxWidth / $width);
                        $width = $maxWidth;
                        # Note that $height <= $maxHeight now.
                    } else {
                        $newwidth = floor($width * $maxHeight / $height);
                        $height = round($height * $newwidth / $width);
                        $width = $newwidth;
                        # Note that $height <= $maxHeight now, but might not be identical
                        # because of rounding.
                    }
                    $msgbig = wfMsgHtml('show-big-image');
                    $msgsmall = wfMsgExt('show-big-image-thumb', 'parseinline', $wgLang->formatNum($width), $wgLang->formatNum($height));
                } else {
                    # Image is small enough to show full size on image page
                    $msgsmall = wfMsgExt('file-nohires', array('parseinline'));
                }
                $params['width'] = $width;
                $thumbnail = $this->displayImg->transform($params);
                $showLink = true;
                $anchorclose = '';
                if (!$this->displayImg->mustRender()) {
                    $anchorclose = "<br />" . $msgsmall;
                }
                $isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1;
                if ($isMulti) {
                    $wgOut->addHTML('<table class="multipageimage"><tr><td>');
                }
                if ($thumbnail) {
                    $options = array('alt' => $this->displayImg->getTitle()->getPrefixedText(), 'file-link' => true);
                    $wgOut->addHTML('<div class="fullImageLink" id="file">' . $thumbnail->toHtml($options) . $anchorclose . "</div>\n");
                }
                if ($isMulti) {
                    $count = $this->displayImg->pageCount();
                    if ($page > 1) {
                        $label = $wgOut->parse(wfMsg('imgmultipageprev'), false);
                        $link = $sk->link($this->mTitle, $label, array(), array('page' => $page - 1), array('known', 'noclasses'));
                        $thumb1 = $sk->makeThumbLinkObj($this->mTitle, $this->displayImg, $link, $label, 'none', array('page' => $page - 1));
                    } else {
                        $thumb1 = '';
                    }
                    if ($page < $count) {
                        $label = wfMsg('imgmultipagenext');
                        $link = $sk->link($this->mTitle, $label, array(), array('page' => $page + 1), array('known', 'noclasses'));
                        $thumb2 = $sk->makeThumbLinkObj($this->mTitle, $this->displayImg, $link, $label, 'none', array('page' => $page + 1));
                    } else {
                        $thumb2 = '';
                    }
                    global $wgScript;
                    $formParams = array('name' => 'pageselector', 'action' => $wgScript, 'onchange' => 'document.pageselector.submit();');
                    for ($i = 1; $i <= $count; $i++) {
                        $options[] = Xml::option($wgLang->formatNum($i), $i, $i == $page);
                    }
                    $select = Xml::tags('select', array('id' => 'pageselector', 'name' => 'page'), implode("\n", $options));
                    $wgOut->addHTML('</td><td><div class="multipageimagenavbox">' . Xml::openElement('form', $formParams) . Html::hidden('title', $this->getTitle()->getPrefixedDbKey()) . wfMsgExt('imgmultigoto', array('parseinline', 'replaceafter'), $select) . Xml::submitButton(wfMsg('imgmultigo')) . Xml::closeElement('form') . "<hr />{$thumb1}\n{$thumb2}<br clear=\"all\" /></div></td></tr></table>");
                }
            } else {
                # if direct link is allowed but it's not a renderable image, show an icon.
                if ($this->displayImg->isSafeFile()) {
                    $icon = $this->displayImg->iconThumb();
                    $wgOut->addHTML('<div class="fullImageLink" id="file">' . $icon->toHtml(array('file-link' => true)) . "</div>\n");
                }
                $showLink = true;
            }
            if ($showLink) {
                $filename = wfEscapeWikiText($this->displayImg->getName());
                $linktext = $filename;
                if (isset($msgbig)) {
                    $linktext = wfEscapeWikiText($msgbig);
                }
                $medialink = "[[Media:{$filename}|{$linktext}]]";
                if (!$this->displayImg->isSafeFile()) {
                    $warning = wfMsgNoTrans('mediawarning');
                    $wgOut->addWikiText(<<<EOT
<div class="fullMedia"><span class="dangerousLink">{$medialink}</span>{$dirmark} <span class="fileInfo">{$longDesc}</span></div>
<div class="mediaWarning">{$warning}</div>
EOT
);
                } else {
                    $wgOut->addWikiText(<<<EOT
<div class="fullMedia">{$medialink}{$dirmark} <span class="fileInfo">{$longDesc}</span>
</div>
EOT
);
                }
            }
            if (!$this->displayImg->isLocal()) {
                $this->printSharedImageText();
            }
        } else {
            # Image does not exist
            if ($wgEnableUploads && $wgUser->isAllowed('upload')) {
                // Only show an upload link if the user can upload
                $uploadTitle = SpecialPage::getTitleFor('Upload');
                $nofile = array('filepage-nofile-link', $uploadTitle->getFullUrl(array('wpDestFile' => $this->img->getName())));
            } else {
                $nofile = 'filepage-nofile';
            }
            $wgOut->setRobotPolicy('noindex,nofollow');
            $wgOut->wrapWikiMsg("<div id='mw-imagepage-nofile' class='plainlinks'>\n\$1\n</div>", $nofile);
            if (!$this->getID()) {
                // If there is no image, no shared image, and no description page,
                // output a 404, to be consistent with articles.
                $wgRequest->response()->header("HTTP/1.1 404 Not Found");
            }
        }
    }
Example #24
0
 /**
  * This is meant to be used by time(), date(), and timeanddate() to get
  * the date preference they're supposed to use, it should be used in
  * all children.
  *
  *<code>
  * function timeanddate([...], $format = true) {
  * 	$datePreference = $this->dateFormat($format);
  * [...]
  * }
  *</code>
  *
  * @param $usePrefs Mixed: if true, the user's preference is used
  *                         if false, the site/language default is used
  *                         if int/string, assumed to be a format.
  * @return string
  */
 function dateFormat($usePrefs = true)
 {
     global $wgUser;
     if (is_bool($usePrefs)) {
         if ($usePrefs) {
             $datePreference = $wgUser->getDatePreference();
         } else {
             $datePreference = (string) User::getDefaultOption('date');
         }
     } else {
         $datePreference = (string) $usePrefs;
     }
     // return int
     if ($datePreference == '') {
         return 'default';
     }
     return $datePreference;
 }
Example #25
0
    function openShowImage()
    {
        global $wgOut, $wgUser, $wgImageLimits, $wgRequest;
        global $wgUseImageResize, $wgGenerateThumbnailOnParse;
        $full_url = $this->img->getURL();
        $anchoropen = '';
        $anchorclose = '';
        if ($wgUser->getOption('imagesize') == '') {
            $sizeSel = User::getDefaultOption('imagesize');
        } else {
            $sizeSel = intval($wgUser->getOption('imagesize'));
        }
        if (!isset($wgImageLimits[$sizeSel])) {
            $sizeSel = User::getDefaultOption('imagesize');
        }
        $max = $wgImageLimits[$sizeSel];
        $maxWidth = $max[0];
        $maxHeight = $max[1];
        $sk = $wgUser->getSkin();
        if ($this->img->exists()) {
            // WERELATE - add wrapper div
            $wgOut->addHTML('<div class="imageWrapper">');
            # image
            $width = $this->img->getWidth();
            $height = $this->img->getHeight();
            $showLink = false;
            if ($this->img->allowInlineDisplay() and $width and $height) {
                # image
                # "Download high res version" link below the image
                $msg = wfMsgHtml('showbigimage', $width, $height, intval($this->img->getSize() / 1024));
                # We'll show a thumbnail of this image
                if ($width > $maxWidth || $height > $maxHeight) {
                    # Calculate the thumbnail size.
                    # First case, the limiting factor is the width, not the height.
                    if ($width / $height >= $maxWidth / $maxHeight) {
                        $height = round($height * $maxWidth / $width);
                        $width = $maxWidth;
                        # Note that $height <= $maxHeight now.
                    } else {
                        $newwidth = floor($width * $maxHeight / $height);
                        $height = round($height * $newwidth / $width);
                        $width = $newwidth;
                        # Note that $height <= $maxHeight now, but might not be identical
                        # because of rounding.
                    }
                    if ($wgUseImageResize) {
                        $thumbnail = $this->img->getThumbnail($width, -1, $wgGenerateThumbnailOnParse);
                        if ($thumbnail == null) {
                            $url = $this->img->getViewURL();
                        } else {
                            $url = $thumbnail->getURL();
                        }
                    } else {
                        # No resize ability? Show the full image, but scale
                        # it down in the browser so it fits on the page.
                        $url = $this->img->getViewURL();
                    }
                    $anchoropen = "<a href=\"{$full_url}\">";
                    $anchorclose = "</a><br />";
                    if ($this->img->mustRender()) {
                        $showLink = true;
                    } else {
                        $anchorclose .= "\n{$anchoropen}{$msg}</a>";
                    }
                } else {
                    $url = $this->img->getViewURL();
                    $showLink = true;
                }
                $wgOut->addHTML('<div class="fullImageLink" id="file">' . $anchoropen . "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" . htmlspecialchars($wgRequest->getVal('image')) . '" />' . $anchorclose . '</div>');
                // WERELATE - added
                global $wgScriptPath;
                $wgOut->addHTML("<script type=\"text/javascript\" src=\"{$wgScriptPath}/fnclientwiki.yui.1.js\"></script>");
            } else {
                #if direct link is allowed but it's not a renderable image, show an icon.
                if ($this->img->isSafeFile()) {
                    $icon = $this->img->iconThumb();
                    $wgOut->addHTML('<div class="fullImageLink" id="file"><a href="' . $full_url . '">' . $icon->toHtml() . '</a></div>');
                }
                $showLink = true;
            }
            if ($showLink) {
                $filename = wfEscapeWikiText($this->img->getName());
                $info = wfMsg('fileinfo', ceil($this->img->getSize() / 1024.0), $this->img->getMimeType());
                global $wgContLang;
                $dirmark = $wgContLang->getDirMark();
                if (!$this->img->isSafeFile()) {
                    $warning = wfMsg('mediawarning');
                    $wgOut->addWikiText(<<<END
<div class="fullMedia">
<span class="dangerousLink">[[Media:{$filename}|{$filename}]]</span>{$dirmark}
<span class="fileInfo"> ({$info})</span>
</div>

<div class="mediaWarning">{$warning}</div>
END
);
                } else {
                    $wgOut->addWikiText(<<<END
<div class="fullMedia">
[[Media:{$filename}|{$filename}]]{$dirmark} <span class="fileInfo"> ({$info})</span>
</div>
END
);
                }
            }
            if ($this->img->fromSharedDirectory) {
                $this->printSharedImageText();
            }
            // WERELATE - end wrapper div
            $wgOut->addHTML('</div>');
        } else {
            # Image does not exist
            $title = Title::makeTitle(NS_SPECIAL, 'Upload');
            $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'), 'wpDestFile=' . urlencode($this->img->getName()));
            $wgOut->addHTML(wfMsgWikiHtml('noimage', $link));
        }
    }
 /**
  * get all global watchlist users
  */
 public function getGlobalWatchlisters($sFlag = 'watchlistdigest')
 {
     global $wgExternalDatawareDB;
     $this->mWatchlisters = array();
     $defaultValue = (int) User::getDefaultOption($sFlag);
     $this->printDebug("Default value for flag {$sFlag}: {$defaultValue}");
     $dbr = wfGetDB(DB_SLAVE, array(), $wgExternalDatawareDB);
     $aWhereClause = array("gwa_user_id > 0", "gwa_timestamp is not null");
     if (count($this->mUsers)) {
         // get only users passed by --users argument
         $aWhereClause['gwa_user_id'] = $this->mUsers;
     }
     $oResource = $dbr->select(array('global_watchlist'), array('distinct gwa_user_id'), $aWhereClause, __METHOD__, array("ORDER BY" => "gwa_user_id"));
     if ($oResource) {
         $this->printDebug("Found " . $dbr->numRows($oResource) . " users ");
         $iWatchlisters = 0;
         while ($oResultRow = $dbr->fetchObject($oResource)) {
             # user object
             $oUser = User::newFromId($oResultRow->gwa_user_id);
             if (!$oUser instanceof User) {
                 $this->printDebug("Invalid user object for user ID: {$oResultRow->gwa_user_id} ");
                 continue;
             }
             # check is email confirmed
             if (!$oUser->isEmailConfirmed()) {
                 $this->printDebug("Email is not confirmed for user ID: {$oResultRow->gwa_user_id} ");
                 continue;
             }
             # flag not set
             if (!$oUser->getBoolOption($sFlag)) {
                 $this->printDebug("{$sFlag} is not set for user ID: {$oResultRow->gwa_user_id} ");
                 continue;
             }
             $iWatchlisters++;
             $this->mWatchlisters[$oResultRow->gwa_user_id] = array('name' => $oUser->getName(), 'email' => $oUser->getEmail());
             unset($oUser);
         }
         $dbr->freeResult($oResource);
         $this->printDebug("{$iWatchlisters} global watchilster(s) found. (time: " . $this->calculateDuration(time() - $this->mStartTime) . ")");
     } else {
         $this->printDebug("No global watchlist users were found.", true);
     }
     return true;
 }
 /**
  * @param Parser $parser
  * @param string $username
  * @return string
  */
 public static function gender($parser, $username)
 {
     $forms = array_slice(func_get_args(), 2);
     // Some shortcuts to avoid loading user data unnecessarily
     if (count($forms) === 0) {
         return '';
     } elseif (count($forms) === 1) {
         return $forms[0];
     }
     $username = trim($username);
     // default
     $gender = User::getDefaultOption('gender');
     // allow prefix.
     $title = Title::newFromText($username);
     if ($title && $title->getNamespace() == NS_USER) {
         $username = $title->getText();
     }
     // check parameter, or use the ParserOptions if in interface message
     $user = User::newFromName($username);
     if ($user) {
         $gender = GenderCache::singleton()->getGenderOf($user, __METHOD__);
     } elseif ($username === '' && $parser->getOptions()->getInterfaceMessage()) {
         $gender = GenderCache::singleton()->getGenderOf($parser->getOptions()->getUser(), __METHOD__);
     }
     $ret = $parser->getFunctionLang()->gender($gender, $forms);
     return $ret;
 }
Example #28
0
 function validateGender($val)
 {
     $valid = array('male', 'female', 'unknown');
     if (in_array($val, $valid)) {
         return $val;
     } else {
         return User::getDefaultOption('gender');
     }
 }
Example #29
0
 /**
  * Given parameters derived from [[Image:Foo|options...]], generate the
  * HTML that that syntax inserts in the page.
  *
  * @param $title Title object
  * @param $file File object, or false if it doesn't exist
  * @param $frameParams Array: associative array of parameters external to the media handler.
  *     Boolean parameters are indicated by presence or absence, the value is arbitrary and
  *     will often be false.
  *          thumbnail       If present, downscale and frame
  *          manualthumb     Image name to use as a thumbnail, instead of automatic scaling
  *          framed          Shows image in original size in a frame
  *          frameless       Downscale but don't frame
  *          upright         If present, tweak default sizes for portrait orientation
  *          upright_factor  Fudge factor for "upright" tweak (default 0.75)
  *          border          If present, show a border around the image
  *          align           Horizontal alignment (left, right, center, none)
  *          valign          Vertical alignment (baseline, sub, super, top, text-top, middle,
  *                          bottom, text-bottom)
  *          alt             Alternate text for image (i.e. alt attribute). Plain text.
  *          caption         HTML for image caption.
  *          link-url        URL to link to
  *          link-title      Title object to link to
  *          link-target     Value for the target attribue, only with link-url
  *          no-link         Boolean, suppress description link
  *
  * @param $handlerParams Array: associative array of media handler parameters, to be passed
  *       to transform(). Typical keys are "width" and "page".
  * @param $time String: timestamp of the file, set as false for current
  * @param $query String: query params for desc url
  * @param $widthOption: Used by the parser to remember the user preference thumbnailsize
  * @return String: HTML for an image, with links, wrappers, etc.
  */
 static function makeImageLink2(Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "", $widthOption = null)
 {
     $res = null;
     $dummy = new DummyLinker();
     if (!wfRunHooks('ImageBeforeProduceHTML', array(&$dummy, &$title, &$file, &$frameParams, &$handlerParams, &$time, &$res))) {
         return $res;
     }
     if ($file && !$file->allowInlineDisplay()) {
         wfDebug(__METHOD__ . ': ' . $title->getPrefixedDBkey() . " does not allow inline display\n");
         return self::link($title);
     }
     // Shortcuts
     $fp =& $frameParams;
     $hp =& $handlerParams;
     // Clean up parameters
     $page = isset($hp['page']) ? $hp['page'] : false;
     if (!isset($fp['align'])) {
         $fp['align'] = '';
     }
     if (!isset($fp['alt'])) {
         $fp['alt'] = '';
     }
     if (!isset($fp['title'])) {
         $fp['title'] = '';
     }
     $prefix = $postfix = '';
     if ('center' == $fp['align']) {
         $prefix = '<div class="center">';
         $postfix = '</div>';
         $fp['align'] = 'none';
     }
     if ($file && !isset($hp['width'])) {
         if (isset($hp['height']) && $file->isVectorized()) {
             // If its a vector image, and user only specifies height
             // we don't want it to be limited by its "normal" width.
             global $wgSVGMaxSize;
             $hp['width'] = $wgSVGMaxSize;
         } else {
             $hp['width'] = $file->getWidth($page);
         }
         if (isset($fp['thumbnail']) || isset($fp['framed']) || isset($fp['frameless']) || !$hp['width']) {
             global $wgThumbLimits, $wgThumbUpright;
             if (!isset($widthOption) || !isset($wgThumbLimits[$widthOption])) {
                 $widthOption = User::getDefaultOption('thumbsize');
             }
             // Reduce width for upright images when parameter 'upright' is used
             if (isset($fp['upright']) && $fp['upright'] == 0) {
                 $fp['upright'] = $wgThumbUpright;
             }
             // For caching health: If width scaled down due to upright parameter, round to full __0 pixel to avoid the creation of a lot of odd thumbs
             $prefWidth = isset($fp['upright']) ? round($wgThumbLimits[$widthOption] * $fp['upright'], -1) : $wgThumbLimits[$widthOption];
             // Use width which is smaller: real image width or user preference width
             // Unless image is scalable vector.
             if (!isset($hp['height']) && ($hp['width'] <= 0 || $prefWidth < $hp['width'] || $file->isVectorized())) {
                 $hp['width'] = $prefWidth;
             }
         }
     }
     if (isset($fp['thumbnail']) || isset($fp['manualthumb']) || isset($fp['framed'])) {
         global $wgContLang;
         # Create a thumbnail. Alignment depends on language
         # writing direction, # right aligned for left-to-right-
         # languages ("Western languages"), left-aligned
         # for right-to-left-languages ("Semitic languages")
         #
         # If  thumbnail width has not been provided, it is set
         # to the default user option as specified in Language*.php
         if ($fp['align'] == '') {
             $fp['align'] = $wgContLang->alignEnd();
         }
         return $prefix . self::makeThumbLink2($title, $file, $fp, $hp, $time, $query) . $postfix;
     }
     if ($file && isset($fp['frameless'])) {
         $srcWidth = $file->getWidth($page);
         # For "frameless" option: do not present an image bigger than the source (for bitmap-style images)
         # This is the same behaviour as the "thumb" option does it already.
         if ($srcWidth && !$file->mustRender() && $hp['width'] > $srcWidth) {
             $hp['width'] = $srcWidth;
         }
     }
     if ($file && isset($hp['width'])) {
         # Create a resized image, without the additional thumbnail features
         $thumb = $file->transform($hp);
     } else {
         $thumb = false;
     }
     if (!$thumb) {
         $s = self::makeBrokenImageLinkObj($title, $fp['title'], '', '', '', $time == true);
     } else {
         $params = array('alt' => $fp['alt'], 'title' => $fp['title'], 'valign' => isset($fp['valign']) ? $fp['valign'] : false, 'img-class' => isset($fp['border']) ? 'thumbborder' : false);
         $params = self::getImageLinkMTOParams($fp, $query) + $params;
         $s = $thumb->toHtml($params);
     }
     if ($fp['align'] != '') {
         $s = "<div class=\"float{$fp['align']}\">{$s}</div>";
     }
     return str_replace("\n", ' ', $prefix . $s . $postfix);
 }
Example #30
0
 function getDisplaySize($img)
 {
     global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang;
     $sizeSel = intval($wgUser->getOption('imagesize'));
     if (!isset($wgImageLimits[$sizeSel])) {
         $sizeSel = User::getDefaultOption('imagesize');
         // The user offset might still be incorrect, specially if
         // $wgImageLimits got changed (see bug #8858).
         if (!isset($wgImageLimits[$sizeSel])) {
             // Default to the first offset in $wgImageLimits
             $sizeSel = 0;
         }
     }
     $max = $wgImageLimits[$sizeSel];
     $maxWidth = $max[0];
     //XXMOD for fixed width new layout.  eventhough 800x600 is default 679 is max article width
     if ($maxWidth > 679) {
         $maxWidth = 629;
     }
     $maxHeight = $max[1];
     if ($img->exists()) {
         # image
         $page = $wgRequest->getIntOrNull('page');
         if (is_null($page)) {
             $params = array();
             $page = 1;
         } else {
             $params = array('page' => $page);
         }
         $width_orig = $img->getWidth();
         $width = $width_orig;
         $height_orig = $img->getHeight();
         $height = $height_orig;
         if ($img->allowInlineDisplay()) {
             # image
             # "Download high res version" link below the image
             #$msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->img->getSize() ), $mime );
             # We'll show a thumbnail of this image
             if ($width > $maxWidth || $height > $maxHeight) {
                 # Calculate the thumbnail size.
                 # First case, the limiting factor is the width, not the height.
                 if ($width / $height >= $maxWidth / $maxHeight) {
                     $height = round($height * $maxWidth / $width);
                     $width = $maxWidth;
                     # Note that $height <= $maxHeight now.
                 } else {
                     $newwidth = floor($width * $maxHeight / $height);
                     $height = round($height * $newwidth / $width);
                     $width = $newwidth;
                     # Note that $height <= $maxHeight now, but might not be identical
                     # because of rounding.
                 }
                 $size['width'] = $width;
                 $size['height'] = $height;
                 $size['full'] = 0;
                 return $size;
             } else {
                 # Image is small enough to show full size on image page
                 $size['width'] = $width;
                 $size['height'] = $height;
                 $size['full'] = 1;
                 return $size;
             }
         } else {
             #if direct link is allowed but it's not a renderable image, show an icon.
             if ($img->isSafeFile()) {
                 $icon = $img->iconThumb();
                 $wgOut->addHTML('<div class="fullImageLink minor_section" id="file">' . $icon->toHtml(array('desc-link' => true)) . '</div>');
             }
             $showLink = true;
         }
         if (!$this->img->isLocal()) {
             $this->printSharedImageText();
         }
     } else {
         # Image does not exist
         $size['width'] = -1;
         $size['height'] = -1;
         return $size;
     }
 }