X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/includes/page/ImagePage.php diff --git a/includes/page/ImagePage.php b/includes/page/ImagePage.php new file mode 100644 index 00000000..0e3eaa5b --- /dev/null +++ b/includes/page/ImagePage.php @@ -0,0 +1,1230 @@ +mPage->setFile( $file ); + $this->displayImg = $file; + $this->fileLoaded = true; + } + + protected function loadFile() { + if ( $this->fileLoaded ) { + return; + } + $this->fileLoaded = true; + + $this->displayImg = $img = false; + + Hooks::run( 'ImagePageFindFile', [ $this, &$img, &$this->displayImg ] ); + if ( !$img ) { // not set by hook? + $img = wfFindFile( $this->getTitle() ); + if ( !$img ) { + $img = wfLocalFile( $this->getTitle() ); + } + } + $this->mPage->setFile( $img ); + if ( !$this->displayImg ) { // not set by hook? + $this->displayImg = $img; + } + $this->repo = $img->getRepo(); + } + + /** + * Handler for action=render + * Include body text only; none of the image extras + */ + public function render() { + $this->getContext()->getOutput()->setArticleBodyOnly( true ); + parent::view(); + } + + public function view() { + global $wgShowEXIF; + + $out = $this->getContext()->getOutput(); + $request = $this->getContext()->getRequest(); + $diff = $request->getVal( 'diff' ); + $diffOnly = $request->getBool( + 'diffonly', + $this->getContext()->getUser()->getOption( 'diffonly' ) + ); + + if ( $this->getTitle()->getNamespace() != NS_FILE || ( $diff !== null && $diffOnly ) ) { + parent::view(); + return; + } + + $this->loadFile(); + + if ( $this->getTitle()->getNamespace() == NS_FILE && $this->mPage->getFile()->getRedirected() ) { + if ( $this->getTitle()->getDBkey() == $this->mPage->getFile()->getName() || $diff !== null ) { + $request->setVal( 'diffonly', 'true' ); + } + + parent::view(); + return; + } + + if ( $wgShowEXIF && $this->displayImg->exists() ) { + // @todo FIXME: Bad interface, see note on MediaHandler::formatMetadata(). + $formattedMetadata = $this->displayImg->formatMetadata( $this->getContext() ); + $showmeta = $formattedMetadata !== false; + } else { + $showmeta = false; + } + + if ( !$diff && $this->displayImg->exists() ) { + $out->addHTML( $this->showTOC( $showmeta ) ); + } + + if ( !$diff ) { + $this->openShowImage(); + } + + # No need to display noarticletext, we use our own message, output in openShowImage() + 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()->getPageViewLanguage(); + $out->addHTML( Xml::openElement( 'div', [ 'id' => 'mw-imagepage-content', + 'lang' => $pageLang->getHtmlCode(), 'dir' => $pageLang->getDir(), + 'class' => 'mw-content-' . $pageLang->getDir() ] ) ); + + parent::view(); + + $out->addHTML( Xml::closeElement( 'div' ) ); + } else { + # Just need to set the right headers + $out->setArticleFlag( true ); + $out->setPageTitle( $this->getTitle()->getPrefixedText() ); + $this->mPage->doViewUpdates( $this->getContext()->getUser(), $this->getOldID() ); + } + + # Show shared description, if needed + if ( $this->mExtraDescription ) { + $fol = $this->getContext()->msg( 'shareddescriptionfollows' ); + if ( !$fol->isDisabled() ) { + $out->addWikiText( $fol->plain() ); + } + $out->addHTML( '
\n" ); + } + + $this->closeShowImage(); + $this->imageHistory(); + // TODO: Cleanup the following + + $out->addHTML( Xml::element( 'h2', + [ 'id' => 'filelinks' ], + $this->getContext()->msg( 'imagelinks' )->text() ) . "\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->imageLinks(); + + # Allow extensions to add something after the image links + $html = ''; + Hooks::run( 'ImagePageAfterImageLinks', [ $this, &$html ] ); + if ( $html ) { + $out->addHTML( $html ); + } + + if ( $showmeta ) { + $out->addHTML( Xml::element( + 'h2', + [ 'id' => 'metadata' ], + $this->getContext()->msg( 'metadata' )->text() ) . "\n" ); + $out->addWikiText( $this->makeMetadataTable( $formattedMetadata ) ); + $out->addModules( [ 'mediawiki.action.view.metadata' ] ); + } + + // Add remote Filepage.css + if ( !$this->repo->isLocal() ) { + $css = $this->repo->getDescriptionStylesheetUrl(); + if ( $css ) { + $out->addStyle( $css ); + } + } + + $out->addModuleStyles( [ + 'filepage', // always show the local local Filepage.css, T31277 + 'mediawiki.action.view.filepage', // Add MediaWiki styles for a file page + ] ); + } + + /** + * @return File + */ + public function getDisplayedFile() { + $this->loadFile(); + return $this->displayImg; + } + + /** + * Create the TOC + * + * @param bool $metadata Whether or not to show the metadata link + * @return string + */ + protected function showTOC( $metadata ) { + $r = [ + '' );
+ }
+
+ if ( $thumbnail ) {
+ $options = [
+ 'alt' => $this->displayImg->getTitle()->getPrefixedText(),
+ 'file-link' => true,
+ ];
+ $out->addHTML( ' ' .
+ $thumbnail->toHtml( $options ) .
+ $anchorclose . " \n" );
+ }
+
+ if ( $isMulti ) {
+ $count = $this->displayImg->pageCount();
+
+ if ( $page > 1 ) {
+ $label = $this->getContext()->msg( 'imgmultipageprev' )->text();
+ // on the client side, this link is generated in ajaxifyPageNavigation()
+ // in the mediawiki.page.image.pagination module
+ $link = Linker::linkKnown(
+ $this->getTitle(),
+ $label,
+ [],
+ [ 'page' => $page - 1 ]
+ );
+ $thumb1 = Linker::makeThumbLinkObj(
+ $this->getTitle(),
+ $this->displayImg,
+ $link,
+ $label,
+ 'none',
+ [ 'page' => $page - 1 ]
+ );
+ } else {
+ $thumb1 = '';
+ }
+
+ if ( $page < $count ) {
+ $label = $this->getContext()->msg( 'imgmultipagenext' )->text();
+ $link = Linker::linkKnown(
+ $this->getTitle(),
+ $label,
+ [],
+ [ 'page' => $page + 1 ]
+ );
+ $thumb2 = Linker::makeThumbLinkObj(
+ $this->getTitle(),
+ $this->displayImg,
+ $link,
+ $label,
+ 'none',
+ [ 'page' => $page + 1 ]
+ );
+ } else {
+ $thumb2 = '';
+ }
+
+ global $wgScript;
+
+ $formParams = [
+ 'name' => 'pageselector',
+ 'action' => $wgScript,
+ ];
+ $options = [];
+ for ( $i = 1; $i <= $count; $i++ ) {
+ $options[] = Xml::option( $lang->formatNum( $i ), $i, $i == $page );
+ }
+ $select = Xml::tags( 'select',
+ [ 'id' => 'pageselector', 'name' => 'page' ],
+ implode( "\n", $options ) );
+
+ $out->addHTML(
+ ' |