remove unused message
[lhc/web/wiklou.git] / includes / ImagePage.php
index 0e55156..7e87090 100644 (file)
@@ -7,7 +7,7 @@
  *
  */
 if( !defined( 'MEDIAWIKI' ) )
-       die( -1 );
+       die( 1 );
 
 require_once( 'Image.php' );
 
@@ -165,7 +165,8 @@ class ImagePage extends Article {
        }
 
        function openShowImage() {
-               global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgUseImageResize;
+               global $wgOut, $wgUser, $wgImageLimits, $wgRequest;
+               global $wgUseImageResize, $wgGenerateThumbnailOnParse;
 
                $full_url  = $this->img->getURL();
                $anchoropen = '';
@@ -213,7 +214,7 @@ class ImagePage extends Article {
                                        }
 
                                        if( $wgUseImageResize ) {
-                                               $thumbnail = $this->img->getThumbnail( $width );
+                                               $thumbnail = $this->img->getThumbnail( $width, -1, $wgGenerateThumbnailOnParse );
                                                if ( $thumbnail == null ) {
                                                        $url = $this->img->getViewURL();
                                                } else {
@@ -258,11 +259,13 @@ class ImagePage extends Article {
                                        ceil($this->img->getSize()/1024.0),
                                        $this->img->getMimeType() );
 
+                               global $wgContLang;
+                               $dirmark = $wgContLang->getDirMark();
                                if (!$this->img->isSafeFile()) {
                                        $warning = wfMsg( 'mediawarning' );
                                        $wgOut->addWikiText( <<<END
 <div class="fullMedia">
-<span class="dangerousLink">[[Media:$filename|$filename]]</span>
+<span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark
 <span class="fileInfo"> ($info)</span>
 </div>
 
@@ -272,7 +275,7 @@ END
                                } else {
                                        $wgOut->addWikiText( <<<END
 <div class="fullMedia">
-[[Media:$filename|$filename]] <span class="fileInfo"> ($info)</span>
+[[Media:$filename|$filename]]$dirmark <span class="fileInfo"> ($info)</span>
 </div>
 END
                                                );
@@ -324,24 +327,31 @@ END
                return $wgServer . $uploadTitle->getLocalUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) );
        }
 
-
-       function uploadLinksBox()
-       {
+       /**
+        * Print out the various links at the bottom of the image page, e.g. reupload,
+        * external editing (and instructions link) etc.
+        */
+       function uploadLinksBox() {
                global $wgUser, $wgOut;
 
-               if ($this->img->fromSharedDirectory)
+               if( $this->img->fromSharedDirectory )
                        return;
 
                $sk = $wgUser->getSkin();
-               $wgOut->addHTML( '<br /><ul>' );
+               
+               $wgOut->addHtml( '<br /><ul>' );
+               
+               # "Upload a new version of this file" link
                if( $wgUser->isAllowed( 'reupload' ) ) {
-                       $wgOut->addWikiText( "<li>\n<div>". wfMsg( 'uploadnewversion', $this->getUploadUrl() ) ."</div>\n</li>\n" );
-               }
-               $wgOut->addHTML( '<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>' );
+                       $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
+                       $wgOut->addHtml( "<li><div>{$ulink}</div></li>" );
+               }
+               
+               # External editing link
+               $elink = $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
+               $wgOut->addHtml( '<li>' . $elink . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );
+               
+               $wgOut->addHtml( '</ul>' );
        }
 
        function closeShowImage()
@@ -363,7 +373,7 @@ END
                $line = $this->img->nextHistoryLine();
 
                if ( $line ) {
-                       $list =& new ImageHistoryList( $sk );
+                       $list = new ImageHistoryList( $sk );
                        $s = $list->beginImageHistoryList() .
                                $list->imageHistoryLine( true, wfTimestamp(TS_MW, $line->img_timestamp),
                                        $this->mTitle->getDBkey(),  $line->img_user,
@@ -425,6 +435,7 @@ END
                global $wgUser, $wgOut, $wgRequest;
 
                $confirm = $wgRequest->wasPosted();
+               $reason = $wgRequest->getVal( 'wpReason' );
                $image = $wgRequest->getVal( 'image' );
                $oldimage = $wgRequest->getVal( 'oldimage' );
 
@@ -446,7 +457,7 @@ END
                $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
                if ( ( !is_null( $image ) )
                  && ( '' == trim( $image ) ) ) {
-                       $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
+                       $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
                        return;
                }
 
@@ -455,9 +466,9 @@ END
                # Deleting old images doesn't require confirmation
                if ( !is_null( $oldimage ) || $confirm ) {
                        if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
-                               $this->doDelete();
+                               $this->doDelete( $reason );
                        } else {
-                               $wgOut->fatalError( wfMsg( 'sessionfailure' ) );
+                               $wgOut->showFatalError( wfMsg( 'sessionfailure' ) );
                        }
                        return;
                }
@@ -472,88 +483,48 @@ END
                return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
        }
 
-       function doDelete()     {
-               global $wgOut, $wgRequest, $wgUseSquid, $wgInternalServer;
+       /*
+        * Delete an image.
+        * @param $reason User provided reason for deletion.
+        */
+       function doDelete( $reason ) {
+               global $wgOut, $wgRequest, $wgUseSquid;
                global $wgPostCommitUpdateList;
 
                $fname = 'ImagePage::doDelete';
 
-               $reason = $wgRequest->getVal( 'wpReason' );
                $oldimage = $wgRequest->getVal( 'oldimage' );
 
                $dbw =& wfGetDB( DB_MASTER );
 
                if ( !is_null( $oldimage ) ) {
                        if ( strlen( $oldimage ) < 16 ) {
-                               $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
+                               $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
                                return;
                        }
                        if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
-                               $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
+                               $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
                                return;
                        }
-
-                       # Invalidate description page cache
-                       $this->mTitle->invalidateCache();
-
-                       # Squid purging
-                       if ( $wgUseSquid ) {
-                               $urlArr = array(
-                                       $wgInternalServer.wfImageArchiveUrl( $oldimage ),
-                                       $this->mTitle->getInternalURL()
-                               );
-                               wfPurgeSquidServers($urlArr);
+                       if ( !$this->doDeleteOldImage( $oldimage ) ) {
+                               return;
                        }
-                       $this->doDeleteOldImage( $oldimage );
-                       $dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) );
                        $deleted = $oldimage;
                } else {
-                       $image = $this->mTitle->getDBkey();
-                       $dest = wfImageDir( $image );
-                       $archive = wfImageDir( $image );
-
-                       # Delete the image file if it exists; due to sync problems
-                       # or manual trimming sometimes the file will be missing.
-                       $targetFile = "{$dest}/{$image}";
-                       if( file_exists( $targetFile ) && ! @unlink( $targetFile ) ) {
+                       $ok = $this->img->delete( $reason );
+                       if( !$ok ) {
                                # If the deletion operation actually failed, bug out:
-                               $wgOut->fileDeleteError( $targetFile );
+                               $wgOut->showFileDeleteError( $this->img->getName() );
                                return;
                        }
-                       $dbw->delete( 'image', array( 'img_name' => $image ) );
-                       $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 );
-                       }
-
-                       # And also the HTML of all pages using this image
-                       $linksTo = $this->img->getLinksTo();
-                       if ( $wgUseSquid ) {
-                               $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.
-
+       
                        $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;
+                       $deleted = $this->img->getName();
                }
 
                $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
@@ -567,29 +538,24 @@ END
                $wgOut->returnToMain( false, $this->mTitle->getPrefixedText() );
        }
 
+       /**
+        * @return success
+        */
        function doDeleteOldImage( $oldimage )
        {
                global $wgOut;
 
-               $name = substr( $oldimage, 15 );
-               $archive = wfImageArchiveDir( $name );
-
-               # Delete the image if it exists. Sometimes the file will be missing
-               # due to manual intervention or weird sync problems; treat that
-               # condition gracefully and continue to delete the database entry.
-               # Also some records may end up with an empty oi_archive_name field
-               # if the original file was missing when a new upload was made;
-               # don't try to delete the directory then!
-               #
-               $targetFile = "{$archive}/{$oldimage}";
-               if( $oldimage != '' && file_exists( $targetFile ) && !@unlink( $targetFile ) ) {
+               $ok = $this->img->deleteOld( $oldimage, '' );
+               if( !$ok ) {
                        # If we actually have a file and can't delete it, throw an error.
-                       $wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
+                       # Something went awry...
+                       $wgOut->showFileDeleteError( "$oldimage" );
                } else {
                        # Log the deletion
                        $log = new LogPage( 'delete' );
                        $log->addEntry( 'delete', $this->mTitle, wfMsg('deletedrevision',$oldimage) );
                }
+               return $ok;
        }
 
        function revert() {
@@ -597,11 +563,11 @@ END
 
                $oldimage = $wgRequest->getText( 'oldimage' );
                if ( strlen( $oldimage ) < 16 ) {
-                       $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
+                       $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
                        return;
                }
                if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
-                       $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
+                       $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
                        return;
                }
 
@@ -610,7 +576,7 @@ END
                        return;
                }
                if( $wgUser->isAnon() ) {
-                       $wgOut->errorpage( 'uploadnologin', 'uploadnologintext' );
+                       $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
                        return;
                }
                if ( ! $this->mTitle->userCanEdit() ) {
@@ -621,7 +587,7 @@ END
                        return $this->blockedIPpage();
                }
                if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
-                       $wgOut->errorpage( 'internalerror', 'sessionfailure' );
+                       $wgOut->showErrorPage( 'internalerror', 'sessionfailure' );
                        return;
                }
                $name = substr( $oldimage, 15 );
@@ -630,8 +596,11 @@ END
                $archive = wfImageArchiveDir( $name );
                $curfile = "{$dest}/{$name}";
 
+               if ( !is_dir( $dest ) ) wfMkdirParents( $dest );
+               if ( !is_dir( $archive ) ) wfMkdirParents( $archive );
+
                if ( ! is_file( $curfile ) ) {
-                       $wgOut->fileNotFoundError( htmlspecialchars( $curfile ) );
+                       $wgOut->showFileNotFoundError( htmlspecialchars( $curfile ) );
                        return;
                }
                $oldver = wfTimestampNow() . "!{$name}";
@@ -640,11 +609,12 @@ END
                $size = $dbr->selectField( 'oldimage', 'oi_size', array( 'oi_archive_name' => $oldimage )  );
 
                if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
-                       $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
+                       $wgOut->showFileRenameError( $curfile, "${archive}/{$oldver}" );
                        return;
                }
                if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
-                       $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile );
+                       $wgOut->showFileCopyError( "${archive}/{$oldimage}", $curfile );
+                       return;
                }
 
                # Record upload and update metadata cache
@@ -660,7 +630,6 @@ END
        }
 
        function blockedIPpage() {
-               require_once( 'EditPage.php' );
                $edit = new EditPage( $this );
                return $edit->blockedIPpage();
        }
@@ -672,8 +641,8 @@ END
                $this->img = new Image( $this->mTitle );
                if( $this->img->exists() ) {
                        wfDebug( "ImagePage::doPurge purging " . $this->img->getName() . "\n" );
-                       $linksTo = $this->img->getLinksTo();
-                       Title::touchArray( $linksTo );
+                       $update = new HTMLCacheUpdate( $this->mTitle, 'imagelinks' );
+                       $update->doUpdate();
                        $this->img->purgeCache();
                } else {
                        wfDebug( "ImagePage::doPurge no image\n" );
@@ -741,18 +710,14 @@ class ImageHistoryList {
                                $dlink = $del;
                        }
                }
-               if ( 0 == $user ) {
-                       $userlink = $usertext;
-               } else {
-                       $userlink = $this->skin->makeLinkObj( Title::makeTitle( NS_USER, $usertext ), $usertext );
-                       $usertalk = $this->skin->makeLinkObj( Title::makeTitle( NS_USER_TALK, $usertext), $wgContLang->getNsText( NS_TALK ) );
-                       $userdata = $userlink . ' (' . $usertalk . ')';
-               }
-               $nbytes = wfMsg( 'nbytes', $size );
+               
+               $userlink = $this->skin->userLink( $user, $usertext ) . $this->skin->userToolLinks( $user, $usertext );
+               $nbytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
+                       $wgLang->formatNum( $size ) );
                $widthheight = wfMsg( 'widthheight', $width, $height );
                $style = $this->skin->getInternalLinkAttributes( $url, $datetime );
 
-               $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a> . . {$userdata} . . {$widthheight} ({$nbytes})";
+               $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a> . . {$userlink} . . {$widthheight} ({$nbytes})";
 
                $s .= $this->skin->commentBlock( $description, $wgTitle );
                $s .= "</li>\n";