Allow an optional &namespace= parameter for Special:Allpages.
[lhc/web/wiklou.git] / includes / SpecialAllpages.php
1 <?php
2
3 function wfSpecialAllpages( $par=NULL )
4 {
5 global $indexMaxperpage, $wgRequest;
6 $indexMaxperpage = 480;
7 $from = $wgRequest->getVal( 'from' );
8 $namespace = $wgRequest->getVal( 'namespace' );
9 if ( is_null($namespace) ) { $namespace = 0; }
10
11 if( $par ) {
12 indexShowChunk( $par, $namespace );
13 } elseif( !is_null( $from ) ) {
14 indexShowChunk( $from, $namespace );
15 } else {
16 indexShowToplevel();
17 }
18 }
19
20 function indexShowToplevel()
21 {
22 global $wgOut, $indexMaxperpage, $wgLang;
23 $fname = "indexShowToplevel";
24
25 # Cache
26 $vsp = $wgLang->getValidSpecialPages();
27 $log = new LogPage( $vsp["Allpages"] );
28 $log->mUpdateRecentChanges = false;
29
30 global $wgMiserMode;
31 if ( $wgMiserMode ) {
32 $log->showAsDisabledPage();
33 return;
34 }
35
36 $dbr =& wfGetDB( DB_SLAVE );
37 $cur = $dbr->tableName( 'cur' );
38 $fromwhere = "FROM $cur WHERE cur_namespace=0";
39 $order = 'ORDER BY cur_title';
40 $out = "";
41 $where = array( 'cur_namespace' => 0 );
42
43 $count = $dbr->selectField( 'cur', 'COUNT(*)', $where, $fname );
44 $sections = ceil( $count / $indexMaxperpage );
45 $inpoint = $dbr->selectField( 'cur', 'cur_title', $where, $fname, $order );
46
47 $out .= "<table>\n";
48 # There's got to be a cleaner way to do this!
49 for( $i = 1; $i < $sections; $i++ ) {
50 $from = $i * $indexMaxperpage;
51 $sql = "SELECT cur_title $fromwhere $order ".$dbr->limitResult(2,$from);
52 $res = $dbr->query( $sql, $fname );
53
54 $s = $dbr->fetchObject( $res );
55 $outpoint = $s->cur_title;
56 $out .= indexShowline( $inpoint, $outpoint );
57
58 $s = $dbr->fetchObject( $res );
59 $inpoint = $s->cur_title;
60
61 $dbr->freeResult( $res );
62 }
63
64 $from = $i * $indexMaxperpage;
65 $sql = "SELECT cur_title $fromwhere $order ".wfLimitResult(1,$count-1);
66 $res = $dbr->query( $sql, $fname );
67 $s = $dbr->fetchObject( $res );
68 $outpoint = $s->cur_title;
69 $out .= indexShowline( $inpoint, $outpoint );
70 $out .= "</table>\n";
71
72 # Saving cache
73 $log->replaceContent( $out );
74
75 $wgOut->addHtml( $out );
76 }
77
78 function indexShowline( $inpoint, $outpoint )
79 {
80 global $wgOut, $wgLang, $wgUser;
81 $sk = $wgUser->getSkin();
82 $dbr =& wfGetDB( DB_SLAVE );
83
84 # Fixme: this is ugly
85 $out = wfMsg(
86 "alphaindexline",
87 $sk->makeKnownLink( $wgLang->specialPage( "Allpages" ),
88 str_replace( "_", " ", $inpoint ),
89 "from=" . $dbr->strencode( $inpoint ) ) . "</td><td>",
90 "</td><td align=\"left\">" .
91 str_replace( "_", " ", $outpoint )
92 );
93 return "<tr><td align=\"right\">{$out}</td></tr>\n";
94 }
95
96 function indexShowChunk( $from, $namespace = 0 )
97 {
98 global $wgOut, $wgUser, $indexMaxperpage, $wgLang;
99 $sk = $wgUser->getSkin();
100 $maxPlusOne = $indexMaxperpage + 1;
101 $namespacee = intval($namespace);
102
103 $out = "";
104 $dbr =& wfGetDB( DB_SLAVE );
105 $cur = $dbr->tableName( 'cur' );
106 $sql = "SELECT cur_title FROM $cur WHERE cur_namespace=$namespacee AND cur_title >= '"
107 . $dbr->strencode( $from ) . "' ORDER BY cur_title LIMIT " . $maxPlusOne;
108 $res = $dbr->query( $sql, "indexShowChunk" );
109
110 ### FIXME: side link to previous
111
112 $n = 0;
113 $out = "<table border=\"0\" width=\"100%\">\n";
114 while( ($n < $indexMaxperpage) && ($s = $dbr->fetchObject( $res )) ) {
115 $t = Title::makeTitle( $namespacee, $s->cur_title );
116 if( $t ) {
117 $link = $sk->makeKnownLinkObj( $t );
118 } else {
119 $link = "[[" . htmlspecialchars( $s->cur_title ) . "]]";
120 }
121 if( $n % 3 == 0 ) {
122 $out .= "<tr>\n";
123 }
124 $out .= "<td>$link</td>";
125 $n++;
126 if( $n % 3 == 0 ) {
127 $out .= "</tr>\n";
128 }
129 }
130 if( ($n % 3) != 0 ) {
131 $out .= "</tr>\n";
132 }
133 $out .= "</table>";
134
135 $out2 = "<div style='text-align: right; font-size: smaller; margin-bottom: 1em;'>" .
136 $sk->makeKnownLink( $wgLang->specialPage( "Allpages" ),
137 wfMsg ( 'allpages' ) );
138 if ( ($n == $indexMaxperpage) && ($s = $dbr->fetchObject( $res )) ) {
139 $out2 .= " | " . $sk->makeKnownLink(
140 $wgLang->specialPage( "Allpages" ),
141 wfMsg ( 'nextpage', $s->cur_title ),
142 "from=" . $dbr->strencode( $s->cur_title ) );
143 }
144 $out2 .= "</div>";
145
146 $wgOut->addHtml( $out2 . $out );
147 }
148
149 ?>