r101 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100‎ | r101 | r102 >
Date:21:42, 8 February 2002
Author:hidders
Status:old
Tags:
Comment:
remove accidentally created file
Modified paths:
  • /trunk/phpwiki/wikipediaPHPScript.txt (deleted) (history)

Diff [purge]

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

Status & tagging log