* Fix explicit s-maxage=0 on raw pages; should help with proxy issues in
[lhc/web/wiklou.git] / includes / User.php
index 02f7ec3..2024364 100644 (file)
@@ -210,8 +210,22 @@ class User {
                        || $parsed->getNamespace()
                        || strcmp( $name, $parsed->getPrefixedText() ) )
                        return false;
-               else
-                       return true;
+               
+               // Check an additional blacklist of troublemaker characters.
+               // Should these be merged into the title char list?
+               $unicodeBlacklist = '/[' .
+                       '\x{0080}-\x{009f}' . # iso-8859-1 control chars
+                       '\x{00a0}' .          # non-breaking space
+                       '\x{2000}-\x{200f}' . # various whitespace
+                       '\x{2028}-\x{202f}' . # breaks and control chars
+                       '\x{3000}' .          # ideographic space
+                       '\x{e000}-\x{f8ff}' . # private use
+                       ']/u';
+               if( preg_match( $unicodeBlacklist, $name ) ) {
+                       return false;
+               }
+               
+               return true;
        }
 
        /**
@@ -293,7 +307,7 @@ class User {
                $fname = 'User::loadDefaults' . $n;
                wfProfileIn( $fname );
 
-               global $wgContLang, $wgDBname;
+               global $wgContLang, $wgCookiePrefix;
                global $wgNamespacesToBeSearchedDefault;
 
                $this->mId = 0;
@@ -315,8 +329,8 @@ class User {
                $this->setToken(); # Random
                $this->mHash = false;
 
-               if ( isset( $_COOKIE[$wgDBname.'LoggedOut'] ) ) {
-                       $this->mTouched = wfTimestamp( TS_MW, $_COOKIE[$wgDBname.'LoggedOut'] );
+               if ( isset( $_COOKIE[$wgCookiePrefix.'LoggedOut'] ) ) {
+                       $this->mTouched = wfTimestamp( TS_MW, $_COOKIE[$wgCookiePrefix.'LoggedOut'] );
                }
                else {
                        $this->mTouched = '0'; # Allow any pages to be cached
@@ -617,7 +631,7 @@ class User {
         * @static
         */
        function loadFromSession() {
-               global $wgMemc, $wgDBname;
+               global $wgMemc, $wgDBname, $wgCookiePrefix;
 
                if ( isset( $_SESSION['wsUserID'] ) ) {
                        if ( 0 != $_SESSION['wsUserID'] ) {
@@ -625,16 +639,16 @@ class User {
                        } else {
                                return new User();
                        }
-               } else if ( isset( $_COOKIE["{$wgDBname}UserID"] ) ) {
-                       $sId = intval( $_COOKIE["{$wgDBname}UserID"] );
+               } else if ( isset( $_COOKIE["{$wgCookiePrefix}UserID"] ) ) {
+                       $sId = intval( $_COOKIE["{$wgCookiePrefix}UserID"] );
                        $_SESSION['wsUserID'] = $sId;
                } else {
                        return new User();
                }
                if ( isset( $_SESSION['wsUserName'] ) ) {
                        $sName = $_SESSION['wsUserName'];
-               } else if ( isset( $_COOKIE["{$wgDBname}UserName"] ) ) {
-                       $sName = $_COOKIE["{$wgDBname}UserName"];
+               } else if ( isset( $_COOKIE["{$wgCookiePrefix}UserName"] ) ) {
+                       $sName = $_COOKIE["{$wgCookiePrefix}UserName"];
                        $_SESSION['wsUserName'] = $sName;
                } else {
                        return new User();
@@ -657,8 +671,8 @@ class User {
 
                if ( isset( $_SESSION['wsToken'] ) ) {
                        $passwordCorrect = $_SESSION['wsToken'] == $user->mToken;
-               } else if ( isset( $_COOKIE["{$wgDBname}Token"] ) ) {
-                       $passwordCorrect = $user->mToken == $_COOKIE["{$wgDBname}Token"];
+               } else if ( isset( $_COOKIE["{$wgCookiePrefix}Token"] ) ) {
+                       $passwordCorrect = $user->mToken == $_COOKIE["{$wgCookiePrefix}Token"];
                } else {
                        return new User(); # Can't log in from session
                }
@@ -796,6 +810,23 @@ class User {
                return (bool)$this->mNewtalk;
        }
 
+       /**
+        * Return the talk page(s) this user has new messages on.
+        */
+       function getNewMessageLinks() {
+       global  $wgDBname;
+               $talks = array();
+               if (!wfRunHooks('UserRetrieveNewTalks', array(&$this, &$talks)))
+                       return $talks;
+
+               if (!$this->getNewtalk())
+                       return array();
+               $up = $this->getUserPage();
+               $utp = $up->getTalkPage();
+               return array(array("wiki" => $wgDBname, "link" => $utp->getLocalURL()));
+       }
+
+               
        /**
         * Perform a user_newtalk check on current slaves; if the memcached data
         * is funky we don't want newtalk state to get stuck on save, as that's
@@ -1210,8 +1241,11 @@ class User {
        function clearNotification( &$title ) {
                global $wgUser, $wgUseEnotif;
 
+
                if ($title->getNamespace() == NS_USER_TALK &&
                        $title->getText() == $this->getName() ) {
+                       if (!wfRunHooks('UserClearNewTalkNotification', array(&$this)))
+                               return;
                        $this->setNewtalk( false );
                }
 
@@ -1852,26 +1886,6 @@ class User {
                        array_keys( $wgGroupPermissions ),
                        array( '*', 'user', 'autoconfirmed' ) );
        }
-
-       /**
-        * Return the set of groups which are not marked "invisible"
-        * @return array
-        * @static
-        */
-       function getVisibleGroups() {
-               global $wgGroupPermissions, $wgInvisibleGroups;
-               return array_diff( User::getAllGroups(), $wgInvisibleGroups );
-       }
-
-       /**
-        * Determine if a given group name is a valid, visible group
-        * @param string name
-        * @return bool
-        */
-       function isVisibleGroup( $group ) {
-               global $wgGroupPermissions, $wgInvisibleGroups;
-               return isset( $wgGroupPermissions[$group] ) && !in_array( $group, $wgInvisibleGroups );
-       }
 }
 
 ?>