* Moving hardcoded styles into CSS.
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index ea209c9..f50ce44 100644 (file)
@@ -213,7 +213,7 @@ function wfUtf8Sequence( $codepoint ) {
 function wfMungeToUtf8( $string ) {
        global $wgInputEncoding; # This is debatable
        #$string = iconv($wgInputEncoding, "UTF-8", $string);
-       $string = preg_replace ( '/&#([0-9]+);/e', 'wfUtf8Sequence($1)', $string );
+       $string = preg_replace ( '/&#0*([0-9]+);/e', 'wfUtf8Sequence($1)', $string );
        $string = preg_replace ( '/&#x([0-9a-f]+);/ie', 'wfUtf8Sequence(0x$1)', $string );
        # Should also do named entities here
        return $string;
@@ -390,8 +390,7 @@ function wfMsgReal( $key, $args, $useDB, $forContent=false ) {
 
        if( is_object( $wgMessageCache ) ) {
                $message = $wgMessageCache->get( $key, $useDB, $forContent );
-    }
-       else {
+       } else {
                if( $forContent ) {
                        $lang = &$wgContLang;
                } else {
@@ -399,6 +398,7 @@ function wfMsgReal( $key, $args, $useDB, $forContent=false ) {
                }
 
                wfSuppressWarnings();
+               
                if( is_object( $lang ) ) {
                        $message = $lang->getMessage( $key );
                } else {
@@ -1017,30 +1017,29 @@ function wfTimestamp($outputtype=TS_UNIX,$ts=0) {
                $uts=$ts;
        } else {
                # Bogus value; fall back to the epoch...
-               wfDebug("wfTimestamp() given bogus time value.\n");
+               wfDebug("wfTimestamp() fed bogus time value: $outputtype; $ts\n");
                $uts = 0;
        }
 
-       if ($ts==0)
-               $uts=time();
+       if ($ts==0) { $uts=time(); }
+               
        switch($outputtype) {
-       case TS_UNIX:
-               return $uts;
-       case TS_MW:
-               return gmdate( 'YmdHis', $uts );
-       case TS_DB:
-               return gmdate( 'Y-m-d H:i:s', $uts );
-       case TS_RFC2822:
-               return gmdate( 'D, d M Y H:i:s', $uts ) . ' GMT';
-       default:
-               wfDebugDieBacktrace( 'wfTimestamp() called with illegal output type.');
+               case TS_UNIX:
+                       return $uts;
+               case TS_MW:
+                       return gmdate( 'YmdHis', $uts );
+               case TS_DB:
+                       return gmdate( 'Y-m-d H:i:s', $uts );
+               case TS_RFC2822:
+                       return gmdate( 'D, d M Y H:i:s', $uts ) . ' GMT';
+               default:
+                       wfDebugDieBacktrace( 'wfTimestamp() called with illegal output type.');
        }
 }
 
 /**
  * Check where as the operating system is Windows
  *
- * @todo document
  * @return bool True if it's windows, False otherwise.
  */
 function wfIsWindows() {   
@@ -1051,4 +1050,67 @@ function wfIsWindows() {
        }   
 } 
 
+/**
+ * Swap two variables
+ */
+function swap( &$x, &$y ) {
+       $z = $x;
+       $x = $y;
+       $y = $z;
+}
+
+function wfGetSiteNotice() {
+       global $wgSiteNotice, $wgTitle, $wgOut;
+       $fname = 'wfGetSiteNotice';
+       wfProfileIn( $fname );
+
+       $notice = wfMsg( 'sitenotice' );
+       if($notice == '<sitenotice>') $notice = '';
+       # Allow individual wikis to turn it off
+       if ( $notice == '-' ) {
+               $notice = '';
+       } else {
+               if ($notice == '') {
+                       $notice = $wgSiteNotice;
+               }
+               if($notice != '-' && $notice != '') {
+                       $specialparser = new Parser();
+                       $parserOutput = $specialparser->parse( $notice, $wgTitle, $wgOut->mParserOptions, false );
+                       $notice = $parserOutput->getText();
+               }
+       }
+       wfProfileOut( $fname );
+       return $notice;
+}
+
+/**
+ * Format an XML element with given attributes and, optionally, text content.
+ * Element and attribute names are assumed to be ready for literal inclusion.
+ * Strings are assumed to not contain XML-illegal characters; special
+ * characters (<, >, &) are escaped but illegals are not touched.
+ *
+ * @param string $element
+ * @param array $attribs Name=>value pairs. Values will be escaped.
+ * @param bool $contents NULL to make an open tag only; '' for a contentless closed tag (default)
+ * @return string
+ */
+function wfElement( $element, $attribs = array(), $contents = '') {
+       $out = '<' . $element;
+       foreach( $attribs as $name => $val ) {
+               $out .= ' ' . $name . '="' . htmlspecialchars( $val ) . '"';
+       }
+       if( is_null( $contents ) ) {
+               $out .= '>';
+       } else {
+               if( $contents == '' ) {
+                       $out .= ' />';
+               } else {
+                       $out .= '>';
+                       $out .= htmlspecialchars( $contents );
+                       $out .= "</$element>";
+               }
+       }
+       return $out;
+}
+
 ?>