r185 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r184‎ | r185 | r186 >
Date:16:01, 22 February 2002
Author:hidders
Status:old
Tags:
Comment:
optimizing database access
Modified paths:
  • /trunk/phpwiki/fpw/special_lonelypages.php (modified) (history)

Diff [purge]

Index: trunk/phpwiki/fpw/special_lonelypages.php
@@ -1,37 +1,49 @@
22 <?
 3+
34 function LonelyPages () {
4 - global $THESCRIPT ;
5 - global $linkedLinks , $unlinkedLinks , $vpage ;
6 - global $wikiLonelyPagesTitle , $wikiLonelyPagesText , $wikiTalk , $wikiUser ;
7 - $vpage->special ( $wikiLonelyPagesTitle ) ;
8 - $vpage->namespace = "" ;
9 - $allPages = array () ;
10 - $ret = $wikiLonelyPagesText ;
 5+ global $THESCRIPT ;
 6+ global $linkedLinks , $unlinkedLinks , $vpage ;
 7+ global $wikiLonelyPagesTitle , $wikiLonelyPagesText , $wikiTalk , $wikiUser ;
 8+
 9+ $vpage->special ( $wikiLonelyPagesTitle ) ;
 10+ $vpage->namespace = "" ;
 11+ $allPages = array () ;
 12+ $ret = $wikiLonelyPagesText ;
1113
12 - $connection = getDBconnection () ;
13 -# $sql = "SELECT cur_title,cur_linked_links,cur_unlinked_links FROM cur WHERE cur_title NOT LIKE \"User:%\" AND cur_title NOT LIKE \"%alk:%\" AND cur_text NOT LIKE \"#redirect%\" AND cur_text != \"\"" ;
14 - $sql = "SELECT cur_title,cur_linked_links,cur_unlinked_links FROM cur WHERE cur_title NOT LIKE \"".ucfirstIntl($wikiUser).":%\" AND cur_title NOT LIKE \"%" . substr($wikiTalk,2) . "%:%\" AND cur_text NOT LIKE \"#redirect%\" AND cur_text != \"\"" ;
15 - $result = mysql_query ( $sql , $connection ) ;
16 - while ( $s = mysql_fetch_object ( $result ) ) {
17 - $allPages[ucfirstIntl($s->cur_title)] = $allPages[ucfirstIntl($s->cur_title)] * 1 ;
18 - $u = explode ( "\n" , $s->cur_linked_links ) ; foreach ( $u as $x ) $allPages[ucfirstIntl($x)] += 1 ;
19 - $u = explode ( "\n" , $s->cur_unlinked_links ) ; foreach ( $u as $x ) $allPages[ucfirstIntl($x)] += 1 ;
20 - }
21 - if ( $result != false ) mysql_free_result ( $result ) ;
 14+ $connection = getDBconnection () ;
 15+ $sql1 = "SELECT cur_title
 16+ FROM cur
 17+ WHERE cur_title NOT LIKE \"".ucfirstIntl($wikiUser).":%\"
 18+ AND cur_title NOT LIKE \"%" . substr($wikiTalk,2) . "%:%\"
 19+ AND cur_text NOT LIKE \"#redirect%\"
 20+ AND cur_text != \"\"
 21+ ORDER BY cur_title " ;
 22+ $result1 = mysql_query ( $sql1 , $connection ) ;
 23+
 24+ $sql2 = "SELECT DISTINCT linked_to
 25+ FROM linked
 26+ ORDER BY linked_to " ;
 27+ $result2 = mysql_query ( $sql2 , $connection ) ;
 28+
 29+ # now we "merge" the two results while removing from the first list the ones in the second
 30+ $s1 = mysql_fetch_object ( $result1 ) ;
 31+ $s2 = mysql_fetch_object ( $result2 ) ;
 32+ while ( $s1 and $s2 ) {
 33+ if ( $s1->cur_title < $s2->linked_to ) {
 34+ $ret .= "# [[$s1->cur_title|".$vpage->getNiceTitle($s1->cur_title)."]]<br>\n" ;
 35+ $s1 = mysql_fetch_object ( $result1 ) ;
 36+ } elseif ( $s1->cur_title > $s2->linked_to ) {
 37+ $s2 = mysql_fetch_object ( $result2 ) ;
 38+ } else {
 39+ $s1 = mysql_fetch_object ( $result1 ) ;
 40+ $s2 = mysql_fetch_object ( $result2 ) ;
 41+ }
 42+ }
 43+ while ( $s1 ) {
 44+ $ret .= "# [[$s1->cur_title|".$vpage->getNiceTitle($s1->cur_title)."]]<br>\n" ;
 45+ $s1 = mysql_fetch_object ( $result1 ) ;
 46+ }
2247
23 - asort ( $allPages ) ;
24 -# $allPages = array_slice ( $allPages , 0 , 50 ) ;
25 -
26 - $orphans = array () ;
27 - $v = array_keys ( $allPages ) ;
28 - foreach ( $v as $x ) {
29 - if ( $allPages[$x] == 0 )
30 - array_push ( $orphans , $x ) ;
31 - }
32 -
33 - asort ( $orphans ) ;
34 - foreach ( $orphans as $x )
35 - $ret .= "# [[$x|".$vpage->getNiceTitle($x)."]]<br>\n" ;
36 - return $ret ;
37 - }
 48+ return $ret ;
 49+}
3850 ?>

Status & tagging log