X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FImagePage.php;h=38f29527dd7f22cd8a083cd7d7455954fde0adf6;hb=399956f4209406fa49898022e34a9741d2c7035f;hp=e68fbfa8c405d0dde61fb791fe252fca62c09f77;hpb=6235449e09873d8b8e37e8ff5b9e310d71d036ee;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ImagePage.php b/includes/ImagePage.php index e68fbfa8c4..38f29527dd 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -1,31 +1,46 @@ img = wfFindFile( $this->mTitle ); + $this->dupes = null; + $this->repo = null; + } + + protected function loadFile() { + if ( $this->fileLoaded ) { + return true; + } + $this->fileLoaded = true; + + $this->displayImg = $this->img = false; + wfRunHooks( 'ImagePageFindFile', array( $this, &$this->img, &$this->displayImg ) ); if ( !$this->img ) { - $this->img = wfLocalFile( $this->mTitle ); + $this->img = wfFindFile( $this->mTitle ); + if ( !$this->img ) { + $this->img = wfLocalFile( $this->mTitle ); + } + } + if ( !$this->displayImg ) { + $this->displayImg = $this->img; } - $this->repo = $this->img->repo; + $this->repo = $this->img->getRepo(); } /** @@ -35,11 +50,28 @@ class ImagePage extends Article { function render() { global $wgOut; $wgOut->setArticleBodyOnly( true ); - $wgOut->addSecondaryWikitext( $this->getContent() ); + parent::view(); } function view() { global $wgOut, $wgShowEXIF, $wgRequest, $wgUser; + $this->loadFile(); + + if ( $this->mTitle->getNamespace() == NS_IMAGE && $this->img->getRedirected() ) { + if ( $this->mTitle->getDBkey() == $this->img->getName() ) { + // mTitle is the same as the redirect target so ask Article + // to perform the redirect for us. + return Article::view(); + } else { + // mTitle is not the same as the redirect target so it is + // probably the redirect page itself. Fake the redirect symbol + $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); + $wgOut->addHTML( $this->viewRedirect( Title::makeTitle( NS_IMAGE, $this->img->getName() ), + /* $appendSubtitle */ true, /* $forceKnown */ true ) ); + $this->viewUpdates(); + return; + } + } $diff = $wgRequest->getVal( 'diff' ); $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) ); @@ -47,16 +79,16 @@ class ImagePage extends Article { if ( $this->mTitle->getNamespace() != NS_IMAGE || ( isset( $diff ) && $diffOnly ) ) return Article::view(); - if ($wgShowEXIF && $this->img->exists()) { - // FIXME: bad interface, see note on MediaHandler::formatMetadata(). - $formattedMetadata = $this->img->formatMetadata(); + if ( $wgShowEXIF && $this->displayImg->exists() ) { + // FIXME: bad interface, see note on MediaHandler::formatMetadata(). + $formattedMetadata = $this->displayImg->formatMetadata(); $showmeta = $formattedMetadata !== false; } else { $showmeta = false; } - if ($this->img->exists()) - $wgOut->addHTML($this->showTOC($showmeta)); + if ( $this->displayImg->exists() ) + $wgOut->addHTML( $this->showTOC($showmeta) ); $this->openShowImage(); @@ -66,22 +98,35 @@ class ImagePage extends Article { } else { # Just need to set the right headers $wgOut->setArticleFlag( true ); - $wgOut->setRobotpolicy( 'index,follow' ); + $wgOut->setRobotPolicy( 'noindex,nofollow' ); $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); $this->viewUpdates(); } # Show shared description, if needed if ( $this->mExtraDescription ) { - $fol = wfMsg( 'shareddescriptionfollows' ); + $fol = wfMsgNoTrans( 'shareddescriptionfollows' ); if( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) { $wgOut->addWikiText( $fol ); } $wgOut->addHTML( '
' . $this->mExtraDescription . '
' ); + } else { + $this->checkSharedConflict(); } $this->closeShowImage(); $this->imageHistory(); + // TODO: Cleanup the following + + $wgOut->addHTML( Xml::element( 'h2', + array( 'id' => 'filelinks' ), + wfMsg( 'imagelinks' ) ) . "\n" ); + $this->imageDupes(); + // TODO: We may want to find local images redirecting to a foreign + // file: "The following local files redirect to this file" + if ( $this->img->isLocal() ) { + $this->imageRedirects(); + } $this->imageLinks(); if ( $showmeta ) { @@ -90,11 +135,83 @@ class ImagePage extends Article { $collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) ); $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ). "\n" ); $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) ); + $wgOut->addScriptFile( 'metadata.js' ); $wgOut->addHTML( - "\n" . "\n" ); } } + + public function getRedirectTarget() { + $this->loadFile(); + if ( $this->img->isLocal() ) { + return parent::getRedirectTarget(); + } + // Foreign image page + $from = $this->img->getRedirected(); + $to = $this->img->getName(); + if ( $from == $to ) { + return null; + } + return $this->mRedirectTarget = Title::makeTitle( NS_IMAGE, $to ); + } + public function followRedirect() { + $this->loadFile(); + if ( $this->img->isLocal() ) { + return parent::followRedirect(); + } + $from = $this->img->getRedirected(); + $to = $this->img->getName(); + if ( $from == $to ) { + return false; + } + return Title::makeTitle( NS_IMAGE, $to ); + } + public function isRedirect( $text = false ) { + $this->loadFile(); + if ( $this->img->isLocal() ) + return parent::isRedirect( $text ); + + return (bool)$this->img->getRedirected(); + } + + public function isLocal() { + $this->loadFile(); + return $this->img->isLocal(); + } + + public function getFile() { + $this->loadFile(); + return $this->img; + } + + public function getDisplayedFile() { + $this->loadFile(); + return $this->displayImg; + } + + public function getDuplicates() { + $this->loadFile(); + if ( !is_null($this->dupes) ) { + return $this->dupes; + } + if ( !( $hash = $this->img->getSha1() ) ) { + return $this->dupes = array(); + } + $dupes = RepoGroup::singleton()->findBySha1( $hash ); + // Remove duplicates with self and non matching file sizes + $self = $this->img->getRepoName().':'.$this->img->getName(); + $size = $this->img->getSize(); + foreach ( $dupes as $index => $file ) { + $key = $file->getRepoName().':'.$file->getName(); + if ( $key == $self ) + unset( $dupes[$index] ); + if ( $file->getSize() != $size ) + unset( $dupes[$index] ); + } + return $this->dupes = $dupes; + + } + /** * Create the TOC @@ -118,7 +235,7 @@ class ImagePage extends Article { /** * Make a table with metadata to be shown in the output page. * - * FIXME: bad interface, see note on MediaHandler::formatMetadata(). + * FIXME: bad interface, see note on MediaHandler::formatMetadata(). * * @access private * @@ -145,11 +262,12 @@ class ImagePage extends Article { /** * Overloading Article's getContent method. - * + * * Omit noarticletext if sharedupload; text will be fetched from the * shared upload server if possible. */ function getContent() { + $this->loadFile(); if( $this->img && !$this->img->isLocal() && 0 == $this->getID() ) { return ''; } @@ -159,7 +277,9 @@ class ImagePage extends Article { function openShowImage() { global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang; - $full_url = $this->img->getURL(); + $this->loadFile(); + + $full_url = $this->displayImg->getURL(); $linkAttribs = false; $sizeSel = intval( $wgUser->getOption( 'imagesize') ); if( !isset( $wgImageLimits[$sizeSel] ) ) { @@ -178,7 +298,7 @@ class ImagePage extends Article { $sk = $wgUser->getSkin(); $dirmark = $wgContLang->getDirMark(); - if ( $this->img->exists() ) { + if ( $this->displayImg->exists() ) { # image $page = $wgRequest->getIntOrNull( 'page' ); if ( is_null( $page ) ) { @@ -187,22 +307,22 @@ class ImagePage extends Article { } else { $params = array( 'page' => $page ); } - $width_orig = $this->img->getWidth(); + $width_orig = $this->displayImg->getWidth(); $width = $width_orig; - $height_orig = $this->img->getHeight(); + $height_orig = $this->displayImg->getHeight(); $height = $height_orig; - $mime = $this->img->getMimeType(); + $mime = $this->displayImg->getMimeType(); $showLink = false; $linkAttribs = array( 'href' => $full_url ); - $longDesc = $this->img->getLongDesc(); + $longDesc = $this->displayImg->getLongDesc(); wfRunHooks( 'ImageOpenShowImageInlineBefore', array( &$this , &$wgOut ) ) ; - if ( $this->img->allowInlineDisplay() ) { + if ( $this->displayImg->allowInlineDisplay() ) { # image # "Download high res version" link below the image - #$msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->img->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. @@ -219,47 +339,49 @@ class ImagePage extends Article { # because of rounding. } $msgbig = wfMsgHtml( 'show-big-image' ); - $msgsmall = wfMsgExt( 'show-big-image-thumb', - array( 'parseinline' ), $wgLang->formatNum( $width ), $wgLang->formatNum( $height ) ); + $msgsmall = wfMsgExt( 'show-big-image-thumb', 'parseinline', + $wgLang->formatNum( $width ), + $wgLang->formatNum( $height ) + ); } else { # Image is small enough to show full size on image page - $msgbig = htmlspecialchars( $this->img->getName() ); + $msgbig = htmlspecialchars( $this->displayImg->getName() ); $msgsmall = wfMsgExt( 'file-nohires', array( 'parseinline' ) ); } $params['width'] = $width; - $thumbnail = $this->img->transform( $params ); + $thumbnail = $this->displayImg->transform( $params ); $anchorclose = "
"; - if( $this->img->mustRender() ) { + if( $this->displayImg->mustRender() ) { $showLink = true; } else { - $anchorclose .= + $anchorclose .= $msgsmall . '
' . Xml::tags( 'a', $linkAttribs, $msgbig ) . "$dirmark " . $longDesc; } - if ( $this->img->isMultipage() ) { + if ( $this->displayImg->isMultipage() ) { $wgOut->addHTML( '
' ); } if ( $thumbnail ) { - $options = array( - 'alt' => $this->img->getTitle()->getPrefixedText(), + $options = array( + 'alt' => $this->displayImg->getTitle()->getPrefixedText(), 'file-link' => true, ); - $wgOut->addHTML( '
' . - "$select
$thumb1\n$thumb2
" ); + $select = Xml::tags( 'select', + array( 'id' => 'pageselector', 'name' => 'page' ), + implode( "\n", $options ) ); + + $wgOut->addHTML( + '
' . + Xml::openElement( 'form', $formParams ) . + Xml::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) . + wfMsgExt( 'imgmultigoto', array( 'parseinline', 'replaceafter' ), $select ) . + Xml::submitButton( wfMsg( 'imgmultigo' ) ) . + Xml::closeElement( 'form' ) . + "
$thumb1\n$thumb2
" + ); } } else { #if direct link is allowed but it's not a renderable image, show an icon. - if ($this->img->isSafeFile()) { - $icon= $this->img->iconThumb(); + if ( $this->displayImg->isSafeFile() ) { + $icon= $this->displayImg->iconThumb(); $wgOut->addHTML( '