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( 'PopularPagesPage', 'Popularpages' ),
28 array( 'ShortPagesPage', 'Shortpages' ),
29 array( 'UncategorizedCategoriesPage','Uncategorizedcategories'),
30 array( 'UncategorizedPagesPage', 'Uncategorizedpages'),
31 array( 'UnusedimagesPage', 'Unusedimages' ),
32 array( 'WantedPagesPage', 'Wantedpages' ),
38 * This is a class for doing query pages; since they're almost all the same,
39 * we factor out some of the functionality into a superclass, and let
40 * subclasses derive from it.
47 * Subclasses return their name here. Make sure the name is also
48 * specified in SpecialPage.php and in Language.php as a language message
56 * Subclasses return an SQL query here.
58 * Note that the query itself should return the following four columns:
59 * 'type' (your special page's name), 'namespace', 'title', and 'value'
60 * *in that order*. 'value' is used for sorting.
62 * These may be stored in the querycache table for expensive queries,
63 * and that cached data will be returned sometimes, so the presence of
64 * extra fields can't be relied upon. The cached 'value' column will be
65 * an integer; non-numeric values are useful only for sorting the initial
68 * Don't include an ORDER or LIMIT clause, this will be added.
71 return "SELECT 'sample' as type, 0 as namespace, 'Sample result' as title, 42 as value";
75 * Override to sort by increasing values
77 function sortDescending() {
82 return ' ORDER BY value ' .
83 ($this->sortDescending() ?
'DESC' : '');
87 * Is this query expensive (for some definition of expensive)? Then we
88 * don't let it run in miser mode. $wgDisableQueryPages causes all query
89 * pages to be declared expensive. Some query pages are always expensive.
91 function isExpensive( ) {
92 global $wgDisableQueryPages;
93 return $wgDisableQueryPages;
97 * Sometime we dont want to build rss / atom feeds.
99 function isSyndicated() {
104 * Formats the results of the query for display. The skin is the current
105 * skin; you can use it for making links. The result is a single row of
106 * result data. You should be able to grab SQL results off of it.
107 * If the function return "false", the line output will be skipped.
109 function formatResult( $skin, $result ) {
114 * The content returned by this function will be output before any result
116 function getPageHeader( ) {
121 * Some special pages (for example SpecialListusers) might not return the
122 * current object formatted, but return the previous one instead.
123 * Setting this to return true, will call one more time wfFormatResult to
124 * be sure that the very last result is formatted and shown.
126 function tryLastResult( ) {
131 * Clear the cache and save new results
133 function recache( $ignoreErrors = true ) {
134 $fname = get_class($this) . '::recache';
135 $dbw =& wfGetDB( DB_MASTER
);
136 $dbr =& wfGetDB( DB_SLAVE
, array( $this->getName(), 'QueryPage::recache', 'vslow' ) );
137 if ( !$dbw ||
!$dbr ) {
141 $querycache = $dbr->tableName( 'querycache' );
143 if ( $ignoreErrors ) {
144 $ignoreW = $dbw->ignoreErrors( true );
145 $ignoreR = $dbr->ignoreErrors( true );
148 # Clear out any old cached data
149 $dbw->delete( 'querycache', array( 'qc_type' => $this->getName() ), $fname );
151 $res = $dbr->query( $this->getSQL() . $this->getOrder() . $dbr->limitResult( 1000,0 ), $fname );
154 $num = $dbr->numRows( $res );
156 $insertSql = "INSERT INTO $querycache (qc_type,qc_namespace,qc_title,qc_value) VALUES ";
158 while ( $res && $row = $dbr->fetchObject( $res ) ) {
164 if ( isset( $row->value
) ) {
165 $value = $row->value
;
171 $dbw->addQuotes( $row->type
) . ',' .
172 $dbw->addQuotes( $row->namespace ) . ',' .
173 $dbw->addQuotes( $row->title
) . ',' .
174 $dbw->addQuotes( $value ) . ')';
177 # Save results into the querycache table on the master
179 if ( !$dbw->query( $insertSql, $fname ) ) {
180 // Set result to false to indicate error
181 $dbr->freeResult( $res );
186 $dbr->freeResult( $res );
188 if ( $ignoreErrors ) {
189 $dbw->ignoreErrors( $ignoreW );
190 $dbr->ignoreErrors( $ignoreR );
197 * This is the actual workhorse. It does everything needed to make a
198 * real, honest-to-gosh query page.
200 * @param $offset database query offset
201 * @param $limit database query limit
203 function doQuery( $offset, $limit ) {
204 global $wgUser, $wgOut, $wgLang, $wgRequest, $wgContLang;
207 $sname = $this->getName();
208 $fname = get_class($this) . '::doQuery';
209 $sql = $this->getSQL();
210 $dbr =& wfGetDB( DB_SLAVE
);
211 $dbw =& wfGetDB( DB_MASTER
);
212 $querycache = $dbr->tableName( 'querycache' );
214 $wgOut->setSyndicated( $this->isSyndicated() );
217 if ( $this->isExpensive() ) {
218 // Disabled recache parameter due to retry problems -- TS
220 $type = $dbr->strencode( $sname );
222 "SELECT qc_type as type, qc_namespace as namespace,qc_title as title, qc_value as value
223 FROM $querycache WHERE qc_type='$type'";
226 $wgOut->addWikiText( wfMsg( 'perfcached' ) );
229 if ( $res === false ) {
230 $res = $dbr->query( $sql . $this->getOrder() .
231 $dbr->limitResult( $limit,$offset ), $fname );
232 $num = $dbr->numRows($res);
235 $sk = $wgUser->getSkin( );
237 $wgOut->addHTML( $this->getPageHeader() );
239 $top = wfShowingResults( $offset, $num);
240 $wgOut->addHTML( "<p>{$top}\n" );
242 # often disable 'next' link when we reach the end
243 if($num < $limit) { $atend = true; } else { $atend = false; }
245 $sl = wfViewPrevNext( $offset, $limit , $wgContLang->specialPage( $sname ), "" ,$atend );
246 $wgOut->addHTML( "<br />{$sl}</p>\n" );
249 $s = "<ol start='" . ( $offset +
1 ) . "' class='special'>";
251 # Only read at most $num rows, because $res may contain the whole 1000
252 for ( $i = 0; $i < $num && $obj = $dbr->fetchObject( $res ); $i++
) {
253 $format = $this->formatResult( $sk, $obj );
255 $attr = ( isset ( $obj->usepatrol
) && $obj->usepatrol
&&
256 $obj->patrolled
== 0 ) ?
' class="not-patrolled"' : '';
257 $s .= "<li{$attr}>{$format}</li>\n";
261 if($this->tryLastResult()) {
262 // flush the very last result
264 $format = $this->formatResult( $sk, $obj );
266 $attr = ( isset ( $obj->usepatrol
) && $obj->usepatrol
&&
267 $obj->patrolled
== 0 ) ?
' class="not-patrolled"' : '';
268 $s .= "<li{$attr}>{$format}</li>\n";
272 $dbr->freeResult( $res );
274 $wgOut->addHTML( $s );
276 $wgOut->addHTML( "<p>{$sl}</p>\n" );
281 * Similar to above, but packaging in a syndicated feed instead of a web page
283 function doFeed( $class = '' ) {
284 global $wgFeedClasses;
285 global $wgOut, $wgLanguageCode, $wgLang;
286 if( isset($wgFeedClasses[$class]) ) {
287 $feed = new $wgFeedClasses[$class](
293 $dbr =& wfGetDB( DB_SLAVE
);
294 $sql = $this->getSQL() . $this->getOrder().$dbr->limitResult( 50, 0 );
295 $res = $dbr->query( $sql, 'QueryPage::doFeed' );
296 while( $obj = $dbr->fetchObject( $res ) ) {
297 $item = $this->feedResult( $obj );
298 if( $item ) $feed->outItem( $item );
300 $dbr->freeResult( $res );
310 * Override for custom handling. If the titles/links are ok, just do
313 function feedResult( $row ) {
314 if( !isset( $row->title
) ) {
317 $title = Title
::MakeTitle( IntVal( $row->namespace ), $row->title
);
319 if( isset( $row->timestamp
) ) {
320 $date = $row->timestamp
;
327 $talkpage = $title->getTalkPage();
328 $comments = $talkpage->getFullURL();
332 $title->getPrefixedText(),
333 $this->feedItemDesc( $row ),
334 $title->getFullURL(),
336 $this->feedItemAuthor( $row ),
343 function feedItemDesc( $row ) {
344 return isset( $row->comment
)
345 ?
htmlspecialchars( $row->comment
)
349 function feedItemAuthor( $row ) {
350 if( isset( $row->user_text
) ) {
351 return $row->user_text
;
357 function feedTitle() {
358 global $wgLanguageCode, $wgSitename, $wgLang;
359 $page = SpecialPage
::getPage( $this->getName() );
360 $desc = $page->getDescription();
361 return "$wgSitename - $desc [$wgLanguageCode]";
364 function feedDesc() {
365 return wfMsg( 'tagline' );
370 $title = Title
::MakeTitle( NS_SPECIAL
, $this->getName() );
371 return $title->getFullURL();
376 * This is a subclass for very simple queries that are just looking for page
377 * titles that match some criteria. It formats each result item as a link to
382 class PageQueryPage
extends QueryPage
{
384 function formatResult( $skin, $result ) {
386 $nt = Title
::makeTitle( $result->namespace, $result->title
);
387 return $skin->makeKnownLinkObj( $nt, $wgContLang->convert( $result->title
) );