Index: trunk/phase3/includes/SpecialAllpages.php |
— | — | @@ -2,25 +2,58 @@ |
3 | 3 | |
4 | 4 | function wfSpecialAllpages( $par=NULL ) |
5 | 5 | { |
6 | | - global $indexMaxperpage, $wgRequest; |
| 6 | + global $indexMaxperpage, $toplevelMaxperpage, $wgRequest, $wgOut, $wgLang; |
7 | 7 | $indexMaxperpage = 480; |
| 8 | + $toplevelMaxperpage = 50; |
8 | 9 | $from = $wgRequest->getVal( 'from' ); |
9 | 10 | $namespace = $wgRequest->getVal( 'namespace' ); |
10 | 11 | if ( is_null($namespace) ) { $namespace = 0; } |
| 12 | + $arr = $wgLang->getNamespaces(); |
| 13 | + $wgOut->setPagetitle ( $namespace > 0 ? wfMsg ( 'allpagesnamespace', $arr[$namespace] ) |
| 14 | + : wfMsg ( 'allarticles' ) ); |
11 | 15 | |
12 | | - if( $par ) { |
| 16 | + if ( $par ) { |
13 | 17 | indexShowChunk( $par, $namespace ); |
14 | | - } elseif( !is_null( $from ) ) { |
| 18 | + } elseif ( $from ) { |
15 | 19 | indexShowChunk( $from, $namespace ); |
16 | 20 | } else { |
17 | | - indexShowToplevel(); |
| 21 | + indexShowToplevel ( $namespace ); |
18 | 22 | } |
19 | 23 | } |
20 | 24 | |
21 | | -function indexShowToplevel() |
| 25 | +function namespaceForm ( $namespace = 0, $from = "" ) |
22 | 26 | { |
23 | | - global $wgOut, $indexMaxperpage, $wgLang; |
| 27 | + global $wgLang, $wgScript; |
| 28 | + |
| 29 | + $t = Title::makeTitle( NS_SPECIAL, "Allpages" ); |
| 30 | + |
| 31 | + $namespaceselect = '<select name="namespace">'; |
| 32 | + $arr = $wgLang->getNamespaces(); |
| 33 | + for ( $i = 0; $i < 14; $i++ ) { |
| 34 | + $namespacename = str_replace ( "_", " ", $arr[$i] ); |
| 35 | + $n = ($i == 0) ? wfMsg ( 'articlenamespace' ) : $namespacename; |
| 36 | + $sel = ($i == $namespace) ? ' selected="selected"' : ''; |
| 37 | + $namespaceselect .= "<option value='{$i}'{$sel}>{$n}</option>"; |
| 38 | + } |
| 39 | + $namespaceselect .= '</select>'; |
| 40 | + |
| 41 | + $frombox = '<input type="text" size="20" name="from" value="' |
| 42 | + . htmlspecialchars ( $from ) . '"/>'; |
| 43 | + $submitbutton = '<input type="submit" value="' . wfMsg( 'go' ) . '" />'; |
| 44 | + |
| 45 | + $out = "<div class='namespaceselector'><form method='get' action='{$wgScript}'>"; |
| 46 | + $out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />'; |
| 47 | + $out .= wfMsg ( 'allpagesformtext', $frombox, $namespaceselect, $submitbutton ); |
| 48 | + $out .= '</form></div>'; |
| 49 | + return $out; |
| 50 | +} |
| 51 | + |
| 52 | +function indexShowToplevel ( $namespace = 0 ) |
| 53 | +{ |
| 54 | + global $wgOut, $indexMaxperpage, $toplevelMaxperpage, $wgLang, $wgRequest, $wgUser; |
| 55 | + $sk = $wgUser->getSkin(); |
24 | 56 | $fname = "indexShowToplevel"; |
| 57 | + $namespace = intval ($namespace); |
25 | 58 | |
26 | 59 | # Cache |
27 | 60 | $vsp = $wgLang->getValidSpecialPages(); |
— | — | @@ -35,62 +68,109 @@ |
36 | 69 | |
37 | 70 | $dbr =& wfGetDB( DB_SLAVE ); |
38 | 71 | $cur = $dbr->tableName( 'cur' ); |
39 | | - $fromwhere = "FROM $cur WHERE cur_namespace=0"; |
40 | | - $order = 'ORDER BY cur_title'; |
| 72 | + $fromwhere = "FROM $cur WHERE cur_namespace=$namespace"; |
| 73 | + $order_arr = array ( 'ORDER BY' => 'cur_title' ); |
| 74 | + $order_str = 'ORDER BY cur_title'; |
41 | 75 | $out = ""; |
42 | | - $where = array( 'cur_namespace' => 0 ); |
| 76 | + $where = array( 'cur_namespace' => $namespace ); |
43 | 77 | |
44 | 78 | $count = $dbr->selectField( 'cur', 'COUNT(*)', $where, $fname ); |
45 | 79 | $sections = ceil( $count / $indexMaxperpage ); |
46 | | - $inpoint = $dbr->selectField( 'cur', 'cur_title', $where, $fname, $order ); |
47 | 80 | |
48 | | - $out .= "<table>\n"; |
49 | | - # There's got to be a cleaner way to do this! |
50 | | - for( $i = 1; $i < $sections; $i++ ) { |
51 | | - $from = $i * $indexMaxperpage; |
52 | | - $sql = "SELECT cur_title $fromwhere $order ".$dbr->limitResult(2,$from); |
53 | | - $res = $dbr->query( $sql, $fname ); |
| 81 | + # We want to display $toplevelMaxperpage lines starting at $offset. |
| 82 | + # NOTICE: $offset starts at 0 |
| 83 | + $offset = intval ( $wgRequest->getVal( 'offset' ) ); |
| 84 | + if ( $offset < 0 ) { $offset = 0; } |
| 85 | + if ( $offset >= $sections ) { $offset = $sections - 1; } |
54 | 86 | |
55 | | - $s = $dbr->fetchObject( $res ); |
56 | | - $outpoint = $s->cur_title; |
57 | | - $out .= indexShowline( $inpoint, $outpoint ); |
| 87 | + # Where to stop? Notice that this can take the value of $sections, but $offset can't, because if |
| 88 | + # we're displaying only the very last section, we still need two DB queries to find the titles |
| 89 | + $stopat = ( $offset + $toplevelMaxperpage < $sections ) |
| 90 | + ? $offset + $toplevelMaxperpage : $sections ; |
58 | 91 | |
| 92 | + # This array is going to hold the cur_titles in order. |
| 93 | + $lines = array(); |
| 94 | + |
| 95 | + # If we are going to show n rows, we need n+1 queries to find the relevant titles. |
| 96 | + for ( $i = $offset; $i <= $stopat; $i++ ) { |
| 97 | + if ( $i == $sections ) # if we're displaying the last section, we need to |
| 98 | + $from = $count-1; # find the last cur_title in the DB |
| 99 | + else if ( $i > $offset ) |
| 100 | + $from = $i * $indexMaxperpage - 1; |
| 101 | + else |
| 102 | + $from = $i * $indexMaxperpage; |
| 103 | + $limit = ( $i == $offset || $i == $stopat ) ? 1 : 2; |
| 104 | + $sql = "SELECT cur_title $fromwhere $order_str " . $dbr->limitResult ( $limit, $from ); |
| 105 | + echo "($offset/$stopat) $sql<br>\n"; |
| 106 | + $res = $dbr->query( $sql, $fname ); |
59 | 107 | $s = $dbr->fetchObject( $res ); |
60 | | - $inpoint = $s->cur_title; |
61 | | - |
| 108 | + array_push ( $lines, $s->cur_title ); |
| 109 | + if ( $s = $dbr->fetchObject( $res ) ) { |
| 110 | + array_push ( $lines, $s->cur_title ); |
| 111 | + } |
62 | 112 | $dbr->freeResult( $res ); |
63 | 113 | } |
64 | 114 | |
65 | | - $from = $i * $indexMaxperpage; |
66 | | - $sql = "SELECT cur_title $fromwhere $order ".wfLimitResult(1,$count-1); |
67 | | - $res = $dbr->query( $sql, $fname ); |
68 | | - $s = $dbr->fetchObject( $res ); |
69 | | - $outpoint = $s->cur_title; |
70 | | - $out .= indexShowline( $inpoint, $outpoint ); |
71 | | - $out .= "</table>\n"; |
| 115 | + # At this point, $lines should contain an even number of elements. |
| 116 | + $out .= "<table style='background: inherit;'>"; |
| 117 | + while ( count ( $lines ) > 0 ) { |
| 118 | + $inpoint = array_shift ( $lines ); |
| 119 | + $outpoint = array_shift ( $lines ); |
| 120 | + $out .= indexShowline ( $inpoint, $outpoint, $namespace ); |
| 121 | + } |
| 122 | + $out .= "</table>"; |
72 | 123 | |
| 124 | + $nsForm = namespaceForm ( $namespace ); |
| 125 | + |
| 126 | + # Is there more? |
| 127 | + $morelinks = ""; |
| 128 | + if ( $offset > 0 ) { |
| 129 | + $morelinks = $sk->makeKnownLink ( |
| 130 | + $wgLang->specialPage ( "Allpages" ), |
| 131 | + wfMsg ( 'allpagesprev' ), |
| 132 | + ( $offset > $toplevelMaxperpage ) ? 'offset='.($offset-$toplevelMaxperpage) : '' |
| 133 | + ); |
| 134 | + } |
| 135 | + if ( $stopat < $sections-1 ) { |
| 136 | + if ( $morelinks != "" ) { $morelinks .= " | "; } |
| 137 | + $morelinks .= $sk->makeKnownLink ( |
| 138 | + $wgLang->specialPage ( "Allpages" ), |
| 139 | + wfMsg ( 'allpagesnext' ), |
| 140 | + 'offset=' . ($offset + $toplevelMaxperpage) |
| 141 | + ); |
| 142 | + } |
| 143 | + |
| 144 | + if ( $morelinks != "" ) { |
| 145 | + $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">'; |
| 146 | + $out2 .= '<tr valign="top"><td align="left">' . $nsForm; |
| 147 | + $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">'; |
| 148 | + $out2 .= $morelinks . '</td></tr></table><hr />'; |
| 149 | + } else { |
| 150 | + $out2 = $nsForm . '<hr />'; |
| 151 | + } |
| 152 | + |
73 | 153 | # Saving cache |
74 | 154 | $log->replaceContent( $out ); |
75 | 155 | |
76 | | - $wgOut->addHtml( $out ); |
| 156 | + $wgOut->addHtml( $out2 . $out ); |
77 | 157 | } |
78 | 158 | |
79 | | -function indexShowline( $inpoint, $outpoint ) |
| 159 | +function indexShowline( $inpoint, $outpoint, $namespace = 0 ) |
80 | 160 | { |
81 | 161 | global $wgOut, $wgLang, $wgUser; |
82 | 162 | $sk = $wgUser->getSkin(); |
83 | 163 | $dbr =& wfGetDB( DB_SLAVE ); |
84 | 164 | |
85 | | - # Fixme: this is ugly |
| 165 | + $inpointf = str_replace( "_", " ", $inpoint ); |
| 166 | + $outpointf = str_replace( "_", " ", $outpoint ); |
| 167 | + $queryparams = 'from=' . $dbr->strencode( $inpoint ); |
| 168 | + if ( $namespace > 0 ) { $queryparams .= '&namespace='.intval($namespace); } |
86 | 169 | $out = wfMsg( |
87 | | - "alphaindexline", |
88 | | - $sk->makeKnownLink( $wgLang->specialPage( "Allpages" ), |
89 | | - str_replace( "_", " ", $inpoint ), |
90 | | - "from=" . $dbr->strencode( $inpoint ) ) . "</td><td>", |
91 | | - "</td><td align=\"left\">" . |
92 | | - str_replace( "_", " ", $outpoint ) |
93 | | - ); |
94 | | - return "<tr><td align=\"right\">{$out}</td></tr>\n"; |
| 170 | + 'alphaindexline', |
| 171 | + $sk->makeKnownLink( $wgLang->specialPage( "Allpages" ), $inpointf, $queryparams ) . '</td><td>', |
| 172 | + '</td><td align="left">' . $outpointf |
| 173 | + ); |
| 174 | + return '<tr><td align="right">'.$out.'</td></tr>'; |
95 | 175 | } |
96 | 176 | |
97 | 177 | function indexShowChunk( $from, $namespace = 0 ) |
— | — | @@ -110,38 +190,41 @@ |
111 | 191 | ### FIXME: side link to previous |
112 | 192 | |
113 | 193 | $n = 0; |
114 | | - $out = "<table border=\"0\" width=\"100%\">\n"; |
| 194 | + $out = '<table style="background: inherit;" border="0" width="100%">'; |
115 | 195 | while( ($n < $indexMaxperpage) && ($s = $dbr->fetchObject( $res )) ) { |
116 | 196 | $t = Title::makeTitle( $namespacee, $s->cur_title ); |
117 | 197 | if( $t ) { |
118 | | - $link = $sk->makeKnownLinkObj( $t ); |
| 198 | + $link = $sk->makeKnownLinkObj( $t, $t->getText() ); |
119 | 199 | } else { |
120 | | - $link = "[[" . htmlspecialchars( $s->cur_title ) . "]]"; |
| 200 | + $link = '[[' . htmlspecialchars( $s->cur_title ) . ']]'; |
121 | 201 | } |
122 | 202 | if( $n % 3 == 0 ) { |
123 | | - $out .= "<tr>\n"; |
| 203 | + $out .= '<tr>'; |
124 | 204 | } |
125 | 205 | $out .= "<td>$link</td>"; |
126 | 206 | $n++; |
127 | 207 | if( $n % 3 == 0 ) { |
128 | | - $out .= "</tr>\n"; |
| 208 | + $out .= '</tr>'; |
129 | 209 | } |
130 | 210 | } |
131 | 211 | if( ($n % 3) != 0 ) { |
132 | | - $out .= "</tr>\n"; |
| 212 | + $out .= '</tr>'; |
133 | 213 | } |
134 | | - $out .= "</table>"; |
| 214 | + $out .= '</table>'; |
135 | 215 | |
136 | | - $out2 = "<div style='text-align: right; font-size: smaller; margin-bottom: 1em;'>" . |
| 216 | + $nsForm = namespaceForm ( $namespace, $from ); |
| 217 | + $out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">'; |
| 218 | + $out2 .= '<tr valign="top"><td align="left">' . $nsForm; |
| 219 | + $out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">' . |
137 | 220 | $sk->makeKnownLink( $wgLang->specialPage( "Allpages" ), |
138 | 221 | wfMsg ( 'allpages' ) ); |
139 | 222 | if ( ($n == $indexMaxperpage) && ($s = $dbr->fetchObject( $res )) ) { |
140 | 223 | $out2 .= " | " . $sk->makeKnownLink( |
141 | 224 | $wgLang->specialPage( "Allpages" ), |
142 | 225 | wfMsg ( 'nextpage', $s->cur_title ), |
143 | | - "from=" . $dbr->strencode( $s->cur_title ) ); |
| 226 | + "from=" . wfUrlEncode ( $s->cur_title ) ); |
144 | 227 | } |
145 | | - $out2 .= "</div>"; |
| 228 | + $out2 .= "</td></tr></table><hr />"; |
146 | 229 | |
147 | 230 | $wgOut->addHtml( $out2 . $out ); |
148 | 231 | } |
Index: trunk/phase3/languages/Language.php |
— | — | @@ -971,7 +971,6 @@ |
972 | 972 | 'wantedpages' => 'Wanted pages', |
973 | 973 | 'nlinks' => '$1 links', |
974 | 974 | 'allpages' => 'All pages', |
975 | | -'nextpage' => 'Next page ($1)', |
976 | 975 | 'randompage' => 'Random page', |
977 | 976 | 'shortpages' => 'Short pages', |
978 | 977 | 'longpages' => 'Long pages', |
— | — | @@ -1006,6 +1005,15 @@ |
1007 | 1006 | 'alphaindexline' => "$1 to $2", |
1008 | 1007 | 'version' => 'Version', |
1009 | 1008 | |
| 1009 | +# Specific to All pages |
| 1010 | +'nextpage' => 'Next page ($1)', |
| 1011 | +'articlenamespace' => '(articles)', |
| 1012 | +'allpagesformtext' => 'Display pages starting at: $1 Choose namespace: $2 $3', |
| 1013 | +'allarticles' => 'All articles', |
| 1014 | +'allpagesprev' => 'Previous', |
| 1015 | +'allpagesnext' => 'Next', |
| 1016 | +'allpagesnamespace' => 'All pages ($1 namespace)', |
| 1017 | + |
1010 | 1018 | # Email this user |
1011 | 1019 | # |
1012 | 1020 | 'mailnologin' => 'No send address', |