imagepage.php

来自「php 开发的内容管理系统」· PHP 代码 · 共 727 行 · 第 1/2 页

PHP
727
字号
<?php/** * @package MediaWiki *//** * */if( !defined( 'MEDIAWIKI' ) )	die( 1 );require_once( 'Image.php' );/** * Special handling for image description pages * @package MediaWiki */class ImagePage extends Article {	/* private */ var $img;  // Image object this page is shown for	var $mExtraDescription = false;	/**	 * Handler for action=render	 * Include body text only; none of the image extras	 */	function render() {		global $wgOut;		$wgOut->setArticleBodyOnly( true );		$wgOut->addSecondaryWikitext( $this->getContent() );	}	function view() {		global $wgOut, $wgShowEXIF;		$this->img = new Image( $this->mTitle );		if( $this->mTitle->getNamespace() == NS_IMAGE  ) {			if ($wgShowEXIF && $this->img->exists()) {				$exif = $this->img->getExifData();				$showmeta = count($exif) ? true : false;			} else {				$exif = false;				$showmeta = false;			}			if ($this->img->exists())				$wgOut->addHTML($this->showTOC($showmeta));			$this->openShowImage();			# 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() );				$this->viewUpdates();			}			# Show shared description, if needed			if( $this->mExtraDescription ) {				$fol = wfMsg( 'shareddescriptionfollows' );				if( $fol != '-' ) {					$wgOut->addWikiText( $fol );				}				$wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . '</div>' );			}			$this->closeShowImage();			$this->imageHistory();			$this->imageLinks();			if( $exif ) {				global $wgStylePath;				$expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) );				$collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) );				$wgOut->addHTML( "<h2 id=\"metadata\">" . wfMsgHtml( 'metadata' ) . "</h2>\n" );				$wgOut->addWikiText( $this->makeMetadataTable( $exif ) );				$wgOut->addHTML(					"<script type=\"text/javascript\" src=\"$wgStylePath/common/metadata.js\"></script>\n" .					"<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );			}		} else {			Article::view();		}	}	/**	 * Create the TOC	 *	 * @access private	 *	 * @param bool $metadata Whether or not to show the metadata link	 * @return string	 */	function showTOC( $metadata ) {		global $wgLang;		$r = '<ul id="filetoc">			<li><a href="#file">' . $wgLang->getNsText( NS_IMAGE ) . '</a></li>			<li><a href="#filehistory">' . wfMsgHtml( 'imghistory' ) . '</a></li>			<li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' .			($metadata ? '<li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . '		</ul>';		return $r;	}	/**	 * Make a table with metadata to be shown in the output page.	 *	 * @access private	 *	 * @param array $exif The array containing the EXIF data	 * @return string	 */	function makeMetadataTable( $exif ) {		$r = wfMsg( 'metadata-help' ) . "\n\n";		$r .= "{| id=mw_metadata class=mw_metadata\n";		$visibleFields = $this->visibleMetadataFields();		foreach( $exif as $k => $v ) {			$tag = strtolower( $k );			$msg = wfMsg( "exif-$tag" );			$class = "exif-$tag";			if( !in_array( $tag, $visibleFields ) ) {				$class .= ' collapsable';			}			$r .= "|- class=\"$class\"\n";			$r .= "!| $msg\n";			$r .= "|| $v\n";		}		$r .= '|}';		return $r;	}	/**	 * Get a list of EXIF metadata items which should be displayed when	 * the metadata table is collapsed.	 *	 * @return array of strings	 * @access private	 */	function visibleMetadataFields() {		$fields = array();		$lines = explode( "\n", wfMsgForContent( 'metadata-fields' ) );		foreach( $lines as $line ) {			if( preg_match( '/^\\*\s*(.*?)\s*$/', $line, $matches ) ) {				$fields[] = $matches[1];			}		}		return $fields;	}	/**	 * Overloading Article's getContent method.	 * 	 * Omit noarticletext if sharedupload; text will be fetched from the	 * shared upload server if possible.	 */	function getContent() {		if( $this->img && $this->img->fromSharedDirectory && 0 == $this->getID() ) {			return '';		}		return Article::getContent();	}	function openShowImage() {		global $wgOut, $wgUser, $wgImageLimits, $wgRequest;		global $wgUseImageResize, $wgGenerateThumbnailOnParse;		$full_url  = $this->img->getURL();		$anchoropen = '';		$anchorclose = '';		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() ) {			# image			$width = $this->img->getWidth();			$height = $this->img->getHeight();			$showLink = false;			if ( $this->img->allowInlineDisplay() and $width and $height) {				# image				# "Download high res version" link below the image				$msg = wfMsgHtml('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) );				# We'll show a thumbnail of this image				if ( $width > $maxWidth || $height > $maxHeight ) {					# Calculate the thumbnail size.					# First case, the limiting factor is the width, not the height.					if ( $width / $height >= $maxWidth / $maxHeight ) {						$height = round( $height * $maxWidth / $width);						$width = $maxWidth;						# Note that $height <= $maxHeight now.					} else {						$newwidth = floor( $width * $maxHeight / $height);						$height = round( $height * $newwidth / $width );						$width = $newwidth;						# Note that $height <= $maxHeight now, but might not be identical						# because of rounding.					}					if( $wgUseImageResize ) {						$thumbnail = $this->img->getThumbnail( $width, -1, $wgGenerateThumbnailOnParse );						if ( $thumbnail == null ) {							$url = $this->img->getViewURL();						} else {							$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 = $this->img->getViewURL();					}					$anchoropen  = "<a href=\"{$full_url}\">";					$anchorclose = "</a><br />";					if( $this->img->mustRender() ) {						$showLink = true;					} else {						$anchorclose .= "\n$anchoropen{$msg}</a>";					}				} else {					$url = $this->img->getViewURL();					$showLink = true;				}				$wgOut->addHTML( '<div class="fullImageLink" id="file">' . $anchoropen .				     "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" .				     htmlspecialchars( $wgRequest->getVal( 'image' ) ).'" />' . $anchorclose . '</div>' );			} else {				#if direct link is allowed but it's not a renderable image, show an icon.				if ($this->img->isSafeFile()) {					$icon= $this->img->iconThumb();					$wgOut->addHTML( '<div class="fullImageLink" id="file"><a href="' . $full_url . '">' .					$icon->toHtml() .					'</a></div>' );				}				$showLink = true;			}			if ($showLink) {				$filename = wfEscapeWikiText( $this->img->getName() );				$info = wfMsg( 'fileinfo',					ceil($this->img->getSize()/1024.0),					$this->img->getMimeType() );				global $wgContLang;				$dirmark = $wgContLang->getDirMark();				if (!$this->img->isSafeFile()) {					$warning = wfMsg( 'mediawarning' );					$wgOut->addWikiText( <<<END<div class="fullMedia"><span class="dangerousLink">[[Media:$filename|$filename]]</span>$dirmark<span class="fileInfo"> ($info)</span></div><div class="mediaWarning">$warning</div>END						);				} else {					$wgOut->addWikiText( <<<END<div class="fullMedia">[[Media:$filename|$filename]]$dirmark <span class="fileInfo"> ($info)</span></div>END						);				}			}			if($this->img->fromSharedDirectory) {				$this->printSharedImageText();			}		} else {			# Image does not exist			$title = Title::makeTitle( NS_SPECIAL, 'Upload' );			$link = $sk->makeKnownLinkObj($title, wfMsgHtml('noimage-linktext'),				'wpDestFile=' . urlencode( $this->img->getName() ) );			$wgOut->addHTML( wfMsgWikiHtml( 'noimage', $link ) );		}	}	function printSharedImageText() {		global $wgRepositoryBaseUrl, $wgFetchCommonsDescriptions, $wgOut, $wgUser;		$url = $wgRepositoryBaseUrl . urlencode($this->mTitle->getDBkey());		$sharedtext = "<div class='sharedUploadNotice'>" . wfMsgWikiHtml("sharedupload");		if ($wgRepositoryBaseUrl && !$wgFetchCommonsDescriptions) {			$sk = $wgUser->getSkin();			$title = Title::makeTitle( NS_SPECIAL, 'Upload' );			$link = $sk->makeKnownLinkObj($title, wfMsgHtml('shareduploadwiki-linktext'),			array( 'wpDestFile' => urlencode( $this->img->getName() )));			$sharedtext .= " " . wfMsgWikiHtml('shareduploadwiki', $link);		}		$sharedtext .= "</div>";		$wgOut->addHTML($sharedtext);		if ($wgRepositoryBaseUrl && $wgFetchCommonsDescriptions) {			require_once("HttpFunctions.php");			$ur = ini_set('allow_url_fopen', true);			$text = wfGetHTTP($url . '?action=render');			ini_set('allow_url_fopen', $ur);			if ($text)				$this->mExtraDescription = $text;		}	}	function getUploadUrl() {		global $wgServer;		$uploadTitle = Title::makeTitle( NS_SPECIAL, 'Upload' );		return $wgServer . $uploadTitle->getLocalUrl( 'wpDestFile=' . urlencode( $this->img->getName() ) );	}	/**	 * Print out the various links at the bottom of the image page, e.g. reupload,	 * external editing (and instructions link) etc.	 */	function uploadLinksBox() {		global $wgUser, $wgOut;		if( $this->img->fromSharedDirectory )			return;		$sk = $wgUser->getSkin();				$wgOut->addHtml( '<br /><ul>' );				# "Upload a new version of this file" link		if( $wgUser->isAllowed( 'reupload' ) ) {			$ulink = $sk->makeExternalLink( $this->getUploadUrl(), wfMsg( 'uploadnewversion-linktext' ) );			$wgOut->addHtml( "<li><div>{$ulink}</div></li>" );		}				# External editing link		$elink = $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'edit-externally' ), 'action=edit&externaledit=true&mode=file' );		$wgOut->addHtml( '<li>' . $elink . '<div>' . wfMsgWikiHtml( 'edit-externally-help' ) . '</div></li>' );				$wgOut->addHtml( '</ul>' );	}	function closeShowImage()	{		# For overloading	}	/**	 * If the page we've just displayed is in the "Image" namespace,

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?