With &debugmsg=1, PHP output a warning because the link trail no longer
[mediawiki.git] / includes / SpecialAllpages.php
blob054385e122a3e2795abaad69c43f50e8afb3f379
1 <?php
3 function wfSpecialAllpages( $par=NULL )
5 global $indexMaxperpage, $wgRequest;
6 $indexMaxperpage = 480;
7 $from = $wgRequest->getVal( 'from' );
9 if( $par ) {
10 indexShowChunk( $par );
11 } elseif( !is_null( $from ) ) {
12 indexShowChunk( $from );
13 } else {
14 indexShowToplevel();
18 function indexShowToplevel()
20 global $wgOut, $indexMaxperpage, $wgLang;
21 $fname = "indexShowToplevel";
23 # Cache
24 $vsp = $wgLang->getValidSpecialPages();
25 $log = new LogPage( $vsp["Allpages"] );
26 $log->mUpdateRecentChanges = false;
28 global $wgMiserMode;
29 if ( $wgMiserMode ) {
30 $log->showAsDisabledPage();
31 return;
34 $dbr =& wfGetDB( DB_SLAVE );
35 $cur = $dbr->tableName( 'cur' );
36 $fromwhere = "FROM $cur WHERE cur_namespace=0";
37 $order = 'ORDER BY cur_title';
38 $out = "";
39 $where = array( 'cur_namespace' => 0 );
41 $count = $dbr->selectField( 'cur', 'COUNT(*)', $where, $fname );
42 $sections = ceil( $count / $indexMaxperpage );
43 $inpoint = $dbr->selectField( 'cur', 'cur_title', $where, $fname, $order );
45 $out .= "<table>\n";
46 # There's got to be a cleaner way to do this!
47 for( $i = 1; $i < $sections; $i++ ) {
48 $from = $i * $indexMaxperpage;
49 $sql = "SELECT cur_title $fromwhere $order ".$dbr->limitResult(2,$from);
50 $res = $dbr->query( $sql, $fname );
52 $s = $dbr->fetchObject( $res );
53 $outpoint = $s->cur_title;
54 $out .= indexShowline( $inpoint, $outpoint );
56 $s = $dbr->fetchObject( $res );
57 $inpoint = $s->cur_title;
59 $dbr->freeResult( $res );
62 $from = $i * $indexMaxperpage;
63 $sql = "SELECT cur_title $fromwhere $order ".wfLimitResult(1,$count-1);
64 $res = $dbr->query( $sql, $fname );
65 $s = $dbr->fetchObject( $res );
66 $outpoint = $s->cur_title;
67 $out .= indexShowline( $inpoint, $outpoint );
68 $out .= "</table>\n";
70 # Saving cache
71 $log->replaceContent( $out );
73 $wgOut->addHtml( $out );
76 function indexShowline( $inpoint, $outpoint )
78 global $wgOut, $wgLang, $wgUser;
79 $sk = $wgUser->getSkin();
80 $dbr =& wfGetDB( DB_SLAVE );
82 # Fixme: this is ugly
83 $out = wfMsg(
84 "alphaindexline",
85 $sk->makeKnownLink( $wgLang->specialPage( "Allpages" ),
86 str_replace( "_", " ", $inpoint ),
87 "from=" . $dbr->strencode( $inpoint ) ) . "</td><td>",
88 "</td><td align=\"left\">" .
89 str_replace( "_", " ", $outpoint )
91 return "<tr><td align=\"right\">{$out}</td></tr>\n";
94 function indexShowChunk( $from )
96 global $wgOut, $wgUser, $indexMaxperpage, $wgLang;
97 $sk = $wgUser->getSkin();
98 $maxPlusOne = $indexMaxperpage + 1;
100 $out = "";
101 $dbr =& wfGetDB( DB_SLAVE );
102 $cur = $dbr->tableName( 'cur' );
103 $sql = "SELECT cur_title FROM $cur WHERE cur_namespace=0 AND cur_title >= '"
104 . $dbr->strencode( $from ) . "' ORDER BY cur_title LIMIT " . $maxPlusOne;
105 $res = $dbr->query( $sql, "indexShowChunk" );
107 ### FIXME: side link to previous
109 $n = 0;
110 $out = "<table border=\"0\" width=\"100%\">\n";
111 while( ($n < $indexMaxperpage) && ($s = $dbr->fetchObject( $res )) ) {
112 $t = Title::makeTitle( 0, $s->cur_title );
113 if( $t ) {
114 $link = $sk->makeKnownLinkObj( $t );
115 } else {
116 $link = "[[" . htmlspecialchars( $s->cur_title ) . "]]";
118 if( $n % 3 == 0 ) {
119 $out .= "<tr>\n";
121 $out .= "<td>$link</td>";
122 $n++;
123 if( $n % 3 == 0 ) {
124 $out .= "</tr>\n";
127 if( ($n % 3) != 0 ) {
128 $out .= "</tr>\n";
130 $out .= "</table>";
132 $out2 = "<div style='text-align: right; font-size: smaller; margin-bottom: 1em;'>" .
133 $sk->makeKnownLink( $wgLang->specialPage( "Allpages" ),
134 wfMsg ( 'allpages' ) );
135 if ( ($n == $indexMaxperpage) && ($s = $dbr->fetchObject( $res )) ) {
136 $out2 .= " | " . $sk->makeKnownLink(
137 $wgLang->specialPage( "Allpages" ),
138 wfMsg ( 'nextpage', $s->cur_title ),
139 "from=" . $dbr->strencode( $s->cur_title ) );
141 $out2 .= "</div>";
143 $wgOut->addHtml( $out2 . $out );