X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FImagePage.php;h=5d4db92eee2d96126c939efd3738311b8667ed95;hb=f47aa05e78dc4d147991ddd93578c44eeae056b2;hp=86ba8cb7476af338b1d4c889221c799b43606565;hpb=a1f9401982d22b77186e4648c4b70c588bdae9f9;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 86ba8cb747..5d4db92eee 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -1,36 +1,46 @@ img = wfFindFile( $this->mTitle, $time ); + $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->current = $this->img; - } else { - $this->current = $time ? wfLocalFile( $this->mTitle ) : $this->img; + $this->img = wfFindFile( $this->mTitle ); + if ( !$this->img ) { + $this->img = wfLocalFile( $this->mTitle ); + } + } + if ( !$this->displayImg ) { + $this->displayImg = $this->img; } $this->repo = $this->img->getRepo(); - $this->dupes = null; } /** @@ -45,6 +55,7 @@ class ImagePage extends Article { 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() ) { @@ -68,16 +79,16 @@ class ImagePage extends Article { if ( $this->mTitle->getNamespace() != NS_IMAGE || ( isset( $diff ) && $diffOnly ) ) return Article::view(); - if ($wgShowEXIF && $this->img->exists()) { + if ( $wgShowEXIF && $this->displayImg->exists() ) { // FIXME: bad interface, see note on MediaHandler::formatMetadata(). - $formattedMetadata = $this->img->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(); @@ -113,7 +124,9 @@ class ImagePage extends Article { $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(); + if ( $this->img->isLocal() ) { + $this->imageRedirects(); + } $this->imageLinks(); if ( $showmeta ) { @@ -129,25 +142,32 @@ class ImagePage extends Article { } public function getRedirectTarget() { - if ( $this->img->isLocal() ) + $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; + if ( $from == $to ) { + return null; + } return $this->mRedirectTarget = Title::makeTitle( NS_IMAGE, $to ); } public function followRedirect() { - if ( $this->img->isLocal() ) + $this->loadFile(); + if ( $this->img->isLocal() ) { return parent::followRedirect(); - + } $from = $this->img->getRedirected(); $to = $this->img->getName(); - if ($from == $to) return false; + 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 ); @@ -155,20 +175,29 @@ class ImagePage extends Article { } 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() { - if ( !is_null($this->dupes) ) return $this->dupes; - - if ( !( $hash = $this->img->getSha1() ) ) + $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(); @@ -238,6 +267,7 @@ class ImagePage extends Article { * shared upload server if possible. */ function getContent() { + $this->loadFile(); if( $this->img && !$this->img->isLocal() && 0 == $this->getID() ) { return ''; } @@ -247,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] ) ) { @@ -266,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 ) ) { @@ -275,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. @@ -311,15 +343,15 @@ class ImagePage extends Article { array( '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 .= @@ -327,13 +359,13 @@ class ImagePage extends Article { '
' . Xml::tags( 'a', $linkAttribs, $msgbig ) . "$dirmark " . $longDesc; } - if ( $this->img->isMultipage() ) { + if ( $this->displayImg->isMultipage() ) { $wgOut->addHTML( '' - . ( $this->img->isLocal() && ($wgUser->isAllowed('delete') || $wgUser->isAllowed('deleterevision') ) ? '' : '' ) + . ( $this->current->isLocal() && ($wgUser->isAllowed('delete') || $wgUser->isAllowed('deleterevision') ) ? '' : '' ) . '' . '' . '' @@ -765,8 +830,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 +892,10 @@ class ImageHistoryList { $row .= ''; // Date/time and image link - $row .= "'; - wfRunHooks( 'ImagePageFileHistoryLine', array( &$file, &$row, &$css ) ); - $tagCSS = $css ? " class='$css'" : ""; - - return "{$row}\n"; + wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) ); + $classAttr = $rowClass ? " class='$rowClass'" : ""; + + return "{$row}\n"; } }
' ); } if ( $thumbnail ) { $options = array( - 'alt' => $this->img->getTitle()->getPrefixedText(), + 'alt' => $this->displayImg->getTitle()->getPrefixedText(), 'file-link' => true, ); $wgOut->addHTML( '' ); } - if ( $this->img->isMultipage() ) { - $count = $this->img->pageCount(); + if ( $this->displayImg->isMultipage() ) { + $count = $this->displayImg->pageCount(); if ( $page > 1 ) { $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false ); $link = $sk->makeKnownLinkObj( $this->mTitle, $label, 'page='. ($page-1) ); - $thumb1 = $sk->makeThumbLinkObj( $this->mTitle, $this->img, $link, $label, 'none', + $thumb1 = $sk->makeThumbLinkObj( $this->mTitle, $this->displayImg, $link, $label, 'none', array( 'page' => $page - 1 ) ); } else { $thumb1 = ''; @@ -356,7 +388,7 @@ class ImagePage extends Article { if ( $page < $count ) { $label = wfMsg( 'imgmultipagenext' ); $link = $sk->makeKnownLinkObj( $this->mTitle, $label, 'page='. ($page+1) ); - $thumb2 = $sk->makeThumbLinkObj( $this->mTitle, $this->img, $link, $label, 'none', + $thumb2 = $sk->makeThumbLinkObj( $this->mTitle, $this->displayImg, $link, $label, 'none', array( 'page' => $page + 1 ) ); } else { $thumb2 = ''; @@ -390,8 +422,8 @@ class ImagePage extends Article { } } 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( '
' . wfMsgHtml( 'filehist-datetime' ) . '' . wfMsgHtml( 'filehist-dimensions' ) . '' . wfMsgHtml( 'filehist-user' ) . '"; + 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 +903,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 ) ); } @@ -873,9 +941,9 @@ class ImageHistoryList { } $row .= '