* functionality), or if it is true then use the wikis
* @return Language object
*/
-function wfGetLangObj( $langcode = false ){
+function wfGetLangObj( $langcode = false ) {
# Identify which language to get or create a language object for.
- if( $langcode instanceof Language )
- # Great, we already have the object!
+ # Using is_object here due to Stub objects.
+ if( is_object( $langcode ) ) {
+ # Great, we already have the object (hopefully)!
return $langcode;
+ }
- global $wgContLang;
- if( $langcode === $wgContLang->getCode() || $langcode === true )
+ global $wgContLang, $wgLanguageCode;
+ if( $langcode === true || $langcode === $wgLanguageCode ) {
# $langcode is the language code of the wikis content language object.
# or it is a boolean and value is true
return $wgContLang;
+ }
global $wgLang;
- if( $langcode === $wgLang->getCode() || $langcode === false )
+ if( $langcode === false || $langcode === $wgLang->getCode() ) {
# $langcode is the language code of user language object.
# or it was a boolean and value is false
return $wgLang;
+ }
$validCodes = array_keys( Language::getLanguageNames() );
- if( in_array( $langcode, $validCodes ) )
+ if( in_array( $langcode, $validCodes ) ) {
# $langcode corresponds to a valid language.
return Language::factory( $langcode );
+ }
# $langcode is a string, but not a valid language code; use content language.
wfDebug( "Invalid language code passed to wfGetLangObj, falling back to content language.\n" );
return $wgContLang;
}
+function wfUILang() {
+ global $wgBetterDirectionality;
+ return wfGetLangObj( $wgBetterDirectionality ? false: true );
+}
+
/**
* Get a message from anywhere, for the current user language.
*
* behaves as a content language switch if it is a boolean.
* @param $transform Boolean: whether to parse magic words, etc.
* @return string
- * @private
*/
function wfMsgGetKey( $key, $useDB, $langCode = false, $transform = true ) {
global $wgContLang, $wgMessageCache;
wfRunHooks('NormalizeMessageKey', array(&$key, &$useDB, &$langCode, &$transform));
- # If $wgMessageCache isn't initialised yet, try to return something sensible.
- if( is_object( $wgMessageCache ) ) {
- $message = $wgMessageCache->get( $key, $useDB, $langCode );
- if( $message === false ){
- $message = '<' . htmlspecialchars( $key ) . '>';
- } elseif ( $transform ) {
- $message = $wgMessageCache->transform( $message );
- }
- } else {
- $lang = wfGetLangObj( $langCode );
-
- # MessageCache::get() does this already, Language::getMessage() doesn't
- # ISSUE: Should we try to handle "message/lang" here too?
- $key = str_replace( ' ' , '_' , $wgContLang->lcfirst( $key ) );
-
- if( is_object( $lang ) ) {
- $message = $lang->getMessage( $key );
- } else {
- $message = false;
- }
+ if ( !is_object( $wgMessageCache ) ) {
+ throw new MWException( "Trying to get message before message cache is initialised" );
}
+ $message = $wgMessageCache->get( $key, $useDB, $langCode );
+ if( $message === false ){
+ $message = '<' . htmlspecialchars( $key ) . '>';
+ } elseif ( $transform ) {
+ $message = $wgMessageCache->transform( $message );
+ }
return $message;
}
$notice = '';
}
}
-
+ $notice = '<div id="localNotice">'.$notice.'</div>';
wfProfileOut( $fname );
return $notice;
}
* @deprecated
*/
function &wfGetMimeMagic() {
+ wfDeprecated( __FUNCTION__ );
return MimeMagic::singleton();
}
if ( is_null( $mode ) )
$mode = $wgDirectoryMode;
+ // Turn off the normal warning, we're doing our own below
+ wfSuppressWarnings();
$ok = mkdir( $dir, $mode, true ); // PHP5 <3
+ wfRestoreWarnings();
+
if( !$ok ) {
// PHP doesn't report the path in its warning message, so add our own to aid in diagnosis.
trigger_error( __FUNCTION__ . ": failed to mkdir \"$dir\" mode $mode", E_USER_WARNING );
|| preg_match( "/^\s*[+-]?0*[1-9]/", $val ); // approx C atoi() function
}
+/**
+ * Wrapper function for PHP's dl(). This doesn't work in most situations from
+ * PHP 5.3 onward, and is usually disabled in shared environments anyway.
+ *
+ * @param $extension String A PHP extension. The file suffix (.so or .dll)
+ * should be omitted
+ * @return Bool - Whether or not the extension is loaded
+ */
+function wfDl( $extension ) {
+ if( extension_loaded( $extension ) ) {
+ return true;
+ }
+
+ $canDl = ( function_exists( 'dl' ) && is_callable( 'dl' )
+ && wfIniGetBool( 'enable_dl' ) && !wfIniGetBool( 'safe_mode' ) );
+
+ if( $canDl ) {
+ wfSuppressWarnings();
+ dl( $extension . '.' . PHP_SHLIB_SUFFIX );
+ wfRestoreWarnings();
+ }
+ return extension_loaded( $extension );
+}
+
/**
* Execute a shell command, with time and memory limits mirrored from the PHP
* configuration if supported.
throw new MWException( "MediaWiki $req_ver required--this is only $wgVersion" );
}
-/**
- * @deprecated use StringUtils::escapeRegexReplacement
- */
-function wfRegexReplacement( $string ) {
- return StringUtils::escapeRegexReplacement( $string );
-}
-
/**
* Return the final portion of a pathname.
* Reimplemented because PHP5's basename() is buggy with multibyte text.
$wgPostCommitUpdateList = array();
}
-/**
- * @deprecated use StringUtils::explodeMarkup
- */
-function wfExplodeMarkup( $separator, $text ) {
- return StringUtils::explodeMarkup( $separator, $text );
-}
-
/**
* Convert an arbitrarily-long digit string from one numeric base
* to another, optionally zero-padding to a minimum column width.
}
}
-/**
- * Alias for modularized function
- * @deprecated Use Http::isLocalURL() instead
- */
-function wfIsLocalURL( $url ) {
- wfDeprecated(__FUNCTION__);
- return Http::isLocalURL( $url );
-}
-
function wfHttpOnlySafe() {
global $wgHttpOnlyBlacklist;
if( !version_compare("5.2", PHP_VERSION, "<") )
}
/**
- * Return a string consisting all callers in stack, somewhat useful sometimes
- * for profiling specific points
+ * Return a string consisting of callers in the stack. Useful sometimes
+ * for profiling specific points.
+ *
+ * @param $limit The maximum depth of the stack frame to return, or false for
+ * the entire stack.
*/
-function wfGetAllCallers() {
- return implode('/', array_map('wfFormatStackFrame',array_reverse(wfDebugBacktrace())));
+function wfGetAllCallers( $limit = 3 ) {
+ $trace = array_reverse( wfDebugBacktrace() );
+ if ( !$limit || $limit > count( $trace ) - 1 ) {
+ $limit = count( $trace ) - 1;
+ }
+ $trace = array_slice( $trace, -$limit - 1, $limit );
+ return implode( '/', array_map( 'wfFormatStackFrame', $trace ) );
}
/**