Index: branches/avendor/phpwiki/wikipediaPHPScript.txt |
— | — | @@ -0,0 +1,1115 @@ |
| 2 | +<i>The script below is wrapped with "pre" tags for display (remove them to use the script).</i> |
| 3 | +---- |
| 4 | +<pre> |
| 5 | +<? |
| 6 | +function getSecureTitle ( $s ) { |
| 7 | + $s=str_replace(" ","_",$s); |
| 8 | + $s=strtoupper(substr($s,0,1)).substr($s,1); |
| 9 | + return $s ; |
| 10 | + } |
| 11 | + |
| 12 | +function getDBconnection () { |
| 13 | + $server="127.0.0.1" ; |
| 14 | + $user="manske" ; |
| 15 | + $passwd="*****" ; |
| 16 | + $connection=mysql_connect ( $server , $user , $passwd ) ; |
| 17 | + return $connection ; |
| 18 | + } |
| 19 | + |
| 20 | +####################################################################### USER FUNCTIONS |
| 21 | + |
| 22 | +function getCurrentUserName () { |
| 23 | + global $USERNAME , $USERPASSWORD , $USERLOGGEDIN ; |
| 24 | + global $REMOTE_ADDR ; |
| 25 | + if ( $USERLOGGEDIN == "YES" ) return $USERNAME ; |
| 26 | + else return $REMOTE_ADDR ; |
| 27 | + } |
| 28 | + |
| 29 | +function doesUserExist ( $un ) { |
| 30 | + $connection=getDBconnection() ; |
| 31 | + mysql_select_db ( "nikipedia" , $connection ) ; |
| 32 | + $sql = "SELECT * FROM user WHERE user_name=\"$un\"" ; |
| 33 | + $result = mysql_query ( $sql , $connection ) ; |
| 34 | + if ( $s = mysql_fetch_object ( $result ) ) $ret = true ; |
| 35 | + else $ret = false ; |
| 36 | + mysql_free_result ( $result ) ; |
| 37 | + mysql_close ( $connection ) ; |
| 38 | + return $ret ; |
| 39 | + } |
| 40 | + |
| 41 | +function getUserSetting ( $un , $s ) { |
| 42 | + $connection=getDBconnection() ; |
| 43 | + mysql_select_db ( "nikipedia" , $connection ) ; |
| 44 | + $sql = "SELECT * FROM user WHERE user_name=\"$un\"" ; |
| 45 | + $result = mysql_query ( $sql , $connection ) ; |
| 46 | + $t = mysql_fetch_object ( $result ) ; |
| 47 | + $ret = $t->$s ; |
| 48 | + mysql_free_result ( $result ) ; |
| 49 | + mysql_close ( $connection ) ; |
| 50 | + return $ret ; |
| 51 | + } |
| 52 | + |
| 53 | +function changeUserSetting ( $un , $s , $v ) { |
| 54 | + $connection=getDBconnection() ; |
| 55 | + mysql_select_db ( "nikipedia" , $connection ) ; |
| 56 | + $sql = "UPDATE user SET $s = \"$v\" WHERE user_name = \"$un\"" ; |
| 57 | + $result = mysql_query ( $sql , $connection ) ; |
| 58 | + mysql_close ( $connection ) ; |
| 59 | + } |
| 60 | + |
| 61 | +function checkUserPassword ( $un , $up ) { |
| 62 | + $connection=getDBconnection() ; |
| 63 | + mysql_select_db ( "nikipedia" , $connection ) ; |
| 64 | + $sql = "SELECT * FROM user WHERE user_name=\"$un\" AND user_password=\"$up\"" ; |
| 65 | + $result = mysql_query ( $sql , $connection ) ; |
| 66 | + if ( $s = mysql_fetch_object ( $result ) ) { |
| 67 | + setcookie ( "USERID" , "$s->user_id" ) ; |
| 68 | + $ret = true ; |
| 69 | + } |
| 70 | + else $ret = false ; |
| 71 | + mysql_free_result ( $result ) ; |
| 72 | + mysql_close ( $connection ) ; |
| 73 | + return $ret ; |
| 74 | + } |
| 75 | + |
| 76 | +function addNewUser ( $un , $up , $ur ) { |
| 77 | + if ( doesUserExist ( $un ) ) return ; |
| 78 | + $connection=getDBconnection() ; |
| 79 | + mysql_select_db ( "nikipedia" , $connection ) ; |
| 80 | + $sql = "INSERT INTO user (user_name, user_password, user_rights) VALUES (\"$un\", \"$up\", \"$ur\")" ; |
| 81 | + $result = mysql_query ( $sql , $connection ) ; |
| 82 | + |
| 83 | + $sql = "SELECT * FROM user WHERE user_name=\"$un\"" ; |
| 84 | + $result = mysql_query ( $sql , $connection ) ; |
| 85 | + $s = mysql_fetch_object ( $result ) ; |
| 86 | + setcookie ( "USERNAME" , "$s->user_name" ) ; |
| 87 | + setcookie ( "USERPASSWORD" , "$s->user_password" ) ; |
| 88 | + setcookie ( "USERID" , "$s->user_id" ) ; |
| 89 | + setcookie ( "USERLOGGEDIN" , "YES" ) ; |
| 90 | + mysql_free_result ( $result ) ; |
| 91 | + |
| 92 | + mysql_close ( $connection ) ; |
| 93 | + } |
| 94 | + |
| 95 | +####################################################################### ARTICLE DATABASE INTERFACE |
| 96 | + |
| 97 | +function acquireTopic ( $s ) { |
| 98 | + global $title ; |
| 99 | + $s=getSecureTitle($s); |
| 100 | + $s=strtolower($s); |
| 101 | + $connection=getDBconnection() ; |
| 102 | + mysql_select_db ( "nikipedia" , $connection ) ; |
| 103 | + $sql = "select * from cur where cur_title='$s'" ; |
| 104 | + $result = mysql_query ( $sql , $connection ) ; |
| 105 | + if ( $s = mysql_fetch_object ( $result ) ) { |
| 106 | + $title=$s->cur_title ; |
| 107 | + $s = $s->cur_text ; |
| 108 | + } |
| 109 | + else { |
| 110 | + $s = "" ; |
| 111 | + } |
| 112 | + mysql_free_result ( $result ) ; |
| 113 | + mysql_close ( $connection ) ; |
| 114 | + return $s ; |
| 115 | + } |
| 116 | + |
| 117 | +function acquireOldTopic ( $s , $id ) { |
| 118 | + global $title ; |
| 119 | + $s=getSecureTitle($s); |
| 120 | + $s=strtolower($s); |
| 121 | + $connection=getDBconnection() ; |
| 122 | + mysql_select_db ( "nikipedia" , $connection ) ; |
| 123 | + $sql = "select * from old where old_title='$title' and old_id=$id" ; |
| 124 | + $result = mysql_query ( $sql , $connection ) ; |
| 125 | + if ( $s = mysql_fetch_object ( $result ) ) { |
| 126 | + $title=$s->old_title ; |
| 127 | + $s = $s->old_text ; |
| 128 | + } |
| 129 | + else { |
| 130 | + $s = "nothing available" ; |
| 131 | + } |
| 132 | + mysql_free_result ( $result ) ; |
| 133 | + mysql_close ( $connection ) ; |
| 134 | + return $s ; |
| 135 | + } |
| 136 | + |
| 137 | +function saveTopic ( $txt , $com , $min ) { |
| 138 | + global $title ; |
| 139 | + global $USERLOGGEDIN , $USERID ; |
| 140 | + $s=getSecureTitle($title); |
| 141 | + $s=strtolower($s); |
| 142 | + $connection=getDBconnection() ; |
| 143 | + mysql_select_db ( "nikipedia" , $connection ) ; |
| 144 | + $txt = str_replace ( "\r" , "" , $txt ) ; |
| 145 | + |
| 146 | + $sql = "update cur set cur_text='$txt' where cur_title='$title'" ; |
| 147 | + $result = mysql_query ( $sql , $connection ) ; |
| 148 | + |
| 149 | + $sql = "update cur set cur_comment='$com' where cur_title='$title'" ; |
| 150 | + $result = mysql_query ( $sql , $connection ) ; |
| 151 | + |
| 152 | + $sql = "update cur set cur_minor_edit=1 where cur_title='$title'" ; |
| 153 | + if ( $min == "on" ) $result = mysql_query ( $sql , $connection ) ; |
| 154 | + |
| 155 | + $id = $USERID ; |
| 156 | + if ( $id == "" or $USERLOGGEDIN != "YES" ) $id = "0" ; |
| 157 | + $sql = "update cur set cur_user='$id' where cur_title='$title'" ; |
| 158 | + $result = mysql_query ( $sql , $connection ) ; |
| 159 | + |
| 160 | + $un = getCurrentUserName () ; |
| 161 | + $sql = "update cur set cur_user_text='$un' where cur_title='$title'" ; |
| 162 | + $result = mysql_query ( $sql , $connection ) ; |
| 163 | + |
| 164 | + mysql_close ( $connection ) ; |
| 165 | + } |
| 166 | + |
| 167 | +function addPlainTopic ( $t ) { |
| 168 | + global $title ; |
| 169 | + $s=getSecureTitle($title); |
| 170 | + $s=strtolower($s); |
| 171 | + $connection=getDBconnection() ; |
| 172 | + mysql_select_db ( "nikipedia" , $connection ) ; |
| 173 | + |
| 174 | + $sql = "insert into cur ( cur_title, cur_text ) VALUES ( '$t' , '' )" ; |
| 175 | + $result = mysql_query ( $sql , $connection ) ; |
| 176 | + |
| 177 | + mysql_close ( $connection ) ; |
| 178 | + } |
| 179 | + |
| 180 | +function backupTopic ( $t ) { |
| 181 | + global $title ; |
| 182 | + $s=getSecureTitle($title); |
| 183 | + $s=strtolower($s); |
| 184 | + $connection=getDBconnection() ; |
| 185 | + mysql_select_db ( "nikipedia" , $connection ) ; |
| 186 | + |
| 187 | + # Reading current version |
| 188 | + $sql = "select * from cur where cur_title='$t'" ; |
| 189 | + $result = mysql_query ( $sql , $connection ) ; |
| 190 | + $s = mysql_fetch_object ( $result ) ; |
| 191 | + |
| 192 | + $o_title = $s->cur_title ; |
| 193 | + $o_text = $s->cur_text ; |
| 194 | + $o_comment = $s->cur_comment ; |
| 195 | + $o_user = $s->cur_user ; |
| 196 | + $o_user_text = $s->cur_user_text ; |
| 197 | + $o_old_version = $s->cur_old_version ; |
| 198 | + $o_timestamp = $s->cur_timestamp ; |
| 199 | + $o_minor_edit = $s->cur_minor_edit ; |
| 200 | + |
| 201 | + $o_text = str_replace ( '"' , '\"' , $o_text ) ; |
| 202 | + |
| 203 | + mysql_free_result ( $result ) ; |
| 204 | + |
| 205 | + # Adding data to "old" table |
| 206 | + $sql = "insert into old ( old_title, old_text , old_comment , old_user, old_user_text , old_old_version , old_timestamp , old_minor_edit ) VALUES ( \"$o_title\" , \"$o_text\" , \"$o_comment\" , \"$o_user\" , \"$o_user_text\" , \"$o_old_version\" , \"$o_timestamp\" , \"$o_minor_edit\" )" ; |
| 207 | + $result = mysql_query ( $sql , $connection ) ; |
| 208 | + |
| 209 | + # Get old id |
| 210 | + $sql = "select * from old where old_title='$o_title' and old_old_version='$o_old_version'" ; |
| 211 | + $result = mysql_query ( $sql , $connection ) ; |
| 212 | + $s = mysql_fetch_object ( $result ) ; |
| 213 | + $n_old_version = $s->old_id ; |
| 214 | + mysql_free_result ( $result ) ; |
| 215 | + |
| 216 | + # Update current version |
| 217 | + $sql = "update cur set cur_old_version='$n_old_version' where cur_title='$title'" ; |
| 218 | + $result = mysql_query ( $sql , $connection ) ; |
| 219 | + |
| 220 | + mysql_close ( $connection ) ; |
| 221 | + } |
| 222 | + |
| 223 | +function doesTopicExist ( $s ) { |
| 224 | + $s=getSecureTitle($s); |
| 225 | + $s=strtolower($s); |
| 226 | + $connection=getDBconnection() ; |
| 227 | + mysql_select_db ( "nikipedia" , $connection ) ; |
| 228 | + $sql = "select * from cur where cur_title=\"$s\"" ; |
| 229 | + $result = mysql_query ( $sql , $connection ) ; |
| 230 | + if ( $s = mysql_fetch_object ( $result ) ) $ret = true ; |
| 231 | + else $ret = false ; |
| 232 | + mysql_free_result ( $result ) ; |
| 233 | + mysql_close ( $connection ) ; |
| 234 | + return $s ; |
| 235 | + } |
| 236 | + |
| 237 | +function getTopicSetting ( $tt , $s ) { |
| 238 | + $tt = getSecureTitle ( $tt ) ; |
| 239 | + $connection=getDBconnection() ; |
| 240 | + mysql_select_db ( "nikipedia" , $connection ) ; |
| 241 | + $sql = "SELECT * FROM cur WHERE cur_title=\"$tt\"" ; |
| 242 | + $result = mysql_query ( $sql , $connection ) ; |
| 243 | + if ( $t = mysql_fetch_object ( $result ) ) $ret = $t->$s ; |
| 244 | + else $ret = "NOSUCHTHING" ; # This topic or property doesn't exist |
| 245 | + mysql_free_result ( $result ) ; |
| 246 | + mysql_close ( $connection ) ; |
| 247 | + return $ret ; |
| 248 | + } |
| 249 | + |
| 250 | +function changeTopicSetting ( $tt , $s , $v ) { |
| 251 | + $secureTitle = getSecureTItle ( $tt ) ; |
| 252 | + $connection=getDBconnection() ; |
| 253 | + mysql_select_db ( "nikipedia" , $connection ) ; |
| 254 | + $sql = "UPDATE cur SET $s = \"$v\" WHERE cur_title = \"$secureTitle\"" ; |
| 255 | + $result = mysql_query ( $sql , $connection ) ; |
| 256 | + mysql_close ( $connection ) ; |
| 257 | + } |
| 258 | + |
| 259 | + |
| 260 | +####################################################################### PARSER FUNCTIONS |
| 261 | + |
| 262 | +function replaceAllEntries ( $s , $f1 , $f2 , $r1 , $r2 ) { |
| 263 | + while ( eregi($f1,$s) && eregi($f2,$s) ) { |
| 264 | + $pieces1=spliti($f1,$s,2); |
| 265 | + $pieces2=spliti($f2,$pieces1[1],2); |
| 266 | + $middle=$pieces2[0] ; |
| 267 | + $s=$pieces1[0].$r1.$middle.$r2.$pieces2[1]; |
| 268 | + } |
| 269 | + return $s ; |
| 270 | + } |
| 271 | + |
| 272 | +# DISPLAY PARSER ; INCOMPLETE!!!! |
| 273 | +function parseContent ( $s ) { |
| 274 | + global $title ; |
| 275 | + $s = str_replace ( "\r" , "" , $s ) ; |
| 276 | + if ( !strpos ( $title , "/" ) and !strpos ( $s , "/Talk" ) ) $s .= "\n----\n[[/Talk]]" ; |
| 277 | + |
| 278 | + # Replace {{{variable}}} |
| 279 | + $var=date("m"); $s = str_replace ( "{{{CURRENTMONTH}}}" , $var , $s ) ; |
| 280 | + $var=date("F"); $s = str_replace ( "{{{CURRENTMONTHNAME}}}" , $var , $s ) ; |
| 281 | + $var=date("d"); $s = str_replace ( "{{{CURRENTDAY}}}" , $var , $s ) ; |
| 282 | + $var=date("l"); $s = str_replace ( "{{{CURRENTDAYNAME}}}" , $var , $s ) ; |
| 283 | + $var=date("Y"); $s = str_replace ( "{{{CURRENTYEAR}}}" , $var , $s ) ; |
| 284 | + |
| 285 | + # Replace [[ and ]] with internal links |
| 286 | + $tag1="\[\["; |
| 287 | + $tag2="\]\]"; |
| 288 | + while ( eregi($tag1,$s) && eregi($tag2,$s) ) { |
| 289 | + $pieces1=spliti($tag1,$s,2); |
| 290 | + $pieces2=spliti($tag2,$pieces1[1],2); |
| 291 | + $middle=$pieces2[0] ; |
| 292 | + $original = $middle ; |
| 293 | + $linkto=getSecureTitle($middle); |
| 294 | + |
| 295 | + if ( strstr ( $middle , "|" ) ) { # show left part, link to right part |
| 296 | + $pos = strpos ( $middle , "|" ) ; |
| 297 | + $linkto = trim ( substr ( $middle , 0 , $pos ) ) ; |
| 298 | + $middle = trim ( substr ( $middle , $pos+1 , 9999 ) ) ; |
| 299 | + } |
| 300 | + |
| 301 | + if ( substr($linkto,0,1)=="/" ) $linkto = $title.$linkto ; |
| 302 | + |
| 303 | + if ( substr_count ( $linkto , "/" ) < 2 ) { |
| 304 | + if ( doesTopicExist($linkto) ) $middle="<a href=\"/niki.phtml?title=$linkto&action=view\">$middle</a>" ; |
| 305 | + else { |
| 306 | + if ( strstr($middle," ") ) $middle="[$middle]" ; |
| 307 | + $middle="$middle<a href=\"/niki.phtml?title=$linkto&action=edit\">?</a>" ; |
| 308 | + } |
| 309 | + } else $middle = "$original" ; |
| 310 | + $s=$pieces1[0].$middle.$pieces2[1]; |
| 311 | + } |
| 312 | + |
| 313 | + |
| 314 | + # Replace ''' |
| 315 | + $s = replaceAllEntries ( $s , "\'\'\'" , "\'\'\'" , "<b>" , "</b>" ) ; |
| 316 | + |
| 317 | + # Replace '' |
| 318 | + $s = replaceAllEntries ( $s , "\'\'" , "\'\'" , "<i>" , "</i>" ) ; |
| 319 | + |
| 320 | + # Replace * |
| 321 | + $s = replaceAllEntries ( $s , "\n\*" , "\n" , "<ul><li>" , "</li></ul>\n" ) ; |
| 322 | + $s = replaceAllEntries ( $s , "<ul><li>\*" , "</li></ul>" , "<ul><li><ul><li>" , "</li></ul></li></ul>\n" ) ; |
| 323 | + $s = str_replace ( "</ul>\n" , "</ul>" , $s ) ; |
| 324 | + while ( strstr ( $s , "</li></ul><ul><li>" ) or strstr ( $s , "</li><li><ul>" ) ) { |
| 325 | + $s = str_replace ( "</li></ul><ul><li>" , "</li><li>" , $s ) ; |
| 326 | + $s = str_replace ( "</li><li><ul>" , "<ul>" , $s ) ; |
| 327 | + } |
| 328 | + |
| 329 | + |
| 330 | + # Replace # |
| 331 | + $s = replaceAllEntries ( $s , "\n\#" , "\n" , "<ol><li>" , "</li></ol>\n" ) ; |
| 332 | + $s = replaceAllEntries ( $s , "<ol><li>\#" , "</li></ol>" , "<ol><li><ol><li>" , "</li></ol></li></ol>\n" ) ; |
| 333 | + $s = str_replace ( "</ol>\n" , "</ol>" , $s ) ; |
| 334 | + while ( strstr ( $s , "</li></ol><ol><li>" ) or strstr ( $s , "</li><li><ol>" ) ) { |
| 335 | + $s = str_replace ( "</li></ol><ol><li>" , "</li><li>" , $s ) ; |
| 336 | + $s = str_replace ( "</li><li><ol>" , "<ol>" , $s ) ; |
| 337 | + } |
| 338 | + |
| 339 | + # Courier |
| 340 | + $s = replaceAllEntries ( $s , "\n " , "\n" , "\n <font face=\"courier\">" , "</font>\n" ) ; |
| 341 | + |
| 342 | + |
| 343 | + # Line by line |
| 344 | + $arr = explode ( "\n" , $s ) ; |
| 345 | + $narr = array () ; |
| 346 | + |
| 347 | + $dp = false ; |
| 348 | + foreach ( $arr as $x ) { |
| 349 | + $y = $x ; |
| 350 | + if ( substr ( $y , 0 , 4 ) == "http" ) $y = "<a href=\"$y\">$y</a>" ; |
| 351 | + if ( substr ( $y , 0 , 1 ) == ":" ) { |
| 352 | + $y = "<dt><dd>".substr ( $y , 1 , 99999 ) ; |
| 353 | + if ( !$dp ) $y = "<DL>".$y ; |
| 354 | + $dp = true ; |
| 355 | + } else if ( $dp ) { |
| 356 | + $y .= "</DL>" ; |
| 357 | + $dp = false ; |
| 358 | + } |
| 359 | + if ( substr ( $y , 0 , 4 ) == "----" ) $y = "<hr>" ; |
| 360 | + if ( substr ( $y , 0 , 4 ) == "<hr>" ) $footnote = 1 ; |
| 361 | + |
| 362 | + # Outside links |
| 363 | + $footnote = 1 ; |
| 364 | + $tag1="\[http://"; |
| 365 | + $tag2="\]"; |
| 366 | + while ( eregi($tag1,$y) && eregi($tag2,$y) ) { |
| 367 | + $pieces1=spliti($tag1,$y,2); |
| 368 | + $pieces2=spliti($tag2,$pieces1[1],2); |
| 369 | + $linkto=trim($pieces2[0]) ; |
| 370 | + |
| 371 | + if ( strpos ( $linkto , " " ) ) { |
| 372 | + $middle = substr ( $linkto , strpos ( $linkto , " " ) + 1 , 99999 ) ; |
| 373 | + $linkto = substr ( $linkto , 0 , strpos ( $linkto , " " ) ) ; |
| 374 | + } else { |
| 375 | + $middle = $footnote ; |
| 376 | + $footnote++ ; |
| 377 | + } |
| 378 | + |
| 379 | + $y=$pieces1[0]."<a href=\"http://$linkto\">[$middle]</a>".$pieces2[1]; |
| 380 | + } |
| 381 | + |
| 382 | + |
| 383 | + if ( $y == "" ) $y = "</p><p>" ; |
| 384 | + array_push ( $narr , $y ) ; |
| 385 | + } |
| 386 | + |
| 387 | + $s = implode ( "\n" , $narr ) ; |
| 388 | + |
| 389 | + # Final |
| 390 | + $s = "<p>$s</p>" ; |
| 391 | + $s = "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">".$s ; |
| 392 | + |
| 393 | + return $s ; |
| 394 | + } |
| 395 | + |
| 396 | +function getCurrentUserText () { |
| 397 | + global $USERNAME , $USERPASSWORD , $USERLOGGEDIN ; |
| 398 | + global $REMOTE_ADDR ; |
| 399 | +# if ( $USERLOGGEDIN != "YES" and $USERNAME != "" and $USERPASSWORD != "" ) { |
| 400 | +# if ( checkUserPassword ( $USERNAME , $USERPASSWORD ) ) setcookie ( "USERLOGGEDIN" , "YES" ) ; |
| 401 | +# $USERLOGGEDIN = "YES" ; |
| 402 | +# } |
| 403 | + if ( $USERLOGGEDIN != "YES" or $USERNAME == "" ) { |
| 404 | + $u = "$REMOTE_ADDR<br>\n<a href=\"/niki.phtml?action=login\">log in</a>" ; |
| 405 | + } |
| 406 | + else { |
| 407 | + $u = "$USERNAME<br>\n<a href=\"/niki.phtml?action=logout\">log out</a>" ; |
| 408 | + $u .= " <a href=\"/niki.phtml?action=prefs\">Preferences</a>" ; |
| 409 | + } |
| 410 | + return $u ; |
| 411 | + } |
| 412 | + |
| 413 | +########### RIGHTS MANAGEMENT |
| 414 | + |
| 415 | +function canEdit( $tt ) { |
| 416 | + global $USERNAME , $USERLOGGEDIN , $action ; |
| 417 | + $restrictions = getTopicSetting ( $tt , "cur_restrictions" ) ; |
| 418 | + if ( $restrictions == "" ) return true ; # No restrictions, OK to edit for everyone |
| 419 | + if ( $restrictions == "NOSUCHTHING" ) { |
| 420 | + $stt = strtolower ( $tt ) ; |
| 421 | + if ( $stt == "recentchanges" ) return false ; |
| 422 | + if ( $action == "revisions" ) return false ; |
| 423 | + if ( $action == "statistics" ) return false ; |
| 424 | + if ( $action == "restrictions" ) return false ; |
| 425 | + if ( $action == "prefs" ) return false ; |
| 426 | + return true ; # New topic |
| 427 | + } |
| 428 | + if ( $USERLOGGEDIN != "YES" ) return false ; # Restrictions, but not logged in -> No edit, bad dog! |
| 429 | + $resArr = explode ( "," , $restrictions ) ; |
| 430 | + $rights = ",".getUserSetting ( $USERNAME , "user_rights" )."," ; |
| 431 | + |
| 432 | + $allowed = false ; |
| 433 | + foreach ( $resArr as $x ) { |
| 434 | + $y = ",is_$x," ; |
| 435 | + if ( strstr ( $rights , $y ) ) $allowed = true ; |
| 436 | + } |
| 437 | + return $allowed ; |
| 438 | + } |
| 439 | + |
| 440 | +function canRestrict ( $tt ) { |
| 441 | + global $USERNAME , $USERLOGGEDIN , $dosearch ; |
| 442 | + if ( $USERLOGGEDIN != "YES" ) return false ; # Not logged in |
| 443 | + if ( $dosearch == 1 ) return false ; # Search page |
| 444 | + if ( !doesTopicExist ( $tt ) ) return false ; # No such topic |
| 445 | + $rights = ",".getUserSetting ( $USERNAME , "user_rights" )."," ; |
| 446 | + $allowed = false ; |
| 447 | + if ( strstr ( $rights , ",is_editor," ) ) $allowed = true ; |
| 448 | + if ( strstr ( $rights , ",is_sysop," ) ) $allowed = true ; |
| 449 | + return $allowed ; |
| 450 | + } |
| 451 | + |
| 452 | + |
| 453 | +####################################### |
| 454 | +# OUTPUT PROCEDURES |
| 455 | +####################################### |
| 456 | + |
| 457 | +function getHeaderFooterParts () { |
| 458 | + global $title , $action , $oid ; |
| 459 | + global $USERNAME ; |
| 460 | + |
| 461 | + $secureTitle = getSecureTitle ( $title ) ; |
| 462 | + $ret = "" ; |
| 463 | + |
| 464 | + $special = false ; |
| 465 | + if ( $title == "recentchanges" ) $special = true ; |
| 466 | + if ( $action == "revisions" or $action == "statistics" or $action == "restrictions" ) $special = true ; |
| 467 | + if ( $action == "prefs" or $action == "edituserrights" ) $special = true ; |
| 468 | + |
| 469 | + $ret .= "<a href=\"/niki.phtml?title=MainPage&action=view\">Main page</a> | " ; |
| 470 | + $ret .= "<a href=\"/niki.phtml?title=recentchanges&action=view\">Recent changes</a>" ; |
| 471 | + if ( !$special ) $ret .= " | <a href=\"/niki.phtml?title=$secureTitle&action=revisions\">Other versions</a>" ; |
| 472 | + if ( !$special and strstr ( $title , "/" ) ) { |
| 473 | + $parent = substr($title , 0 , strrpos($title,"/")) ; |
| 474 | + $sparent = getSecureTitle ( $parent ) ; |
| 475 | + $ret .= " | <a href=\"/niki.phtml?title=$sparent&action=view\">$parent</a>" ; |
| 476 | + } |
| 477 | + |
| 478 | + if ( $action == "view" and !$special and canEdit($title) ) $ret .= " | <a href=\"/niki.phtml?title=$secureTitle&action=edit\">Edit this page</a>" ; |
| 479 | + if ( $action == "view_old_article" ) $ret .= " | <a href=\"/niki.phtml?title=$secureTitle&action=view_old_source&oid=$oid\">View this source</a>" ; |
| 480 | + if ( $action == "view_old_source" ) $ret .= " | <a href=\"/niki.phtml?title=$secureTitle&action=view_old_article&oid=$oid\">View this article</a>" ; |
| 481 | + $ret .= " | <a href=\"./niki_upload.phtml\" target=\"_blank\">Upload files</a>" ; |
| 482 | + if ( $action != "statistics" ) $ret .= " | <a href=\"/niki.phtml?action=statistics\">Statistics</a>" ; |
| 483 | + |
| 484 | + if ( !$special and canRestrict($title) ) $ret .= " | <a href=\"/niki.phtml?title=$secureTitle&action=restrictions\">Change restrictions</a>" ; |
| 485 | + |
| 486 | + return $ret ; |
| 487 | + } |
| 488 | + |
| 489 | +function getStandardHeader () { |
| 490 | + global $title , $action , $oid ; |
| 491 | + global $USERNAME ; |
| 492 | + |
| 493 | + $special = false ; |
| 494 | + if ( $title == "recentchanges" ) $special = true ; |
| 495 | + if ( $action == "revisions" or $action == "statistics" or $action == "restrictions" ) $special = true ; |
| 496 | + if ( $action == "prefs" or $action == "edituserrights" ) $special = true ; |
| 497 | + |
| 498 | + $secureTitle = getSecureTitle ( $title ) ; |
| 499 | + $hversion = "" ; |
| 500 | + if ( $action == "view_old_article" or $action == "view_old_source" ) $hversion = " (Older version)" ; |
| 501 | + |
| 502 | + $userName = getCurrentUserText () ; |
| 503 | + |
| 504 | + $hpre = "<table width=\"100%\"><tr><td><font size=\"+3\">" ; |
| 505 | + $hpost = "</font></td><td align=right><font color=red>User : $userName</font></td></tr></table>" ; |
| 506 | + |
| 507 | + if ( $action == "view" or $action == "view_old_article" or $action == "view_old_source" or $special ) { |
| 508 | + if ( $title == "recentchanges" ) $thebody = "Recent Changes" ; |
| 509 | + else if ( $action == "revisions" ) $thebody = "History of $title" ; |
| 510 | + else if ( $action == "statistics" ) $thebody = "Statistics (".date("l, F d, Y H:i:s").", PST)" ; |
| 511 | + else if ( $action == "edituserrights" ) $thebody = "Edit user access rights here" ; |
| 512 | + else if ( $action == "restrictions" ) $thebody = "Restrictions of $title" ; |
| 513 | + else if ( $action == "prefs" ) $thebody = "Preferences for $USERNAME" ; |
| 514 | + else $thebody = "<a href=\"/niki.phtml?$action=search&search=$secureTitle&dosearch=1\">$title</a>$hversion" ; |
| 515 | + $head = $hpre.$thebody.$hpost ; |
| 516 | + } else if ( $action == "edit" or $action == "preview" ) { |
| 517 | + $head = $hpre."Editing $title".$hpost ; |
| 518 | + } |
| 519 | + |
| 520 | + $head .= getHeaderFooterParts() ; |
| 521 | + $head .= "<hr>" ; |
| 522 | + return $head ; |
| 523 | + } |
| 524 | + |
| 525 | +function getStandardFooter () { |
| 526 | + $ret = "<FORM><hr>" ; |
| 527 | + $ret .= getHeaderFooterParts () ; |
| 528 | + $ret .= "<br>Search: <INPUT TYPE=text NAME=search SIZE=20><INPUT TYPE=hidden NAME=dosearch VALUE=1></FORM>" ; |
| 529 | + return $ret ; |
| 530 | + } |
| 531 | + |
| 532 | +######## APPLY RESTRICTIONS TO AN ARTICLE |
| 533 | +function restrictions () { |
| 534 | + global $title , $therestrictions ; |
| 535 | + $secureTitle = getSecureTitle ( $title ) ; |
| 536 | + if ( !canRestrict ( $title ) ) return "You are not allowed to restrict this article. Follow <a href=\"/niki.phtml?title=$secureTitle\">this link</a> to go back." ; |
| 537 | + |
| 538 | + if ( isset ( $therestrictions ) ) { |
| 539 | + changeTopicSetting ( $title , "cur_restrictions" , $therestrictions ) ; |
| 540 | + $ret="<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=/niki.phtml?title=$title&action=view\">" ; |
| 541 | + unset ( $therestrictions ) ; |
| 542 | + } else { |
| 543 | + $ret = "" ; |
| 544 | + $ret .= getStandardHeader () ; |
| 545 | + $r = getTopicSetting ( $title , "cur_restrictions" ) ; |
| 546 | + $ret .= "<FORM action=\"/niki.phtml?title=$title&action=restrictions\" method=post>\n" ; |
| 547 | + $ret .= "Restrictions : <INPUT TABINDEX=1 TYPE=text NAME=therestrictions VALUE=\"$r\" SIZE=80><br>\n" ; |
| 548 | + $ret .= "<INPUT TYPE=SUBMIT NAME=changeprefs value=\"Save new restrictions\">\n" ; |
| 549 | + $ret .= "</FORM>\n" ; |
| 550 | + } |
| 551 | + |
| 552 | + return $ret ; |
| 553 | + } |
| 554 | + |
| 555 | +############################################ |
| 556 | +# BASIC FUNCTIONS |
| 557 | +############################################ |
| 558 | + |
| 559 | +function view () { |
| 560 | + global $title , $action ; |
| 561 | + |
| 562 | + $content = acquireTopic ( $title ) ; |
| 563 | + $content = parseContent ( $content ) ; |
| 564 | + |
| 565 | + $secureTitle = getSecureTitle ( $title ) ; |
| 566 | + $head = getStandardHeader () ; |
| 567 | + $content = $head.$content."\n" ; |
| 568 | + $content .= getStandardFooter () ; |
| 569 | + return $content ; |
| 570 | + } |
| 571 | + |
| 572 | +function view_old_article ( $mode="parsed" ) { |
| 573 | + global $title , $action , $oid ; |
| 574 | + if ( $oid == "" ) return "NO OID GIVEN" ; |
| 575 | + |
| 576 | + $content = acquireOldTopic ( $title , $oid ) ; |
| 577 | + if ( $mode == "parsed" ) |
| 578 | + $content = parseContent ( $content ) ; |
| 579 | + else if ( $mode == "source" ) |
| 580 | + $content = "<textarea name=newtext rows=20 cols=65 STYLE=\"width:100%\" wrap=virtual>$content</textarea>" ; |
| 581 | + |
| 582 | + $secureTitle = getSecureTitle ( $title ) ; |
| 583 | + $head = getStandardHeader () ; |
| 584 | + |
| 585 | + $content = $head.$content ; |
| 586 | + $content .= "\n<hr>\n" ; |
| 587 | + |
| 588 | + return $content ; |
| 589 | + } |
| 590 | + |
| 591 | +function edit () { |
| 592 | + global $title , $action ; |
| 593 | + global $newtext , $comment , $recent_edit ; |
| 594 | + |
| 595 | + if ( ! $comment ) $comment = "*" ; |
| 596 | + if ( $recent_edit ) $recent_edit = "on" ; |
| 597 | + else $recent_edit = "off" ; |
| 598 | + |
| 599 | + $realTitle=$title ; |
| 600 | + $secureTitle = getSecureTitle ( $title ) ; |
| 601 | + |
| 602 | + # Checking clearance |
| 603 | + if ( !canEdit($title) ) return "You are not allowed to edit this article. Follow <a href=\"/niki.phtml?title=$secureTitle\">this link</a> to go back." ; |
| 604 | + |
| 605 | + if ( $newtext ) { |
| 606 | + $content = $newtext ; |
| 607 | + $content = str_replace ( "\\\"" , "\"" , $content ) ; |
| 608 | + $content = str_replace ( "\\'" , "'" , $content ) ; |
| 609 | + } |
| 610 | + else $content = acquireTopic ( $title ) ; |
| 611 | + |
| 612 | + $content = str_replace ( "\r" , "" , $content ) ; |
| 613 | + |
| 614 | + $source = $content ; |
| 615 | + |
| 616 | + $head = getStandardHeader () ; |
| 617 | + $head .= "<form action=\"/niki.phtml?title=$title&action=edited\" method=post>\n"; |
| 618 | + |
| 619 | + if ( $content == "" ) $content = "Describe the new page here.\n" ; |
| 620 | + |
| 621 | + $content = "<textarea name=newtext rows=20 cols=65 STYLE=\"width:100%\" wrap=virtual>$content</textarea><br>\n" ; |
| 622 | + |
| 623 | + $content .= "Summary:<INPUT TYPE=text NAME=comment VALUE=\"$comment\" SIZE=60 MAXLENGTH=200><br>\n" ; |
| 624 | + $content .= "<INPUT TYPE=checkbox NAME=\"minor_edit\" VALUE=\"on\">This change is a minor edit.<br>\n" ; |
| 625 | + $content .= "<input type=submit name=save value=\"Save changes\">\n" ; |
| 626 | + $content .= "<input type=submit name=preview value=\"Preview changes\">\n" ; |
| 627 | + |
| 628 | + $content .= "</form>\n" ; |
| 629 | + |
| 630 | + if ( $action=="preview" ) { |
| 631 | + $source = parseContent ( $source ) ; |
| 632 | + $content .= "<hr>\n" ; |
| 633 | + $content .= "<font size=\"+3\">PREVIEW</font><br><br>\n" ; |
| 634 | + $content .= $source ; |
| 635 | + $content .= "\n<hr><b>Remember, this is just a preview!</b>\n" ; |
| 636 | + } |
| 637 | + |
| 638 | + unset ( $recent_edit ) ; |
| 639 | + unset ( $comment ) ; |
| 640 | + unset ( $newtext ) ; |
| 641 | + |
| 642 | + $content = $head.$content ; |
| 643 | + return $content ; |
| 644 | + } |
| 645 | + |
| 646 | +function edited () { |
| 647 | + global $action , $preview , $title , $save ; |
| 648 | + global $newtext , $comment , $minor_edit ; |
| 649 | + |
| 650 | + $secureTitle = getSecureTitle ( $title ) ; |
| 651 | + # Checking clearance |
| 652 | + if ( !canEdit($title) ) return "You are not allowed to edit this article. Follow <a href=\"/niki.phtml?title=$secureTitle\">this link</a> to go back." ; |
| 653 | + |
| 654 | + if ( doesTopicExist ( $title ) ) { |
| 655 | + # Backup old version |
| 656 | + backupTopic ( $title ) ; |
| 657 | + } else { |
| 658 | + # New topic |
| 659 | + addPlainTopic ( $title ) ; |
| 660 | + } |
| 661 | + |
| 662 | + saveTopic ( $newtext , $comment , $minor_edit ) ; |
| 663 | + |
| 664 | + unset ( $preview ) ; |
| 665 | + unset ( $newtext ) ; |
| 666 | + unset ( $save ) ; |
| 667 | + |
| 668 | + $action="view" ; |
| 669 | + $ret="<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=/niki.phtml?title=$title&action=view\">" ; |
| 670 | + return $ret ; |
| 671 | + } |
| 672 | + |
| 673 | +function MySQLtimestamp ( $edit_time ) { |
| 674 | + $qh = substr ( $edit_time , 8 , 2 ) ; |
| 675 | + $qm = substr ( $edit_time , 10 , 2 ) ; |
| 676 | + $qs = substr ( $edit_time , 12 , 2 ) ; |
| 677 | + $qo = substr ( $edit_time , 4 , 2 ) ; |
| 678 | + $qd = substr ( $edit_time , 6 , 2 ) ; |
| 679 | + $qy = substr ( $edit_time , 0 , 4 ) ; |
| 680 | + $edit_time = date ( "F d, Y, H:i:s" , mktime ( $qh , $qm , $qs , $qo , $qd , $qy ) ) ; |
| 681 | + if ( $edit_time == "" ) $edit_time = "<unknown>" ; |
| 682 | + return $edit_time ; |
| 683 | + } |
| 684 | + |
| 685 | +function currentMySQLtime () { |
| 686 | + return date ( "YmdHis" ) ; |
| 687 | + } |
| 688 | + |
| 689 | +############################################ |
| 690 | +# HIGHER BRAIN FUNCTIONS |
| 691 | +############################################ |
| 692 | + |
| 693 | +function showRecentChanges () { |
| 694 | + global $title ; |
| 695 | + $s=getSecureTitle($s); |
| 696 | + $s=strtolower($s); |
| 697 | + $connection=getDBconnection() ; |
| 698 | + mysql_select_db ( "nikipedia" , $connection ) ; |
| 699 | + $sql = "SELECT * FROM cur ORDER BY cur_timestamp DESC LIMIT 100" ; |
| 700 | + $result = mysql_query ( $sql , $connection ) ; |
| 701 | + |
| 702 | + $output .= getStandardHeader () ; |
| 703 | + |
| 704 | + $output .= "<table width=\"100%\" border=1>\n" ; |
| 705 | + $output .= "<tr><th width=150 nowrap>Title</th><th width=180 nowrap>Other Version</th><th width=180 nowrap>Time</th><th>User</th><th>Last comment</th></tr>"; |
| 706 | + while ( $s = mysql_fetch_object ( $result ) ) { |
| 707 | + $secureTitle=getSecureTitle($s->cur_title); |
| 708 | + $edit_time = MySQLtimestamp ( $s->cur_timestamp ) ; |
| 709 | + $comment=$s->cur_comment ; |
| 710 | + if ( $s->cur_minor_edit == 1 ) $comment = "<i>[edit]</i> ".$comment ; |
| 711 | + $cuser=$s->cur_user_text ; |
| 712 | + if ( $cuser == "" ) $cuser = "<unknown>" ; |
| 713 | + $output .= "<tr>" ; |
| 714 | + $output .= "<td width=150 nowrap><a href=\"/niki.phtml?title=$secureTitle&action=view\">$s->cur_title</a></td>"; |
| 715 | + $output .= "<td width=180 nowrap><a href=\"/niki.phtml?title=$secureTitle&action=revisions\">Other versions of this article</a>" ; |
| 716 | + $output .= "<td width=180 nowrap>$edit_time</td>" ; |
| 717 | + $output .= "<td width=120 nowrap>$cuser</td>" ; |
| 718 | + $output .= "<td>$comment</td>" ; |
| 719 | + $output .= "</tr>\n" ; |
| 720 | + } |
| 721 | + $output .= "</table>\n" ; |
| 722 | + mysql_free_result ( $result ) ; |
| 723 | + mysql_close ( $connection ) ; |
| 724 | + return $output ; |
| 725 | + } |
| 726 | + |
| 727 | +function revisions () { |
| 728 | + global $title ; |
| 729 | + if ( !doesTopicExist ( $title ) ) return "There is no topic $title." ; |
| 730 | + |
| 731 | + $ret .= getStandardHeader () ; |
| 732 | + |
| 733 | + $s=getSecureTitle($title); |
| 734 | + $s=strtolower($s); |
| 735 | + $stitle=$s ; |
| 736 | + $connection=getDBconnection() ; |
| 737 | + mysql_select_db ( "nikipedia" , $connection ) ; |
| 738 | + $sql = "select * from cur where cur_title='$stitle'" ; |
| 739 | + $result = mysql_query ( $sql , $connection ) ; |
| 740 | + |
| 741 | + $s = mysql_fetch_object ( $result ) ; |
| 742 | + $id = $s->cur_id ; |
| 743 | + $next = $s->cur_old_version ; |
| 744 | + $comment = $s->cur_comment ; |
| 745 | + $user_text = $s->cur_user_text ; |
| 746 | + $edit_time = $s->cur_timestamp ; |
| 747 | + $release = "current" ; |
| 748 | + |
| 749 | + $ret .= "<table width=\"100%\" border=1>\n" ; |
| 750 | + $ret .= "<tr><th nowrap width=60><center><b>History</b></center></th>"; |
| 751 | + $ret .= "<th nowrap width=10><b>Article</b></th>" ; |
| 752 | + $ret .= "<th nowrap width=10><b>Source</b></th>" ; |
| 753 | + $ret .= "<th nowrap width=10><b>User</b></th>" ; |
| 754 | + $ret .= "<th nowrap width=10><b>Time</b></th>" ; |
| 755 | + $ret .= "<th nowrap width=\"100%\"><b>Comment</b></th>" ; |
| 756 | + $ret .= "</tr>\n" ; |
| 757 | + do { |
| 758 | + $oid = $next ; |
| 759 | + if ( $release == "current" ) $oid = $release ; |
| 760 | + |
| 761 | + $edit_time = MySQLtimestamp ( $edit_time ) ; |
| 762 | + |
| 763 | + if ( $user_text == "" ) $user_text = "<unknown>" ; |
| 764 | + $ret .= "<tr>" ; |
| 765 | + $ret .= "<td nowrap><center>$release</center></td>" ; |
| 766 | + $ret .= "<td nowrap><a href=\"/niki.phtml?title=$title&action=view_old_article&oid=$oid\">Go to this article version</a></td>"; |
| 767 | + $ret .= "<td nowrap><a href=\"/niki.phtml?title=$title&action=view_old_source&oid=$oid\">Go to this source version</a></td>"; |
| 768 | + $ret .= "<td nowrap>$user_text</td>" ; |
| 769 | + $ret .= "<td nowrap>$edit_time</td>" ; |
| 770 | + $ret .= "<td>$comment</td>" ; |
| 771 | + $ret .= "</tr>\n" ; |
| 772 | + |
| 773 | + if ( $release != "current" ) $next = $s->old_old_version ; |
| 774 | + if ( $release == "current" ) $release = 0 ; |
| 775 | + $release = $release + 1 ; |
| 776 | + if ( $next != 0 ) { |
| 777 | + mysql_free_result ( $result ) ; |
| 778 | + $sql = "select * from old where old_id=$next" ; |
| 779 | + $result = mysql_query ( $sql , $connection ) ; |
| 780 | + $s = mysql_fetch_object ( $result ) ; |
| 781 | + $comment = $s->old_comment ; |
| 782 | + $user_text = $s->old_user_text ; |
| 783 | + $edit_time = $s->old_timestamp ; |
| 784 | + } |
| 785 | + } while ( $next != 0 ) ; |
| 786 | + $ret .= "</table>\n" ; |
| 787 | + $ret .= getStandardFooter () ; |
| 788 | + |
| 789 | + mysql_close ( $connection ) ; |
| 790 | + return $ret ; |
| 791 | + } |
| 792 | + |
| 793 | +function doSearch () { |
| 794 | + global $search ; |
| 795 | + |
| 796 | + $connection=getDBconnection() ; |
| 797 | + mysql_select_db ( "nikipedia" , $connection ) ; |
| 798 | + $sql = "SELECT * FROM cur WHERE cur_text LIKE \"%$search%\" OR cur_title LIKE \"%$search%\" ORDER BY cur_title" ; |
| 799 | + $result = mysql_query ( $sql , $connection ) ; |
| 800 | + |
| 801 | + $output="<h1>Search results</h1>\n"; |
| 802 | + $output .= getStandardHeader () ; |
| 803 | + $output .= "<br><table width=\"100%\" border=1>\n" ; |
| 804 | + $output .= "<tr><th width=150 nowrap>Title</th><th width=180 nowrap>Other Version</th><th width=180 nowrap>Time</th><th>User</th><th>Last comment</th></tr>"; |
| 805 | + while ( $s = mysql_fetch_object ( $result ) ) { |
| 806 | + $secureTitle=getSecureTitle($s->cur_title); |
| 807 | + $edit_time = MySQLtimestamp ( $s->cur_timestamp ) ; |
| 808 | + $comment=$s->cur_comment ; |
| 809 | + if ( $s->cur_minor_edit == 1 ) $comment = "<i>[edit]</i> ".$comment ; |
| 810 | + $cuser=$s->cur_user_text ; |
| 811 | + if ( $cuser == "" ) $cuser = "<unknown>" ; |
| 812 | + $output .= "<tr>" ; |
| 813 | + $output .= "<td width=150 nowrap><a href=\"/niki.phtml?title=$secureTitle&action=view\">$s->cur_title</a></td>"; |
| 814 | + $output .= "<td width=180 nowrap><a href=\"/niki.phtml?title=$secureTitle&action=revisions\">Other versions of this article</a>" ; |
| 815 | + $output .= "<td width=180 nowrap>$edit_time</td>" ; |
| 816 | + $output .= "<td width=120 nowrap>$cuser</td>" ; |
| 817 | + $output .= "<td>$comment</td>" ; |
| 818 | + $output .= "</tr>\n" ; |
| 819 | + } |
| 820 | + $output .= "</table>\n" ; |
| 821 | + mysql_free_result ( $result ) ; |
| 822 | + mysql_close ( $connection ) ; |
| 823 | + |
| 824 | + $output .= getStandardFooter () ; |
| 825 | + return $output ; |
| 826 | + } |
| 827 | + |
| 828 | +function login () { |
| 829 | + global $USERNAME , $USERPASSWORD , $USERLOGGEDIN ; |
| 830 | + $ret = "<font size=\"+3\">Log in</font><hr>\n" ; |
| 831 | + if ( $USERLOGGEDIN == "YES" ) $ret .= "$USERNAME, you are already logged in!<br>\n" ; |
| 832 | + $ret .= "<FORM action=\"/niki.phtml?action=loginattempt\" method=post><font face=courier>\n" ; |
| 833 | + $ret .= "Your current user name : <INPUT TABINDEX=1 TYPE=text NAME=user_name VALUE=\"$USERNAME\" SIZE=20><br>\n" ; |
| 834 | + |
| 835 | + $pwd = $USERPASSWORD ; |
| 836 | + if ( !doesUserExist($USERNAME) ) $pwd = "" ; |
| 837 | + |
| 838 | + $ret .= "Your current password : <INPUT TABINDEX=2 TYPE=password NAME=user_password VALUE=\"$pwd\" SIZE=20><br>\n" ; |
| 839 | + $ret .= "<INPUT TABINDEX=3 TYPE=checkbox NAME=user_remember_password>Remember my password (as a cookie).<br>\n" ; |
| 840 | + $ret .= "<input TABINDEX=4 type=submit name=dologin value=\"Log in\">\n" ; |
| 841 | + $ret .= "</font></FORM>\n" ; |
| 842 | + $ret .= "<hr>Return to the <a href=\"/niki.phtml\">Main Page</a> without logging in" ; |
| 843 | + |
| 844 | + return $ret ; |
| 845 | + } |
| 846 | + |
| 847 | +function loginattempt () { |
| 848 | + global $user_name , $user_password , $user_remember_password , $newuser ; |
| 849 | + global $USERNAME , $USERPASSWORD , $USERLOGGEDIN ; |
| 850 | + |
| 851 | + if ( $newuser == "YES" and !doesUserExist ( $user_name ) ) { |
| 852 | + addNewUser ( $user_name , $user_password , "" ) ; |
| 853 | + $ret .= "Congratulations, $user_name! You were added to the user list.<br>\n" ; |
| 854 | + $ret .= "Check your preferences <a href=\"/niki.phtml?action=prefs\">here</a>!<br>\n" ; |
| 855 | + $ret .= "Or go directly to the <a href=\"/niki.phtml\">Main Page</a>.\n" ; |
| 856 | + } else if ( checkUserPassword ( $user_name , $user_password ) ) { # Correct log-in |
| 857 | + setcookie ( "USERNAME" , $user_name ) ; |
| 858 | + if ( $user_remember_password == "on" ) setcookie ( "USERPASSWORD" , $user_password ) ; |
| 859 | + else setcookie ( "USERPASSWORD" , "" ) ; |
| 860 | + setcookie ( "USERLOGGEDIN" , "YES" ) ; |
| 861 | + $ret .= "$USERNAME, you have been successfully logged in!<br>\n" ; |
| 862 | + $ret .= "<hr>Return to the <a href=\"/niki.phtml\">Main Page</a>" ; |
| 863 | + } else { #Wrong log-in |
| 864 | + $ret .= "Sorry, your login was incorrect. You can :<br>\n" ; |
| 865 | + $ret .= "- <a href=\"/niki.phtml?action=login\">Try again</a>.<br>\n" ; |
| 866 | + $ret .= "- Go to the <a href=\"/niki.phtml\">Main Page</a> without logging in.<br>\n" ; |
| 867 | + if ( !doesUserExist ( $user_name ) ) { |
| 868 | + $ret .= "- Create a new user \"$user_name\", with the password \"$user_password\"." ; |
| 869 | + $ret .= "<FORM action=\"/niki.phtml?action=loginattempt\" method=post>\n" ; |
| 870 | + $ret .= "<input type=submit name=createnewuser value=\"Create user $user_name\">\n" ; |
| 871 | + $ret .= "<INPUT TYPE=HIDDEN NAME=user_name VALUE=\"$user_name\">\n" ; |
| 872 | + $ret .= "<INPUT TYPE=HIDDEN NAME=user_password VALUE=\"$user_password\">\n" ; |
| 873 | + $ret .= "<INPUT TYPE=HIDDEN NAME=newuser VALUE=\"YES\">\n" ; |
| 874 | + $ret .= "</FORM>\n" ; |
| 875 | + } |
| 876 | + } |
| 877 | + |
| 878 | + unset ( $newuser ) ; |
| 879 | + return $ret ; |
| 880 | + } |
| 881 | + |
| 882 | +function logout () { |
| 883 | + global $USERNAME , $USERPASSWORD , $USERLOGGEDIN , $USERID ; |
| 884 | + setcookie ( "USERLOGGEDIN" , "NO" ) ; |
| 885 | + $ret = "<font size=\"+3\">Goodbye, $USERNAME!</font><br>\n" ; |
| 886 | + $ret .= "Return to the <a href=\"/niki.phtml\">Main Page</a>" ; |
| 887 | + return $ret ; |
| 888 | + } |
| 889 | + |
| 890 | +function prefs () { |
| 891 | + global $changeprefs , $u_email , $u_password ; |
| 892 | + global $USERNAME , $USERPASSWORD , $USERLOGGEDIN , $USERID ; |
| 893 | + if ( $USERLOGGEDIN != "YES" ) return "You are not logged in. <a href=\"/niki.phtml?action=login\">Log in</a> or return to the <a href=\"/niki.phtml\">Main Page</a>" ; |
| 894 | + $ret = getStandardHeader () ; |
| 895 | + |
| 896 | + if ( $changeprefs ) { # Save new settings |
| 897 | + changeUserSetting ( $USERNAME , "user_email" , $u_email ) ; |
| 898 | + changeUserSetting ( $USERNAME , "user_password" , $u_password ) ; |
| 899 | + $ret .= "Settings are changed.<br>\n" ; |
| 900 | + } |
| 901 | + |
| 902 | + $uemail = getUserSetting ( $USERNAME , "user_email" ) ; |
| 903 | + $ur = getUserSetting ( $USERNAME , "user_rights" ) ; |
| 904 | + $ret .= "<font face=courier>\n" ; |
| 905 | + $ret .= "<FORM action=\"/niki.phtml?action=prefs\" method=post>\n" ; |
| 906 | + $ret .= "<p>Your user ID : $USERID</p>\n" ; |
| 907 | + $ret .= "<p>Your rights : $ur</p>\n" ; |
| 908 | + $ret .= "<p>Your email : <INPUT TABINDEX=1 TYPE=text NAME=u_email VALUE=\"$uemail\" SIZE=20></p>\n" ; |
| 909 | + $ret .= "<p>Your password : <INPUT TABINDEX=1 TYPE=text NAME=u_password VALUE=\"$USERPASSWORD\" SIZE=20></p>\n" ; |
| 910 | + $ret .= "<INPUT TYPE=SUBMIT NAME=changeprefs value=\"Save settings\">\n" ; |
| 911 | + $ret .= "</FORM>\n" ; |
| 912 | + $ret .= "</font>\n" ; |
| 913 | + |
| 914 | + $rights = ",".getUserSetting ( $USERNAME , "user_rights" )."," ; |
| 915 | + if ( strstr ( $rights , ",is_editor" ) or strstr ( $rights , ",is_sysop" ) ) { |
| 916 | + $ret .= "<hr><font color=red>You are allowed to <a href=\"/niki.phtml?action=editUserRights\">edit user rights</a>!</font>" ; |
| 917 | + } |
| 918 | + |
| 919 | + $ret .= getStandardFooter () ; |
| 920 | + |
| 921 | + return $ret ; |
| 922 | + } |
| 923 | + |
| 924 | +######## EDIT USER RIGHTS |
| 925 | +function editUserRights () { |
| 926 | + global $title , $editusername , $newuserrights , $USERLOGGEDIN , $USERNAME ; |
| 927 | + $secureTitle = getSecureTitle ( $title ) ; |
| 928 | + if ( !$USERLOGGEDIN ) return "You are not logged in. <a href=\"/niki.phtml?action=login\">Log in</a> or return to the <a href=\"/niki.phtml\">Main Page</a>" ; |
| 929 | + |
| 930 | + # AUTHENTIFICATION |
| 931 | + $rights = ",".getUserSetting ( $USERNAME , "user_rights" )."," ; |
| 932 | + if ( strstr ( $rights , ",is_editor," ) or strstr ( $rights , ",is_sysop" ) ) $isEditor = true ; |
| 933 | + else $isEditor = false ; |
| 934 | + if ( strstr ( $rights , ",is_sysop," ) or strstr ( $rights , ",is_sysop" ) ) $isSysop = true ; |
| 935 | + else $isSysop = false ; |
| 936 | + if ( !$isSysop and !isEditor ) return "You are neither an editor nor a sysop. Return to the <a href=\"/niki.phtml\">Main Page</a>" ; |
| 937 | + |
| 938 | + $ret = "" ; |
| 939 | + if ( isset ( $editusername ) ) { |
| 940 | + if ( isset ( $newuserrights ) ) { |
| 941 | + changeUserSetting ( $editusername , "user_rights" , $newuserrights ) ; |
| 942 | + $ret="<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=/niki.phtml?action=prefs\">" ; |
| 943 | + } else { |
| 944 | + $ret .= getStandardHeader () ; |
| 945 | + $ret .= "<font size=\"+2\">Editing rights of user $editusername</font><br>" ; |
| 946 | + $r = getUserSetting ( $editusername , "user_rights" ) ; |
| 947 | + $ret .= "<FORM action=\"/niki.phtml?action=editUserRights&editusername=$editusername\" method=post>\n" ; |
| 948 | + $ret .= "User rights : <INPUT TABINDEX=1 TYPE=text NAME=newuserrights VALUE=\"$r\" SIZE=80><br>\n" ; |
| 949 | + $ret .= "<INPUT TYPE=SUBMIT NAME=changeprefs value=\"Save new user rights\">\n" ; |
| 950 | + $ret .= "</FORM>\n" ; |
| 951 | + } |
| 952 | + unset ( $editusername ) ; |
| 953 | + unset ( $newuserrights ) ; |
| 954 | + } else { |
| 955 | + $ret .= getStandardHeader () ; |
| 956 | + $connection=getDBconnection() ; |
| 957 | + mysql_select_db ( "nikipedia" , $connection ) ; |
| 958 | + $sql = "SELECT * FROM user" ; |
| 959 | + if ( !$isSysop ) $sql .= " WHERE user_rights NOT LIKE \"is_sysop\"" ; |
| 960 | + $sql .= " ORDER BY user_name" ; |
| 961 | + $result = mysql_query ( $sql , $connection ) ; |
| 962 | + while ( $s = mysql_fetch_object ( $result ) ) { |
| 963 | + $t = $s->user_name ; |
| 964 | + $t = "<a href=\"/niki.phtml?action=editUserRights&editusername=$t\">$t</a>" ; |
| 965 | + $ret .= "Edit the rights of $t ($s->user_rights)<br>\n" ; |
| 966 | + } |
| 967 | + mysql_free_result ( $result ) ; |
| 968 | + mysql_close ( $connection ) ; |
| 969 | + $ret .= getStandardFooter () ; |
| 970 | + } |
| 971 | + |
| 972 | + return $ret ; |
| 973 | + } |
| 974 | + |
| 975 | + |
| 976 | +function statistics () { |
| 977 | + $ret = getStandardHeader () ; |
| 978 | + $connection=getDBconnection() ; |
| 979 | + mysql_select_db ( "nikipedia" , $connection ) ; |
| 980 | + $ret = getStandardHeader() ; |
| 981 | + $ret .= "<h2>Article statistics</h2><ul>" ; |
| 982 | + |
| 983 | + $nf1 = "<font color=red><b>" ; |
| 984 | + $nf2 = "</b></font>" ; |
| 985 | + |
| 986 | + # TOTAL |
| 987 | + $sql = "SELECT COUNT(*) AS number FROM cur" ; |
| 988 | + $result = mysql_query ( $sql , $connection ) ; |
| 989 | + $s = mysql_fetch_object ( $result ) ; |
| 990 | + $totalPages = $s->number ; |
| 991 | + $ret .= "<li>There are $nf1$totalPages$nf2 pages in the database</li>" ; |
| 992 | + mysql_free_result ( $result ) ; |
| 993 | + |
| 994 | + # /TALK |
| 995 | + $sql = "SELECT COUNT(*) as number FROM cur WHERE cur_title LIKE \"%/Talk\"" ; |
| 996 | + $result = mysql_query ( $sql , $connection ) ; |
| 997 | + $s = mysql_fetch_object ( $result ) ; |
| 998 | + $talkPages = $s->number ; |
| 999 | + $ret .= "<li>There are $nf1$talkPages$nf2 <b>/Talk</b> pages</li>" ; |
| 1000 | + mysql_free_result ( $result ) ; |
| 1001 | + |
| 1002 | + # , NOT /TALK |
| 1003 | + $sql = "SELECT COUNT(*) as number FROM cur WHERE cur_title NOT LIKE \"%/Talk\" AND cur_text LIKE \"%,%\"" ; |
| 1004 | + $result = mysql_query ( $sql , $connection ) ; |
| 1005 | + $s = mysql_fetch_object ( $result ) ; |
| 1006 | + $commaPages = $s->number ; |
| 1007 | + $ret .= "<li>There are $nf1$commaPages$nf2 with a comma that are <i>not</i> <b>/Talk</b> pages</li>" ; |
| 1008 | + mysql_free_result ( $result ) ; |
| 1009 | + |
| 1010 | + # WIKIPEDIA NOT /TALK |
| 1011 | + $sql = "SELECT COUNT(*) as number FROM cur WHERE cur_title NOT LIKE \"%/Talk\" AND cur_title LIKE \"%ikipedia%\"" ; |
| 1012 | + $result = mysql_query ( $sql , $connection ) ; |
| 1013 | + $s = mysql_fetch_object ( $result ) ; |
| 1014 | + $wikiPages = $s->number ; |
| 1015 | + $ret .= "<li>There are $nf1$wikiPages$nf2 that have \"ikipedia\" in the title and are <i>not</i> <b>/Talk</b> pages</li>" ; |
| 1016 | + mysql_free_result ( $result ) ; |
| 1017 | + |
| 1018 | + # WIKIPEDIA NOT /TALK |
| 1019 | + $sql = "SELECT COUNT(*) as number FROM cur WHERE cur_title LIKE \"%/%\"" ; |
| 1020 | + $result = mysql_query ( $sql , $connection ) ; |
| 1021 | + $s = mysql_fetch_object ( $result ) ; |
| 1022 | + $subPages = $s->number - $talkPages; |
| 1023 | + $ret .= "<li>There are $nf1$subPages$nf2 subpages that are <i>not</i> <b>/Talk</b> pages</li>" ; |
| 1024 | + mysql_free_result ( $result ) ; |
| 1025 | + |
| 1026 | + # RESULT |
| 1027 | + $x = $commaPages - $wikiPages ; # Comma (no /Talk) - wiki pages = articles, including subpages |
| 1028 | + $ret .= "<li>That means there are about $nf1$x$nf2 articles, including subpages (except <b>/Talk</b>).</li>" ; |
| 1029 | + $y = $x - $subPages ; |
| 1030 | + $ret .= "<li>Or, there are about $nf1$y$nf2 articles, not counting any subpages!</li>" ; |
| 1031 | + $z = $totalPages - $talkPages - $commaPages ; |
| 1032 | + $ret .= "<li>Finally, there are about $nf1$z$nf2 junk pages :-(</li>" ; |
| 1033 | + |
| 1034 | + # OLD PAGES |
| 1035 | + $sql = "SELECT COUNT(*) as number FROM old" ; |
| 1036 | + $result = mysql_query ( $sql , $connection ) ; |
| 1037 | + $s = mysql_fetch_object ( $result ) ; |
| 1038 | + $oldPages = $s->number - $talkPages; |
| 1039 | + $p = round ( $oldPages / $totalPages , 2 ) ; |
| 1040 | + $ret .= "<li>And, there are $nf1$oldPages$nf2 old page versions in the database, giving an average of $p old pages on every active page.</li>" ; |
| 1041 | + mysql_free_result ( $result ) ; |
| 1042 | + |
| 1043 | + |
| 1044 | + $ret .= "</ul><hr>" ; |
| 1045 | + $ret .= "<h2>User statistics</h2><ul>" ; |
| 1046 | + |
| 1047 | + # USERS |
| 1048 | + $sql = "SELECT COUNT(*) as number FROM user" ; |
| 1049 | + $result = mysql_query ( $sql , $connection ) ; |
| 1050 | + $s = mysql_fetch_object ( $result ) ; |
| 1051 | + $numUser = $s->number ; |
| 1052 | + $ret .= "<li>There are currently $nf1$numUser$nf2 users signed up.</li>" ; |
| 1053 | + mysql_free_result ( $result ) ; |
| 1054 | + |
| 1055 | + # EDITORS AND SYSOPS |
| 1056 | + $sql = "SELECT COUNT(*) as number FROM user WHERE user_rights LIKE \"%is_editor%\" OR user_rights LIKE \"%is_sysop%\"" ; |
| 1057 | + $result = mysql_query ( $sql , $connection ) ; |
| 1058 | + $s = mysql_fetch_object ( $result ) ; |
| 1059 | + $numEditors = $s->number ; |
| 1060 | + $ret .= "<li>$nf1$numEditors$nf2 of them have editor or sysop status.</li>" ; |
| 1061 | + mysql_free_result ( $result ) ; |
| 1062 | + |
| 1063 | + mysql_close ( $connection ) ; |
| 1064 | + $ret .= "</ul>" ; |
| 1065 | + $ret .= getStandardFooter () ; |
| 1066 | + return $ret ; |
| 1067 | + } |
| 1068 | + |
| 1069 | +############################# |
| 1070 | +# MAIN PROGRAM |
| 1071 | +############################# |
| 1072 | + |
| 1073 | + global $title , $action , $doSearch ; |
| 1074 | + if ( $title == "" ) $title="MainPage" ; |
| 1075 | + if ( $action == "" ) $action = "view" ; |
| 1076 | + $action = strtolower ( $action ) ; |
| 1077 | + |
| 1078 | + if ( $action == "edited" && $preview ) $action="preview" ; |
| 1079 | + unset ( $preview ) ; |
| 1080 | + |
| 1081 | + if ( $action == "view_old_article" and $oid == "current" ) $action = "view" ; |
| 1082 | + if ( $action == "view_old_source" and $oid == "current" ) $action = "edit" ; |
| 1083 | + if ( $dosearch == 1 ) $action = "search" ; |
| 1084 | + |
| 1085 | + $ltitle=strtolower($title); |
| 1086 | + if ( $ltitle=="recentchanges" ) $ret = showRecentChanges() ; |
| 1087 | + else if ( $dosearch == 1 ) $ret = doSearch () ; |
| 1088 | + else if ( $action == "statistics" ) $ret = statistics() ; |
| 1089 | + else if ( $action == "restrictions" ) $ret = restrictions() ; |
| 1090 | + else if ( $action == "edituserrights" ) $ret = editUserRights() ; |
| 1091 | + else if ( $action == "prefs" ) $ret = prefs() ; |
| 1092 | + else if ( $action == "login" ) $ret = login() ; |
| 1093 | + else if ( $action == "loginattempt" ) $ret = loginattempt() ; |
| 1094 | + else if ( $action == "logout" ) $ret = logout() ; |
| 1095 | + else if ( $action == "view" ) $ret = view() ; |
| 1096 | + else if ( $action == "edit" ) $ret = edit() ; |
| 1097 | + else if ( $action == "preview" ) $ret = edit() ; |
| 1098 | + else if ( $action == "edited" ) $ret = edited() ; |
| 1099 | + else if ( $action == "revisions" ) $ret = revisions() ; |
| 1100 | + else if ( $action == "view_old_article" ) $ret = view_old_article( "parsed" ) ; |
| 1101 | + else if ( $action == "view_old_source" ) $ret = view_old_article( "source" ) ; |
| 1102 | + else { # No valid action! |
| 1103 | + $ret = "<font size=\"+4\">ILLEGAL COMMAND!</font><br>\n" ; |
| 1104 | + $ret .= "Return to the <a href=\"/niki.phtml\">Main Page</a>" ; |
| 1105 | + } |
| 1106 | + print "<html>\n<head>\n</head>\n<body>" ; |
| 1107 | + echo $ret ; |
| 1108 | + unset ( $oid ) ; |
| 1109 | + unset ( $doSearch ) ; |
| 1110 | + unset ( $editusername ) ; |
| 1111 | +?> |
| 1112 | + |
| 1113 | +</body> |
| 1114 | + |
| 1115 | +</html> |
| 1116 | +</pre> |
Property changes on: branches/avendor/phpwiki/wikipediaPHPScript.txt |
___________________________________________________________________ |
Name: svn:keywords |
1 | 1117 | + Author Date Id Revision |
Name: svn:eol-style |
2 | 1118 | + native |
Index: branches/avendor/phpwiki/phpwiki/.ssh/random_seed |
— | — | @@ -0,0 +1,3 @@ |
| 2 | +��0��D��"�lj%V����h�gE��3F�xş�o{o�V |
| 3 | +�cUz"df��t��&�?B�L��T#�9�v2�g<����gn+�Ҝ�zû 6�9K�?� �3h���`*}}y�bDՐ�ЕD��p��� |
| 4 | +7���lأ���i�_PC�+���^��)"���6Y��`����H��O46jY��W����]�[�����T���NF�CԪ��`����z�M, |
\ No newline at end of file |
Property changes on: branches/avendor/phpwiki/phpwiki/.ssh/random_seed |
___________________________________________________________________ |
Name: svn:keywords |
1 | 5 | + Author Date Id Revision |
Name: svn:eol-style |
2 | 6 | + native |
Index: branches/avendor/phpwiki/phpwiki/.ssh/known_hosts |
— | — | @@ -0,0 +1 @@ |
| 2 | +cvs.wikipedia.sourceforge.net 1024 35 135459351736321163060158393531468444816302234590973809357152436576350207072252287835707057476174967415296163010396506793977298682224754860632880044268868000037878105011492026587585650803634691714922798574463393683597106735308595648792534668214949718972181353995125678208863789676171889408918130030154710172303 |
Property changes on: branches/avendor/phpwiki/phpwiki/.ssh/known_hosts |
___________________________________________________________________ |
Name: svn:keywords |
1 | 3 | + Author Date Id Revision |
Name: svn:eol-style |
2 | 4 | + native |