Stabilize image description links
authorAaron Schulz <aaron@users.mediawiki.org>
Mon, 19 May 2008 18:55:48 +0000 (18:55 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Mon, 19 May 2008 18:55:48 +0000 (18:55 +0000)
includes/ImageGallery.php
includes/ImagePage.php
includes/Linker.php
includes/MediaTransformOutput.php
includes/Parser.php
skins/common/shared.css

index 150fe03..a2c167b 100644 (file)
@@ -242,8 +242,8 @@ class ImageGallery
                        $text = $pair[1];
 
                        # Give extensions a chance to select the file revision for us
-                       $time = false;
-                       wfRunHooks( 'BeforeGalleryFindFile', array( &$this, &$nt, &$time ) );
+                       $time = $descQuery = false;
+                       wfRunHooks( 'BeforeGalleryFindFile', array( &$this, &$nt, &$time, &$descQuery ) );
 
                        $img = wfFindFile( $nt, $time );
 
@@ -268,7 +268,7 @@ class ImageGallery
                                        # handlers since they may emit block-level elements as opposed to simple <img> tags.
                                        # ref http://css-discuss.incutio.com/?page=CenteringBlockElement
                                        . '<div style="margin-left: auto; margin-right: auto; width: ' .$this->mWidths.'px;">'
-                                       . $thumb->toHtml( array( 'desc-link' => true ) ) . '</div></div>';
+                                       . $thumb->toHtml( array( 'desc-link' => true, 'desc-query' => $descQuery ) ) . '</div></div>';
 
                                // Call parser transform hook
                                if ( $this->mParser && $img->getHandler() ) {
index 86ba8cb..7aaab02 100644 (file)
@@ -22,6 +22,10 @@ class ImagePage extends Article {
 
        function __construct( $title, $time = false ) {
                parent::__construct( $title );
+
+               global $wgRequest;
+               $time = $time ? $time : $wgRequest->getVal( 'filetimestamp' );
+
                $this->img = wfFindFile( $this->mTitle, $time );
                if ( !$this->img ) {
                        $this->img = wfLocalFile( $this->mTitle );
@@ -561,7 +565,7 @@ EOT
                $sk = $wgUser->getSkin();
 
                if ( $this->img->exists() ) {
-                       $list = new ImageHistoryList( $sk, $this->current );
+                       $list = new ImageHistoryList( $sk, $this->current, $this->img );
                        $file = $this->current;
                        $dims = $file->getDimensionsString();
                        $s = $list->beginImageHistoryList();
@@ -729,8 +733,9 @@ class ImageHistoryList {
 
        protected $img, $skin, $title, $repo;
 
-       public function __construct( $skin, $img ) {
+       public function __construct( $skin, $curimg, $img ) {
                $this->skin = $skin;
+               $this->current = $curimg;
                $this->img = $img;
                $this->title = $img->getTitle();
        }
@@ -741,7 +746,7 @@ class ImageHistoryList {
                        . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) )
                        . Xml::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n"
                        . '<tr><td></td>'
-                       . ( $this->img->isLocal() && ($wgUser->isAllowed('delete') || $wgUser->isAllowed('deleterevision') ) ? '<td></td>' : '' )
+                       . ( $this->current->isLocal() && ($wgUser->isAllowed('delete') || $wgUser->isAllowed('deleterevision') ) ? '<td></td>' : '' )
                        . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
                        . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
                        . '<th>' . wfMsgHtml( 'filehist-user' ) . '</th>' 
@@ -765,8 +770,8 @@ class ImageHistoryList {
                $dims = $file->getDimensionsString();
                $sha1 = $file->getSha1();
 
-               $local = $this->img->isLocal();
-               $row = $css = '';
+               $local = $this->current->isLocal();
+               $row = $css = $selected = '';
 
                // Deletion link
                if( $local && ($wgUser->isAllowed('delete') || $wgUser->isAllowed('deleterevision') ) ) {
@@ -827,7 +832,10 @@ class ImageHistoryList {
                $row .= '</td>';
 
                // Date/time and image link
-               $row .= "<td style='white-space: nowrap;'>";
+               if( $file->getTimestamp() === $this->img->getTimestamp() ) {
+                       $selected = "class='filehistory-selected'";
+               }
+               $row .= "<td $selected style='white-space: nowrap;'>";
                if( !$file->userCan(File::DELETED_FILE) ) {
                        # Don't link to unviewable files
                        $row .= '<span class="history-deleted">' . $wgLang->timeAndDate( $timestamp, true ) . '</span>';
@@ -835,10 +843,10 @@ class ImageHistoryList {
                        $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() );
+                               "target=".$wgTitle->getPrefixedText()."&file=$sha1.".$this->current->getExtension() );
                        $row .= '<span class="history-deleted">'.$url.'</span>';
                } else {
-                       $url = $iscur ? $this->img->getUrl() : $this->img->getArchiveUrl( $img );
+                       $url = $iscur ? $this->current->getUrl() : $this->current->getArchiveUrl( $img );
                        $row .= Xml::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) );
                }
 
@@ -874,8 +882,8 @@ class ImageHistoryList {
                $row .= '</td>';
 
                wfRunHooks( 'ImagePageFileHistoryLine', array( &$file, &$row, &$css ) );
-               $tagCSS = $css ? " class='$css'" : "";
-               return "<tr{$tagCSS}>{$row}</tr>\n";
+               $trCSS = $css ? " class='$css'" : "";
+
+               return "<tr{$trCSS}>{$row}</tr>\n";
        }
 }
index a2d48c6..a30190c 100644 (file)
@@ -511,9 +511,10 @@ class Linker {
         * @param array $handlerParams Associative array of media handler parameters, to be passed
         *       to transform(). Typical keys are "width" and "page".
         * @param string $time, timestamp of the file, set as false for current
+        * @param string $query, query params for desc url
         * @return string HTML for an image, with links, wrappers, etc.
         */
-       function makeImageLink2( Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false ) {
+       function makeImageLink2( Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "" ) {
                $res = null;
                if( !wfRunHooks( 'ImageBeforeProduceHTML', array( &$this, &$title,
                &$file, &$frameParams, &$handlerParams, &$time, &$res ) ) ) {
@@ -580,7 +581,7 @@ class Linker {
                        if ( $fp['align'] == '' ) {
                                $fp['align'] = $wgContLang->isRTL() ? 'left' : 'right';
                        }
-                       return $prefix.$this->makeThumbLink2( $title, $file, $fp, $hp, $time ).$postfix;
+                       return $prefix.$this->makeThumbLink2( $title, $file, $fp, $hp, $time, $query ).$postfix;
                }
 
                if ( $file && isset( $fp['frameless'] ) ) {
@@ -604,6 +605,7 @@ class Linker {
                } else {
                        $s = $thumb->toHtml( array(
                                'desc-link' => true,
+                               'desc-query' => $query,
                                'alt' => $fp['alt'],
                                'valign' => isset( $fp['valign'] ) ? $fp['valign'] : false ,
                                'img-class' => isset( $fp['border'] ) ? 'thumbborder' : false ) );
@@ -630,7 +632,7 @@ class Linker {
                return $this->makeThumbLink2( $title, $file, $frameParams, $params );
        }
 
-       function makeThumbLink2( Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false ) {
+       function makeThumbLink2( Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "" ) {
                global $wgStylePath, $wgContLang;
                $exists = $file && $file->exists();
 
@@ -683,7 +685,9 @@ class Linker {
                        }
                }
 
-               $query = $page ? 'page=' . urlencode( $page ) : '';
+               if( $page ) {
+                       $query = $query ? '&page=' . urlencode( $page ) : 'page=' . urlencode( $page );
+               }
                $url = $title->getLocalURL( $query );
 
                $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
@@ -699,7 +703,8 @@ class Linker {
                        $s .= $thumb->toHtml( array(
                                'alt' => $fp['alt'],
                                'img-class' => 'thumbimage',
-                               'desc-link' => true ) );
+                               'desc-link' => true,
+                               'desc-query' => $query ) );
                        if ( isset( $fp['framed'] ) ) {
                                $zoomicon="";
                        } else {
index 1c1f403..bd53a16 100644 (file)
@@ -74,8 +74,11 @@ abstract class MediaTransformOutput {
                }
        }
 
-       function getDescLinkAttribs( $alt = false ) {
+       function getDescLinkAttribs( $alt = false, $params = '' ) {
                $query = $this->page ? ( 'page=' . urlencode( $this->page ) ) : '';
+               if( $params ) {
+                       $query .= $query ? '&'.$params : $params;
+               }
                $title = $this->file->getTitle();
                if ( strval( $alt ) === '' ) {
                        $alt = $title->getText();
@@ -125,6 +128,7 @@ class ThumbnailImage extends MediaTransformOutput {
         *     file-link    Boolean, show a file download link
         *     valign       vertical-align property, if the output is an inline element
         *     img-class    Class applied to the <img> tag, if there is such a tag
+        *     desc-query   String, description link query params
         *
         * For images, desc-link and file-link are implemented as a click-through. For
         * sounds and videos, they may be displayed in other ways.
@@ -138,8 +142,9 @@ class ThumbnailImage extends MediaTransformOutput {
                }
 
                $alt = empty( $options['alt'] ) ? '' : $options['alt'];
+               $query = empty($options['desc-query'])  ? '' : $options['desc-query'];
                if ( !empty( $options['desc-link'] ) ) {
-                       $linkAttribs = $this->getDescLinkAttribs( $alt );
+                       $linkAttribs = $this->getDescLinkAttribs( $alt, $query );
                } elseif ( !empty( $options['file-link'] ) ) {
                        $linkAttribs = array( 'href' => $this->file->getURL() );
                } else {
index 94a95d5..23f29ef 100644 (file)
@@ -4443,8 +4443,8 @@ class Parser
                $sk = $this->mOptions->getSkin();
 
                # Give extensions a chance to select the file revision for us
-               $skip = $time = false;
-               wfRunHooks( 'BeforeParserMakeImageLinkObj', array( &$this, &$title, &$skip, &$time ) );
+               $skip = $time = $descQuery = false;
+               wfRunHooks( 'BeforeParserMakeImageLinkObj', array( &$this, &$title, &$skip, &$time, &$descQuery ) );
 
                if ( $skip ) {
                        return $sk->makeLinkObj( $title );
@@ -4540,7 +4540,7 @@ class Parser
                wfRunHooks( 'ParserMakeImageParams', array( $title, $file, &$params ) );
 
                # Linker does the rest
-               $ret = $sk->makeImageLink2( $title, $file, $params['frame'], $params['handler'], $time );
+               $ret = $sk->makeImageLink2( $title, $file, $params['frame'], $params['handler'], $time, $descQuery );
 
                # Give the handler a chance to modify the parser object
                if ( $handler ) {
index d841985..5aa8bfe 100644 (file)
@@ -47,6 +47,10 @@ table.filehistory th.mw-imagepage-filesize {
        white-space:nowrap;
 }
 
+table.filehistory td.filehistory-selected {
+       font-weight: bold;
+}
+
 /*
  * rev_deleted stuff
  */