r26 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25‎ | r26 | r27 >
Date:09:49, 18 October 2001
Author:magnus_manske
Status:old
Tags:
Comment:
major changes to all files
Modified paths:
  • /trunk/phpwiki/fpw/scandb.phtml (added) (history)
  • /trunk/phpwiki/fpw/specialPages.php (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/specialPages.php
@@ -308,33 +308,31 @@
309309 function WantedPages () {
310310 global $THESCRIPT ;
311311 global $linkedLinks , $unlinkedLinks , $vpage ;
312 - $vpage->special ( "The Most Wanted Topics" ) ;
 312+ $vpage->special ( "The Most Wanted Pages" ) ;
313313 $vpage->namespace = "" ;
314314 $allPages = array () ;
315 - $linkedLinks = array () ;
316 - $unlinkedLinks = array () ;
317 - $ret = "'''These articles don't exist, but other articles link to them!'''\n\n" ;
 315+ $ret = "'''These articles don't exist, but other articles link to them!''' (the top 50)\n\n" ;
318316
319317 $connection = getDBconnection () ;
320318 mysql_select_db ( "wikipedia" , $connection ) ;
321 - $sql = "SELECT cur_title FROM cur" ;
 319+ $sql = "SELECT cur_title,cur_linked_links,cur_unlinked_links FROM cur" ;
322320 $result = mysql_query ( $sql , $connection ) ;
323 - while ( $s = mysql_fetch_object ( $result ) ) array_push ( $allPages , $s->cur_title ) ;
 321+ while ( $s = mysql_fetch_object ( $result ) ) {
 322+ $allPages[$s->cur_title] = -999999999999 ; # Effectively removing existing topics from list
 323+ $u = explode ( "\n" , $s->cur_linked_links ) ; foreach ( $u as $x ) $allPages[$x] += 1 ;
 324+ $u = explode ( "\n" , $s->cur_unlinked_links ) ; foreach ( $u as $x ) $allPages[$x] += 1 ;
 325+ }
324326 mysql_free_result ( $result ) ;
325327 mysql_close ( $connection ) ;
326328
327 - foreach ( $allPages as $x ) {
328 - $p = new WikiPage ;
329 - $p->load ( $x ) ;
330 - $p->replaceInternalLinks ( $p->contents ) ;
 329+
 330+ arsort ( $allPages ) ;
 331+ array_shift ( $allPages ) ; # Removing blank "link"
 332+ $k = array_keys ( $allPages ) ;
 333+ for ( $a = 0 ; $a < 50 ; $a++ ) {
 334+ $x = $k[$a] ;
 335+ $ret .= "[[$x|".$vpage->getNiceTitle($x)."]] is wanted by ".$allPages[$x]." articles.<br>\n" ;
331336 }
332 -
333 - arsort ( $unlinkedLinks ) ;
334 - while ( count ( $unlinkedLinks ) > 20 ) array_pop ( $unlinkedLinks ) ;
335 - $a = array_keys ( $unlinkedLinks ) ;
336 - foreach ( $a as $x )
337 - $ret .= "[[$x]] (linked from $unlinkedLinks[$x] other topics)<br>\n" ;
338 -
339337 return $ret ;
340338 }
341339
@@ -344,35 +342,30 @@
345343 $vpage->special ( "The Orphans" ) ;
346344 $vpage->namespace = "" ;
347345 $allPages = array () ;
348 - $linkedLinks = array () ;
349 - $unlinkedLinks = array () ;
350346 $ret = "'''These articles exist, but no articles link to them!'''\n\n" ;
351347
352348 $connection = getDBconnection () ;
353349 mysql_select_db ( "wikipedia" , $connection ) ;
354 - $sql = "SELECT cur_title FROM cur" ;
 350+ $sql = "SELECT cur_title,cur_linked_links,cur_unlinked_links FROM cur" ;
355351 $result = mysql_query ( $sql , $connection ) ;
356 - while ( $s = mysql_fetch_object ( $result ) ) array_push ( $allPages , $s->cur_title ) ;
 352+ while ( $s = mysql_fetch_object ( $result ) ) {
 353+ $allPages[$s->cur_title] = $allPages[$s->cur_title] * 1 ;
 354+ $u = explode ( "\n" , $s->cur_linked_links ) ; foreach ( $u as $x ) $allPages[$x] += 1 ;
 355+ $u = explode ( "\n" , $s->cur_unlinked_links ) ; foreach ( $u as $x ) $allPages[$x] += 1 ;
 356+ }
357357 mysql_free_result ( $result ) ;
358358 mysql_close ( $connection ) ;
359 -
360 - $r = array () ;
361 - foreach ( $allPages as $x ) {
362 - $p = new WikiPage ;
363 - $p->load ( $x ) ;
364 - $r["$p->secureTitle"] = 0 ;
365 - $p->replaceInternalLinks ( $p->contents ) ;
 359+
 360+ $orphans = array () ;
 361+ $v = array_keys ( $allPages ) ;
 362+ foreach ( $v as $x ) {
 363+ if ( $allPages[$x] == 0 )
 364+ array_push ( $orphans , $x ) ;
366365 }
367366
368 - $a = array_keys ( $linkedLinks ) ;
369 - foreach ( $a as $x ) $r[$x]++ ;
370 -
371 - $a = array_keys ( $r ) ;
372 - foreach ( $a as $x ) {
373 - if ( $r[$x] == 0 )
374 - $ret .= "[[$x]]<br>\n" ;
375 - }
376 -
 367+ asort ( $orphans ) ;
 368+ foreach ( $orphans as $x )
 369+ $ret .= "[[$x|".$vpage->getNiceTitle($x)."]]<br>\n" ;
377370 return $ret ;
378371 }
379372
@@ -487,6 +480,28 @@
488481 }
489482
490483 function listUsers () {
 484+ global $user , $vpage , $startat ;
 485+ if ( !isset ( $startat ) ) $startat = 1 ;
 486+ $perpage = $user->options["resultsPerPage"] ;
 487+ if ( $perpage == 0 ) $perpage = 20 ;
 488+
 489+ $vpage->special ( "User List" ) ;
 490+ $vpage->namespace = "" ;
 491+ $ret = "'''These are all wikipedia users (that have an account)!'''\n\n" ;
 492+ $connection = getDBconnection () ;
 493+ mysql_select_db ( "wikipedia" , $connection ) ;
 494+ $sql = "SELECT * from user" ;
 495+ $result = mysql_query ( $sql , $connection ) ;
 496+ while ( $s = mysql_fetch_object ( $result ) ) {
 497+ $ret .= "#[[user:$s->user_name|$s->user_name]]" ;
 498+ if ( in_array ( "is_sysop" , $user->rights ) ) $ret .= " ($s->user_rights)" ;
 499+ $ret .= "\n" ;
 500+ }
 501+
 502+
 503+ return $ret ;
 504+
 505+#------------------------------------------------
491506 global $THESCRIPT ;
492507 global $user , $vpage , $startat ;
493508 if ( !isset ( $startat ) ) $startat = 1 ;
@@ -1065,15 +1080,74 @@
10661081 return $ret ;
10671082 }
10681083
 1084+function removeFromLinkList ( $item , $link ) {
 1085+ $connection = getDBconnection () ;
 1086+ mysql_select_db ( "wikipedia" , $connection ) ;
 1087+ $sql = "SELECT cur_id FROM cur WHERE $item LIKE \"%$link%\"" ;
 1088+ $result = mysql_query ( $sql , $connection ) ;
 1089+ $ids = array () ;
 1090+ while ( $s = mysql_fetch_object ( $result ) ) array_push ( $ids , $s->cur_id ) ;
 1091+ mysql_free_result ( $result ) ;
 1092+
 1093+ foreach ( $ids as $x ) {
 1094+ $sql = "SELECT cur_timestamp,$item FROM cur WHERE cur_id=$x" ;
 1095+ $result = mysql_query ( $sql , $connection ) ;
 1096+ $s = mysql_fetch_object ( $result ) ;
 1097+ mysql_free_result ( $result ) ;
 1098+ $y = explode ( "\n" , $s->$item ) ;
 1099+ $z = array () ;
 1100+ foreach ( $y as $u ) {
 1101+ if ( $u != $link )
 1102+ array_push ( $z , $u ) ;
 1103+ }
 1104+ $y = implode ( "\n" , $z ) ;
 1105+ $sql = "UPDATE cur SET cur_timestamp=\"$s->cur_timestamp\",$item=\"$y\" WHERE cur_id=$x" ;
 1106+ $result = mysql_query ( $sql , $connection ) ;
 1107+ }
 1108+
 1109+ mysql_close ( $connection ) ;
 1110+ }
 1111+
 1112+function deletepage () {
 1113+ global $THESCRIPT , $target , $user , $iamsure ;
 1114+ global $vpage ;
 1115+ $target = str_replace ( "\\\\" , "\\" , $target ) ;
 1116+ $target = str_replace ( "\\\\" , "\\" , $target ) ;
 1117+ $vpage = new WikiPage ;
 1118+ $vpage->title = $title ;
 1119+ $vpage->makeSecureTitle () ;
 1120+ $ti = $vpage->secureTitle ;
 1121+ $vpage->special ( "Deleting article '$target'" ) ;
 1122+ $vpage->makeSecureTitle () ;
 1123+ if ( !in_array ( "is_sysop" , $user->rights ) ) return "<h1>You are not allowed to delete this page!</h1>" ;
 1124+ if ( $iamsure == "yes" ) {
 1125+ $connection = getDBconnection () ;
 1126+ mysql_select_db ( "wikipedia" , $connection ) ;
 1127+ $sql = "DELETE FROM cur WHERE cur_title=\"$target\"" ;
 1128+ $result = mysql_query ( $sql , $connection ) ;
 1129+ mysql_close ( $connection ) ;
 1130+ removeFromLinkList ( "cur_linked_links" , $target ) ;
 1131+ removeFromLinkList ( "cur_unlinked_links" , $target ) ;
 1132+ $ret = "<h2>'$target' has been removed.</h2>" ;
 1133+ } else {
 1134+ $ret = "<h2>You are about to delete the article \"$target\" and its complete history!<br>\n" ;
 1135+ $ret .= "If you are absolutely sure you want to do this, " ;
 1136+ $ret .= "<a href=\"$THESCRIPT?title=special:deletepage&target=$target&iamsure=yes\">click here</a>.</h2>" ;
 1137+ }
 1138+ return "<nowiki>$ret</nowiki>" ;
 1139+ }
 1140+
10691141 # A little hack; disabled; to enable, allow function call in wikiPage->load()
10701142 function askSQL () {
10711143 global $THESCRIPT ;
10721144 global $Save , $question ;
10731145 $ret = "" ;
10741146 if ( isset ( $Save ) ) {
 1147+ $ret .= "$question<br>" ;
10751148 unset ( $Save ) ;
10761149 $connection = getDBconnection () ;
10771150 mysql_select_db ( "wikipedia" , $connection ) ;
 1151+ $question = str_replace ( "\\\"" , "\"" , $question ) ;
10781152 $result = mysql_query ( $question , $connection ) ;
10791153 $n = mysql_num_fields ( $result ) ;
10801154 $k = array () ;
Index: trunk/phpwiki/fpw/wikiPage.php
@@ -1,16 +1,20 @@
22 <?
33 class WikiPage extends WikiTitle {
44 var $contents ;
 5+ var $knownLinkedLinks , $knownUnlinkedLinks ;
56
67 #Functions
78 function load ( $t , $doRedirect = true ) {
8 - global $action ;
 9+ global $action , $user ;
 10+ $this->knownLinkedLinks = array () ;
 11+ $this->knownUnlinkedLinks = array () ;
912 $this->title = $t ;
1013 $this->makeSecureTitle () ;
1114 $this->isSpecialPage = false ;
1215 $this->revision = "current" ;
1316 if ( $this->namespace == "special" ) {
14 - $allowed = array("userlogin","userlogout","recentchanges","upload","statistics","lonelypages","wantedpages","allpages","randompage","shortpages","listusers","watchlist","special_pages","editusersettings","asksql") ;
 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" ) ;
1519 $call = $this->mainTitle ;
1620 if ( !in_array ( strtolower ( $call ) , $allowed ) ) {
1721 $this->isSpecialPage = true ;
@@ -43,6 +47,8 @@
4448 $this->title=$s->cur_title ;
4549 $this->makeSecureTitle () ;
4650 $this->contents = $s->cur_text ;
 51+ $this->knownLinkedLinks = explode ( "\n" , $s->cur_linked_links ) ;
 52+ $this->knownUnlinkedLinks = explode ( "\n" , $s->cur_unlinked_links ) ;
4753 }
4854 else $this->contents = "Describe the new page here." ;
4955 }
@@ -77,7 +83,7 @@
7884 while ( $s = mysql_fetch_object ( $result ) ) {
7985 $t = strstr ( $s->cur_title , "/" ) ;
8086 $z = explode ( ":" , $t , 2 ) ;
81 - $t = "[[$t]]" ;
 87+ $t = "[[$t|- ".$this->getNiceTitle(substr($z[count($z)-1],1))."]]" ;
8288 array_push ( $a , $t ) ;
8389 }
8490 if ( $result != "" ) mysql_free_result ( $result ) ;
@@ -152,11 +158,18 @@
153159 }
154160 function setEntry ( $text , $comment , $userID , $userName , $minorEdit ) {
155161 $cond = "cur_title=\"$this->secureTitle\"" ;
 162+
 163+ global $linkedLinks , $unlinkedLinks ;
 164+ $this->parseContents ( $text ) ;
 165+ $ll = implode ( "\n" , array_keys ( $linkedLinks ) ) ;
 166+ $ull = implode ( "\n" , array_keys ( $unlinkedLinks ) ) ;
 167+
156168 $connection = getDBconnection () ;
157169 mysql_select_db ( "wikipedia" , $connection ) ;
158170 $text = str_replace ( "\"" , "\\\"" , $text ) ;
159171 $sql = "UPDATE cur SET cur_text=\"$text\",cur_comment=\"$comment\",cur_user=\"$userID\"," ;
160 - $sql .= "cur_user_text=\"$userName\",cur_minor_edit=\"$minorEdit\" WHERE $cond" ;
 172+ $sql .= "cur_user_text=\"$userName\",cur_minor_edit=\"$minorEdit\",";
 173+ $sql .= "cur_linked_links=\"$ll\",cur_unlinked_links=\"$ull\" WHERE $cond" ;
161174 mysql_query ( $sql , $connection ) ;
162175 mysql_close ( $connection ) ;
163176 }
@@ -165,6 +178,7 @@
166179 function replaceInternalLinks ( $s ) {
167180 global $THESCRIPT ;
168181 global $user , $unlinkedLinks , $linkedLinks ;
 182+ if ( !isset ( $this->knownLinkedLinks ) ) $this->knownLinkedLinks = array () ;
169183 $a = explode ( "[[" , " ".$s ) ;
170184 $s = array_shift ( $a ) ;
171185 $s = substr ( $s , 1 ) ;
@@ -184,7 +198,10 @@
185199 if ( count ( $c ) == 1 ) array_push ( $c , $topic->getMainTitle() ) ;
186200 $text = $c[1] ;
187201
188 - if ( $topic->doesTopicExist( $connection ) ) {
 202+ if ( in_array ( $topic->secureTitle , $this->knownLinkedLinks ) ) $doesItExist = true ;
 203+ else $doesItExist = $topic->doesTopicExist( $connection ) ;
 204+
 205+ if ( $doesItExist ) {
189206 $linkedLinks[$topic->secureTitle]++ ;
190207 if ( $user->options["showHover"] == "yes" ) $hover = "title=\"$link\"" ;
191208 $s .= "<a href=\"$THESCRIPT?title=".urlencode($link)."\" $hover>$text</a>" ;
@@ -460,8 +477,7 @@
461478 $column .= "<br><a href=\"$THESCRIPT?title=special:RecentChanges\">Recent Changes</a>\n" ;
462479 if ( $this->canEdit() ) $column .= "<br><a href=\"$THESCRIPT?action=edit&title=$this->url$editOldVersion\">Edit this page</a>\n" ;
463480
464 -# No user management due to request of Larry
465 -# if ( $this->canDelete() ) $column .= "<br><a href=\"$THESCRIPT?action=deletepage&title=$this->url\">Delete this page</a>\n" ;
 481+ if ( $this->canDelete() ) $column .= "<br><a href=\"$THESCRIPT?title=special:deletepage&target=$this->url\">Delete this page</a>\n" ;
466482 # if ( $this->canProtect() ) $column .= "<br><a href=\"$THESCRIPT?action=protectpage&title=$this->url\">Protect this page</a>\n" ;
467483 # if ( $this->canAdvance() ) $column .= "<br><a href=\"$THESCRIPT?title=special:Advance&topic=$this->safeTitle\">Advance</a>\n" ;
468484
@@ -546,9 +562,9 @@
547563 }
548564
549565 $fc = $user->options["background"] ;
550 - if ( $fc == "" ) $fc = "=white" ;
 566+ if ( $fc == "" ) $fc = "=black" ;
551567 $fc = substr ( $fc , strpos("=",$fc)+1 ) ;
552 - $bc = " bordercolor=".$fc ;
 568+ $bc = " bordercolor=white" ;
553569 $fc = " color=".$fc ;
554570 $result = mysql_query ( $sql , $connection ) ;
555571 if ( $result != "" and $s->old_old_version != 0 ) {
@@ -561,10 +577,10 @@
562578 foreach ( $a1 as $x ) if ( !in_array ( $x , $a2 ) ) array_push ( $nl , htmlentities ( $x ) ) ;
563579 foreach ( $a2 as $x ) if ( !in_array ( $x , $a1 ) ) array_push ( $dl , htmlentities ( $x ) ) ;
564580 # Output
565 - $ret .= "<font color=#0000FF>Blue text</font> was added or changed, <font color=red>red text</font> was changed or deleted." ;
 581+ $ret .= "<font color=#2AAA2A>Green text</font> was added or changed, <font color=#AAAA00>yellow text</font> was changed or deleted." ;
566582 $ret .= "<table width=100% border=1$bc cellspacing=0 cellpadding=2>\n" ;
567 - foreach ( $nl as $x ) $ret .= "<tr><td bgcolor=#0000FF><font$fc>$x</font></td></tr>\n" ;
568 - foreach ( $dl as $x ) $ret .= "<tr><td bgcolor=#DD0000><font$fc>$x</font></td></tr>\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" ;
569585 $ret .= "</table>\n" ;
570586 } 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" ;
571587 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
@@ -3,6 +3,7 @@
44 var $id , $name , $password , $retypePassword ;
55 var $isLoggedIn ;
66 var $options , $email ;
 7+ var $rights ;
78
89 function skin () {
910 if ( $this->options["skin"] == "" ) $this->skinBlank () ;
@@ -84,6 +85,8 @@
8586 $b = explode ( "=" , $x ) ;
8687 $this->options[$b[0]] = $b[1] ;
8788 }
 89+ $t = getMySQL ( "user" , "user_rights" , "user_id=".$this->id ) ;
 90+ $this->rights = explode ( "," , strtolower ( $t ) ) ;
8891 $this->password = getMySQL ( "user" , "user_password" , "user_id=".$this->id ) ;
8992 $this->email = getMySQL ( "user" , "user_email" , "user_id=".$this->id ) ;
9093 $this->skin () ;
Index: trunk/phpwiki/fpw/wikiTitle.php
@@ -19,28 +19,31 @@
2020 return true ;
2121 }
2222 function canDelete () {
23 - global $action ;
 23+ global $action , $user ;
2424 global $oldID ; if ( isset ( $oldID ) ) return false ;
2525 if ( !$this->validateTitle() ) return false ;
2626 if ( $this->isSpecialPage ) return false ;
2727 if ( $this->namespace == "special" ) return false ;
28 - return true ;
 28+ if ( in_array ( "is_sysop" , $user->rights ) ) return true ;
 29+ return false ;
2930 }
3031 function canProtect () {
31 - global $action ;
 32+ global $action , $user ;
3233 global $oldID ; if ( isset ( $oldID ) ) return false ;
3334 if ( !$this->validateTitle() ) return false ;
3435 if ( $this->isSpecialPage ) return false ;
3536 if ( $this->namespace == "special" ) return false ;
36 - return true ;
 37+ if ( in_array ( "is_sysop" , $user->rights ) ) return true ;
 38+ return false ;
3739 }
3840 function canAdvance () {
39 - global $action ;
 41+ global $action , $user ;
4042 global $oldID ; if ( isset ( $oldID ) ) return false ;
4143 if ( !$this->validateTitle() ) return false ;
4244 if ( $this->isSpecialPage ) return false ;
4345 if ( $this->namespace == "special" ) return false ;
44 - return true ;
 46+ if ( in_array ( "is_sysop" , $user->rights ) ) return true ;
 47+ return false ;
4548 }
4649
4750 # Title functions
Index: trunk/phpwiki/fpw/scandb.phtml
@@ -0,0 +1,145 @@
 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+ while (!feof($fd)) {
 23+ $buffer = fgets($fd, 99999);
 24+ array_push ( $t , $buffer ) ;
 25+ }
 26+ fclose ( $fd ) ;
 27+
 28+ array_pop ( $t ) ;
 29+ $t = implode ( "" , $t ) ;
 30+
 31+ #SPLIT PAGE
 32+ $sp = explode ( $FS1 , $t ) ;
 33+
 34+ $x = array_pop ( $sp ) ;
 35+ $sections = explode ( $FS2 , $x ) ;
 36+ foreach ( $sections as $y ) {
 37+ $text = explode ( $FS3 , $y ) ;
 38+ foreach ( $text as $z ) {
 39+ $ret = $z ;
 40+ }
 41+ }
 42+
 43+ return $ret ;
 44+ }
 45+
 46+
 47+
 48+function scantext ( $fn ) {
 49+ $fd = fopen ( $fn , "r" ) ;
 50+ $leadingThree = 0 ;
 51+ $n = 0 ;
 52+ $t = array () ;
 53+ while (!feof($fd)) {
 54+ $buffer = fgets($fd, 4096);
 55+ if ( substr ( $buffer , 0 , 1 ) == "�" ) $leadingThree++ ;
 56+ if ( $leadingThree > 0 ) {
 57+ $t[$n] = $buffer ;
 58+ $n++ ;
 59+ }
 60+ }
 61+ fclose ( $fd ) ;
 62+
 63+ $c1 = $t[0] ;
 64+ $t[0] = substr ( $c1 , strrpos ( $c1 , "�" ) + 2 ) ;
 65+ $c1 = substr ( $c1 , 0 , strrpos ( $c1 , "�" ) + 2 ) ;
 66+
 67+ $c2 = array_pop ( $t ) ;
 68+
 69+ $c1 = explode ( "�" , $c1 ) ;
 70+ $c2 = explode ( "�" , $c2 ) ;
 71+
 72+ $ret = "" ;
 73+ for ( $a = 0 ; $a < $n ; $a++ ) $ret .= $t[$a] ;
 74+ return $ret ;
 75+ }
 76+
 77+function getFileName ( $an ) {
 78+ global $rootDir ;
 79+ $ret = $rootDir ;
 80+ $sd = ucfirst ( substr ( $an , 0 , 1 ) ) ;
 81+ if ( $sd < "A" or $sd > "Z" ) $sd = "other" ;
 82+ $ret .= "$sd/".ucfirst($an).".db" ;
 83+ return $ret ;
 84+ }
 85+
 86+function storeInDB ( $title , $text ) {
 87+ $text = str_replace ( "\\'" , "'" , $text ) ;
 88+ $text = str_replace ( "\\\"" , "\"" , $text ) ;
 89+ $title = str_replace ( "\\'" , "'" , $title ) ;
 90+ $title = str_replace ( "\\\"" , "\"" , $title ) ;
 91+ $npage = new wikiPage ;
 92+ $npage->title = $title ;
 93+ $npage->makeAll () ;
 94+ if ( !$npage->doesTopicExist() ) { $MinorEdit = 2 ; $npage->ensureExistence () ; }
 95+ else $npage->backup() ;
 96+ $npage->setEntry ( $text , "conversion" , 0 , "wikipedia conversion script" , 1 ) ;
 97+ }
 98+
 99+function getTopics ( $dir ) {
 100+ $ret = array () ;
 101+
 102+ $mydir = opendir($dir);
 103+ while ($entry = readdir($mydir)) {
 104+ if ($entry != '.' && $entry != '..') {
 105+ if ( is_dir ( "$dir/$entry" ) ) {
 106+ $a = getTopics ( "$dir/$entry" ) ;
 107+ foreach ( $a as $x ) array_push ( $ret , "$entry/$x" ) ;
 108+ } else {
 109+ $x = substr ( $entry , 0 , strlen ( $entry ) - 3 ) ;
 110+ array_push ( $ret , $x ) ;
 111+ }
 112+ }
 113+ }
 114+ closedir($mydir);
 115+
 116+ return $ret ;
 117+ }
 118+
 119+function dir2DB ( $letter ) {
 120+ global $rootDir ;
 121+ $a = getTopics ( "$rootDir/$letter" ) ;
 122+ foreach ( $a as $an ) {
 123+ print "<b>$an</b><br>\n" ;
 124+ $fn = getFileName ( $an ) ;
 125+ $t = scantext2 ( $fn ) ;
 126+ storeInDB ( $an , $t ) ;
 127+ }
 128+ }
 129+
 130+# MAIN PROGRAM
 131+ global $rootDir ;
 132+ $rootDir = "/home/groups/w/wi/wikipedia/htdocs/fpw/wiki-de/lib-http/db/wiki/page/" ;
 133+
 134+ global $l ;
 135+ if ( !isset ( $l ) ) $l = 65 ;
 136+ if ( $l == "other" ) $letter = "other" ;
 137+ else $letter = chr ( $l ) ;
 138+ $nl = $l+1 ;
 139+ if ( $letter == "Z" ) $nl = "other" ;
 140+
 141+ print "<html><head></head><body>" ;
 142+ dir2DB ( $letter ) ;
 143+ if ( $l != "other" ) print "<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=scandb.phtml?l=$nl\">" ;
 144+ else print "<h1>FINISHED!</h1>" ;
 145+ print "</body></html>" ;
 146+?>
\ No newline at end of file
Property changes on: trunk/phpwiki/fpw/scandb.phtml
___________________________________________________________________
Added: svn:eol-style
1147 + native
Added: svn:keywords
2148 + Author Date Id Revision

Status & tagging log