* (bug 10263) update Farsi translations
[lhc/web/wiklou.git] / languages / Language.php
index 5815f61..d36b549 100644 (file)
@@ -228,7 +228,22 @@ class Language {
        }
 
        /**
-        * Get a namespace key by value, case insensetive.
+        * Get a namespace key by value, case insensitive.
+        * Only matches namespace names for the current language, not the
+        * canonical ones defined in Namespace.php.
+        *
+        * @param string $text
+        * @return mixed An integer if $text is a valid value otherwise false
+        */
+       function getLocalNsIndex( $text ) {
+               $this->load();
+               $lctext = $this->lc($text);
+               return isset( $this->mNamespaceIds[$lctext] ) ? $this->mNamespaceIds[$lctext] : false;
+       }
+
+       /**
+        * Get a namespace key by value, case insensitive.  Canonical namespace
+        * names override custom ones defined for the current language.
         *
         * @param string $text
         * @return mixed An integer if $text is a valid value otherwise false
@@ -236,6 +251,7 @@ class Language {
        function getNsIndex( $text ) {
                $this->load();
                $lctext = $this->lc($text);
+               if( ( $ns = Namespace::getCanonicalIndex( $lctext ) ) !== null ) return $ns;
                return isset( $this->mNamespaceIds[$lctext] ) ? $this->mNamespaceIds[$lctext] : false;
        }
 
@@ -391,7 +407,7 @@ class Language {
         * @return int
         */
        function userAdjust( $ts, $tz = false ) {
-               global $wgUser, $wgLocalTZoffset, $wgDBtimezone;
+               global $wgUser, $wgLocalTZoffset;
 
                if (!$tz) {
                        $tz = $wgUser->getOption( 'timecorrection' );
@@ -404,8 +420,12 @@ class Language {
                if ( $tz === '' ) {
                        # Global offset in minutes.
                        if( isset($wgLocalTZoffset) ) {
-                               $hrDiff = $wgLocalTZoffset % 60;
-                               $minDiff = $wgLocalTZoffset - ($hrDiff * 60);
+                               if( $wgLocalTZoffset >= 0 ) {
+                                       $hrDiff = floor($wgLocalTZoffset / 60);
+                               } else {
+                                       $hrDiff = ceil($wgLocalTZoffset / 60);
+                               }
+                               $minDiff = $wgLocalTZoffset % 60;
                        }
                } elseif ( strpos( $tz, ':' ) !== false ) {
                        $tzArray = explode( ':', $tz );
@@ -415,11 +435,6 @@ class Language {
                        $hrDiff = intval( $tz );
                }
 
-               # Account for databases that use timestamp with time zone
-               if ( isset($wgDBtimezone) ) {
-                       $hrDiff -= $wgDBtimezone;
-               }
-
                # No difference ? Return time unchanged
                if ( 0 == $hrDiff && 0 == $minDiff ) { return $ts; }
 
@@ -759,10 +774,7 @@ class Language {
        function timeanddate( $ts, $adj = false, $format = true, $timecorrection = false) {
                $this->load();
 
-               ## Account for non-integer timestamps
-               if (substr($ts,4,1) === '-') {
-                       $ts = preg_replace('/\D/', '', $ts);
-               }
+               $ts = wfTimestamp( TS_MW, $ts );
 
                if ( $adj ) { 
                        $ts = $this->userAdjust( $ts, $timecorrection );