return new Message( $key, $params );
}
+/**
+ * This function accepts multiple message keys and returns a message instance
+ * for the first message which is non-empty. If all messages are empty then an
+ * instance of the first message key is returned.
+ * Varargs: message keys
+ * @return \type{Message}
+ * @since 1.18
+ */
+function wfMessageFallback( /*...*/ ) {
+ $keys = func_get_args();
+ $first = $keys[0];
+ foreach ( $keys as $key ) {
+ if ( wfEmptyMsg( $key ) ) {
+ continue;
+ }
+ return wfMessage( $key );
+ }
+ return wfMessage( $first );
+}
+
/**
* Get a message from anywhere, for the current user language.
*
/**
* 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
+ * If force is true, it will set the value even if source is NULL
*/
-function wfSetVar( &$dest, $source ) {
+function wfSetVar( &$dest, $source, $force = false ) {
$temp = $dest;
- if ( !is_null( $source ) ) {
+ if ( !is_null( $source ) || $force ) {
$dest = $source;
}
return $temp;
$da = array();
$strtime = '';
- if ( $ts === 0 ) {
+ if ( !$ts ) { // We want to catch 0, '', null... but not date strings starting with a letter.
$uts = time();
$strtime = "@$uts";
} elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)$/D', $ts, $da ) ) {
# asctime
$strtime = $ts;
} else {
- # Bogus value; fall back to the epoch...
+ # Bogus value...
wfDebug("wfTimestamp() fed bogus time value: TYPE=$outputtype; VALUE=$ts\n");
return false;
/**
* Get the load balancer factory object
+ * @return LBFactory
*/
function &wfGetLBFactory() {
return LBFactory::singleton();