r30 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r29‎ | r30 | r31 >
Date:18:47, 27 October 2001
Author:magnus_manske
Status:old
Tags:
Comment:
added print option, minor fixes
Modified paths:
  • /trunk/phpwiki/fpw/basicFunctions.php (modified) (history)
  • /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/basicFunctions.php
@@ -88,7 +88,7 @@
8989 }
9090
9191 function doEdit ( $title ) {
92 - global $THESCRIPT ;
 92+ global $THESCRIPT , $headerScript ;
9393 global $vpage , $action , $wasSaved ;
9494 $wasSaved = false ;
9595 $vpage = new WikiPage ;
@@ -101,8 +101,11 @@
102102
103103 $theMiddle = edit ( $title ) ;
104104 if ( $wasSaved ) {
105 - $theMiddle = "<h1>Your page [[$title]] was successfully saved!</h1>" ;
106 - $theMiddle .= "<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=$THESCRIPT?title=$vpage->secureTitle\">";
 105+ $ti = new wikiTitle ;
 106+ $ti->setTitle ( $title ) ;
 107+ $theMiddle = "<h1>Your page <a href=\"$THESCRIPT?title=$ti->secureTitle\">$title</a> was successfully saved!</h1>" ;
 108+ $theMiddle .= "(If this page doesn't forward automatically, you have a really lame browser...)" ;
 109+ $headerScript .= "<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=$THESCRIPT?title=$vpage->secureTitle\">";
107110 }
108111 $ret .= $vpage->getMiddle ( $theMiddle ) ;
109112
@@ -118,4 +121,11 @@
119122 $vpage->load ( $title ) ;
120123 return $vpage->renderPage () ;
121124 }
 125+
 126+function doPrint ( $title ) {
 127+ global $vpage ;
 128+ $vpage = new WikiPage ;
 129+ $vpage->load ( $title ) ;
 130+ return $vpage->renderPage ( true ) ;
 131+ }
122132 ?>
\ No newline at end of file
Index: trunk/phpwiki/fpw/specialPages.php
@@ -434,8 +434,7 @@
435435 }
436436
437437 function randompage () {
438 - global $THESCRIPT ;
439 - global $vpage ;
 438+ global $THESCRIPT , $headerScript , $vpage ;
440439 $connection=getDBconnection() ;
441440 mysql_select_db ( "wikipedia" , $connection ) ;
442441 $sql = "SELECT COUNT(*) AS number FROM cur" ;
@@ -455,7 +454,7 @@
456455 $nt = $vpage->getNiceTitle($thelink) ;
457456 if ( count ( explode ( ":" , $thelink ) ) == 1 ) $thelink = ":".$thelink ;
458457 $ret = "<h2>Loading random page [[$thelink|".$nt."]]...</h2>" ;
459 - $ret .= "<nowiki><META HTTP-EQUIV=Refresh CONTENT=\"0; URL=$THESCRIPT?title=$thelink\"></nowiki>" ;
 458+ $headerScript .= "<nowiki><META HTTP-EQUIV=Refresh CONTENT=\"0; URL=$THESCRIPT?title=$thelink\"></nowiki>" ;
460459 mysql_free_result ( $result ) ;
461460 mysql_close ( $connection ) ;
462461
Index: trunk/phpwiki/fpw/wiki.phtml
@@ -41,9 +41,11 @@
4242 unset ( $search ) ;
4343 } else if ( $action == "watch" ) {
4444 global $mode ;
 45+ include_once ( "./specialPages.php" ) ;
4546 $out = watch ( $title , $mode ) ;
4647 } else if ( $action == "view" ) $out = view ( $title ) ;
4748 else if ( $action == "edit" ) $out = doEdit ( $title ) ;
 49+ else if ( $action == "print" ) $out = doPrint ( $title ) ;
4850 else if ( $action == "history" ) {
4951 include_once ( "./specialPages.php" ) ;
5052 $out = doHistory ( $title ) ;
Index: trunk/phpwiki/fpw/wikiPage.php
@@ -264,6 +264,7 @@
265265 $a = explode ( "[http://" , " ".$s ) ;
266266 $s = array_shift ( $a ) ;
267267 $s = substr ( $s , 1 ) ;
 268+ $image = "<img src=earth_small.png valign=center border=0>" ; # Remove or set to blank for no image
268269 foreach ( $a as $t ) {
269270 $b = spliti ( "]" , $t , 2 ) ;
270271 if ( count($b) < 2 ) $s .= "Illegal link : ?$b[0]?" ;
@@ -280,13 +281,13 @@
281282 if ( substr_count ( $b[1] , "<hr>" ) > 0 ) $cnt = 1 ;
282283 $link = "~http://".$link ;
283284 if ( $user->options["showHover"] == "yes" ) $hover = "title=\"$link\"" ;
284 - $s .= "<a href=\"$link\" $hover>$text</a>" ;
 285+ $s .= "<a href=\"$link\" $hover>$image$text</a>" ;
285286 $s .= $b[1] ;
286287 }
287288 }
288289
289290 $o = "A-Za-z0-9/\.:?&=_~%-@^" ;
290 - $s = eregi_replace ( "([^~\"])http://([$o]+)([^$o])" , "\\1<a href=\"http://\\2\">[http://\\2]</a>\\3" , $s ) ;
 291+ $s = eregi_replace ( "([^~\"])http://([$o]+)([^$o])" , "\\1<a href=\"http://\\2\">".$image."http://\\2</a>\\3" , $s ) ;
291292 $s = str_replace ( "~http://" , "http://" , $s ) ;
292293
293294 return $s ;
@@ -325,6 +326,7 @@
326327 # This function is called to replace wiki-style tags with HTML, e.g., the first occurrence of ''' with <b>, the second with </b>
327328 function pingPongReplace ( $f , $r1 , $r2 , $s ) {
328329 $a = explode ( $f , " ".$s ) ;
 330+ if ( count ( $a ) == 1 ) return $s ;
329331 $s = substr ( array_shift ( $a ) , 1 ) ;
330332 $r = $r1 ;
331333 foreach ( $a as $t ) {
@@ -373,25 +375,30 @@
374376
375377 # This function removes "forbidden" HTML tags
376378 function removeHTMLtags ( $s ) {
377 - $s = eregi_replace ( "<a (.*)>" , "&lt;a \\1&gt;" , $s ) ;
378 - $s = eregi_replace ( "</a(.*)>" , "&lt;/a\\1&gt;" , $s ) ;
379 - $s = eregi_replace ( "<script(.*)>" , "&lt;script\\1&gt;" , $s ) ;
380 - $s = eregi_replace ( "</script(.*)>" , "&lt;/script\\1&gt;" , $s ) ;
 379+ $forbidden = array ( "a" , "script" , "title" , "html" , "body" , "header" ) ;
 380+ foreach ( $forbidden as $x ) {
 381+ $s = eregi_replace ( "<".$x." (.*)>" , "&lt;".$x." \\1&gt;" , $s ) ;
 382+ $s = eregi_replace ( "</".$x."(.*)>" , "&lt;/".$x."\\1&gt;" , $s ) ;
 383+ }
381384 return $s ;
382385 }
383386
384 - # This function does the actual parsing of the wiki parts of the article
 387+ # This function does the actual parsing of the wiki parts of the article, for regions NOT marked with <nowiki>
385388 function subParseContents ( $s ) {
386389 global $user ;
387390 # Removed automatic links for mixedThings; wasn't working, anyway...
388391 # $s = ereg_replace ( "([\.|\n| )([a-z0-9]*[A-Z0-9]+[A-Za-z0-9]*)( |\n|\.)" , "\\1[[\\2]]\\3" , $s ) ;
389392 $s = $this->removeHTMLtags ( $s ) ; # Removing "forbidden" HTML tags
 393+
390394 # Now some repalcements wiki->HTML
391395 $s = ereg_replace ( "-----*" , "<hr>" , $s ) ;
392396 $s = str_replace ( "<HR>" , "<hr>" , $s ) ;
393397 $s = $this->replaceVariables ( $s ) ;
 398+ $s = $this->pingPongReplace ( "'''''" , "<i><b>" , "</b></i>" , $s ) ;
394399 $s = $this->pingPongReplace ( "'''" , "<b>" , "</b>" , $s ) ;
395400 $s = $this->pingPongReplace ( "''" , "<i>" , "</i>" , $s ) ;
 401+ $s = $this->pingPongReplace ( "====" , "<h4>" , "</h4>" , $s ) ;
 402+ $s = $this->pingPongReplace ( "===" , "<h3>" , "</h3>" , $s ) ;
396403
397404 # Automatic links to subpages (e.g., /Talk -> [[/Talk]]
398405 $s = ereg_replace ( "([\n| ])/([a-zA-Z0-9_]*)" , "\\1[[/\\2|/\\2]]" , $s ) ;
@@ -484,7 +491,7 @@
485492 global $user , $oldID , $version ;
486493 $editOldVersion = "" ;
487494 if ( $oldID != "" ) $editOldVersion="&oldID=$oldID&version=$version" ;
488 - $ret = "<a href=\"$THESCRIPT?\">HomePage</a>" ;
 495+ $ret = "<a href=\"$THESCRIPT\">Homepage</a>" ;
489496
490497 $spl = $this->getSubpageList () ;
491498 if ( count ( $spl ) > 0 and $this->subpageTitle != "" ) {
@@ -522,11 +529,14 @@
523530 } else $ret .= "<font size=+3>".$t."</font>" ;
524531 } else {
525532 $ret .= "<font size=+3><a href=\"$THESCRIPT?search=$this->title\">".$this->getNiceTitle($t)."</a>$this->thisVersion</font>" ;
 533+ $subText = array () ;
526534 if ( $user->isLoggedIn ) {
527535 if ( $user->doWatch($this->title) )
528 - $ret.="<br><a href=\"$THESCRIPT?action=watch&title=$this->secureTitle&mode=no\">Stop watching this article for me</a>";
529 - else $ret .= "<br><a href=\"$THESCRIPT?action=watch&title=$this->secureTitle&mode=yes\">Watch this article for me</a>" ;
 536+ array_push($subText,"<br><a href=\"$THESCRIPT?action=watch&title=$this->secureTitle&mode=no\">Stop watching this article for me</a>");
 537+ else array_push($subText,"<br><a href=\"$THESCRIPT?action=watch&title=$this->secureTitle&mode=yes\">Watch this article for me</a>") ;
530538 }
 539+ if ( $action == "view" and !$this->isSpecialPage ) array_push ( $subText , "<a href=\"$THESCRIPT?action=print&title=$this->secureTitle\">Printable version</a>" ) ;
 540+ $ret .= implode ( " | " , $subText ) ;
531541 }
532542 $ret .= "</td>\n<td valign=top width=200 rowspan=2 nowrap>".$user->getLink()."<br>" ;
533543 if ( $user->isLoggedIn ) $ret .= "<a href=\"$THESCRIPT?title=special:userLogout\">Log out</a> | <a href=\"$THESCRIPT?title=special:editUserSettings\">Preferences</a>" ;
@@ -577,6 +587,7 @@
578588 # Some special pages have their own rendering function
579589 function getMiddle ( $ret ) {
580590 global $user , $action ;
 591+ if ( $action == "print" ) return $ret ;
581592 $oaction = $action ;
582593 if ( $action == "edit" ) $action = "" ;
583594 if ( $user->options["quickBar"] == "right" or $user->options["quickBar"] == "left" or $user->options["forceQuickBar"] != "" ) {
@@ -617,13 +628,20 @@
618629
619630 # This generates header, diff (if wanted), article body (with QuickBar), and footer
620631 # The whole page (for normal pages) is generated here
621 - function renderPage () {
622 - global $pageTitle , $diff ;
 632+ function renderPage ( $doPrint = false ) {
 633+ global $pageTitle , $diff , $THESCRIPT ;
623634 $pageTitle = $this->title ;
624635 if ( isset ( $diff ) ) $middle = $this->doDiff().$this->contents ;
625636 else $middle = $this->contents ;
626637 $middle = $this->getMiddle($this->parseContents($middle)) ;
627 - return $this->getHeader().$middle.$this->getFooter() ;
 638+ if ( $doPrint ) {
 639+ $header = "<h1>".$this->getNiceTitle($pageTitle)."</h1>\n" ;
 640+ $link = "http://wikipedia.sourceforge.net/fpw/wiki.phtml?title=$this->secureTitle" ;
 641+# $link = "http://127.0.0.1/fpw/wiki.phtml?title=$this->secureTitle" ;
 642+ $footer = "<hr>This article is from <b>Wikipedia</b> (<a href=\"http://wikipedia.com\">http://wikipedia.com</a>), " ;
 643+ $footer .= "the free online encyclopedia. You can find this article at <a href=\"$link\">$link</a>" ;
 644+ return $header.$middle.$footer ;
 645+ } else return $this->getHeader().$middle.$this->getFooter() ;
628646 }
629647
630648 # This displays the diff. Currently, only diff with the last edit!
Index: trunk/phpwiki/fpw/wikiUser.php
@@ -18,7 +18,7 @@
1919
2020 # This sets the options for the standard skin
2121 function skinBlank () {
22 - $this->options["background"] = "" ;
 22+ $this->options["background"] = " BGCOLOR=#FFFFFF" ;
2323 $this->options["text"] = "" ;
2424 $this->options["forceQuickBar"] = "" ;
2525 $this->options["quickBarBackground"] = "" ;
Index: trunk/phpwiki/fpw/wikiTitle.php
@@ -108,9 +108,11 @@
109109 $this->namespace = strtolower ( $this->namespace ) ;
110110 }
111111
112 - # I don't remember what this does, or if I use it somewhere...
 112+ # This converts an internal link to stay in the same namespace, if desired. Used in wikiPage-getInternalLinks()
113113 function getLinkTo ( $target ) {
114 - $n = $this->namespace ;
 114+ $keepNamespace = array ( "stable" ) ; # For future use
 115+ $n = "" ;
 116+ if ( in_array ( strtolower ( $this->namespace ) , $keepNamespace ) ) $n = $this->namespace ;
115117 if ( $target->hasNamespace ) $n = $target->namespace ;
116118 if ( $n != "" ) $n .= ":" ;
117119 $p = $target->mainTitle ;

Status & tagging log