skintemplate.php

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

PHP
1,125
字号
		$tpl->setRef( 'debug', $out->mDebugtext );		$tpl->set( 'reporttime', $out->reportTime() );		$tpl->set( 'sitenotice', wfGetSiteNotice() );		$printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";		$out->mBodytext .= $printfooter ;		$tpl->setRef( 'bodytext', $out->mBodytext );		# Language links		$language_urls = array();		if ( !$wgHideInterlanguageLinks ) {			foreach( $wgOut->getLanguageLinks() as $l ) {				$tmp = explode( ':', $l, 2 );				$class = 'interwiki-' . $tmp[0];				unset($tmp);				$nt = Title::newFromText( $l );				$language_urls[] = array(					'href' => $nt->getFullURL(),					'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),					'class' => $class				);			}		}		if(count($language_urls)) {			$tpl->setRef( 'language_urls', $language_urls);		} else {			$tpl->set('language_urls', false);		}		wfProfileOut( "$fname-stuff4" );		# Personal toolbar		$tpl->set('personal_urls', $this->buildPersonalUrls());		$content_actions = $this->buildContentActionUrls();		$tpl->setRef('content_actions', $content_actions);		// XXX: attach this from javascript, same with section editing		if($this->iseditable &&	$wgUser->getOption("editondblclick") )		{			$tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');		} else {			$tpl->set('body_ondblclick', false);		}		if( $this->iseditable && $wgUser->getOption( 'editsectiononrightclick' ) ) {			$tpl->set( 'body_onload', 'setupRightClickEdit()' );		} else {			$tpl->set( 'body_onload', false );		}		$tpl->set( 'sidebar', $this->buildSidebar() );		$tpl->set( 'nav_urls', $this->buildNavUrls() );		// execute template		wfProfileIn( "$fname-execute" );		$res = $tpl->execute();		wfProfileOut( "$fname-execute" );		// result may be an error		$this->printOrError( $res );		wfProfileOut( $fname );	}	/**	 * Output the string, or print error message if it's	 * an error object of the appropriate type.	 * For the base class, assume strings all around.	 *	 * @param mixed $str	 * @private	 */	function printOrError( &$str ) {		echo $str;	}	/**	 * build array of urls for personal toolbar	 * @return array	 * @private	 */	function buildPersonalUrls() {		global $wgTitle, $wgShowIPinHeader;		$fname = 'SkinTemplate::buildPersonalUrls';		$pageurl = $wgTitle->getLocalURL();		wfProfileIn( $fname );		/* set up the default links for the personal toolbar */		$personal_urls = array();		if ($this->loggedin) {			$personal_urls['userpage'] = array(				'text' => $this->username,				'href' => &$this->userpageUrlDetails['href'],				'class' => $this->userpageUrlDetails['exists']?false:'new',				'active' => ( $this->userpageUrlDetails['href'] == $pageurl )			);			$usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);			$personal_urls['mytalk'] = array(				'text' => wfMsg('mytalk'),				'href' => &$usertalkUrlDetails['href'],				'class' => $usertalkUrlDetails['exists']?false:'new',				'active' => ( $usertalkUrlDetails['href'] == $pageurl )			);			$href = $this->makeSpecialUrl('Preferences');			$personal_urls['preferences'] = array(				'text' => wfMsg('preferences'),				'href' => $this->makeSpecialUrl('Preferences'),				'active' => ( $href == $pageurl )			);			$href = $this->makeSpecialUrl('Watchlist');			$personal_urls['watchlist'] = array(				'text' => wfMsg('watchlist'),				'href' => $href,				'active' => ( $href == $pageurl )			);			$href = $this->makeSpecialUrl("Contributions/$this->username");			$personal_urls['mycontris'] = array(				'text' => wfMsg('mycontris'),				'href' => $href				# FIXME #  'active' => ( $href == $pageurl . '/' . $this->username )			);			$personal_urls['logout'] = array(				'text' => wfMsg('userlogout'),				'href' => $this->makeSpecialUrl( 'Userlogout',					$wgTitle->getNamespace() === NS_SPECIAL && $wgTitle->getText() === 'Preferences' ? '' : "returnto={$this->thisurl}"				)			);		} else {			if( $wgShowIPinHeader && isset(  $_COOKIE[ini_get("session.name")] ) ) {				$href = &$this->userpageUrlDetails['href'];				$personal_urls['anonuserpage'] = array(					'text' => $this->username,					'href' => $href,					'class' => $this->userpageUrlDetails['exists']?false:'new',					'active' => ( $pageurl == $href )				);				$usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);				$href = &$usertalkUrlDetails['href'];				$personal_urls['anontalk'] = array(					'text' => wfMsg('anontalk'),					'href' => $href,					'class' => $usertalkUrlDetails['exists']?false:'new',					'active' => ( $pageurl == $href )				);				$personal_urls['anonlogin'] = array(					'text' => wfMsg('userlogin'),					'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl ),					'active' => ( NS_SPECIAL == $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )				);			} else {				$personal_urls['login'] = array(					'text' => wfMsg('userlogin'),					'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl ),					'active' => ( NS_SPECIAL == $wgTitle->getNamespace() && 'Userlogin' == $wgTitle->getDBkey() )				);			}		}		wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );				wfProfileOut( $fname );		return $personal_urls;	}	/**	 * Returns true if the IP should be shown in the header	 */	function showIPinHeader() {		global $wgShowIPinHeader;		return $wgShowIPinHeader && isset(  $_COOKIE[ini_get("session.name")] );	}	function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {		$classes = array();		if( $selected ) {			$classes[] = 'selected';		}		if( $checkEdit && $title->getArticleId() == 0 ) {			$classes[] = 'new';			$query = 'action=edit';		}		$text = wfMsg( $message );		if ( $text == "&lt;$message&gt;" ) {			global $wgContLang;			$text = $wgContLang->getNsText( Namespace::getSubject( $title->getNamespace() ) );		}		return array(			'class' => implode( ' ', $classes ),			'text' => $text,			'href' => $title->getLocalUrl( $query ) );	}	function makeTalkUrlDetails( $name, $urlaction='' ) {		$title = Title::newFromText( $name );		$title = $title->getTalkPage();		$this->checkTitle($title, $name);		return array(			'href' => $title->getLocalURL( $urlaction ),			'exists' => $title->getArticleID() != 0?true:false		);	}	function makeArticleUrlDetails( $name, $urlaction='' ) {		$title = Title::newFromText( $name );		$title= $title->getSubjectPage();		$this->checkTitle($title, $name);		return array(			'href' => $title->getLocalURL( $urlaction ),			'exists' => $title->getArticleID() != 0?true:false		);	}	/**	 * an array of edit links by default used for the tabs	 * @return array	 * @private	 */	function buildContentActionUrls () {		global $wgContLang, $wgOut;		$fname = 'SkinTemplate::buildContentActionUrls';		wfProfileIn( $fname );		global $wgUser, $wgRequest;		$action = $wgRequest->getText( 'action' );		$section = $wgRequest->getText( 'section' );		$content_actions = array();		$prevent_active_tabs = false ;		wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) )	;		if( $this->iscontent ) {			$subjpage = $this->mTitle->getSubjectPage();			$talkpage = $this->mTitle->getTalkPage();			$nskey = $this->mTitle->getNamespaceKey();			$content_actions[$nskey] = $this->tabAction(				$subjpage,				$nskey,				!$this->mTitle->isTalkPage() && !$prevent_active_tabs,				'', true);			$content_actions['talk'] = $this->tabAction(				$talkpage,				'talk',				$this->mTitle->isTalkPage() && !$prevent_active_tabs,				'',				true);			wfProfileIn( "$fname-edit" );			if ( $this->mTitle->userCanEdit() && ( $this->mTitle->exists() || $this->mTitle->userCanCreate() ) ) {				$istalk = $this->mTitle->isTalkPage();				$istalkclass = $istalk?' istalk':'';				$content_actions['edit'] = array(					'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,					'text' => wfMsg('edit'),					'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )				);				if ( $istalk || $wgOut->showNewSectionLink() ) {					$content_actions['addsection'] = array(						'class' => $section == 'new'?'selected':false,						'text' => wfMsg('addsection'),						'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )					);				}			} else {				$content_actions['viewsource'] = array(					'class' => ($action == 'edit') ? 'selected' : false,					'text' => wfMsg('viewsource'),					'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )				);			}			wfProfileOut( "$fname-edit" );			wfProfileIn( "$fname-live" );			if ( $this->mTitle->getArticleId() ) {				$content_actions['history'] = array(					'class' => ($action == 'history') ? 'selected' : false,					'text' => wfMsg('history_short'),					'href' => $this->mTitle->getLocalUrl( 'action=history')				);				if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {					if(!$this->mTitle->isProtected()){						$content_actions['protect'] = array(							'class' => ($action == 'protect') ? 'selected' : false,							'text' => wfMsg('protect'),							'href' => $this->mTitle->getLocalUrl( 'action=protect' )						);					} else {						$content_actions['unprotect'] = array(							'class' => ($action == 'unprotect') ? 'selected' : false,							'text' => wfMsg('unprotect'),							'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )						);					}				}				if($wgUser->isAllowed('delete')){					$content_actions['delete'] = array(						'class' => ($action == 'delete') ? 'selected' : false,						'text' => wfMsg('delete'),						'href' => $this->mTitle->getLocalUrl( 'action=delete' )					);				}				if ( $this->mTitle->userCanMove()) {					$moveTitle = Title::makeTitle( NS_SPECIAL, 'Movepage' );					$content_actions['move'] = array(						'class' => ($this->mTitle->getDbKey() == 'Movepage' and $this->mTitle->getNamespace == NS_SPECIAL) ? 'selected' : false,						'text' => wfMsg('move'),						'href' => $moveTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )					);				}			} else {				//article doesn't exist or is deleted				if( $wgUser->isAllowed( 'delete' ) ) {					if( $n = $this->mTitle->isDeleted() ) {						$undelTitle = Title::makeTitle( NS_SPECIAL, 'Undelete' );						$content_actions['undelete'] = array(							'class' => false,							'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $n ),							'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )							#'href' => $this->makeSpecialUrl("Undelete/$this->thispage")						);					}				}			}			wfProfileOut( "$fname-live" );			if( $this->loggedin ) {				if( !$this->mTitle->userIsWatching()) {					$content_actions['watch'] = array(						'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,						'text' => wfMsg('watch'),						'href' => $this->mTitle->getLocalUrl( 'action=watch' )					);				} else {					$content_actions['unwatch'] = array(						'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,						'text' => wfMsg('unwatch'),						'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )					);				}			}			wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) )	;		} else {			/* show special page tab */			$content_actions['article'] = array(				'class' => 'selected',				'text' => wfMsg('specialpage'),				'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510			);			wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );		}		/* show links to different language variants */		global $wgDisableLangConversion;		$variants = $wgContLang->getVariants();		if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {			$preferred = $wgContLang->getPreferredVariant();			$actstr = '';			if( $action )				$actstr = 'action=' . $action . '&';			$vcount=0;			foreach( $variants as $code ) {				$varname = $wgContLang->getVariantname( $code );				if( $varname == 'disable' )					continue;				$selected = ( $code == $preferred )? 'selected' : false;				$content_actions['varlang-' . $vcount] = array(						'class' => $selected,

⌨️ 快捷键说明

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