X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FImagePage.php;h=d5f603eb5c364187668fcac6cbd8623abc0a5b28;hb=b36244532ec7e340dec933308c29621344ded1db;hp=1dc6fd6749af212dca6b48856a5d8a6d28482765;hpb=b13fc73642662da98115834508171b5c76696336;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 1dc6fd6749..d5f603eb5c 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -105,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(); } @@ -116,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(); @@ -129,6 +126,8 @@ class ImagePage extends Article { array( 'id' => 'filelinks' ), wfMsg( 'imagelinks' ) ) . "\n" ); $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(); @@ -136,7 +135,7 @@ class ImagePage extends Article { 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( @@ -225,11 +224,11 @@ class ImagePage extends Article { protected function showTOC( $metadata ) { global $wgLang; $r = ''; +
  • ' . wfMsgHtml( 'imagelinks' ) . "
  • \n" . + ($metadata ? '
  • ' . wfMsgHtml( 'metadata' ) . '
  • ' : '') . " + \n"; return $r; } @@ -242,8 +241,9 @@ 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 = "
    "; + $r .= wfMsgNoTrans( 'metadata-help' ); + $r .= "\n"; foreach ( $metadata as $type => $stuff ) { foreach ( $stuff as $v ) { # FIXME, why is this using escapeId for a class?! @@ -251,12 +251,12 @@ class ImagePage extends Article { 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; } @@ -275,7 +275,8 @@ class ImagePage extends Article { } protected function openShowImage() { - global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgLang, $wgContLang; + global $wgOut, $wgUser, $wgImageLimits, $wgRequest, + $wgLang, $wgContLang, $wgEnableUploads; $this->loadFile(); @@ -372,7 +373,7 @@ class ImagePage extends Article { ); $wgOut->addHTML( '' ); + $anchorclose . "\n" ); } if( $this->displayImg->isMultipage() ) { @@ -380,7 +381,13 @@ class ImagePage extends Article { if( $page > 1 ) { $label = $wgOut->parse( wfMsg( 'imgmultipageprev' ), false ); - $link = $sk->makeKnownLinkObj( $this->mTitle, $label, 'page='. ($page-1) ); + $link = $sk->link( + $this->mTitle, + $label, + array(), + array( 'page' => $page - 1 ), + array( 'known', 'noclasses' ) + ); $thumb1 = $sk->makeThumbLinkObj( $this->mTitle, $this->displayImg, $link, $label, 'none', array( 'page' => $page - 1 ) ); } else { @@ -389,7 +396,13 @@ class ImagePage extends Article { if( $page < $count ) { $label = wfMsg( 'imgmultipagenext' ); - $link = $sk->makeKnownLinkObj( $this->mTitle, $label, 'page='. ($page+1) ); + $link = $sk->link( + $this->mTitle, + $label, + array(), + array( 'page' => $page + 1 ), + array( 'known', 'noclasses' ) + ); $thumb2 = $sk->makeThumbLinkObj( $this->mTitle, $this->displayImg, $link, $label, 'none', array( 'page' => $page + 1 ) ); } else { @@ -429,7 +442,7 @@ class ImagePage extends Article { $wgOut->addHTML( '' ); + "\n" ); } $showLink = true; @@ -438,25 +451,26 @@ class ImagePage extends Article { if($showLink) { $filename = wfEscapeWikiText( $this->displayImg->getName() ); + $medialink = "[[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 - ); + ); } } @@ -465,11 +479,20 @@ EOT } } else { # Image does not exist - - $title = SpecialPage::getTitleFor( 'Upload' ); - $link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'), - 'wpDestFile=' . urlencode( $this->displayImg->getName() ) ); - $wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) ); + if ( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) { + // Only show an upload link if the user can upload + $uploadTitle = SpecialPage::getTitleFor( 'Upload' ); + $nofile = array( + 'filepage-nofile-link', + $uploadTitle->getFullUrl( array( 'wpDestFile' => $this->img->getName() ) ) + ); + } + else + { + $nofile = 'filepage-nofile'; + } + $wgOut->setRobotPolicy( 'noindex,nofollow' ); + $wgOut->wrapWikiMsg( "", $nofile ); } } @@ -477,83 +500,37 @@ EOT * Show a notice that the file is from a shared repository */ protected function printSharedImageText() { - global $wgOut, $wgUser; + global $wgOut; $this->loadFile(); $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; - } - } + $wrap = "
    \n$1\n
    \n"; + $repo = $this->img->getRepo()->getDisplayName(); - /* - * 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()) - ); - - $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() ) . '&wpForReUpload=1' ); + return $uploadTitle->getFullUrl( array( + 'wpDestFile' => $this->img->getName(), + 'wpForReUpload' => 1 + ) ); } /** @@ -561,7 +538,9 @@ EOT * external editing (and instructions link) etc. */ protected function uploadLinksBox() { - global $wgUser, $wgOut; + global $wgUser, $wgOut, $wgEnableUploads; + + if( !$wgEnableUploads ) { return; } $this->loadFile(); if( !$this->img->isLocal() ) @@ -569,19 +548,29 @@ EOT $sk = $wgUser->getSkin(); - $wgOut->addHTML( '
    \n" ); } protected function closeShowImage() {} # For overloading @@ -646,17 +635,23 @@ EOT $count++; if( $count <= $limit ) { // We have not yet reached the extra one that tells us there is more to fetch - $name = Title::makeTitle( $s->page_namespace, $s->page_title ); - $link = $sk->makeKnownLinkObj( $name, "" ); + $link = $sk->link( + Title::makeTitle( $s->page_namespace, $s->page_title ), + null, + array(), + array(), + array( 'known', 'noclasses' ) + ); $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() { @@ -673,7 +668,13 @@ EOT $sk = $wgUser->getSkin(); foreach ( $redirects as $title ) { - $link = $sk->makeKnownLinkObj( $title, "", "redirect=no" ); + $link = $sk->link( + $title, + null, + array(), + array( 'redirect' => 'no' ), + array( 'known', 'noclasses' ) + ); $wgOut->addHTML( "
  • {$link}
  • \n" ); } $wgOut->addHTML( "\n" ); @@ -696,13 +697,21 @@ EOT $sk = $wgUser->getSkin(); foreach ( $dupes as $file ) { - if( $file->isLocal() ) - $link = $sk->makeKnownLinkObj( $file->getTitle(), "" ); - else { + $fromSrc = ''; + if( $file->isLocal() ) { + $link = $sk->link( + $file->getTitle(), + null, + array(), + array(), + array( 'known', 'noclasses' ) + ); + } 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" ); } @@ -742,7 +751,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(); } @@ -768,15 +780,16 @@ EOT */ class ImageHistoryList { - protected $imagePage, $img, $skin, $title, $repo; + protected $imagePage, $img, $skin, $title, $repo, $showThumb; public function __construct( $imagePage ) { - global $wgUser; + global $wgUser, $wgShowArchiveThumbnails; $this->skin = $wgUser->getSkin(); $this->current = $imagePage->getFile(); $this->img = $imagePage->getDisplayedFile(); $this->title = $imagePage->getTitle(); $this->imagePage = $imagePage; + $this->showThumb = $wgShowArchiveThumbnails; } public function getImagePage() { @@ -793,14 +806,15 @@ 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 - . Xml::openElement( 'table', array( 'class' => 'filehistory' ) ) . "\n" + . $navLinks . "\n" + . Xml::openElement( 'table', array( 'class' => 'wikitable filehistory' ) ) . "\n" . '' . ( $this->current->isLocal() && ($wgUser->isAllowed('delete') || $wgUser->isAllowed('deleterevision') ) ? '' : '' ) . '' . wfMsgHtml( 'filehist-datetime' ) . '' - . '' . wfMsgHtml( 'filehist-thumb' ) . '' + . ( $this->showThumb ? '' . wfMsgHtml( 'filehist-thumb' ) . '' : '' ) . '' . wfMsgHtml( 'filehist-dimensions' ) . '' . '' . wfMsgHtml( 'filehist-user' ) . '' . '' . wfMsgHtml( 'filehist-comment' ) . '' @@ -808,7 +822,7 @@ class ImageHistoryList { } public function endImageHistoryList( $navLinks = '' ) { - return "\n$navLinks\n"; + return "\n$navLinks\n
    \n"; } public function imageHistoryLine( $iscur, $file ) { @@ -818,10 +832,7 @@ class ImageHistoryList { $img = $iscur ? $file->getName() : $file->getArchiveName(); $user = $file->getUser('id'); $usertext = $file->getUser('text'); - $size = $file->getSize(); $description = $file->getDescription(); - $dims = $file->getDimensionsString(); - $sha1 = $file->getSha1(); $local = $this->current->isLocal(); $row = $css = $selected = ''; @@ -831,14 +842,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 @@ -851,16 +861,21 @@ class ImageHistoryList { if( $iscur || !$file->userCan(File::DELETED_RESTRICTED) ) { $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( + 'type' => 'oldimage', + 'target' => $wgTitle->getPrefixedText(), + 'ids' => $ts, + ), + array( 'known' ) + ); // Bolden oversighted content if( $file->isDeleted(File::DELETED_RESTRICTED) ) $del = "$del"; } - $row .= "$del"; + $row .= "$del"; } $row .= ''; } @@ -873,13 +888,17 @@ class ImageHistoryList { if( $file->isDeleted(File::DELETED_FILE) ) { $row .= wfMsgHtml('filehist-revert'); } else { - $q = array(); - $q[] = 'action=revert'; - $q[] = 'oldimage=' . urlencode( $img ); - $q[] = 'wpEditToken=' . urlencode( $wgUser->editToken( $img ) ); - $row .= $this->skin->makeKnownLinkObj( $this->title, + $row .= $this->skin->link( + $this->title, wfMsgHtml( 'filehist-revert' ), - implode( '&', $q ) ); + array(), + array( + 'action' => 'revert', + 'oldimage' => $img, + 'wpEditToken' => $wgUser->editToken( $img ) + ), + array( 'known', 'noclasses' ) + ); } } $row .= ''; @@ -892,43 +911,40 @@ 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() ); + $url = $this->skin->link( + $revdel, + $wgLang->timeAndDate( $timestamp, true ), + array(), + array( + 'target' => $wgTitle->getPrefixedText(), + 'file' => $img, + 'token' => $wgUser->editToken( $img ) + ), + array( 'known', 'noclasses' ) + ); $row .= ''.$url.''; } else { $url = $iscur ? $this->current->getUrl() : $this->current->getArchiveUrl( $img ); $row .= Xml::element( 'a', array( 'href' => $url ), $wgLang->timeAndDate( $timestamp, true ) ); } + $row .= ""; // Thumbnail - if( $file->allowInlineDisplay() && $file->userCan( File::DELETED_FILE ) && !$file->isDeleted( File::DELETED_FILE ) ) { - $params = array( - 'width' => '120', - 'height' => '120', - ); - $thumbnail = $file->transform( $params ); - $options = array( - 'alt' => wfMsg( 'filehist-thumbtext', $wgLang->timeAndDate( $timestamp, true ) ), - 'file-link' => true, - ); - $row .= '' . ( $thumbnail ? $thumbnail->toHtml( $options ) : - wfMsgHtml( 'filehist-nothumb' ) ); - } else { - $row .= '' . wfMsgHtml( 'filehist-nothumb' ); + if ( $this->showThumb ) { + $row .= '' . $this->getThumbForLine( $file ) . ''; } - $row .= ""; - // Image dimensions - $row .= htmlspecialchars( $dims ); - - // File size - $row .= " (" . $this->skin->formatSize( $size ) . ')'; + // Image dimensions + size + $row .= ''; + $row .= htmlspecialchars( $file->getDimensionsString() ); + $row .= " (" . $this->skin->formatSize( $file->getSize() ) . ')'; + $row .= ''; // Uploading user - $row .= ''; + $row .= ''; if( $local ) { // Hide deleted usernames if( $file->isDeleted(File::DELETED_USER) ) { @@ -955,6 +971,33 @@ class ImageHistoryList { return "{$row}\n"; } + + protected function getThumbForLine( $file ) { + global $wgLang; + + if( $file->allowInlineDisplay() && $file->userCan( File::DELETED_FILE ) && !$file->isDeleted( File::DELETED_FILE ) ) { + $params = array( + 'width' => '120', + 'height' => '120', + ); + $timestamp = wfTimestamp(TS_MW, $file->getTimestamp()); + + $thumbnail = $file->transform( $params ); + $options = array( + 'alt' => wfMsg( 'filehist-thumbtext', + $wgLang->timeAndDate( $timestamp, true ), + $wgLang->date( $timestamp, true ), + $wgLang->time( $timestamp, true ) ), + 'file-link' => true, + ); + + if ( !$thumbnail ) return wfMsgHtml( 'filehist-nothumb' ); + + return $thumbnail->toHtml( $options ); + } else { + return wfMsgHtml( 'filehist-nothumb' ); + } + } } class ImageHistoryPseudoPager extends ReverseChronologicalPager {