<?php
/**
- * @package MediaWiki
*/
/**
if( !defined( 'MEDIAWIKI' ) )
die( 1 );
-require_once( 'Image.php' );
-
/**
* Special handling for image description pages
- * @package MediaWiki
*/
class ImagePage extends Article {
}
function view() {
- global $wgOut, $wgShowEXIF;
+ global $wgOut, $wgShowEXIF, $wgRequest, $wgUser;
$this->img = new Image( $this->mTitle );
- if( $this->mTitle->getNamespace() == NS_IMAGE ) {
- if ($wgShowEXIF && $this->img->exists()) {
- $exif = $this->img->getExifData();
- $showmeta = count($exif) ? true : false;
- } else {
- $exif = false;
- $showmeta = false;
- }
+ $diff = $wgRequest->getVal( 'diff' );
+ $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
- if ($this->img->exists())
- $wgOut->addHTML($this->showTOC($showmeta));
+ if ( $this->mTitle->getNamespace() != NS_IMAGE || ( isset( $diff ) && $diffOnly ) )
+ return Article::view();
- $this->openShowImage();
+ if ($wgShowEXIF && $this->img->exists()) {
+ $exif = $this->img->getExifData();
+ $showmeta = count($exif) ? true : false;
+ } else {
+ $exif = false;
+ $showmeta = false;
+ }
- # No need to display noarticletext, we use our own message, output in openShowImage()
- if( $this->getID() ) {
- Article::view();
- } else {
- # Just need to set the right headers
- $wgOut->setArticleFlag( true );
- $wgOut->setRobotpolicy( 'index,follow' );
- $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
- $this->viewUpdates();
- }
+ if ($this->img->exists())
+ $wgOut->addHTML($this->showTOC($showmeta));
- # Show shared description, if needed
- if( $this->mExtraDescription ) {
- $fol = wfMsg( 'shareddescriptionfollows' );
- if( $fol != '-' ) {
- $wgOut->addWikiText( $fol );
- }
- $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . '</div>' );
- }
+ $this->openShowImage();
- $this->closeShowImage();
- $this->imageHistory();
- $this->imageLinks();
- if( $exif ) {
- global $wgStylePath;
- $expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) );
- $collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) );
- $wgOut->addHTML( "<h2 id=\"metadata\">" . wfMsgHtml( 'metadata' ) . "</h2>\n" );
- $wgOut->addWikiText( $this->makeMetadataTable( $exif ) );
- $wgOut->addHTML(
- "<script type=\"text/javascript\" src=\"$wgStylePath/common/metadata.js\"></script>\n" .
- "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
- }
- } else {
+ # No need to display noarticletext, we use our own message, output in openShowImage()
+ if ( $this->getID() ) {
Article::view();
+ } else {
+ # Just need to set the right headers
+ $wgOut->setArticleFlag( true );
+ $wgOut->setRobotpolicy( 'index,follow' );
+ $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
+ $this->viewUpdates();
+ }
+
+ # Show shared description, if needed
+ if ( $this->mExtraDescription ) {
+ $fol = wfMsg( 'shareddescriptionfollows' );
+ if( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) {
+ $wgOut->addWikiText( $fol );
+ }
+ $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . '</div>' );
+ }
+
+ $this->closeShowImage();
+ $this->imageHistory();
+ $this->imageLinks();
+
+ if ( $exif ) {
+ global $wgStylePath, $wgStyleVersion;
+ $expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) );
+ $collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) );
+ $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ). "\n" );
+ $wgOut->addWikiText( $this->makeMetadataTable( $exif ) );
+ $wgOut->addHTML(
+ "<script type=\"text/javascript\" src=\"$wgStylePath/common/metadata.js?$wgStyleVersion\"></script>\n" .
+ "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
}
}
$fields = array();
$lines = explode( "\n", wfMsgForContent( 'metadata-fields' ) );
foreach( $lines as $line ) {
+ $matches = array();
if( preg_match( '/^\\*\s*(.*?)\s*$/', $line, $matches ) ) {
$fields[] = $matches[1];
}
}
function openShowImage() {
- global $wgOut, $wgUser, $wgImageLimits, $wgRequest;
+ 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' ) );
- }
+ $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];
if ( $this->img->exists() ) {
# image
- $width = $this->img->getWidth();
- $height = $this->img->getHeight();
+ $page = $wgRequest->getIntOrNull( 'page' );
+ if ( ! is_null( $page ) ) {
+ $this->img->selectPage( $page );
+ } else {
+ $page = 1;
+ }
+ $width_orig = $this->img->getWidth();
+ $width = $width_orig;
+ $height_orig = $this->img->getHeight();
+ $height = $height_orig;
+ $mime = $this->img->getMimeType();
$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 ) );
-
+ $msgbig = wfMsgHtml('show-big-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.
if( $this->img->mustRender() ) {
$showLink = true;
} else {
- $anchorclose .= "\n$anchoropen{$msg}</a>";
+ $anchorclose .= wfMsg('show-big-image-thumb', $width, $height ) .
+ '<br />' . "\n$anchoropen{$msgbig}</a> " . $msgsize;
}
} 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>' );
+ htmlspecialchars( $this->img->getTitle()->getPrefixedText() ).'" />' . $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 = '';
+ }
+
+ 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()) {
if ($showLink) {
+ // Hacky workaround: for some reason we use the incorrect MIME type
+ // image/svg for SVG. This should be fixed internally, but at least
+ // make the displayed type right.
+ if ($mime == 'image/svg') $mime = 'image/svg+xml';
+
$filename = wfEscapeWikiText( $this->img->getName() );
- $info = wfMsg( 'fileinfo',
- ceil($this->img->getSize()/1024.0),
- $this->img->getMimeType() );
+ $info = wfMsg( 'file-info', $sk->formatSize( $this->img->getSize() ), $mime );
+ $infores = '';
+
+ // Check for MIME type. Other types may have more information in the future.
+ if (substr($mime,0,9) == 'image/svg' ) {
+ $infores = wfMsg('file-svg', $width_orig, $height_orig ) . '<br />';
+ } elseif ( substr($mime,0,5) == 'image' ) {
+ $infores = wfMsg('file-nohires') . '<br />';
+ $info = wfMsg(
+ 'file-info-size',
+ $width_orig, $height_orig,
+ $sk->formatSize( $this->img->getSize() ),
+ $mime );
+ }
global $wgContLang;
$dirmark = $wgContLang->getDirMark();
if (!$this->img->isSafeFile()) {
$warning = wfMsg( 'mediawarning' );
$wgOut->addWikiText( <<<END
-<div class="fullMedia">
+<div class="fullMedia">$infores
<span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
-<span class="fileInfo"> ($info)</span>
+<span class="fileInfo"> $info</span>
</div>
<div class="mediaWarning">$warning</div>
);
} else {
$wgOut->addWikiText( <<<END
-<div class="fullMedia">
-[[Media:$filename|$filename]]$dirmark <span class="fileInfo"> ($info)</span>
+<div class="fullMedia">$infores
+[[Media:$filename|$filename]]$dirmark <span class="fileInfo"> $info</span>
</div>
END
);
} else {
# Image does not exist
- $title = Title::makeTitle( NS_SPECIAL, 'Upload' );
+ $title = SpecialPage::getTitleFor( 'Upload' );
$link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),
'wpDestFile=' . urlencode( $this->img->getName() ) );
$wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );
if ($wgRepositoryBaseUrl && !$wgFetchCommonsDescriptions) {
$sk = $wgUser->getSkin();
- $title = Title::makeTitle( NS_SPECIAL, 'Upload' );
+ $title = SpecialPage::getTitleFor( 'Upload' );
$link = $sk->makeKnownLinkObj($title, wfMsgHtml('shareduploadwiki-linktext'),
array( 'wpDestFile' => urlencode( $this->img->getName() )));
$sharedtext .= " " . wfMsgWikiHtml('shareduploadwiki', $link);
$wgOut->addHTML($sharedtext);
if ($wgRepositoryBaseUrl && $wgFetchCommonsDescriptions) {
- require_once("HttpFunctions.php");
- $ur = ini_set('allow_url_fopen', true);
- $text = wfGetHTTP($url . '?action=render');
- ini_set('allow_url_fopen', $ur);
+ $renderUrl = wfAppendQuery( $url, 'action=render' );
+ wfDebug( "Fetching shared description from $renderUrl\n" );
+ $text = Http::get( $renderUrl );
if ($text)
$this->mExtraDescription = $text;
}
function getUploadUrl() {
global $wgServer;
- $uploadTitle = Title::makeTitle( NS_SPECIAL, 'Upload' );
+ $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
return $wgServer . $uploadTitle->getLocalUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) );
}
# "Upload a new version of this file" link
if( $wgUser->isAllowed( 'reupload' ) ) {
$ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
- $wgOut->addHtml( "<li><div>{$ulink}</div></li>" );
+ $wgOut->addHtml( "<li><div class='plainlinks'>{$ulink}</div></li>" );
}
# External editing link
- $elink = $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
+ $elink = $sk->makeKnownLinkObj( $this->mTitle, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
$wgOut->addHtml( '<li>' . $elink . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );
$wgOut->addHtml( '</ul>' );
{
global $wgUser, $wgOut;
- $wgOut->addHTML( '<h2 id="filelinks">' . wfMsg( 'imagelinks' ) . "</h2>\n" );
+ $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'filelinks' ), wfMsg( 'imagelinks' ) ) . "\n" );
- $dbr =& wfGetDB( DB_SLAVE );
+ $dbr = wfGetDB( DB_SLAVE );
$page = $dbr->tableName( 'page' );
$imagelinks = $dbr->tableName( 'imagelinks' );
# Only sysops can delete images. Previously ordinary users could delete
# old revisions, but this is no longer the case.
if ( !$wgUser->isAllowed('delete') ) {
- $wgOut->sysopRequired();
+ $wgOut->permissionRequired( 'delete' );
return;
}
if ( $wgUser->isBlocked() ) {
* @param $reason User provided reason for deletion.
*/
function doDelete( $reason ) {
- global $wgOut, $wgRequest, $wgUseSquid;
- global $wgPostCommitUpdateList;
-
- $fname = 'ImagePage::doDelete';
+ global $wgOut, $wgRequest;
$oldimage = $wgRequest->getVal( 'oldimage' );
- $dbw =& wfGetDB( DB_MASTER );
-
if ( !is_null( $oldimage ) ) {
if ( strlen( $oldimage ) < 16 ) {
$wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
$wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
return;
}
- if ( ! $this->mTitle->userCanEdit() ) {
- $wgOut->sysopRequired();
+ if ( ! $this->mTitle->userCan( 'edit' ) ) {
+ $wgOut->readOnlyPage( $this->getContent(), true );
return;
}
if ( $wgUser->isBlocked() ) {
}
$oldver = wfTimestampNow() . "!{$name}";
- $dbr =& wfGetDB( DB_SLAVE );
- $size = $dbr->selectField( 'oldimage', 'oi_size', array( 'oi_archive_name' => $oldimage ) );
-
if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
$wgOut->showFileRenameError( $curfile, "${archive}/{$oldver}" );
return;
/**
* @todo document
- * @package MediaWiki
*/
class ImageHistoryList {
function ImageHistoryList( &$skin ) {
}
function beginImageHistoryList() {
- $s = "\n<h2 id=\"filehistory\">" . wfMsg( 'imghistory' ) . "</h2>\n" .
- "<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
+ $s = "\n" .
+ Xml::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'imghistory' ) ) .
+ "\n<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
return $s;
}
global $wgUser, $wgLang, $wgTitle, $wgContLang;
$datetime = $wgLang->timeanddate( $timestamp, true );
- $del = wfMsg( 'deleteimg' );
- $delall = wfMsg( 'deleteimgcompletely' );
- $cur = wfMsg( 'cur' );
+ $del = wfMsgHtml( 'deleteimg' );
+ $delall = wfMsgHtml( 'deleteimgcompletely' );
+ $cur = wfMsgHtml( 'cur' );
if ( $iscur ) {
$url = Image::imageUrl( $img );
}
} else {
$url = htmlspecialchars( wfImageArchiveUrl( $img ) );
- if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
+ if( $wgUser->getID() != 0 && $wgTitle->userCan( 'edit' ) ) {
$token = urlencode( $wgUser->editToken( $img ) );
$rlink = $this->skin->makeKnownLinkObj( $wgTitle,
- wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
+ wfMsgHtml( 'revertimg' ), 'action=revert&oldimage=' .
urlencode( $img ) . "&wpEditToken=$token" );
$dlink = $this->skin->makeKnownLinkObj( $wgTitle,
$del, 'action=delete&oldimage=' . urlencode( $img ) .
# Having live active links for non-logged in users
# means that bots and spiders crawling our site can
# inadvertently change content. Baaaad idea.
- $rlink = wfMsg( 'revertimg' );
+ $rlink = wfMsgHtml( 'revertimg' );
$dlink = $del;
}
}
$userlink = $this->skin->userLink( $user, $usertext ) . $this->skin->userToolLinks( $user, $usertext );
$nbytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
$wgLang->formatNum( $size ) );
- $widthheight = wfMsg( 'widthheight', $width, $height );
+ $widthheight = wfMsgHtml( 'widthheight', $width, $height );
$style = $this->skin->getInternalLinkAttributes( $url, $datetime );
$s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a> . . {$userlink} . . {$widthheight} ({$nbytes})";