typo
[lhc/web/wiklou.git] / includes / ImagePage.php
index b3630fc..6e8d72b 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();
@@ -26,21 +29,21 @@ class ImagePage extends Article {
 
        function openShowImage()
        {
-               global $wgOut, $wgUser;
-               $name = $this->mTitle->getText();
-               $path = wfImagePath( $name );
-               $url   = wfImageUrl( $name );
+               global $wgOut, $wgUser,$wgRequest;
+               $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 .= "<center><img src=\"{$url}\" width=\"{$width}\" height=\"{$height}\"></center>";
+                               $s = "<div class=\"fullImage\">" .
+                                    "<img src=\"{$url}\" width=\"" . $this->img->getWidth() . "\" height=\"" . $this->img->getHeight() .
+                                    "\" alt=\"".$wgRequest->getVal( 'image' )."\" /></div>";
                        } else {
-                               $s .= "<center>".$sk->makeMediaLink($name,"")."</center>";
+                               $s = "<div class=\"fullMedia\">".$sk->makeMediaLink($this->img->getName(),"")."</div>";
                        }
                        $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,
+                 $this->mTitle->getDBkey(),  $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 );
@@ -100,10 +90,10 @@ class ImagePage extends Article {
                $res = wfQuery( $sql, DB_READ, "Article::imageLinks" );
 
                if ( 0 == wfNumRows( $res ) ) {
-                       $wgOut->addHtml( "<p>" . wfMsg( "nolinkstoimage" ) . "\n" );
+                       $wgOut->addHtml( "<p>" . wfMsg( "nolinkstoimage" ) . "</p>\n" );
                        return;
                }
-               $wgOut->addHTML( "<p>" . wfMsg( "linkstoimage" ) .  "\n<ul>" );
+               $wgOut->addHTML( "<p>" . wfMsg( "linkstoimage" ) .  "</p>\n<ul>" );
 
                $sk = $wgUser->getSkin();
                while ( $s = wfFetchObject( $res ) ) {
@@ -116,12 +106,14 @@ class ImagePage extends Article {
 
        function delete()
        {
-               global $wgUser, $wgOut;
-               global $wpConfirm, $wpReason, $image, $oldimage;
-
-               # Anybody can delete old revisions of images; only sysops
-               # can delete articles and current images
+               global $wgUser, $wgOut, $wgRequest;
 
+               $confirm = $wgRequest->getBool( 'wpConfirm' );
+               $image = $wgRequest->getVal( 'image' );
+               $oldimage = $wgRequest->getVal( 'oldimage' );
+               
+               # Only sysops can delete images. Previously ordinary users could delete 
+               # old revisions, but this is no longer the case.
                if ( !$wgUser->isSysop() ) {
                        $wgOut->sysopRequired();
                        return;
@@ -133,38 +125,43 @@ class ImagePage extends Article {
 
                # Better double-check that it hasn't been deleted yet!
                $wgOut->setPagetitle( wfMsg( "confirmdelete" ) );
-               if ( $image ) {
+               if ( !is_null( $image ) ) {
                        if ( "" == trim( $image ) ) {
                                $wgOut->fatalError( wfMsg( "cannotdelete" ) );
                                return;
                        }
                }
                
-               # Likewise, deleting old images doesn't require confirmation
-               if ( $oldimage || 1 == $wpConfirm ) {
+               # Deleting old images doesn't require confirmation
+               if ( !is_null( $oldimage ) || $confirm ) {
                        $this->doDelete();
                        return;
                }
                
-               if ( $image ) {
-                       $q = "&image={$image}";
-               } else if ( $oldimage ) {
-                       $q = "&oldimage={$oldimage}";
+               if ( !is_null( $image ) ) {
+                       $q = "&image=" . urlencode( $image );
+               } else if ( !is_null( $oldimage ) ) {
+                       $q = "&oldimage=" . urlencode( $oldimage );
+               } else {
+                       $q = "";
                }
-               return $this->confirmDelete( $q );
+               return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
        }
 
        function doDelete()
        {
-               global $wgOut, $wgUser, $wgLang;
-               global $image, $oldimage, $wpReason;
+               global $wgOut, $wgUser, $wgLang, $wgRequest;
                global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
                $fname = "Article::doDelete";
 
-               if ( $image ) {
+               $reason = $wgRequest->getVal( 'wpReason' );
+               $image = $wgRequest->getVal( 'image' );
+               $oldimage = $wgRequest->getVal( 'oldimage' );
+
+               if ( !is_null( $image ) ) {
                        $dest = wfImageDir( $image );
                        $archive = wfImageDir( $image );
-                       if ( ! unlink( "{$dest}/{$image}" ) ) {
+                       if ( ! @unlink( "{$dest}/{$image}" ) ) {
                                $wgOut->fileDeleteError( "{$dest}/{$image}" );
                                return;
                        }
@@ -179,7 +176,7 @@ class ImagePage extends Article {
                        # Squid purging
                        if ( $wgUseSquid ) {
                                $urlArr = Array(
-                                       $wgInternalServer.wfImageUrl( $image )
+                                       $wgInternalServer . Image::wfImageUrl( $image )
                                );
                                wfPurgeSquidServers($urlArr);
                        }
@@ -194,7 +191,7 @@ class ImagePage extends Article {
                        # Squid purging, part II
                        if ( $wgUseSquid ) {
                                /* this needs to be done after LinksUpdate */
-                               $u = new SquidUpdate($this->mTitle, $urlArr);
+                               $u = new SquidUpdate( $urlArr );
                                array_push( $wgDeferredUpdateList, $u );
                        }
                        
@@ -206,10 +203,11 @@ class ImagePage extends Article {
                        # Now we remove the image description page.
 
                        $nt = Title::newFromText( $wgLang->getNsText( Namespace::getImage() ) . ":" . $image );
-                       $this->doDeleteArticle( $nt );
+                       $article = new Article( $nt );
+                       $article->doDeleteArticle( $reason ); # ignore errors
 
                        $deleted = $image;
-               } else if ( $oldimage ) {
+               } else if ( !is_null( $oldimage ) ) {
                        # Squid purging
                        if ( $wgUseSquid ) {
                                $urlArr = Array(
@@ -224,7 +222,7 @@ class ImagePage extends Article {
 
                        $deleted = $oldimage;
                } else {
-                       $this->doDeleteArticle( $this->mTitle );
+                       $this->doDeleteArticle( $reason ); # ignore errors
                        $deleted = $this->mTitle->getPrefixedText();
                }
                $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
@@ -237,7 +235,7 @@ class ImagePage extends Article {
 
                $text = wfMsg( "deletedtext", $deleted, $loglink );
 
-               $wgOut->addHTML( "<p>" . $text );
+               $wgOut->addHTML( "<p>" . $text . "</p>\n" );
                $wgOut->returnToMain( false );
        }
 
@@ -254,10 +252,11 @@ class ImagePage extends Article {
 
        function revert()
        {
-               global $wgOut;
-               global $oldimage;
+               global $wgOut, $wgRequest;
                global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
 
+               $oldimage = $wgRequest->getText( 'oldimage' );
+               
                if ( strlen( $oldimage ) < 16 ) {
                        $wgOut->unexpectedValueError( "oldimage", $oldimage );
                        return;
@@ -292,7 +291,7 @@ class ImagePage extends Article {
                if ( $wgUseSquid ) {
                        $urlArr = Array(
                                $wgInternalServer.wfImageArchiveUrl( $name ),
-                               $wgInternalServer.wfImageUrl( $name )
+                               $wgInternalServer . Image::wfImageUrl( $name )
                        );
                        wfPurgeSquidServers($urlArr);
                }