X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FImagePage.php;h=54c676c4fcf4750f431f0f6b115b04b6af4bb213;hb=3139582d50f37b93468458741ee2c9225da36da4;hp=bc31e3374430234e963d97ab95274a13e813db4d;hpb=6f18e92bffa85b1dc6650ccc36d8b746a873fb37;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ImagePage.php b/includes/ImagePage.php index bc31e33744..54c676c4fc 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -7,10 +7,14 @@ */ class ImagePage extends Article { - /* private */ var $img; // Image object - /* private */ var $displayImg; - /* private */ var $repo; - /* private */ var $fileLoaded; + /** + * @var File + */ + private $img; + private $displayImg; + private $repo; + private $fileLoaded; + var $mExtraDescription = false; var $dupes; @@ -21,7 +25,7 @@ class ImagePage extends Article { } /** - * @param $file File: + * @param $file File: * @return void */ public function setFile( $file ) { @@ -99,11 +103,13 @@ class ImagePage extends Article { $showmeta = false; } - if ( !$diff && $this->displayImg->exists() ) + if ( !$diff && $this->displayImg->exists() ) { $wgOut->addHTML( $this->showTOC( $showmeta ) ); + } - if ( !$diff ) + if ( !$diff ) { $this->openShowImage(); + } # No need to display noarticletext, we use our own message, output in openShowImage() if ( $this->getID() ) { @@ -134,19 +140,19 @@ class ImagePage extends Article { $this->imageDupes(); # TODO! FIXME! For some freaky reason, we can't redirect to foreign images. # Yet we return metadata about the target. Definitely an issue in the FileRepo - $this->imageRedirects(); $this->imageLinks(); # Allow extensions to add something after the image links $html = ''; wfRunHooks( 'ImagePageAfterImageLinks', array( $this, &$html ) ); - if ( $html ) + if ( $html ) { $wgOut->addHTML( $html ); + } if ( $showmeta ) { $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ) . "\n" ); $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) ); - $wgOut->addModules( array( 'mediawiki.legacy.metadata' ) ); + $wgOut->addModules( array( 'mediawiki.action.view.metadata' ) ); } $css = $this->repo->getDescriptionStylesheetUrl(); @@ -168,6 +174,7 @@ class ImagePage extends Article { } return $this->mRedirectTarget = Title::makeTitle( NS_FILE, $to ); } + public function followRedirect() { $this->loadFile(); if ( $this->img->isLocal() ) { @@ -180,10 +187,12 @@ class ImagePage extends Article { } return Title::makeTitle( NS_FILE, $to ); } + public function isRedirect( $text = false ) { $this->loadFile(); - if ( $this->img->isLocal() ) + if ( $this->img->isLocal() ) { return parent::isRedirect( $text ); + } return (bool)$this->img->getRedirected(); } @@ -208,7 +217,8 @@ class ImagePage extends Article { if ( !is_null( $this->dupes ) ) { return $this->dupes; } - if ( !( $hash = $this->img->getSha1() ) ) { + $hash = $this->img->getSha1(); + if ( !( $hash ) ) { return $this->dupes = array(); } $dupes = RepoGroup::singleton()->findBySha1( $hash ); @@ -217,15 +227,15 @@ class ImagePage extends Article { $size = $this->img->getSize(); foreach ( $dupes as $index => $file ) { $key = $file->getRepoName() . ':' . $file->getName(); - if ( $key == $self ) + if ( $key == $self ) { unset( $dupes[$index] ); - if ( $file->getSize() != $size ) + } + if ( $file->getSize() != $size ) { unset( $dupes[$index] ); + } } return $this->dupes = $dupes; - } - /** * Create the TOC @@ -235,9 +245,9 @@ class ImagePage extends Article { */ protected function showTOC( $metadata ) { $r = array( - '
  • ' . wfMsgHtml( 'file-anchor-link' ) . '
  • ', - '
  • ' . wfMsgHtml( 'filehist' ) . '
  • ', - '
  • ' . wfMsgHtml( 'imagelinks' ) . '
  • ', + '
  • ' . wfMsgHtml( 'file-anchor-link' ) . '
  • ', + '
  • ' . wfMsgHtml( 'filehist' ) . '
  • ', + '
  • ' . wfMsgHtml( 'imagelinks' ) . '
  • ', ); if ( $metadata ) { $r[] = '
  • ' . wfMsgHtml( 'metadata' ) . '
  • '; @@ -254,7 +264,7 @@ class ImagePage extends Article { * FIXME: bad interface, see note on MediaHandler::formatMetadata(). * * @param $metadata Array: the array containing the EXIF data - * @return String + * @return String The metadata table. This is treated as Wikitext (!) */ protected function makeMetadataTable( $metadata ) { $r = "
    "; @@ -335,7 +345,7 @@ class ImagePage extends Article { # image # "Download high res version" link below the image - # $msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->displayImg->getSize() ), $mime ); + # $msgsize = wfMsgHtml( 'file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->displayImg->getSize() ), $mime ); # We'll show a thumbnail of this image if ( $width > $maxWidth || $height > $maxHeight ) { # Calculate the thumbnail size. @@ -352,20 +362,29 @@ class ImagePage extends Article { # because of rounding. } $msgbig = wfMsgHtml( 'show-big-image' ); - $msgsmall = wfMsgExt( 'show-big-image-thumb', 'parseinline', - $wgLang->formatNum( $width ), - $wgLang->formatNum( $height ) - ); + $otherSizes = array(); + foreach ( $wgImageLimits as $size ) { + if ( $size[0] < $width_orig && $size[1] < $height_orig && + $size[0] != $width && $size[1] != $height ) { + $otherSizes[] = $this->makeSizeLink( $params, $size[0], $size[1] ); + } + } + $msgsmall = wfMessage( 'show-big-image-preview' )-> + rawParams( $this->makeSizeLink( $params, $width, $height ) )-> + parse() . ' ' . + wfMessage( 'show-big-image-other' )-> + rawParams( $wgLang->pipeList( $otherSizes ) )->parse(); } else { # Image is small enough to show full size on image page $msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) ); } $params['width'] = $width; + $params['height'] = $height; $thumbnail = $this->displayImg->transform( $params ); $showLink = true; - $anchorclose = "
    " . $msgsmall; + $anchorclose = '
    ' . $msgsmall; $isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1; if ( $isMulti ) { @@ -433,7 +452,7 @@ class ImagePage extends Article { $wgOut->addHTML( '
    ' . Xml::openElement( 'form', $formParams ) . - Html::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) . + Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . wfMsgExt( 'imgmultigoto', array( 'parseinline', 'replaceafter' ), $select ) . Xml::submitButton( wfMsg( 'imgmultigo' ) ) . Xml::closeElement( 'form' ) . @@ -446,14 +465,13 @@ class ImagePage extends Article { $icon = $this->displayImg->iconThumb(); $wgOut->addHTML( '\n" ); + $icon->toHtml( array( 'file-link' => true ) ) . + "
    \n" ); } $showLink = true; } - if ( $showLink ) { $filename = wfEscapeWikiText( $this->displayImg->getName() ); $linktext = $filename; @@ -488,11 +506,9 @@ EOT $uploadTitle = SpecialPage::getTitleFor( 'Upload' ); $nofile = array( 'filepage-nofile-link', - $uploadTitle->getFullUrl( array( 'wpDestFile' => $this->img->getName() ) ) + $uploadTitle->getFullURL( array( 'wpDestFile' => $this->img->getName() ) ) ); - } - else - { + } else { $nofile = 'filepage-nofile'; } // Note, if there is an image description page, but @@ -503,10 +519,32 @@ EOT if ( !$this->getID() ) { // If there is no image, no shared image, and no description page, // output a 404, to be consistent with articles. - $wgRequest->response()->header( "HTTP/1.x 404 Not Found" ); + $wgRequest->response()->header( 'HTTP/1.1 404 Not Found' ); } } } + + /** + * Creates an thumbnail of specified size and returns an HTML link to it + * @param array $params Scaler parameters + * @param int $width + * @param int $height + */ + private function makeSizeLink( $params, $width, $height ) { + $params['width'] = $width; + $params['height'] = $height; + $thumbnail = $this->displayImg->transform( $params ); + if ( $thumbnail && !$thumbnail->isError() ) { + return Html::rawElement( 'a', array( + 'href' => $thumbnail->getUrl(), + 'class' => 'mw-thumbnail-link' + ), wfMessage( 'show-big-image-size' )->numParams( + $thumbnail->getWidth(), $thumbnail->getHeight() + )->parse() ); + } else { + return ''; + } + } /** * Show a notice that the file is from a shared repository @@ -543,7 +581,7 @@ EOT public function getUploadUrl() { $this->loadFile(); $uploadTitle = SpecialPage::getTitleFor( 'Upload' ); - return $uploadTitle->getFullUrl( array( + return $uploadTitle->getFullURL( array( 'wpDestFile' => $this->img->getName(), 'wpForReUpload' => 1 ) ); @@ -556,11 +594,14 @@ EOT protected function uploadLinksBox() { global $wgUser, $wgOut, $wgEnableUploads, $wgUseExternalEditor; - if ( !$wgEnableUploads ) { return; } + if ( !$wgEnableUploads ) { + return; + } $this->loadFile(); - if ( !$this->img->isLocal() ) + if ( !$this->img->isLocal() ) { return; + } $sk = $wgUser->getSkin(); @@ -585,7 +626,11 @@ EOT ), array( 'known', 'noclasses' ) ); - $wgOut->addHTML( '
  • ' . $elink . ' ' . wfMsgExt( 'edit-externally-help', array( 'parseinline' ) ) . "
  • \n" ); + $wgOut->addHTML( + '
  • ' . $elink . ' ' . + wfMsgExt( 'edit-externally-help', array( 'parseinline' ) ) . + "
  • \n" + ); } $wgOut->addHTML( "\n" ); @@ -614,28 +659,56 @@ EOT } } - protected function imageLinks() { - global $wgUser, $wgOut, $wgLang; - - $limit = 100; - + protected function queryImageLinks( $target, $limit ) { $dbr = wfGetDB( DB_SLAVE ); - $res = $dbr->select( + return $dbr->select( array( 'imagelinks', 'page' ), - array( 'page_namespace', 'page_title' ), - array( 'il_to' => $this->mTitle->getDBkey(), 'il_from = page_id' ), + array( 'page_namespace', 'page_title', 'page_is_redirect', 'il_to' ), + array( 'il_to' => $target, 'il_from = page_id' ), __METHOD__, array( 'LIMIT' => $limit + 1 ) - ); - $count = $dbr->numRows( $res ); + ); + } + + protected function imageLinks() { + global $wgUser, $wgOut, $wgLang; + + $limit = 100; + + $res = $this->queryImageLinks( $this->mTitle->getDbKey(), $limit + 1); + $rows = array(); + $redirects = array(); + foreach ( $res as $row ) { + if ( $row->page_is_redirect ) { + $redirects[$row->page_title] = array(); + } + $rows[] = $row; + } + $count = count( $rows ); + + $hasMore = $count > $limit; + if ( !$hasMore && count( $redirects ) ) { + $res = $this->queryImageLinks( array_keys( $redirects ), + $limit - count( $rows ) + 1 ); + foreach ( $res as $row ) { + $redirects[$row->il_to][] = $row; + $count++; + } + $hasMore = ( $res->numRows() + count( $rows ) ) > $limit; + } + if ( $count == 0 ) { - $wgOut->wrapWikiMsg( Html::rawElement( 'div', array ( 'id' => 'mw-imagepage-nolinkstoimage' ), "\n$1\n" ), 'nolinkstoimage' ); + $wgOut->wrapWikiMsg( + Html::rawElement( 'div', + array( 'id' => 'mw-imagepage-nolinkstoimage' ), "\n$1\n" ), + 'nolinkstoimage' + ); return; } $wgOut->addHTML( "
    \n" ); - if ( $count <= $limit - 1 ) { + if ( !$hasMore ) { $wgOut->addWikiMsg( 'linkstoimage', $count ); } else { // More links than the limit. Add a link to [[Special:Whatlinkshere]] @@ -645,29 +718,51 @@ EOT ); } - $wgOut->addHTML( Html::openElement( 'ul', array( 'class' => 'mw-imagepage-linkstoimage' ) ) . "\n" ); + $wgOut->addHTML( + Html::openElement( 'ul', + array( 'class' => 'mw-imagepage-linkstoimage' ) ) . "\n" + ); $sk = $wgUser->getSkin(); $count = 0; - $elements = array(); - foreach ( $res as $s ) { - $count++; - if ( $count <= $limit ) { - // We have not yet reached the extra one that tells us there is more to fetch - $elements[] = $s; - } - } // Sort the list by namespace:title - usort ( $elements, array( $this, 'compare' ) ); + usort( $rows, array( $this, 'compare' ) ); // Create links for every element - foreach( $elements as $element ) { + $currentCount = 0; + foreach( $rows as $element ) { + $currentCount++; + if ( $currentCount > $limit ) { + break; + } + $link = $sk->linkKnown( Title::makeTitle( $element->page_namespace, $element->page_title ) ); - $wgOut->addHTML( Html::rawElement( + if ( !isset( $redirects[$element->page_title] ) ) { + $liContents = $link; + } else { + $ul = "'; + $liContents = wfMessage( 'linkstoimage-redirect' )->rawParams( + $link, $ul )->parse(); + } + $wgOut->addHTML( Html::rawElement( + 'li', + array( 'id' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ), + $liContents + ) . "\n" ); }; @@ -680,33 +775,6 @@ EOT } $wgOut->addHTML( Html::closeElement( 'div' ) . "\n" ); } - - protected function imageRedirects() { - global $wgUser, $wgOut, $wgLang; - - $redirects = $this->getTitle()->getRedirectsHere( NS_FILE ); - if ( count( $redirects ) == 0 ) return; - - $wgOut->addHTML( "
    \n" ); - $wgOut->addWikiMsg( 'redirectstofile', - $wgLang->formatNum( count( $redirects ) ) - ); - $wgOut->addHTML( "
      \n" ); - - $sk = $wgUser->getSkin(); - foreach ( $redirects as $title ) { - $link = $sk->link( - $title, - null, - array(), - array( 'redirect' => 'no' ), - array( 'known', 'noclasses' ) - ); - $wgOut->addHTML( "
    • {$link}
    • \n" ); - } - $wgOut->addHTML( "
    \n" ); - - } protected function imageDupes() { global $wgOut, $wgUser, $wgLang; @@ -714,7 +782,9 @@ EOT $this->loadFile(); $dupes = $this->getDuplicates(); - if ( count( $dupes ) == 0 ) return; + if ( count( $dupes ) == 0 ) { + return; + } $wgOut->addHTML( "
    \n" ); $wgOut->addWikiMsg( 'duplicatesoffile', @@ -779,13 +849,13 @@ EOT public function doPurge() { $this->loadFile(); if ( $this->img->exists() ) { - wfDebug( "ImagePage::doPurge purging " . $this->img->getName() . "\n" ); + wfDebug( 'ImagePage::doPurge purging ' . $this->img->getName() . "\n" ); $update = new HTMLCacheUpdate( $this->mTitle, 'imagelinks' ); $update->doUpdate(); $this->img->upgradeRow(); $this->img->purgeCache(); } else { - wfDebug( "ImagePage::doPurge no image for " . $this->img->getName() . "; limiting purge to cache only\n" ); + wfDebug( 'ImagePage::doPurge no image for ' . $this->img->getName() . "; limiting purge to cache only\n" ); // even if the file supposedly doesn't exist, force any cached information // to be updated (in case the cached information is wrong) $this->img->purgeCache(); @@ -798,14 +868,13 @@ EOT */ function showError( $description ) { global $wgOut; - $wgOut->setPageTitle( wfMsg( "internalerror" ) ); - $wgOut->setRobotPolicy( "noindex,nofollow" ); + $wgOut->setPageTitle( wfMsg( 'internalerror' ) ); + $wgOut->setRobotPolicy( 'noindex,nofollow' ); $wgOut->setArticleRelated( false ); $wgOut->enableClientCache( false ); $wgOut->addWikiText( $description ); } - /** * Callback for usort() to do link sorts by (namespace, title) * Function copied from Title::compare() @@ -830,9 +899,32 @@ EOT */ class ImageHistoryList { - protected $imagePage, $img, $skin, $title, $repo, $showThumb; + /** + * @var Title + */ + protected $title; + + /** + * @var File + */ + protected $img; + + /** + * @var ImagePage + */ + protected $imagePage; + + /** + * @var Skin + */ + protected $skin; + + protected $repo, $showThumb; protected $preventClickjacking = false; + /** + * @param ImagePage $imagePage + */ public function __construct( $imagePage ) { global $wgUser, $wgShowArchiveThumbnails; $this->skin = $wgUser->getSkin(); @@ -863,7 +955,7 @@ class ImageHistoryList { . $navLinks . "\n" . Xml::openElement( 'table', array( 'class' => 'wikitable filehistory' ) ) . "\n" . '' - . ( $this->current->isLocal() && ( $wgUser->isAllowed( 'delete' ) || $wgUser->isAllowed( 'deletedhistory' ) ) ? '' : '' ) + . ( $this->current->isLocal() && ( $wgUser->isAllowedAny( 'delete', 'deletedhistory' ) ) ? '' : '' ) . '' . wfMsgHtml( 'filehist-datetime' ) . '' . ( $this->showThumb ? '' . wfMsgHtml( 'filehist-thumb' ) . '' : '' ) . '' . wfMsgHtml( 'filehist-dimensions' ) . '' @@ -876,6 +968,11 @@ class ImageHistoryList { return "\n$navLinks\n
    \n"; } + /** + * @param $iscur + * @param $file File + * @return string + */ public function imageHistoryLine( $iscur, $file ) { global $wgUser, $wgLang; @@ -889,13 +986,14 @@ class ImageHistoryList { $row = $selected = ''; // Deletion link - if ( $local && ( $wgUser->isAllowed( 'delete' ) || $wgUser->isAllowed( 'deletedhistory' ) ) ) { + if ( $local && ( $wgUser->isAllowedAny( 'delete', 'deletedhistory' ) ) ) { $row .= ''; # Link to remove from history if ( $wgUser->isAllowed( 'delete' ) ) { $q = array( 'action' => 'delete' ); - if ( !$iscur ) + if ( !$iscur ) { $q['oldimage'] = $img; + } $row .= $this->skin->link( $this->title, wfMsgHtml( $iscur ? 'filehist-deleteall' : 'filehist-deleteone' ), @@ -958,20 +1056,24 @@ class ImageHistoryList { # Don't link to unviewable files $row .= '' . $wgLang->timeAndDate( $timestamp, true ) . ''; } elseif ( $file->isDeleted( File::DELETED_FILE ) ) { - $this->preventClickjacking(); - $revdel = SpecialPage::getTitleFor( 'Revisiondelete' ); - # Make a link to review the image - $url = $this->skin->link( - $revdel, - $wgLang->timeAndDate( $timestamp, true ), - array(), - array( - 'target' => $this->title->getPrefixedText(), - 'file' => $img, - 'token' => $wgUser->editToken( $img ) - ), - array( 'known', 'noclasses' ) - ); + if ( $local ) { + $this->preventClickjacking(); + $revdel = SpecialPage::getTitleFor( 'Revisiondelete' ); + # Make a link to review the image + $url = $this->skin->link( + $revdel, + $wgLang->timeAndDate( $timestamp, true ), + array(), + array( + 'target' => $this->title->getPrefixedText(), + 'file' => $img, + 'token' => $wgUser->editToken( $img ) + ), + array( 'known', 'noclasses' ) + ); + } else { + $url = $wgLang->timeAndDate( $timestamp, true ); + } $row .= '' . $url . ''; } else { $url = $iscur ? $this->current->getUrl() : $this->current->getArchiveUrl( $img ); @@ -987,21 +1089,21 @@ class ImageHistoryList { // Image dimensions + size $row .= ''; $row .= htmlspecialchars( $file->getDimensionsString() ); - $row .= " (" . $this->skin->formatSize( $file->getSize() ) . ')'; + $row .= ' (' . $this->skin->formatSize( $file->getSize() ) . ')'; $row .= ''; // Uploading user $row .= ''; - if ( $local ) { - // Hide deleted usernames - if ( $file->isDeleted( File::DELETED_USER ) ) { - $row .= '' . wfMsgHtml( 'rev-deleted-user' ) . ''; + // Hide deleted usernames + if ( $file->isDeleted( File::DELETED_USER ) ) { + $row .= '' . wfMsgHtml( 'rev-deleted-user' ) . ''; + } else { + if ( $local ) { + $row .= $this->skin->userLink( $user, $usertext ) . ' ' . + $this->skin->userToolLinks( $user, $usertext ) . ''; } else { - $row .= $this->skin->userLink( $user, $usertext ) . " " . - $this->skin->userToolLinks( $user, $usertext ) . ""; + $row .= htmlspecialchars( $usertext ); } - } else { - $row .= htmlspecialchars( $usertext ); } $row .= ''; @@ -1009,17 +1111,21 @@ class ImageHistoryList { if ( $file->isDeleted( File::DELETED_COMMENT ) ) { $row .= '' . wfMsgHtml( 'rev-deleted-comment' ) . ''; } else { - $row .= $this->skin->commentBlock( $description, $this->title ); + $row .= $this->skin->commentBlock( $description, $this->title, false, false ); } $row .= ''; $rowClass = null; wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) ); - $classAttr = $rowClass ? " class='$rowClass'" : ""; + $classAttr = $rowClass ? " class='$rowClass'" : ''; return "{$row}\n"; } + /** + * @param $file File + * @return string + */ protected function getThumbForLine( $file ) { global $wgLang; @@ -1039,7 +1145,9 @@ class ImageHistoryList { 'file-link' => true, ); - if ( !$thumbnail ) return wfMsgHtml( 'filehist-nothumb' ); + if ( !$thumbnail ) { + return wfMsgHtml( 'filehist-nothumb' ); + } return $thumbnail->toHtml( $options ); } else { @@ -1059,6 +1167,19 @@ class ImageHistoryList { class ImageHistoryPseudoPager extends ReverseChronologicalPager { protected $preventClickjacking = false; + /** + * @var File + */ + protected $mImg; + + /** + * @var Title + */ + protected $mTitle; + + /** + * @param ImagePage $imagePage + */ function __construct( $imagePage ) { parent::__construct(); $this->mImagePage = $imagePage; @@ -1108,7 +1229,9 @@ class ImageHistoryPseudoPager extends ReverseChronologicalPager { } function doQuery() { - if ( $this->mQueryDone ) return; + if ( $this->mQueryDone ) { + return; + } $this->mImg = $this->mImagePage->getFile(); // ensure loading if ( !$this->mImg->exists() ) { return;