From c651692075a3eb8521069922f0aed830b93f9bd3 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 19 May 2008 18:55:48 +0000 Subject: [PATCH] Stabilize image description links --- includes/ImageGallery.php | 6 +++--- includes/ImagePage.php | 30 +++++++++++++++++++----------- includes/Linker.php | 15 ++++++++++----- includes/MediaTransformOutput.php | 9 +++++++-- includes/Parser.php | 6 +++--- skins/common/shared.css | 4 ++++ 6 files changed, 46 insertions(+), 24 deletions(-) diff --git a/includes/ImageGallery.php b/includes/ImageGallery.php index 150fe0381e..a2c167bad3 100644 --- a/includes/ImageGallery.php +++ b/includes/ImageGallery.php @@ -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 tags. # ref http://css-discuss.incutio.com/?page=CenteringBlockElement . '
' - . $thumb->toHtml( array( 'desc-link' => true ) ) . '
'; + . $thumb->toHtml( array( 'desc-link' => true, 'desc-query' => $descQuery ) ) . ''; // Call parser transform hook if ( $this->mParser && $img->getHandler() ) { diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 86ba8cb747..7aaab02c1e 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -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" . '' - . ( $this->img->isLocal() && ($wgUser->isAllowed('delete') || $wgUser->isAllowed('deleterevision') ) ? '' : '' ) + . ( $this->current->isLocal() && ($wgUser->isAllowed('delete') || $wgUser->isAllowed('deleterevision') ) ? '' : '' ) . '' . wfMsgHtml( 'filehist-datetime' ) . '' . '' . wfMsgHtml( 'filehist-dimensions' ) . '' . '' . wfMsgHtml( 'filehist-user' ) . '' @@ -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 .= ''; // Date/time and image link - $row .= ""; + if( $file->getTimestamp() === $this->img->getTimestamp() ) { + $selected = "class='filehistory-selected'"; + } + $row .= ""; if( !$file->userCan(File::DELETED_FILE) ) { # Don't link to unviewable files $row .= '' . $wgLang->timeAndDate( $timestamp, true ) . ''; @@ -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 .= ''.$url.''; } 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 .= ''; wfRunHooks( 'ImagePageFileHistoryLine', array( &$file, &$row, &$css ) ); - $tagCSS = $css ? " class='$css'" : ""; - - return "{$row}\n"; + $trCSS = $css ? " class='$css'" : ""; + + return "{$row}\n"; } } diff --git a/includes/Linker.php b/includes/Linker.php index a2d48c6b17..a30190c619 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -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 { diff --git a/includes/MediaTransformOutput.php b/includes/MediaTransformOutput.php index 1c1f403fe7..bd53a16227 100644 --- a/includes/MediaTransformOutput.php +++ b/includes/MediaTransformOutput.php @@ -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 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 { diff --git a/includes/Parser.php b/includes/Parser.php index 94a95d5199..23f29ef993 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -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 ) { diff --git a/skins/common/shared.css b/skins/common/shared.css index d841985cc3..5aa8bfec33 100644 --- a/skins/common/shared.css +++ b/skins/common/shared.css @@ -47,6 +47,10 @@ table.filehistory th.mw-imagepage-filesize { white-space:nowrap; } +table.filehistory td.filehistory-selected { + font-weight: bold; +} + /* * rev_deleted stuff */ -- 2.20.1