X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FImagePage.php;h=1ab1c36f455952da02b5e5dc3f670c77fc9c41ba;hb=8f618346f808fcc65de4574654053c73b588bf50;hp=7a9209ebe878fd84a772e8edc631525423a10f60;hpb=f943ce06fd4de70eb9bd73138db922ce3ae485be;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 7a9209ebe8..1ab1c36f45 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -17,45 +17,131 @@ require_once( 'Image.php' ); */ class ImagePage extends Article { - /* private */ var $img; // Image object this page is shown for. Initilaized in openShowImage, not - // available in doDelete etc. + /* private */ var $img; // Image object this page is shown for + var $mExtraDescription = false; + + function render() { + global $wgOut; + $wgOut->setArticleBodyOnly(true); + $wgOut->addWikitext($this->getContent(true)); + } function view() { - global $wgUseExternalEditor; - if( $this->mTitle->getNamespace() == NS_IMAGE ) { + global $wgUseExternalEditor, $wgOut, $wgShowEXIF; + + $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; + } + + if ($this->img->exists()) + $wgOut->addHTML($this->showTOC($showmeta)); + $this->openShowImage(); - } + if ($exif) + $wgOut->addWikiText($this->makeMetadataTable($exif)); - Article::view(); - if($wgUseExternalEditor) { - $this->externalEditorLink(); - } - - # If the article we've just shown is in the "Image" namespace, - # follow it with the history list and link list for the image - # it describes. + # 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() ); + $wgOut->addMetaTags(); + $this->viewUpdates(); + } + + if ($this->mExtraDescription) { + $fol = wfMsg('shareddescriptionfollows'); + if ($fol != '-') + $wgOut->addWikiText(wfMsg('shareddescriptionfollows')); + $wgOut->addHTML($this->mExtraDescription); + } - if( $this->mTitle->getNamespace() == NS_IMAGE ) { $this->closeShowImage(); $this->imageHistory(); $this->imageLinks(); + } else { + Article::view(); } } + /** + * Create the TOC + * + * @access private + * + * @param bool $metadata Whether or not to show the metadata link + * @return string + */ + function showTOC( $metadata ) { + global $wgLang; + $r = ''; + return $r; + } + + /** + * Make a table with metadata to be shown in the output page. + * + * @access private + * + * @param array $exif The array containing the EXIF data + * @return string + */ + function makeMetadataTable( $exif ) { + $r = "{| class=metadata align=right width=250px\n"; + $r .= '|+ id=metadata | '. wfMsg( 'metadata' ) . "\n"; + foreach( $exif as $k => $v ) { + $tag = strtolower( $k ); + $msg = wfMsg( "exif-$tag" ); + + $r .= "! class=$tag | $msg\n"; + $r .= "| class=$tag | $v\n"; + $r .= "|-\n"; + } + return substr($r, 0, -3) . '|}'; + } + + /** + * Overloading Article's getContent method. + * Omit noarticletext if sharedupload + * + * @param $noredir If true, do not follow redirects + */ + function getContent( $noredir ) + { + if ( $this->img && $this->img->fromSharedDirectory && 0 == $this->getID() ) { + return ''; + } + return Article::getContent( $noredir ); + } + function openShowImage() { - global $wgOut, $wgUser, $wgImageLimits, $wgRequest, - $wgUseImageResize, $wgRepositoryBaseUrl, - $wgUseExternalEditor; - $this->img = Image::newFromTitle( $this->mTitle ); - $full_url = $this->img->getViewURL(); + global $wgOut, $wgUser, $wgImageLimits, $wgRequest, + $wgUseImageResize, $wgRepositoryBaseUrl, + $wgUseExternalEditor, $wgServer, $wgFetchCommonsDescriptions; + $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' ); @@ -63,21 +149,23 @@ class ImagePage extends Article { $max = $wgImageLimits[$sizeSel]; $maxWidth = $max[0]; $maxHeight = $max[1]; - + $sk = $wgUser->getSkin(); if ( $this->img->exists() ) { + # image + $width = $this->img->getWidth(); + $height = $this->img->getHeight(); + $showLink = false; - $sk = $wgUser->getSkin(); - - if ( $this->img->getType() != '' ) { + if ( $this->img->allowInlineDisplay() and $width and $height) { # image - $width = $this->img->getWidth(); - $height = $this->img->getHeight(); - $msg = wfMsg('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) ); + + # "Download high res version" link below the image + $msg = wfMsgHtml('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) ); if ( $width > $maxWidth ) { $height = floor( $height * $maxWidth / $width ); $width = $maxWidth; - } + } if ( $height > $maxHeight ) { $width = floor( $width * $maxHeight / $height ); $height = $maxHeight; @@ -85,63 +173,140 @@ class ImagePage extends Article { if ( $width != $this->img->getWidth() || $height != $this->img->getHeight() ) { if( $wgUseImageResize ) { $thumbnail = $this->img->getThumbnail( $width ); - - if ( ( ! $this->img->mustRender() ) - && ( $thumbnail->getSize() > $this->img->getSize() ) ) { - # the thumbnail is bigger thatn the original image. - # show the original image instead of the thumb. - $url = $full_url; - $width = $this->img->getWidth(); - $height = $this->img->getHeight(); + if ( $thumbnail == null ) { + $url = $this->img->getViewURL(); } else { - $url = $thumbnail->getUrl(); + $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 = $full_url; + $url = $this->img->getViewURL(); } $anchoropen = ""; - $anchorclose = "
\n$anchoropen{$msg}"; + $anchorclose = "
"; + if( $this->img->mustRender() ) { + $showLink = true; + } else { + $anchorclose .= "\n$anchoropen{$msg}"; + } } else { - $url = $full_url; + $url = $this->img->getViewURL(); + $showLink = true; } - $s = '' ); } else { - $s = "
" . $sk->makeMediaLink( $this->img->getName(),'' ) . '
'; + #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( '' ); + } + + $showLink = true; } - $wgOut->addHTML( $s ); - if($this->img->fromSharedDirectory) { - $sharedtext="
" . wfMsg("sharedupload"); - if($wgRepositoryBaseUrl) { - $sharedtext .= " ". wfMsg("shareduploadwiki",$wgRepositoryBaseUrl . urlencode($this->mTitle->getDBkey())); + + + if ($showLink) { + $filename = wfEscapeWikiText( $this->img->getName() ); + $info = wfMsg( 'fileinfo', + ceil($this->img->getSize()/1024.0), + $this->img->getMimeType() ); + + if (!$this->img->isSafeFile()) { + $warning = wfMsg( 'mediawarning' ); + $wgOut->addWikiText( << +[[Media:$filename|$filename]] + ($info) +
+ +
$warning
+END + ); + } else { + $wgOut->addWikiText( << +[[Media:$filename|$filename]] ($info) + +END + ); } - $sharedtext.=""; - $wgOut->addWikiText($sharedtext); } - + + 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 ) ); } } - - function externalEditorLink() + + function printSharedImageText() { + global $wgRepositoryBaseUrl, $wgFetchCommonsDescriptions, $wgOut, $wgUser; + + $url = $wgRepositoryBaseUrl . urlencode($this->mTitle->getDBkey()); + $sharedtext = "
" . wfMsgWikiHtml("sharedupload"); + if ($wgRepositoryBaseUrl && !$wgFetchCommonsDescriptions) { + + $sk = $wgUser->getSkin(); + $title = Title::makeTitle( NS_SPECIAL, 'Upload' ); + $link = $sk->makeKnownLinkObj($title, wfMsgHtml('shareduploadwiki-linktext'), + array( 'wpDestFile' => urlencode( $this->img->getName() ))); + $sharedtext .= " " . wfMsgWikiHtml('shareduploadwiki', $link); + } + $sharedtext .= "
"; + $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); + if ($text) + $this->mExtraDescription = $text; + } + } + + function getUploadUrl() { + global $wgServer; + $uploadTitle = Title::makeTitle( NS_SPECIAL, 'Upload' ); + return $wgServer . $uploadTitle->getLocalUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) ); + } + + + function uploadLinksBox() { - global $wgUser,$wgOut; + global $wgUser, $wgOut; + + if ($this->img->fromSharedDirectory) + return; + $sk = $wgUser->getSkin(); - $wgOut->addHTML( '
' ); + $wgOut->addHTML( '

' ); + wfMsg( 'edit-externally' ), "action=edit&externaledit=true&mode=file" ) ); + $wgOut->addWikiText( '
' . wfMsg('edit-externally-help') . '
' ); + $wgOut->addHTML( '' ); } - + function closeShowImage() { # For overloading - + } /** @@ -150,7 +315,7 @@ class ImagePage extends Article { */ function imageHistory() { - global $wgUser, $wgOut; + global $wgUser, $wgOut, $wgUseExternalEditor; $sk = $wgUser->getSkin(); @@ -159,33 +324,44 @@ class ImagePage extends Article { if ( $line ) { $list =& new ImageHistoryList( $sk ); $s = $list->beginImageHistoryList() . - $list->imageHistoryLine( true, $line->img_timestamp, + $list->imageHistoryLine( true, wfTimestamp(TS_MW, $line->img_timestamp), $this->mTitle->getDBkey(), $line->img_user, - $line->img_user_text, $line->img_size, $line->img_description ); + $line->img_user_text, $line->img_size, $line->img_description, + $line->img_width, $line->img_height + ); while ( $line = $this->img->nextHistoryLine() ) { $s .= $list->imageHistoryLine( false, $line->img_timestamp, - $line->oi_archive_name, $line->img_user, - $line->img_user_text, $line->img_size, $line->img_description ); + $line->oi_archive_name, $line->img_user, + $line->img_user_text, $line->img_size, $line->img_description, + $line->img_width, $line->img_height + ); } $s .= $list->endImageHistoryList(); } else { $s=''; } $wgOut->addHTML( $s ); + + # 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() ) { + $this->uploadLinksBox(); + } + } function imageLinks() { global $wgUser, $wgOut; - $wgOut->addHTML( '

' . wfMsg( 'imagelinks' ) . "

\n" ); + $wgOut->addHTML( '\n" ); $dbr =& wfGetDB( DB_SLAVE ); $page = $dbr->tableName( 'page' ); $imagelinks = $dbr->tableName( 'imagelinks' ); - + $sql = "SELECT page_namespace,page_title FROM $imagelinks,$page WHERE il_to=" . - $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=page_id" - . " LIMIT 500"; # quickie emergency brake + $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=page_id"; + $sql = $dbr->limitResult($sql, 500, 0); $res = $dbr->query( $sql, "ImagePage::imageLinks" ); if ( 0 == $dbr->numRows( $res ) ) { @@ -210,13 +386,16 @@ class ImagePage extends Article { $confirm = $wgRequest->getBool( 'wpConfirmB' ); $image = $wgRequest->getVal( 'image' ); $oldimage = $wgRequest->getVal( 'oldimage' ); - - # Only sysops can delete images. Previously ordinary users could delete + + # 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(); return; } + if ( $wgUser->isBlocked() ) { + return $this->blockedIPpage(); + } if ( wfReadOnly() ) { $wgOut->readOnlyPage(); return; @@ -229,7 +408,9 @@ class ImagePage extends Article { $wgOut->fatalError( wfMsg( 'cannotdelete' ) ); 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 ) ) { @@ -239,7 +420,7 @@ class ImagePage extends Article { } return; } - + if ( !is_null( $image ) ) { $q = '&image=' . urlencode( $image ); } else if ( !is_null( $oldimage ) ) { @@ -253,12 +434,12 @@ class ImagePage extends Article { function doDelete() { global $wgOut, $wgUser, $wgContLang, $wgRequest; - global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList; + global $wgUseSquid, $wgInternalServer, $wgPostCommitUpdateList; $fname = 'ImagePage::doDelete'; $reason = $wgRequest->getVal( 'wpReason' ); $oldimage = $wgRequest->getVal( 'oldimage' ); - + $dbw =& wfGetDB( DB_MASTER ); if ( !is_null( $oldimage ) ) { @@ -270,10 +451,15 @@ class ImagePage extends Article { $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) ); return; } + + # Invalidate description page cache + $this->mTitle->invalidateCache(); + # Squid purging if ( $wgUseSquid ) { $urlArr = Array( - $wgInternalServer.wfImageArchiveUrl( $oldimage ) + $wgInternalServer.wfImageArchiveUrl( $oldimage ), + $wgInternalServer.$this->mTitle->getFullURL() ); wfPurgeSquidServers($urlArr); } @@ -284,7 +470,7 @@ class ImagePage extends Article { $image = $this->mTitle->getDBkey(); $dest = wfImageDir( $image ); $archive = wfImageDir( $image ); - + # Delete the image file if it exists; due to sync problems # or manual trimming sometimes the file will be missing. $targetFile = "{$dest}/{$image}"; @@ -295,40 +481,36 @@ class ImagePage extends Article { } $dbw->delete( 'image', array( 'img_name' => $image ) ); $res = $dbw->select( 'oldimage', array( 'oi_archive_name' ), array( 'oi_name' => $image ) ); - - # Squid purging - if ( $wgUseSquid ) { - $urlArr = Array( - $wgInternalServer . Image::wfImageUrl( $image ) - ); - wfPurgeSquidServers($urlArr); - } - + # Purge archive URLs from the squid $urlArr = Array(); while ( $s = $dbw->fetchObject( $res ) ) { $this->doDeleteOldImage( $s->oi_archive_name ); $urlArr[] = $wgInternalServer.wfImageArchiveUrl( $s->oi_archive_name ); - } - - # Squid purging, part II + } + + # And also the HTML of all pages using this image + $linksTo = $this->img->getLinksTo(); if ( $wgUseSquid ) { - /* this needs to be done after LinksUpdate */ - $u = new SquidUpdate( $urlArr ); - array_push( $wgDeferredUpdateList, $u ); + $u = SquidUpdate::newFromTitles( $linksTo, $urlArr ); + array_push( $wgPostCommitUpdateList, $u ); } - + $dbw->delete( 'oldimage', array( 'oi_name' => $image ) ); # Image itself is now gone, and database is cleaned. # Now we remove the image description page. - $nt = Title::makeTitleSafe( NS_IMAGE, $image ); - $article = new Article( $nt ); + $article = new Article( $this->mTitle ); $article->doDeleteArticle( $reason ); # ignore errors - /* refresh image metadata cache */ - new Image( $image, true ); + # Invalidate parser cache and client cache for pages using this image + # This is left until relatively late to reduce lock time + Title::touchArray( $linksTo ); + + /* Delete thumbnails and refresh image metadata cache */ + $this->img->purgeCache(); + $deleted = $image; } @@ -336,15 +518,12 @@ class ImagePage extends Article { $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) ); $wgOut->setRobotpolicy( 'noindex,nofollow' ); - $sk = $wgUser->getSkin(); - $loglink = $sk->makeKnownLinkObj( - Title::makeTitle( NS_SPECIAL, 'Delete/log' ), - wfMsg( 'deletionlog' ) ); - + $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]'; $text = wfMsg( 'deletedtext', $deleted, $loglink ); - $wgOut->addHTML( '

' . $text . "

\n" ); - $wgOut->returnToMain( false ); + $wgOut->addWikiText( $text ); + + $wgOut->returnToMain( false, $this->mTitle->getPrefixedText() ); } function doDeleteOldImage( $oldimage ) @@ -353,7 +532,7 @@ class ImagePage extends Article { $name = substr( $oldimage, 15 ); $archive = wfImageArchiveDir( $name ); - + # Delete the image if it exists. Sometimes the file will be missing # due to manual intervention or weird sync problems; treat that # condition gracefully and continue to delete the database entry. @@ -399,10 +578,13 @@ class ImagePage extends Article { $wgOut->sysopRequired(); return; } + if ( $wgUser->isBlocked() ) { + return $this->blockedIPpage(); + } if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) { $wgOut->errorpage( 'internalerror', 'sessionfailure' ); return; - } + } $name = substr( $oldimage, 15 ); $dest = wfImageDir( $name ); @@ -414,10 +596,9 @@ class ImagePage extends Article { return; } $oldver = wfTimestampNow() . "!{$name}"; - + $dbr =& wfGetDB( DB_SLAVE ); - $size = $dbr->selectField( 'oldimage', 'oi_size', 'oi_archive_name=\'' . - $dbr->strencode( $oldimage ) . "'" ); + $size = $dbr->selectField( 'oldimage', 'oi_size', array( 'oi_archive_name' => $oldimage ) ); if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) { $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" ); @@ -426,25 +607,25 @@ class ImagePage extends Article { if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) { $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile ); } - wfRecordUpload( $name, $oldver, $size, wfMsg( "reverted" ) ); - /* refresh image metadata cache */ - new Image( $name, true ); - - # Squid purging - if ( $wgUseSquid ) { - $urlArr = Array( - $wgInternalServer.wfImageArchiveUrl( $name ), - $wgInternalServer . Image::wfImageUrl( $name ) - ); - wfPurgeSquidServers($urlArr); - } + # 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' ) ); - $wgOut->returnToMain( false ); + + $descTitle = $img->getTitle(); + $wgOut->returnToMain( false, $descTitle->getPrefixedText() ); + } + + function blockedIPpage() { + require_once( 'EditPage.php' ); + $edit = new EditPage( $this ); + return $edit->blockedIPpage(); } + } /** @@ -455,9 +636,9 @@ class ImageHistoryList { function ImageHistoryList( &$skin ) { $this->skin =& $skin; } - + function beginImageHistoryList() { - $s = "\n

" . wfMsg( 'imghistory' ) . "

\n" . + $s = "\n

" . wfMsg( 'imghistory' ) . "

\n" . "

" . wfMsg( 'imghistlegend' ) . "

\n".'