Merging Vector's navigation_urls and SkinTemplate's content_actions code into content...
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index 79438d9..d636b44 100644 (file)
@@ -595,6 +595,26 @@ function wfMessage( $key /*...*/) {
        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.
  *
@@ -1287,10 +1307,11 @@ function wfTime() {
 /**
  * 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;
@@ -1948,7 +1969,7 @@ function wfTimestamp( $outputtype = TS_UNIX, $ts = 0 ) {
        $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 ) ) {
@@ -1988,7 +2009,7 @@ function wfTimestamp( $outputtype = TS_UNIX, $ts = 0 ) {
                # 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;
@@ -3153,6 +3174,7 @@ function wfGetLB( $wiki = false ) {
 
 /**
  * Get the load balancer factory object
+ * @return LBFactory
  */
 function &wfGetLBFactory() {
        return LBFactory::singleton();