imagepage.php

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

PHP
727
字号
	 * we follow it with an upload history of the image and its usage.	 */	function imageHistory()	{		global $wgUser, $wgOut, $wgUseExternalEditor;		$sk = $wgUser->getSkin();		$line = $this->img->nextHistoryLine();		if ( $line ) {			$list =& new ImageHistoryList( $sk );			$s = $list->beginImageHistoryList() .				$list->imageHistoryLine( true, wfTimestamp(TS_MW, $line->img_timestamp),					$this->mTitle->getDBkey(),  $line->img_user,					$line->img_user_text, $line->img_size, $line->img_description,					$line->img_width, $line->img_height				);			while ( $line = $this->img->nextHistoryLine() ) {				$s .= $list->imageHistoryLine( false, $line->img_timestamp,			  		$line->oi_archive_name, $line->img_user,			  		$line->img_user_text, $line->img_size, $line->img_description,					$line->img_width, $line->img_height				);			}			$s .= $list->endImageHistoryList();		} else { $s=''; }		$wgOut->addHTML( $s );		# Exist check because we don't want to show this on pages where an image		# doesn't exist along with the noimage message, that would suck. -忙var		if( $wgUseExternalEditor && $this->img->exists() ) {			$this->uploadLinksBox();		}	}	function imageLinks()	{		global $wgUser, $wgOut;		$wgOut->addHTML( '<h2 id="filelinks">' . wfMsg( 'imagelinks' ) . "</h2>\n" );		$dbr =& wfGetDB( DB_SLAVE );		$page = $dbr->tableName( 'page' );		$imagelinks = $dbr->tableName( 'imagelinks' );		$sql = "SELECT page_namespace,page_title FROM $imagelinks,$page WHERE il_to=" .		  $dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=page_id";		$sql = $dbr->limitResult($sql, 500, 0);		$res = $dbr->query( $sql, "ImagePage::imageLinks" );		if ( 0 == $dbr->numRows( $res ) ) {			$wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );			return;		}		$wgOut->addHTML( '<p>' . wfMsg( 'linkstoimage' ) .  "</p>\n<ul>" );		$sk = $wgUser->getSkin();		while ( $s = $dbr->fetchObject( $res ) ) {			$name = Title::MakeTitle( $s->page_namespace, $s->page_title );			$link = $sk->makeKnownLinkObj( $name, "" );			$wgOut->addHTML( "<li>{$link}</li>\n" );		}		$wgOut->addHTML( "</ul>\n" );	}	function delete()	{		global $wgUser, $wgOut, $wgRequest;		$confirm = $wgRequest->wasPosted();		$image = $wgRequest->getVal( 'image' );		$oldimage = $wgRequest->getVal( 'oldimage' );		# Only sysops can delete images. Previously ordinary users could delete		# old revisions, but this is no longer the case.		if ( !$wgUser->isAllowed('delete') ) {			$wgOut->sysopRequired();			return;		}		if ( $wgUser->isBlocked() ) {			return $this->blockedIPpage();		}		if ( wfReadOnly() ) {			$wgOut->readOnlyPage();			return;		}		# Better double-check that it hasn't been deleted yet!		$wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );		if ( ( !is_null( $image ) )		  && ( '' == trim( $image ) ) ) {			$wgOut->showFatalError( wfMsg( 'cannotdelete' ) );			return;		}		$this->img  = new Image( $this->mTitle );		# Deleting old images doesn't require confirmation		if ( !is_null( $oldimage ) || $confirm ) {			if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {				$this->doDelete();			} else {				$wgOut->showFatalError( wfMsg( 'sessionfailure' ) );			}			return;		}		if ( !is_null( $image ) ) {			$q = '&image=' . urlencode( $image );		} else if ( !is_null( $oldimage ) ) {			$q = '&oldimage=' . urlencode( $oldimage );		} else {			$q = '';		}		return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );	}	function doDelete()	{		global $wgOut, $wgRequest, $wgUseSquid;		global $wgPostCommitUpdateList;		$fname = 'ImagePage::doDelete';		$reason = $wgRequest->getVal( 'wpReason' );		$oldimage = $wgRequest->getVal( 'oldimage' );		$dbw =& wfGetDB( DB_MASTER );		if ( !is_null( $oldimage ) ) {			if ( strlen( $oldimage ) < 16 ) {				$wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );				return;			}			if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {				$wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );				return;			}			if ( !$this->doDeleteOldImage( $oldimage ) ) {				return;			}			$deleted = $oldimage;		} else {			$ok = $this->img->delete( $reason );			if( !$ok ) {				# If the deletion operation actually failed, bug out:				$wgOut->showFileDeleteError( $this->img->getName() );				return;			}						# Image itself is now gone, and database is cleaned.			# Now we remove the image description page.				$article = new Article( $this->mTitle );			$article->doDeleteArticle( $reason ); # ignore errors			$deleted = $this->img->getName();		}		$wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );		$wgOut->setRobotpolicy( 'noindex,nofollow' );		$loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';		$text = wfMsg( 'deletedtext', $deleted, $loglink );		$wgOut->addWikiText( $text );		$wgOut->returnToMain( false, $this->mTitle->getPrefixedText() );	}	/**	 * @return success	 */	function doDeleteOldImage( $oldimage )	{		global $wgOut;		$ok = $this->img->deleteOld( $oldimage, '' );		if( !$ok ) {			# If we actually have a file and can't delete it, throw an error.			# Something went awry...			$wgOut->showFileDeleteError( "$oldimage" );		} else {			# Log the deletion			$log = new LogPage( 'delete' );			$log->addEntry( 'delete', $this->mTitle, wfMsg('deletedrevision',$oldimage) );		}		return $ok;	}	function revert() {		global $wgOut, $wgRequest, $wgUser;		$oldimage = $wgRequest->getText( 'oldimage' );		if ( strlen( $oldimage ) < 16 ) {			$wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );			return;		}		if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {			$wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );			return;		}		if ( wfReadOnly() ) {			$wgOut->readOnlyPage();			return;		}		if( $wgUser->isAnon() ) {			$wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );			return;		}		if ( ! $this->mTitle->userCanEdit() ) {			$wgOut->sysopRequired();			return;		}		if ( $wgUser->isBlocked() ) {			return $this->blockedIPpage();		}		if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {			$wgOut->showErrorPage( 'internalerror', 'sessionfailure' );			return;		}		$name = substr( $oldimage, 15 );		$dest = wfImageDir( $name );		$archive = wfImageArchiveDir( $name );		$curfile = "{$dest}/{$name}";		if ( !is_dir( $dest ) ) wfMkdirParents( $dest );		if ( !is_dir( $archive ) ) wfMkdirParents( $archive );		if ( ! is_file( $curfile ) ) {			$wgOut->showFileNotFoundError( htmlspecialchars( $curfile ) );			return;		}		$oldver = wfTimestampNow() . "!{$name}";		$dbr =& wfGetDB( DB_SLAVE );		$size = $dbr->selectField( 'oldimage', 'oi_size', array( 'oi_archive_name' => $oldimage )  );		if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {			$wgOut->showFileRenameError( $curfile, "${archive}/{$oldver}" );			return;		}		if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {			$wgOut->showFileCopyError( "${archive}/{$oldimage}", $curfile );			return;		}		# 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' ) );		$descTitle = $img->getTitle();		$wgOut->returnToMain( false, $descTitle->getPrefixedText() );	}	function blockedIPpage() {		$edit = new EditPage( $this );		return $edit->blockedIPpage();	}		/**	 * Override handling of action=purge	 */	function doPurge() {		$this->img = new Image( $this->mTitle );		if( $this->img->exists() ) {			wfDebug( "ImagePage::doPurge purging " . $this->img->getName() . "\n" );			$update = new HTMLCacheUpdate( $this->mTitle, 'imagelinks' );			$update->doUpdate();			$this->img->purgeCache();		} else {			wfDebug( "ImagePage::doPurge no image\n" );		}		parent::doPurge();	}}/** * @todo document * @package MediaWiki */class ImageHistoryList {	function ImageHistoryList( &$skin ) {		$this->skin =& $skin;	}	function beginImageHistoryList() {		$s = "\n<h2 id=\"filehistory\">" . wfMsg( 'imghistory' ) . "</h2>\n" .		  "<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';		return $s;	}	function endImageHistoryList() {		$s = "</ul>\n";		return $s;	}	function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description, $width, $height ) {		global $wgUser, $wgLang, $wgTitle, $wgContLang;		$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 = '<a href="'.$link.'"'.$style.'>'.$delall.'</a>';			} 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;			}		}				$userlink = $this->skin->userLink( $user, $usertext ) . $this->skin->userToolLinks( $user, $usertext );		$nbytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),			$wgLang->formatNum( $size ) );		$widthheight = wfMsg( 'widthheight', $width, $height );		$style = $this->skin->getInternalLinkAttributes( $url, $datetime );		$s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a> . . {$userlink} . . {$widthheight} ({$nbytes})";		$s .= $this->skin->commentBlock( $description, $wgTitle );		$s .= "</li>\n";		return $s;	}}?>

⌨️ 快捷键说明

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