language.php

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

PHP
919
字号
	function getLanguageNames() {		global $wgLanguageNamesEn;		return $wgLanguageNamesEn;	}	function getLanguageName( $code ) {		global $wgLanguageNamesEn;		if ( ! array_key_exists( $code, $wgLanguageNamesEn ) ) {			return '';		}		return $wgLanguageNamesEn[$code];	}	function getMonthName( $key ) {		global $wgMonthNamesEn, $wgContLang;		// see who called us and use the correct message function		if( get_class( $wgContLang->getLangObj() ) == get_class( $this ) )			return wfMsgForContent($wgMonthNamesEn[$key-1]);		else			return wfMsg($wgMonthNamesEn[$key-1]);	}	/* by default we just return base form */	function getMonthNameGen( $key ) {		return $this->getMonthName( $key );	}	function getMonthAbbreviation( $key ) {		global $wgMonthAbbreviationsEn, $wgContLang;		// see who called us and use the correct message function		if( get_class( $wgContLang->getLangObj() ) == get_class( $this ) )			return wfMsgForContent(@$wgMonthAbbreviationsEn[$key-1]);		else			return wfMsg(@$wgMonthAbbreviationsEn[$key-1]);	}	function getWeekdayName( $key ) {		global $wgWeekdayNamesEn, $wgContLang;		// see who called us and use the correct message function		if( get_class( $wgContLang->getLangObj() ) == get_class( $this ) )			return wfMsgForContent($wgWeekdayNamesEn[$key-1]);		else			return wfMsg($wgWeekdayNamesEn[$key-1]);	}	/**	 * Used by date() and time() to adjust the time output.	 * @public	 * @param int   $ts the time in date('YmdHis') format	 * @param mixed $tz adjust the time by this amount (default false,	 *                  mean we get user timecorrection setting)	 * @return int	 */	function userAdjust( $ts, $tz = false )	{		global $wgUser, $wgLocalTZoffset;		if (!$tz) {			$tz = $wgUser->getOption( 'timecorrection' );		}		#聽minutes and hours differences:		$minDiff = 0;		$hrDiff  = 0;		if ( $tz === '' ) {			#聽Global offset in minutes.			if( isset($wgLocalTZoffset) ) {				$hrDiff = $wgLocalTZoffset % 60;				$minDiff = $wgLocalTZoffset - ($hrDiff * 60);			}		} elseif ( strpos( $tz, ':' ) !== false ) {			$tzArray = explode( ':', $tz );			$hrDiff = intval($tzArray[0]);			$minDiff = intval($hrDiff < 0 ? -$tzArray[1] : $tzArray[1]);		} else {			$hrDiff = intval( $tz );		}		# No difference ? Return time unchanged		if ( 0 == $hrDiff && 0 == $minDiff ) { return $ts; }		#聽Generate an adjusted date		$t = mktime( (		  (int)substr( $ts, 8, 2) ) + $hrDiff, # Hours		  (int)substr( $ts, 10, 2 ) + $minDiff, # Minutes		  (int)substr( $ts, 12, 2 ), # Seconds		  (int)substr( $ts, 4, 2 ), # Month		  (int)substr( $ts, 6, 2 ), # Day		  (int)substr( $ts, 0, 4 ) ); #Year		return date( 'YmdHis', $t );	}	/**	 * This is meant to be used by time(), date(), and timeanddate() to get	 * the date preference they're supposed to use, it should be used in	 * all children.	 *	 *<code>	 * function timeanddate([...], $format = true) {	 * 	$datePreference = $this->dateFormat($format);	 * [...]	 *</code>	 *	 * @param mixed $usePrefs: if true, the user's preference is used	 *                         if false, the site/language default is used	 *                         if int/string, assumed to be a format.	 * @return string	 */	function dateFormat( $usePrefs = true ) {		global $wgUser;		if( is_bool( $usePrefs ) ) {			if( $usePrefs ) {				$datePreference = $wgUser->getOption( 'date' );			} else {				$options = $this->getDefaultUserOptions();				$datePreference = (string)$options['date'];			}		} else {			$datePreference = (string)$usePrefs;		}		// return int		if( $datePreference == '' ) {			return MW_DATE_DEFAULT;		}				return $datePreference;	}	/**	 * @public	 * @param mixed  $ts the time format which needs to be turned into a	 *               date('YmdHis') format with wfTimestamp(TS_MW,$ts)	 * @param bool   $adj whether to adjust the time output according to the	 *               user configured offset ($timecorrection)	 * @param mixed  $format true to use user's date format preference	 * @param string $timecorrection the time offset as returned by	 *               validateTimeZone() in Special:Preferences	 * @return string	 */	function date( $ts, $adj = false, $format = true, $timecorrection = false ) {		global $wgUser, $wgAmericanDates;		if ( $adj ) { $ts = $this->userAdjust( $ts, $timecorrection ); }		$datePreference = $this->dateFormat( $format );		if( $datePreference == MW_DATE_DEFAULT ) {			$datePreference = $wgAmericanDates ? MW_DATE_MDY : MW_DATE_DMY;		}		$month = $this->formatMonth( substr( $ts, 4, 2 ), $datePreference );		$day = $this->formatDay( substr( $ts, 6, 2 ), $datePreference );		$year = $this->formatNum( substr( $ts, 0, 4 ), true );		switch( $datePreference ) {			case MW_DATE_DMY: return "$day $month $year";			case MW_DATE_YMD: return "$year $month $day";			case MW_DATE_ISO: return substr($ts, 0, 4). '-' . substr($ts, 4, 2). '-' .substr($ts, 6, 2);			default: return "$month $day, $year";		}	}	/**	* @public	* @param mixed  $ts the time format which needs to be turned into a	*               date('YmdHis') format with wfTimestamp(TS_MW,$ts)	* @param bool   $adj whether to adjust the time output according to the	*               user configured offset ($timecorrection)	* @param mixed  $format true to use user's date format preference	* @param string $timecorrection the time offset as returned by	*               validateTimeZone() in Special:Preferences	* @return string	*/	function time( $ts, $adj = false, $format = true, $timecorrection = false ) {		global $wgUser;		if ( $adj ) { $ts = $this->userAdjust( $ts, $timecorrection ); }		$datePreference = $this->dateFormat( $format );		$sep = $this->timeSeparator( $format );		$hh = substr( $ts, 8, 2 );		$mm = substr( $ts, 10, 2 );		$ss = substr( $ts, 12, 2 );		if ( $datePreference != MW_DATE_ISO ) {			$hh = $this->formatNum( $hh, true );			$mm = $this->formatNum( $mm, true );			//$ss = $this->formatNum( $ss, true );			return $hh . $sep . $mm;		} else {			return $hh . ':' . $mm . ':' . $ss;		}	}	/**	 * Default separator character between hours, minutes, and seconds.	 * Will be used by Language::time() for non-ISO formats.	 * (ISO will always use a colon.)	 * @return string	 */	function timeSeparator( $format ) {		return ':';	}	/**	 * String to insert between the time and the date in a combined	 * string. Should include any relevant whitespace.	 * @return string	 */	function timeDateSeparator( $format ) {		return ', ';	}	/**	 * Return true if the time should display before the date.	 * @return bool	 * @private	 */	function timeBeforeDate() {		return true;	}	function formatMonth( $month, $format ) {		return $this->getMonthName( $month );	}	function formatDay( $day, $format ) {		return $this->formatNum( 0 + $day, true );	}	/**	* @public	* @param mixed  $ts the time format which needs to be turned into a	*               date('YmdHis') format with wfTimestamp(TS_MW,$ts)	* @param bool   $adj whether to adjust the time output according to the	*               user configured offset ($timecorrection)	* @param mixed  $format what format to return, if it's false output the	*               default one (default true)	* @param string $timecorrection the time offset as returned by	*               validateTimeZone() in Special:Preferences	* @return string	*/	function timeanddate( $ts, $adj = false, $format = true, $timecorrection = false) {		global $wgUser;		$datePreference = $this->dateFormat($format);		switch ( $datePreference ) {			case MW_DATE_ISO: return $this->date( $ts, $adj, $format, $timecorrection ) . ' ' .				$this->time( $ts, $adj, $format, $timecorrection );			default:				$time = $this->time( $ts, $adj, $format, $timecorrection );				$sep = $this->timeDateSeparator( $datePreference );				$date = $this->date( $ts, $adj, $format, $timecorrection );				return $this->timeBeforeDate( $datePreference )					? $time . $sep . $date					: $date . $sep . $time;		}	}	function getMessage( $key ) {		global $wgAllMessagesEn;		return @$wgAllMessagesEn[$key];	}	function getAllMessages() {		global $wgAllMessagesEn;		return $wgAllMessagesEn;	}	function iconv( $in, $out, $string ) {		# For most languages, this is a wrapper for iconv		return iconv( $in, $out, $string );	}	function ucfirst( $string ) {		# For most languages, this is a wrapper for ucfirst()		return ucfirst( $string );	}	function uc( $str ) {		return strtoupper( $str );	}	function lcfirst( $s ) {		return strtolower( $s{0} ). substr( $s, 1 );	}	function lc( $str ) {		return strtolower( $str );	}	function checkTitleEncoding( $s ) {		global $wgInputEncoding;		# Check for UTF-8 URLs; Internet Explorer produces these if you		# type non-ASCII chars in the URL bar or follow unescaped links.		$ishigh = preg_match( '/[\x80-\xff]/', $s);		$isutf = ($ishigh ? preg_match( '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .		         '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s ) : true );		if( ($wgInputEncoding != 'utf-8') and $ishigh and $isutf )			return @iconv( 'UTF-8', $wgInputEncoding, $s );		if( ($wgInputEncoding == 'utf-8') and $ishigh and !$isutf )			return utf8_encode( $s );		# Other languages can safely leave this function, or replace		# it with one to detect and convert another legacy encoding.		return $s;	}	/**	 * Some languages have special punctuation to strip out	 * or characters which need to be converted for MySQL's	 * indexing to grok it correctly. Make such changes here.	 *	 * @param string $in	 * @return string	 */	function stripForSearch( $in ) {		return strtolower( $in );	}	function convertForSearchResult( $termsArray ) {		# some languages, e.g. Chinese, need to do a conversion		# in order for search results to be displayed correctly		return $termsArray;	}	/**	 * Get the first character of a string. In ASCII, return	 * first byte of the string. UTF8 and others have to	 * overload this.	 *	 * @param string $s	 * @return string	 */	function firstChar( $s ) {		return $s[0];	}	function initEncoding() {		# Some languages may have an alternate char encoding option		# (Esperanto X-coding, Japanese furigana conversion, etc)		# If this language is used as the primary content language,		# an override to the defaults can be set here on startup.		#global $wgInputEncoding, $wgOutputEncoding, $wgEditEncoding;	}	function setAltEncoding() {		# Some languages may have an alternate char encoding option		# (Esperanto X-coding, Japanese furigana conversion, etc)		# If 'altencoding' is checked in user prefs, this gives a		# chance to swap out the default encoding settings.		#global $wgInputEncoding, $wgOutputEncoding, $wgEditEncoding;	}	function recodeForEdit( $s ) {		# For some languages we'll want to explicitly specify		# which characters make it into the edit box raw		# or are converted in some way or another.		# Note that if wgOutputEncoding is different from		# wgInputEncoding, this text will be further converted		# to wgOutputEncoding.		global $wgInputEncoding, $wgEditEncoding;		if( $wgEditEncoding == '' or		  $wgEditEncoding == $wgInputEncoding ) {			return $s;		} else {			return $this->iconv( $wgInputEncoding, $wgEditEncoding, $s );		}	}	function recodeInput( $s ) {		# Take the previous into account.		global $wgInputEncoding, $wgOutputEncoding, $wgEditEncoding;		if($wgEditEncoding != "") {			$enc = $wgEditEncoding;		} else {			$enc = $wgOutputEncoding;		}		if( $enc == $wgInputEncoding ) {			return $s;		} else {			return $this->iconv( $enc, $wgInputEncoding, $s );		}	}	/**	 * For right-to-left language support	 *	 * @return bool	 */	function isRTL() { return false; }	/**	 * A hidden direction mark (LRM or RLM), depending on the language direction	 *	 * @return string	 */	function getDirMark() { return $this->isRTL() ? "\xE2\x80\x8F" : "\xE2\x80\x8E"; }	/**	 * To allow "foo[[bar]]" to extend the link over the whole word "foobar"	 *	 * @return bool	 */	function linkPrefixExtension() { return false; }	function &getMagicWords() {		global $wgMagicWordsEn;		return $wgMagicWordsEn;	}	# Fill a MagicWord object with data from here	function getMagic( &$mw ) {		if ( !isset( $this->mMagicExtensions ) ) {			$this->mMagicExtensions = array();			wfRunHooks( 'LanguageGetMagic', array( &$this->mMagicExtensions, $this->getCode() ) );		}		if ( isset( $this->mMagicExtensions[$mw->mId] ) ) {			$rawEntry = $this->mMagicExtensions[$mw->mId];		} else {			$magicWords =& $this->getMagicWords();			if ( isset( $magicWords[$mw->mId] ) ) {				$rawEntry = $magicWords[$mw->mId];			} else {				# Fall back to English if local list is incomplete				$magicWords =& Language::getMagicWords();				$rawEntry = $magicWords[$mw->mId];			}		}		$mw->mCaseSensitive = $rawEntry[0];		$mw->mSynonyms = array_slice( $rawEntry, 1 );	}	/**	 * Italic is unsuitable for some languages	 *	 * @public	 *	 * @param string $text The text to be emphasized.	 * @return string	 */	function emphasize( $text ) {		return "<em>$text</em>";	}	 /**	 * Normally we output all numbers in plain en_US style, that is	 * 293,291.235 for twohundredninetythreethousand-twohundredninetyone	 * point twohundredthirtyfive. However this is not sutable for all	 * languages, some such as Pakaran want 喋ㄠ┋喋

⌨️ 快捷键说明

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