X-Git-Url: https://git.cyclocoop.org/admin/?a=blobdiff_plain;f=includes%2FImagePage.php;h=b1a03a77e9c5f8155a7eda271202fa2962e6cabc;hb=c7900e7c36bfaa9a402f611b7cb0444e6b53ff41;hp=be02750e3c7de95f0a24ccf0ccc99f9ab635b5d2;hpb=180876cc83bd98bafa05b321e579ea8abeee7946;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ImagePage.php b/includes/ImagePage.php index be02750e3c..b1a03a77e9 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -17,32 +17,107 @@ 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 + function view() { - if ( Namespace::getImage() == $this->mTitle->getNamespace() ) { - $this->openShowImage(); - } + global $wgUseExternalEditor, $wgOut, $wgShowEXIF; - Article::view(); - - # 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. + $this->img = new Image( $this->mTitle ); - if ( Namespace::getImage() == $this->mTitle->getNamespace() ) { + 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)); + + # 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(); + } + $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 | '. htmlspecialchars( wfMsg( 'metadata' ) ) . "\n"; + foreach( $exif as $k => $v ) { + $tag = strtolower( $k ); + $r .= "! class=$tag |" . wfMsg( "exif-$tag" ) . "\n"; + $r .= "| class=$tag |" . htmlspecialchars( $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; - $this->img = Image::newFromTitle( $this->mTitle ); + $wgUseImageResize, $wgRepositoryBaseUrl, + $wgUseExternalEditor, $wgServer; $full_url = $this->img->getViewURL(); $anchoropen = ''; $anchorclose = ''; @@ -58,16 +133,18 @@ class ImagePage extends Article { $max = $wgImageLimits[$sizeSel]; $maxWidth = $max[0]; $maxHeight = $max[1]; - + $sk = $wgUser->getSkin(); if ( $this->img->exists() ) { - - $sk = $wgUser->getSkin(); + # image + $width = $this->img->getWidth(); + $height = $this->img->getHeight(); + $showLink = false; - if ( $this->img->getType() != '' ) { + if ( $this->img->allowInlineDisplay() and $width and $height) { # image - $width = $this->img->getWidth(); - $height = $this->img->getHeight(); + + # "Download high res version" link below the image $msg = wfMsg('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) ); if ( $width > $maxWidth ) { $height = floor( $height * $maxWidth / $width ); @@ -77,17 +154,12 @@ class ImagePage extends Article { $width = floor( $width * $maxHeight / $height ); $height = $maxHeight; } - if ( $width != $this->img->getWidth() || $height != $this->img->getHeight() ) { + if ( !$this->img->mustRender() + && ( $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. + if ( $thumbnail == null ) { $url = $full_url; - $width = $this->img->getWidth(); - $height = $this->img->getHeight(); } else { $url = $thumbnail->getUrl(); } @@ -97,17 +169,60 @@ class ImagePage extends Article { $url = $full_url; } $anchoropen = ""; - $anchorclose = "
{$msg}
"; + $anchorclose = "
\n$anchoropen{$msg}"; } else { $url = $full_url; + $showLink = $this->img->mustRender(); } - $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 ($showLink) { + $s= $sk->makeMediaLink( $this->img->getName(), '', '', true ); + $info= wfMsg( 'fileinfo', ceil($this->img->getSize()/1024.0), $this->img->getMimeType() ); + + if (!$this->img->isSafeFile()) { + $wgOut->addHTML("
"); + $wgOut->addHTML(""); + $wgOut->addHTML($s); + $wgOut->addHTML(""); + + $wgOut->addHTML(" ("); + $wgOut->addWikiText( $info, false ); + $wgOut->addHTML(")"); + $wgOut->addHTML("
"); + + #this should be formated a little nicer. Is CSS sufficient? + $wgOut->addHTML("
"); + $wgOut->addWikiText( wfMsg( 'mediawarning' ) ); + $wgOut->addHTML('
'); + + } else { + $wgOut->addHTML("
"); + $wgOut->addHTML($s); + + $wgOut->addHTML(" ("); + $wgOut->addWikiText( $info, false ); + $wgOut->addHTML(")"); + + $wgOut->addHTML("
"); + } + } + if($this->img->fromSharedDirectory) { $sharedtext="
" . wfMsg("sharedupload"); if($wgRepositoryBaseUrl) { @@ -116,12 +231,37 @@ class ImagePage extends Article { $sharedtext.="
"; $wgOut->addWikiText($sharedtext); } + + } else { + # Image does not exist + $wgOut->addWikiText( wfMsg( 'noimage', $this->getUploadUrl() ) ); } } + function getUploadUrl() { + global $wgServer; + $uploadTitle = Title::makeTitle( NS_SPECIAL, 'Upload' ); + return $wgServer . $uploadTitle->getLocalUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) ); + } + + + function uploadLinksBox() + { + global $wgUser,$wgOut; + $sk = $wgUser->getSkin(); + $wgOut->addHTML( '
' ); + } + function closeShowImage() { # For overloading + } /** @@ -130,7 +270,7 @@ class ImagePage extends Article { */ function imageHistory() { - global $wgUser, $wgOut; + global $wgUser, $wgOut, $wgUseExternalEditor; $sk = $wgUser->getSkin(); @@ -151,13 +291,20 @@ class ImagePage extends Article { $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' ); @@ -166,7 +313,7 @@ class ImagePage extends Article { $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 - $res = $dbr->query( $sql, DB_SLAVE, "Article::imageLinks" ); + $res = $dbr->query( $sql, "ImagePage::imageLinks" ); if ( 0 == $dbr->numRows( $res ) ) { $wgOut->addHtml( '

' . wfMsg( "nolinkstoimage" ) . "

\n" ); @@ -187,7 +334,7 @@ class ImagePage extends Article { { global $wgUser, $wgOut, $wgRequest; - $confirm = $wgRequest->getBool( 'wpConfirm' ); + $confirm = $wgRequest->getBool( 'wpConfirmB' ); $image = $wgRequest->getVal( 'image' ); $oldimage = $wgRequest->getVal( 'oldimage' ); @@ -210,9 +357,15 @@ class ImagePage extends Article { return; } + $this->img = new Image( $this->mTitle ); + # Deleting old images doesn't require confirmation if ( !is_null( $oldimage ) || $confirm ) { - $this->doDelete(); + if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) { + $this->doDelete(); + } else { + $wgOut->fatalError( wfMsg( 'sessionfailure' ) ); + } return; } @@ -229,20 +382,32 @@ 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' ); - $image = $wgRequest->getVal( 'image' ); $oldimage = $wgRequest->getVal( 'oldimage' ); $dbw =& wfGetDB( DB_MASTER ); if ( !is_null( $oldimage ) ) { + if ( strlen( $oldimage ) < 16 ) { + $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) ); + return; + } + if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) { + $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); } @@ -250,9 +415,7 @@ class ImagePage extends Article { $dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) ); $deleted = $oldimage; } else { - if ( is_null ( $image ) ) { - $image = $this->mTitle->getDBkey(); - } + $image = $this->mTitle->getDBkey(); $dest = wfImageDir( $image ); $archive = wfImageDir( $image ); @@ -265,28 +428,20 @@ class ImagePage extends Article { return; } $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); - } - + $res = $dbw->select( 'oldimage', array( 'oi_archive_name' ), array( 'oi_name' => $image ) ); + # 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 ) ); @@ -294,10 +449,17 @@ class ImagePage extends Article { # Image itself is now gone, and database is cleaned. # Now we remove the image description page. - $nt = Title::newFromText( $wgContLang->getNsText( Namespace::getImage() ) . ":" . $image ); - $article = new Article( $nt ); + $article = new Article( $this->mTitle ); $article->doDeleteArticle( $reason ); # ignore errors + # 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; } @@ -305,14 +467,14 @@ class ImagePage extends Article { $wgOut->setRobotpolicy( 'noindex,nofollow' ); $sk = $wgUser->getSkin(); - $loglink = $sk->makeKnownLink( $wgContLang->getNsText( - Namespace::getWikipedia() ) . - ':' . wfMsg( 'dellogpage' ), wfMsg( 'deletionlog' ) ); + $loglink = $sk->makeKnownLinkObj( + Title::makeTitle( NS_SPECIAL, 'Log/delete' ), + wfMsg( 'deletionlog' ) ); $text = wfMsg( 'deletedtext', $deleted, $loglink ); $wgOut->addHTML( '

' . $text . "

\n" ); - $wgOut->returnToMain( false ); + $wgOut->returnToMain( false, $this->mTitle->getPrefixedText() ); } function doDeleteOldImage( $oldimage ) @@ -342,7 +504,7 @@ class ImagePage extends Article { function revert() { - global $wgOut, $wgRequest; + global $wgOut, $wgRequest, $wgUser; global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList; $oldimage = $wgRequest->getText( 'oldimage' ); @@ -359,7 +521,7 @@ class ImagePage extends Article { $wgOut->readOnlyPage(); return; } - if( $wgUser->getId() == 0 ) { + if( $wgUser->isAnon() ) { $wgOut->errorpage( 'uploadnologin', 'uploadnologintext' ); return; } @@ -367,6 +529,10 @@ class ImagePage extends Article { $wgOut->sysopRequired(); return; } + if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) { + $wgOut->errorpage( 'internalerror', 'sessionfailure' ); + return; + } $name = substr( $oldimage, 15 ); $dest = wfImageDir( $name ); @@ -380,8 +546,7 @@ class ImagePage extends Article { $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}" ); @@ -390,20 +555,17 @@ class ImagePage extends Article { if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) { $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile ); } - wfRecordUpload( $name, $oldver, $size, wfMsg( "reverted" ) ); - # 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() ); } } @@ -417,7 +579,7 @@ class ImageHistoryList { } function beginImageHistoryList() { - $s = "\n

" . wfMsg( 'imghistory' ) . "

\n" . + $s = "\n

" . wfMsg( 'imghistory' ) . "

\n" . "

" . wfMsg( 'imghistlegend' ) . "

\n".'