X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FImagePage.php;h=b41e12646f1a09f4acc58c4ee242477909373cda;hb=0abb52ae76adfadefdc5e37ee754eb6fc4c4c2fc;hp=c278070f3341ea68700ed3331b5faab3e71f172d;hpb=04f68827d0e3e53ba2924ff7e9f67f6a7e485656;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ImagePage.php b/includes/ImagePage.php index c278070f33..b41e12646f 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -1,31 +1,51 @@ dupes = null; - $this->repo = null; + /** + * @param $title Title + * @return WikiFilePage + */ + protected function newPage( Title $title ) { + // Overload mPage with a file-specific page + return new WikiFilePage( $title ); } - + + /** + * Constructor from a page id + * @param $id Int article ID to load + * @returnImagePage|null + */ + public static function newFromID( $id ) { + $t = Title::newFromID( $id ); + # @todo FIXME: Doesn't inherit right + return $t == null ? null : new self( $t ); + # return $t == null ? null : new static( $t ); // PHP 5.3 + } + + /** + * @param $file File: + * @return void + */ public function setFile( $file ) { + $this->mPage->setFile( $file ); $this->displayImg = $file; - $this->img = $file; $this->fileLoaded = true; } @@ -35,18 +55,19 @@ class ImagePage extends Article { } $this->fileLoaded = true; - $this->displayImg = $this->img = false; - wfRunHooks( 'ImagePageFindFile', array( $this, &$this->img, &$this->displayImg ) ); - if ( !$this->img ) { - $this->img = wfFindFile( $this->mTitle ); - if ( !$this->img ) { - $this->img = wfLocalFile( $this->mTitle ); + $this->displayImg = $img = false; + wfRunHooks( 'ImagePageFindFile', array( $this, &$img, &$this->displayImg ) ); + if ( !$img ) { // not set by hook? + $img = wfFindFile( $this->getTitle() ); + if ( !$img ) { + $img = wfLocalFile( $this->getTitle() ); } } - if ( !$this->displayImg ) { - $this->displayImg = $this->img; + $this->mPage->setFile( $img ); + if ( !$this->displayImg ) { // not set by hook? + $this->displayImg = $img; } - $this->repo = $this->img->getRepo(); + $this->repo = $img->getRepo(); } /** @@ -65,60 +86,67 @@ class ImagePage extends Article { $diff = $wgRequest->getVal( 'diff' ); $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) ); - if ( $this->mTitle->getNamespace() != NS_FILE || ( isset( $diff ) && $diffOnly ) ) { - return Article::view(); + if ( $this->getTitle()->getNamespace() != NS_FILE || ( isset( $diff ) && $diffOnly ) ) { + return parent::view(); } - + $this->loadFile(); - if ( $this->mTitle->getNamespace() == NS_FILE && $this->img->getRedirected() ) { - if ( $this->mTitle->getDBkey() == $this->img->getName() || isset( $diff ) ) { + if ( $this->getTitle()->getNamespace() == NS_FILE && $this->mPage->getFile()->getRedirected() ) { + if ( $this->getTitle()->getDBkey() == $this->mPage->getFile()->getName() || isset( $diff ) ) { // mTitle is the same as the redirect target so ask Article // to perform the redirect for us. $wgRequest->setVal( 'diffonly', 'true' ); - return Article::view(); + return parent::view(); } else { - // mTitle is not the same as the redirect target so it is + // 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_FILE, $this->img->getName() ), + $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() ); + $wgOut->addHTML( $this->viewRedirect( Title::makeTitle( NS_FILE, $this->mPage->getFile()->getName() ), /* $appendSubtitle */ true, /* $forceKnown */ true ) ); - $this->viewUpdates(); + $this->mPage->doViewUpdates( $this->getContext()->getUser() ); return; } } - $this->showRedirectedFromHeader(); - if ( $wgShowEXIF && $this->displayImg->exists() ) { - // FIXME: bad interface, see note on MediaHandler::formatMetadata(). + // @todo FIXME: Bad interface, see note on MediaHandler::formatMetadata(). $formattedMetadata = $this->displayImg->formatMetadata(); $showmeta = $formattedMetadata !== false; } else { $showmeta = false; } - if ( !$diff && $this->displayImg->exists() ) + if ( !$diff && $this->displayImg->exists() ) { $wgOut->addHTML( $this->showTOC( $showmeta ) ); + } - if ( !$diff ) + if ( !$diff ) { $this->openShowImage(); + } # No need to display noarticletext, we use our own message, output in openShowImage() - if ( $this->getID() ) { - Article::view(); + if ( $this->mPage->getID() ) { + # NS_FILE is in the user language, but this section (the actual wikitext) + # should be in page content language + $pageLang = $this->getTitle()->getPageLanguage(); + $wgOut->addHTML( Xml::openElement( 'div', array( 'id' => 'mw-imagepage-content', + 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(), + 'class' => 'mw-content-'.$pageLang->getDir() ) ) ); + parent::view(); + $wgOut->addHTML( Xml::closeElement( 'div' ) ); } else { # Just need to set the right headers $wgOut->setArticleFlag( true ); - $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); - $this->viewUpdates(); + $wgOut->setPageTitle( $this->getTitle()->getPrefixedText() ); + $this->mPage->doViewUpdates( $this->getContext()->getUser() ); } # Show shared description, if needed if ( $this->mExtraDescription ) { - $fol = wfMsgNoTrans( 'shareddescriptionfollows' ); - if ( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) { - $wgOut->addWikiText( $fol ); + $fol = wfMessage( 'shareddescriptionfollows' ); + if ( !$fol->isDisabled() ) { + $wgOut->addWikiText( $fol->plain() ); } $wgOut->addHTML( '
\n" ); } @@ -131,104 +159,41 @@ 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. + # @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(); - + # Allow extensions to add something after the image links $html = ''; wfRunHooks( 'ImagePageAfterImageLinks', array( $this, &$html ) ); - if ( $html ) + if ( $html ) { $wgOut->addHTML( $html ); + } if ( $showmeta ) { - $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->addWikiText( $this->makeMetadataTable( $formattedMetadata ) ); - $wgOut->addScriptFile( 'metadata.js' ); - $wgOut->addHTML( - "\n" ); - } - - $css = $this->repo->getDescriptionStylesheetUrl(); - if ( $css ) { - $wgOut->addStyle( $css ); - } - } - - 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_FILE, $to ); - } - public function followRedirect() { - $this->loadFile(); - if ( $this->img->isLocal() ) { - return parent::followRedirect(); + $wgOut->addModules( array( 'mediawiki.action.view.metadata' ) ); } - $from = $this->img->getRedirected(); - $to = $this->img->getName(); - if ( $from == $to ) { - return false; + + // Add remote Filepage.css + if( !$this->repo->isLocal() ) { + $css = $this->repo->getDescriptionStylesheetUrl(); + if ( $css ) { + $wgOut->addStyle( $css ); + } } - return Title::makeTitle( NS_FILE, $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(); + // always show the local local Filepage.css, bug 29277 + $wgOut->addModuleStyles( 'filepage' ); } - - public function getFile() { - $this->loadFile(); - return $this->img; - } - + + /** + * @return File + */ 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 @@ -238,26 +203,26 @@ class ImagePage extends Article { */ protected function showTOC( $metadata ) { $r = array( - '