446dc6f0fd7d34c9641c406a2331549b9ec02060
3 * Contain a class for special pages
10 require_once ( 'Feed.php' );
13 * This is a class for doing query pages; since they're almost all the same,
14 * we factor out some of the functionality into a superclass, and let
15 * subclasses derive from it.
22 * Subclasses return their name here. Make sure the name is also
23 * specified in SpecialPage.php and in Language.php as a language message
31 * Subclasses return an SQL query here.
33 * Note that the query itself should return the following four columns:
34 * 'type' (your special page's name), 'namespace', 'title', and 'value'
35 * *in that order*. 'value' is used for sorting.
37 * These may be stored in the querycache table for expensive queries,
38 * and that cached data will be returned sometimes, so the presence of
39 * extra fields can't be relied upon. The cached 'value' column will be
40 * an integer; non-numeric values are useful only for sorting the initial
43 * Don't include an ORDER or LIMIT clause, this will be added.
46 return "SELECT 'sample' as type, 0 as namespace, 'Sample result' as title, 42 as value";
50 * Override to sort by increasing values
52 function sortDescending() {
57 return ' ORDER BY value ' .
58 ($this->sortDescending() ?
'DESC' : '');
62 * Is this query expensive (for some definition of expensive)? Then we
63 * don't let it run in miser mode. $wgDisableQueryPages causes all query
64 * pages to be declared expensive. Some query pages are always expensive.
66 function isExpensive( ) {
67 global $wgDisableQueryPages;
68 return $wgDisableQueryPages;
72 * Sometime we dont want to build rss / atom feeds.
74 function isSyndicated() {
79 * Formats the results of the query for display. The skin is the current
80 * skin; you can use it for making links. The result is a single row of
81 * result data. You should be able to grab SQL results off of it.
83 function formatResult( $skin, $result ) {
88 * The content returned by this function will be output before any result
90 function getPageHeader( ) {
95 * This is the actual workhorse. It does everything needed to make a
96 * real, honest-to-gosh query page.
98 * @param $offset database query offset
99 * @param $limit database query limit
101 function doQuery( $offset, $limit ) {
102 global $wgUser, $wgOut, $wgLang, $wgRequest, $wgContLang;
105 $sname = $this->getName();
106 $fname = get_class($this) . '::doQuery';
107 $sql = $this->getSQL();
108 $dbr =& wfGetDB( DB_SLAVE
);
109 $dbw =& wfGetDB( DB_MASTER
);
110 $querycache = $dbr->tableName( 'querycache' );
112 $wgOut->setSyndicated( $this->isSyndicated() );
115 if ( $this->isExpensive() ) {
116 $recache = $wgRequest->getBool( 'recache' );
118 # Clear out any old cached data
119 $dbw->delete( 'querycache', array( 'qc_type' => $sname ), $fname );
121 # Do query on the (possibly out of date) slave server
123 $res = $dbr->query( $sql . $this->getOrder() . $dbr->limitResult( $maxstored,0 ), $fname );
126 $insertSql = "INSERT INTO $querycache (qc_type,qc_namespace,qc_title,qc_value) VALUES ";
128 while ( $row = $dbr->fetchObject( $res ) ) {
135 $dbw->addQuotes( $row->type
) . ',' .
136 $dbw->addQuotes( $row->namespace ) . ',' .
137 $dbw->addQuotes( $row->title
) . ',' .
138 $dbw->addQuotes( $row->value
) . ')';
141 # Save results into the querycache table on the master
142 $dbw->query( $insertSql, $fname );
144 # Set result pointer to allow reading for display
145 $numRows = $dbr->numRows( $res );
146 if ( $numRows <= $offset ) {
149 $dbr->dataSeek( $res, $offset );
150 $num = max( $limit, $numRows - $offset );
153 if( $wgMiserMode ||
$recache ) {
154 $type = $dbr->strencode( $sname );
156 "SELECT qc_type as type, qc_namespace as namespace,qc_title as title, qc_value as value
157 FROM $querycache WHERE qc_type='$type'";
160 $wgOut->addWikiText( wfMsg( 'perfcached' ) );
163 if ( $res === false ) {
164 $res = $dbr->query( $sql . $this->getOrder() .
165 $dbr->limitResult( $limit,$offset ), $fname );
166 $num = $dbr->numRows($res);
170 $sk = $wgUser->getSkin( );
172 $wgOut->addHTML( $this->getPageHeader() );
174 $top = wfShowingResults( $offset, $num);
175 $wgOut->addHTML( "<p>{$top}\n" );
177 # often disable 'next' link when we reach the end
178 if($num < $limit) { $atend = true; } else { $atend = false; }
180 $sl = wfViewPrevNext( $offset, $limit , $wgContLang->specialPage( $sname ), "" ,$atend );
181 $wgOut->addHTML( "<br />{$sl}</p>\n" );
184 $s = "<ol start='" . ( $offset +
1 ) . "' class='special'>";
185 # Only read at most $num rows, because $res may contain the whole 1000
186 for ( $i = 0; $i < $num && $obj = $dbr->fetchObject( $res ); $i++
) {
187 $format = $this->formatResult( $sk, $obj );
188 $attr = ( isset ( $obj->usepatrol
) && $obj->usepatrol
&&
189 $obj->patrolled
== 0 ) ?
' class="not_patrolled"' : '';
190 $s .= "<li{$attr}>{$format}</li>\n";
192 $dbr->freeResult( $res );
194 $wgOut->addHTML( $s );
196 $wgOut->addHTML( "<p>{$sl}</p>\n" );
200 * Similar to above, but packaging in a syndicated feed instead of a web page
202 function doFeed( $class = '' ) {
203 global $wgFeedClasses;
204 global $wgOut, $wgLanguageCode, $wgLang;
205 if( isset($wgFeedClasses[$class]) ) {
206 $feed = new $wgFeedClasses[$class](
212 $dbr =& wfGetDB( DB_SLAVE
);
213 $sql = $this->getSQL() . $this->getOrder().$dbr->limitResult( 50, 0 );
214 $res = $dbr->query( $sql, 'QueryPage::doFeed' );
215 while( $obj = $dbr->fetchObject( $res ) ) {
216 $item = $this->feedResult( $obj );
217 if( $item ) $feed->outItem( $item );
219 $dbr->freeResult( $res );
229 * Override for custom handling. If the titles/links are ok, just do
232 function feedResult( $row ) {
233 if( !isset( $row->title
) ) {
236 $title = Title
::MakeTitle( IntVal( $row->namespace ), $row->title
);
238 if( isset( $row->timestamp
) ) {
239 $date = $row->timestamp
;
246 $talkpage = $title->getTalkPage();
247 $comments = $talkpage->getFullURL();
252 $this->feedItemDesc( $row ),
253 $title->getFullURL(),
255 $this->feedItemAuthor( $row ),
262 function feedItemDesc( $row ) {
264 if( isset( $row->comment
) ) {
265 $text = htmlspecialchars( $row->comment
);
270 if( isset( $row->text
) ) {
271 $text = '<p>' . htmlspecialchars( wfMsg( 'summary' ) ) . ': ' . $text . "</p>\n<hr />\n<div>" .
272 nl2br( htmlspecialchars( $row->text
) ) . "</div>";;
277 function feedItemAuthor( $row ) {
278 if( isset( $row->user_text
) ) {
279 return $row->user_text
;
285 function feedTitle() {
286 global $wgLanguageCode, $wgSitename, $wgLang;
287 $page = SpecialPage
::getPage( $this->getName() );
288 $desc = $page->getDescription();
289 return "$wgSitename - $desc [$wgLanguageCode]";
292 function feedDesc() {
293 return wfMsg( 'tagline' );
298 $title = Title
::MakeTitle( NS_SPECIAL
, $this->getName() );
299 return $title->getFullURL();
304 * This is a subclass for very simple queries that are just looking for page
305 * titles that match some criteria. It formats each result item as a link to
310 class PageQueryPage
extends QueryPage
{
312 function formatResult( $skin, $result ) {
314 $nt = Title
::makeTitle( $result->namespace, $result->title
);
315 return $skin->makeKnownLinkObj( $nt, $wgContLang->convert( $result->title
) );