globalfunctions.php
来自「php 开发的内容管理系统」· PHP 代码 · 共 2,006 行 · 第 1/4 页
PHP
2,006 行
} } return $message;}/** * Return an HTML-escaped version of a message. * Parameter replacements, if any, are done *after* the HTML-escaping, * so parameters may contain HTML (eg links or form controls). Be sure * to pre-escape them if you really do want plaintext, or just wrap * the whole thing in htmlspecialchars(). * * @param string $key * @param string ... parameters * @return string */function wfMsgHtml( $key ) { $args = func_get_args(); array_shift( $args ); return wfMsgReplaceArgs( htmlspecialchars( wfMsgGetKey( $key, true ) ), $args );}/** * Return an HTML version of message * Parameter replacements, if any, are done *after* parsing the wiki-text message, * so parameters may contain HTML (eg links or form controls). Be sure * to pre-escape them if you really do want plaintext, or just wrap * the whole thing in htmlspecialchars(). * * @param string $key * @param string ... parameters * @return string */function wfMsgWikiHtml( $key ) { global $wgOut; $args = func_get_args(); array_shift( $args ); return wfMsgReplaceArgs( $wgOut->parse( wfMsgGetKey( $key, true ), /* can't be set to false */ true ), $args );}/** * Returns message in the requested format * @param string $key Key of the message * @param array $options Processing rules: * <i>parse<i>: parses wikitext to html * <i>parseinline<i>: parses wikitext to html and removes the surrounding p's added by parser or tidy * <i>escape<i>: filters message trough htmlspecialchars * <i>replaceafter<i>: parameters are substituted after parsing or escaping */function wfMsgExt( $key, $options ) { global $wgOut, $wgMsgParserOptions, $wgParser; $args = func_get_args(); array_shift( $args ); array_shift( $args ); if( !is_array($options) ) { $options = array($options); } $string = wfMsgGetKey( $key, true, false, false ); if( !in_array('replaceafter', $options) ) { $string = wfMsgReplaceArgs( $string, $args ); } if( in_array('parse', $options) ) { $string = $wgOut->parse( $string, true, true ); } elseif ( in_array('parseinline', $options) ) { $string = $wgOut->parse( $string, true, true ); $m = array(); if( preg_match( "~^<p>(.*)\n?</p>$~", $string, $m ) ) { $string = $m[1]; } } elseif ( in_array('parsemag', $options) ) { global $wgTitle; $parser = new Parser(); $parserOptions = new ParserOptions(); $parserOptions->setInterfaceMessage( true ); $parser->startExternalParse( $wgTitle, $parserOptions, OT_MSG ); $string = $parser->transformMsg( $string, $parserOptions ); } if ( in_array('escape', $options) ) { $string = htmlspecialchars ( $string ); } if( in_array('replaceafter', $options) ) { $string = wfMsgReplaceArgs( $string, $args ); } return $string;}/** * Just like exit() but makes a note of it. * Commits open transactions except if the error parameter is set * * @obsolete Please return control to the caller or throw an exception */function wfAbruptExit( $error = false ){ global $wgLoadBalancer; static $called = false; if ( $called ){ exit( -1 ); } $called = true; if( function_exists( 'debug_backtrace' ) ){ // PHP >= 4.3 $bt = debug_backtrace(); for($i = 0; $i < count($bt) ; $i++){ $file = isset($bt[$i]['file']) ? $bt[$i]['file'] : "unknown"; $line = isset($bt[$i]['line']) ? $bt[$i]['line'] : "unknown"; wfDebug("WARNING: Abrupt exit in $file at line $line\n"); } } else { wfDebug('WARNING: Abrupt exit\n'); } wfProfileClose(); logProfilingData(); if ( !$error ) { $wgLoadBalancer->closeAll(); } exit( -1 );}/** * @obsolete Please return control the caller or throw an exception */function wfErrorExit() { wfAbruptExit( true );}/** * Print a simple message and die, returning nonzero to the shell if any. * Plain die() fails to return nonzero to the shell if you pass a string. * @param string $msg */function wfDie( $msg='' ) { echo $msg; die( 1 );}/** * Throw a debugging exception. This function previously once exited the process, * but now throws an exception instead, with similar results. * * @param string $msg Message shown when dieing. */function wfDebugDieBacktrace( $msg = '' ) { throw new MWException( $msg );}/** * Fetch server name for use in error reporting etc. * Use real server name if available, so we know which machine * in a server farm generated the current page. * @return string */function wfHostname() { if ( function_exists( 'posix_uname' ) ) { // This function not present on Windows $uname = @posix_uname(); } else { $uname = false; } if( is_array( $uname ) && isset( $uname['nodename'] ) ) { return $uname['nodename']; } else { # This may be a virtual server. return $_SERVER['SERVER_NAME']; }} /** * Returns a HTML comment with the elapsed time since request. * This method has no side effects. * @return string */ function wfReportTime() { global $wgRequestTime; $now = wfTime(); $elapsed = $now - $wgRequestTime; $com = sprintf( "<!-- Served by %s in %01.3f secs. -->", wfHostname(), $elapsed ); return $com; }function wfBacktrace() { global $wgCommandLineMode; if ( !function_exists( 'debug_backtrace' ) ) { return false; } if ( $wgCommandLineMode ) { $msg = ''; } else { $msg = "<ul>\n"; } $backtrace = debug_backtrace(); foreach( $backtrace as $call ) { if( isset( $call['file'] ) ) { $f = explode( DIRECTORY_SEPARATOR, $call['file'] ); $file = $f[count($f)-1]; } else { $file = '-'; } if( isset( $call['line'] ) ) { $line = $call['line']; } else { $line = '-'; } if ( $wgCommandLineMode ) { $msg .= "$file line $line calls "; } else { $msg .= '<li>' . $file . ' line ' . $line . ' calls '; } if( !empty( $call['class'] ) ) $msg .= $call['class'] . '::'; $msg .= $call['function'] . '()'; if ( $wgCommandLineMode ) { $msg .= "\n"; } else { $msg .= "</li>\n"; } } if ( $wgCommandLineMode ) { $msg .= "\n"; } else { $msg .= "</ul>\n"; } return $msg;}/* Some generic result counters, pulled out of SearchEngine *//** * @todo document */function wfShowingResults( $offset, $limit ) { global $wgLang; return wfMsg( 'showingresults', $wgLang->formatNum( $limit ), $wgLang->formatNum( $offset+1 ) );}/** * @todo document */function wfShowingResultsNum( $offset, $limit, $num ) { global $wgLang; return wfMsg( 'showingresultsnum', $wgLang->formatNum( $limit ), $wgLang->formatNum( $offset+1 ), $wgLang->formatNum( $num ) );}/** * @todo document */function wfViewPrevNext( $offset, $limit, $link, $query = '', $atend = false ) { global $wgLang; $fmtLimit = $wgLang->formatNum( $limit ); $prev = wfMsg( 'prevn', $fmtLimit ); $next = wfMsg( 'nextn', $fmtLimit ); if( is_object( $link ) ) { $title =& $link; } else { $title = Title::newFromText( $link ); if( is_null( $title ) ) { return false; } } if ( 0 != $offset ) { $po = $offset - $limit; if ( $po < 0 ) { $po = 0; } $q = "limit={$limit}&offset={$po}"; if ( '' != $query ) { $q .= '&'.$query; } $plink = '<a href="' . $title->escapeLocalUrl( $q ) . "\">{$prev}</a>"; } else { $plink = $prev; } $no = $offset + $limit; $q = 'limit='.$limit.'&offset='.$no; if ( '' != $query ) { $q .= '&'.$query; } if ( $atend ) { $nlink = $next; } else { $nlink = '<a href="' . $title->escapeLocalUrl( $q ) . "\">{$next}</a>"; } $nums = wfNumLink( $offset, 20, $title, $query ) . ' | ' . wfNumLink( $offset, 50, $title, $query ) . ' | ' . wfNumLink( $offset, 100, $title, $query ) . ' | ' . wfNumLink( $offset, 250, $title, $query ) . ' | ' . wfNumLink( $offset, 500, $title, $query ); return wfMsg( 'viewprevnext', $plink, $nlink, $nums );}/** * @todo document */function wfNumLink( $offset, $limit, &$title, $query = '' ) { global $wgLang; if ( '' == $query ) { $q = ''; } else { $q = $query.'&'; } $q .= 'limit='.$limit.'&offset='.$offset; $fmtLimit = $wgLang->formatNum( $limit ); $s = '<a href="' . $title->escapeLocalUrl( $q ) . "\">{$fmtLimit}</a>"; return $s;}/** * @todo document * @todo FIXME: we may want to blacklist some broken browsers * * @return bool Whereas client accept gzip compression */function wfClientAcceptsGzip() { global $wgUseGzip; if( $wgUseGzip ) { # FIXME: we may want to blacklist some broken browsers if( preg_match( '/\bgzip(?:;(q)=([0-9]+(?:\.[0-9]+)))?\b/', $_SERVER['HTTP_ACCEPT_ENCODING'], $m ) ) { if( isset( $m[2] ) && ( $m[1] == 'q' ) && ( $m[2] == 0 ) ) return false; wfDebug( " accepts gzip\n" ); return true; } } return false;}/** * Obtain the offset and limit values from the request string; * used in special pages * * @param $deflimit Default limit if none supplied * @param $optionname Name of a user preference to check against * @return array * */function wfCheckLimits( $deflimit = 50, $optionname = 'rclimit' ) { global $wgRequest; return $wgRequest->getLimitOffset( $deflimit, $optionname );}/** * Escapes the given text so that it may be output using addWikiText() * without any linking, formatting, etc. making its way through. This * is achieved by substituting certain characters with HTML entities. * As required by the callers, <nowiki> is not used. It currently does * not filter out characters which have special meaning only at the * start of a line, such as "*". * * @param string $text Text to be escaped */function wfEscapeWikiText( $text ) { $text = str_replace( array( '[', '|', '\'', 'ISBN ' , '://' , "\n=", '{{' ), array( '[', '|', ''', 'ISBN ', '://' , "\n=", '{{' ), htmlspecialchars($text) ); return $text;}/** * @todo document */function wfQuotedPrintable( $string, $charset = '' ) { # Probably incomplete; see RFC 2045 if( empty( $charset ) ) { global $wgInputEncoding; $charset = $wgInputEncoding; } $charset = strtoupper( $charset ); $charset = str_replace( 'ISO-8859', 'ISO8859', $charset ); // ? $illegal = '\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\xff='; $replace = $illegal . '\t ?_'; if( !preg_match( "/[$illegal]/", $string ) ) return $string; $out = "=?$charset?Q?"; $out .= preg_replace( "/([$replace])/e", 'sprintf("=%02X",ord("$1"))', $string ); $out .= '?='; return $out;}/** * @todo document * @return float */function wfTime() { return microtime(true);}/** * Sets dest to source and returns the original value of dest * If source is NULL, it just returns the value, it doesn't set the variable */function wfSetVar( &$dest, $source ) { $temp = $dest; if ( !is_null( $source ) ) { $dest = $source; } return $temp;}/** * As for wfSetVar except setting a bit */function wfSetBit( &$dest, $bit, $state = true ) { $temp = (bool)($dest & $bit ); if ( !is_null( $state ) ) { if ( $state ) { $dest |= $bit; } else { $dest &= ~$bit; } } return $temp;}/** * This function takes two arrays as input, and returns a CGI-style string, e.g. * "days=7&limit=100". Options in the first array override options in the second. * Options set to "" will not be output. */function wfArrayToCGI( $array1, $array2 = NULL ){ if ( !is_null( $array2 ) ) { $array1 = $array1 + $array2; } $cgi = ''; foreach ( $array1 as $key => $value ) { if ( '' !== $value ) { if ( '' != $cgi ) { $cgi .= '&'; } $cgi .= urlencode( $key ) . '=' . urlencode( $value ); } } return $cgi;}/** * This is obsolete, use SquidUpdate::purge() * @deprecated */function wfPurgeSquidServers ($urlArr) { SquidUpdate::purge( $urlArr );}/** * Windows-compatible version of escapeshellarg() * Windows doesn't recognise single-quotes in the shell, but the escapeshellarg() * function puts single quotes in regardless of OS */function wfEscapeShellArg( ) { $args = func_get_args(); $first = true; $retVal = ''; foreach ( $args as $arg ) { if ( !$first ) { $retVal .= ' '; } else { $first = false; } if ( wfIsWindows() ) { // Escaping for an MSVC-style command line parser // Ref: http://mailman.lyra.org/pipermail/scite-interest/2002-March/000436.html // Double the backslashes before any double quotes. Escape the double quotes. $tokens = preg_split( '/(\\\\*")/', $arg, -1, PREG_SPLIT_DELIM_CAPTURE ); $arg = ''; $delim = false; foreach ( $tokens as $token ) { if ( $delim ) { $arg .= str_replace( '\\', '\\\\', substr( $token, 0, -1 ) ) . '\\"'; } else { $arg .= $token; } $delim = !$delim; } // Double the backslashes before the end of the string, because // we will soon add a quote if ( preg_match( '/^(.*?)(\\\\+)$/', $arg, $m ) ) { $arg = $m[1] . str_replace( '\\', '\\\\', $m[2] ); } // Add surrounding quotes $retVal .= '"' . $arg . '"'; } else { $retVal .= escapeshellarg( $arg );
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?