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