r28 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r27‎ | r28 | r29 >
Date:13:26, 19 October 2001
Author:magnus_manske
Status:old
Tags:
Comment:
*** empty log message ***
Modified paths:
  • /trunk/phpwiki/fpw/basicFunctions.php (added) (history)
  • /trunk/phpwiki/fpw/specialPages.php (modified) (history)
  • /trunk/phpwiki/fpw/wiki.phtml (modified) (history)
  • /trunk/phpwiki/fpw/wikiPage.php (modified) (history)

Diff [purge]

Index: trunk/phpwiki/fpw/basicFunctions.php
@@ -0,0 +1,108 @@
 2+<?
 3+# Output error message. Rarely used.
 4+function error ( $error ) {
 5+ $page = new WikiPage ;
 6+ $page->special ( "Yikes! An error!" ) ;
 7+ $page->contents = "<h2>$error!</h2>Return to the [[:HomePage|HomePage]]!" ;
 8+ return $page->renderPage () ;
 9+ }
 10+
 11+# Called when editing/saving a page
 12+function edit ( $title ) {
 13+ global $EditBox , $SaveButton , $PreviewButton , $MinorEdit ;
 14+ global $user , $CommentBox , $vpage , $EditTime ;
 15+ $npage = new WikiPage ;
 16+ $npage->title = $title ;
 17+ $npage->makeAll () ;
 18+ $ret = "" ;
 19+ if ( !$vpage->canEdit() ) return "<h3>You cannot edit this page!</h3>" ; # Check for allowance
 20+
 21+ if ( $EditTime == "" ) $EditTime = date ( "YmdHis" ) ; # Stored for edit conflict detection
 22+
 23+ if ( isset ( $SaveButton ) ) { # The edit is finished, someone pressed the "Save" button
 24+ unset ( $SaveButton ) ;
 25+ if ( $vpage->doesTopicExist() ) {
 26+ $lastTime = getMySQL ( "cur" , "cur_timestamp" , "cur_title=\"$vpage->secureTitle\"" ) ;
 27+ if ( tsc($EditTime) < tsc($lastTime) ) return "<h1>While you were typing, someone saved another version of this article!</h1>" ;
 28+ }
 29+ $text = $EditBox ;
 30+ $text = str_replace ( "\\'" , "'" , $text ) ;
 31+ $text = str_replace ( "\\\"" , "\"" , $text ) ;
 32+ if ( $user->isLoggedIn ) $text = str_replace ( "~~~" , "[[user:$user->name|$user->name]]" , $text ) ;
 33+ else $text = str_replace ( "~~~" , $user->getLink() , $text ) ;
 34+ $title = str_replace ( "\\'" , "'" , $title ) ;
 35+ $title = str_replace ( "\\\"" , "\"" , $title ) ;
 36+ $npage->title = $title ;
 37+ $npage->makeAll () ;
 38+ if ( $npage->doesTopicExist() ) $npage->backup() ;
 39+ else { $MinorEdit = 2 ; $npage->ensureExistence () ; }
 40+ if ( !$user->isLoggedIn ) $npage->setEntry ( $text , $CommentBox , 0 , $user->getLink() , $MinorEdit*1 ) ;
 41+ else $npage->setEntry ( $text , $CommentBox , $user->id , $user->name , $MinorEdit*1 ) ;
 42+ global $wasSaved ;
 43+ $wasSaved = true ;
 44+ return "" ;
 45+ } else if ( isset ( $PreviewButton ) ) { # Generating a preview to append to the page
 46+ unset ( $PreviewButton ) ;
 47+ $text = $EditBox ;
 48+ $text = str_replace ( "\\'" , "'" , $text ) ;
 49+ $text = str_replace ( "\\\"" , "\"" , $text ) ;
 50+ $append = "<hr>\n<h2>Preview :</h2>\n".$npage->parseContents($text)."<hr><h3>Remember, this is only a preview and not yet saved!</h3>" ;
 51+ } else if ( $npage->doesTopicExist() ) { # The initial edit request for an existing page
 52+ $npage->load ( $npage->title ) ;
 53+ $text = $npage->contents ;
 54+ } else { # The initial edit request for a new page
 55+ $text = "Describe the new page here." ;
 56+ }
 57+
 58+ if ( $MinorEdit ) $checked = "checked" ;
 59+ else $checked = "" ;
 60+ if ( $CommentBox == "" ) $CommentBox = "*" ;
 61+
 62+
 63+ # Just trying to set the initial keyboard focus to the edit window; doesn't work, though...
 64+ global $bodyOptions , $headerScript ;
 65+ $headerScript = "<script> <!-- function setfocus() { document.f.EditBox.focus(); } --> </script>" ;
 66+ $bodyOptions = " onLoad=setfocus()" ;
 67+
 68+ $ret .= "<form method=POST name=f>" ;
 69+ $ret .= "<textarea tabindex=1 name=EditBox rows=".$user->options["rows"]." cols=".$user->options["cols"]." STYLE=\"width:100%\" WRAP=virtual>$text</textarea><br>\n" ;
 70+ $ret .= "Summary:<input tabindex=2 type=text value=\"$CommentBox\" name=CommentBox size=50 maxlength=200> \n" ;
 71+ $ret .= "<input tabindex=3 type=checkbox name=MinorEdit $checked value=1>This is a minor edit \n" ;
 72+ $ret .= "<input tabindex=4 type=submit value=Save name=SaveButton> \n" ;
 73+ $ret .= "<input tabindex=5 type=submit value=Preview name=PreviewButton>\n" ;
 74+ $ret .= "<input type=hidden value=\"$EditTime\" name=EditTime>\n" ;
 75+ $ret .= "</form>" ;
 76+
 77+ return $ret.$append ;
 78+ }
 79+
 80+function doEdit ( $title ) {
 81+ global $THESCRIPT ;
 82+ global $vpage , $action , $wasSaved ;
 83+ $wasSaved = false ;
 84+ $vpage = new WikiPage ;
 85+ $vpage->isSpecialPage = true ;
 86+ $vpage->title = $title ;
 87+ $vpage->makeSecureTitle () ;
 88+ $action = "" ;
 89+ $ret = $vpage->getHeader() ;
 90+ $action = "edit" ;
 91+
 92+ $theMiddle = edit ( $title ) ;
 93+ if ( $wasSaved )
 94+ $theMiddle = "<h1>Your page was successfully saved!</h1><META HTTP-EQUIV=Refresh CONTENT=\"0; URL=$THESCRIPT?title=$vpage->secureTitle\">" ;
 95+ $ret .= $vpage->getMiddle ( $theMiddle ) ;
 96+
 97+ $action = "" ;
 98+ $ret .= $vpage->getFooter() ;
 99+ $action = "edit" ;
 100+ return $ret ;
 101+ }
 102+
 103+function view ( $title ) {
 104+ global $vpage ;
 105+ $vpage = new WikiPage ;
 106+ $vpage->load ( $title ) ;
 107+ return $vpage->renderPage () ;
 108+ }
 109+?>
\ No newline at end of file
Property changes on: trunk/phpwiki/fpw/basicFunctions.php
___________________________________________________________________
Name: svn:eol-style
1110 + native
Name: svn:keywords
2111 + Author Date Id Revision
Index: trunk/phpwiki/fpw/specialPages.php
@@ -494,6 +494,79 @@
495495 return $ret ;
496496 }
497497
 498+function newPages_timeSort ( $a , $b ) { # This belongs to newpages alone!
 499+ $a = $a->cur_timestamp ;
 500+ $b = $b->cur_timestamp ;
 501+ if ($a == $b) return 0;
 502+ return ($a < $b) ? -1 : 1;
 503+ }
 504+
 505+function newpages () {
 506+ global $THESCRIPT ;
 507+ global $vpage , $maxcnt , $daysAgo ;
 508+ $vpage->special ( "New pages" ) ;
 509+ $vpage->makeSecureTitle() ;
 510+ if ( !isset ( $maxcnt ) ) $maxcnt = 100 ;
 511+ if ( !isset ( $daysAgo ) ) $daysAgo = 3 ;
 512+
 513+ $ret = "<nowiki>" ;
 514+ $ret .= "These are the last <b>$maxcnt</b> new pages on Wikipedia in the last <b>$daysAgo</b> days.<br>\n" ;
 515+ $ret .= "View the last " ;
 516+ $ret .= "<a href=\"$THESCRIPT?title=special:NewPages&daysAgo=$daysAgo&maxcnt=50\">50</a> | " ;
 517+ $ret .= "<a href=\"$THESCRIPT?title=special:NewPages&daysAgo=$daysAgo&maxcnt=100\">100</a> | " ;
 518+ $ret .= "<a href=\"$THESCRIPT?title=special:NewPages&daysAgo=$daysAgo&maxcnt=250\">250</a> | " ;
 519+ $ret .= "<a href=\"$THESCRIPT?title=special:NewPages&daysAgo=$daysAgo&maxcnt=500\">500</a> | " ;
 520+ $ret .= "<a href=\"$THESCRIPT?title=special:NewPages&daysAgo=$daysAgo&maxcnt=1000\">1000</a> | " ;
 521+ $ret .= "<a href=\"$THESCRIPT?title=special:NewPages&daysAgo=$daysAgo&maxcnt=2500\">2500</a> | " ;
 522+ $ret .= "<a href=\"$THESCRIPT?title=special:NewPages&daysAgo=$daysAgo&maxcnt=5000\">5000</a> " ;
 523+ $ret .= "new pages.<br>\n" ;
 524+ $ret .= "View the last " ;
 525+ $ret .= "<a href=\"$THESCRIPT?title=special:NewPages&maxcnt=$maxcnt&daysAgo=1\">1 day</a> | " ;
 526+ $ret .= "<a href=\"$THESCRIPT?title=special:NewPages&maxcnt=$maxcnt&daysAgo=2\">2 days</a> | " ;
 527+ $ret .= "<a href=\"$THESCRIPT?title=special:NewPages&maxcnt=$maxcnt&daysAgo=3\">3 days</a> | " ;
 528+ $ret .= "<a href=\"$THESCRIPT?title=special:NewPages&maxcnt=$maxcnt&daysAgo=5\">5 days</a> | " ;
 529+ $ret .= "<a href=\"$THESCRIPT?title=special:NewPages&maxcnt=$maxcnt&daysAgo=7\">7 days</a> | " ;
 530+ $ret .= "<a href=\"$THESCRIPT?title=special:NewPages&maxcnt=$maxcnt&daysAgo=14\">14 days</a><br>\n" ;
 531+ $ret .= "</nowiki>" ;
 532+ $arr = array () ;
 533+
 534+ $mindate = date ( "Ymd000000" , time () - $daysAgo*24*60*60 ) ;
 535+ $connection=getDBconnection() ;
 536+ mysql_select_db ( "wikipedia" , $connection ) ;
 537+
 538+ # Looking at the "cur" table
 539+ $sql = "SELECT cur_title FROM cur WHERE cur_minor_edit=2 AND cur_timestamp>$mindate ORDER BY cur_timestamp DESC LIMIT $maxcnt" ;
 540+ $result = mysql_query ( $sql , $connection ) ;
 541+ while ( $s = mysql_fetch_object ( $result ) ) $names[$s->cur_title] = 1 ;
 542+ mysql_free_result ( $result ) ;
 543+
 544+ # Looking at the "old" table
 545+ $arrB = array () ;
 546+ $sql = "SELECT old_title FROM old WHERE old_minor_edit=2 AND old_timestamp>$mindate ORDER BY old_timestamp DESC LIMIT $maxcnt" ;
 547+ $result = mysql_query ( $sql , $connection ) ;
 548+ while ( $s = mysql_fetch_object ( $result ) ) $names[$s->old_title] = 1 ;
 549+ mysql_free_result ( $result ) ;
 550+
 551+ # Merging things
 552+ $k = array_keys ( $names ) ;
 553+ $arr = array () ;
 554+ foreach ( $k as $x ) {
 555+ $sql = "SELECT cur_timestamp,cur_title,cur_comment,cur_user,cur_user_text,cur_minor_edit FROM cur WHERE cur_title=\"$x\"" ;
 556+ $result = mysql_query ( $sql , $connection ) ;
 557+ if ( $s = mysql_fetch_object ( $result ) ) {
 558+ array_push ( $arr , $s ) ;
 559+ mysql_free_result ( $result ) ;
 560+ }
 561+ }
 562+ mysql_close ( $connection ) ;
 563+
 564+ uasort ( $arr , "newPages_timeSort" ) ;
 565+ while ( count ( $arr ) > $maxcnt ) array_pop ( $arr ) ;
 566+
 567+ $ret .= recentChangesLayout($arr) ;
 568+ return $ret ;
 569+ }
 570+
498571 function recentChangesLayout ( &$arr ) {
499572 global $THESCRIPT ;
500573 global $user ;
Index: trunk/phpwiki/fpw/wiki.phtml
@@ -5,7 +5,7 @@
66
77 # Includes the necessary parts
88 #include_once ( "./specialPages.php" ) ;
9 -include_once ( "basicFunctions.php" ) ;
 9+include_once ( "./basicFunctions.php" ) ;
1010 include_once ( "./databaseFunctions.php" ) ;
1111 include_once ( "./wikiTitle.php" ) ;
1212 include_once ( "./wikiPage.php" ) ;
@@ -43,8 +43,10 @@
4444 $out = watch ( $title , $mode ) ;
4545 } else if ( $action == "view" ) $out = view ( $title ) ;
4646 else if ( $action == "edit" ) $out = doEdit ( $title ) ;
47 - else if ( $action == "history" ) $out = doHistory ( $title ) ;
48 - else $out = error ( "No such action \"$action\"" ) ;
 47+ else if ( $action == "history" ) {
 48+ include_once ( "./specialPages.php" ) ;
 49+ $out = doHistory ( $title ) ;
 50+ } else $out = error ( "No such action \"$action\"" ) ;
4951
5052 # Cleaning up, setting <title>, etc.
5153 global $bodyOptions , $headerScript ;
Index: trunk/phpwiki/fpw/wikiPage.php
@@ -18,7 +18,7 @@
1919 $this->isSpecialPage = false ;
2020 $this->revision = "current" ;
2121 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
 22+ $allowed = array("userlogin","userlogout","newpages","recentchanges","upload","statistics","lonelypages","wantedpages","allpages","randompage","shortpages","listusers","watchlist","special_pages","editusersettings","deletepage"); # List of allowed special pages
2323 if ( in_array ( "is_sysop" , $user->rights ) ) array_push ( $allowed , "asksql" ) ; # Another function just for sysops
2424 $call = $this->mainTitle ;
2525 if ( !in_array ( strtolower ( $call ) , $allowed ) ) {
@@ -27,7 +27,7 @@
2828 return ;
2929 }
3030 $this->title = $call ;
31 - include_once ( "specialPages.php") ;
 31+ include_once ( "./specialPages.php") ;
3232 $this->contents = $call () ;
3333 $this->isSpecialPage = true ;
3434 return ; # contents of special page is returned here!!!
@@ -554,6 +554,7 @@
555555 $column .= "<br><a href=\"$THESCRIPT?title=special:Upload\">Upload files</a>\n" ;
556556 $column .= "<hr>" ;
557557 $column .= "<a href=\"$THESCRIPT?title=special:Statistics\">Statistics</a>" ;
 558+ $column .= "<br>\n<a href=\"$THESCRIPT?title=special:NewPages\">New pages</a>" ;
558559 $column .= "<br>\n<a href=\"$THESCRIPT?title=special:LonelyPages\">Orphans</a>" ;
559560 $column .= "<br>\n<a href=\"$THESCRIPT?title=special:WantedPages\">Most wanted</a>" ;
560561 $column .= "<br>\n<a href=\"$THESCRIPT?title=special:AllPages\">All pages</a>" ;

Follow-up revisions

RevisionCommit summaryAuthorDate
r55510Add a Makefile and a copy of the cssjanus script so folks can update the RTL ...brion22:44, 22 August 2009

Status & tagging log