2b72e35c6863bed95ad55c89e2b3b72a8f6974a5
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.
82 * If the function return "false", the line output will be skipped.
84 function formatResult( $skin, $result ) {
89 * The content returned by this function will be output before any result
91 function getPageHeader( ) {
96 * This is the actual workhorse. It does everything needed to make a
97 * real, honest-to-gosh query page.
99 * @param $offset database query offset
100 * @param $limit database query limit
102 function doQuery( $offset, $limit ) {
103 global $wgUser, $wgOut, $wgLang, $wgRequest, $wgContLang;
106 $sname = $this->getName();
107 $fname = get_class($this) . '::doQuery';
108 $sql = $this->getSQL();
109 $dbr =& wfGetDB( DB_SLAVE
);
110 $dbw =& wfGetDB( DB_MASTER
);
111 $querycache = $dbr->tableName( 'querycache' );
113 $wgOut->setSyndicated( $this->isSyndicated() );
116 if ( $this->isExpensive() ) {
117 $recache = $wgRequest->getBool( 'recache' );
119 # Clear out any old cached data
120 $dbw->delete( 'querycache', array( 'qc_type' => $sname ), $fname );
122 # Do query on the (possibly out of date) slave server
124 $res = $dbr->query( $sql . $this->getOrder() . $dbr->limitResult( $maxstored,0 ), $fname );
127 $insertSql = "INSERT INTO $querycache (qc_type,qc_namespace,qc_title,qc_value) VALUES ";
129 while ( $row = $dbr->fetchObject( $res ) ) {
136 $dbw->addQuotes( $row->type
) . ',' .
137 $dbw->addQuotes( $row->namespace ) . ',' .
138 $dbw->addQuotes( $row->title
) . ',' .
139 $dbw->addQuotes( $row->value
) . ')';
142 # Save results into the querycache table on the master
143 $dbw->query( $insertSql, $fname );
145 # Set result pointer to allow reading for display
146 $numRows = $dbr->numRows( $res );
147 if ( $numRows <= $offset ) {
150 $dbr->dataSeek( $res, $offset );
151 $num = max( $limit, $numRows - $offset );
154 if( $wgMiserMode ||
$recache ) {
155 $type = $dbr->strencode( $sname );
157 "SELECT qc_type as type, qc_namespace as namespace,qc_title as title, qc_value as value
158 FROM $querycache WHERE qc_type='$type'";
161 $wgOut->addWikiText( wfMsg( 'perfcached' ) );
164 if ( $res === false ) {
165 $res = $dbr->query( $sql . $this->getOrder() .
166 $dbr->limitResult( $limit,$offset ), $fname );
167 $num = $dbr->numRows($res);
171 $sk = $wgUser->getSkin( );
173 $wgOut->addHTML( $this->getPageHeader() );
175 $top = wfShowingResults( $offset, $num);
176 $wgOut->addHTML( "<p>{$top}\n" );
178 # often disable 'next' link when we reach the end
179 if($num < $limit) { $atend = true; } else { $atend = false; }
181 $sl = wfViewPrevNext( $offset, $limit , $wgContLang->specialPage( $sname ), "" ,$atend );
182 $wgOut->addHTML( "<br />{$sl}</p>\n" );
185 $s = "<ol start='" . ( $offset +
1 ) . "' class='special'>";
186 # Only read at most $num rows, because $res may contain the whole 1000
187 for ( $i = 0; $i < $num && $obj = $dbr->fetchObject( $res ); $i++
) {
188 $format = $this->formatResult( $sk, $obj );
190 $attr = ( isset ( $obj->usepatrol
) && $obj->usepatrol
&&
191 $obj->patrolled
== 0 ) ?
' class="not-patrolled"' : '';
192 $s .= "<li{$attr}>{$format}</li>\n";
195 $dbr->freeResult( $res );
197 $wgOut->addHTML( $s );
199 $wgOut->addHTML( "<p>{$sl}</p>\n" );
203 * Similar to above, but packaging in a syndicated feed instead of a web page
205 function doFeed( $class = '' ) {
206 global $wgFeedClasses;
207 global $wgOut, $wgLanguageCode, $wgLang;
208 if( isset($wgFeedClasses[$class]) ) {
209 $feed = new $wgFeedClasses[$class](
215 $dbr =& wfGetDB( DB_SLAVE
);
216 $sql = $this->getSQL() . $this->getOrder().$dbr->limitResult( 50, 0 );
217 $res = $dbr->query( $sql, 'QueryPage::doFeed' );
218 while( $obj = $dbr->fetchObject( $res ) ) {
219 $item = $this->feedResult( $obj );
220 if( $item ) $feed->outItem( $item );
222 $dbr->freeResult( $res );
232 * Override for custom handling. If the titles/links are ok, just do
235 function feedResult( $row ) {
236 if( !isset( $row->title
) ) {
239 $title = Title
::MakeTitle( IntVal( $row->namespace ), $row->title
);
241 if( isset( $row->timestamp
) ) {
242 $date = $row->timestamp
;
249 $talkpage = $title->getTalkPage();
250 $comments = $talkpage->getFullURL();
255 $this->feedItemDesc( $row ),
256 $title->getFullURL(),
258 $this->feedItemAuthor( $row ),
265 function feedItemDesc( $row ) {
267 if( isset( $row->comment
) ) {
268 $text = htmlspecialchars( $row->comment
);
273 if( isset( $row->text
) ) {
274 $text = '<p>' . htmlspecialchars( wfMsg( 'summary' ) ) . ': ' . $text . "</p>\n<hr />\n<div>" .
275 nl2br( htmlspecialchars( $row->text
) ) . "</div>";;
280 function feedItemAuthor( $row ) {
281 if( isset( $row->user_text
) ) {
282 return $row->user_text
;
288 function feedTitle() {
289 global $wgLanguageCode, $wgSitename, $wgLang;
290 $page = SpecialPage
::getPage( $this->getName() );
291 $desc = $page->getDescription();
292 return "$wgSitename - $desc [$wgLanguageCode]";
295 function feedDesc() {
296 return wfMsg( 'tagline' );
301 $title = Title
::MakeTitle( NS_SPECIAL
, $this->getName() );
302 return $title->getFullURL();
307 * This is a subclass for very simple queries that are just looking for page
308 * titles that match some criteria. It formats each result item as a link to
313 class PageQueryPage
extends QueryPage
{
315 function formatResult( $skin, $result ) {
317 $nt = Title
::makeTitle( $result->namespace, $result->title
);
318 return $skin->makeKnownLinkObj( $nt, $wgContLang->convert( $result->title
) );