From: Jens Frank Date: Sat, 8 May 2004 18:55:22 +0000 (+0000) Subject: Moved image history retrieval function to Image.php. X-Git-Tag: 1.3.0beta1~120 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=e434f7b9cdd6ad52ca5629ca5261fd3c92469611;p=lhc%2Fweb%2Fwiklou.git Moved image history retrieval function to Image.php. Variable names in Skin::imageHistoryLine() changed. --- diff --git a/includes/Image.php b/includes/Image.php index 9b01e7814a..f50e69baa9 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -11,6 +11,8 @@ class Image $url, # Image URL $title, # Title object for this image. Initialized when needed. $fileExists, # does the image file exist on disk? + $historyLine, # Number of line to return by nextHistoryLine() + $historyRes, # result of the query for the image's history $width, # \ $height, # --- returned by getimagesize, see http://de3.php.net/manual/en/function.getimagesize.php $type, # | @@ -34,6 +36,7 @@ class Image { list($this->width, $this->height, $this->type, $this->attr) = getimagesize( $this->imagePath ); } + $this->historyLine = 0; } function newFromTitle( $nt ) @@ -108,6 +111,12 @@ class Image return $width."px-".$this->name; } + //********************************************************************** + // Create a thumbnail of the image having the specified width. + // The thumbnail will not be created if the width is larger than the + // image's width. Let the browser do the scaling in this case. + // The thumbnail is stored on disk and is only computed if the thumbnail + // file does not exist OR if it is older than the image. function createThumb( $width ) { global $wgUploadDirectory; global $wgImageMagickConvertCommand; @@ -217,7 +226,47 @@ class Image } return $thumbUrl; - } //function createThumb + } // END OF function createThumb + + //********************************************************************** + // Return the image history of this image, line by line. + // start with current version, than old versions. + // use $this->historyLine to check which line to return: + // 0 return line for current version + // 1 query for old versions, return first one + // 2, ... return next old version from above query + function nextHistoryLine() + { + $fname = "Image::nextHistoryLine()"; + + if ( $this->historyLine == 0 ) // called for the first time, return line from cur + { + $sql = "SELECT img_size,img_description,img_user," . + "img_user_text,img_timestamp, '' AS oi_archive_name FROM image WHERE " . + "img_name='" . wfStrencode( $this->title->getDBkey() ) . "'"; + $this->historyRes = wfQuery( $sql, DB_READ, $fname ); + + if ( 0 == wfNumRows( $this->historyRes ) ) { return FALSE; } + + } else if ( $this->historyLine == 1 ) + { + $sql = "SELECT oi_size AS img_size, oi_description AS img_description," . + "oi_user AS img_user," . + "oi_user_text AS img_user_text, oi_timestamp AS img_timestamp , oi_archive_name FROM oldimage WHERE " . + "oi_name='" . wfStrencode( $this->title->getDBkey() ) . "' " . + "ORDER BY oi_timestamp DESC"; + $this->historyRes = wfQuery( $sql, DB_READ, $fname ); + } + $this->historyLine ++; + + return wfFetchObject( $this->historyRes ); + } + + function resetHistory() + { + $this->historyLine = 0; + } + } //class diff --git a/includes/ImagePage.php b/includes/ImagePage.php index eb6d3374ab..164abb5a37 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -6,6 +6,9 @@ class ImagePage extends Article { + /* private */ var $img; // Image object this page is shown for. Initilaized in openShowImage, not + // available in doDelete etc. + function view() { if ( Namespace::getImage() == $this->mTitle->getNamespace() ) { $this->openShowImage(); @@ -27,20 +30,20 @@ class ImagePage extends Article { function openShowImage() { global $wgOut, $wgUser,$wgRequest; - $img = Image::newFromTitle( $this->mTitle ); - $url = $img->getUrl(); + $this->img = Image::newFromTitle( $this->mTitle ); + $url = $this->img->getUrl(); - if ( $img->exists() ) { + if ( $this->img->exists() ) { $sk = $wgUser->getSkin(); - if ( $img->getType() != "" ) { + if ( $this->img->getType() != "" ) { # image $s = "
" . - "getWidth() . "\" height=\"" . $img->getHeight() . + "img->getWidth() . "\" height=\"" . $this->img->getHeight() . "\" alt=\"".$wgRequest->getVal( 'image' )."\" />
"; } else { - $s = "
".$sk->makeMediaLink($img->getName(),"")."
"; + $s = "
".$sk->makeMediaLink($this->img->getName(),"")."
"; } $wgOut->addHTML( $s ); } @@ -56,34 +59,21 @@ class ImagePage extends Article { function imageHistory() { - global $wgUser, $wgOut, $wgLang; - $fname = "Article::imageHistory"; - - $sql = "SELECT img_size,img_description,img_user," . - "img_user_text,img_timestamp FROM image WHERE " . - "img_name='" . wfStrencode( $this->mTitle->getDBkey() ) . "'"; - $res = wfQuery( $sql, DB_READ, $fname ); - - if ( 0 == wfNumRows( $res ) ) { return; } + global $wgUser, $wgOut; $sk = $wgUser->getSkin(); $s = $sk->beginImageHistoryList(); - $line = wfFetchObject( $res ); + $line = $this->img->nextHistoryLine(); + $s .= $sk->imageHistoryLine( true, $line->img_timestamp, $this->mTitle->getText(), $line->img_user, $line->img_user_text, $line->img_size, $line->img_description ); - $sql = "SELECT oi_size,oi_description,oi_user," . - "oi_user_text,oi_timestamp,oi_archive_name FROM oldimage WHERE " . - "oi_name='" . wfStrencode( $this->mTitle->getDBkey() ) . "' " . - "ORDER BY oi_timestamp DESC"; - $res = wfQuery( $sql, DB_READ, $fname ); - - while ( $line = wfFetchObject( $res ) ) { - $s .= $sk->imageHistoryLine( false, $line->oi_timestamp, - $line->oi_archive_name, $line->oi_user, - $line->oi_user_text, $line->oi_size, $line->oi_description ); + while ( $line = $this->img->nextHistoryLine() ) { + $s .= $sk->imageHistoryLine( false, $line->img_timestamp, + $line->oi_archive_name, $line->img_user, + $line->img_user_text, $line->img_size, $line->img_description ); } $s .= $sk->endImageHistoryList(); $wgOut->addHTML( $s ); diff --git a/includes/Skin.php b/includes/Skin.php index 2720affbee..13692961a7 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -2401,11 +2401,11 @@ class Skin { } - function imageHistoryLine( $iscur, $ts, $img, $u, $ut, $size, $c ) + function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description ) { global $wgUser, $wgLang, $wgTitle; - $dt = $wgLang->timeanddate( $ts, true ); + $datetime = $wgLang->timeanddate( $timestamp, true ); $del = wfMsg( "deleteimg" ); $cur = wfMsg( "cur" ); @@ -2425,10 +2425,10 @@ class Skin { $url = wfEscapeHTML( wfImageArchiveUrl( $img ) ); if( $wgUser->getID() != 0 ) { $rlink = $this->makeKnownLink( $wgTitle->getPrefixedText(), - wfMsg( "revertimg" ), "action=revert&oldimage=" . - urlencode( $img ) ); + wfMsg( "revertimg" ), "action=revert&oldimage=" . + urlencode( $img ) ); $dlink = $this->makeKnownLink( $wgTitle->getPrefixedText(), - $del, "action=delete&oldimage=" . urlencode( $img ) ); + $del, "action=delete&oldimage=" . urlencode( $img ) ); } else { # Having live active links for non-logged in users # means that bots and spiders crawling our site can @@ -2437,19 +2437,21 @@ class Skin { $dlink = $del; } } - if ( 0 == $u ) { $ul = $ut; } - else { $ul = $this->makeLink( $wgLang->getNsText( - Namespace::getUser() ) . ":{$ut}", $ut ); } - - $nb = wfMsg( "nbytes", $size ); - $style = $this->getInternalLinkAttributes( $url, $dt ); + if ( 0 == $user ) { + $userlink = $usertext; + } else { + $userlink = $this->makeLink( $wgLang->getNsText( Namespace::getUser() ) . + ":{$usertext}", $usertext ); + } + $nbytes = wfMsg( "nbytes", $size ); + $style = $this->getInternalLinkAttributes( $url, $datetime ); - $s = "
  • ({$dlink}) ({$rlink}) {$dt}" - . " . . {$ul} ({$nb})"; + $s = "
  • ({$dlink}) ({$rlink}) {$datetime}" + . " . . {$userlink} ({$nbytes})"; - if ( "" != $c && "*" != $c ) { + if ( "" != $description && "*" != $description ) { $sk=$wgUser->getSkin(); - $s .= $wgLang->emphasize(" (" . $sk->formatComment($c) . ")"); + $s .= $wgLang->emphasize(" (" . $sk->formatComment($description) . ")"); } $s .= "
  • \n"; return $s;