3 * Contain a class for special pages
10 require_once ( 'Feed.php' );
13 * List of query page classes and their associated special pages, for periodic update purposes
15 $wgQueryPages = array(
16 // QueryPage subclass Special page name
17 //------------------------------------------------------------
18 array( 'AncientPagesPage', 'Ancientpages' ),
19 array( 'BrokenRedirectsPage', 'BrokenRedirects' ),
20 array( 'DeadendPagesPage', 'Deadendpages' ),
21 array( 'DisambiguationsPage', 'Disambiguations' ),
22 array( 'DoubleRedirectsPage', 'DoubleRedirects' ),
23 array( 'ListUsersPage', 'Listusers' ),
24 array( 'LonelyPagesPage', 'Lonelypages' ),
25 array( 'LongPagesPage', 'Longpages' ),
26 array( 'NewPagesPage', 'Newpages' ),
27 array( 'ShortPagesPage', 'Shortpages' ),
28 array( 'UncategorizedCategoriesPage','Uncategorizedcategories'),
29 array( 'UncategorizedPagesPage', 'Uncategorizedpages'),
30 array( 'UnusedimagesPage', 'Unusedimages' ),
31 array( 'WantedPagesPage', 'Wantedpages' ),
32 array( 'MostlinkedPage', 'Mostlinked' ),
35 global $wgDisableCounters;
36 if( !$wgDisableCounters ) {
37 $wgQueryPages[] = array( 'PopularPagesPage', 'Popularpages' );
41 * This is a class for doing query pages; since they're almost all the same,
42 * we factor out some of the functionality into a superclass, and let
43 * subclasses derive from it.
50 * Subclasses return their name here. Make sure the name is also
51 * specified in SpecialPage.php and in Language.php as a language message
59 * Subclasses return an SQL query here.
61 * Note that the query itself should return the following four columns:
62 * 'type' (your special page's name), 'namespace', 'title', and 'value'
63 * *in that order*. 'value' is used for sorting.
65 * These may be stored in the querycache table for expensive queries,
66 * and that cached data will be returned sometimes, so the presence of
67 * extra fields can't be relied upon. The cached 'value' column will be
68 * an integer; non-numeric values are useful only for sorting the initial
71 * Don't include an ORDER or LIMIT clause, this will be added.
74 return "SELECT 'sample' as type, 0 as namespace, 'Sample result' as title, 42 as value";
78 * Override to sort by increasing values
80 function sortDescending() {
85 return ' ORDER BY value ' .
86 ($this->sortDescending() ?
'DESC' : '');
90 * Is this query expensive (for some definition of expensive)? Then we
91 * don't let it run in miser mode. $wgDisableQueryPages causes all query
92 * pages to be declared expensive. Some query pages are always expensive.
94 function isExpensive( ) {
95 global $wgDisableQueryPages;
96 return $wgDisableQueryPages;
100 * Sometime we dont want to build rss / atom feeds.
102 function isSyndicated() {
107 * Formats the results of the query for display. The skin is the current
108 * skin; you can use it for making links. The result is a single row of
109 * result data. You should be able to grab SQL results off of it.
110 * If the function return "false", the line output will be skipped.
112 function formatResult( $skin, $result ) {
117 * The content returned by this function will be output before any result
119 function getPageHeader( ) {
124 * If using extra form wheely-dealies, return a set of parameters here
125 * as an associative array. They will be encoded and added to the paging
126 * links (prev/next/lengths).
129 function linkParameters() {
134 * Some special pages (for example SpecialListusers) might not return the
135 * current object formatted, but return the previous one instead.
136 * Setting this to return true, will call one more time wfFormatResult to
137 * be sure that the very last result is formatted and shown.
139 function tryLastResult( ) {
144 * Clear the cache and save new results
146 function recache( $ignoreErrors = true ) {
147 $fname = get_class($this) . '::recache';
148 $dbw =& wfGetDB( DB_MASTER
);
149 $dbr =& wfGetDB( DB_SLAVE
, array( $this->getName(), 'QueryPage::recache', 'vslow' ) );
150 if ( !$dbw ||
!$dbr ) {
154 $querycache = $dbr->tableName( 'querycache' );
156 if ( $ignoreErrors ) {
157 $ignoreW = $dbw->ignoreErrors( true );
158 $ignoreR = $dbr->ignoreErrors( true );
161 # Clear out any old cached data
162 $dbw->delete( 'querycache', array( 'qc_type' => $this->getName() ), $fname );
164 $sql = $this->getSQL() . $this->getOrder();
165 $sql = $dbr->limitResult($sql, 1000,0);
166 $res = $dbr->query($sql, $fname);
169 $num = $dbr->numRows( $res );
171 $insertSql = "INSERT INTO $querycache (qc_type,qc_namespace,qc_title,qc_value) VALUES ";
173 while ( $res && $row = $dbr->fetchObject( $res ) ) {
179 if ( isset( $row->value
) ) {
180 $value = $row->value
;
186 $dbw->addQuotes( $row->type
) . ',' .
187 $dbw->addQuotes( $row->namespace ) . ',' .
188 $dbw->addQuotes( $row->title
) . ',' .
189 $dbw->addQuotes( $value ) . ')';
192 # Save results into the querycache table on the master
194 if ( !$dbw->query( $insertSql, $fname ) ) {
195 // Set result to false to indicate error
196 $dbr->freeResult( $res );
201 $dbr->freeResult( $res );
203 if ( $ignoreErrors ) {
204 $dbw->ignoreErrors( $ignoreW );
205 $dbr->ignoreErrors( $ignoreR );
212 * This is the actual workhorse. It does everything needed to make a
213 * real, honest-to-gosh query page.
215 * @param $offset database query offset
216 * @param $limit database query limit
217 * @param $shownavigation show navigation like "next 200"?
219 function doQuery( $offset, $limit, $shownavigation=true ) {
220 global $wgUser, $wgOut, $wgLang, $wgRequest, $wgContLang;
223 $sname = $this->getName();
224 $fname = get_class($this) . '::doQuery';
225 $sql = $this->getSQL();
226 $dbr =& wfGetDB( DB_SLAVE
);
227 $dbw =& wfGetDB( DB_MASTER
);
228 $querycache = $dbr->tableName( 'querycache' );
230 $wgOut->setSyndicated( $this->isSyndicated() );
232 if ( $this->isExpensive() ) {
233 // Disabled recache parameter due to retry problems -- TS
235 $type = $dbr->strencode( $sname );
237 "SELECT qc_type as type, qc_namespace as namespace,qc_title as title, qc_value as value
238 FROM $querycache WHERE qc_type='$type'";
239 $wgOut->addWikiText( wfMsg( 'perfcached' ) );
243 $sql .= $this->getOrder();
244 $sql = $dbr->limitResult($sql, $limit, $offset);
245 $res = $dbr->query( $sql );
246 $num = $dbr->numRows($res);
248 $sk = $wgUser->getSkin( );
250 if($shownavigation) {
251 $wgOut->addHTML( $this->getPageHeader() );
252 $top = wfShowingResults( $offset, $num);
253 $wgOut->addHTML( "<p>{$top}\n" );
255 # often disable 'next' link when we reach the end
256 if($num < $limit) { $atend = true; } else { $atend = false; }
258 $sl = wfViewPrevNext( $offset, $limit ,
259 $wgContLang->specialPage( $sname ),
260 wfArrayToCGI( $this->linkParameters() ), $atend );
261 $wgOut->addHTML( "<br />{$sl}</p>\n" );
264 $s = "<ol start='" . ( $offset +
1 ) . "' class='special'>";
266 # Only read at most $num rows, because $res may contain the whole 1000
267 for ( $i = 0; $i < $num && $obj = $dbr->fetchObject( $res ); $i++
) {
268 $format = $this->formatResult( $sk, $obj );
270 $attr = ( isset ( $obj->usepatrol
) && $obj->usepatrol
&&
271 $obj->patrolled
== 0 ) ?
' class="not-patrolled"' : '';
272 $s .= "<li{$attr}>{$format}</li>\n";
276 if($this->tryLastResult()) {
277 // flush the very last result
279 $format = $this->formatResult( $sk, $obj );
281 $attr = ( isset ( $obj->usepatrol
) && $obj->usepatrol
&&
282 $obj->patrolled
== 0 ) ?
' class="not-patrolled"' : '';
283 $s .= "<li{$attr}>{$format}</li>\n";
287 $dbr->freeResult( $res );
289 $wgOut->addHTML( $s );
291 if($shownavigation) {
292 $wgOut->addHTML( "<p>{$sl}</p>\n" );
298 * Similar to above, but packaging in a syndicated feed instead of a web page
300 function doFeed( $class = '' ) {
301 global $wgFeedClasses;
302 global $wgOut, $wgLanguageCode, $wgLang;
303 if( isset($wgFeedClasses[$class]) ) {
304 $feed = new $wgFeedClasses[$class](
310 $dbr =& wfGetDB( DB_SLAVE
);
311 $sql = $this->getSQL() . $this->getOrder();
312 $sql = $dbr->limitResult( $sql, 50, 0 );
313 $res = $dbr->query( $sql, 'QueryPage::doFeed' );
314 while( $obj = $dbr->fetchObject( $res ) ) {
315 $item = $this->feedResult( $obj );
316 if( $item ) $feed->outItem( $item );
318 $dbr->freeResult( $res );
328 * Override for custom handling. If the titles/links are ok, just do
331 function feedResult( $row ) {
332 if( !isset( $row->title
) ) {
335 $title = Title
::MakeTitle( intval( $row->namespace ), $row->title
);
337 if( isset( $row->timestamp
) ) {
338 $date = $row->timestamp
;
345 $talkpage = $title->getTalkPage();
346 $comments = $talkpage->getFullURL();
350 $title->getPrefixedText(),
351 $this->feedItemDesc( $row ),
352 $title->getFullURL(),
354 $this->feedItemAuthor( $row ),
361 function feedItemDesc( $row ) {
362 return isset( $row->comment
)
363 ?
htmlspecialchars( $row->comment
)
367 function feedItemAuthor( $row ) {
368 if( isset( $row->user_text
) ) {
369 return $row->user_text
;
375 function feedTitle() {
376 global $wgLanguageCode, $wgSitename, $wgLang;
377 $page = SpecialPage
::getPage( $this->getName() );
378 $desc = $page->getDescription();
379 return "$wgSitename - $desc [$wgLanguageCode]";
382 function feedDesc() {
383 return wfMsg( 'tagline' );
388 $title = Title
::MakeTitle( NS_SPECIAL
, $this->getName() );
389 return $title->getFullURL();
394 * This is a subclass for very simple queries that are just looking for page
395 * titles that match some criteria. It formats each result item as a link to
400 class PageQueryPage
extends QueryPage
{
402 function formatResult( $skin, $result ) {
404 $nt = Title
::makeTitle( $result->namespace, $result->title
);
405 return $skin->makeKnownLinkObj( $nt, $wgContLang->convert( $nt->getPrefixedText() ) );