3 require_once ( "Feed.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.
10 # Subclasses return their name here. Make sure the name is also
11 # specified in SpecialPage.php and in Language.php as a language message param.
17 # Subclasses return an SQL query here.
19 # Note that the query itself should return the following three columns:
20 # 'type' (your special page's name), 'namespace, 'title', and 'value'
21 # (numeric) *in that order*. These may be stored in the querycache table
22 # for expensive queries, and that cached data will be returned sometimes,
23 # so the presence of extra fields can't be relied on.
25 # Don't include an ORDER or LIMIT clause, this will be added.
28 return "SELECT 'sample' as type, 0 as namespace, 'Sample result' as title, 42 as value";
31 # Override to sort by increasing values
32 function sortDescending() {
36 # Don't override this unless you're darn sure.
37 function getOrderLimit( $offset, $limit ) {
38 return " ORDER BY value " .
39 ($this->sortDescending() ?
"DESC" : "")
40 . " LIMIT {$offset}, {$limit}";
43 # Is this query expensive (for some definition of expensive)? Then we
44 # don't let it run in miser mode. $wgDisableQueryPages causes all query
45 # pages to be declared expensive. Some query pages are always expensive.
46 function isExpensive( ) {
47 global $wgDisableQueryPages;
48 return $wgDisableQueryPages;
51 # Formats the results of the query for display. The skin is the current
52 # skin; you can use it for making links. The result is a single row of
53 # result data. You should be able to grab SQL results off of it.
55 function formatResult( $skin, $result ) {
59 # This is the actual workhorse. It does everything needed to make a
60 # real, honest-to-gosh query page.
62 function doQuery( $offset, $limit ) {
63 global $wgUser, $wgOut, $wgLang, $wgRequest;
66 $sname = $this->getName();
67 $fname = get_class($this) . "::doQuery";
68 $sql = $this->getSQL( $offset, $limit );
70 $wgOut->setSyndicated( true );
72 if ( $this->isExpensive() ) {
73 $type = wfStrencode( $sname );
74 $recache = $wgRequest->getBool( "recache" );
76 # Clear out any old cached data
77 $res = wfQuery( "DELETE FROM querycache WHERE qc_type='$type'", DB_WRITE
, $fname );
79 # Save results into the querycache table
82 "INSERT INTO querycache(qc_type,qc_namespace,qc_title,qc_value) " .
84 $this->getOrderLimit( 0, $maxstored ),
87 if( $wgMiserMode ||
$recache ) {
89 "SELECT qc_type as type, qc_namespace as namespace,qc_title as title, qc_value as value
90 FROM querycache WHERE qc_type='$type'";
93 $wgOut->addWikiText( wfMsg( "perfcached" ) );
97 $res = wfQuery( $sql . $this->getOrderLimit( $offset, $limit ), DB_READ
, $fname );
99 $num = wfNumRows($res);
101 $sk = $wgUser->getSkin( );
103 $top = wfShowingResults( $offset, $num);
104 $wgOut->addHTML( "<p>{$top}\n" );
106 # often disable 'next' link when we reach the end
107 if($num < $limit) { $atend = true; } else { $atend = false; }
109 $sl = wfViewPrevNext( $offset, $limit , $wgLang->specialPage( $sname ), "" ,$atend );
110 $wgOut->addHTML( "<br />{$sl}</p>\n" );
112 $s = "<ol start='" . ( $offset +
1 ) . "'>";
113 while ( $obj = wfFetchObject( $res ) ) {
114 $format = $this->formatResult( $sk, $obj );
115 $s .= "<li>{$format}</li>\n";
117 wfFreeResult( $res );
119 $wgOut->addHTML( $s );
120 $wgOut->addHTML( "<p>{$sl}</p>\n" );
123 # Similar to above, but packaging in a syndicated feed instead of a web page
124 function doFeed( $class = "" ) {
125 global $wgFeedClasses;
126 global $wgOut, $wgLanguageCode, $wgLang;
127 if( isset($wgFeedClasses[$class]) ) {
128 $feed = new $wgFeedClasses[$class](
134 $sql = $this->getSQL( 0, 50 );
135 $res = wfQuery( $sql, DB_READ
, "QueryPage::doFeed" );
136 while( $obj = wfFetchObject( $res ) ) {
137 $item = $this->feedResult( $obj );
138 if( $item ) $feed->outItem( $item );
140 wfFreeResult( $res );
149 # Override for custom handling. If the titles/links are ok, just do feedItemDesc()
150 function feedResult( $row ) {
151 if( !isset( $row->title
) ) {
154 $title = Title
::MakeTitle( IntVal( $row->namespace ), $row->title
);
156 if( isset( $row->timestamp
) ) {
157 $date = $row->timestamp
;
164 $talkpage = $title->getTalkPage();
165 $comments = $talkpage->getFullURL();
170 $this->feedItemDesc( $row ),
171 $title->getFullURL(),
173 $this->feedItemAuthor( $row ),
180 function feedItemDesc( $row ) {
182 if( isset( $row->comment
) ) {
183 $text = htmlspecialchars( $row->comment
);
188 if( isset( $row->text
) ) {
189 $text = "<p>" . htmlspecialchars( wfMsg( "summary" ) ) . ": " . $text . "</p>\n<hr />\n<div>" .
190 nl2br( htmlspecialchars( $row->text
) ) . "</div>";;
195 function feedItemAuthor( $row ) {
196 if( isset( $row->user_text
) ) {
197 return $row->user_text
;
203 function feedTitle() {
204 global $wgLanguageCode, $wgSitename, $wgLang;
205 $page = SpecialPage
::getPage( $this->getName() );
206 $desc = $page->getDescription();
207 return "$wgSitename - $desc [$wgLanguageCode]";
210 function feedDesc() {
211 return wfMsg( "fromwikipedia" );
216 $title = Title
::MakeTitle( NS_SPECIAL
, $this->getName() );
217 return $title->getFullURL();
221 # This is a subclass for very simple queries that are just looking for page
222 # titles that match some criteria. It formats each result item as a link to
225 class PageQueryPage
extends QueryPage
{
227 function formatResult( $skin, $result ) {
228 $nt = Title
::makeTitle( $result->namespace, $result->title
);
229 return $skin->makeKnownLinkObj( $nt, "" );