Index: trunk/phpwiki/fpw/wikiUser.php |
— | — | @@ -2,267 +2,277 @@ |
3 | 3 | # The wikiUser class handles all user information |
4 | 4 | |
5 | 5 | class WikiUser { |
6 | | - var $id , $name , $password , $retypePassword ; |
7 | | - var $options , $email ; |
8 | | - var $rights ; |
9 | | - var $isLoggedIn ; # Is this user currently logged in? |
| 6 | + var $id , $name , $password , $retypePassword ; |
| 7 | + var $options , $email ; |
| 8 | + var $rights ; |
| 9 | + var $isLoggedIn ; # Is this user currently logged in? |
10 | 10 | |
11 | 11 | #### Skin functions |
12 | 12 | |
13 | | - # Creates the options for the currently selected skin by calling the appropriate function |
14 | | - function skin () { |
15 | | - if ( $this->options["skin"] == "" ) $this->skinBlank () ; |
16 | | - else if ( $this->options["skin"] == "None" ) $this->skinBlank () ; |
17 | | - else if ( $this->options["skin"] == "Star Trek" ) $this->skinStarTrek () ; |
18 | | - } |
| 13 | + # Creates the options for the currently selected skin by calling the appropriate function |
| 14 | + function skin () { |
| 15 | + if ( $this->options["skin"] == "" ) $this->skinBlank () ; |
| 16 | + else if ( $this->options["skin"] == "None" ) $this->skinBlank () ; |
| 17 | + else if ( $this->options["skin"] == "Star Trek" ) $this->skinStarTrek () ; |
| 18 | + } |
19 | 19 | |
20 | | - # This sets the options for the standard skin |
21 | | - function skinBlank () { |
22 | | - #$this->options["background"] = " BGCOLOR=\"#FFFFFF\"" ; |
23 | | - $this->options["background"] = "#FFFFFF" ; |
24 | | - $this->options["text"] = "" ; |
25 | | - $this->options["forceQuickBar"] = "" ; |
26 | | - $this->options["quickBarBackground"] = "" ; |
27 | | - $this->options["textTableBackground"] = "" ; |
28 | | - $this->options["forceLinks"] = "" ; |
29 | | - $this->options["leftImage"] = "" ; |
30 | | - $this->options["borderColor"] = "black" ; |
31 | | - $this->options["tabLine0"] = " bgcolor=\"#BBBBBB\" " ; |
32 | | - $this->options["tabLine1"] = "" ; |
33 | | - $this->options["tabLine2"] = " bgcolor=\"#FFFFCC\"" ; |
34 | | - } |
| 20 | + # This sets the options for the standard skin |
| 21 | + function skinBlank () { |
| 22 | + #$this->options["background"] = " BGCOLOR=\"#FFFFFF\"" ; |
| 23 | + $this->options["background"] = "#FFFFFF" ; |
| 24 | + $this->options["text"] = "" ; |
| 25 | + $this->options["forceQuickBar"] = "" ; |
| 26 | + $this->options["quickBarBackground"] = "" ; |
| 27 | + $this->options["textTableBackground"] = "" ; |
| 28 | + $this->options["forceLinks"] = "" ; |
| 29 | + $this->options["leftImage"] = "" ; |
| 30 | + $this->options["borderColor"] = "black" ; |
| 31 | + $this->options["tabLine0"] = " bgcolor=\"#BBBBBB\" " ; |
| 32 | + $this->options["tabLine1"] = "" ; |
| 33 | + $this->options["tabLine2"] = " bgcolor=\"#FFFFCC\"" ; |
| 34 | + } |
35 | 35 | |
36 | | - # This sets the options for the StarTrek skin |
37 | | - function skinStarTrek () { |
38 | | - global $wikiStarTrekImage ; |
39 | | - #$this->options["background"] = " BGCOLOR=\"#000000\" " ; |
40 | | - #$this->options["text"] = " TEXT=\"#00BB00\" " ; |
41 | | - $this->options["background"] = "#000000" ; |
42 | | - $this->options["text"] = "#00BB00" ; |
43 | | - $this->options["forceQuickBar"] = "left" ; |
44 | | - $this->options["quickBarBackground"] = " bgcolor=yellow " ; |
45 | | - $this->options["textTableBackground"] = " bgcolor=\"#444444\"" ; |
46 | | - $this->options["forceLinks"] = " style=\"color:#0000FF;text-decoration:none\" " ; |
47 | | - $this->options["leftImage"] = $wikiStarTrekImage ; |
48 | | - $this->options["borderColor"] = "yellow" ; |
49 | | - $this->options["tabLine0"] = " bgcolor=\"#550055\" " ; |
50 | | - $this->options["tabLine1"] = "" ; |
51 | | - $this->options["tabLine2"] = " bgcolor=\"#333333\"" ; |
52 | | - } |
53 | | - |
54 | | - # Creates a style sheet for the page from the skin & link style options |
55 | | - function styleSheet( $action = "view" ) { |
56 | | - global $namespaceBackground ; |
57 | | - $ret = "<style type=\"text/css\"><!--\n"; |
58 | | - $ret .= "body { "; |
59 | | - $textcolor = $this->options[text]; |
60 | | - $bgcolor = $this->options[background]; |
61 | | - if ( $namespaceBackground != "" ) $bgcolor = $namespaceBackground ; |
62 | | - if ( $textcolor == "" ) |
63 | | - $textcolor = "black"; # For un-coloring links. Should be "inherit" but Netscape 4.x messes it up |
64 | | - else |
65 | | - $ret .= "color: $textcolor; "; |
66 | | - if ( $bgcolor == "" ) |
67 | | - $bgcolor = "white"; |
68 | | - else |
69 | | - $ret .= "background: $bgcolor; "; |
70 | | - $ret .= "}\n"; |
71 | | - |
72 | | - $ret .= "p.bodytext { " . (($this->options[justify] == "yes") ? "text-align: justify; " : "") . "}\n"; |
73 | | - $ret .= "a { text-decoration: " . (($this->options[underlineLinks] == "no") ? "none" : "underline") . "; }\n"; |
74 | | - |
75 | | - $qbside = ( $this->options["quickBar"] == "left" ) ? "right" : "left"; |
76 | | - $ret .= "a.interwiki, a.external { color: #3333BB; text-decoration: none; }\n" . |
77 | | - "a.red { color: red; text-decoration: none; }\n" . |
78 | | - "a.green { color: green; text-decoration: none; }\n" . |
79 | | - ".topbar { border-bottom-width: 2; border-bottom-style: ridge; }\n" . |
80 | | - ".middle { }\n" . |
81 | | - ".quickbar { border-$qbside-width: 2; border-$qbside-style: ridge; }\n" . |
82 | | - ".footer { border-top-color: black; border-top-width: 2; border-top-style: groove; }\n"; |
83 | | - |
84 | | - if ( $action == "print" ) { |
85 | | - $ret .= "a { color: inherit; text-decoration: none; font-style: italic; }\n "; |
86 | | - $ret .= "a.newlink { color: inherit; font-style: inherit; }\n.newlinkedge { display: none; }\n"; |
87 | | - } elseif ( $this->options[markupNewTopics] == "red") { |
88 | | - $ret .= "a.newlink { color: red; }\n.newlinkedge { display: none; }\n"; |
89 | | - } elseif ( $this->options[markupNewTopics] == "inverse") { |
90 | | - $ret .= "a.newlink { color: white; background: blue; }\n.newlinkedge { display: inline; }\n"; |
91 | | - } else { |
92 | | - $ret .= "a.newlink { color: $textcolor; text-decoration: none; }\n.newlinkedge { display: inline; }\n"; |
93 | | - } |
94 | | - $ret .= "//--></style>"; |
95 | | - return $ret; |
96 | | - } |
| 36 | + # This sets the options for the StarTrek skin |
| 37 | + function skinStarTrek () { |
| 38 | + global $wikiStarTrekImage ; |
| 39 | + #$this->options["background"] = " BGCOLOR=\"#000000\" " ; |
| 40 | + #$this->options["text"] = " TEXT=\"#00BB00\" " ; |
| 41 | + $this->options["background"] = "#000000" ; |
| 42 | + $this->options["text"] = "#00BB00" ; |
| 43 | + $this->options["forceQuickBar"] = "left" ; |
| 44 | + $this->options["quickBarBackground"] = " bgcolor=yellow " ; |
| 45 | + $this->options["textTableBackground"] = " bgcolor=\"#444444\"" ; |
| 46 | + $this->options["forceLinks"] = " style=\"color:#0000FF;text-decoration:none\" " ; |
| 47 | + $this->options["leftImage"] = $wikiStarTrekImage ; |
| 48 | + $this->options["borderColor"] = "yellow" ; |
| 49 | + $this->options["tabLine0"] = " bgcolor=\"#550055\" " ; |
| 50 | + $this->options["tabLine1"] = "" ; |
| 51 | + $this->options["tabLine2"] = " bgcolor=\"#333333\"" ; |
| 52 | + } |
| 53 | + |
| 54 | + # Creates a style sheet for the page from the skin & link style options |
| 55 | + function styleSheet( $action = "view" ) { |
| 56 | + global $namespaceBackground ; |
| 57 | + $ret = "<style type=\"text/css\"><!--\n"; |
| 58 | + $ret .= "body { "; |
| 59 | + $textcolor = $this->options[text]; |
| 60 | + $bgcolor = $this->options[background]; |
| 61 | + if ( $namespaceBackground != "" ) $bgcolor = $namespaceBackground ; |
| 62 | + if ( $textcolor == "" ) |
| 63 | + $textcolor = "black"; # For un-coloring links. Should be "inherit" but Netscape 4.x messes it up |
| 64 | + else |
| 65 | + $ret .= "color: $textcolor; "; |
| 66 | + if ( $bgcolor == "" ) |
| 67 | + $bgcolor = "white"; |
| 68 | + else |
| 69 | + $ret .= "background: $bgcolor; "; |
| 70 | + $ret .= "}\n"; |
| 71 | + |
| 72 | + $ret .= "p.bodytext { " . (($this->options[justify] == "yes") ? "text-align: justify; " : "") . "}\n"; |
| 73 | + $ret .= "a { text-decoration: " . (($this->options[underlineLinks] == "no") ? "none" : "underline") . "; }\n"; |
| 74 | + |
| 75 | + $qbside = ( $this->options["quickBar"] == "left" ) ? "right" : "left"; |
| 76 | + $ret .= "a.interwiki, a.external { color: #3333BB; text-decoration: none; }\n" . |
| 77 | + "a.red { color: red; text-decoration: none; }\n" . |
| 78 | + "a.green { color: green; text-decoration: none; }\n" . |
| 79 | + ".topbar { border-bottom-width: 2; border-bottom-style: ridge; }\n" . |
| 80 | + ".middle { }\n" . |
| 81 | + ".quickbar { border-$qbside-width: 2; border-$qbside-style: ridge; }\n" . |
| 82 | + ".footer { border-top-color: black; border-top-width: 2; border-top-style: groove; }\n"; |
| 83 | + |
| 84 | + if ( $action == "print" ) { |
| 85 | + $ret .= "a { color: inherit; text-decoration: none; font-style: italic; }\n "; |
| 86 | + $ret .= "a.newlink { color: inherit; font-style: inherit; }\n.newlinkedge { display: none; }\n"; |
| 87 | + } elseif ( $this->options[markupNewTopics] == "red") { |
| 88 | + $ret .= "a.newlink { color: red; }\n.newlinkedge { display: none; }\n"; |
| 89 | + } elseif ( $this->options[markupNewTopics] == "inverse") { |
| 90 | + $ret .= "a.newlink { color: white; background: blue; }\n.newlinkedge { display: inline; }\n"; |
| 91 | + } else { |
| 92 | + $ret .= "a.newlink { color: $textcolor; text-decoration: none; }\n.newlinkedge { display: inline; }\n"; |
| 93 | + } |
| 94 | + $ret .= "//--></style>"; |
| 95 | + return $ret; |
| 96 | + } |
97 | 97 | |
98 | 98 | #### Management functions |
99 | 99 | |
100 | | - # This checks the cookies for prior log-ins |
101 | | - function scanCookies () { |
102 | | - global $WikiUserID , $WikiUserPassword , $WikiLoggedIn ; |
103 | | - $this->id = 0 ; |
104 | | - $this->name = "" ; |
105 | | - $this->isLoggedIn = false ; |
106 | | - if ( $WikiUserID > 0 and $WikiLoggedIn == "yes" ) { |
107 | | - $connection = getDBconnection () ; |
108 | | - $sql = "SELECT * FROM user WHERE user_id=$WikiUserID" ; |
109 | | - $result = mysql_query ( $sql , $connection ) ; |
110 | | - if ( $result ) { |
111 | | - $s = mysql_fetch_object ( $result ) ; |
112 | | - $this->name = $s->user_name ; |
113 | | - if ( $WikiUserPassword == $s->user_password ) { |
114 | | - $this->password = $s->user_password ; |
115 | | - $this->id = $s->user_id ; |
116 | | - $this->isLoggedIn = true ; |
117 | | - } |
118 | | - mysql_free_result ( $result ) ; |
119 | | - } |
120 | | - } |
121 | | - $this->loadSettings () ; |
122 | | - $this->ensureDefaultOptions () ; |
123 | | - $this->skin () ; |
124 | | - } |
| 100 | + # This checks the cookies for prior log-ins |
| 101 | + function scanCookies () { |
| 102 | + global $WikiUserID , $WikiUserPassword , $WikiLoggedIn ; |
| 103 | + $this->id = 0 ; |
| 104 | + $this->name = "" ; |
| 105 | + $this->isLoggedIn = false ; |
| 106 | + if ( $WikiUserID > 0 and $WikiLoggedIn == "yes" ) { |
| 107 | + $connection = getDBconnection () ; |
| 108 | + $sql = "SELECT * FROM user WHERE user_id=$WikiUserID" ; |
| 109 | + $result = mysql_query ( $sql , $connection ) ; |
| 110 | + if ( $result ) { |
| 111 | + $s = mysql_fetch_object ( $result ) ; |
| 112 | + $this->name = $s->user_name ; |
| 113 | + if ( $WikiUserPassword == $s->user_password ) { |
| 114 | + $this->password = $s->user_password ; |
| 115 | + $this->id = $s->user_id ; |
| 116 | + $this->isLoggedIn = true ; |
| 117 | + } |
| 118 | + mysql_free_result ( $result ) ; |
| 119 | + } |
| 120 | + } |
| 121 | + $this->loadSettings () ; |
| 122 | + $this->ensureDefaultOptions () ; |
| 123 | + $this->skin () ; |
| 124 | + } |
125 | 125 | |
126 | | - # This sets the default options for new and no-log-in users |
127 | | - function ensureDefaultOptions () { |
128 | | - if ( $this->options["quickBar"] == "" ) $this->options["quickBar"] = "right" ; # For demonstration |
129 | | - if ( $this->options["markupNewTopics"] == "" ) $this->options["markupNewTopics"] = "normal" ; |
130 | | - if ( $this->options["underlineLinks"] == "" ) $this->options["underlineLinks"] = "yes" ; |
131 | | - if ( $this->options["showHover"] == "" ) $this->options["showHover"] = "yes" ; |
132 | | - if ( $this->options["cols"] == "" ) $this->options["cols"] = "60" ; |
133 | | - if ( $this->options["rows"] == "" ) $this->options["rows"] = "20" ; |
134 | | - if ( $this->options["changesLayout"] == "" ) $this->options["changesLayout"] = "classic" ; |
135 | | - if ( $this->options["hideMinor"] == "" ) $this->options["hideMinor"] = "no" ; |
136 | | - if ( $this->options["justify"] == "" ) $this->options["justify"] = "no" ; |
137 | | - if ( $this->options["resultsPerPage"] == "" ) $this->options["resultsPerPage"] = "20" ; |
138 | | - if ( $this->options["skin"] == "" ) $this->options["skin"] = "None" ; |
139 | | - if ( $this->options["hourDiff"] == "" ) $this->options["hourDiff"] = "0" ; |
140 | | - if ( $this->options["encoding"] == "") $this->options["encoding"] = 0; |
141 | | - if ( $this->options["numberHeadings"] == "" ) $this->options["numberHeadings"] = "no" ; |
142 | | - if ( $this->options["viewFrames"] == "" ) $this->options["viewFrames"] = "no" ; |
143 | | - if ( $this->options["viewRecentChanges"] == "" ) $this->options["viewRecentChanges"] = "50" ; |
| 126 | + # This sets the default options for new and no-log-in users |
| 127 | + function ensureDefaultOptions () { |
| 128 | + if ( $this->options["quickBar"] == "" ) $this->options["quickBar"] = "right" ; # For demonstration |
| 129 | + if ( $this->options["markupNewTopics"] == "" ) $this->options["markupNewTopics"] = "normal" ; |
| 130 | + if ( $this->options["underlineLinks"] == "" ) $this->options["underlineLinks"] = "yes" ; |
| 131 | + if ( $this->options["showHover"] == "" ) $this->options["showHover"] = "yes" ; |
| 132 | + if ( $this->options["cols"] == "" ) $this->options["cols"] = "60" ; |
| 133 | + if ( $this->options["rows"] == "" ) $this->options["rows"] = "20" ; |
| 134 | + if ( $this->options["changesLayout"] == "" ) $this->options["changesLayout"] = "classic" ; |
| 135 | + if ( $this->options["hideMinor"] == "" ) $this->options["hideMinor"] = "no" ; |
| 136 | + if ( $this->options["justify"] == "" ) $this->options["justify"] = "no" ; |
| 137 | + if ( $this->options["resultsPerPage"] == "" ) $this->options["resultsPerPage"] = "20" ; |
| 138 | + if ( $this->options["skin"] == "" ) $this->options["skin"] = "None" ; |
| 139 | + if ( $this->options["hourDiff"] == "" ) $this->options["hourDiff"] = "0" ; |
| 140 | + if ( $this->options["encoding"] == "") $this->options["encoding"] = 0; |
| 141 | + if ( $this->options["numberHeadings"] == "" ) $this->options["numberHeadings"] = "no" ; |
| 142 | + if ( $this->options["viewFrames"] == "" ) $this->options["viewFrames"] = "no" ; |
| 143 | + if ( $this->options["viewRecentChanges"] == "" ) $this->options["viewRecentChanges"] = "50" ; |
144 | 144 | |
145 | | -# if ( $this->options["showStructure"] == "" ) # NO SUBPAGES ANYMORE |
146 | | - $this->options["showStructure"] = "no" ; |
147 | | - } |
| 145 | +# if ( $this->options["showStructure"] == "" ) # NO SUBPAGES ANYMORE |
| 146 | + $this->options["showStructure"] = "no" ; |
| 147 | + } |
148 | 148 | |
149 | | - # Loads the user settings from the database |
150 | | - function loadSettings () { |
151 | | - $this->rights = array () ; |
152 | | - if ( !$this->isLoggedIn ) return ; |
153 | | - $t = getMySQL ( "user" , "user_options" , "user_id=".$this->id ) ; |
154 | | - $t = urldecode ( $t ) ; |
155 | | - $a = explode ( "\n" , $t ) ; |
156 | | - $this->options = array () ; |
157 | | - foreach ( $a as $x ) { |
158 | | - $b = explode ( "=" , $x ) ; |
159 | | - $this->options[$b[0]] = $b[1] ; |
160 | | - } |
161 | | - $t = getMySQL ( "user" , "user_rights" , "user_id=".$this->id ) ; |
162 | | - $this->rights = explode ( "," , strtolower ( $t ) ) ; |
163 | | - $this->password = getMySQL ( "user" , "user_password" , "user_id=".$this->id ) ; |
164 | | - $this->email = getMySQL ( "user" , "user_email" , "user_id=".$this->id ) ; |
165 | | - $this->skin () ; |
166 | | - } |
| 149 | + # Loads the user settings from the database |
| 150 | + function loadSettings () { |
| 151 | + $this->rights = array () ; |
| 152 | + |
| 153 | + # if the user is not logged in, there are no settings |
| 154 | + if ( !$this->isLoggedIn ) return ; |
| 155 | + |
| 156 | + # get the settings from the database |
| 157 | + $connection = getDBconnection() ; |
| 158 | + $sql = "SELECT user_options, user_rights, user_password, user_email |
| 159 | + FROM user |
| 160 | + WHERE user_id = $this->id" ; |
| 161 | + $result = mysql_query ( $sql , $connection ) ; |
| 162 | + $t = mysql_fetch_object ( $result ) ; |
| 163 | + mysql_free_result ( $result ) ; |
| 164 | + |
| 165 | + # filling the settings variables |
| 166 | + $this->options = array () ; |
| 167 | + $a = explode ( "\n" , urldecode ( $t->user_options ) ) ; |
| 168 | + foreach ( $a as $x ) { |
| 169 | + $b = explode ( "=" , $x ) ; |
| 170 | + $this->options[$b[0]] = $b[1] ; |
| 171 | + } |
| 172 | + $this->rights = explode ( "," , strtolower ( $t->user_rights ) ) ; |
| 173 | + $this->password = $t->user_password ; |
| 174 | + $this->email = $t->user_email ; |
| 175 | + $this->skin () ; |
| 176 | + } |
167 | 177 | |
168 | | - # Saves/updates the user settings in the database |
169 | | - function saveSettings () { |
170 | | - global $expiration ; |
171 | | - if ( !$this->isLoggedIn ) return ; |
172 | | - $t = "" ; |
173 | | - $a = array_keys ( $this->options ) ; |
174 | | - foreach ( $a as $x ) { |
175 | | - if ( $x != "" ) { |
176 | | - if ( $t != "" ) $t .= "\n" ; |
177 | | - $t .= $x."=".$this->options[$x] ; |
178 | | - } |
179 | | - } |
180 | | - setMySQL ( "user" , "user_options" , nurlencode ( $t ) , "user_id=".$this->id ) ; |
181 | | - setMySQL ( "user" , "user_password" , $this->password , "user_id=".$this->id ) ; |
182 | | - setMySQL ( "user" , "user_email" , $this->email , "user_id=".$this->id ) ; |
183 | | - if ( $this->options["rememberPassword"] == "on" ) setcookie ( "WikiUserPassword" , $this->password , $expiration ) ; |
184 | | - } |
| 178 | + # Saves/updates the user settings in the database |
| 179 | + function saveSettings () { |
| 180 | + global $expiration ; |
| 181 | + if ( !$this->isLoggedIn ) return ; |
| 182 | + $t = "" ; |
| 183 | + $a = array_keys ( $this->options ) ; |
| 184 | + foreach ( $a as $x ) { |
| 185 | + if ( $x != "" ) { |
| 186 | + if ( $t != "" ) $t .= "\n" ; |
| 187 | + $t .= $x."=".$this->options[$x] ; |
| 188 | + } |
| 189 | + } |
| 190 | + setMySQL ( "user" , "user_options" , nurlencode ( $t ) , "user_id=".$this->id ) ; |
| 191 | + setMySQL ( "user" , "user_password" , $this->password , "user_id=".$this->id ) ; |
| 192 | + setMySQL ( "user" , "user_email" , $this->email , "user_id=".$this->id ) ; |
| 193 | + if ( $this->options["rememberPassword"] == "on" ) setcookie ( "WikiUserPassword" , $this->password , $expiration ) ; |
| 194 | + } |
185 | 195 | |
186 | | - # Creates a link to the user home page, or returns the IP |
187 | | - function getLink () { |
188 | | - global $wikiUser ; |
189 | | - if ( $this->isLoggedIn ) { |
190 | | - $s = new WikiPage ; |
191 | | - $s = $s->parseContents ( "[[$wikiUser:$this->name|$this->name]]" ) ; |
192 | | - $s = substr ( strstr ( $s , ">" ) , 1 ) ; |
193 | | - $s = str_replace ( "</p>" , "" , $s ) ; |
194 | | - return $s ; |
195 | | - } |
| 196 | + # Creates a link to the user home page, or returns the IP |
| 197 | + function getLink () { |
| 198 | + global $wikiUser ; |
| 199 | + if ( $this->isLoggedIn ) { |
| 200 | + $s = new WikiPage ; |
| 201 | + $s = $s->parseContents ( "[[$wikiUser:$this->name|$this->name]]" ) ; |
| 202 | + $s = substr ( strstr ( $s , ">" ) , 1 ) ; |
| 203 | + $s = str_replace ( "</p>" , "" , $s ) ; |
| 204 | + return $s ; |
| 205 | + } |
196 | 206 | |
197 | | - # These headers can be exploited to falsify an IP. Probably not worth bothering with them, |
198 | | - # let proxies be proxies. |
199 | | - #if ( getenv ( HTTP_X_FORWARDED_FOR ) ) $s = getenv ( HTTP_X_FORWARDED_FOR ) ; |
200 | | - #elseif ( getenv ( HTTP_CLIENT_IP ) ) $s = getenv ( HTTP_CLIENT_IP ) ; |
201 | | - #else $s = getenv ( REMOTE_ADDR ) ; |
202 | | - $s = getenv ( REMOTE_ADDR ) ; |
| 207 | + # These headers can be exploited to falsify an IP. Probably not worth bothering with them, |
| 208 | + # let proxies be proxies. |
| 209 | + #if ( getenv ( HTTP_X_FORWARDED_FOR ) ) $s = getenv ( HTTP_X_FORWARDED_FOR ) ; |
| 210 | + #elseif ( getenv ( HTTP_CLIENT_IP ) ) $s = getenv ( HTTP_CLIENT_IP ) ; |
| 211 | + #else $s = getenv ( REMOTE_ADDR ) ; |
| 212 | + $s = getenv ( REMOTE_ADDR ) ; |
203 | 213 | |
204 | 214 | |
205 | | -# THIS USED TO CHANGE THE URL OF NON LOGGED-IN USERS TO ".xxx" ; |
206 | | -# $s = explode ( "." , $s ) ; |
207 | | -# $s = $s[0].".".$s[1].".".$s[2].".xxx" ; |
208 | | - return $s ; |
209 | | - } |
| 215 | +# THIS USED TO CHANGE THE URL OF NON LOGGED-IN USERS TO ".xxx" ; |
| 216 | +# $s = explode ( "." , $s ) ; |
| 217 | +# $s = $s[0].".".$s[1].".".$s[2].".xxx" ; |
| 218 | + return $s ; |
| 219 | + } |
210 | 220 | |
211 | | - # Checks if a user with that name exists |
212 | | - function doesUserExist () { |
213 | | - $s = trim ( $this->name ) ; |
214 | | - if ( $s == "" ) return false ; |
215 | | - $connection = getDBconnection () ; |
216 | | - $sql = "SELECT user_id FROM user WHERE user_name=\"$s\"" ; |
217 | | - $result = mysql_query ( $sql , $connection ) ; |
218 | | - if ( $result == "" ) { |
219 | | - return false ; |
220 | | - } |
221 | | - $s = mysql_fetch_object ( $result ) ; |
222 | | - mysql_free_result ( $result ) ; |
223 | | - if ( $s == "" ) return false ; |
224 | | - return true ; |
225 | | - } |
| 221 | + # Checks if a user with that name exists |
| 222 | + function doesUserExist () { |
| 223 | + $s = trim ( $this->name ) ; |
| 224 | + if ( $s == "" ) return false ; |
| 225 | + $connection = getDBconnection () ; |
| 226 | + $sql = "SELECT user_id FROM user WHERE user_name=\"$s\"" ; |
| 227 | + $result = mysql_query ( $sql , $connection ) ; |
| 228 | + if ( $result == "" ) { |
| 229 | + return false ; |
| 230 | + } |
| 231 | + $s = mysql_fetch_object ( $result ) ; |
| 232 | + mysql_free_result ( $result ) ; |
| 233 | + if ( $s == "" ) return false ; |
| 234 | + return true ; |
| 235 | + } |
226 | 236 | |
227 | | - # Adds a new user to the database |
228 | | - function addToDatabase () { |
229 | | - $connection = getDBconnection () ; |
230 | | - $sql = "INSERT INTO user (user_name,user_password) VALUES (\"$this->name\",\"$this->password\")" ; |
231 | | - $result = mysql_query ( $sql , $connection ) ; |
232 | | - } |
| 237 | + # Adds a new user to the database |
| 238 | + function addToDatabase () { |
| 239 | + $connection = getDBconnection () ; |
| 240 | + $sql = "INSERT INTO user (user_name,user_password) VALUES (\"$this->name\",\"$this->password\")" ; |
| 241 | + $result = mysql_query ( $sql , $connection ) ; |
| 242 | + } |
233 | 243 | |
234 | | - # Checks the login |
235 | | - function verify () { |
236 | | - global $wikiNoSuchUser , $wikiWrongPassword , $wikiYouAreLoggedIn , $wikiUserError ; |
237 | | - $this->isLoggedIn = false ; |
238 | | - if ( !$this->doesUserExist() ) return str_replace ( "$1" , $this->name , $wikiNoSuchUser ) ; |
239 | | - $connection = getDBconnection () ; |
240 | | - $sql = "SELECT * FROM user WHERE user_name=\"$this->name\"" ; |
241 | | - $result = mysql_query ( $sql , $connection ) ; |
242 | | - if ( $result == "" ) return str_replace ( "$1" , $this->name , $wikiNoSuchUser ) ; |
243 | | - if ( $s = mysql_fetch_object ( $result ) ) { |
244 | | - mysql_free_result ( $result ) ; |
245 | | - if ( $s->user_password == $this->password ) { |
246 | | - $ret = str_replace ( "$1" , $this->name , $wikiYouAreLoggedIn ) ; |
247 | | - $this->id = $s->user_id ; |
248 | | - $this->isLoggedIn = true ; |
249 | | - $this->loadSettings() ; |
250 | | - } else { |
251 | | - $ret = str_replace ( "$1" , $this->name , $wikiWrongPassword ) ; |
252 | | - } |
253 | | - } |
254 | | - else { |
255 | | - mysql_free_result ( $result ) ; |
256 | | - $this->contents = str_replace ( "$1" , $this->name , $wikiUserError ) ; |
257 | | - } |
258 | | - |
259 | | - return $ret ; |
260 | | - } |
| 244 | + # Checks the login |
| 245 | + function verify () { |
| 246 | + global $wikiNoSuchUser , $wikiWrongPassword , $wikiYouAreLoggedIn , $wikiUserError ; |
| 247 | + $this->isLoggedIn = false ; |
| 248 | + if ( !$this->doesUserExist() ) return str_replace ( "$1" , $this->name , $wikiNoSuchUser ) ; |
| 249 | + $connection = getDBconnection () ; |
| 250 | + $sql = "SELECT * FROM user WHERE user_name=\"$this->name\"" ; |
| 251 | + $result = mysql_query ( $sql , $connection ) ; |
| 252 | + if ( $result == "" ) return str_replace ( "$1" , $this->name , $wikiNoSuchUser ) ; |
| 253 | + if ( $s = mysql_fetch_object ( $result ) ) { |
| 254 | + mysql_free_result ( $result ) ; |
| 255 | + if ( $s->user_password == $this->password ) { |
| 256 | + $ret = str_replace ( "$1" , $this->name , $wikiYouAreLoggedIn ) ; |
| 257 | + $this->id = $s->user_id ; |
| 258 | + $this->isLoggedIn = true ; |
| 259 | + $this->loadSettings() ; |
| 260 | + } else { |
| 261 | + $ret = str_replace ( "$1" , $this->name , $wikiWrongPassword ) ; |
| 262 | + } |
| 263 | + } |
| 264 | + else { |
| 265 | + mysql_free_result ( $result ) ; |
| 266 | + $this->contents = str_replace ( "$1" , $this->name , $wikiUserError ) ; |
| 267 | + } |
| 268 | + |
| 269 | + return $ret ; |
| 270 | + } |
261 | 271 | |
262 | | - # Toggles the watch on an article for this user |
263 | | - function doWatch ( $t ) { |
264 | | - $a = getMySQL ( "user" , "user_watch" , "user_id=$this->id" ) ; |
265 | | - $b = explode ( "\n" , $a ) ; |
266 | | - return in_array ( $t , $b ) ; |
267 | | - } |
268 | | - } |
| 272 | + # Toggles the watch on an article for this user |
| 273 | + function doWatch ( $t ) { |
| 274 | + $a = getMySQL ( "user" , "user_watch" , "user_id=$this->id" ) ; |
| 275 | + $b = explode ( "\n" , $a ) ; |
| 276 | + return in_array ( $t , $b ) ; |
| 277 | + } |
| 278 | + } |
269 | 279 | ?> |