Fix bug: max-slave-length => max-slave-lag
[lhc/web/wiklou.git] / includes / ImagePage.php
index b3d2d42..002fc25 100644 (file)
@@ -38,7 +38,7 @@ class ImagePage extends Article {
        function render() {
                global $wgOut;
                $wgOut->setArticleBodyOnly( true );
-               $wgOut->addSecondaryWikitext( $this->getContent() );
+               $wgOut->addWikiTextTitleTidy( $this->getContent(), $this->mTitle );
        }
 
        function view() {
@@ -78,7 +78,7 @@ class ImagePage extends Article {
                if ( $this->mExtraDescription ) {
                        $fol = wfMsgNoTrans( 'shareddescriptionfollows' );
                        if( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) {
-                               $wgOut->addWikiMsg( $fol );
+                               $wgOut->addWikiText( $fol );
                        }
                        $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . '</div>' );
                }
@@ -346,19 +346,27 @@ EOT
                }
        }
 
+       /**
+        * Show a notice that the file is from a shared repository
+        */
        function printSharedImageText() {
                global $wgOut, $wgUser;
 
                $descUrl = $this->img->getDescriptionUrl();
                $descText = $this->img->getDescriptionText();
-               $s = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml("sharedupload");
-               if ( $descUrl && !$descText) {
+               $s = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml( 'sharedupload' );
+               if ( $descUrl ) {
                        $sk = $wgUser->getSkin();
-                       $link = $sk->makeExternalLink( $descUrl, wfMsg('shareduploadwiki-linktext') );
-                       $s .= " " . wfMsgWikiHtml('shareduploadwiki', $link);
+                       $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadwiki-linktext' ) );
+                       $msg = ( $descText ) ? 'shareduploadwiki-desc' : 'shareduploadwiki';
+                       $msg = wfMsgExt( $msg, array( 'parseinline', 'replaceafter' ), $link );
+                       if ( $msg != '-' ) {
+                               # Show message only if not voided by local sysops
+                               $s .= $msg;
+                       }
                }
                $s .= "</div>";
-               $wgOut->addHTML($s);
+               $wgOut->addHTML( $s );
 
                if ( $descText ) {
                        $this->mExtraDescription = $descText;
@@ -389,7 +397,11 @@ EOT
                        $ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );
                        $wgOut->addHtml( "<li><div class='plainlinks'>{$ulink}</div></li>" );
                }
-               
+
+               # Link to Special:FileDuplicateSearch
+               $dupeLink = $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'FileDuplicateSearch', $this->mTitle->getDBkey() ), wfMsgHtml( 'imagepage-searchdupe' ) );
+               $wgOut->addHtml( "<li>{$dupeLink}</li>" );
+
                # External editing link
                $elink = $sk->makeKnownLinkObj( $this->mTitle, wfMsgHtml( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );
                $wgOut->addHtml( '<li>' . $elink . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );
@@ -418,20 +430,12 @@ EOT
                        $file = $this->current;
                        $dims = $file->getDimensionsString();
                        $s = $list->beginImageHistoryList() .
-                               $list->imageHistoryLine( true, wfTimestamp(TS_MW, $file->getTimestamp()),
-                                       $this->mTitle->getDBkey(),  $file->getUser('id'),
-                                       $file->getUser('text'), $file->getSize(), $file->getDescription(),
-                                       $dims
-                               );
-
+                               $list->imageHistoryLine( true, $file );
+                       // old image versions
                        $hist = $this->img->getHistory();
                        foreach( $hist as $file ) {
                                $dims = $file->getDimensionsString();
-                               $s .= $list->imageHistoryLine( false, wfTimestamp(TS_MW, $file->getTimestamp()),
-                                       $file->getArchiveName(), $file->getUser('id'),
-                                       $file->getUser('text'), $file->getSize(), $file->getDescription(),
-                                       $dims
-                               );
+                               $s .= $list->imageHistoryLine( false, $file );
                        }
                        $s .= $list->endImageHistoryList();
                } else { $s=''; }
@@ -545,11 +549,12 @@ class ImageHistoryList {
 
        public function beginImageHistoryList() {
                global $wgOut, $wgUser;
+               $deleteColumn = $wgUser->isAllowed( 'delete' ) || $wgUser->isAllowed( 'deleterevision' );
                return Xml::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) )
                        . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
                        . Xml::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
                        . '<tr><td></td>'
-                       . ( $this->img->isLocal() && $wgUser->isAllowed( 'delete' ) ? '<td></td>' : '' )
+                       . ( $this->img->isLocal() && $deleteColumn ? '<td></td>' : '' )
                        . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
                        . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>'
                        . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
@@ -562,36 +567,55 @@ class ImageHistoryList {
                return "</table>\n";
        }
 
-       /**
-        * Create one row of file history
-        *
-        * @param bool $iscur is this the current file version?
-        * @param string $timestamp timestamp of file version
-        * @param string $img filename
-        * @param int $user ID of uploading user
-        * @param string $usertext username of uploading user
-        * @param int $size size of file version
-        * @param string $description description of file version
-        * @param string $dims dimensions of file version
-        * @return string a HTML formatted table row
-        */
-       public function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description, $dims ) {
-               global $wgUser, $wgLang, $wgContLang;
+       public function imageHistoryLine( $iscur, $file ) {
+               global $wgUser, $wgLang, $wgContLang, $wgTitle;
+               
+               $timestamp = wfTimestamp(TS_MW, $file->getTimestamp());
+               $img = $iscur ? $file->getName() : $file->getArchiveName();
+               $user = $file->getUser('id');
+               $usertext = $file->getUser('text');
+               $size = $file->getSize();
+               $description = $file->getDescription();
+               $dims = $file->getDimensionsString();
+               $sha1 = $file->getSha1();
+               
                $local = $this->img->isLocal();
                $row = '';
 
                // Deletion link
-               if( $local && $wgUser->isAllowed( 'delete' ) ) {
+               if( $local && ($wgUser->isAllowed('delete') || $wgUser->isAllowed('deleterevision') ) ) {
                        $row .= '<td>';
-                       $q = array();
-                       $q[] = 'action=delete';
-                       if( !$iscur )
-                               $q[] = 'oldimage=' . urlencode( $img );
-                       $row .= $this->skin->makeKnownLinkObj(
-                               $this->title,
-                               wfMsgHtml( $iscur ? 'filehist-deleteall' : 'filehist-deleteone' ),
-                               implode( '&', $q )
-                       );
+                       # Link to remove from history
+                       if( $wgUser->isAllowed( 'delete' ) ) {
+                               $q = array();
+                               $q[] = 'action=delete';
+                               if( !$iscur )
+                                       $q[] = 'oldimage=' . urlencode( $img );
+                               $row .= $this->skin->makeKnownLinkObj(
+                                       $this->title,
+                                       wfMsgHtml( $iscur ? 'filehist-deleteall' : 'filehist-deleteone' ),
+                                       implode( '&', $q )
+                               );
+                               $row .= '<br/>';
+                       }
+                       # Link to hide content
+                       if( $wgUser->isAllowed( 'deleterevision' ) ) {
+                               $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
+                               // If file is top revision or locked from this user, don't link
+                               if( $iscur || !$file->userCan(File::DELETED_RESTRICTED) ) {
+                                       $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( $file->isDeleted(File::DELETED_RESTRICTED) )
+                                               $del = "<strong>$del</strong>";
+                               }
+                               $row .= "<tt><small>$del</small></tt>";
+                       }
                        $row .= '</td>';
                }
 
@@ -600,32 +624,49 @@ class ImageHistoryList {
                if( $iscur ) {
                        $row .= wfMsgHtml( 'filehist-current' );
                } elseif( $local && $wgUser->isLoggedIn() && $this->title->userCan( 'edit' ) ) {
-                       $q = array();
-                       $q[] = 'action=revert';
-                       $q[] = 'oldimage=' . urlencode( $img );
-                       $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
-                       $row .= $this->skin->makeKnownLinkObj(
-                               $this->title,
-                               wfMsgHtml( 'filehist-revert' ),
-                               implode( '&', $q )
-                       );
+                       if( $file->isDeleted(File::DELETED_FILE) ) {
+                               $row .= wfMsgHtml('filehist-revert');
+                       } else {
+                               $q = array();
+                               $q[] = 'action=revert';
+                               $q[] = 'oldimage=' . urlencode( $img );
+                               $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) );
+                               $row .= $this->skin->makeKnownLinkObj( $this->title,
+                                       wfMsgHtml( 'filehist-revert' ),
+                                       implode( '&', $q ) );
+                       }
                }
                $row .= '</td>';
 
                // Date/time and image link
                $row .= '<td>';
-               $url = $iscur ? $this->img->getUrl() : $this->img->getArchiveUrl( $img );
-               $row .= Xml::element(
-                       'a',
-                       array( 'href' => $url ),
-                       $wgLang->timeAndDate( $timestamp, true )
-               );
+               if( !$file->userCan(File::DELETED_FILE) ) {
+                       # Don't link to unviewable files
+                       $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
+               } else if( $file->isDeleted(File::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 ) );
+               }
+
                $row .= '</td>';
 
                // Uploading user
                $row .= '<td>';
                if( $local ) {
-                       $row .= $this->skin->userLink( $user, $usertext ) . $this->skin->userToolLinks( $user, $usertext );
+                       // Hide deleted usernames
+                       if( $file->isDeleted(File::DELETED_USER) )
+                               $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
+                       else
+                               $row .= $this->skin->userLink( $user, $usertext ) . 
+                                       $this->skin->userToolLinks( $user, $usertext );
                } else {
                        $row .= htmlspecialchars( $usertext );
                }
@@ -637,10 +678,12 @@ class ImageHistoryList {
                // File size
                $row .= '<td class="mw-imagepage-filesize">' . $this->skin->formatSize( $size ) . '</td>';
 
-               // Comment
-               $row .= '<td>' . $this->skin->formatComment( $description, $this->title ) . '</td>';
+               // Don't show deleted descriptions
+               if ( $file->isDeleted(File::DELETED_COMMENT) )
+                       $row .= '<td><span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span></td>';
+               else
+                       $row .= '<td>' . $this->skin->commentBlock( $description, $this->title ) . '</td>';
 
                return "<tr>{$row}</tr>\n";
        }
-
 }