* It's not nice to throw sql errors with invalid input
[lhc/web/wiklou.git] / includes / ImagePage.php
index 531c59e..e68fbfa 100644 (file)
@@ -157,7 +157,7 @@ class ImagePage extends Article {
        }
 
        function openShowImage() {
-               global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang;
+               global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang;
 
                $full_url  = $this->img->getURL();
                $linkAttribs = false;
@@ -176,6 +176,7 @@ class ImagePage extends Article {
                $maxWidth = $max[0];
                $maxHeight = $max[1];
                $sk = $wgUser->getSkin();
+               $dirmark = $wgContLang->getDirMark();
 
                if ( $this->img->exists() ) {
                        # image
@@ -219,7 +220,7 @@ class ImagePage extends Article {
                                        }
                                        $msgbig  = wfMsgHtml( 'show-big-image' );
                                        $msgsmall = wfMsgExt( 'show-big-image-thumb',
-                                               array( 'parseinline' ), $width, $height );
+                                               array( 'parseinline' ), $wgLang->formatNum( $width ), $wgLang->formatNum( $height ) );
                                } else {
                                        # Image is small enough to show full size on image page
                                        $msgbig = htmlspecialchars( $this->img->getName() );
@@ -235,7 +236,7 @@ class ImagePage extends Article {
                                } else {
                                        $anchorclose .= 
                                                $msgsmall .
-                                               '<br />' . Xml::tags( 'a', $linkAttribs,  $msgbig ) . ' ' . $longDesc;
+                                               '<br />' . Xml::tags( 'a', $linkAttribs,  $msgbig ) . "$dirmark " . $longDesc;
                                }
 
                                if ( $this->img->isMultipage() ) {
@@ -308,8 +309,6 @@ class ImagePage extends Article {
                        if ($showLink) {
                                $filename = wfEscapeWikiText( $this->img->getName() );
 
-                               global $wgContLang;
-                               $dirmark = $wgContLang->getDirMark();
                                if (!$this->img->isSafeFile()) {
                                        $warning = wfMsg( 'mediawarning' );
                                        $wgOut->addWikiText( <<<EOT
@@ -416,23 +415,22 @@ EOT
 
                if ( $line ) {
                        $list = new ImageHistoryList( $sk, $this->img );
-                       // Our top image
                        $file = $this->repo->newFileFromRow( $line );
                        $dims = $file->getDimensionsString();
                        $s = $list->beginImageHistoryList() .
                                $list->imageHistoryLine( true, wfTimestamp(TS_MW, $line->img_timestamp),
-                                       $this->mTitle->getDBkey(), $line->img_user,
-                                       $line->img_user_text, $line->img_size, $line->img_description, $dims, 
-                                       $line->oi_deleted, $line->img_sha1
+                                       $this->mTitle->getDBkey(),  $line->img_user,
+                                       $line->img_user_text, $line->img_size, $line->img_description,
+                                       $dims
                                );
-                       // old image versions
+
                        while ( $line = $this->img->nextHistoryLine() ) {
                                $file = $this->repo->newFileFromRow( $line );
                                $dims = $file->getDimensionsString();
                                $s .= $list->imageHistoryLine( false, $line->oi_timestamp,
                                        $line->oi_archive_name, $line->oi_user,
                                        $line->oi_user_text, $line->oi_size, $line->oi_description,
-                                       $dims, $line->oi_deleted, $line->oi_sha1
+                                       $dims
                                );
                        }
                        $s .= $list->endImageHistoryList();
@@ -551,7 +549,7 @@ class ImageHistoryList {
                        . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
                        . Xml::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
                        . '<tr><td></td>'
-                       . ( $this->img->isLocal() && $wgUser->isAllowed( 'deleterevision' ) ? '<td></td>' : '' )
+                       . ( $this->img->isLocal() && $wgUser->isAllowed( 'delete' ) ? '<td></td>' : '' )
                        . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
                        . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
                        . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
@@ -564,48 +562,30 @@ class ImageHistoryList {
                return "</table>\n";
        }
 
-       public function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description, $dims,
-               $deleted, $sha1 ) {
-               global $wgUser, $wgLang, $wgContLang, $wgTitle;
+       public function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description, $dims ) {
+               global $wgUser, $wgLang, $wgContLang;
                $local = $this->img->isLocal();
-               $row = '<td>';
+               $row = '';
 
                // Deletion link
-               if( $iscur && $local && $wgUser->isAllowed( 'delete' ) ) {
+               if( $local && $wgUser->isAllowed( 'delete' ) ) {
+                       $row .= '<td>';
                        $q = array();
                        $q[] = 'action=delete';
-                       $q[] = 'image=' . $this->title->getPartialUrl();
+                       if( !$iscur )
+                               $q[] = 'oldimage=' . urlencode( $img );
                        $row .= '(' . $this->skin->makeKnownLinkObj(
                                $this->title,
                                wfMsgHtml( $iscur ? 'filehist-deleteall' : 'filehist-deleteone' ),
                                implode( '&', $q )
                        ) . ')';
-                       $row .= '</td><td>';
+                       $row .= '</td>';
                }
 
-               if( !$iscur && $local && $wgUser->isAllowed( 'deleterevision' ) ) {
-                       $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
-                       if( !$this->userCan($deleted,Image::DELETED_RESTRICTED) ) {
-                               // If file was hidden from sysops
-                               $del = wfMsgHtml( 'rev-delundel' );                     
-                       } else {
-                               // If the file was hidden, link to sha-1
-                               list($ts,$name) = explode('!',$img,2);
-                               $del = $this->skin->makeKnownLinkObj( $revdel,  wfMsg( 'rev-delundel' ),
-                                       'target=' . urlencode( $wgTitle->getPrefixedText() ) .
-                                       '&oldimage=' . urlencode( $ts ) );
-                               // Bolden oversighted content
-                               if( $this->isDeleted($deleted,Image::DELETED_RESTRICTED) )
-                                       $del = "<strong>$del</strong>";
-                       }
-                       $row .= "<tt>(<small>$del</small>)</tt></td><td> ";
-               }
-               
                // Reversion link/current indicator
+               $row .= '<td>';
                if( $iscur ) {
-                       $row .= ' (' . wfMsgHtml( 'filehist-current' ) . ')';
-               } elseif( $this->isDeleted($deleted,Image::DELETED_FILE) ) {
-                       $row .= '(' . wfMsgHtml('filehist-revert') . ')';
+                       $row .= '(' . wfMsgHtml( 'filehist-current' ) . ')';
                } elseif( $local && $wgUser->isLoggedIn() && $this->title->userCan( 'edit' ) ) {
                        $q = array();
                        $q[] = 'action=revert';
@@ -621,32 +601,18 @@ class ImageHistoryList {
 
                // Date/time and image link
                $row .= '<td>';
-               if( !$this->userCan($deleted,Image::DELETED_FILE) ) {
-                       # Don't link to unviewable files
-                       $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
-               } else if( $this->isDeleted($deleted,Image::DELETED_FILE) ) {
-                       $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
-                       # Make a link to review the image
-                       $url = $this->skin->makeKnownLinkObj( $revdel, $wgLang->timeAndDate( $timestamp, true ), 
-                               "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->img->getExtension() );
-                       $row .= '<span class="history-deleted">'.$url.'</span>';
-               } else {
-                       $url = $iscur ? $this->img->getUrl() : $this->img->getArchiveUrl( $img );
-                       $row .= Xml::element( 'a',
-                               array( 'href' => $url ),
-                               $wgLang->timeAndDate( $timestamp, true ) );
-               }
-
+               $url = $iscur ? $this->img->getUrl() : $this->img->getArchiveUrl( $img );
+               $row .= Xml::element(
+                       'a',
+                       array( 'href' => $url ),
+                       $wgLang->timeAndDate( $timestamp, true )
+               );
                $row .= '</td>';
 
                // Uploading user
                $row .= '<td>';
                if( $local ) {
-                       // Hide deleted usernames
-                       if( $this->isDeleted($deleted,Image::DELETED_USER) )
-                               $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
-                       else
-                               $row .= $this->skin->userLink( $user, $usertext ) . $this->skin->userToolLinks( $user, $usertext );
+                       $row .= $this->skin->userLink( $user, $usertext ) . $this->skin->userToolLinks( $user, $usertext );
                } else {
                        $row .= htmlspecialchars( $usertext );
                }
@@ -658,45 +624,10 @@ class ImageHistoryList {
                // File size
                $row .= '<td class="mw-imagepage-filesize">' . $this->skin->formatSize( $size ) . '</td>';
 
-               // Don't show deleted descriptions
-               if ( $this->isDeleted($deleted,Image::DELETED_COMMENT) )
-                       $row .= '<td><span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span></td>';
-               else
-                       $row .= '<td>' . $this->skin->commentBlock( $description, $this->title ) . '</td>';
+               // Comment
+               $row .= '<td>' . $this->skin->formatComment( $description, $this->title ) . '</td>';
 
                return "<tr>{$row}</tr>\n";
        }
-       
-       /**
-        * int $field one of DELETED_* bitfield constants
-        * for file or revision rows
-        * @param int $bitfield
-        * @param int $field
-        * @return bool
-        */
-       function isDeleted( $bitfield, $field ) {
-               return ($bitfield & $field) == $field;
-       }
-       
-       /**
-        * Determine if the current user is allowed to view a particular
-        * field of this FileStore image file, if it's marked as deleted.
-        * @param int $bitfield
-        * @param int $field
-        * @return bool
-        */
-       function userCan( $bitfield, $field ) {
-               if( ($bitfield & $field) == $field ) {
-               // images
-                       global $wgUser;
-                       $permission = ( $bitfield & File::DELETED_RESTRICTED ) == File::DELETED_RESTRICTED
-                               ? 'hiderevision'
-                               : 'deleterevision';
-                       wfDebug( "Checking for $permission due to $field match on $bitfield\n" );
-                       return $wgUser->isAllowed( $permission );
-               } else {
-                       return true;
-               }
-       }
 
 }