r29 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r28‎ | r29 | r30 >
Date:21:55, 21 October 2001
Author:magnus_manske
Status:old
Tags:
Comment:
preparing for wiki tarball
Modified paths:
  • /trunk/phpwiki/fpw/basicFunctions.php (modified) (history)
  • /trunk/phpwiki/fpw/convertWiki2SQL.php (added) (history)
  • /trunk/phpwiki/fpw/databaseFunctions.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/wikiUser.php (modified) (history)

Diff [purge]

Index: trunk/phpwiki/fpw/basicFunctions.php
@@ -7,6 +7,17 @@
88 return $page->renderPage () ;
99 }
1010
 11+# Convert MySQL timestame to date
 12+function tsc ( $t ) {
 13+ $year = substr ( $t , 0 , 4 ) ;
 14+ $month = substr ( $t , 4 , 2 ) ;
 15+ $day = substr ( $t , 6 , 2 ) ;
 16+ $hour = substr ( $t , 8 , 2 ) ;
 17+ $min = substr ( $t , 10 , 2 ) ;
 18+ $sec = substr ( $t , 12 , 2 ) ;
 19+ return mktime ( $hour , $min , $sec , $month , $day , $year ) ;
 20+ }
 21+
1122 # Called when editing/saving a page
1223 function edit ( $title ) {
1324 global $EditBox , $SaveButton , $PreviewButton , $MinorEdit ;
@@ -89,8 +100,10 @@
90101 $action = "edit" ;
91102
92103 $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\">" ;
 104+ 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\">";
 107+ }
95108 $ret .= $vpage->getMiddle ( $theMiddle ) ;
96109
97110 $action = "" ;
Index: trunk/phpwiki/fpw/databaseFunctions.php
@@ -1,7 +1,7 @@
22 <?
33 function getDBconnection () {
4 - $server="mysql" ;
5 - $user="wikipedia" ;
 4+ $server="127.0.0.1" ;
 5+ $user="root" ;
66 $passwd="" ;
77 $connection=mysql_connect ( $server , $user , $passwd ) ;
88 return $connection ;
Index: trunk/phpwiki/fpw/specialPages.php
@@ -106,6 +106,7 @@
107107 unset ( $ButtonSave ) ;
108108 global $QuickBar , $NewTopics , $UnderlineLinks , $AutoTalk , $ShowHover , $ROWS , $COLS , $doSkin ;
109109 global $OLDPASSWORD , $NEWPASSWORD , $RETYPEPASSWORD , $EMAIL , $RESULTSPERPAGE , $doJustify , $ChangesLayout ;
 110+ global $SHOWSTRUCTURE ;
110111 if ( $RESULTSPERPAGE < 2 ) $RESULTSPERPAGE = 20 ;
111112 $user->options["quickBar"] = $QuickBar ;
112113 $user->options["markupNewTopics"] = $NewTopics ;
@@ -117,6 +118,7 @@
118119 $user->options["justify"] = $doJustify ;
119120 $user->options["resultsPerPage"] = $RESULTSPERPAGE ;
120121 $user->options["skin"] = $doSkin ;
 122+ $user->options["showStructure"] = $SHOWSTRUCTURE ;
121123 $user->options["changesLayout"] = $ChangesLayout ;
122124 $user->email = $EMAIL ;
123125
@@ -212,6 +214,19 @@
213215 $ret .= "<input type=radio value=table ".$cl["table"]." name=ChangesLayout>As a table<br>\n" ;
214216 $ret .= "</td></tr>" ;
215217
 218+ # Show subpage structure in QuickBar
 219+ $shs[$user->options["showStructure"]] = "checked" ;
 220+ $ret .= "<tr><td valign=top nowrap><b>Show subpage structure :</b><br>\n" ;
 221+ $ret .= "<input type=radio value=yes ".$shs["yes"]." name=SHOWSTRUCTURE>Yes<br>\n" ;
 222+ $ret .= "<input type=radio value=no ".$shs["no"]." name=SHOWSTRUCTURE>No (Standard)<br>\n" ;
 223+
 224+ # UNUSED
 225+# $cl[$user->options["changesLayout"]] = "checked" ;
 226+# $ret .= "</td><td valign=top nowrap><b>New Topics :</b><br>\n" ;
 227+# $ret .= "<input type=radio value=classic ".$cl["classic"]." name=ChangesLayout>Classic (Standard)<br>\n" ;
 228+# $ret .= "<input type=radio value=table ".$cl["table"]." name=ChangesLayout>As a table<br>\n" ;
 229+ $ret .= "</td></tr>" ;
 230+
216231 $ret .= "<tr><td><center><input type=submit value=Save name=ButtonSave></center></td>" ;
217232 $ret .= "<td><center><input type=reset value=Reset name=ButtonReset></center></td></tr>" ;
218233
@@ -293,7 +308,10 @@
294309 mysql_select_db ( "wikipedia" , $connection ) ;
295310 $sql = "SELECT cur_title FROM cur ORDER BY cur_title" ;
296311 $result = mysql_query ( $sql , $connection ) ;
297 - while ( $s = mysql_fetch_object ( $result ) ) $ret .= "[[$s->cur_title]]<br>\n";
 312+ $ret .= "<nowiki>" ;
 313+ while ( $s = mysql_fetch_object ( $result ) )
 314+ $ret .= "<a href=\"$THESCRIPT?title=$s->cur_title\">".$vpage->getNiceTitle($s->cur_title)."</a><br>" ;
 315+ $ret .= "</nowiki>" ;
298316 mysql_free_result ( $result ) ;
299317 mysql_close ( $connection ) ;
300318 return $ret ;
@@ -434,24 +452,16 @@
435453 $randval-- ;
436454 }
437455 $thelink = $s->cur_title ;
438 - $ret = "<h2>Loading random page [[$thelink|".$vpage->getNiceTitle($thelink)."]]...</h2>" ;
439 - $ret .= "<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=$THESCRIPT?title=$thelink\">" ;
 456+ $nt = $vpage->getNiceTitle($thelink) ;
 457+ if ( count ( explode ( ":" , $thelink ) ) == 1 ) $thelink = ":".$thelink ;
 458+ $ret = "<h2>Loading random page [[$thelink|".$nt."]]...</h2>" ;
 459+ $ret .= "<nowiki><META HTTP-EQUIV=Refresh CONTENT=\"0; URL=$THESCRIPT?title=$thelink\"></nowiki>" ;
440460 mysql_free_result ( $result ) ;
441461 mysql_close ( $connection ) ;
442462
443463 return $ret ;
444464 }
445465
446 -# Convert MySQL timestame to date
447 -function tsc ( $t ) {
448 - $year = substr ( $t , 0 , 4 ) ;
449 - $month = substr ( $t , 4 , 2 ) ;
450 - $day = substr ( $t , 6 , 2 ) ;
451 - $hour = substr ( $t , 8 , 2 ) ;
452 - $min = substr ( $t , 10 , 2 ) ;
453 - $sec = substr ( $t , 12 , 2 ) ;
454 - return mktime ( $hour , $min , $sec , $month , $day , $year ) ;
455 - }
456466
457467 function recentchanges () {
458468 global $THESCRIPT ;
@@ -508,6 +518,7 @@
509519 $vpage->makeSecureTitle() ;
510520 if ( !isset ( $maxcnt ) ) $maxcnt = 100 ;
511521 if ( !isset ( $daysAgo ) ) $daysAgo = 3 ;
 522+ $names = array () ;
512523
513524 $ret = "<nowiki>" ;
514525 $ret .= "These are the last <b>$maxcnt</b> new pages on Wikipedia in the last <b>$daysAgo</b> days.<br>\n" ;
Index: trunk/phpwiki/fpw/wiki.phtml
@@ -36,6 +36,7 @@
3737
3838 # Do what is asked
3939 if ( isset ( $search ) ) {
 40+ include_once ( "./specialPages.php" ) ;
4041 $out = doSearch () ;
4142 unset ( $search ) ;
4243 } else if ( $action == "watch" ) {
Index: trunk/phpwiki/fpw/wikiPage.php
@@ -184,7 +184,7 @@
185185 $cond = "cur_title=\"$this->secureTitle\"" ;
186186
187187 global $linkedLinks , $unlinkedLinks ;
188 - $this->parseContents ( $text ) ;
 188+ $this->parseContents ( $text , true ) ; # Calling with savingMode flag set, so only internal Links are parsed
189189 $ll = implode ( "\n" , array_keys ( $linkedLinks ) ) ;
190190 $ull = implode ( "\n" , array_keys ( $unlinkedLinks ) ) ;
191191
@@ -336,7 +336,7 @@
337337 }
338338
339339 # This function organizes the <nowiki> parts and calls subPageContents() for the wiki parts
340 - function parseContents ( $s ) {
 340+ function parseContents ( $s , $savingMode = false ) {
341341 global $linkedLinks , $unlinkedLinks ;
342342 $linkedLinks = array () ;
343343 $unlinkedLinks = array () ;
@@ -355,8 +355,12 @@
356356 $s .= $d.$c[1] ;
357357 } else $s .= "&lt;nowiki&gt;".$x ;
358358 }
359 - $s = $this->subParseContents ( $s ) ;
360359
 360+ # If called from setEntry(), only parse internal links and return dummy entry
 361+ if ( $savingMode ) return $this->replaceInternalLinks ( $s ) ;
 362+
 363+ $s = $this->subParseContents ( $s , $savingMode ) ;
 364+
361365 # replacing $d with the actual nowiki contents
362366 $a = spliti ( $d , $s ) ;
363367 $s = array_shift ( $a ) ;
@@ -510,7 +514,7 @@
511515 $ret = "<table ".$user->options["quickBarBackground"]." width=100% $border bordercolor=black cellspacing=0>\n<tr>" ;
512516 if ( $user->options["leftImage"] != "" )
513517 $ret .= "<td width=1% rowspan=2 bgcolor=#000000><img src=\"".$user->options["leftImage"]."\"></td>" ;
514 - $ret .= "<td valign=top height=1>" ;
 518+ $ret .= "<td valign=top height=1 width=100%>" ;
515519 if ( $this->isSpecialPage ) {
516520 if ( $action == "edit" ) {
517521 $ret .= "<font size=+3>Editing ".$t."</font><br>Your changes will not be committed until you hit the <b>Save</b> button.<br>" ;
@@ -578,10 +582,11 @@
579583 if ( $user->options["quickBar"] == "right" or $user->options["quickBar"] == "left" or $user->options["forceQuickBar"] != "" ) {
580584 $column = $this->getQuickBar();
581585 $spl = $this->getSubpageList () ;
582 - if ( count ( $spl ) > 0 ) $column .= "<font size=-1>".$this->parseContents ( "<hr>".implode ( "<br>\n" , $spl ) )."</font>" ;
 586+ if ( !$this->isSpecialPage and $user->options["showStructure"]=="yes" and count ( $spl ) > 0 )
 587+ $column .= "<font size=-1>".$this->parseContents ( "<hr>".implode ( "<br>\n" , $spl ) )."</font>" ;
583588
584589 $column = "<td ".$user->options["quickBarBackground"]." width=120 valign=top nowrap>".$column."</td>" ;
585 - $ret = "<td valign=top>".$ret."</td>" ;
 590+ $ret = "<td valign=top width=100%>".$ret."</td>" ;
586591 global $HTTP_USER_AGENT ;
587592 if ( stristr ( $HTTP_USER_AGENT , "MSIE" ) ) $border = "border=1 frame=void rules=cols" ;
588593 else $border = "border=0" ;
Index: trunk/phpwiki/fpw/wikiUser.php
@@ -89,6 +89,7 @@
9090 if ( $this->options["justify"] == "" ) $this->options["justify"] = "no" ;
9191 if ( $this->options["resultsPerPage"] == "" ) $this->options["resultsPerPage"] = "20" ;
9292 if ( $this->options["skin"] == "" ) $this->options["skin"] = "None" ;
 93+ if ( $this->options["showStructure"] == "" ) $this->options["showStructure"] = "no" ;
9394 }
9495
9596 # Loads the user settings from the database
Index: trunk/phpwiki/fpw/convertWiki2SQL.php
@@ -0,0 +1,209 @@
 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" ) ;
 9+
 10+function scanText2 ( $fn ) {
 11+ $ret = "" ;
 12+
 13+ #CONSTANTS
 14+ $FS = "�" ;
 15+ $FS1 = $FS."1" ;
 16+ $FS2 = $FS."2" ;
 17+ $FS3 = $FS."3" ;
 18+
 19+ #READING FILE
 20+ $t = array () ;
 21+ $fd = fopen ( $fn , "r" ) ;
 22+ if ( $fd == false ) return "There was an error converting this file : file not found." ;
 23+ while (!feof($fd)) {
 24+ $buffer = fgets($fd, 99999);
 25+ array_push ( $t , $buffer ) ;
 26+ }
 27+ fclose ( $fd ) ;
 28+
 29+ array_pop ( $t ) ;
 30+ $t = implode ( "" , $t ) ;
 31+
 32+ #SPLIT PAGE
 33+ $sp = explode ( $FS1 , $t ) ;
 34+
 35+ $x = array_pop ( $sp ) ;
 36+ $sections = explode ( $FS2 , $x ) ;
 37+ foreach ( $sections as $y ) {
 38+ $text = explode ( $FS3 , $y ) ;
 39+ foreach ( $text as $z ) {
 40+ $ret = $z ;
 41+ }
 42+ }
 43+
 44+ return $ret ;
 45+ }
 46+
 47+
 48+
 49+
 50+function getFileName ( $an ) {
 51+ global $rootDir ;
 52+ $ret = $rootDir ;
 53+ $sd = ucfirst ( substr ( $an , 0 , 1 ) ) ;
 54+ if ( $sd < "A" or $sd > "Z" ) $sd = "other" ;
 55+ $ret .= "$sd/".ucfirst($an).".db" ;
 56+ return $ret ;
 57+ }
 58+
 59+function fixLinks ( $s ) {
 60+ global $npage , $ll , $ull , $allTopics ;
 61+
 62+ $talk = explode ( "/" , $npage->secureTitle ) ;
 63+ if ( count($talk)==2 and strtolower($talk[1])=="talk" ) $isTalkPage = true ;
 64+ else $isTalkPage = false ;
 65+
 66+ $s = " $s" ;
 67+ $a = explode ( "[[" , $s ) ;
 68+ $s = array_shift ( $a ) ;
 69+ foreach ( $a as $x ) {
 70+ $b = explode ( "]]" , $x , 2 ) ;
 71+ $s .= "[[" ;
 72+ if ( count ( $b ) == 1 ) $s .= $x ;
 73+ else {
 74+ $c = explode ( "|" , $b[0] ) ;
 75+ $link = $c[0] ;
 76+ if ( substr ( $link , 0 , 1 ) == "/" ) { # Converting subpages
 77+ $u = explode ( "/" , $npage->title ) ;
 78+ $link = $u[0].$link ;
 79+ }
 80+ $n = str_replace ( " " , "_" , $link ) ;
 81+ $n = ucfirst ( $n ) ;
 82+ $m = substr ( $n , 0 , 1 ) ;
 83+ if ( $m < "A" or $m > "Z" ) $m = "0" ;
 84+ if ( in_array ( $n , $allTopics[$m] ) ) array_push ( $ll , $n ) ;
 85+ else array_push ( $ull , $n ) ;
 86+
 87+ # Re-linking /Talk pages to talk:
 88+ $talk = explode ( "/" , $link ) ;
 89+ if ( count ( $talk ) == 2 and strtolower($talk[1]) == "talk" ) $link = "talk:".$talk[0] ;
 90+ else if ( $isTalkPage ) {
 91+ if ( count ( $c ) == 1 ) array_push ( $c , $link ) ;
 92+ $link = ":".$link ;
 93+ }
 94+
 95+ $s .= $link ;
 96+ if ( count ( $c ) == 2 ) $s .= "|".$c[1] ;
 97+ $s .= "]]".$b[1] ;
 98+ }
 99+ }
 100+ return substr ( $s , 1 ) ;
 101+ }
 102+
 103+function convertText ( $s ) {
 104+ $s = str_replace ( "\\'" , "'" , $s ) ;
 105+ $s = str_replace ( "\\\"" , "\"" , $s ) ;
 106+ $s = str_replace ( "\"" , "\\\"" , $s ) ;
 107+ $s = str_replace ( "'" , "\\'" , $s ) ;
 108+
 109+ $a = spliti ( "<nowiki>" , $s ) ;
 110+ $s = fixLinks ( array_shift ( $a ) ) ;
 111+ foreach ( $a as $x ) {
 112+ $b = spliti ( "</nowiki>" , $x , 2 ) ;
 113+ if ( count ( $b ) == 1 ) $s .= "<nowiki>".$x ;
 114+ else $s .= "<nowiki>".$b[0]."</nowiki>".fixLinks($b[1]);
 115+ }
 116+
 117+ return $s ;
 118+ }
 119+
 120+function storeInDB ( $title , $text ) {
 121+ global $of , $npage , $ll , $ull ;
 122+ $ll = array () ;
 123+ $ull = array () ;
 124+ $title = str_replace ( "\\'" , "'" , $title ) ;
 125+ $title = str_replace ( "\\\"" , "\"" , $title ) ;
 126+ $npage = new wikiPage ;
 127+ $npage->title = $title ;
 128+ $npage->makeAll () ;
 129+ $text = convertText ( $text ) ;
 130+ $ll1 = implode ( "\n" , $ll ) ;
 131+ $ull1 = implode ( "\n" , $ull ) ;
 132+ $st = $npage->secureTitle ;
 133+
 134+ # Move talk pages to talk namespace
 135+ $talk = explode ( "/" , $st ) ;
 136+ if( count ( $talk ) == 2 and strtolower($talk[1]) == "talk" ) $st = "Talk:".$talk[0] ;
 137+
 138+ $sql = "INSERT INTO cur (cur_title,cur_text,cur_comment,cur_user,cur_user_text,cur_old_version,cur_minor_edit,cur_linked_links,cur_unlinked_links) VALUES ";
 139+ $sql .= "(\"$st\",\"$text\",";
 140+ $sql .= "\"Automated conversion\",0,\"conversion script\",0,1,\"$ll1\",\"$ull1\");\n" ;
 141+ fwrite ( $of , $sql ) ;
 142+ print " (".count($ll)."/".count($ull).")" ;
 143+ if ( count ( $ull ) != 0 ) print "!!" ;
 144+ }
 145+
 146+function getTopics ( $dir ) {
 147+ $ret = array () ;
 148+
 149+ $mydir = opendir($dir);
 150+ while ($entry = readdir($mydir)) {
 151+ if ($entry != '.' && $entry != '..') {
 152+ if ( is_dir ( "$dir/$entry" ) ) {
 153+ $a = getTopics ( "$dir/$entry" ) ;
 154+ foreach ( $a as $x ) array_push ( $ret , "$entry/$x" ) ;
 155+ } else {
 156+ $x = substr ( $entry , 0 , strlen ( $entry ) - 3 ) ;
 157+ array_push ( $ret , $x ) ;
 158+ }
 159+ }
 160+ }
 161+ closedir($mydir);
 162+
 163+ return $ret ;
 164+ }
 165+
 166+function dir2DB ( $letter ) {
 167+ global $rootDir ;
 168+ $a = getTopics ( "$rootDir/$letter" ) ;
 169+ print "Reading :\n" ;
 170+ foreach ( $a as $an ) {
 171+ print "$an" ;
 172+ $fn = getFileName ( $an ) ;
 173+ storeInDB ( $an , scantext2 ( $fn ) ) ;
 174+ print "\n" ;
 175+ }
 176+ print "\n" ;
 177+ }
 178+
 179+function getAllTopics () {
 180+ global $allTopics , $rootDir ;
 181+ $allTopics = array () ;
 182+ for ( $c = 65 ; chr($c) <= "Z" ; $c++ ) $allTopics[chr($c)] = getTopics ( "$rootDir/".chr($c) ) ;
 183+ $allTopics["0"] = getTopics ( "$rootDir/other" ) ;
 184+ }
 185+
 186+# MAIN PROGRAM
 187+ global $rootDir ;
 188+# $rootDir = "/home/groups/w/wi/wikipedia/htdocs/fpw/wiki-de/lib-http/db/wiki/page/" ;
 189+ $rootDir = "/home/manske/wiki/lib-http/db/wiki/page/" ;
 190+
 191+ global $ll , $ull , $allTopics ;
 192+ $ll = array () ;
 193+ $ull = array () ;
 194+ getAllTopics () ;
 195+
 196+ global $l , $of ;
 197+ $of = fopen ( "./newiki.sql" , "w" ) ;
 198+ do {
 199+ if ( !isset ( $l ) ) $l = 65 ;
 200+ if ( $l == "other" ) $letter = "other" ;
 201+ else $letter = chr ( $l ) ;
 202+ $nl = $l+1 ;
 203+ if ( $letter == "Z" ) $nl = "other" ;
 204+ $l = $nl ;
 205+ dir2DB ( $letter ) ;
 206+ } while ( $letter != "other" ) ;
 207+ fclose ( $of ) ;
 208+
 209+ print "FINISHED!\n" ;
 210+?>
\ No newline at end of file
Property changes on: trunk/phpwiki/fpw/convertWiki2SQL.php
___________________________________________________________________
Name: svn:eol-style
1211 + native
Name: svn:keywords
2212 + Author Date Id Revision

Status & tagging log