skintemplate.php
来自「php 开发的内容管理系统」· PHP 代码 · 共 1,125 行 · 第 1/3 页
PHP
1,125 行
<?phpif ( ! defined( 'MEDIAWIKI' ) ) die( 1 );# This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License along# with this program; if not, write to the Free Software Foundation, Inc.,# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.# http://www.gnu.org/copyleft/gpl.html/** * Template-filler skin base class * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin * Based on Brion's smarty skin * Copyright (C) Gabriel Wicke -- http://www.aulinx.de/ * * Todo: Needs some serious refactoring into functions that correspond * to the computations individual esi snippets need. Most importantly no body * parsing for most of those of course. * * @package MediaWiki * @subpackage Skins */require_once 'GlobalFunctions.php';/** * Wrapper object for MediaWiki's localization functions, * to be passed to the template engine. * * @private * @package MediaWiki */class MediaWiki_I18N { var $_context = array(); function set($varName, $value) { $this->_context[$varName] = $value; } function translate($value) { $fname = 'SkinTemplate-translate'; wfProfileIn( $fname ); // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23 $value = preg_replace( '/^string:/', '', $value ); $value = wfMsg( $value ); // interpolate variables while (preg_match('/\$([0-9]*?)/sm', $value, $m)) { list($src, $var) = $m; wfSuppressWarnings(); $varValue = $this->_context[$var]; wfRestoreWarnings(); $value = str_replace($src, $varValue, $value); } wfProfileOut( $fname ); return $value; }}/** * * @package MediaWiki */class SkinTemplate extends Skin { /**#@+ * @private */ /** * Name of our skin, set in initPage() * It probably need to be all lower case. */ var $skinname; /** * Stylesheets set to use * Sub directory in ./skins/ where various stylesheets are located */ var $stylename; /** * For QuickTemplate, the name of the subclass which * will actually fill the template. */ var $template; /**#@-*/ /** * Setup the base parameters... * Child classes should override this to set the name, * style subdirectory, and template filler callback. * * @param OutputPage $out */ function initPage( &$out ) { parent::initPage( $out ); $this->skinname = 'monobook'; $this->stylename = 'monobook'; $this->template = 'QuickTemplate'; } /** * Create the template engine object; we feed it a bunch of data * and eventually it spits out some HTML. Should have interface * roughly equivalent to PHPTAL 0.7. * * @param string $callback (or file) * @param string $repository subdirectory where we keep template files * @param string $cache_dir * @return object * @private */ function setupTemplate( $classname, $repository=false, $cache_dir=false ) { return new $classname(); } /** * initialize various variables and generate the template * * @param OutputPage $out * @public */ function outputPage( &$out ) { global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut; global $wgScript, $wgStylePath, $wgContLanguageCode; global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest; global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks; global $wgMaxCredits, $wgShowCreditsIfMax; global $wgPageShowWatchingUsers; global $wgUseTrackbacks; global $wgDBname; $fname = 'SkinTemplate::outputPage'; wfProfileIn( $fname ); // Hook that allows last minute changes to the output page, e.g. // adding of CSS or Javascript by extensions. wfRunHooks( 'BeforePageDisplay', array( &$out ) ); extract( $wgRequest->getValues( 'oldid', 'diff' ) ); wfProfileIn( "$fname-init" ); $this->initPage( $out ); $this->mTitle =& $wgTitle; $this->mUser =& $wgUser; $tpl = $this->setupTemplate( $this->template, 'skins' ); #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText $tpl->setTranslator(new MediaWiki_I18N()); #} wfProfileOut( "$fname-init" ); wfProfileIn( "$fname-stuff" ); $this->thispage = $this->mTitle->getPrefixedDbKey(); $this->thisurl = $this->mTitle->getPrefixedURL(); $this->loggedin = $wgUser->isLoggedIn(); $this->iscontent = ($this->mTitle->getNamespace() != NS_SPECIAL ); $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit')); $this->username = $wgUser->getName(); $userPage = $wgUser->getUserPage(); $this->userpage = $userPage->getPrefixedText(); if ( $wgUser->isLoggedIn() || $this->showIPinHeader() ) { $this->userpageUrlDetails = $this->makeUrlDetails($this->userpage); } else { # This won't be used in the standard skins, but we define it to preserve the interface # To save time, we check for existence $this->userpageUrlDetails = $this->makeKnownUrlDetails($this->userpage); } $this->usercss = $this->userjs = $this->userjsprev = false; $this->setupUserCss(); $this->setupUserJs(); $this->titletxt = $this->mTitle->getPrefixedText(); wfProfileOut( "$fname-stuff" ); wfProfileIn( "$fname-stuff2" ); $tpl->set( 'title', $wgOut->getPageTitle() ); $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() ); $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle ); $tpl->setRef( "thispage", $this->thispage ); $subpagestr = $this->subPageSubtitle(); $tpl->set( 'subtitle', !empty($subpagestr)? '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle(): $out->getSubtitle() ); $undelete = $this->getUndeleteLink(); $tpl->set( "undelete", !empty($undelete)? '<span class="subpages">'.$undelete.'</span>': '' ); $tpl->set( 'catlinks', $this->getCategories()); if( $wgOut->isSyndicated() ) { $feeds = array(); foreach( $wgFeedClasses as $format => $class ) { $feeds[$format] = array( 'text' => $format, 'href' => $wgRequest->appendQuery( "feed=$format" ) ); } $tpl->setRef( 'feeds', $feeds ); } else { $tpl->set( 'feeds', false ); } if ($wgUseTrackbacks && $out->isArticleRelated()) $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF()); $tpl->setRef( 'mimetype', $wgMimeType ); $tpl->setRef( 'jsmimetype', $wgJsMimeType ); $tpl->setRef( 'charset', $wgOutputEncoding ); $tpl->set( 'headlinks', $out->getHeadLinks() ); $tpl->set('headscripts', $out->getScript() ); $tpl->setRef( 'wgScript', $wgScript ); $tpl->setRef( 'skinname', $this->skinname ); $tpl->setRef( 'stylename', $this->stylename ); $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) ); $tpl->setRef( 'loggedin', $this->loggedin ); $tpl->set('nsclass', 'ns-'.$this->mTitle->getNamespace()); $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL); /* XXX currently unused, might get useful later $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) ); $tpl->set( "exists", $this->mTitle->getArticleID() != 0 ); $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" ); $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" ); $tpl->set( "helppage", wfMsg('helppage')); */ $tpl->set( 'searchaction', $this->escapeSearchLink() ); $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) ); $tpl->setRef( 'stylepath', $wgStylePath ); $tpl->setRef( 'logopath', $wgLogo ); $tpl->setRef( "lang", $wgContLanguageCode ); $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" ); $tpl->set( 'rtl', $wgContLang->isRTL() ); $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) ); $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) ); $tpl->setRef( 'username', $this->username ); $tpl->setRef( 'userpage', $this->userpage); $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']); $tpl->set( 'pagecss', $this->setupPageCss() ); $tpl->setRef( 'usercss', $this->usercss); $tpl->setRef( 'userjs', $this->userjs); $tpl->setRef( 'userjsprev', $this->userjsprev); global $wgUseSiteJs; if ($wgUseSiteJs) { if($this->loggedin) { $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') ); } else { $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') ); } } else { $tpl->set('jsvarurl', false); } $newtalks = $wgUser->getNewMessageLinks(); if (count($newtalks) == 1 && $newtalks[0]["wiki"] === $wgDBname) { $usertitle = $this->mUser->getUserPage(); $usertalktitle = $usertitle->getTalkPage(); if( !$usertalktitle->equals( $this->mTitle ) ) { $ntl = wfMsg( 'youhavenewmessages', $this->makeKnownLinkObj( $usertalktitle, wfMsgHtml( 'newmessageslink' ), 'redirect=no' ), $this->makeKnownLinkObj( $usertalktitle, wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' ) ); # Disable Cache $wgOut->setSquidMaxage(0); } } else if (count($newtalks)) { $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator")); $msgs = array(); foreach ($newtalks as $newtalk) { $msgs[] = wfElement("a", array('href' => $newtalk["link"]), $newtalk["wiki"]); } $parts = implode($sep, $msgs); $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts); $wgOut->setSquidMaxage(0); } else { $ntl = ''; } wfProfileOut( "$fname-stuff2" ); wfProfileIn( "$fname-stuff3" ); $tpl->setRef( 'newtalk', $ntl ); $tpl->setRef( 'skin', $this); $tpl->set( 'logo', $this->logoText() ); if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) { if ( !$wgDisableCounters ) { $viewcount = $wgLang->formatNum( $wgArticle->getCount() ); if ( $viewcount ) { $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) ); } else { $tpl->set('viewcount', false); } } else { $tpl->set('viewcount', false); } if ($wgPageShowWatchingUsers) { $dbr =& wfGetDB( DB_SLAVE ); extract( $dbr->tableNames( 'watchlist' ) ); $sql = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBKey()) . "' AND wl_namespace=" . $this->mTitle->getNamespace() ; $res = $dbr->query( $sql, 'SkinTemplate::outputPage'); $x = $dbr->fetchObject( $res ); $numberofwatchingusers = $x->n; if ($numberofwatchingusers > 0) { $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers)); } else { $tpl->set('numberofwatchingusers', false); } } else { $tpl->set('numberofwatchingusers', false); } $tpl->set('copyright',$this->getCopyright()); $this->credits = false; if (isset($wgMaxCredits) && $wgMaxCredits != 0) { require_once("Credits.php"); $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax); } else { $tpl->set('lastmod', $this->lastModified()); } $tpl->setRef( 'credits', $this->credits ); } elseif ( isset( $oldid ) && !isset( $diff ) ) { $tpl->set('copyright', $this->getCopyright()); $tpl->set('viewcount', false); $tpl->set('lastmod', false); $tpl->set('credits', false); $tpl->set('numberofwatchingusers', false); } else { $tpl->set('copyright', false); $tpl->set('viewcount', false); $tpl->set('lastmod', false); $tpl->set('credits', false); $tpl->set('numberofwatchingusers', false); } wfProfileOut( "$fname-stuff3" ); wfProfileIn( "$fname-stuff4" ); $tpl->set( 'copyrightico', $this->getCopyrightIcon() ); $tpl->set( 'poweredbyico', $this->getPoweredBy() ); $tpl->set( 'disclaimer', $this->disclaimerLink() ); $tpl->set( 'privacy', $this->privacyLink() ); $tpl->set( 'about', $this->aboutLink() );
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?