Index: trunk/phpwiki/fpw/specialPages.php |
— | — | @@ -1,110 +1,24 @@ |
2 | 2 | <? |
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!) |
9 | 22 | |
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 | | - |
109 | 23 | function userLogout () { |
110 | 24 | global $user , $vpage ; |
111 | 25 | $vpage->title = "User logout" ; |
— | — | @@ -497,56 +411,8 @@ |
498 | 412 | if ( in_array ( "is_sysop" , $user->rights ) ) $ret .= " ($s->user_rights)" ; |
499 | 413 | $ret .= "\n" ; |
500 | 414 | } |
501 | | - |
502 | 415 | |
503 | 416 | 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<<</a> " ; |
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\">>>$after-$fin</a>" ; |
547 | | - $ret .= "</nowiki>" ; |
548 | | - mysql_free_result ( $result ) ; |
549 | | - mysql_close ( $connection ) ; |
550 | | - return $ret ; |
551 | 417 | } |
552 | 418 | |
553 | 419 | function randompage () { |
— | — | @@ -864,22 +730,14 @@ |
865 | 731 | global $removeFile , $xtitle , $removeFile , $Upload , $Upload_name , $no_copyright ; |
866 | 732 | global $user , $vpage ; |
867 | 733 | $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 ) ; |
877 | 735 | $xtitle = "File upload page"; |
878 | 736 | $ret = "<nowiki>" ; |
879 | 737 | |
880 | 738 | $message = "" ; |
881 | 739 | |
882 | 740 | 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>" ; |
884 | 742 | if (is_file("upload/$removeFile") ) unlink ("./upload/$removeFile"); |
885 | 743 | $message = "File <b>$removeFile</b> deleted!" ; |
886 | 744 | unset ( $removeFile ) ; |
— | — | @@ -949,16 +807,16 @@ |
950 | 808 | $i = 0; |
951 | 809 | $ret .= "<table border=1 width=\"100%\">\n"; |
952 | 810 | $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>"; |
955 | 813 | $ret .= "</tr>\n" ; |
956 | 814 | while ($entry = readdir($mydir)) { |
957 | 815 | if ($entry != '.' && $entry != '..') { |
958 | 816 | $ret .= "<tr><td align=center>" ; |
959 | 817 | $ret .= "<a href=upload/$entry>$entry</a></td>"; |
960 | 818 | $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>" ; |
963 | 821 | $ret .= "</tr>" ; |
964 | 822 | $i++; |
965 | 823 | } |
— | — | @@ -1137,7 +995,7 @@ |
1138 | 996 | return "<nowiki>$ret</nowiki>" ; |
1139 | 997 | } |
1140 | 998 | |
1141 | | -# A little hack; disabled; to enable, allow function call in wikiPage->load() |
| 999 | +# A little hack for direct MySQL access; for sysops only! |
1142 | 1000 | function askSQL () { |
1143 | 1001 | global $THESCRIPT ; |
1144 | 1002 | global $Save , $question ; |
Index: trunk/phpwiki/fpw/wiki.phtml |
— | — | @@ -1,19 +1,28 @@ |
2 | 2 | <? |
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 |
9 | 4 | |
| 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 | + |
10 | 15 | # Main program |
11 | 16 | global $action , $title , $pageTitle ; |
12 | 17 | global $user , $search , $expiration ; |
13 | 18 | global $THESCRIPT ; |
14 | 19 | $expiration = time()+315360000 ; # Cookies set will expire in ten years from now |
15 | 20 | $pageTitle = "" ; |
| 21 | + |
| 22 | + # Verifying the current user. Logged in? Password in a cookie? |
16 | 23 | $user = new WikiUser ; |
17 | 24 | $user->scanCookies () ; |
| 25 | + |
| 26 | + # Default settings |
18 | 27 | if ( $action == "" ) $action = "view" ; |
19 | 28 | if ( $title == "" ) $title = "HomePage" ; |
20 | 29 | |
— | — | @@ -25,6 +34,7 @@ |
26 | 35 | $action = strtolower ( trim ( $action ) ) ; |
27 | 36 | $title = urldecode ( $title ) ; |
28 | 37 | |
| 38 | + # Do what is asked |
29 | 39 | if ( isset ( $search ) ) { |
30 | 40 | $out = doSearch () ; |
31 | 41 | unset ( $search ) ; |
— | — | @@ -36,6 +46,7 @@ |
37 | 47 | else if ( $action == "history" ) $out = doHistory ( $title ) ; |
38 | 48 | else $out = error ( "No such action \"$action\"" ) ; |
39 | 49 | |
| 50 | + # Cleaning up, setting <title>, etc. |
40 | 51 | global $bodyOptions , $headerScript ; |
41 | 52 | $pageTitle = "Wikipedia : ".str_replace ( "_" , " " , $pageTitle ) ; |
42 | 53 | $bodyOptions .= $user->options["background"] ; |
— | — | @@ -43,12 +54,13 @@ |
44 | 55 | $head = "<HTML><HEAD><TITLE>$pageTitle</TITLE> $headerScript </HEAD><BODY $bodyOptions>\n" ; |
45 | 56 | $tail = "</BODY></HTML>" ; |
46 | 57 | |
| 58 | + # Adjusting link style |
47 | 59 | $linkStyle = "style=\"color:blue\"" ; |
48 | 60 | if ( $user->options["underlineLinks"] == "no" ) $linkStyle = "style=\"color:blue;text-decoration:none\"" ; |
49 | 61 | if ( $user->options["forceLinks"] != "" ) $linkStyle = $user->options["forceLinks"] ; |
50 | 62 | $out = str_replace ( "<a href=" , "<a $linkStyle href=" , $out ) ; |
51 | 63 | $out = str_replace ( "<a style=\"color:blue\"" , "<a " , $out ) ; # Correcting weird replacement above |
52 | 64 | |
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!!!! |
55 | 67 | ?> |
\ No newline at end of file |
Index: trunk/phpwiki/fpw/wikiPage.php |
— | — | @@ -1,9 +1,14 @@ |
2 | 2 | <? |
| 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 | + |
3 | 6 | 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 |
6 | 9 | |
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) |
8 | 13 | function load ( $t , $doRedirect = true ) { |
9 | 14 | global $action , $user ; |
10 | 15 | $this->knownLinkedLinks = array () ; |
— | — | @@ -12,9 +17,9 @@ |
13 | 18 | $this->makeSecureTitle () ; |
14 | 19 | $this->isSpecialPage = false ; |
15 | 20 | $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 |
19 | 24 | $call = $this->mainTitle ; |
20 | 25 | if ( !in_array ( strtolower ( $call ) , $allowed ) ) { |
21 | 26 | $this->isSpecialPage = true ; |
— | — | @@ -22,15 +27,18 @@ |
23 | 28 | return ; |
24 | 29 | } |
25 | 30 | $this->title = $call ; |
| 31 | + include_once ( "specialPages.php") ; |
26 | 32 | $this->contents = $call () ; |
27 | 33 | $this->isSpecialPage = true ; |
28 | | - return ; |
| 34 | + return ; # contents of special page is returned here!!! |
29 | 35 | } |
| 36 | + |
| 37 | + # No special page, loading article form the database |
30 | 38 | $connection = getDBconnection () ; |
31 | 39 | mysql_select_db ( "wikipedia" , $connection ) ; |
32 | 40 | $thisVersion = "" ; |
33 | 41 | global $oldID , $version , $THESCRIPT ; |
34 | | - if ( isset ( $oldID ) ) { |
| 42 | + if ( isset ( $oldID ) ) { # an old article version |
35 | 43 | $sql = "SELECT * FROM old WHERE old_id=$oldID" ; |
36 | 44 | $result = mysql_query ( $sql , $connection ) ; |
37 | 45 | if ( $s = mysql_fetch_object ( $result ) ) { |
— | — | @@ -40,7 +48,7 @@ |
41 | 49 | $this->thisVersion = "<br><font size=-1>This is the old version #$version; see the <a href=\"$THESCRIPT?title=$this->secureTitle\">current version</a></font>" ; |
42 | 50 | } |
43 | 51 | else $this->contents = "Describe the new page here." ; |
44 | | - } else { |
| 52 | + } else { # The current article version |
45 | 53 | $sql = "SELECT * FROM cur WHERE cur_title=\"".$this->secureTitle."\"" ; |
46 | 54 | $result = mysql_query ( $sql , $connection ) ; |
47 | 55 | if ( $s = mysql_fetch_object ( $result ) ) { |
— | — | @@ -56,7 +64,7 @@ |
57 | 65 | mysql_close ( $connection ) ; |
58 | 66 | $this->makeURL () ; |
59 | 67 | $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 |
61 | 69 | $z = $this->contents ; |
62 | 70 | $z = strstr ( $z , "[[" ) ; |
63 | 71 | $z = str_replace ( "[[" , "" , $z ) ; |
— | — | @@ -64,10 +72,14 @@ |
65 | 73 | $this->load ( trim($z) , false ) ; |
66 | 74 | } |
67 | 75 | } |
| 76 | + |
| 77 | + # This function - well, you know... |
68 | 78 | function special ( $t ) { |
69 | 79 | $this->title = $t ; |
70 | 80 | $this->isSpecialPage = true ; |
71 | 81 | } |
| 82 | + |
| 83 | + # This lists all the subpages of a page (for the QuickBar) |
72 | 84 | function getSubpageList () { |
73 | 85 | $a = array () ; |
74 | 86 | $t = ucfirst ( $this->namespace ) ; |
— | — | @@ -91,6 +103,9 @@ |
92 | 104 | if ( count ( $a ) > 0 ) array_unshift ( $a , "[[$mother]]" ) ; |
93 | 105 | return $a ; |
94 | 106 | } |
| 107 | + |
| 108 | + # This lists all namespaces that contain an article with the same name |
| 109 | + # Called by QuickBar() and getFooter() |
95 | 110 | function getOtherNamespaces () { |
96 | 111 | global $THESCRIPT ; |
97 | 112 | $a = array () ; |
— | — | @@ -121,6 +136,8 @@ |
122 | 137 | mysql_close ( $connection ) ; |
123 | 138 | return $a ; |
124 | 139 | } |
| 140 | + |
| 141 | + # This creates a new article if there is none with the same title yet |
125 | 142 | function ensureExistence () { |
126 | 143 | $this->makeSecureTitle () ; |
127 | 144 | if ( $this->doesTopicExist() ) return ; |
— | — | @@ -130,6 +147,10 @@ |
131 | 148 | $result = mysql_query ( $sql , $connection ) ; |
132 | 149 | mysql_close ( $connection ) ; |
133 | 150 | } |
| 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 |
134 | 155 | function backup () { |
135 | 156 | $id = getMySQL ( "cur" , "cur_id" , "cur_title=\"$this->secureTitle\"" ) ; |
136 | 157 | $oid = getMySQL ( "cur" , "cur_old_version" , "cur_id=$id" ) ; |
— | — | @@ -156,6 +177,9 @@ |
157 | 178 | |
158 | 179 | mysql_close ( $connection ) ; |
159 | 180 | } |
| 181 | + |
| 182 | + # This function stores the passed parameters into the database (the "cur" table) |
| 183 | + # The target data set is defined by $this->secureTitle |
160 | 184 | function setEntry ( $text , $comment , $userID , $userName , $minorEdit ) { |
161 | 185 | $cond = "cur_title=\"$this->secureTitle\"" ; |
162 | 186 | |
— | — | @@ -174,7 +198,9 @@ |
175 | 199 | mysql_close ( $connection ) ; |
176 | 200 | } |
177 | 201 | |
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]]) |
179 | 205 | function replaceInternalLinks ( $s ) { |
180 | 206 | global $THESCRIPT ; |
181 | 207 | global $user , $unlinkedLinks , $linkedLinks ; |
— | — | @@ -185,7 +211,7 @@ |
186 | 212 | $connection = getDBconnection () ; |
187 | 213 | foreach ( $a as $t ) { |
188 | 214 | $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>" ; |
190 | 216 | else { |
191 | 217 | $c = explode ( "|" , $b[0] , 2 ) ; |
192 | 218 | $link = $c[0] ; |
— | — | @@ -224,10 +250,14 @@ |
225 | 251 | mysql_close ( $connection ) ; |
226 | 252 | return $s ; |
227 | 253 | } |
| 254 | + |
| 255 | + # This function replaces wiki-style image links with the HTML code to display them |
228 | 256 | function parseImages ( $s ) { |
229 | 257 | $s = ereg_replace ( "http://([a-zA-Z0-9_/:.]*)\.(png|jpg|jpeg|tif|tiff|gif)" , "<img src=\"http://\\1.\\2\">" , $s ) ; |
230 | 258 | return $s ; |
231 | 259 | } |
| 260 | + |
| 261 | + # This function replaces wiki-style external links (both with and without []) with HTML links |
232 | 262 | function replaceExternalLinks ( $s ) { |
233 | 263 | global $user ; |
234 | 264 | $cnt = 1 ; |
— | — | @@ -261,13 +291,15 @@ |
262 | 292 | |
263 | 293 | return $s ; |
264 | 294 | } |
| 295 | + |
| 296 | + # This function replaces the newly introduced wiki variables with their values (for display only!) |
265 | 297 | function replaceVariables ( $s ) { |
266 | 298 | $var=date("m"); $s = str_replace ( "{{{CURRENTMONTH}}}" , $var , $s ) ; |
267 | 299 | $var=date("F"); $s = str_replace ( "{{{CURRENTMONTHNAME}}}" , $var , $s ) ; |
268 | 300 | $var=date("j"); $s = str_replace ( "{{{CURRENTDAY}}}" , $var , $s ) ; |
269 | 301 | $var=date("l"); $s = str_replace ( "{{{CURRENTDAYNAME}}}" , $var , $s ) ; |
270 | 302 | $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! |
272 | 304 | $connection=getDBconnection() ; |
273 | 305 | mysql_select_db ( "wikipedia" , $connection ) ; |
274 | 306 | $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 @@ |
280 | 312 | } |
281 | 313 | return $s ; |
282 | 314 | } |
| 315 | + |
| 316 | + # This function ensures all occurrences of $f are replaces with $r within $s |
283 | 317 | function replaceAll ( $f , $r , &$s ) { |
284 | 318 | $t = "" ; |
285 | 319 | while ( $s != $t ) { |
— | — | @@ -287,6 +321,8 @@ |
288 | 322 | } |
289 | 323 | return $s ; |
290 | 324 | } |
| 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> |
291 | 327 | function pingPongReplace ( $f , $r1 , $r2 , $s ) { |
292 | 328 | $a = explode ( $f , " ".$s ) ; |
293 | 329 | $s = substr ( array_shift ( $a ) , 1 ) ; |
— | — | @@ -298,24 +334,40 @@ |
299 | 335 | } |
300 | 336 | return $s ; |
301 | 337 | } |
| 338 | + |
| 339 | + # This function organizes the <nowiki> parts and calls subPageContents() for the wiki parts |
302 | 340 | function parseContents ( $s ) { |
303 | 341 | global $linkedLinks , $unlinkedLinks ; |
304 | 342 | $linkedLinks = array () ; |
305 | 343 | $unlinkedLinks = array () ; |
306 | 344 | $s .= "\n" ; |
307 | 345 | $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 ) ; |
309 | 352 | 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 .= "<nowiki>".$x ; |
317 | 358 | } |
| 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 | + |
318 | 368 | return $s ; |
319 | 369 | } |
| 370 | + |
| 371 | + # This function removes "forbidden" HTML tags |
320 | 372 | function removeHTMLtags ( $s ) { |
321 | 373 | $s = eregi_replace ( "<a (.*)>" , "<a \\1>" , $s ) ; |
322 | 374 | $s = eregi_replace ( "</a(.*)>" , "</a\\1>" , $s ) ; |
— | — | @@ -323,19 +375,25 @@ |
324 | 376 | $s = eregi_replace ( "</script(.*)>" , "</script\\1>" , $s ) ; |
325 | 377 | return $s ; |
326 | 378 | } |
| 379 | + |
| 380 | + # This function does the actual parsing of the wiki parts of the article |
327 | 381 | function subParseContents ( $s ) { |
328 | 382 | global $user ; |
329 | | -# Removed autoLink for mixedThings; wasn't working, anyway... |
| 383 | +# Removed automatic links for mixedThings; wasn't working, anyway... |
330 | 384 | # $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 |
332 | 387 | $s = ereg_replace ( "-----*" , "<hr>" , $s ) ; |
333 | 388 | $s = str_replace ( "<HR>" , "<hr>" , $s ) ; |
334 | 389 | $s = $this->replaceVariables ( $s ) ; |
335 | 390 | $s = $this->pingPongReplace ( "'''" , "<b>" , "</b>" , $s ) ; |
336 | 391 | $s = $this->pingPongReplace ( "''" , "<i>" , "</i>" , $s ) ; |
337 | 392 | |
| 393 | + # Automatic links to subpages (e.g., /Talk -> [[/Talk]] |
338 | 394 | $s = ereg_replace ( "([\n| ])/([a-zA-Z0-9_]*)" , "\\1[[/\\2|/\\2]]" , $s ) ; |
339 | 395 | |
| 396 | + # Parsing through the text line by line |
| 397 | + # The main thing happening here is handling of lines starting with * # : etc. |
340 | 398 | $justify = "" ; |
341 | 399 | if ( $user->options["justify"] == "yes" ) $justify = " align=justify" ; |
342 | 400 | $a = explode ( "\n" , $s ) ; |
— | — | @@ -397,20 +455,26 @@ |
398 | 456 | } |
399 | 457 | $s .= "</p>" ; |
400 | 458 | |
| 459 | + # Removing artefact empty paragraphs like <p></p> |
401 | 460 | $this->replaceAll ( "<p$justify>\n</p>" , "<p$justify></p>" , $s ) ; |
402 | 461 | $this->replaceAll ( "<p$justify></p>" , "" , $s ) ; |
403 | 462 | |
| 463 | + # Stuff for the skins |
404 | 464 | if ( $user->options["textTableBackground"] != "" ) { |
405 | 465 | $s = str_replace ( "<table" , "<table".$user->options["textTableBackground"] , $s ) ; |
406 | 466 | } |
407 | 467 | |
| 468 | + # And now, for the final... |
408 | 469 | $s = $this->parseImages ( $s ) ; |
409 | 470 | $s = $this->replaceExternalLinks ( $s ) ; |
410 | 471 | $s = $this->replaceInternalLinks ( $s ) ; |
411 | 472 | return $s ; |
412 | 473 | } |
413 | 474 | |
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() |
415 | 479 | function getLinkBar () { |
416 | 480 | global $THESCRIPT ; |
417 | 481 | global $user , $oldID , $version ; |
— | — | @@ -433,6 +497,8 @@ |
434 | 498 | $ret .= " | <a href=\"$THESCRIPT?title=special:Special_pages\">Special Pages</a>" ; |
435 | 499 | return $ret ; |
436 | 500 | } |
| 501 | + |
| 502 | + # This generates the header with title, user name and functions, wikipedia logo, search box etc. |
437 | 503 | function getHeader () { |
438 | 504 | global $THESCRIPT ; |
439 | 505 | global $user , $action ; |
— | — | @@ -467,6 +533,8 @@ |
468 | 534 | $ret .= "<tr><td valign=bottom>".$this->getLinkBar()."</td></tr></table>" ; |
469 | 535 | return $ret ; |
470 | 536 | } |
| 537 | + |
| 538 | + # This generates the QuickBar (also used by the list of special pages function) |
471 | 539 | function getQuickBar () { |
472 | 540 | global $THESCRIPT ; |
473 | 541 | global $user , $oldID , $version ; |
— | — | @@ -478,6 +546,7 @@ |
479 | 547 | if ( $this->canEdit() ) $column .= "<br><a href=\"$THESCRIPT?action=edit&title=$this->url$editOldVersion\">Edit this page</a>\n" ; |
480 | 548 | |
481 | 549 | if ( $this->canDelete() ) $column .= "<br><a href=\"$THESCRIPT?title=special:deletepage&target=$this->url\">Delete this page</a>\n" ; |
| 550 | +# To be implemented later |
482 | 551 | # if ( $this->canProtect() ) $column .= "<br><a href=\"$THESCRIPT?action=protectpage&title=$this->url\">Protect this page</a>\n" ; |
483 | 552 | # if ( $this->canAdvance() ) $column .= "<br><a href=\"$THESCRIPT?title=special:Advance&topic=$this->safeTitle\">Advance</a>\n" ; |
484 | 553 | |
— | — | @@ -498,6 +567,9 @@ |
499 | 568 | if ( count ( $a ) > 0 ) $column .= "<hr>".implode ( "<br>\n" , $a ) ; |
500 | 569 | return $column."</nowiki>" ; |
501 | 570 | } |
| 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 |
502 | 574 | function getMiddle ( $ret ) { |
503 | 575 | global $user , $action ; |
504 | 576 | $oaction = $action ; |
— | — | @@ -521,6 +593,8 @@ |
522 | 594 | $action = $oaction ; |
523 | 595 | return $ret ; |
524 | 596 | } |
| 597 | + |
| 598 | + # This generates the footer with link bar, search box, etc. |
525 | 599 | function getFooter () { |
526 | 600 | global $THESCRIPT ; |
527 | 601 | $ret = $this->getLinkBar() ; |
— | — | @@ -534,6 +608,9 @@ |
535 | 609 | $ret .= "<FORM>Search: <INPUT TYPE=text NAME=search SIZE=20></FORM>" ; |
536 | 610 | return $ret ; |
537 | 611 | } |
| 612 | + |
| 613 | + # This generates header, diff (if wanted), article body (with QuickBar), and footer |
| 614 | + # The whole page (for normal pages) is generated here |
538 | 615 | function renderPage () { |
539 | 616 | global $pageTitle , $diff ; |
540 | 617 | $pageTitle = $this->title ; |
— | — | @@ -542,6 +619,8 @@ |
543 | 620 | $middle = $this->getMiddle($this->parseContents($middle)) ; |
544 | 621 | return $this->getHeader().$middle.$this->getFooter() ; |
545 | 622 | } |
| 623 | + |
| 624 | + # This displays the diff. Currently, only diff with the last edit! |
546 | 625 | function doDiff () { |
547 | 626 | global $oldID , $version , $user ; |
548 | 627 | $ret = "<nowiki><font color=red><b>BEGIN DIFF</b></font><br>\n" ; |
— | — | @@ -579,8 +658,8 @@ |
580 | 659 | # Output |
581 | 660 | $ret .= "<font color=#2AAA2A>Green text</font> was added or changed, <font color=#AAAA00>yellow text</font> was changed or deleted." ; |
582 | 661 | $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" ; |
585 | 664 | $ret .= "</table>\n" ; |
586 | 665 | } 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" ; |
587 | 666 | 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 @@ |
2 | 2 | <? |
| 3 | +# The wikiUser class handles all user information |
| 4 | + |
3 | 5 | class WikiUser { |
4 | 6 | var $id , $name , $password , $retypePassword ; |
5 | | - var $isLoggedIn ; |
6 | 7 | var $options , $email ; |
7 | 8 | var $rights ; |
| 9 | + var $isLoggedIn ; # Is this user currently logged in? |
8 | 10 | |
| 11 | +#### Skin functions |
| 12 | + |
| 13 | + # Creates the options for the currently selected skin by calling the appropriate function |
9 | 14 | function skin () { |
10 | 15 | if ( $this->options["skin"] == "" ) $this->skinBlank () ; |
11 | 16 | else if ( $this->options["skin"] == "None" ) $this->skinBlank () ; |
12 | 17 | else if ( $this->options["skin"] == "Star Trek" ) $this->skinStarTrek () ; |
13 | 18 | } |
| 19 | + |
| 20 | + # This sets the options for the standard skin |
14 | 21 | function skinBlank () { |
15 | 22 | $this->options["background"] = "" ; |
16 | 23 | $this->options["text"] = "" ; |
— | — | @@ -23,6 +30,8 @@ |
24 | 31 | $this->options["tabLine1"] = "" ; |
25 | 32 | $this->options["tabLine2"] = " bgcolor=#FFFFCC" ; |
26 | 33 | } |
| 34 | + |
| 35 | + # This sets the options for the StarTrek skin |
27 | 36 | function skinStarTrek () { |
28 | 37 | $this->options["background"] = " BGCOLOR=#000000 " ; |
29 | 38 | $this->options["text"] = " TEXT=#00BB00 " ; |
— | — | @@ -36,6 +45,10 @@ |
37 | 46 | $this->options["tabLine1"] = "" ; |
38 | 47 | $this->options["tabLine2"] = " bgcolor=#333333" ; |
39 | 48 | } |
| 49 | + |
| 50 | +#### Management functions |
| 51 | + |
| 52 | + # This checks the cookies for prior log-ins |
40 | 53 | function scanCookies () { |
41 | 54 | global $WikiUserID , $WikiUserPassword , $WikiLoggedIn ; |
42 | 55 | $this->id = 0 ; |
— | — | @@ -62,8 +75,10 @@ |
63 | 76 | $this->ensureDefaultOptions () ; |
64 | 77 | $this->skin () ; |
65 | 78 | } |
| 79 | + |
| 80 | + # This sets the default options for new and no-log-in users |
66 | 81 | function ensureDefaultOptions () { |
67 | | - if ( $this->options["quickBar"] == "" ) $this->options["quickBar"] = "none" ; |
| 82 | + if ( $this->options["quickBar"] == "" ) $this->options["quickBar"] = "right" ; # For demonstration |
68 | 83 | if ( $this->options["markupNewTopics"] == "" ) $this->options["markupNewTopics"] = "normal" ; |
69 | 84 | if ( $this->options["underlineLinks"] == "" ) $this->options["underlineLinks"] = "yes" ; |
70 | 85 | if ( $this->options["showHover"] == "" ) $this->options["showHover"] = "yes" ; |
— | — | @@ -75,7 +90,10 @@ |
76 | 91 | if ( $this->options["resultsPerPage"] == "" ) $this->options["resultsPerPage"] = "20" ; |
77 | 92 | if ( $this->options["skin"] == "" ) $this->options["skin"] = "None" ; |
78 | 93 | } |
| 94 | + |
| 95 | + # Loads the user settings from the database |
79 | 96 | function loadSettings () { |
| 97 | + $this->rights = array () ; |
80 | 98 | if ( !$this->isLoggedIn ) return ; |
81 | 99 | $t = getMySQL ( "user" , "user_options" , "user_id=".$this->id ) ; |
82 | 100 | $t = urldecode ( $t ) ; |
— | — | @@ -91,6 +109,8 @@ |
92 | 110 | $this->email = getMySQL ( "user" , "user_email" , "user_id=".$this->id ) ; |
93 | 111 | $this->skin () ; |
94 | 112 | } |
| 113 | + |
| 114 | + # Saves/updates the user settings in the database |
95 | 115 | function saveSettings () { |
96 | 116 | global $expiration ; |
97 | 117 | if ( !$this->isLoggedIn ) return ; |
— | — | @@ -107,11 +127,12 @@ |
108 | 128 | setMySQL ( "user" , "user_email" , $this->email , "user_id=".$this->id ) ; |
109 | 129 | if ( $this->options["rememberPassword"] == "on" ) setcookie ( "WikiUserPassword" , $this->password , $expiration ) ; |
110 | 130 | } |
| 131 | + |
| 132 | + # Creates a link to the user home page, or returns the IP |
111 | 133 | function getLink () { |
112 | 134 | global $REMOTE_ADDR ; |
113 | 135 | if ( $this->isLoggedIn ) { |
114 | 136 | $s = new WikiPage ; |
115 | | -# $s->setTitle ( "user:$this->name" ) ; |
116 | 137 | $s = $s->parseContents ( "[[user:$this->name|$this->name]]" ) ; |
117 | 138 | $s = substr ( strstr ( $s , ">" ) , 1 ) ; |
118 | 139 | $s = str_replace ( "</p>" , "" , $s ) ; |
— | — | @@ -122,6 +143,8 @@ |
123 | 144 | $s = $s[0].".".$s[1].".".$s[2].".xxx" ; |
124 | 145 | return $s ; |
125 | 146 | } |
| 147 | + |
| 148 | + # Checks if a user with that name exists |
126 | 149 | function doesUserExist () { |
127 | 150 | $s = trim ( $this->name ) ; |
128 | 151 | if ( $s == "" ) return false ; |
— | — | @@ -139,6 +162,8 @@ |
140 | 163 | if ( $s == "" ) return false ; |
141 | 164 | return true ; |
142 | 165 | } |
| 166 | + |
| 167 | + # Adds a new user to the database |
143 | 168 | function addToDatabase () { |
144 | 169 | $connection = getDBconnection () ; |
145 | 170 | mysql_select_db ( "wikipedia" , $connection ) ; |
— | — | @@ -146,6 +171,8 @@ |
147 | 172 | $result = mysql_query ( $sql , $connection ) ; |
148 | 173 | mysql_close ( $connection ) ; |
149 | 174 | } |
| 175 | + |
| 176 | + # Checks the login |
150 | 177 | function verify () { |
151 | 178 | $this->isLoggedIn = false ; |
152 | 179 | if ( !$this->doesUserExist() ) return "<font color=red>Unknown user \"$this->name\"!</font>" ; |
— | — | @@ -174,6 +201,8 @@ |
175 | 202 | |
176 | 203 | return $ret ; |
177 | 204 | } |
| 205 | + |
| 206 | + # Toggles the watch on an article for this user |
178 | 207 | function doWatch ( $t ) { |
179 | 208 | $a = getMySQL ( "user" , "user_watch" , "user_id=$this->id" ) ; |
180 | 209 | $b = explode ( "'" , $a ) ; |
Index: trunk/phpwiki/fpw/wikiTitle.php |
— | — | @@ -1,10 +1,14 @@ |
2 | 2 | <? |
| 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 | + |
3 | 6 | class WikiTitle { |
4 | 7 | var $title , $secureTitle , $url , $isSpecialPage , $thisVersion ; |
5 | 8 | var $namespace , $mainTitle , $subpageTitle , $hasNamespace ; |
6 | 9 | |
7 | | - # Functions |
8 | | - # User rights |
| 10 | +##### Functions |
| 11 | +####### # User rights |
| 12 | + # Can the current user delete this page? |
9 | 13 | function canEdit () { |
10 | 14 | global $action ; |
11 | 15 | # global $oldID ; if ( isset ( $oldID ) ) return false ; |
— | — | @@ -18,6 +22,8 @@ |
19 | 23 | |
20 | 24 | return true ; |
21 | 25 | } |
| 26 | + |
| 27 | + # Can the current user delete this page? |
22 | 28 | function canDelete () { |
23 | 29 | global $action , $user ; |
24 | 30 | global $oldID ; if ( isset ( $oldID ) ) return false ; |
— | — | @@ -27,6 +33,8 @@ |
28 | 34 | if ( in_array ( "is_sysop" , $user->rights ) ) return true ; |
29 | 35 | return false ; |
30 | 36 | } |
| 37 | + |
| 38 | + # Can the current user protect this page? (NOT USED YET) |
31 | 39 | function canProtect () { |
32 | 40 | global $action , $user ; |
33 | 41 | global $oldID ; if ( isset ( $oldID ) ) return false ; |
— | — | @@ -36,6 +44,8 @@ |
37 | 45 | if ( in_array ( "is_sysop" , $user->rights ) ) return true ; |
38 | 46 | return false ; |
39 | 47 | } |
| 48 | + |
| 49 | + # Can the current user advance this page? (NOT USED YET) |
40 | 50 | function canAdvance () { |
41 | 51 | global $action , $user ; |
42 | 52 | global $oldID ; if ( isset ( $oldID ) ) return false ; |
— | — | @@ -46,7 +56,9 @@ |
47 | 57 | return false ; |
48 | 58 | } |
49 | 59 | |
50 | | - # Title functions |
| 60 | +#### Title functions |
| 61 | + |
| 62 | + # Generates a "secure" title |
51 | 63 | function makeSecureTitle () { |
52 | 64 | $this->splitTitle () ; |
53 | 65 | $s = ucfirst ( trim ( $this->namespace ) ) ; |
— | — | @@ -58,14 +70,17 @@ |
59 | 71 | $s = str_replace ( "\\'" , "'" , $s ) ; |
60 | 72 | |
61 | 73 | # Make it compatible with old wiki |
62 | | -# $s = str_replace ( "'" , "" , $s ) ; |
63 | 74 | $s = str_replace ( " " , "_" , $s ) ; |
64 | 75 | |
65 | 76 | $this->secureTitle = $s ; |
66 | 77 | } |
| 78 | + |
| 79 | + # Converts the secure title to an even more secure one (URL-style) |
67 | 80 | function makeURL () { |
68 | 81 | $this->url = urlencode ( $this->secureTitle ) ; |
69 | 82 | } |
| 83 | + |
| 84 | + # Converts a secure title back to a nice-looking one |
70 | 85 | function getNiceTitle ( $s ) { |
71 | 86 | if ( !isset ( $s ) ) $s = $this->secureTitle ; |
72 | 87 | $s = str_replace ( "_" , " " , $s ) ; |
— | — | @@ -73,6 +88,8 @@ |
74 | 89 | $s = str_replace ( "\\\\" , "\\" , $s ) ; |
75 | 90 | return ucfirst ( $s ) ; |
76 | 91 | } |
| 92 | + |
| 93 | + # Takes apart a title by namespace, subpage... |
77 | 94 | function splitTitle () { |
78 | 95 | $a = explode ( ":" , $this->title , 2 ) ; |
79 | 96 | if ( count ( $a ) == 1 ) { |
— | — | @@ -90,6 +107,8 @@ |
91 | 108 | else $this->subpageTitle = $a[1] ; |
92 | 109 | $this->namespace = strtolower ( $this->namespace ) ; |
93 | 110 | } |
| 111 | + |
| 112 | + # I don't remember what this does, or if I use it somewhere... |
94 | 113 | function getLinkTo ( $target ) { |
95 | 114 | $n = $this->namespace ; |
96 | 115 | if ( $target->hasNamespace ) $n = $target->namespace ; |
— | — | @@ -100,14 +119,20 @@ |
101 | 120 | if ( $target->subpageTitle != "" ) $ret .= "/".$target->subpageTitle ; |
102 | 121 | return $ret ; |
103 | 122 | } |
| 123 | + |
| 124 | + # These are pretty straight-forward |
104 | 125 | function makeAll () { $this->makeSecureTitle(); $this->makeURL(); } |
105 | 126 | function setTitle ( $t ) { $this->title = $t ; $this->makeAll() ; } |
| 127 | + |
| 128 | + # OUTDATED!!! BUT LEAVE IT!! |
106 | 129 | function getMainTitle () { |
107 | 130 | $r = $this->title ; |
108 | 131 | # if ( strstr ( $r , ":" ) == false and $this->hasNamespace and $this->namespace != "" ) $r = $this->namespace.":$r" ; |
109 | 132 | # if ( $this->subpageTitle != "" ) $r .= "/".$this->subpageTitle ; |
110 | 133 | return $r ; |
111 | 134 | } |
| 135 | + |
| 136 | + # Checks the database if this topic already exists |
112 | 137 | function doesTopicExist ( $conn = "" ) { |
113 | 138 | $this->makeSecureTitle () ; |
114 | 139 | if ( $this->namespace == "special" ) return true ; |
— | — | @@ -124,6 +149,8 @@ |
125 | 150 | } |
126 | 151 | return false ; |
127 | 152 | } |
| 153 | + |
| 154 | + # Checks for one namespace and one subpage level max. |
128 | 155 | function validateTitle () { |
129 | 156 | $this->makeSecureTitle () ; |
130 | 157 | if ( $this->mainTitle == "" ) return false ; |