X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FImagePage.php;h=d3e01f29ebc877ff84eaa21afca0fc6585f7cdeb;hb=4512a96741006924b8f9eada971726de7d0f49aa;hp=7fb33a5d883093f80949980fd99a9b0a1a6368f7;hpb=753cc671ca3fed0e76324d7f87a002195a1c34c4;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 7fb33a5d88..d3e01f29eb 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -93,10 +93,11 @@ class ImagePage extends Article { $showmeta = false; } - if( $this->displayImg->exists() ) + if( !$diff && $this->displayImg->exists() ) $wgOut->addHTML( $this->showTOC($showmeta) ); - $this->openShowImage(); + if( !$diff ) + $this->openShowImage(); # No need to display noarticletext, we use our own message, output in openShowImage() if( $this->getID() ) { @@ -104,7 +105,6 @@ class ImagePage extends Article { } else { # Just need to set the right headers $wgOut->setArticleFlag( true ); - $wgOut->setRobotPolicy( 'noindex,nofollow' ); $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); $this->viewUpdates(); } @@ -115,9 +115,7 @@ class ImagePage extends Article { if( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) { $wgOut->addWikiText( $fol ); } - $wgOut->addHTML( '
' . $this->mExtraDescription . '
' ); - } else { - $this->checkSharedConflict(); + $wgOut->addHTML( '
' . $this->mExtraDescription . "
\n" ); } $this->closeShowImage(); @@ -128,18 +126,16 @@ class ImagePage extends Article { 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(); - } + # 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(); if( $showmeta ) { global $wgStylePath, $wgStyleVersion; $expand = htmlspecialchars( Xml::escapeJsString( wfMsg( 'metadata-expand' ) ) ); $collapse = htmlspecialchars( Xml::escapeJsString( wfMsg( 'metadata-collapse' ) ) ); - $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ). "\n" ); + $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ) . "\n" ); $wgOut->addWikiText( $this->makeMetadataTable( $formattedMetadata ) ); $wgOut->addScriptFile( 'metadata.js' ); $wgOut->addHTML( @@ -230,9 +226,9 @@ class ImagePage extends Article { $r = ''; +
  • ' . wfMsgHtml( 'imagelinks' ) . "
  • \n" . + ($metadata ? '
  • ' . wfMsgHtml( 'metadata' ) . '
  • ' : '') . " + \n"; return $r; } @@ -245,20 +241,22 @@ class ImagePage extends Article { * @return string */ protected function makeMetadataTable( $metadata ) { - $r = wfMsg( 'metadata-help' ) . "\n\n"; - $r .= "{| id=mw_metadata class=mw_metadata\n"; + $r = "
    \n"; + $r .= wfMsg( 'metadata-help' ); + $r .= "\n"; foreach ( $metadata as $type => $stuff ) { foreach ( $stuff as $v ) { + # FIXME, why is this using escapeId for a class?! $class = Sanitizer::escapeId( $v['id'] ); if( $type == 'collapsed' ) { $class .= ' collapsable'; } - $r .= "|- class=\"$class\"\n"; - $r .= "!| {$v['name']}\n"; - $r .= "|| {$v['value']}\n"; + $r .= "\n"; + $r .= "\n"; + $r .= "\n"; } } - $r .= '|}'; + $r .= "
    {$v['name']}{$v['value']}
    \n
    \n"; return $r; } @@ -374,7 +372,7 @@ class ImagePage extends Article { ); $wgOut->addHTML( '' ); + $anchorclose . "\n" ); } if( $this->displayImg->isMultipage() ) { @@ -431,7 +429,7 @@ class ImagePage extends Article { $wgOut->addHTML( '' ); + "\n" ); } $showLink = true; @@ -440,22 +438,25 @@ class ImagePage extends Article { if($showLink) { $filename = wfEscapeWikiText( $this->displayImg->getName() ); + $medialink = $this->displayImg->isMissing() ? + "'''$filename'''" : + "[[Media:$filename|$filename]]"; if( !$this->displayImg->isSafeFile() ) { $warning = wfMsgNoTrans( 'mediawarning' ); $wgOut->addWikiText( << -[[Media:$filename|$filename]]$dirmark - $longDesc +{$medialink}$dirmark +$longDesc -
    $warning
    EOT ); } else { $wgOut->addWikiText( << -[[Media:$filename|$filename]]$dirmark $longDesc +{$medialink}{$dirmark} +$longDesc EOT ); @@ -471,6 +472,7 @@ EOT $title = SpecialPage::getTitleFor( 'Upload' ); $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'), 'wpDestFile=' . urlencode( $this->displayImg->getName() ) ); + $wgOut->setRobotPolicy( 'noindex,nofollow' ); $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) ); } } @@ -485,77 +487,28 @@ EOT $descUrl = $this->img->getDescriptionUrl(); $descText = $this->img->getDescriptionText(); - $s = "
    " . wfMsgWikiHtml( 'sharedupload' ); - if( $descUrl ) { - $sk = $wgUser->getSkin(); - $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadwiki-linktext' ) ); - $msg = ( $descText ) ? 'shareduploadwiki-desc' : 'shareduploadwiki'; - $msg = wfMsgExt( $msg, array( 'parseinline', 'replaceafter' ), $link ); - if( $msg != '-' ) { - # Show message only if not voided by local sysops - $s .= $msg; - } - } - $s .= "
    "; - $wgOut->addHTML( $s ); - - if( $descText ) { - $this->mExtraDescription = $descText; - } - } - - /* - * Check for files with the same name on the foreign repos. - */ - protected function checkSharedConflict() { - global $wgOut, $wgUser; - - $repoGroup = RepoGroup::singleton(); - if( !$repoGroup->hasForeignRepos() ) { - return; - } - - $this->loadFile(); - if( !$this->img->isLocal() ) { - return; - } - $this->dupFile = null; - $repoGroup->forEachForeignRepo( array( $this, 'checkSharedConflictCallback' ) ); - - if( !$this->dupFile ) - return; - $dupfile = $this->dupFile; - $same = ( - ($this->img->getSha1() == $dupfile->getSha1()) && - ($this->img->getSize() == $dupfile->getSize()) - ); + $wrap = "
    \n$1\n
    \n"; + $repo = $this->img->getRepo()->getDisplayName(); - $sk = $wgUser->getSkin(); - $descUrl = $dupfile->getDescriptionUrl(); - if( $same ) { - $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadduplicate-linktext' ) ); - $wgOut->addHTML( '
    ' . wfMsgWikiHtml( 'shareduploadduplicate', $link ) . '
    ' ); + $msg = ''; + if( $descUrl && $descText && wfMsgNoTrans( 'sharedupload-desc-here' ) !== '-' ) { + $wgOut->wrapWikiMsg( $wrap, array( 'sharedupload-desc-here', $repo, $descUrl ) ); + } elseif ( $descUrl && wfMsgNoTrans( 'sharedupload-desc-there' ) !== '-' ) { + $wgOut->wrapWikiMsg( $wrap, array( 'sharedupload-desc-there', $repo, $descUrl ) ); } else { - $link = $sk->makeExternalLink( $descUrl, wfMsg( 'shareduploadconflict-linktext' ) ); - $wgOut->addHTML( '
    ' . wfMsgWikiHtml( 'shareduploadconflict', $link ) . '
    ' ); + $wgOut->wrapWikiMsg( $wrap, array( 'sharedupload', $repo ), ''/*BACKCOMPAT*/ ); } - } - public function checkSharedConflictCallback( $repo ) { - $this->loadFile(); - $dupfile = $repo->newFile( $this->img->getTitle() ); - if( $dupfile && $dupfile->exists() ) { - $this->dupFile = $dupfile; - return $dupfile->exists(); + if( $descText ) { + $this->mExtraDescription = $descText; } - return false; } public function getUploadUrl() { $this->loadFile(); $uploadTitle = SpecialPage::getTitleFor( 'Upload' ); - return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) ); + return $uploadTitle->getFullUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) . '&wpForReUpload=1' ); } /** @@ -571,23 +524,19 @@ EOT $sk = $wgUser->getSkin(); - $wgOut->addHTML( '
    \n" ); } protected function closeShowImage() {} # For overloading @@ -657,12 +606,13 @@ EOT $wgOut->addHTML( "
  • {$link}
  • \n" ); } } - $wgOut->addHTML( "\n" ); + $wgOut->addHTML( "\n" ); $res->free(); // Add a links to [[Special:Whatlinkshere]] if( $count > $limit ) $wgOut->addWikiMsg( 'morelinkstoimage', $this->mTitle->getPrefixedDBkey() ); + $wgOut->addHTML( "\n" ); } protected function imageRedirects() { @@ -696,19 +646,21 @@ EOT $wgOut->addHTML( "
    \n" ); $wgOut->addWikiMsg( 'duplicatesoffile', - $wgLang->formatNum( count( $dupes ) ) + $wgLang->formatNum( count( $dupes ) ), $this->mTitle->getDBkey() ); $wgOut->addHTML( "
      \n" ); $sk = $wgUser->getSkin(); foreach ( $dupes as $file ) { + $fromSrc = ''; if( $file->isLocal() ) $link = $sk->makeKnownLinkObj( $file->getTitle(), "" ); else { $link = $sk->makeExternalLink( $file->getDescriptionUrl(), $file->getTitle()->getPrefixedText() ); + $fromSrc = wfMsg( 'shared-repo-from', $file->getRepo()->getDisplayName() ); } - $wgOut->addHTML( "
    • {$link}
    • \n" ); + $wgOut->addHTML( "
    • {$link} {$fromSrc}
    • \n" ); } $wgOut->addHTML( "
    \n" ); } @@ -748,7 +700,10 @@ EOT $this->img->upgradeRow(); $this->img->purgeCache(); } else { - wfDebug( "ImagePage::doPurge no image\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(); } parent::doPurge(); } @@ -799,9 +754,10 @@ class ImageHistoryList { public function beginImageHistoryList( $navLinks = '' ) { global $wgOut, $wgUser; - return Xml::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) ) + return Xml::element( 'h2', array( 'id' => 'filehistory' ), wfMsg( 'filehist' ) ) . "\n" + . "
    \n" . $wgOut->parse( wfMsgNoTrans( 'filehist-help' ) ) - . $navLinks + . $navLinks . "\n" . Xml::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n" . '' . ( $this->current->isLocal() && ($wgUser->isAllowed('delete') || $wgUser->isAllowed('deleterevision') ) ? '' : '' ) @@ -814,7 +770,7 @@ class ImageHistoryList { } public function endImageHistoryList( $navLinks = '' ) { - return "\n$navLinks\n"; + return "\n$navLinks\n
    \n"; } public function imageHistoryLine( $iscur, $file ) { @@ -837,14 +793,13 @@ class ImageHistoryList { $row .= ''; # Link to remove from history if( $wgUser->isAllowed( 'delete' ) ) { - $q = array(); - $q[] = 'action=delete'; + $q = array( 'action' => 'delete' ); if( !$iscur ) - $q[] = 'oldimage=' . urlencode( $img ); - $row .= $this->skin->makeKnownLinkObj( + $q['oldimage'] = $img; + $row .= $this->skin->link( $this->title, wfMsgHtml( $iscur ? 'filehist-deleteall' : 'filehist-deleteone' ), - implode( '&', $q ) + array(), $q, array( 'known' ) ); } # Link to hide content @@ -858,10 +813,12 @@ class ImageHistoryList { $del = wfMsgHtml( 'rev-delundel' ); } else { // If the file was hidden, link to sha-1 - list($ts,$name) = explode('!',$img,2); - $del = $this->skin->makeKnownLinkObj( $revdel, wfMsg( 'rev-delundel' ), - 'target=' . urlencode( $wgTitle->getPrefixedText() ) . - '&oldimage=' . urlencode( $ts ) ); + list( $ts, $name ) = explode( '!', $img, 2 ); + $del = $this->skin->link( $revdel, wfMsgHtml( 'rev-delundel' ), + array(), + array( 'target' => $wgTitle->getPrefixedText(), 'oldimage' => $ts ), + array( 'known' ) + ); // Bolden oversighted content if( $file->isDeleted(File::DELETED_RESTRICTED) ) $del = "$del"; @@ -898,19 +855,24 @@ class ImageHistoryList { if( !$file->userCan(File::DELETED_FILE) ) { # Don't link to unviewable files $row .= '' . $wgLang->timeAndDate( $timestamp, true ) . ''; - } else if( $file->isDeleted(File::DELETED_FILE) ) { + } elseif( $file->isDeleted(File::DELETED_FILE) ) { $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->current->getExtension() ); $row .= ''.$url.''; + } elseif( $file->isMissing() ) { + # Don't link to missing files + $row .= $wgLang->timeAndDate( $timestamp, true ); } else { $url = $iscur ? $this->current->getUrl() : $this->current->getArchiveUrl( $img ); $row .= Xml::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) ); } // Thumbnail - if( $file->allowInlineDisplay() && $file->userCan( File::DELETED_FILE ) && !$file->isDeleted( File::DELETED_FILE ) ) { + if( $file->isMissing() ) { + $row .= '' . wfMsgHtml( 'filehist-missing' ) . ''; + } elseif( $file->allowInlineDisplay() && $file->userCan( File::DELETED_FILE ) && !$file->isDeleted( File::DELETED_FILE ) ) { $params = array( 'width' => '120', 'height' => '120', @@ -920,7 +882,8 @@ class ImageHistoryList { 'alt' => wfMsg( 'filehist-thumbtext', $wgLang->timeAndDate( $timestamp, true ) ), 'file-link' => true, ); - $row .= '' . $thumbnail->toHtml( $options ); + $row .= '' . ( $thumbnail ? $thumbnail->toHtml( $options ) : + wfMsgHtml( 'filehist-nothumb' ) ); } else { $row .= '' . wfMsgHtml( 'filehist-nothumb' ); } @@ -965,12 +928,17 @@ class ImageHistoryList { class ImageHistoryPseudoPager extends ReverseChronologicalPager { function __construct( $imagePage ) { parent::__construct(); - $this->mImagePage =& $imagePage; - $this->mTitle = $imagePage->getTitle(); + $this->mImagePage = $imagePage; + $this->mTitle = clone( $imagePage->getTitle() ); + $this->mTitle->setFragment( '#filehistory' ); $this->mImg = NULL; $this->mHist = array(); $this->mRange = array( 0, 0 ); // display range } + + function getTitle() { + return $this->mTitle; + } function getQueryInfo() { return false;