/**
* Special handling for image description pages
+ *
+ * @addtogroup Media
*/
class ImagePage extends Article {
/* private */ var $img; // Image object this page is shown for
var $mExtraDescription = false;
+ function __construct( $title ) {
+ parent::__construct( $title );
+ $this->img = wfFindFile( $this->mTitle );
+ if ( !$this->img ) {
+ $this->img = wfLocalFile( $this->mTitle );
+ }
+ }
+
/**
* Handler for action=render
* Include body text only; none of the image extras
function view() {
global $wgOut, $wgShowEXIF, $wgRequest, $wgUser;
- $this->img = new Image( $this->mTitle );
-
$diff = $wgRequest->getVal( 'diff' );
$diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
<li><a href="#file">' . $wgLang->getNsText( NS_IMAGE ) . '</a></li>
<li><a href="#filehistory">' . wfMsgHtml( 'imghistory' ) . '</a></li>
<li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' .
- ($metadata ? '<li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
+ ($metadata ? ' <li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '
</ul>';
return $r;
}
* shared upload server if possible.
*/
function getContent() {
- if( $this->img && $this->img->fromSharedDirectory && 0 == $this->getID() ) {
+ if( $this->img && !$this->img->isLocal() && 0 == $this->getID() ) {
return '';
}
return Article::getContent();
function openShowImage() {
global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang;
- global $wgUseImageResize, $wgGenerateThumbnailOnParse;
$full_url = $this->img->getURL();
- $anchoropen = '';
- $anchorclose = '';
+ $linkAttribs = false;
$sizeSel = intval( $wgUser->getOption( 'imagesize') );
if( !isset( $wgImageLimits[$sizeSel] ) ) {
$sizeSel = User::getDefaultOption( 'imagesize' );
if ( $this->img->exists() ) {
# image
$page = $wgRequest->getIntOrNull( 'page' );
- if ( ! is_null( $page ) ) {
- $this->img->selectPage( $page );
- } else {
+ if ( is_null( $page ) ) {
+ $params = array();
$page = 1;
+ } else {
+ $params = array( 'page' => $page );
}
$width_orig = $this->img->getWidth();
$width = $width_orig;
$height = $height_orig;
$mime = $this->img->getMimeType();
$showLink = false;
+ $linkAttribs = array( 'href' => $full_url );
+
+ wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this , &$wgOut ) ) ;
if ( $this->img->allowInlineDisplay() and $width and $height) {
# image
# "Download high res version" link below the image
- $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 ) {
# 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 .= wfMsg('show-big-image-thumb', $width, $height ) .
- '<br />' . "\n$anchoropen{$msgbig}</a> " . $msgsize;
- }
+ $msgbig = wfMsgHtml( 'show-big-image' );
+ $msgsmall = wfMsgExt( 'show-big-image-thumb',
+ array( 'parseinline' ), $width, $height );
} else {
- $url = $this->img->getViewURL();
+ # 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 ) . ' ' . $msgsize;
}
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( $this->img->getTitle()->getPrefixedText() ).'" />' . $anchorclose . '</div>' );
+ $imgAttribs = array(
+ 'border' => 0,
+ 'alt' => $this->img->getTitle()->getPrefixedText()
+ );
+
+ if ( $thumbnail ) {
+ $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
+ $thumbnail->toHtml( $imgAttribs, $linkAttribs ) .
+ $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' );
+ $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' );
- $this->img->selectPage( $page + 1 );
- $link = $sk->makeLinkObj( $this->mTitle, $label, 'page='. ($page+1) );
- $thumb2 = $sk->makeThumbLinkObj( $this->img, $link, $label, 'none' );
+ $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 = '';
}
htmlspecialchars( wfMsg( 'imgmultigo' ) ) . '"></form>';
$wgOut->addHTML( '</td><td><div class="multipageimagenavbox">' .
- "$select<hr />$thumb1\n$thumb2<br clear=\"all\" /></div></td></tr></table>" );
+ "$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 ($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.
+ // Workaround for incorrect MIME type on SVGs uploaded in previous versions
if ($mime == 'image/svg') $mime = 'image/svg+xml';
$filename = wfEscapeWikiText( $this->img->getName() );
// 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
+ $wgOut->addWikiText( <<<EOT
<div class="fullMedia">$infores
<span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
<span class="fileInfo"> $info</span>
</div>
<div class="mediaWarning">$warning</div>
-END
+EOT
);
} else {
- $wgOut->addWikiText( <<<END
+ $wgOut->addWikiText( <<<EOT
<div class="fullMedia">$infores
[[Media:$filename|$filename]]$dirmark <span class="fileInfo"> $info</span>
</div>
-END
+EOT
);
}
}
- if($this->img->fromSharedDirectory) {
+ if(!$this->img->isLocal()) {
$this->printSharedImageText();
}
} else {
}
function printSharedImageText() {
- global $wgRepositoryBaseUrl, $wgFetchCommonsDescriptions, $wgOut, $wgUser;
-
- $url = $wgRepositoryBaseUrl . urlencode($this->mTitle->getDBkey());
- $sharedtext = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml("sharedupload");
- if ($wgRepositoryBaseUrl && !$wgFetchCommonsDescriptions) {
+ global $wgOut, $wgUser;
+ $descUrl = $this->img->getDescriptionUrl();
+ $descText = $this->img->getDescriptionText();
+ $s = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml("sharedupload");
+ if ( $descUrl && !$descText) {
$sk = $wgUser->getSkin();
- $title = SpecialPage::getTitleFor( 'Upload' );
- $link = $sk->makeKnownLinkObj($title, wfMsgHtml('shareduploadwiki-linktext'),
- array( 'wpDestFile' => urlencode( $this->img->getName() )));
- $sharedtext .= " " . wfMsgWikiHtml('shareduploadwiki', $link);
+ $link = $sk->makeExternalLink( $descUrl, wfMsg('shareduploadwiki-linktext') );
+ $s .= " " . wfMsgWikiHtml('shareduploadwiki', $link);
}
- $sharedtext .= "</div>";
- $wgOut->addHTML($sharedtext);
+ $s .= "</div>";
+ $wgOut->addHTML($s);
- if ($wgRepositoryBaseUrl && $wgFetchCommonsDescriptions) {
- $text = Http::get($url . '?action=render');
- if ($text)
- $this->mExtraDescription = $text;
+ if ( $descText ) {
+ $this->mExtraDescription = $descText;
}
}
function uploadLinksBox() {
global $wgUser, $wgOut;
- if( $this->img->fromSharedDirectory )
+ if( !$this->img->isLocal() )
return;
$sk = $wgUser->getSkin();
$wgOut->addHtml( '<br /><ul>' );
# "Upload a new version of this file" link
- if( $wgUser->isAllowed( 'reupload' ) ) {
+ if( UploadForm::userCanReUpload($wgUser,$this->img->name) ) {
$ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
$wgOut->addHtml( "<li><div class='plainlinks'>{$ulink}</div></li>" );
}
$line = $this->img->nextHistoryLine();
if ( $line ) {
- $list = new ImageHistoryList( $sk );
+ $list = new ImageHistoryList( $sk, $this->img );
$s = $list->beginImageHistoryList() .
$list->imageHistoryLine( true, wfTimestamp(TS_MW, $line->img_timestamp),
$this->mTitle->getDBkey(), $line->img_user,
} else { $s=''; }
$wgOut->addHTML( $s );
+ $this->img->resetHistory(); // free db resources
+
# Exist check because we don't want to show this on pages where an image
# doesn't exist along with the noimage message, that would suck. -ævar
if( $wgUseExternalEditor && $this->img->exists() ) {
{
global $wgUser, $wgOut, $wgRequest;
+ if ( !$this->img->exists() || !$this->img->isLocal() ) {
+ # Use standard article deletion
+ Article::delete();
+ return;
+ }
+
$confirm = $wgRequest->wasPosted();
$reason = $wgRequest->getVal( 'wpReason' );
$image = $wgRequest->getVal( 'image' );
return;
}
if ( $wgUser->isBlocked() ) {
- return $this->blockedIPpage();
+ $wgOut->blockedPage();
+ return;
}
if ( wfReadOnly() ) {
$wgOut->readOnlyPage();
return;
}
- $this->img = new Image( $this->mTitle );
-
# Deleting old images doesn't require confirmation
if ( !is_null( $oldimage ) || $confirm ) {
if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
- $this->doDelete( $reason );
+ $this->doDeleteImage( $reason );
} else {
$wgOut->showFatalError( wfMsg( 'sessionfailure' ) );
}
/*
* Delete an image.
+ * Called doDeleteImage() not doDelete() so that Article::delete() doesn't
+ * call back to here.
+ *
* @param $reason User provided reason for deletion.
*/
- function doDelete( $reason ) {
+ function doDeleteImage( $reason ) {
global $wgOut, $wgRequest;
$oldimage = $wgRequest->getVal( 'oldimage' );
return;
}
if ( $wgUser->isBlocked() ) {
- return $this->blockedIPpage();
+ $wgOut->blockedPage();
+ return;
}
if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
$wgOut->showErrorPage( 'internalerror', 'sessionfailure' );
return;
}
- $name = substr( $oldimage, 15 );
-
- $dest = wfImageDir( $name );
- $archive = wfImageArchiveDir( $name );
- $curfile = "{$dest}/{$name}";
- if ( !is_dir( $dest ) ) wfMkdirParents( $dest );
- if ( !is_dir( $archive ) ) wfMkdirParents( $archive );
+ $sourcePath = $this->img->getArchiveVirtualUrl( $oldimage );
+ $comment = wfMsg( "reverted" );
+ $result = $this->img->upload( $sourcePath, $comment, $comment );
- if ( ! is_file( $curfile ) ) {
- $wgOut->showFileNotFoundError( htmlspecialchars( $curfile ) );
+ if ( WikiError::isError( $result ) ) {
+ $this->showError( $result );
return;
}
- $oldver = wfTimestampNow() . "!{$name}";
-
- if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
- $wgOut->showFileRenameError( $curfile, "${archive}/{$oldver}" );
- return;
- }
- if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
- $wgOut->showFileCopyError( "${archive}/{$oldimage}", $curfile );
- return;
- }
-
- # Record upload and update metadata cache
- $img = Image::newFromName( $name );
- $img->recordUpload( $oldver, wfMsg( "reverted" ) );
$wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
$wgOut->setRobotpolicy( 'noindex,nofollow' );
$wgOut->addHTML( wfMsg( 'imagereverted' ) );
- $descTitle = $img->getTitle();
+ $descTitle = $this->img->getTitle();
$wgOut->returnToMain( false, $descTitle->getPrefixedText() );
}
-
- function blockedIPpage() {
- $edit = new EditPage( $this );
- return $edit->blockedIPpage();
- }
/**
* Override handling of action=purge
*/
function doPurge() {
- $this->img = new Image( $this->mTitle );
if( $this->img->exists() ) {
wfDebug( "ImagePage::doPurge purging " . $this->img->getName() . "\n" );
$update = new HTMLCacheUpdate( $this->mTitle, 'imagelinks' );
$update->doUpdate();
+ $this->img->upgradeRow();
$this->img->purgeCache();
} else {
wfDebug( "ImagePage::doPurge no image\n" );
parent::doPurge();
}
+ /**
+ * Display an error from a wikitext-formatted WikiError object
+ */
+ function showError( WikiError $error ) {
+ global $wgOut;
+ $wgOut->setPageTitle( wfMsg( "internalerror" ) );
+ $wgOut->setRobotpolicy( "noindex,nofollow" );
+ $wgOut->setArticleRelated( false );
+ $wgOut->enableClientCache( false );
+ $wgOut->addWikiText( $error->getMessage() );
+ }
+
}
/**
* @todo document
+ * @addtogroup Media
*/
class ImageHistoryList {
- function ImageHistoryList( &$skin ) {
- $this->skin =& $skin;
+ var $img, $skin;
+ function ImageHistoryList( $skin, $img ) {
+ $this->skin = $skin;
+ $this->img = $img;
}
function beginImageHistoryList() {
$del = wfMsgHtml( 'deleteimg' );
$delall = wfMsgHtml( 'deleteimgcompletely' );
$cur = wfMsgHtml( 'cur' );
+ $local = $this->img->isLocal();
if ( $iscur ) {
- $url = Image::imageUrl( $img );
+ $url = htmlspecialchars( $this->img->getURL() );
$rlink = $cur;
- if ( $wgUser->isAllowed('delete') ) {
+ if ( $local && $wgUser->isAllowed('delete') ) {
$link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() .
'&action=delete' );
$style = $this->skin->getInternalLinkAttributes( $link, $delall );
$dlink = $del;
}
} else {
- $url = htmlspecialchars( wfImageArchiveUrl( $img ) );
- if( $wgUser->getID() != 0 && $wgTitle->userCan( 'edit' ) ) {
+ $url = htmlspecialchars( $this->img->getArchiveUrl( $img ) );
+ if( $local && $wgUser->getID() != 0 && $wgTitle->userCan( 'edit' ) ) {
$token = urlencode( $wgUser->editToken( $img ) );
$rlink = $this->skin->makeKnownLinkObj( $wgTitle,
wfMsgHtml( 'revertimg' ), 'action=revert&oldimage=' .
$dlink = $del;
}
}
-
- $userlink = $this->skin->userLink( $user, $usertext ) . $this->skin->userToolLinks( $user, $usertext );
+
+ if ( $local ) {
+ $userlink = $this->skin->userLink( $user, $usertext ) . $this->skin->userToolLinks( $user, $usertext );
+ } else {
+ $userlink = htmlspecialchars( $usertext );
+ }
$nbytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
$wgLang->formatNum( $size ) );
$widthheight = wfMsgHtml( 'widthheight', $width, $height );
$s .= "</li>\n";
return $s;
}
-
}
-?>
+