r27 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r26‎ | r27 | r28 >
Date:12:47, 19 October 2001
Author:magnus_manske
Status:old
Tags:
Comment:
misc. improvements
Modified paths:
  • /trunk/phpwiki/fpw/specialPages.php (modified) (history)
  • /trunk/phpwiki/fpw/wiki.phtml (modified) (history)
  • /trunk/phpwiki/fpw/wikiPage.php (modified) (history)
  • /trunk/phpwiki/fpw/wikiTitle.php (modified) (history)
  • /trunk/phpwiki/fpw/wikiUser.php (modified) (history)

Diff [purge]

Index: trunk/phpwiki/fpw/specialPages.php
@@ -1,110 +1,24 @@
22 <?
3 -function error ( $error ) {
4 - $page = new WikiPage ;
5 - $page->special ( "Yikes! An error!" ) ;
6 - $page->contents = "<h2>$error!</h2>Return to the [[:HomePage|HomePage]]!" ;
7 - return $page->renderPage () ;
8 - }
 3+# This contains special functions that are not necessare for basic view/edit purposes
 4+# - userLogout
 5+# - userLogin
 6+# - editUserSettings
 7+# - WantedPages (the most wanted)
 8+# - shortPages (stub articles)
 9+# - lonelyPages (orphans)
 10+# - watchlist
 11+# - recentChanges
 12+# - randomPage
 13+# - statistics
 14+# - allPages
 15+# - search
 16+# - specialPages (the list)
 17+# - history
 18+# - upload
 19+# - statistics
 20+# - delete (a page; for sysops only!)
 21+# - askSQL (for sysops only!)
922
10 -function edit ( $title ) {
11 - global $EditBox , $SaveButton , $PreviewButton , $MinorEdit ;
12 - global $user , $CommentBox , $vpage , $EditTime ;
13 - $npage = new WikiPage ;
14 - $npage->title = $title ;
15 - $npage->makeAll () ;
16 - $ret = "" ;
17 - if ( !$vpage->canEdit() ) return "<h3>You cannot edit this page!</h3>" ;
18 -
19 - if ( $EditTime == "" ) $EditTime = date ( "YmdHis" ) ;
20 -
21 -
22 - if ( isset ( $SaveButton ) ) {
23 - unset ( $SaveButton ) ;
24 - if ( $vpage->doesTopicExist() ) {
25 - $lastTime = getMySQL ( "cur" , "cur_timestamp" , "cur_title=\"$vpage->secureTitle\"" ) ;
26 - if ( tsc($EditTime) < tsc($lastTime) ) return "<h1>While you were typing, someone saved another version of this article!</h1>" ;
27 - }
28 - $text = $EditBox ;
29 - $text = str_replace ( "\\'" , "'" , $text ) ;
30 - $text = str_replace ( "\\\"" , "\"" , $text ) ;
31 - if ( $user->isLoggedIn ) $text = str_replace ( "~~~" , "[[user:$user->name|$user->name]]" , $text ) ;
32 - else $text = str_replace ( "~~~" , $user->getLink() , $text ) ;
33 - $title = str_replace ( "\\'" , "'" , $title ) ;
34 - $title = str_replace ( "\\\"" , "\"" , $title ) ;
35 - $npage->title = $title ;
36 - $npage->makeAll () ;
37 - if ( $npage->doesTopicExist() ) $npage->backup() ;
38 - else { $MinorEdit = 2 ; $npage->ensureExistence () ; }
39 - if ( !$user->isLoggedIn ) $npage->setEntry ( $text , $CommentBox , 0 , $user->getLink() , $MinorEdit*1 ) ;
40 - else $npage->setEntry ( $text , $CommentBox , $user->id , $user->name , $MinorEdit*1 ) ;
41 - global $wasSaved ;
42 - $wasSaved = true ;
43 - return "" ;
44 - } else if ( isset ( $PreviewButton ) ) {
45 - unset ( $PreviewButton ) ;
46 - $text = $EditBox ;
47 - $text = str_replace ( "\\'" , "'" , $text ) ;
48 - $text = str_replace ( "\\\"" , "\"" , $text ) ;
49 - $append = "<hr>\n<h2>Preview :</h2>\n".$npage->parseContents($text)."<hr><h3>Remember, this is only a preview and not yet saved!</h3>" ;
50 - } else if ( $npage->doesTopicExist() ) {
51 - $npage->load ( $npage->title ) ;
52 - $text = $npage->contents ;
53 - } else {
54 - $text = "Describe the new page here." ;
55 - }
56 -
57 - if ( $MinorEdit ) $checked = "checked" ;
58 - else $checked = "" ;
59 - if ( $CommentBox == "" ) $CommentBox = "*" ;
60 -
61 -
62 - # Just trying to set the initial keyboard focus to the edit window; doesn't work, though...
63 - global $bodyOptions , $headerScript ;
64 - $headerScript = "<script> <!-- function setfocus() { document.f.EditBox.focus(); } --> </script>" ;
65 - $bodyOptions = " onLoad=setfocus()" ;
66 -
67 - $ret .= "<form method=POST name=f>" ;
68 - $ret .= "<textarea tabindex=1 name=EditBox rows=".$user->options["rows"]." cols=".$user->options["cols"]." STYLE=\"width:100%\" WRAP=virtual>$text</textarea><br>\n" ;
69 - $ret .= "Summary:<input tabindex=2 type=text value=\"$CommentBox\" name=CommentBox size=50 maxlength=200> \n" ;
70 - $ret .= "<input tabindex=3 type=checkbox name=MinorEdit $checked value=1>This is a minor edit \n" ;
71 - $ret .= "<input tabindex=4 type=submit value=Save name=SaveButton> \n" ;
72 - $ret .= "<input tabindex=5 type=submit value=Preview name=PreviewButton>\n" ;
73 - $ret .= "<input type=hidden value=\"$EditTime\" name=EditTime>\n" ;
74 - $ret .= "</form>" ;
75 -
76 - return $ret.$append ;
77 - }
78 -
79 -function doEdit ( $title ) {
80 - global $THESCRIPT ;
81 - global $vpage , $action , $wasSaved ;
82 - $wasSaved = false ;
83 - $vpage = new WikiPage ;
84 - $vpage->isSpecialPage = true ;
85 - $vpage->title = $title ;
86 - $vpage->makeSecureTitle () ;
87 - $action = "" ;
88 - $ret = $vpage->getHeader() ;
89 - $action = "edit" ;
90 -
91 - $theMiddle = edit ( $title ) ;
92 - if ( $wasSaved )
93 - $theMiddle = "<h1>Your page was successfully saved!</h1><META HTTP-EQUIV=Refresh CONTENT=\"0; URL=$THESCRIPT?title=$vpage->secureTitle\">" ;
94 - $ret .= $vpage->getMiddle ( $theMiddle ) ;
95 -
96 - $action = "" ;
97 - $ret .= $vpage->getFooter() ;
98 - $action = "edit" ;
99 - return $ret ;
100 - }
101 -
102 -function view ( $title ) {
103 - global $vpage ;
104 - $vpage = new WikiPage ;
105 - $vpage->load ( $title ) ;
106 - return $vpage->renderPage () ;
107 - }
108 -
10923 function userLogout () {
11024 global $user , $vpage ;
11125 $vpage->title = "User logout" ;
@@ -497,56 +411,8 @@
498412 if ( in_array ( "is_sysop" , $user->rights ) ) $ret .= " ($s->user_rights)" ;
499413 $ret .= "\n" ;
500414 }
501 -
502415
503416 return $ret ;
504 -
505 -#------------------------------------------------
506 - global $THESCRIPT ;
507 - global $user , $vpage , $startat ;
508 - if ( !isset ( $startat ) ) $startat = 1 ;
509 - $perpage = $user->options["resultsPerPage"] ;
510 - if ( $perpage == 0 ) $perpage = 20 ;
511 -
512 - $vpage->special ( "User List" ) ;
513 - $vpage->namespace = "" ;
514 - $ret = "'''These are all wikipedia users (that have an account)!'''\n\n" ;
515 - $connection = getDBconnection () ;
516 - mysql_select_db ( "wikipedia" , $connection ) ;
517 - $sql = "SELECT COUNT(*) AS number FROM cur WHERE cur_title LIKE \"User:%\"" ;
518 - $result = mysql_query ( $sql , $connection ) ;
519 - $s = mysql_fetch_object ( $result ) ;
520 - $total = $s->number ;
521 - $sql = "SELECT * FROM cur WHERE cur_title LIKE \"User:%\" ORDER BY cur_title" ;
522 - $result = mysql_query ( $sql , $connection ) ;
523 - $cnt = 1 ;
524 - $color1 = $user->options["tabLine1"] ;
525 - $color2 = $user->options["tabLine2"] ;
526 - $color = $color1 ;
527 - $ret .= "<table width=100%>\n" ;
528 - while ( $s = mysql_fetch_object ( $result ) and $cnt < $startat+$perpage ) {
529 - if ( $cnt >= $startat ) {
530 - $u = $s->cur_title ;
531 - $u = substr ( strstr ( $u , ":" ) , 1 ) ;
532 - $u = $vpage->getNiceTitle ( $u ) ;
533 - $ret .= "<tr><td$color align=right nowrap>$cnt</td>" ;
534 - $ret .= "<td$color width=100% valign=top>[[$s->cur_title|$u]]</td></tr>\n";
535 - if ( $color == $color1 ) $color = $color2 ;
536 - else $color = $color1 ;
537 - }
538 - $cnt++ ;
539 - }
540 - $ret .= "</table>\n" ;
541 -
542 - $ret .= "<nowiki>" ;
543 - $before = $startat - $perpage ; $fin = $before + $perpage - 1 ;
544 - if ( $startat > 1 ) $ret .= "<a href=\"$THESCRIPT?title=special:UserList&startat=$before\">$before-$fin&lt;&lt;</a> &nbsp;" ;
545 - $after = $startat + $perpage ; $fin = $after+$perpage - 1 ; if ( $fin > $total ) $fin = $total ;
546 - if ( $after-1 < $total ) $ret .= "<a href=\"$THESCRIPT?title=special:UserList&startat=$after\">&gt;&gt;$after-$fin</a>" ;
547 - $ret .= "</nowiki>" ;
548 - mysql_free_result ( $result ) ;
549 - mysql_close ( $connection ) ;
550 - return $ret ;
551417 }
552418
553419 function randompage () {
@@ -864,22 +730,14 @@
865731 global $removeFile , $xtitle , $removeFile , $Upload , $Upload_name , $no_copyright ;
866732 global $user , $vpage ;
867733 $vpage->special ( "Upload Page" ) ;
868 -
869 -# if ( $USERLOGGEDIN != "YES" ) return "You are not logged in! You have to be logged in to upload a file. <a href=\"$THESCRIPT?action=login\">Log in</a> or return to the <a href=\"$THESCRIPT?no\">HomePage</a>" ;
870 -
871 -# $rights = ",".getUserSetting ( $USERNAME , "user_rights" )."," ;
872 -# if ( strstr ( $rights , ",is_editor," ) or strstr ( $rights , ",is_sysop" ) ) $isEditor = true ;
873 -# else $isEditor = false ;
874 -# if ( strstr ( $rights , ",is_sysop," ) or strstr ( $rights , ",is_sysop" ) ) $isSysop = true ;
875 -# else $isSysop = false ;
876 -
 734+ $isSysop = in_array ( "is_sysop" , $user->rights ) ;
877735 $xtitle = "File upload page";
878736 $ret = "<nowiki>" ;
879737
880738 $message = "" ;
881739
882740 if (isset($removeFile)) {
883 -# if ( !$isSysop and !$isEditor ) return "You are neither an editor nor a sysop. Return to the <a href=\"$THESCRIPT?action=upload\">Upload page</a>" ;
 741+ if ( !$isSysop ) return "You are neither an editor nor a sysop. Return to the <a href=\"$THESCRIPT?action=upload\">Upload page</a>" ;
884742 if (is_file("upload/$removeFile") ) unlink ("./upload/$removeFile");
885743 $message = "File <b>$removeFile</b> deleted!" ;
886744 unset ( $removeFile ) ;
@@ -949,16 +807,16 @@
950808 $i = 0;
951809 $ret .= "<table border=1 width=\"100%\">\n";
952810 $ret .= "<tr><th>File</th><th>Size (byte)</th>";
953 -# if ( $isSysop or $isEditor )
954 - $ret .= "<th>File removal</th>";
 811+ if ( $isSysop )
 812+ $ret .= "<th>File removal</th>";
955813 $ret .= "</tr>\n" ;
956814 while ($entry = readdir($mydir)) {
957815 if ($entry != '.' && $entry != '..') {
958816 $ret .= "<tr><td align=center>" ;
959817 $ret .= "<a href=upload/$entry>$entry</a></td>";
960818 $ret .= "<td align=center>".filesize("upload/$entry")." bytes</td>";
961 -# if ( $isSysop or $isEditor )
962 - $ret .= "<td align=center><a href=\"$THESCRIPT?title=special:upload&removeFile=$entry\">Click here to remove $entry.</a></td>" ;
 819+ if ( $isSysop )
 820+ $ret .= "<td align=center><a href=\"$THESCRIPT?title=special:upload&removeFile=$entry\">Click here to remove $entry.</a></td>" ;
963821 $ret .= "</tr>" ;
964822 $i++;
965823 }
@@ -1137,7 +995,7 @@
1138996 return "<nowiki>$ret</nowiki>" ;
1139997 }
1140998
1141 -# A little hack; disabled; to enable, allow function call in wikiPage->load()
 999+# A little hack for direct MySQL access; for sysops only!
11421000 function askSQL () {
11431001 global $THESCRIPT ;
11441002 global $Save , $question ;
Index: trunk/phpwiki/fpw/wiki.phtml
@@ -1,19 +1,28 @@
22 <?
3 -$THESCRIPT = "wiki.phtml" ;
4 -include ( "./specialPages.php" ) ;
5 -include ( "./databaseFunctions.php" ) ;
6 -include ( "./wikiTitle.php" ) ;
7 -include ( "./wikiPage.php" ) ;
8 -include ( "./wikiUser.php" ) ;
 3+# THIS IS THE MAIN FILE OF THE PHP WIKIPEDIA SCRIPT
94
 5+$THESCRIPT = "wiki.phtml" ; # The name of the script. The $PHP_SELF variable doesn't work with Netscape
 6+
 7+# Includes the necessary parts
 8+#include_once ( "./specialPages.php" ) ;
 9+include_once ( "basicFunctions.php" ) ;
 10+include_once ( "./databaseFunctions.php" ) ;
 11+include_once ( "./wikiTitle.php" ) ;
 12+include_once ( "./wikiPage.php" ) ;
 13+include_once ( "./wikiUser.php" ) ;
 14+
1015 # Main program
1116 global $action , $title , $pageTitle ;
1217 global $user , $search , $expiration ;
1318 global $THESCRIPT ;
1419 $expiration = time()+315360000 ; # Cookies set will expire in ten years from now
1520 $pageTitle = "" ;
 21+
 22+ # Verifying the current user. Logged in? Password in a cookie?
1623 $user = new WikiUser ;
1724 $user->scanCookies () ;
 25+
 26+ # Default settings
1827 if ( $action == "" ) $action = "view" ;
1928 if ( $title == "" ) $title = "HomePage" ;
2029
@@ -25,6 +34,7 @@
2635 $action = strtolower ( trim ( $action ) ) ;
2736 $title = urldecode ( $title ) ;
2837
 38+ # Do what is asked
2939 if ( isset ( $search ) ) {
3040 $out = doSearch () ;
3141 unset ( $search ) ;
@@ -36,6 +46,7 @@
3747 else if ( $action == "history" ) $out = doHistory ( $title ) ;
3848 else $out = error ( "No such action \"$action\"" ) ;
3949
 50+ # Cleaning up, setting <title>, etc.
4051 global $bodyOptions , $headerScript ;
4152 $pageTitle = "Wikipedia : ".str_replace ( "_" , " " , $pageTitle ) ;
4253 $bodyOptions .= $user->options["background"] ;
@@ -43,12 +54,13 @@
4455 $head = "<HTML><HEAD><TITLE>$pageTitle</TITLE> $headerScript </HEAD><BODY $bodyOptions>\n" ;
4556 $tail = "</BODY></HTML>" ;
4657
 58+ # Adjusting link style
4759 $linkStyle = "style=\"color:blue\"" ;
4860 if ( $user->options["underlineLinks"] == "no" ) $linkStyle = "style=\"color:blue;text-decoration:none\"" ;
4961 if ( $user->options["forceLinks"] != "" ) $linkStyle = $user->options["forceLinks"] ;
5062 $out = str_replace ( "<a href=" , "<a $linkStyle href=" , $out ) ;
5163 $out = str_replace ( "&lt;a style=\"color:blue\"" , "&lt;a " , $out ) ; # Correcting weird replacement above
5264
53 - global $append; # For testing
54 - print $head.$out.$tail.$append ;
 65+ global $append; # For testing. Usually, $append is empty
 66+ print $head.$out.$tail.$append ; # FINALLY!!!!
5567 ?>
\ No newline at end of file
Index: trunk/phpwiki/fpw/wikiPage.php
@@ -1,9 +1,14 @@
22 <?
 3+# The wikiPage class is used for both database management and rendering (display) of articles
 4+# It inherits some functions and variables from the wikiTitle class
 5+
36 class WikiPage extends WikiTitle {
4 - var $contents ;
5 - var $knownLinkedLinks , $knownUnlinkedLinks ;
 7+ var $contents ; # The actual article body
 8+ var $knownLinkedLinks , $knownUnlinkedLinks ; # Used for faster display
69
7 - #Functions
 10+#### Database management functions
 11+
 12+ # This loads an article from the database, or calls a special function instead (all pages with "special:" namespace)
813 function load ( $t , $doRedirect = true ) {
914 global $action , $user ;
1015 $this->knownLinkedLinks = array () ;
@@ -12,9 +17,9 @@
1318 $this->makeSecureTitle () ;
1419 $this->isSpecialPage = false ;
1520 $this->revision = "current" ;
16 - if ( $this->namespace == "special" ) {
17 - $allowed = array("userlogin","userlogout","recentchanges","upload","statistics","lonelypages","wantedpages","allpages","randompage","shortpages","listusers","watchlist","special_pages","editusersettings","deletepage");
18 - if ( in_array ( "is_sysop" , $user->rights ) ) array_push ( $allowed , "asksql" ) ;
 21+ if ( $this->namespace == "special" ) { # Special page, calling appropriate function
 22+ $allowed = array("userlogin","userlogout","recentchanges","upload","statistics","lonelypages","wantedpages","allpages","randompage","shortpages","listusers","watchlist","special_pages","editusersettings","deletepage"); # List of allowed special pages
 23+ if ( in_array ( "is_sysop" , $user->rights ) ) array_push ( $allowed , "asksql" ) ; # Another function just for sysops
1924 $call = $this->mainTitle ;
2025 if ( !in_array ( strtolower ( $call ) , $allowed ) ) {
2126 $this->isSpecialPage = true ;
@@ -22,15 +27,18 @@
2328 return ;
2429 }
2530 $this->title = $call ;
 31+ include_once ( "specialPages.php") ;
2632 $this->contents = $call () ;
2733 $this->isSpecialPage = true ;
28 - return ;
 34+ return ; # contents of special page is returned here!!!
2935 }
 36+
 37+ # No special page, loading article form the database
3038 $connection = getDBconnection () ;
3139 mysql_select_db ( "wikipedia" , $connection ) ;
3240 $thisVersion = "" ;
3341 global $oldID , $version , $THESCRIPT ;
34 - if ( isset ( $oldID ) ) {
 42+ if ( isset ( $oldID ) ) { # an old article version
3543 $sql = "SELECT * FROM old WHERE old_id=$oldID" ;
3644 $result = mysql_query ( $sql , $connection ) ;
3745 if ( $s = mysql_fetch_object ( $result ) ) {
@@ -40,7 +48,7 @@
4149 $this->thisVersion = "<br><font size=-1>This is the old version #$version; see the <a href=\"$THESCRIPT?title=$this->secureTitle\">current version</a></font>" ;
4250 }
4351 else $this->contents = "Describe the new page here." ;
44 - } else {
 52+ } else { # The current article version
4553 $sql = "SELECT * FROM cur WHERE cur_title=\"".$this->secureTitle."\"" ;
4654 $result = mysql_query ( $sql , $connection ) ;
4755 if ( $s = mysql_fetch_object ( $result ) ) {
@@ -56,7 +64,7 @@
5765 mysql_close ( $connection ) ;
5866 $this->makeURL () ;
5967 $this->splitTitle () ;
60 - if ( strtolower ( substr ( $this->contents , 0 , 9 ) ) == "#redirect" and $doRedirect and $action != "edit" ) {
 68+ if ( strtolower ( substr ( $this->contents , 0 , 9 ) ) == "#redirect" and $doRedirect and $action != "edit" ) { # #REDIRECT
6169 $z = $this->contents ;
6270 $z = strstr ( $z , "[[" ) ;
6371 $z = str_replace ( "[[" , "" , $z ) ;
@@ -64,10 +72,14 @@
6573 $this->load ( trim($z) , false ) ;
6674 }
6775 }
 76+
 77+ # This function - well, you know...
6878 function special ( $t ) {
6979 $this->title = $t ;
7080 $this->isSpecialPage = true ;
7181 }
 82+
 83+ # This lists all the subpages of a page (for the QuickBar)
7284 function getSubpageList () {
7385 $a = array () ;
7486 $t = ucfirst ( $this->namespace ) ;
@@ -91,6 +103,9 @@
92104 if ( count ( $a ) > 0 ) array_unshift ( $a , "[[$mother]]" ) ;
93105 return $a ;
94106 }
 107+
 108+ # This lists all namespaces that contain an article with the same name
 109+ # Called by QuickBar() and getFooter()
95110 function getOtherNamespaces () {
96111 global $THESCRIPT ;
97112 $a = array () ;
@@ -121,6 +136,8 @@
122137 mysql_close ( $connection ) ;
123138 return $a ;
124139 }
 140+
 141+ # This creates a new article if there is none with the same title yet
125142 function ensureExistence () {
126143 $this->makeSecureTitle () ;
127144 if ( $this->doesTopicExist() ) return ;
@@ -130,6 +147,10 @@
131148 $result = mysql_query ( $sql , $connection ) ;
132149 mysql_close ( $connection ) ;
133150 }
 151+
 152+ # This function performs a backup from the "cur" to the "old" table, building a
 153+ # single-linked chain with the cur_old_version/old_old_version entries
 154+ # The target data set is defined by $this->secureTitle
134155 function backup () {
135156 $id = getMySQL ( "cur" , "cur_id" , "cur_title=\"$this->secureTitle\"" ) ;
136157 $oid = getMySQL ( "cur" , "cur_old_version" , "cur_id=$id" ) ;
@@ -156,6 +177,9 @@
157178
158179 mysql_close ( $connection ) ;
159180 }
 181+
 182+ # This function stores the passed parameters into the database (the "cur" table)
 183+ # The target data set is defined by $this->secureTitle
160184 function setEntry ( $text , $comment , $userID , $userName , $minorEdit ) {
161185 $cond = "cur_title=\"$this->secureTitle\"" ;
162186
@@ -174,7 +198,9 @@
175199 mysql_close ( $connection ) ;
176200 }
177201
178 - # Output functions
 202+#### Rendering functions
 203+ # This function converts wiki-style internal links like [[HomePage]] with the appropriate HTML code
 204+ # It has to handle namespaces, subpages, and alternate names (as in [[namespace:page/subpage name]])
179205 function replaceInternalLinks ( $s ) {
180206 global $THESCRIPT ;
181207 global $user , $unlinkedLinks , $linkedLinks ;
@@ -185,7 +211,7 @@
186212 $connection = getDBconnection () ;
187213 foreach ( $a as $t ) {
188214 $b = explode ( "]]" , $t , 2 ) ;
189 - if ( count($b) < 2 ) $s .= "Illegal link : ?$b[0]?" ;
 215+ if ( count($b) < 2 ) $s .= "<font color=red><b>Incorrect link : [[$b[0]</b></font>" ;
190216 else {
191217 $c = explode ( "|" , $b[0] , 2 ) ;
192218 $link = $c[0] ;
@@ -224,10 +250,14 @@
225251 mysql_close ( $connection ) ;
226252 return $s ;
227253 }
 254+
 255+ # This function replaces wiki-style image links with the HTML code to display them
228256 function parseImages ( $s ) {
229257 $s = ereg_replace ( "http://([a-zA-Z0-9_/:.]*)\.(png|jpg|jpeg|tif|tiff|gif)" , "<img src=\"http://\\1.\\2\">" , $s ) ;
230258 return $s ;
231259 }
 260+
 261+ # This function replaces wiki-style external links (both with and without []) with HTML links
232262 function replaceExternalLinks ( $s ) {
233263 global $user ;
234264 $cnt = 1 ;
@@ -261,13 +291,15 @@
262292
263293 return $s ;
264294 }
 295+
 296+ # This function replaces the newly introduced wiki variables with their values (for display only!)
265297 function replaceVariables ( $s ) {
266298 $var=date("m"); $s = str_replace ( "{{{CURRENTMONTH}}}" , $var , $s ) ;
267299 $var=date("F"); $s = str_replace ( "{{{CURRENTMONTHNAME}}}" , $var , $s ) ;
268300 $var=date("j"); $s = str_replace ( "{{{CURRENTDAY}}}" , $var , $s ) ;
269301 $var=date("l"); $s = str_replace ( "{{{CURRENTDAYNAME}}}" , $var , $s ) ;
270302 $var=date("Y"); $s = str_replace ( "{{{CURRENTYEAR}}}" , $var , $s ) ;
271 - if ( strstr ( $s , "{{{NUMBEROFARTICLES}}}" ) ) {
 303+ if ( strstr ( $s , "{{{NUMBEROFARTICLES}}}" ) ) { # This should count only "real" articles!
272304 $connection=getDBconnection() ;
273305 mysql_select_db ( "wikipedia" , $connection ) ;
274306 $sql = "SELECT COUNT(*) as number FROM cur WHERE cur_title NOT LIKE \"%/Talk\" AND cur_title NOT LIKE \"%ikipedia%\" AND cur_text LIKE \"%,%\"" ;
@@ -279,6 +311,8 @@
280312 }
281313 return $s ;
282314 }
 315+
 316+ # This function ensures all occurrences of $f are replaces with $r within $s
283317 function replaceAll ( $f , $r , &$s ) {
284318 $t = "" ;
285319 while ( $s != $t ) {
@@ -287,6 +321,8 @@
288322 }
289323 return $s ;
290324 }
 325+
 326+ # This function is called to replace wiki-style tags with HTML, e.g., the first occurrence of ''' with <b>, the second with </b>
291327 function pingPongReplace ( $f , $r1 , $r2 , $s ) {
292328 $a = explode ( $f , " ".$s ) ;
293329 $s = substr ( array_shift ( $a ) , 1 ) ;
@@ -298,24 +334,40 @@
299335 }
300336 return $s ;
301337 }
 338+
 339+ # This function organizes the <nowiki> parts and calls subPageContents() for the wiki parts
302340 function parseContents ( $s ) {
303341 global $linkedLinks , $unlinkedLinks ;
304342 $linkedLinks = array () ;
305343 $unlinkedLinks = array () ;
306344 $s .= "\n" ;
307345 $a = spliti ( "<nowiki>" , $s ) ;
308 - $s = $this->subParseContents ( array_shift ( $a ) ) ;
 346+
 347+ # $d needs to contain a unique string - this can be altered at will, as long it stays unique!
 348+ $d = "��~~����~~�~��~�~��~��~�~�~�����~���~���~�" ;
 349+
 350+ $b = array () ;
 351+ $s = array_shift ( $a ) ;
309352 foreach ( $a as $x ) {
310 - $b = spliti ( "</nowiki>" , $x , 2 ) ;
311 - $s .= $b[0] ;
312 - if ( count ( $b ) == 2 ) {
313 - $sub = $this->subParseContents ( $b[1] ) ;
314 - $sub = substr ( strstr ( $sub , ">" ) , 1 ) ;
315 - $s .= $sub ;
316 - }
 353+ $c = spliti ( "</nowiki>" , $x , 2 ) ;
 354+ if ( count ( $c ) == 2 ) {
 355+ array_push ( $b , $c[0] ) ;
 356+ $s .= $d.$c[1] ;
 357+ } else $s .= "&lt;nowiki&gt;".$x ;
317358 }
 359+ $s = $this->subParseContents ( $s ) ;
 360+
 361+ # replacing $d with the actual nowiki contents
 362+ $a = spliti ( $d , $s ) ;
 363+ $s = array_shift ( $a ) ;
 364+ foreach ( $a as $x ) {
 365+ $s .= array_shift ( $b ) . $x ;
 366+ }
 367+
318368 return $s ;
319369 }
 370+
 371+ # This function removes "forbidden" HTML tags
320372 function removeHTMLtags ( $s ) {
321373 $s = eregi_replace ( "<a (.*)>" , "&lt;a \\1&gt;" , $s ) ;
322374 $s = eregi_replace ( "</a(.*)>" , "&lt;/a\\1&gt;" , $s ) ;
@@ -323,19 +375,25 @@
324376 $s = eregi_replace ( "</script(.*)>" , "&lt;/script\\1&gt;" , $s ) ;
325377 return $s ;
326378 }
 379+
 380+ # This function does the actual parsing of the wiki parts of the article
327381 function subParseContents ( $s ) {
328382 global $user ;
329 -# Removed autoLink for mixedThings; wasn't working, anyway...
 383+# Removed automatic links for mixedThings; wasn't working, anyway...
330384 # $s = ereg_replace ( "([\.|\n| )([a-z0-9]*[A-Z0-9]+[A-Za-z0-9]*)( |\n|\.)" , "\\1[[\\2]]\\3" , $s ) ;
331 - $s = $this->removeHTMLtags ( $s ) ;
 385+ $s = $this->removeHTMLtags ( $s ) ; # Removing "forbidden" HTML tags
 386+ # Now some repalcements wiki->HTML
332387 $s = ereg_replace ( "-----*" , "<hr>" , $s ) ;
333388 $s = str_replace ( "<HR>" , "<hr>" , $s ) ;
334389 $s = $this->replaceVariables ( $s ) ;
335390 $s = $this->pingPongReplace ( "'''" , "<b>" , "</b>" , $s ) ;
336391 $s = $this->pingPongReplace ( "''" , "<i>" , "</i>" , $s ) ;
337392
 393+ # Automatic links to subpages (e.g., /Talk -> [[/Talk]]
338394 $s = ereg_replace ( "([\n| ])/([a-zA-Z0-9_]*)" , "\\1[[/\\2|/\\2]]" , $s ) ;
339395
 396+ # Parsing through the text line by line
 397+ # The main thing happening here is handling of lines starting with * # : etc.
340398 $justify = "" ;
341399 if ( $user->options["justify"] == "yes" ) $justify = " align=justify" ;
342400 $a = explode ( "\n" , $s ) ;
@@ -397,20 +455,26 @@
398456 }
399457 $s .= "</p>" ;
400458
 459+ # Removing artefact empty paragraphs like <p></p>
401460 $this->replaceAll ( "<p$justify>\n</p>" , "<p$justify></p>" , $s ) ;
402461 $this->replaceAll ( "<p$justify></p>" , "" , $s ) ;
403462
 463+ # Stuff for the skins
404464 if ( $user->options["textTableBackground"] != "" ) {
405465 $s = str_replace ( "<table" , "<table".$user->options["textTableBackground"] , $s ) ;
406466 }
407467
 468+ # And now, for the final...
408469 $s = $this->parseImages ( $s ) ;
409470 $s = $this->replaceExternalLinks ( $s ) ;
410471 $s = $this->replaceInternalLinks ( $s ) ;
411472 return $s ;
412473 }
413474
414 - # Header and footer section
 475+#### Header and footer section
 476+
 477+ # This generates the bar at the top and bottom of each page
 478+ # Used by getHeader() and getFooter()
415479 function getLinkBar () {
416480 global $THESCRIPT ;
417481 global $user , $oldID , $version ;
@@ -433,6 +497,8 @@
434498 $ret .= " | <a href=\"$THESCRIPT?title=special:Special_pages\">Special Pages</a>" ;
435499 return $ret ;
436500 }
 501+
 502+ # This generates the header with title, user name and functions, wikipedia logo, search box etc.
437503 function getHeader () {
438504 global $THESCRIPT ;
439505 global $user , $action ;
@@ -467,6 +533,8 @@
468534 $ret .= "<tr><td valign=bottom>".$this->getLinkBar()."</td></tr></table>" ;
469535 return $ret ;
470536 }
 537+
 538+ # This generates the QuickBar (also used by the list of special pages function)
471539 function getQuickBar () {
472540 global $THESCRIPT ;
473541 global $user , $oldID , $version ;
@@ -478,6 +546,7 @@
479547 if ( $this->canEdit() ) $column .= "<br><a href=\"$THESCRIPT?action=edit&title=$this->url$editOldVersion\">Edit this page</a>\n" ;
480548
481549 if ( $this->canDelete() ) $column .= "<br><a href=\"$THESCRIPT?title=special:deletepage&target=$this->url\">Delete this page</a>\n" ;
 550+# To be implemented later
482551 # if ( $this->canProtect() ) $column .= "<br><a href=\"$THESCRIPT?action=protectpage&title=$this->url\">Protect this page</a>\n" ;
483552 # if ( $this->canAdvance() ) $column .= "<br><a href=\"$THESCRIPT?title=special:Advance&topic=$this->safeTitle\">Advance</a>\n" ;
484553
@@ -498,6 +567,9 @@
499568 if ( count ( $a ) > 0 ) $column .= "<hr>".implode ( "<br>\n" , $a ) ;
500569 return $column."</nowiki>" ;
501570 }
 571+
 572+ # This calls the parser and eventually adds the QuickBar. Used fro display of normal article pages
 573+ # Some special pages have their own rendering function
502574 function getMiddle ( $ret ) {
503575 global $user , $action ;
504576 $oaction = $action ;
@@ -521,6 +593,8 @@
522594 $action = $oaction ;
523595 return $ret ;
524596 }
 597+
 598+ # This generates the footer with link bar, search box, etc.
525599 function getFooter () {
526600 global $THESCRIPT ;
527601 $ret = $this->getLinkBar() ;
@@ -534,6 +608,9 @@
535609 $ret .= "<FORM>Search: <INPUT TYPE=text NAME=search SIZE=20></FORM>" ;
536610 return $ret ;
537611 }
 612+
 613+ # This generates header, diff (if wanted), article body (with QuickBar), and footer
 614+ # The whole page (for normal pages) is generated here
538615 function renderPage () {
539616 global $pageTitle , $diff ;
540617 $pageTitle = $this->title ;
@@ -542,6 +619,8 @@
543620 $middle = $this->getMiddle($this->parseContents($middle)) ;
544621 return $this->getHeader().$middle.$this->getFooter() ;
545622 }
 623+
 624+ # This displays the diff. Currently, only diff with the last edit!
546625 function doDiff () {
547626 global $oldID , $version , $user ;
548627 $ret = "<nowiki><font color=red><b>BEGIN DIFF</b></font><br>\n" ;
@@ -579,8 +658,8 @@
580659 # Output
581660 $ret .= "<font color=#2AAA2A>Green text</font> was added or changed, <font color=#AAAA00>yellow text</font> was changed or deleted." ;
582661 $ret .= "<table width=100% border=1$bc cellspacing=0 cellpadding=2>\n" ;
583 - foreach ( $nl as $x ) $ret .= "<tr><td bgcolor=#FFFFAF><font$fc>$x</font></td></tr>\n" ;
584 - foreach ( $dl as $x ) $ret .= "<tr><td bgcolor=#CFFFCF><font$fc>$x</font></td></tr>\n" ;
 662+ foreach ( $nl as $x ) $ret .= "<tr><td bgcolor=#CFFFCF><font$fc>$x</font></td></tr>\n" ;
 663+ foreach ( $dl as $x ) $ret .= "<tr><td bgcolor=#FFFFAF><font$fc>$x</font></td></tr>\n" ;
585664 $ret .= "</table>\n" ;
586665 } else if ( isset ( $oldID ) and $s->old_old_version == 0 ) $ret .= "This is the first version of this article. All text is new!<br>\n" ;
587666 else if ( !isset ( $oldID ) ) $ret .= "This is the first version of this article. All text is new!<br>\n" ;
Index: trunk/phpwiki/fpw/wikiUser.php
@@ -1,15 +1,22 @@
22 <?
 3+# The wikiUser class handles all user information
 4+
35 class WikiUser {
46 var $id , $name , $password , $retypePassword ;
5 - var $isLoggedIn ;
67 var $options , $email ;
78 var $rights ;
 9+ var $isLoggedIn ; # Is this user currently logged in?
810
 11+#### Skin functions
 12+
 13+ # Creates the options for the currently selected skin by calling the appropriate function
914 function skin () {
1015 if ( $this->options["skin"] == "" ) $this->skinBlank () ;
1116 else if ( $this->options["skin"] == "None" ) $this->skinBlank () ;
1217 else if ( $this->options["skin"] == "Star Trek" ) $this->skinStarTrek () ;
1318 }
 19+
 20+ # This sets the options for the standard skin
1421 function skinBlank () {
1522 $this->options["background"] = "" ;
1623 $this->options["text"] = "" ;
@@ -23,6 +30,8 @@
2431 $this->options["tabLine1"] = "" ;
2532 $this->options["tabLine2"] = " bgcolor=#FFFFCC" ;
2633 }
 34+
 35+ # This sets the options for the StarTrek skin
2736 function skinStarTrek () {
2837 $this->options["background"] = " BGCOLOR=#000000 " ;
2938 $this->options["text"] = " TEXT=#00BB00 " ;
@@ -36,6 +45,10 @@
3746 $this->options["tabLine1"] = "" ;
3847 $this->options["tabLine2"] = " bgcolor=#333333" ;
3948 }
 49+
 50+#### Management functions
 51+
 52+ # This checks the cookies for prior log-ins
4053 function scanCookies () {
4154 global $WikiUserID , $WikiUserPassword , $WikiLoggedIn ;
4255 $this->id = 0 ;
@@ -62,8 +75,10 @@
6376 $this->ensureDefaultOptions () ;
6477 $this->skin () ;
6578 }
 79+
 80+ # This sets the default options for new and no-log-in users
6681 function ensureDefaultOptions () {
67 - if ( $this->options["quickBar"] == "" ) $this->options["quickBar"] = "none" ;
 82+ if ( $this->options["quickBar"] == "" ) $this->options["quickBar"] = "right" ; # For demonstration
6883 if ( $this->options["markupNewTopics"] == "" ) $this->options["markupNewTopics"] = "normal" ;
6984 if ( $this->options["underlineLinks"] == "" ) $this->options["underlineLinks"] = "yes" ;
7085 if ( $this->options["showHover"] == "" ) $this->options["showHover"] = "yes" ;
@@ -75,7 +90,10 @@
7691 if ( $this->options["resultsPerPage"] == "" ) $this->options["resultsPerPage"] = "20" ;
7792 if ( $this->options["skin"] == "" ) $this->options["skin"] = "None" ;
7893 }
 94+
 95+ # Loads the user settings from the database
7996 function loadSettings () {
 97+ $this->rights = array () ;
8098 if ( !$this->isLoggedIn ) return ;
8199 $t = getMySQL ( "user" , "user_options" , "user_id=".$this->id ) ;
82100 $t = urldecode ( $t ) ;
@@ -91,6 +109,8 @@
92110 $this->email = getMySQL ( "user" , "user_email" , "user_id=".$this->id ) ;
93111 $this->skin () ;
94112 }
 113+
 114+ # Saves/updates the user settings in the database
95115 function saveSettings () {
96116 global $expiration ;
97117 if ( !$this->isLoggedIn ) return ;
@@ -107,11 +127,12 @@
108128 setMySQL ( "user" , "user_email" , $this->email , "user_id=".$this->id ) ;
109129 if ( $this->options["rememberPassword"] == "on" ) setcookie ( "WikiUserPassword" , $this->password , $expiration ) ;
110130 }
 131+
 132+ # Creates a link to the user home page, or returns the IP
111133 function getLink () {
112134 global $REMOTE_ADDR ;
113135 if ( $this->isLoggedIn ) {
114136 $s = new WikiPage ;
115 -# $s->setTitle ( "user:$this->name" ) ;
116137 $s = $s->parseContents ( "[[user:$this->name|$this->name]]" ) ;
117138 $s = substr ( strstr ( $s , ">" ) , 1 ) ;
118139 $s = str_replace ( "</p>" , "" , $s ) ;
@@ -122,6 +143,8 @@
123144 $s = $s[0].".".$s[1].".".$s[2].".xxx" ;
124145 return $s ;
125146 }
 147+
 148+ # Checks if a user with that name exists
126149 function doesUserExist () {
127150 $s = trim ( $this->name ) ;
128151 if ( $s == "" ) return false ;
@@ -139,6 +162,8 @@
140163 if ( $s == "" ) return false ;
141164 return true ;
142165 }
 166+
 167+ # Adds a new user to the database
143168 function addToDatabase () {
144169 $connection = getDBconnection () ;
145170 mysql_select_db ( "wikipedia" , $connection ) ;
@@ -146,6 +171,8 @@
147172 $result = mysql_query ( $sql , $connection ) ;
148173 mysql_close ( $connection ) ;
149174 }
 175+
 176+ # Checks the login
150177 function verify () {
151178 $this->isLoggedIn = false ;
152179 if ( !$this->doesUserExist() ) return "<font color=red>Unknown user \"$this->name\"!</font>" ;
@@ -174,6 +201,8 @@
175202
176203 return $ret ;
177204 }
 205+
 206+ # Toggles the watch on an article for this user
178207 function doWatch ( $t ) {
179208 $a = getMySQL ( "user" , "user_watch" , "user_id=$this->id" ) ;
180209 $b = explode ( "'" , $a ) ;
Index: trunk/phpwiki/fpw/wikiTitle.php
@@ -1,10 +1,14 @@
22 <?
 3+# The wikiTitle class manages the titles of articles. Useful for converting titles into different needed formats.
 4+# Gives its functions and variables to the wikiPage class
 5+
36 class WikiTitle {
47 var $title , $secureTitle , $url , $isSpecialPage , $thisVersion ;
58 var $namespace , $mainTitle , $subpageTitle , $hasNamespace ;
69
7 - # Functions
8 - # User rights
 10+##### Functions
 11+####### # User rights
 12+ # Can the current user delete this page?
913 function canEdit () {
1014 global $action ;
1115 # global $oldID ; if ( isset ( $oldID ) ) return false ;
@@ -18,6 +22,8 @@
1923
2024 return true ;
2125 }
 26+
 27+ # Can the current user delete this page?
2228 function canDelete () {
2329 global $action , $user ;
2430 global $oldID ; if ( isset ( $oldID ) ) return false ;
@@ -27,6 +33,8 @@
2834 if ( in_array ( "is_sysop" , $user->rights ) ) return true ;
2935 return false ;
3036 }
 37+
 38+ # Can the current user protect this page? (NOT USED YET)
3139 function canProtect () {
3240 global $action , $user ;
3341 global $oldID ; if ( isset ( $oldID ) ) return false ;
@@ -36,6 +44,8 @@
3745 if ( in_array ( "is_sysop" , $user->rights ) ) return true ;
3846 return false ;
3947 }
 48+
 49+ # Can the current user advance this page? (NOT USED YET)
4050 function canAdvance () {
4151 global $action , $user ;
4252 global $oldID ; if ( isset ( $oldID ) ) return false ;
@@ -46,7 +56,9 @@
4757 return false ;
4858 }
4959
50 - # Title functions
 60+#### Title functions
 61+
 62+ # Generates a "secure" title
5163 function makeSecureTitle () {
5264 $this->splitTitle () ;
5365 $s = ucfirst ( trim ( $this->namespace ) ) ;
@@ -58,14 +70,17 @@
5971 $s = str_replace ( "\\'" , "'" , $s ) ;
6072
6173 # Make it compatible with old wiki
62 -# $s = str_replace ( "'" , "" , $s ) ;
6374 $s = str_replace ( " " , "_" , $s ) ;
6475
6576 $this->secureTitle = $s ;
6677 }
 78+
 79+ # Converts the secure title to an even more secure one (URL-style)
6780 function makeURL () {
6881 $this->url = urlencode ( $this->secureTitle ) ;
6982 }
 83+
 84+ # Converts a secure title back to a nice-looking one
7085 function getNiceTitle ( $s ) {
7186 if ( !isset ( $s ) ) $s = $this->secureTitle ;
7287 $s = str_replace ( "_" , " " , $s ) ;
@@ -73,6 +88,8 @@
7489 $s = str_replace ( "\\\\" , "\\" , $s ) ;
7590 return ucfirst ( $s ) ;
7691 }
 92+
 93+ # Takes apart a title by namespace, subpage...
7794 function splitTitle () {
7895 $a = explode ( ":" , $this->title , 2 ) ;
7996 if ( count ( $a ) == 1 ) {
@@ -90,6 +107,8 @@
91108 else $this->subpageTitle = $a[1] ;
92109 $this->namespace = strtolower ( $this->namespace ) ;
93110 }
 111+
 112+ # I don't remember what this does, or if I use it somewhere...
94113 function getLinkTo ( $target ) {
95114 $n = $this->namespace ;
96115 if ( $target->hasNamespace ) $n = $target->namespace ;
@@ -100,14 +119,20 @@
101120 if ( $target->subpageTitle != "" ) $ret .= "/".$target->subpageTitle ;
102121 return $ret ;
103122 }
 123+
 124+ # These are pretty straight-forward
104125 function makeAll () { $this->makeSecureTitle(); $this->makeURL(); }
105126 function setTitle ( $t ) { $this->title = $t ; $this->makeAll() ; }
 127+
 128+ # OUTDATED!!! BUT LEAVE IT!!
106129 function getMainTitle () {
107130 $r = $this->title ;
108131 # if ( strstr ( $r , ":" ) == false and $this->hasNamespace and $this->namespace != "" ) $r = $this->namespace.":$r" ;
109132 # if ( $this->subpageTitle != "" ) $r .= "/".$this->subpageTitle ;
110133 return $r ;
111134 }
 135+
 136+ # Checks the database if this topic already exists
112137 function doesTopicExist ( $conn = "" ) {
113138 $this->makeSecureTitle () ;
114139 if ( $this->namespace == "special" ) return true ;
@@ -124,6 +149,8 @@
125150 }
126151 return false ;
127152 }
 153+
 154+ # Checks for one namespace and one subpage level max.
128155 function validateTitle () {
129156 $this->makeSecureTitle () ;
130157 if ( $this->mainTitle == "" ) return false ;

Status & tagging log