X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FImagePage.php;h=3265b7f386066a34d22e9b8a27d7def2c3669a32;hb=8c3b4616cdf2bcd9c8cc1264b806c47b2523f163;hp=fda8f132bfc8ead6599aed2615c1accbad767b36;hpb=64e572519fecaf495c5461e66521cf084eea8d45;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ImagePage.php b/includes/ImagePage.php index fda8f132bf..3265b7f386 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -10,12 +10,22 @@ if( !defined( 'MEDIAWIKI' ) ) /** * 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 @@ -29,8 +39,6 @@ class ImagePage extends Article { function view() { global $wgOut, $wgShowEXIF, $wgRequest, $wgUser; - $this->img = new Image( $this->mTitle ); - $diff = $wgRequest->getVal( 'diff' ); $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) ); @@ -64,7 +72,7 @@ class ImagePage extends Article { # Show shared description, if needed if ( $this->mExtraDescription ) { $fol = wfMsg( 'shareddescriptionfollows' ); - if( $fol != '-' ) { + if( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) { $wgOut->addWikiText( $fol ); } $wgOut->addHTML( '
' . $this->mExtraDescription . '
' ); @@ -100,7 +108,7 @@ class ImagePage extends Article {
  • ' . $wgLang->getNsText( NS_IMAGE ) . '
  • ' . wfMsgHtml( 'imghistory' ) . '
  • ' . wfMsgHtml( 'imagelinks' ) . '
  • ' . - ($metadata ? '
  • ' . wfMsgHtml( 'metadata' ) . '
  • ' : '') . ' + ($metadata ? '
  • ' . wfMsgHtml( 'metadata' ) . '
  • ' : '') . ' '; return $r; } @@ -158,7 +166,7 @@ class ImagePage extends Article { * 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(); @@ -166,15 +174,19 @@ class ImagePage extends Article { 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' ); + + // 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]; @@ -184,21 +196,27 @@ class ImagePage extends Article { 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 = $this->img->getWidth(); - $height = $this->img->getHeight(); + $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 ); + + wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this , &$wgOut ) ) ; 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 ) ); - + $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. @@ -214,56 +232,59 @@ class ImagePage extends Article { # 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 = ""; - $anchorclose = "
    "; - if( $this->img->mustRender() ) { - $showLink = true; - } else { - $anchorclose .= "\n$anchoropen{$msg}"; - } + $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 = "
    "; + if( $this->img->mustRender() ) { $showLink = true; + } else { + $anchorclose .= + $msgsmall . + '
    ' . Xml::tags( 'a', $linkAttribs, $msgbig ) . ' ' . $msgsize; } if ( $this->img->isMultipage() ) { $wgOut->addHTML( '
    ' ); } - $wgOut->addHTML( '' ); + $imgAttribs = array( + 'border' => 0, + 'alt' => $this->img->getTitle()->getPrefixedText() + ); + + if ( $thumbnail ) { + $wgOut->addHTML( '' ); + } 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 = ''; } @@ -284,7 +305,7 @@ class ImagePage extends Article { htmlspecialchars( wfMsg( 'imgmultigo' ) ) . '">'; $wgOut->addHTML( '
    ' . - "$select
    $thumb1\n$thumb2
    " ); + "$select
    $thumb1\n$thumb2
    " ); } } else { #if direct link is allowed but it's not a renderable image, show an icon. @@ -301,41 +322,42 @@ class ImagePage extends Article { if ($showLink) { - $filename = wfEscapeWikiText( $this->img->getName() ); - // 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. - $mime = $this->img->getMimeType(); + // Workaround for incorrect MIME type on SVGs uploaded in previous versions if ($mime == 'image/svg') $mime = 'image/svg+xml'; - $info = wfMsg( 'fileinfo', - ceil($this->img->getSize()/1024.0), - $mime ); + $filename = wfEscapeWikiText( $this->img->getName() ); + $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 ) . '
    '; + } global $wgContLang; $dirmark = $wgContLang->getDirMark(); if (!$this->img->isSafeFile()) { $warning = wfMsg( 'mediawarning' ); - $wgOut->addWikiText( << + $wgOut->addWikiText( <<$infores [[Media:$filename|$filename]]$dirmark - ($info) + $info
    $warning
    -END +EOT ); } else { - $wgOut->addWikiText( << -[[Media:$filename|$filename]]$dirmark ($info) + $wgOut->addWikiText( <<$infores +[[Media:$filename|$filename]]$dirmark $info -END +EOT ); } } - if($this->img->fromSharedDirectory) { + if(!$this->img->isLocal()) { $this->printSharedImageText(); } } else { @@ -349,25 +371,21 @@ END } function printSharedImageText() { - global $wgRepositoryBaseUrl, $wgFetchCommonsDescriptions, $wgOut, $wgUser; - - $url = $wgRepositoryBaseUrl . urlencode($this->mTitle->getDBkey()); - $sharedtext = "
    " . wfMsgWikiHtml("sharedupload"); - if ($wgRepositoryBaseUrl && !$wgFetchCommonsDescriptions) { + global $wgOut, $wgUser; + $descUrl = $this->img->getDescriptionUrl(); + $descText = $this->img->getDescriptionText(); + $s = "
    " . 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 .= "
    "; - $wgOut->addHTML($sharedtext); + $s .= "
    "; + $wgOut->addHTML($s); - if ($wgRepositoryBaseUrl && $wgFetchCommonsDescriptions) { - $text = Http::get($url . '?action=render'); - if ($text) - $this->mExtraDescription = $text; + if ( $descText ) { + $this->mExtraDescription = $descText; } } @@ -384,7 +402,7 @@ END function uploadLinksBox() { global $wgUser, $wgOut; - if( $this->img->fromSharedDirectory ) + if( !$this->img->isLocal() ) return; $sk = $wgUser->getSkin(); @@ -392,9 +410,9 @@ END $wgOut->addHtml( '
      ' ); # "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( "
    • {$ulink}
    • " ); + $wgOut->addHtml( "
    • " ); } # External editing link @@ -423,7 +441,7 @@ END $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, @@ -442,6 +460,8 @@ END } 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() ) { @@ -484,6 +504,12 @@ END { 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' ); @@ -496,7 +522,8 @@ END return; } if ( $wgUser->isBlocked() ) { - return $this->blockedIPpage(); + $wgOut->blockedPage(); + return; } if ( wfReadOnly() ) { $wgOut->readOnlyPage(); @@ -511,12 +538,10 @@ END 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' ) ); } @@ -535,9 +560,12 @@ END /* * 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' ); @@ -629,62 +657,40 @@ END 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 ) ); - 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 ); + if ( WikiError::isError( $result ) ) { + $this->showError( $result ); 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" ); @@ -692,14 +698,29 @@ END 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() { @@ -721,11 +742,12 @@ class ImageHistoryList { $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 ); @@ -735,8 +757,8 @@ class ImageHistoryList { $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=' . @@ -752,8 +774,12 @@ class ImageHistoryList { $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 ); @@ -765,8 +791,7 @@ class ImageHistoryList { $s .= "\n"; return $s; } - } -?> +