r20 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r19‎ | r20 | r21 >
Date:18:39, 4 October 2001
Author:magnus_manske
Status:old
Tags:
Comment:
more fixes
Modified paths:
  • /trunk/phpwiki/fpw/specialPages.php (modified) (history)
  • /trunk/phpwiki/fpw/wikiPage.php (modified) (history)
  • /trunk/phpwiki/fpw/wikiTitle.php (modified) (history)

Diff [purge]

Index: trunk/phpwiki/fpw/specialPages.php
@@ -325,7 +325,7 @@
326326
327327 function LonelyPages () {
328328 global $linkedLinks , $unlinkedLinks , $vpage ;
329 - $vpage->special ( "The Lonely Pages" ) ;
 329+ $vpage->special ( "The Orphans" ) ;
330330 $vpage->namespace = "" ;
331331 $allPages = array () ;
332332 $linkedLinks = array () ;
@@ -553,28 +553,30 @@
554554 }
555555
556556 function recentchanges () {
557 - global $vpage , $maxcnt , $PHP_SELF , $SERVER_NAME ;
 557+ global $vpage , $maxcnt ;
558558 $vpage->special ( "Recent Changes" ) ;
559559 $vpage->makeSecureTitle() ;
560560 if ( !isset ( $maxcnt ) ) $maxcnt = 100 ;
 561+ $daysAgo = 3 ;
561562
562 - $ret = "" ;
563 - $ret .= "<b>These are the last $maxcnt changes made on [[Wikipedia]].</b> View the last " ;
564 - $ret .= "[http://$SERVER_NAME$PHP_SELF?title=special:RecentChanges&maxcnt=50 50] / " ;
565 - $ret .= "[http://$SERVER_NAME$PHP_SELF?title=special:RecentChanges&maxcnt=100 100] / " ;
566 - $ret .= "[http://$SERVER_NAME$PHP_SELF?title=special:RecentChanges&maxcnt=250 250] / " ;
567 - $ret .= "[http://$SERVER_NAME$PHP_SELF?title=special:RecentChanges&maxcnt=500 500] " ;
568 - $ret .= "changes." ;
 563+ $ret = "<nowiki>" ;
 564+ $ret .= "These are the last <b>$maxcnt</b> of the changes made on Wikipedia in the last $daysAgo days. View the last " ;
 565+ $ret .= "<a href=\"$PHP_SELF?title=special:RecentChanges&maxcnt=50\">50</a> / " ;
 566+ $ret .= "<a href=\"$PHP_SELF?title=special:RecentChanges&maxcnt=100\">100</a> / " ;
 567+ $ret .= "<a href=\"$PHP_SELF?title=special:RecentChanges&maxcnt=250\">250</a> / " ;
 568+ $ret .= "<a href=\"$PHP_SELF?title=special:RecentChanges&maxcnt=500\">500</a> " ;
 569+ $ret .= "changes.<br></nowiki>" ;
569570 $arr = array () ;
570571
 572+ $mindate = date ( "Ymd000000" , time () - $daysAgo*24*60*60 ) ;
571573 $connection=getDBconnection() ;
572574 mysql_select_db ( "wikipedia" , $connection ) ;
573 - $sql = "SELECT * FROM cur ORDER BY cur_timestamp DESC LIMIT $maxcnt" ;
 575+ $sql = "SELECT cur_timestamp,cur_title,cur_comment,cur_user,cur_user_text,cur_minor_edit FROM cur WHERE cur_timestamp>$mindate ORDER BY cur_timestamp DESC LIMIT $maxcnt" ;
574576 $result = mysql_query ( $sql , $connection ) ;
575577 while ( $s = mysql_fetch_object ( $result ) ) array_push ( $arr , $s ) ;
576578 mysql_free_result ( $result ) ;
577579 mysql_close ( $connection ) ;
578 - $ret .= recentChangesLayout ( $arr ) ;
 580+ $ret .= recentChangesLayout($arr) ;
579581 return $ret ;
580582 }
581583
@@ -585,7 +587,7 @@
586588 $color2 = $user->options["tabLine2"] ;
587589 $xyz = new WikiTitle ;
588590 $editTypes = array ( "0"=>"" , "1"=>"<font color=green>M</font>" , "2"=>"<font color=red>N</font>" ) ;
589 - $ret = " ('''Legend :''' ".$editTypes["1"]."=Minor edit ; ".$editTypes["2"]."=New article.)" ;
 591+ $ret = " (<b>Legend :</b> ".$editTypes["1"]."=Minor edit ; ".$editTypes["2"]."=New article.)" ;
590592 $ret .= "<table width=100% border=0 cellpadding=2 cellspacing=0>\n" ;
591593 $dummy = "$PHP_SELF?x=y" ;
592594 foreach ( $arr as $s ) {
@@ -598,7 +600,11 @@
599601 $color = $color1 ;
600602 }
601603 $u = $s->cur_user_text ;
602 - if ( $s->cur_user != 0 ) $u = "[[user:$u|$u]]" ;
 604+ if ( $s->cur_user != 0 ) {
 605+ $xyz->title = $u ;
 606+ $xyz->makeSecureTitle () ;
 607+ $u = "<a href=\"$PHP_SELF?title=user:$xyz->secureTitle\">$u</a>" ;
 608+ }
603609 $comment = trim($s->cur_comment) ;
604610 if ( $comment == "*" ) $comment = "" ;
605611 if ( $s->cur_minor_edit == 1 ) $comment = "<font size=-1><i>$comment</i></font>" ;
@@ -606,12 +612,13 @@
607613 $minor = $editTypes[$s->cur_minor_edit] ;
608614
609615 $t = "<tr><td$color valign=top width=0%>" ;
610 - if ( $s->version == "current" ) $t .= "<a href=\"$PHP_SELF?$s->cur_title&diff=yes\">(diff)</a>&nbsp;" ;
611 - else if ( $s->version != "" ) $t .= "<a href=\"$PHP_SELF?$s->cur_title&oldID=$s->old_id&version=$s->version&diff=yes\">(diff)</a>&nbsp;" ;
 616+ if ( $s->version == "current" ) $t .= "<a href=\"$PHP_SELF?title=$s->cur_title&diff=yes\">(diff)</a>&nbsp;" ;
 617+ else if ( $s->version != "" ) $t .= "<a href=\"$PHP_SELF?title=$s->cur_title&oldID=$s->old_id&version=$s->version&diff=yes\">(diff)</a>&nbsp;" ;
 618+ else $t .= "<a href=\"$PHP_SELF?title=$s->cur_title&diff=yes\">(diff)</a>" ;
612619 $t .= "</td><td$color valign=top>" ;
613620 if ( $s->version == "current" ) $t .= "<a href=\"$PHP_SELF?$s->cur_title\">$nt</a></td>" ;
614621 else if ( $s->version != "" ) $t .= "<a href=\"$PHP_SELF?$s->cur_title&oldID=$s->old_id&version=$s->version\">$nt ($s->version)</a></td>" ;
615 - else $t .= "[[$s->cur_title|$nt]]</td>" ;
 622+ else $t .= "<a href=\"$PHP_SELF?title=$s->cur_title\">$nt</a>" ;
616623 $t .= "<td$color valign=top width=0% nowrap>$time</td>" ;
617624 if ( $s->version != "" ) {
618625 $v = new wikiTitle ;
@@ -628,7 +635,7 @@
629636 else $color = $color1 ;
630637 }
631638 $ret .= "</table>" ;
632 - return $ret ;
 639+ return "<nowiki>$ret</nowiki>" ;
633640 }
634641
635642 function modifyArray ( $a , $sep , $rem , $add = "" ) {
Index: trunk/phpwiki/fpw/wikiPage.php
@@ -99,11 +99,12 @@
100100 $s = mysql_fetch_object ( $result ) ;
101101 mysql_free_result ( $result ) ;
102102
 103+ $s->cur_text = str_replace ( "\"" , "\\\"" , $s->cur_text ) ;
103104 $sql = "INSERT INTO old (old_title,old_old_version,old_text,old_comment,old_user,old_user_text,old_minor_edit)";
104 - $sql .= " VALUES (\"$this->secureTitle\",$oid,\"$s->cur_text\",\"$s->cur_comment\",$s->cur_user,\"$s->cur_user_text\",$s->cur_minor_edit)" ;
 105+ $sql .= " VALUES (\"$this->secureTitle\",\"$oid\",\"".$s->cur_text."\",\"".$s->cur_comment."\",\"$s->cur_user\",\"$s->cur_user_text\",$s->cur_minor_edit)" ;
105106 mysql_query ( $sql , $connection ) ;
106107
107 - $sql = "SELECT old_id FROM old WHERE old_old_version=$oid AND old_title=\"$this->secureTitle\"" ;
 108+ $sql = "SELECT old_id FROM old WHERE old_old_version=\"$oid\" AND old_title=\"$this->secureTitle\"" ;
108109 $result = mysql_query ( $sql , $connection ) ;
109110 $s = mysql_fetch_object ( $result ) ;
110111 mysql_free_result ( $result ) ;
@@ -130,6 +131,7 @@
131132 $a = explode ( "[[" , " ".$s ) ;
132133 $s = array_shift ( $a ) ;
133134 $s = substr ( $s , 1 ) ;
 135+ $connection = getDBconnection () ;
134136 foreach ( $a as $t ) {
135137 $b = explode ( "]]" , $t , 2 ) ;
136138 if ( count($b) < 2 ) $s .= "Illegal link : ?$b[0]?" ;
@@ -146,7 +148,7 @@
147149 $text = $c[1] ;
148150
149151
150 - if ( $topic->doesTopicExist() ) {
 152+ if ( $topic->doesTopicExist( $connection ) ) {
151153 $linkedLinks[$topic->secureTitle]++ ;
152154 if ( $user->options["showHover"] == "yes" ) $hover = "title=\"$link\"" ;
153155 $s .= "<a href=\"$PHP_SELF?title=".urlencode($link)."\" $hover>$text</a>" ;
@@ -166,6 +168,7 @@
167169 $s .= $b[1] ;
168170 }
169171 }
 172+ mysql_close ( $connection ) ;
170173 return $s ;
171174 }
172175 function parseImages ( $s ) {
@@ -203,7 +206,7 @@
204207
205208 # $o = "A-Za-z0-9/\.:?&=~%-@^" ;
206209 # $s = eregi_replace ( "([^~])http://([$o]+)([^$o])" , "\\1<a href=\"http://\\2\">http://\\2</a>\\3" , $s ) ;
207 -# $s = str_replace ( "~http://" , "http://" , $s ) ;
 210+ $s = str_replace ( "~http://" , "http://" , $s ) ;
208211
209212 return $s ;
210213 }
@@ -372,7 +375,10 @@
373376 global $user , $action ;
374377 $t = $this->getNiceTitle ( $this->title ) ;
375378 if ( substr_count ( $t , ":" ) > 0 ) $t = ucfirst ( $t ) ;
376 - $ret = "<table ".$user->options["quickBarBackground"]." width=100% border=1 frame=below rules=none bordercolor=black cellspacing=0>\n<tr>" ;
 379+ global $HTTP_USER_AGENT ;
 380+ if ( stristr ( $HTTP_USER_AGENT , "MSIE" ) ) $border = "border=1 frame=below rules=none" ;
 381+ else $border = "border=0" ;
 382+ $ret = "<table ".$user->options["quickBarBackground"]." width=100% $border bordercolor=black cellspacing=0>\n<tr>" ;
377383 if ( $user->options["leftImage"] != "" )
378384 $ret .= "<td width=1% rowspan=2 bgcolor=#000000><img src=\"".$user->options["leftImage"]."\"></td>" ;
379385 $ret .= "<td valign=top height=1>" ;
@@ -411,7 +417,7 @@
412418 $column .= "<br><a href=\"$PHP_SELF?title=special:Upload\">Upload files</a>\n" ;
413419 $column .= "<hr>" ;
414420 $column .= "<a href=\"$PHP_SELF?title=special:Statistics\">Statistics</a>" ;
415 - $column .= "<br>\n<a href=\"$PHP_SELF?title=special:LonelyPages\">Lonely pages</a>" ;
 421+ $column .= "<br>\n<a href=\"$PHP_SELF?title=special:LonelyPages\">Orphans</a>" ;
416422 $column .= "<br>\n<a href=\"$PHP_SELF?title=special:WantedPages\">Most wanted</a>" ;
417423 $column .= "<br>\n<a href=\"$PHP_SELF?title=special:AllPages\">All pages</a>" ;
418424 $column .= "<br>\n<a href=\"$PHP_SELF?title=special:RandomPage\">Random Page</a>" ;
@@ -433,7 +439,10 @@
434440
435441 $column = "<td ".$user->options["quickBarBackground"]." width=110 valign=top nowrap>".$column."</td>" ;
436442 $ret = "<td valign=top>".$ret."</td>" ;
437 - $table = "<table width=100% border=1 frame=void bordercolor=black rules=cols cellpadding=2 cellspacing=0><tr>" ;
 443+ global $HTTP_USER_AGENT ;
 444+ if ( stristr ( $HTTP_USER_AGENT , "MSIE" ) ) $border = "border=1 frame=void rules=cols" ;
 445+ else $border = "border=0" ;
 446+ $table = "<table width=100% $border bordercolor=black cellpadding=2 cellspacing=0><tr>" ;
438447 $qb = $user->options["quickBar"] ;
439448 if ( $user->options["forceQuickBar"] != "" ) $qb = $user->options["forceQuickBar"] ;
440449 if ( $qb == "left" ) $ret = $table.$column.$ret."</tr></table>" ;
@@ -444,7 +453,10 @@
445454 }
446455 function getFooter () {
447456 $ret = $this->getLinkBar() ;
448 - $ret = "<table width=100% border=1 frame=above rules=none bordercolor=black cellspacing=0><tr><td>$ret</td></tr></table>" ;
 457+ global $HTTP_USER_AGENT ;
 458+ if ( stristr ( $HTTP_USER_AGENT , "MSIE" ) ) $border = "border=1 frame=above rules=none" ;
 459+ else $border = "border=0" ;
 460+ $ret = "<table width=100% $border bordercolor=black cellspacing=0><tr><td>$ret</td></tr></table>" ;
449461 $ret .= "<FORM>Search: <INPUT TYPE=text NAME=search SIZE=20></FORM>" ;
450462 return $ret ;
451463 }
@@ -457,7 +469,7 @@
458470 return $this->getHeader().$middle.$this->getFooter() ;
459471 }
460472 function doDiff () {
461 - global $oldID , $version ;
 473+ global $oldID , $version , $user ;
462474 $ret = "<nowiki><font color=red><b>BEGIN DIFF</b></font><br>\n" ;
463475 $connection = getDBconnection () ;
464476 mysql_select_db ( "wikipedia" , $connection ) ;
@@ -475,6 +487,11 @@
476488 $sql = "SELECT * FROM old WHERE old_id=$s->cur_old_version" ;
477489 }
478490
 491+ $fc = $user->options["background"] ;
 492+ if ( $fc == "" ) $fc = "=white" ;
 493+ $fc = substr ( $fc , strpos("=",$fc)+1 ) ;
 494+ $bc = " bordercolor=".$fc ;
 495+ $fc = " color=".$fc ;
479496 $result = mysql_query ( $sql , $connection ) ;
480497 if ( $result != "" and $s->old_old_version != 0 ) {
481498 $s = mysql_fetch_object ( $result ) ;
@@ -483,13 +500,13 @@
484501 $a2 = explode ( "\n" , $s->old_text ) ;
485502 $nl = array () ;
486503 $dl = array () ;
487 - foreach ( $a1 as $x ) if ( !in_array ( $x , $a2 ) ) array_push ( $nl , $x ) ;
488 - foreach ( $a2 as $x ) if ( !in_array ( $x , $a1 ) ) array_push ( $dl , $x ) ;
 504+ foreach ( $a1 as $x ) if ( !in_array ( $x , $a2 ) ) array_push ( $nl , htmlentities ( $x ) ) ;
 505+ foreach ( $a2 as $x ) if ( !in_array ( $x , $a1 ) ) array_push ( $dl , htmlentities ( $x ) ) ;
489506 # Output
490507 $ret .= "<font color=#0000FF>Blue text</font> was added or changed, <font color=red>red text</font> was changed or deleted." ;
491 - $ret .= "<table width=100% border=1 bordercolor=white cellspacing=0 cellpadding=2>\n" ;
492 - foreach ( $nl as $x ) $ret .= "<tr><td bgcolor=#0000FF><font color=white>$x</font></td></tr>\n" ;
493 - foreach ( $dl as $x ) $ret .= "<tr><td bgcolor=#DD0000><font color=white>$x</font></td></tr>\n" ;
 508+ $ret .= "<table width=100% border=1$bc cellspacing=0 cellpadding=2>\n" ;
 509+ foreach ( $nl as $x ) $ret .= "<tr><td bgcolor=#0000FF><font$fc>$x</font></td></tr>\n" ;
 510+ foreach ( $dl as $x ) $ret .= "<tr><td bgcolor=#DD0000><font$fc>$x</font></td></tr>\n" ;
494511 $ret .= "</table>\n" ;
495512 } 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" ;
496513 else $ret .= "No diff possible. Reason unknown. Blame the programmer! Tell him SQL said \"$sql\"<br>\n" ;
Index: trunk/phpwiki/fpw/wikiTitle.php
@@ -94,17 +94,18 @@
9595 }
9696 function makeAll () { $this->makeSecureTitle(); $this->makeURL(); }
9797 function setTitle ( $t ) { $this->title = $t ; $this->makeAll() ; }
98 - function doesTopicExist () {
 98+ function doesTopicExist ( $conn = "" ) {
9999 $this->makeSecureTitle () ;
100100 if ( $this->namespace == "special" ) return true ;
101 - $connection = getDBconnection () ;
 101+ if ( $conn == "" ) $connection = getDBconnection () ;
 102+ else $connection = $conn ;
102103 mysql_select_db ( "wikipedia" , $connection ) ;
103104 $sql = "SELECT cur_id FROM cur WHERE cur_title=\"$this->secureTitle\"" ;
104105 $result = mysql_query ( $sql , $connection ) ;
105106 if ( $result == "" ) return false ;
106107 if ( $s = mysql_fetch_object ( $result ) ) {
107108 mysql_free_result ( $result ) ;
108 - mysql_close ( $connection ) ;
 109+ if ( $conn == "" ) mysql_close ( $connection ) ; # Closing local connection
109110 return true ;
110111 }
111112 return false ;

Follow-up revisions

RevisionCommit summaryAuthorDate
r100160Import wfMsg statistics script by Seb35 (follow-up r100158, r100159)...platonides20:54, 18 October 2011

Status & tagging log