skin.php

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

PHP
1,500
字号
		$mp = wfMsg( 'mainpage' );		$titleObj = Title::newFromText( $mp );		if ( is_object( $titleObj ) ) {			$url = $titleObj->escapeLocalURL();		} else {			$url = '';		}		$logourl = $this->getLogo();		$s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";		return $s;	}	/**	 * show a drop-down box of special pages	 * @TODO crash bug913. Need to be rewrote completly.	 */	function specialPagesList() {		global $wgUser, $wgContLang, $wgServer, $wgRedirectScript, $wgAvailableRights;		require_once('SpecialPage.php');		$a = array();		$pages = SpecialPage::getPages();		// special pages without access restriction		foreach ( $pages[''] as $name => $page ) {			$a[$name] = $page->getDescription();		}		// Other special pages that are restricted.		// Copied from SpecialSpecialpages.php		foreach($wgAvailableRights as $right) {			if( $wgUser->isAllowed($right) ) {				/** Add all pages for this right */				if(isset($pages[$right])) {					foreach($pages[$right] as $name => $page) {					$a[$name] = $page->getDescription();					}				}			}		}		$go = wfMsg( 'go' );		$sp = wfMsg( 'specialpages' );		$spp = $wgContLang->specialPage( 'Specialpages' );		$s = '<form id="specialpages" method="get" class="inline" ' .		  'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";		$s .= "<select name=\"wpDropdown\">\n";		$s .= "<option value=\"{$spp}\">{$sp}</option>\n";		foreach ( $a as $name => $desc ) {			$p = $wgContLang->specialPage( $name );			$s .= "<option value=\"{$p}\">{$desc}</option>\n";		}		$s .= "</select>\n";		$s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";		$s .= "</form>\n";		return $s;	}	function mainPageLink() {		$mp = wfMsgForContent( 'mainpage' );		$mptxt = wfMsg( 'mainpage');		$s = $this->makeKnownLink( $mp, $mptxt );		return $s;	}	function copyrightLink() {		$s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),		  wfMsg( 'copyrightpagename' ) );		return $s;	}	function privacyLink() {		$privacy = wfMsg( 'privacy' );		if ($privacy == '-') {			return '';		} else {			return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);		}	}	function aboutLink() {		$s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),		  wfMsg( 'aboutsite' ) );		return $s;	}	function disclaimerLink() {		$disclaimers = wfMsg( 'disclaimers' );		if ($disclaimers == '-') {			return '';		} else {			return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),			                             $disclaimers );		}	}	function editThisPage() {		global $wgOut, $wgTitle;		if ( ! $wgOut->isArticleRelated() ) {			$s = wfMsg( 'protectedpage' );		} else {			if ( $wgTitle->userCanEdit() ) {				$t = wfMsg( 'editthispage' );			} else {				$t = wfMsg( 'viewsource' );			}			$s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );		}		return $s;	}	/**	 * Return URL options for the 'edit page' link.	 * This may include an 'oldid' specifier, if the current page view is such.	 *	 * @return string	 * @private	 */	function editUrlOptions() {		global $wgArticle;		if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {			return "action=edit&oldid=" . intval( $this->mRevisionId );		} else {			return "action=edit";		}	}	function deleteThisPage() {		global $wgUser, $wgTitle, $wgRequest;		$diff = $wgRequest->getVal( 'diff' );		if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {			$t = wfMsg( 'deletethispage' );			$s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );		} else {			$s = '';		}		return $s;	}	function protectThisPage() {		global $wgUser, $wgTitle, $wgRequest;		$diff = $wgRequest->getVal( 'diff' );		if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {			if ( $wgTitle->isProtected() ) {				$t = wfMsg( 'unprotectthispage' );				$q = 'action=unprotect';			} else {				$t = wfMsg( 'protectthispage' );				$q = 'action=protect';			}			$s = $this->makeKnownLinkObj( $wgTitle, $t, $q );		} else {			$s = '';		}		return $s;	}	function watchThisPage() {		global $wgOut, $wgTitle;		if ( $wgOut->isArticleRelated() ) {			if ( $wgTitle->userIsWatching() ) {				$t = wfMsg( 'unwatchthispage' );				$q = 'action=unwatch';			} else {				$t = wfMsg( 'watchthispage' );				$q = 'action=watch';			}			$s = $this->makeKnownLinkObj( $wgTitle, $t, $q );		} else {			$s = wfMsg( 'notanarticle' );		}		return $s;	}	function moveThisPage() {		global $wgTitle;		if ( $wgTitle->userCanMove() ) {			return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Movepage' ),			  wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );		} else {			// no message if page is protected - would be redundant			return '';		}	}	function historyLink() {		global $wgTitle;		return $this->makeKnownLinkObj( $wgTitle,		  wfMsg( 'history' ), 'action=history' );	}	function whatLinksHere() {		global $wgTitle;		return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Whatlinkshere' ),		  wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );	}	function userContribsLink() {		global $wgTitle;		return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ),		  wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );	}	function showEmailUser( $id ) {		global $wgEnableEmail, $wgEnableUserEmail, $wgUser;		return $wgEnableEmail &&		       $wgEnableUserEmail &&		       $wgUser->isLoggedIn() && # show only to signed in users		       0 != $id; # we can only email to non-anons ..#		       '' != $id->getEmail() && # who must have an email address stored ..#		       0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated#		       1 != $wgUser->getOption('disablemail'); # and not disabled	}	function emailUserLink() {		global $wgTitle;		return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Emailuser' ),		  wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );	}	function watchPageLinksLink() {		global $wgOut, $wgTitle;		if ( ! $wgOut->isArticleRelated() ) {			return '(' . wfMsg( 'notanarticle' ) . ')';		} else {			return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL,			  'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),			  'target=' . $wgTitle->getPrefixedURL() );		}	}	function trackbackLink() {		global $wgTitle;		return "<a href=\"" . $wgTitle->trackbackURL() . "\">"			. wfMsg('trackbacklink') . "</a>";	}	function otherLanguages() {		global $wgOut, $wgContLang, $wgHideInterlanguageLinks;		if ( $wgHideInterlanguageLinks ) {			return '';		}		$a = $wgOut->getLanguageLinks();		if ( 0 == count( $a ) ) {			return '';		}		$s = wfMsg( 'otherlanguages' ) . ': ';		$first = true;		if($wgContLang->isRTL()) $s .= '<span dir="LTR">';		foreach( $a as $l ) {			if ( ! $first ) { $s .= ' | '; }			$first = false;			$nt = Title::newFromText( $l );			$url = $nt->escapeFullURL();			$text = $wgContLang->getLanguageName( $nt->getInterwiki() );			if ( '' == $text ) { $text = $l; }			$style = $this->getExternalLinkAttributes( $l, $text );			$s .= "<a href=\"{$url}\"{$style}>{$text}</a>";		}		if($wgContLang->isRTL()) $s .= '</span>';		return $s;	}	function bugReportsLink() {		$s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),		  wfMsg( 'bugreports' ) );		return $s;	}	function dateLink() {		$t1 = Title::newFromText( gmdate( 'F j' ) );		$t2 = Title::newFromText( gmdate( 'Y' ) );		$id = $t1->getArticleID();		if ( 0 == $id ) {			$s = $this->makeBrokenLink( $t1->getText() );		} else {			$s = $this->makeKnownLink( $t1->getText() );		}		$s .= ', ';		$id = $t2->getArticleID();		if ( 0 == $id ) {			$s .= $this->makeBrokenLink( $t2->getText() );		} else {			$s .= $this->makeKnownLink( $t2->getText() );		}		return $s;	}	function talkLink() {		global $wgTitle;		if ( NS_SPECIAL == $wgTitle->getNamespace() ) {			# No discussion links for special pages			return '';		}		if( $wgTitle->isTalkPage() ) {			$link = $wgTitle->getSubjectPage();			switch( $link->getNamespace() ) {			case NS_MAIN:				$text = wfMsg('articlepage');				break;			case NS_USER:				$text = wfMsg('userpage');				break;			case NS_PROJECT:				$text = wfMsg('projectpage');				break;			case NS_IMAGE:				$text = wfMsg('imagepage');				break;			default:				$text= wfMsg('articlepage');			}		} else {			$link = $wgTitle->getTalkPage();			$text = wfMsg( 'talkpage' );		}		$s = $this->makeLinkObj( $link, $text );		return $s;	}	function commentLink() {		global $wgTitle, $wgOut;		if ( $wgTitle->getNamespace() == NS_SPECIAL ) {			return '';		}				# __NEWSECTIONLINK___ changes behaviour here		# If it's present, the link points to this page, otherwise		# it points to the talk page		if( $wgTitle->isTalkPage() ) {			$title =& $wgTitle;		} elseif( $wgOut->showNewSectionLink() ) {			$title =& $wgTitle;		} else {			$title =& $wgTitle->getTalkPage();		}				return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit&section=new' );	}	/* these are used extensively in SkinTemplate, but also some other places */	/*static*/ function makeSpecialUrl( $name, $urlaction='' ) {		$title = Title::makeTitle( NS_SPECIAL, $name );		return $title->getLocalURL( $urlaction );	}	/*static*/ function makeI18nUrl ( $name, $urlaction='' ) {		$title = Title::newFromText( wfMsgForContent($name) );		$this->checkTitle($title, $name);		return $title->getLocalURL( $urlaction );	}	/*static*/ function makeUrl ( $name, $urlaction='' ) {		$title = Title::newFromText( $name );		$this->checkTitle($title, $name);		return $title->getLocalURL( $urlaction );	}	# If url string starts with http, consider as external URL, else	# internal	/*static*/ function makeInternalOrExternalUrl( $name ) {		if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {			return $name;		} else {			return $this->makeUrl( $name );		}	}	# this can be passed the NS number as defined in Language.php	/*static*/ function makeNSUrl( $name, $urlaction='', $namespace=NS_MAIN ) {		$title = Title::makeTitleSafe( $namespace, $name );		$this->checkTitle($title, $name);		return $title->getLocalURL( $urlaction );	}	/* these return an array with the 'href' and boolean 'exists' */	/*static*/ function makeUrlDetails ( $name, $urlaction='' ) {		$title = Title::newFromText( $name );		$this->checkTitle($title, $name);		return array(			'href' => $title->getLocalURL( $urlaction ),			'exists' => $title->getArticleID() != 0?true:false		);	}	/**	 * Make URL details where the article exists (or at least it's convenient to think so)	 */	function makeKnownUrlDetails( $name, $urlaction='' ) {		$title = Title::newFromText( $name );		$this->checkTitle($title, $name);		return array(			'href' => $title->getLocalURL( $urlaction ),			'exists' => true		);	}	# make sure we have some title to operate on	/*static*/ function checkTitle ( &$title, &$name ) {		if(!is_object($title)) {			$title = Title::newFromText( $name );			if(!is_object($title)) {				$title = Title::newFromText( '--error: link target missing--' );			}		}	}	/**	 * Build an array that represents the sidebar(s), the navigation bar among them	 *	 * @return array	 * @private	 */	function buildSidebar() {		global $wgDBname, $parserMemc, $wgEnableSidebarCache;		global $wgLanguageCode, $wgContLanguageCode;		$fname = 'SkinTemplate::buildSidebar';		wfProfileIn( $fname );		$key = "{$wgDBname}:sidebar";		$cacheSidebar = $wgEnableSidebarCache &&			($wgLanguageCode == $wgContLanguageCode);				if ($cacheSidebar) {			$cachedsidebar = $parserMemc->get( $key );			if ($cachedsidebar!="") {				wfProfileOut($fname);				return $cachedsidebar;			}		}		$bar = array();		$lines = explode( "\n", wfMsgForContent( 'sidebar' ) );		foreach ($lines as $line) {			if (strpos($line, '*') !== 0)				continue;			if (strpos($line, '**') !== 0) {				$line = trim($line, '* ');				$heading = $line;			} else {				if (strpos($line, '|') !== false) { // sanity check					$line = explode( '|' , trim($line, '* '), 2 );					$link = wfMsgForContent( $line[0] );					if ($link == '-')						continue;					if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))						$text = $line[1];					if (wfEmptyMsg($line[0], $link))						$link = $line[0];					$href = $this->makeInternalOrExternalUrl( $link );					$bar[$heading][] = array(						'text' => $text,						'href' => $href,						'id' => 'n-' . strtr($line[1], ' ', '-'),						'active' => false					);				} else { continue; }			}		}		if ($cacheSidebar)			$cachednotice = $parserMemc->set( $key, $bar, 86400 );		wfProfileOut( $fname );		return $bar;	}}?>

⌨️ 快捷键说明

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