Feature-Request #816659,#668443: No (next 50) link if there is no next page
[lhc/web/wiklou.git] / includes / QueryPage.php
1 <?
2
3 include_once ( "LogPage.php" ) ;
4
5 # This is a class for doing query pages; since they're almost all the same,
6 # we factor out some of the functionality into a superclass, and let
7 # subclasses derive from it.
8
9 class QueryPage {
10
11 # Subclasses return their name here. Make sure the name is also
12 # specified in Language.php, both in the $wgValidSpecialPagesEn
13 # variable, and as a language message param.
14
15 function getName() {
16 return "";
17 }
18
19 # Subclasses return a SQL query here.
20
21 function getSQL( $offset, $limit ) {
22 return "";
23 }
24
25 # Is this query expensive (for some definition of expensive)? Then we
26 # don't let it run in miser mode. The default is 0. Expensive
27 # subqueries should override this.
28
29 function isExpensive( ) {
30 return 0;
31 }
32
33 # Formats the results of the query for display. The skin is the current
34 # skin; you can use it for making links. The result is a single row of
35 # result data. You should be able to grab SQL results off of it.
36
37 function formatResult( $skin, $result ) {
38 return "";
39 }
40
41 # This is the actual workhorse. It does everything needed to make a
42 # real, honest-to-gosh query page.
43
44 function doQuery( $offset, $limit ) {
45
46 global $wgUser, $wgOut, $wgLang, $wgMiserMode;
47
48 $sname = $this->getName();
49 $fname = get_class($this) . "::doQuery";
50
51 if ( $this->isExpensive( ) ) {
52
53 $vsp = $wgLang->getValidSpecialPages();
54 $logpage = new LogPage( $vsp[$sname] );
55 $logpage->mUpdateRecentChanges = false;
56
57 if ( $wgMiserMode ) {
58 $logpage->showAsDisabledPage();
59 return;
60 }
61 }
62
63 $sql = $this->getSQL( $offset, $limit+1 );
64
65 $res = wfQuery( $sql, DB_READ, $fname );
66
67 $sk = $wgUser->getSkin( );
68
69 $top = wfShowingResults( $offset, $limit );
70 $wgOut->addHTML( "<p>{$top}\n" );
71
72 $sl = wfViewPrevNext( $offset, $limit, $wgLang->specialPage( $sname ), "",
73 wfNumRows( $res ) < ($limit+1) );
74 $wgOut->addHTML( "<br>{$sl}\n" );
75
76 $s = "<ol start=" . ( $offset + 1 ) . ">";
77 $i = 0;
78 while ( ($i<$limit) && ($obj = wfFetchObject( $res )) ) {
79 $format = $this->formatResult( $sk, $obj );
80 $s .= "<li>{$format}</li>\n";
81 $i++;
82 }
83 wfFreeResult( $res );
84 $s .= "</ol>";
85 $wgOut->addHTML( $s );
86 $wgOut->addHTML( "<p>{$sl}\n" );
87
88 # Saving cache
89
90 if ( $this->isExpensive() && $offset == 0 && $limit >= 50 ) {
91 $logpage->replaceContent( $s );
92 }
93 }
94 }
95
96 # This is a subclass for very simple queries that are just looking for page
97 # titles that match some criteria. It formats each result item as a link to
98 # that page.
99
100 class PageQueryPage extends QueryPage {
101
102 function formatResult( $skin, $result ) {
103 return $skin->makeKnownLink( $result->cur_title, "" );
104 }
105 }
106
107 ?>