*/
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() {
- global $wgUseExternalEditor;
- if( $this->mTitle->getNamespace() == NS_IMAGE ) {
- $this->openShowImage();
- }
+ global $wgUseExternalEditor, $wgOut ;
- 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.
+ $this->img = new Image( $this->mTitle );
- if( $this->mTitle->getNamespace() == NS_IMAGE ) {
+ if( $this->mTitle->getNamespace() == NS_IMAGE ) {
+ if( $this->img->exists() ) {
+ $this->showTOC();
+ }
+ $this->openShowImage();
+
+ # 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();
+ if( $this->img->exists() ) {
+ $this->showEXIFdata();
+ }
+ } else {
+ Article::view();
+ }
+ }
+
+ function showTOC() {
+ global $wgOut, $wgShowEXIF, $wgLang;
+
+ $r= '<div class="imagepagetoc"><table class="toc"><tr><td><b>'.htmlspecialchars( wfMsg( 'toc' )) .'</b><br />';
+ $r .= '<a href="#toc">' . htmlspecialchars( $wgLang->getNStext( NS_IMAGE ) ) . '</a> - ';
+ $r .= '<a href="#imghistory">' . htmlspecialchars( wfMsg( 'imghistory' ) ) . '</a> - ';
+ $r .= '<a href="#imagelinks">' . htmlspecialchars( wfMsg( 'imagelinks' ) ) . '</a>';
+ if ( $wgShowEXIF ) {
+ $r .= ' - <a href="#exifdata">' . htmlspecialchars( wfMsg( 'exifdata' ) ) . '</a>';
}
+
+
+ $wgOut->addHTML( $r . '</td></tr></table></div>' );
+
+ }
+
+ function showEXIFdata() {
+ global $wgOut, $wgShowEXIF;
+ if( !$wgShowEXIF ) {
+ return;
+ }
+
+ # Get the EXIF data
+ $exif = $this->img->getExifData();
+ if( count ( $exif ) == 0 ) {
+ return; # No EXIF data available
+ }
+
+ # Create the table
+ $r = '<h2 id="exifdata">'. htmlspecialchars( wfMsg( 'exifdata' ) ) . "</h2>\n";
+ $r .= "<table class=\"exif\">\n" ;
+ $n = 0;
+ foreach( $exif as $k => $v ) {
+ if( $n % 2 == 0 ) {
+ $r .= '<tr>';
+ }
+ $r .= '<th>' . wfMsg( 'exif-' . strtolower( $k ) ) . "</th>\n";
+ $r .= '<td>' . htmlspecialchars( $v ) . "</td>\n";
+ if ( $n % 2 == 1 ) {
+ $r .= "</tr>\n";
+ } else {
+ $r .= "<td class='spacer'> </td>\n";
+ }
+ $n++;
+ }
+ if ( $n % 2 == 1 ) {
+ $r .= "<th></th><td></td></tr>\n";
+ }
+
+ $wgOut->addHTML( $r . "</table>\n" );
}
function openShowImage()
{
global $wgOut, $wgUser, $wgImageLimits, $wgRequest,
$wgUseImageResize, $wgRepositoryBaseUrl,
- $wgUseExternalEditor;
- $this->img = Image::newFromTitle( $this->mTitle );
+ $wgUseExternalEditor, $wgServer;
$full_url = $this->img->getViewURL();
$anchoropen = '';
$anchorclose = '';
$max = $wgImageLimits[$sizeSel];
$maxWidth = $max[0];
$maxHeight = $max[1];
-
+ $sk = $wgUser->getSkin();
if ( $this->img->exists() ) {
-
- $sk = $wgUser->getSkin();
-
if ( $this->img->getType() != '' ) {
# 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 );
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();
- } 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.
$wgOut->addWikiText($sharedtext);
}
+ } else {
+ # Image does not exist
+ $wgOut->addWikiText( wfMsg( 'noimage', $this->getUploadUrl() ) );
}
}
- function externalEditorLink()
+ 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("<div class=\"editExternally\">");
- $wgOut->addHTML($sk->makeKnownLink($this->mTitle->getPrefixedDBkey(),wfMsg("edit-externally"),
- "action=edit&externaledit=true&mode=file"));
- $wgOut->addWikiText("<div class=\"editExternallyHelp\">".wfMsg("edit-externally-help"));
- $wgOut->addHTML("</div><br clear=\"all\">");
-
+ $wgOut->addHTML( '<br /><ul><li>' );
+ $wgOut->addWikiText( '<div>'. wfMsg( 'uploadnewversion', $this->getUploadUrl() ) .'</div>' );
+ $wgOut->addHTML( '</li><li>' );
+ $wgOut->addHTML( $sk->makeKnownLinkObj( $this->mTitle,
+ wfMsg( 'edit-externally' ), "action=edit&externaledit=true&mode=file" ) );
+ $wgOut->addWikiText( '<div>' . wfMsg('edit-externally-help') . '</div>' );
+ $wgOut->addHTML( '</li></ul>' );
}
+
function closeShowImage()
{
# For overloading
*/
function imageHistory()
{
- global $wgUser, $wgOut;
+ global $wgUser, $wgOut, $wgUseExternalEditor;
$sk = $wgUser->getSkin();
$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( '<h2>' . wfMsg( 'imagelinks' ) . "</h2>\n" );
+ $wgOut->addHTML( '<h2 id="imagelinks">' . wfMsg( 'imagelinks' ) . "</h2>\n" );
$dbr =& wfGetDB( DB_SLAVE );
$page = $dbr->tableName( 'page' );
$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( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
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 ) ) {
function doDelete()
{
global $wgOut, $wgUser, $wgContLang, $wgRequest;
- global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
+ global $wgUseSquid, $wgInternalServer, $wgPostCommitUpdateList;
$fname = 'ImagePage::doDelete';
$reason = $wgRequest->getVal( 'wpReason' );
$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);
}
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 ) );
# 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;
}
$sk = $wgUser->getSkin();
$loglink = $sk->makeKnownLinkObj(
- Title::makeTitle( NS_SPECIAL, 'Delete/log' ),
+ Title::makeTitle( NS_SPECIAL, 'Log/delete' ),
wfMsg( 'deletionlog' ) );
$text = wfMsg( 'deletedtext', $deleted, $loglink );
$wgOut->addHTML( '<p>' . $text . "</p>\n" );
- $wgOut->returnToMain( false );
+ $wgOut->returnToMain( false, $this->mTitle->getPrefixedText() );
}
function doDeleteOldImage( $oldimage )
$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}" );
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 beginImageHistoryList() {
- $s = "\n<h2>" . wfMsg( 'imghistory' ) . "</h2>\n" .
+ $s = "\n<h2 id=\"imghistory\">" . wfMsg( 'imghistory' ) . "</h2>\n" .
"<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
return $s;
}
$cur = wfMsg( 'cur' );
if ( $iscur ) {
- $url = Image::wfImageUrl( $img );
+ $url = Image::imageUrl( $img );
$rlink = $cur;
if ( $wgUser->isAllowed('delete') ) {
$link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() .
$url = htmlspecialchars( wfImageArchiveUrl( $img ) );
if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
$token = urlencode( $wgUser->editToken( $img ) );
- $rlink = $this->skin->makeKnownLink( $wgTitle->getPrefixedText(),
+ $rlink = $this->skin->makeKnownLinkObj( $wgTitle,
wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
urlencode( $img ) . "&wpEditToken=$token" );
- $dlink = $this->skin->makeKnownLink( $wgTitle->getPrefixedText(),
+ $dlink = $this->skin->makeKnownLinkObj( $wgTitle,
$del, 'action=delete&oldimage=' . urlencode( $img ) .
"&wpEditToken=$token" );
} else {