proper CSS class for sitesupport link
[mediawiki.git] / includes / QueryPage.php
blob50f34c340553a3b629bbfe8ac9e813994d358d9d
1 <?
3 include_once ( "LogPage.php" ) ;
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.
9 class QueryPage {
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.
15 function getName() {
16 return "";
19 # Subclasses return a SQL query here.
21 function getSQL( $offset, $limit ) {
22 return "";
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.
29 function isExpensive( ) {
30 return 0;
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.
37 function formatResult( $skin, $result ) {
38 return "";
41 # This is the actual workhorse. It does everything needed to make a
42 # real, honest-to-gosh query page.
44 function doQuery( $offset, $limit ) {
46 global $wgUser, $wgOut, $wgLang, $wgMiserMode;
48 $sname = $this->getName();
49 $fname = get_class($this) . "::doQuery";
51 if ( $this->isExpensive( ) ) {
53 $vsp = $wgLang->getValidSpecialPages();
54 $logpage = new LogPage( $vsp[$sname] );
55 $logpage->mUpdateRecentChanges = false;
57 if ( $wgMiserMode ) {
58 $logpage->showAsDisabledPage();
59 return;
63 $sql = $this->getSQL( $offset, $limit );
65 $res = wfQuery( $sql, DB_READ, $fname );
67 $sk = $wgUser->getSkin( );
69 $top = wfShowingResults( $offset, $limit );
70 $wgOut->addHTML( "<p>{$top}\n" );
72 $sl = wfViewPrevNext( $offset, $limit, $wgLang->specialPage( $sname ) );
73 $wgOut->addHTML( "<br>{$sl}\n" );
75 $s = "<ol start=" . ( $offset + 1 ) . ">";
76 while ( $obj = wfFetchObject( $res ) ) {
77 $format = $this->formatResult( $sk, $obj );
78 $s .= "<li>{$format}</li>\n";
80 wfFreeResult( $res );
81 $s .= "</ol>";
82 $wgOut->addHTML( $s );
83 $wgOut->addHTML( "<p>{$sl}\n" );
85 # Saving cache
87 if ( $this->isExpensive() && $offset == 0 && $limit >= 50 ) {
88 $logpage->replaceContent( $s );
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.
97 class PageQueryPage extends QueryPage {
99 function formatResult( $skin, $result ) {
100 return $skin->makeKnownLink( $result->cur_title, "" );