X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FImagePage.php;h=6abf063e859e0e4e08d9b9ca2dfa5f82959beb6d;hb=0ee9a04366b22971725e45af9abd6b28827880dc;hp=1a3b9382d1ce0371b4c24b84f08b8daf0bb2e9de;hpb=28ea816fbafe96825d3c35187a12cadafca6905f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 1a3b9382d1..6abf063e85 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -6,6 +6,9 @@ /** * */ +if( !defined( 'MEDIAWIKI' ) ) + die(); + require_once( 'Image.php' ); /** @@ -14,82 +17,164 @@ require_once( 'Image.php' ); */ class ImagePage extends Article { - /* private */ var $img; // Image object this page is shown for. Initilaized in openShowImage, not - // available in doDelete etc. - + /* private */ var $img; // Image object this page is shown for + function view() { - if ( Namespace::getImage() == $this->mTitle->getNamespace() ) { - $this->openShowImage(); - } + global $wgUseExternalEditor, $wgOut ; - Article::view(); - - # If the article we've just shown is in the "Image" namespace, - # follow it with the history list and link list for the image - # it describes. + $this->img = new Image( $this->mTitle ); - if ( Namespace::getImage() == $this->mTitle->getNamespace() ) { + if( $this->mTitle->getNamespace() == NS_IMAGE ) { + $this->openShowImage(); + if ( $this->img->exists() ) $this->showEXIFdata(); + + # No need to display noarticletext, we use our own message, output in openShowImage() + if ( $this->getID() ) { + Article::view(); + } else { + # Just need to set the right headers + $wgOut->setArticleFlag( true ); + $wgOut->setRobotpolicy( 'index,follow' ); + $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); + $wgOut->addMetaTags(); + $this->viewUpdates(); + } + + if ( $this->img->exists() ) { + $this->uploadNewVersionLink(); + if ( $wgUseExternalEditor && $this->img->exists() ) { + $this->externalEditorLink(); + } + } $this->closeShowImage(); $this->imageHistory(); $this->imageLinks(); + } else { + Article::view(); } } + + function showEXIFdata() { + global $wgOut, $wgShowEXIF; + if ( ! $wgShowEXIF ) return; + + # Get the EXIF data + $exif = $this->img->getExifData(); + if ( count ( $exif ) == 0 ) return; # No EXIF data available + + # Create the table + $r = "{| class=exif\n" ; + $r .= '|+ ' . wfMsg( 'exifdata' ) . "\n|-\n" ; + foreach ( $exif as $k => $v ) { + $r .= "! $k\n"; + $r .= '| ' . htmlspecialchars($v) . "\n|-\n"; + } + $wgOut->addWikiText( substr($r, 0, -3) . '|}' ); + } function openShowImage() { - global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgUseImageResize; - $this->img = Image::newFromTitle( $this->mTitle ); - $url = $this->img->getViewURL(); + global $wgOut, $wgUser, $wgImageLimits, $wgRequest, + $wgUseImageResize, $wgRepositoryBaseUrl, + $wgUseExternalEditor, $wgServer; + $full_url = $this->img->getViewURL(); $anchoropen = ''; $anchorclose = ''; - if ( $wgUseImageResize && $wgUser->getOption( 'imagesize' ) != '' ) { - $max = $wgImageLimits[ intval( $wgUser->getOption( 'imagesize' ) ) ]; - $maxWidth = $max[0]; - $maxHeight = $max[1]; - } + if( $wgUser->getOption( 'imagesize' ) == '' ) { + $sizeSel = User::getDefaultOption( 'imagesize' ); + } else { + $sizeSel = IntVal( $wgUser->getOption( 'imagesize' ) ); + } + if( !isset( $wgImageLimits[$sizeSel] ) ) { + $sizeSel = User::getDefaultOption( 'imagesize' ); + } + $max = $wgImageLimits[$sizeSel]; + $maxWidth = $max[0]; + $maxHeight = $max[1]; + $sk = $wgUser->getSkin(); if ( $this->img->exists() ) { - - $sk = $wgUser->getSkin(); - if ( $this->img->getType() != '' ) { # image $width = $this->img->getWidth(); $height = $this->img->getHeight(); $msg = wfMsg('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) ); - if ( $width > $maxWidth && $wgUseImageResize ) { - $anchoropen = ""; - $anchorclose = "
{$msg}
"; - - $url = $this->img->createThumb( $maxWidth ); + if ( $width > $maxWidth ) { $height = floor( $height * $maxWidth / $width ); $width = $maxWidth; } - if ( $height > $maxHeight && $wgUseImageResize ) { - $anchoropen = ""; - $anchorclose = "
{$msg}
"; - + if ( $height > $maxHeight ) { $width = floor( $width * $maxHeight / $height ); $height = $maxHeight; - $url = $this->img->createThumb( $width ); } - $s = "
" . $anchoropen . + if ( $width != $this->img->getWidth() || $height != $this->img->getHeight() ) { + if( $wgUseImageResize ) { + $thumbnail = $this->img->getThumbnail( $width ); + $url = $thumbnail->getUrl(); + } else { + # No resize ability? Show the full image, but scale + # it down in the browser so it fits on the page. + $url = $full_url; + } + $anchoropen = ""; + $anchorclose = "
\n$anchoropen{$msg}"; + } else { + $url = $full_url; + } + $s = '"; + htmlspecialchars( $wgRequest->getVal( 'image' ) ).'" />' . $anchorclose . '
'; } else { - $s = "
".$sk->makeMediaLink($this->img->getName(),"")."
"; + $s = "
" . $sk->makeMediaLink( $this->img->getName(),'' ) . '
'; } + $wgOut->addHTML( $s ); if($this->img->fromSharedDirectory) { - $s.="
".wfMsg("sharedupload")."
"; + $sharedtext="
" . wfMsg("sharedupload"); + if($wgRepositoryBaseUrl) { + $sharedtext .= " ". wfMsg("shareduploadwiki",$wgRepositoryBaseUrl . urlencode($this->mTitle->getDBkey())); + } + $sharedtext.="
"; + $wgOut->addWikiText($sharedtext); } - $wgOut->addHTML( $s ); + + } else { + # Image does not exist + $wgOut->addWikiText( wfMsg( 'noimage', $this->getUploadUrl() ) ); } } + function getUploadUrl() { + global $wgServer; + $uploadTitle = Title::makeTitle( NS_SPECIAL, 'Upload' ); + return $wgServer . $uploadTitle->getLocalUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) ); + } + + + function uploadNewVersionLink() { + global $wgOut; + $wgOut->addHTML("
"); + $wgOut->addWikiText( wfMsg( 'uploadnewversion', $this->getUploadUrl() ) ); + $wgOut->addHTML("

"); + } + + function externalEditorLink() + { + global $wgUser,$wgOut; + $sk = $wgUser->getSkin(); + $wgOut->addHTML( '
' ); + $wgOut->addHTML( $sk->makeKnownLinkObj( $this->mTitle, + wfMsg( 'edit-externally' ), + "action=edit&externaledit=true&mode=file" ) ); + $wgOut->addWikiText( '
' . + wfMsg('edit-externally-help') . '
' ); + $wgOut->addHTML( '

' ); + } + function closeShowImage() { # For overloading + } /** @@ -105,17 +190,18 @@ class ImagePage extends Article { $line = $this->img->nextHistoryLine(); if ( $line ) { - $s = $sk->beginImageHistoryList() . - $sk->imageHistoryLine( true, $line->img_timestamp, + $list =& new ImageHistoryList( $sk ); + $s = $list->beginImageHistoryList() . + $list->imageHistoryLine( true, $line->img_timestamp, $this->mTitle->getDBkey(), $line->img_user, $line->img_user_text, $line->img_size, $line->img_description ); while ( $line = $this->img->nextHistoryLine() ) { - $s .= $sk->imageHistoryLine( false, $line->img_timestamp, + $s .= $list->imageHistoryLine( false, $line->img_timestamp, $line->oi_archive_name, $line->img_user, $line->img_user_text, $line->img_size, $line->img_description ); } - $s .= $sk->endImageHistoryList(); + $s .= $list->endImageHistoryList(); } else { $s=''; } $wgOut->addHTML( $s ); } @@ -127,12 +213,13 @@ class ImagePage extends Article { $wgOut->addHTML( '

' . wfMsg( 'imagelinks' ) . "

\n" ); $dbr =& wfGetDB( DB_SLAVE ); - $cur = $dbr->tableName( 'cur' ); + $page = $dbr->tableName( 'page' ); $imagelinks = $dbr->tableName( 'imagelinks' ); - $sql = "SELECT cur_namespace,cur_title FROM $imagelinks,$cur WHERE il_to=" . - $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=cur_id"; - $res = $dbr->query( $sql, DB_SLAVE, "Article::imageLinks" ); + $sql = "SELECT page_namespace,page_title FROM $imagelinks,$page WHERE il_to=" . + $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=page_id" + . " LIMIT 500"; # quickie emergency brake + $res = $dbr->query( $sql, "ImagePage::imageLinks" ); if ( 0 == $dbr->numRows( $res ) ) { $wgOut->addHtml( '

' . wfMsg( "nolinkstoimage" ) . "

\n" ); @@ -142,7 +229,7 @@ class ImagePage extends Article { $sk = $wgUser->getSkin(); while ( $s = $dbr->fetchObject( $res ) ) { - $name = Title::MakeTitle( $s->cur_namespace, $s->cur_title ); + $name = Title::MakeTitle( $s->page_namespace, $s->page_title ); $link = $sk->makeKnownLinkObj( $name, "" ); $wgOut->addHTML( "
  • {$link}
  • \n" ); } @@ -153,7 +240,7 @@ class ImagePage extends Article { { global $wgUser, $wgOut, $wgRequest; - $confirm = $wgRequest->getBool( 'wpConfirm' ); + $confirm = $wgRequest->getBool( 'wpConfirmB' ); $image = $wgRequest->getVal( 'image' ); $oldimage = $wgRequest->getVal( 'oldimage' ); @@ -170,16 +257,21 @@ class ImagePage extends Article { # Better double-check that it hasn't been deleted yet! $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) ); - if ( !is_null( $image ) ) { - if ( '' == trim( $image ) ) { - $wgOut->fatalError( wfMsg( 'cannotdelete' ) ); - return; - } + if ( ( !is_null( $image ) ) + && ( '' == trim( $image ) ) ) { + $wgOut->fatalError( wfMsg( 'cannotdelete' ) ); + return; } + $this->img = new Image( $this->mTitle ); + # Deleting old images doesn't require confirmation if ( !is_null( $oldimage ) || $confirm ) { - $this->doDelete(); + if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) { + $this->doDelete(); + } else { + $wgOut->fatalError( wfMsg( 'sessionfailure' ) ); + } return; } @@ -196,20 +288,32 @@ class ImagePage extends Article { function doDelete() { global $wgOut, $wgUser, $wgContLang, $wgRequest; - global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList; + global $wgUseSquid, $wgInternalServer, $wgPostCommitUpdateList; $fname = 'ImagePage::doDelete'; $reason = $wgRequest->getVal( 'wpReason' ); - $image = $wgRequest->getVal( 'image' ); $oldimage = $wgRequest->getVal( 'oldimage' ); $dbw =& wfGetDB( DB_MASTER ); if ( !is_null( $oldimage ) ) { + if ( strlen( $oldimage ) < 16 ) { + $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) ); + return; + } + if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) { + $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) ); + return; + } + + # Invalidate description page cache + $this->mTitle->invalidateCache(); + # Squid purging if ( $wgUseSquid ) { $urlArr = Array( - $wgInternalServer.wfImageArchiveUrl( $oldimage ) + $wgInternalServer.wfImageArchiveUrl( $oldimage ), + $wgInternalServer.$this->mTitle->getFullURL() ); wfPurgeSquidServers($urlArr); } @@ -217,9 +321,7 @@ class ImagePage extends Article { $dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) ); $deleted = $oldimage; } else { - if ( is_null ( $image ) ) { - $image = $this->mTitle->getDBkey(); - } + $image = $this->mTitle->getDBkey(); $dest = wfImageDir( $image ); $archive = wfImageDir( $image ); @@ -232,28 +334,20 @@ class ImagePage extends Article { return; } $dbw->delete( 'image', array( 'img_name' => $image ) ); - $res = $dbw->select( 'oldimage', array( 'oi_archive_name' ), array( 'oi_name' => $image ) ); - - # Squid purging - if ( $wgUseSquid ) { - $urlArr = Array( - $wgInternalServer . Image::wfImageUrl( $image ) - ); - wfPurgeSquidServers($urlArr); - } - + $res = $dbw->select( 'oldimage', array( 'oi_archive_name' ), array( 'oi_name' => $image ) ); + # Purge archive URLs from the squid $urlArr = Array(); while ( $s = $dbw->fetchObject( $res ) ) { $this->doDeleteOldImage( $s->oi_archive_name ); $urlArr[] = $wgInternalServer.wfImageArchiveUrl( $s->oi_archive_name ); } - - # Squid purging, part II + + # And also the HTML of all pages using this image + $linksTo = $this->img->getLinksTo(); if ( $wgUseSquid ) { - /* this needs to be done after LinksUpdate */ - $u = new SquidUpdate( $urlArr ); - array_push( $wgDeferredUpdateList, $u ); + $u = SquidUpdate::newFromTitles( $linksTo, $urlArr ); + array_push( $wgPostCommitUpdateList, $u ); } $dbw->delete( 'oldimage', array( 'oi_name' => $image ) ); @@ -261,10 +355,17 @@ class ImagePage extends Article { # Image itself is now gone, and database is cleaned. # Now we remove the image description page. - $nt = Title::newFromText( $wgContLang->getNsText( Namespace::getImage() ) . ":" . $image ); - $article = new Article( $nt ); + $article = new Article( $this->mTitle ); $article->doDeleteArticle( $reason ); # ignore errors + # Invalidate parser cache and client cache for pages using this image + # This is left until relatively late to reduce lock time + Title::touchArray( $linksTo ); + + /* Delete thumbnails and refresh image metadata cache */ + $this->img->purgeCache(); + + $deleted = $image; } @@ -272,14 +373,14 @@ class ImagePage extends Article { $wgOut->setRobotpolicy( 'noindex,nofollow' ); $sk = $wgUser->getSkin(); - $loglink = $sk->makeKnownLink( $wgContLang->getNsText( - Namespace::getWikipedia() ) . - ':' . wfMsg( 'dellogpage' ), wfMsg( 'deletionlog' ) ); + $loglink = $sk->makeKnownLinkObj( + Title::makeTitle( NS_SPECIAL, 'Log/delete' ), + wfMsg( 'deletionlog' ) ); $text = wfMsg( 'deletedtext', $deleted, $loglink ); $wgOut->addHTML( '

    ' . $text . "

    \n" ); - $wgOut->returnToMain( false ); + $wgOut->returnToMain( false, $this->mTitle->getPrefixedText() ); } function doDeleteOldImage( $oldimage ) @@ -309,7 +410,7 @@ class ImagePage extends Article { function revert() { - global $wgOut, $wgRequest; + global $wgOut, $wgRequest, $wgUser; global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList; $oldimage = $wgRequest->getText( 'oldimage' ); @@ -326,10 +427,18 @@ class ImagePage extends Article { $wgOut->readOnlyPage(); return; } + if( $wgUser->isAnon() ) { + $wgOut->errorpage( 'uploadnologin', 'uploadnologintext' ); + return; + } if ( ! $this->mTitle->userCanEdit() ) { $wgOut->sysopRequired(); return; } + if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) { + $wgOut->errorpage( 'internalerror', 'sessionfailure' ); + return; + } $name = substr( $oldimage, 15 ); $dest = wfImageDir( $name ); @@ -343,8 +452,7 @@ class ImagePage extends Article { $oldver = wfTimestampNow() . "!{$name}"; $dbr =& wfGetDB( DB_SLAVE ); - $size = $dbr->selectField( 'oldimage', 'oi_size', 'oi_archive_name=\'' . - $dbr->strencode( $oldimage ) . "'" ); + $size = $dbr->selectField( 'oldimage', 'oi_size', array( 'oi_archive_name' => $oldimage ) ); if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) { $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" ); @@ -353,22 +461,97 @@ class ImagePage extends Article { if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) { $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile ); } - wfRecordUpload( $name, $oldver, $size, wfMsg( "reverted" ) ); - # Squid purging - if ( $wgUseSquid ) { - $urlArr = Array( - $wgInternalServer.wfImageArchiveUrl( $name ), - $wgInternalServer . Image::wfImageUrl( $name ) - ); - wfPurgeSquidServers($urlArr); - } + + # Record upload and update metadata cache + $img = Image::newFromName( $name ); + $img->recordUpload( $oldver, wfMsg( "reverted" ) ); $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) ); $wgOut->setRobotpolicy( 'noindex,nofollow' ); $wgOut->addHTML( wfMsg( 'imagereverted' ) ); - $wgOut->returnToMain( false ); + + $descTitle = $img->getTitle(); + $wgOut->returnToMain( false, $descTitle->getPrefixedText() ); } } +/** + * @todo document + * @package MediaWiki + */ +class ImageHistoryList { + function ImageHistoryList( &$skin ) { + $this->skin =& $skin; + } + + function beginImageHistoryList() { + $s = "\n

    " . wfMsg( 'imghistory' ) . "

    \n" . + "

    " . wfMsg( 'imghistlegend' ) . "

    \n".'\n"; + return $s; + } + + function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description ) { + global $wgUser, $wgLang, $wgContLang, $wgTitle; + + $datetime = $wgLang->timeanddate( $timestamp, true ); + $del = wfMsg( 'deleteimg' ); + $delall = wfMsg( 'deleteimgcompletely' ); + $cur = wfMsg( 'cur' ); + + if ( $iscur ) { + $url = Image::imageUrl( $img ); + $rlink = $cur; + if ( $wgUser->isAllowed('delete') ) { + $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() . + '&action=delete' ); + $style = $this->skin->getInternalLinkAttributes( $link, $delall ); + + $dlink = ''.$delall.''; + } else { + $dlink = $del; + } + } else { + $url = htmlspecialchars( wfImageArchiveUrl( $img ) ); + if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) { + $token = urlencode( $wgUser->editToken( $img ) ); + $rlink = $this->skin->makeKnownLinkObj( $wgTitle, + wfMsg( 'revertimg' ), 'action=revert&oldimage=' . + urlencode( $img ) . "&wpEditToken=$token" ); + $dlink = $this->skin->makeKnownLinkObj( $wgTitle, + $del, 'action=delete&oldimage=' . urlencode( $img ) . + "&wpEditToken=$token" ); + } else { + # Having live active links for non-logged in users + # means that bots and spiders crawling our site can + # inadvertently change content. Baaaad idea. + $rlink = wfMsg( 'revertimg' ); + $dlink = $del; + } + } + if ( 0 == $user ) { + $userlink = $usertext; + } else { + $userlink = $this->skin->makeLinkObj( + Title::makeTitle( NS_USER, $usertext ), + $usertext ); + } + $nbytes = wfMsg( 'nbytes', $size ); + $style = $this->skin->getInternalLinkAttributes( $url, $datetime ); + + $s = "
  • ({$dlink}) ({$rlink}) {$datetime}" + . " . . {$userlink} ({$nbytes})"; + + $s .= $this->skin->commentBlock( $description, $wgTitle ); + $s .= "
  • \n"; + return $s; + } + +} + ?>