Moved image history retrieval function to Image.php.
[lhc/web/wiklou.git] / includes / ImagePage.php
index c805667..164abb5 100644 (file)
@@ -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,21 +30,20 @@ class ImagePage extends Article {
        function openShowImage()
        {
                global $wgOut, $wgUser,$wgRequest;
-               $name = $this->mTitle->getText();
-               $path = wfImagePath( $name );
-               $url   = wfImageUrl( $name );
+               $this->img  = Image::newFromTitle( $this->mTitle );
+               $url  = $this->img->getUrl();
 
-               if ( file_exists( $path ) ) {
-                       list($width, $height, $type, $attr) = getimagesize( $path );
+               if ( $this->img->exists() ) {
 
                        $sk = $wgUser->getSkin();
                        
-                       if ( $type != "" ) {
+                       if ( $this->img->getType() != "" ) {
                                # image
-                               $s = "<span style=\"text-align: center\"><img src=\"{$url}\" width=\"{$width}\" height=\"{$height}\"".
-                               "alt=\"".$wgRequest->getVal( 'image' )."\" /></span>";
+                               $s = "<div class=\"fullImage\">" .
+                                    "<img src=\"{$url}\" width=\"" . $this->img->getWidth() . "\" height=\"" . $this->img->getHeight() .
+                                    "\" alt=\"".$wgRequest->getVal( 'image' )."\" /></div>";
                        } else {
-                               $s = "<span style=\"text-align: center\">".$sk->makeMediaLink($name,"")."</span>";
+                               $s = "<div class=\"fullMedia\">".$sk->makeMediaLink($this->img->getName(),"")."</div>";
                        }
                        $wgOut->addHTML( $s );
                }
@@ -57,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 );
@@ -187,7 +176,7 @@ class ImagePage extends Article {
                        # Squid purging
                        if ( $wgUseSquid ) {
                                $urlArr = Array(
-                                       $wgInternalServer.wfImageUrl( $image )
+                                       $wgInternalServer . Image::wfImageUrl( $image )
                                );
                                wfPurgeSquidServers($urlArr);
                        }
@@ -302,7 +291,7 @@ class ImagePage extends Article {
                if ( $wgUseSquid ) {
                        $urlArr = Array(
                                $wgInternalServer.wfImageArchiveUrl( $name ),
-                               $wgInternalServer.wfImageUrl( $name )
+                               $wgInternalServer . Image::wfImageUrl( $name )
                        );
                        wfPurgeSquidServers($urlArr);
                }