I was adding a special page (dead-end pages), and I realized that almost all
[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 );
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 $wgOut->addHTML( "<br>{$sl}\n" );
74
75 $s = "<ol start=" . ( $offset + 1 ) . ">";
76 while ( $obj = wfFetchObject( $res ) ) {
77 $format = $this->formatResult( $sk, $obj );
78 $s .= "<li>{$format}</li>\n";
79 }
80 wfFreeResult( $res );
81 $s .= "</ol>";
82 $wgOut->addHTML( $s );
83 $wgOut->addHTML( "<p>{$sl}\n" );
84
85 # Saving cache
86
87 if ( $this->isExpensive() && $offset == 0 && $limit >= 50 ) {
88 $logpage->replaceContent( $s );
89 }
90 }
91 }
92
93 # This is a subclass for very simple queries that are just looking for page
94 # titles that match some criteria. It formats each result item as a link to
95 # that page.
96
97 class PageQueryPage extends QueryPage {
98
99 function formatResult( $skin, $result ) {
100 return $skin->makeKnownLink( $result->cur_title, "" );
101 }
102 }
103
104 ?>