2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Contain a class for special pages
|
|
|
|
|
*/
|
I was adding a special page (dead-end pages), and I realized that almost all
the special query pages were pretty much identical. I copy-and-pasted one to
make the one I was working on, and I realized that that was Wrong.
So, I took the common elements and made them into a class, QueryPage.php.
Then, I derived each of the existing special pages from QueryPage, and
overrode places where they differed. This is a Recipe pattern, btw, for
those of you following along at home.
Anyways, the upshot is that the query pages are a lot shorter, with just the
essentials that make them different from other query pages, and there's one
place to make big UI changes for all queries.
2003-12-01 16:04:35 +00:00
|
|
|
|
2005-04-24 04:16:50 +00:00
|
|
|
/**
|
2007-02-21 17:37:25 +00:00
|
|
|
* List of query page classes and their associated special pages,
|
|
|
|
|
* for periodic updates.
|
|
|
|
|
*
|
|
|
|
|
* DO NOT CHANGE THIS LIST without testing that
|
|
|
|
|
* maintenance/updateSpecialPages.php still works.
|
2005-04-24 04:16:50 +00:00
|
|
|
*/
|
2005-10-12 03:45:56 +00:00
|
|
|
global $wgQueryPages; // not redundant
|
2005-04-24 04:16:50 +00:00
|
|
|
$wgQueryPages = array(
|
2005-10-12 03:45:56 +00:00
|
|
|
// QueryPage subclass Special page name Limit (false for none, none for the default)
|
|
|
|
|
//----------------------------------------------------------------------------
|
2007-02-21 17:37:25 +00:00
|
|
|
array( 'AncientPagesPage', 'Ancientpages' ),
|
|
|
|
|
array( 'BrokenRedirectsPage', 'BrokenRedirects' ),
|
|
|
|
|
array( 'DeadendPagesPage', 'Deadendpages' ),
|
|
|
|
|
array( 'DisambiguationsPage', 'Disambiguations' ),
|
|
|
|
|
array( 'DoubleRedirectsPage', 'DoubleRedirects' ),
|
2007-03-31 22:54:30 +00:00
|
|
|
array( 'ListredirectsPage', 'Listredirects' ),
|
2007-02-21 17:37:25 +00:00
|
|
|
array( 'LonelyPagesPage', 'Lonelypages' ),
|
|
|
|
|
array( 'LongPagesPage', 'Longpages' ),
|
|
|
|
|
array( 'MostcategoriesPage', 'Mostcategories' ),
|
|
|
|
|
array( 'MostimagesPage', 'Mostimages' ),
|
|
|
|
|
array( 'MostlinkedCategoriesPage', 'Mostlinkedcategories' ),
|
|
|
|
|
array( 'MostlinkedPage', 'Mostlinked' ),
|
|
|
|
|
array( 'MostrevisionsPage', 'Mostrevisions' ),
|
2007-04-08 07:23:15 +00:00
|
|
|
array( 'FewestrevisionsPage', 'Fewestrevisions' ),
|
2007-02-21 17:37:25 +00:00
|
|
|
array( 'NewPagesPage', 'Newpages' ),
|
|
|
|
|
array( 'ShortPagesPage', 'Shortpages' ),
|
|
|
|
|
array( 'UncategorizedCategoriesPage', 'Uncategorizedcategories' ),
|
|
|
|
|
array( 'UncategorizedPagesPage', 'Uncategorizedpages' ),
|
2007-03-31 22:54:30 +00:00
|
|
|
array( 'UncategorizedImagesPage', 'Uncategorizedimages' ),
|
2007-02-21 17:37:25 +00:00
|
|
|
array( 'UnusedCategoriesPage', 'Unusedcategories' ),
|
|
|
|
|
array( 'UnusedimagesPage', 'Unusedimages' ),
|
|
|
|
|
array( 'WantedCategoriesPage', 'Wantedcategories' ),
|
|
|
|
|
array( 'WantedPagesPage', 'Wantedpages' ),
|
|
|
|
|
array( 'UnwatchedPagesPage', 'Unwatchedpages' ),
|
2007-03-31 22:54:30 +00:00
|
|
|
array( 'UnusedtemplatesPage', 'Unusedtemplates' ),
|
|
|
|
|
array( 'WithoutInterwikiPage', 'Withoutinterwiki' ),
|
2005-04-24 04:16:50 +00:00
|
|
|
);
|
2005-10-12 03:45:56 +00:00
|
|
|
wfRunHooks( 'wgQueryPages', array( &$wgQueryPages ) );
|
|
|
|
|
|
2005-07-15 23:56:58 +00:00
|
|
|
global $wgDisableCounters;
|
2005-10-19 01:39:12 +00:00
|
|
|
if ( !$wgDisableCounters )
|
|
|
|
|
$wgQueryPages[] = array( 'PopularPagesPage', 'Popularpages' );
|
|
|
|
|
|
2005-04-24 04:16:50 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* This is a class for doing query pages; since they're almost all the same,
|
|
|
|
|
* we factor out some of the functionality into a superclass, and let
|
|
|
|
|
* subclasses derive from it.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2006-05-11 22:40:38 +00:00
|
|
|
class QueryPage {
|
2005-10-16 02:03:21 +00:00
|
|
|
/**
|
|
|
|
|
* Whether or not we want plain listoutput rather than an ordered list
|
|
|
|
|
*
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
2006-05-11 22:40:38 +00:00
|
|
|
var $listoutput = false;
|
2007-01-20 13:34:31 +00:00
|
|
|
|
2006-04-21 06:49:23 +00:00
|
|
|
/**
|
|
|
|
|
* The offset and limit in use, as passed to the query() function
|
|
|
|
|
*
|
|
|
|
|
* @var integer
|
|
|
|
|
*/
|
2006-05-11 22:40:38 +00:00
|
|
|
var $offset = 0;
|
|
|
|
|
var $limit = 0;
|
2005-10-16 02:03:21 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A mutator for $this->listoutput;
|
|
|
|
|
*
|
|
|
|
|
* @param bool $bool
|
|
|
|
|
*/
|
|
|
|
|
function setListoutput( $bool ) {
|
|
|
|
|
$this->listoutput = $bool;
|
|
|
|
|
}
|
2004-09-03 21:22:20 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Subclasses return their name here. Make sure the name is also
|
|
|
|
|
* specified in SpecialPage.php and in Language.php as a language message
|
|
|
|
|
* param.
|
|
|
|
|
*/
|
2004-01-25 02:27:49 +00:00
|
|
|
function getName() {
|
2004-08-15 19:12:17 +00:00
|
|
|
return '';
|
I was adding a special page (dead-end pages), and I realized that almost all
the special query pages were pretty much identical. I copy-and-pasted one to
make the one I was working on, and I realized that that was Wrong.
So, I took the common elements and made them into a class, QueryPage.php.
Then, I derived each of the existing special pages from QueryPage, and
overrode places where they differed. This is a Recipe pattern, btw, for
those of you following along at home.
Anyways, the upshot is that the query pages are a lot shorter, with just the
essentials that make them different from other query pages, and there's one
place to make big UI changes for all queries.
2003-12-01 16:04:35 +00:00
|
|
|
}
|
|
|
|
|
|
2006-05-03 01:23:10 +00:00
|
|
|
/**
|
|
|
|
|
* Return title object representing this page
|
|
|
|
|
*
|
|
|
|
|
* @return Title
|
|
|
|
|
*/
|
|
|
|
|
function getTitle() {
|
2006-10-30 06:25:31 +00:00
|
|
|
return SpecialPage::getTitleFor( $this->getName() );
|
2006-05-03 01:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Subclasses return an SQL query here.
|
2004-09-03 21:22:20 +00:00
|
|
|
*
|
2004-09-02 23:28:24 +00:00
|
|
|
* Note that the query itself should return the following four columns:
|
|
|
|
|
* 'type' (your special page's name), 'namespace', 'title', and 'value'
|
|
|
|
|
* *in that order*. 'value' is used for sorting.
|
|
|
|
|
*
|
|
|
|
|
* These may be stored in the querycache table for expensive queries,
|
|
|
|
|
* and that cached data will be returned sometimes, so the presence of
|
|
|
|
|
* extra fields can't be relied upon. The cached 'value' column will be
|
|
|
|
|
* an integer; non-numeric values are useful only for sorting the initial
|
|
|
|
|
* query.
|
|
|
|
|
*
|
|
|
|
|
* Don't include an ORDER or LIMIT clause, this will be added.
|
|
|
|
|
*/
|
2004-05-09 01:30:34 +00:00
|
|
|
function getSQL() {
|
|
|
|
|
return "SELECT 'sample' as type, 0 as namespace, 'Sample result' as title, 42 as value";
|
|
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Override to sort by increasing values
|
|
|
|
|
*/
|
2004-05-09 01:30:34 +00:00
|
|
|
function sortDescending() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
I was adding a special page (dead-end pages), and I realized that almost all
the special query pages were pretty much identical. I copy-and-pasted one to
make the one I was working on, and I realized that that was Wrong.
So, I took the common elements and made them into a class, QueryPage.php.
Then, I derived each of the existing special pages from QueryPage, and
overrode places where they differed. This is a Recipe pattern, btw, for
those of you following along at home.
Anyways, the upshot is that the query pages are a lot shorter, with just the
essentials that make them different from other query pages, and there's one
place to make big UI changes for all queries.
2003-12-01 16:04:35 +00:00
|
|
|
|
2004-08-10 13:55:29 +00:00
|
|
|
function getOrder() {
|
2004-08-15 19:12:17 +00:00
|
|
|
return ' ORDER BY value ' .
|
|
|
|
|
($this->sortDescending() ? 'DESC' : '');
|
2004-08-10 13:55:29 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Is this query expensive (for some definition of expensive)? Then we
|
|
|
|
|
* don't let it run in miser mode. $wgDisableQueryPages causes all query
|
|
|
|
|
* pages to be declared expensive. Some query pages are always expensive.
|
|
|
|
|
*/
|
2004-01-25 02:27:49 +00:00
|
|
|
function isExpensive( ) {
|
|
|
|
|
global $wgDisableQueryPages;
|
|
|
|
|
return $wgDisableQueryPages;
|
|
|
|
|
}
|
I was adding a special page (dead-end pages), and I realized that almost all
the special query pages were pretty much identical. I copy-and-pasted one to
make the one I was working on, and I realized that that was Wrong.
So, I took the common elements and made them into a class, QueryPage.php.
Then, I derived each of the existing special pages from QueryPage, and
overrode places where they differed. This is a Recipe pattern, btw, for
those of you following along at home.
Anyways, the upshot is that the query pages are a lot shorter, with just the
essentials that make them different from other query pages, and there's one
place to make big UI changes for all queries.
2003-12-01 16:04:35 +00:00
|
|
|
|
2005-09-16 15:05:07 +00:00
|
|
|
/**
|
|
|
|
|
* Whether or not the output of the page in question is retrived from
|
|
|
|
|
* the database cache.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
function isCached() {
|
|
|
|
|
global $wgMiserMode;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-09-16 15:05:07 +00:00
|
|
|
return $this->isExpensive() && $wgMiserMode;
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-13 20:33:37 +00:00
|
|
|
/**
|
|
|
|
|
* Sometime we dont want to build rss / atom feeds.
|
|
|
|
|
*/
|
|
|
|
|
function isSyndicated() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2006-11-08 07:12:03 +00:00
|
|
|
* Formats the results of the query for display. The skin is the current
|
|
|
|
|
* skin; you can use it for making links. The result is a single row of
|
|
|
|
|
* result data. You should be able to grab SQL results off of it.
|
2005-02-01 01:42:22 +00:00
|
|
|
* If the function return "false", the line output will be skipped.
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2006-11-08 07:12:03 +00:00
|
|
|
function formatResult( $skin, $result ) {
|
2004-08-15 19:12:17 +00:00
|
|
|
return '';
|
I was adding a special page (dead-end pages), and I realized that almost all
the special query pages were pretty much identical. I copy-and-pasted one to
make the one I was working on, and I realized that that was Wrong.
So, I took the common elements and made them into a class, QueryPage.php.
Then, I derived each of the existing special pages from QueryPage, and
overrode places where they differed. This is a Recipe pattern, btw, for
those of you following along at home.
Anyways, the upshot is that the query pages are a lot shorter, with just the
essentials that make them different from other query pages, and there's one
place to make big UI changes for all queries.
2003-12-01 16:04:35 +00:00
|
|
|
}
|
2004-09-03 21:22:20 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* The content returned by this function will be output before any result
|
2005-06-30 07:37:04 +00:00
|
|
|
*/
|
2004-08-15 19:22:40 +00:00
|
|
|
function getPageHeader( ) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-06-30 07:37:04 +00:00
|
|
|
/**
|
|
|
|
|
* If using extra form wheely-dealies, return a set of parameters here
|
|
|
|
|
* as an associative array. They will be encoded and added to the paging
|
|
|
|
|
* links (prev/next/lengths).
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
function linkParameters() {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-02-01 02:02:14 +00:00
|
|
|
/**
|
|
|
|
|
* Some special pages (for example SpecialListusers) might not return the
|
|
|
|
|
* current object formatted, but return the previous one instead.
|
|
|
|
|
* Setting this to return true, will call one more time wfFormatResult to
|
|
|
|
|
* be sure that the very last result is formatted and shown.
|
|
|
|
|
*/
|
|
|
|
|
function tryLastResult( ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2005-04-24 08:31:12 +00:00
|
|
|
/**
|
|
|
|
|
* Clear the cache and save new results
|
|
|
|
|
*/
|
2005-10-12 03:45:56 +00:00
|
|
|
function recache( $limit, $ignoreErrors = true ) {
|
2005-04-24 08:31:12 +00:00
|
|
|
$fname = get_class($this) . '::recache';
|
2007-01-22 23:50:42 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
|
|
|
|
$dbr = wfGetDB( DB_SLAVE, array( $this->getName(), 'QueryPage::recache', 'vslow' ) );
|
2005-04-24 08:31:12 +00:00
|
|
|
if ( !$dbw || !$dbr ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$querycache = $dbr->tableName( 'querycache' );
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-04-24 08:31:12 +00:00
|
|
|
if ( $ignoreErrors ) {
|
|
|
|
|
$ignoreW = $dbw->ignoreErrors( true );
|
|
|
|
|
$ignoreR = $dbr->ignoreErrors( true );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Clear out any old cached data
|
|
|
|
|
$dbw->delete( 'querycache', array( 'qc_type' => $this->getName() ), $fname );
|
|
|
|
|
# Do query
|
2005-08-09 10:30:20 +00:00
|
|
|
$sql = $this->getSQL() . $this->getOrder();
|
2005-10-12 03:45:56 +00:00
|
|
|
if ($limit !== false)
|
|
|
|
|
$sql = $dbr->limitResult($sql, $limit, 0);
|
2005-08-09 10:30:20 +00:00
|
|
|
$res = $dbr->query($sql, $fname);
|
2005-04-24 08:31:12 +00:00
|
|
|
$num = false;
|
|
|
|
|
if ( $res ) {
|
|
|
|
|
$num = $dbr->numRows( $res );
|
|
|
|
|
# Fetch results
|
|
|
|
|
$insertSql = "INSERT INTO $querycache (qc_type,qc_namespace,qc_title,qc_value) VALUES ";
|
|
|
|
|
$first = true;
|
|
|
|
|
while ( $res && $row = $dbr->fetchObject( $res ) ) {
|
|
|
|
|
if ( $first ) {
|
|
|
|
|
$first = false;
|
|
|
|
|
} else {
|
|
|
|
|
$insertSql .= ',';
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $row->value ) ) {
|
|
|
|
|
$value = $row->value;
|
|
|
|
|
} else {
|
|
|
|
|
$value = '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$insertSql .= '(' .
|
|
|
|
|
$dbw->addQuotes( $row->type ) . ',' .
|
|
|
|
|
$dbw->addQuotes( $row->namespace ) . ',' .
|
|
|
|
|
$dbw->addQuotes( $row->title ) . ',' .
|
|
|
|
|
$dbw->addQuotes( $value ) . ')';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Save results into the querycache table on the master
|
|
|
|
|
if ( !$first ) {
|
|
|
|
|
if ( !$dbw->query( $insertSql, $fname ) ) {
|
|
|
|
|
// Set result to false to indicate error
|
|
|
|
|
$dbr->freeResult( $res );
|
|
|
|
|
$res = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( $res ) {
|
|
|
|
|
$dbr->freeResult( $res );
|
|
|
|
|
}
|
|
|
|
|
if ( $ignoreErrors ) {
|
|
|
|
|
$dbw->ignoreErrors( $ignoreW );
|
|
|
|
|
$dbr->ignoreErrors( $ignoreR );
|
|
|
|
|
}
|
2006-04-17 04:30:39 +00:00
|
|
|
|
|
|
|
|
# Update the querycache_info record for the page
|
|
|
|
|
$dbw->delete( 'querycache_info', array( 'qci_type' => $this->getName() ), $fname );
|
|
|
|
|
$dbw->insert( 'querycache_info', array( 'qci_type' => $this->getName(), 'qci_timestamp' => $dbw->timestamp() ), $fname );
|
|
|
|
|
|
2005-04-24 08:31:12 +00:00
|
|
|
}
|
|
|
|
|
return $num;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* This is the actual workhorse. It does everything needed to make a
|
|
|
|
|
* real, honest-to-gosh query page.
|
|
|
|
|
*
|
|
|
|
|
* @param $offset database query offset
|
|
|
|
|
* @param $limit database query limit
|
2005-05-28 17:17:27 +00:00
|
|
|
* @param $shownavigation show navigation like "next 200"?
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2005-05-28 17:17:27 +00:00
|
|
|
function doQuery( $offset, $limit, $shownavigation=true ) {
|
2006-11-08 07:12:03 +00:00
|
|
|
global $wgUser, $wgOut, $wgLang, $wgContLang;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2006-04-21 06:49:23 +00:00
|
|
|
$this->offset = $offset;
|
|
|
|
|
$this->limit = $limit;
|
|
|
|
|
|
2004-01-25 02:27:49 +00:00
|
|
|
$sname = $this->getName();
|
2004-08-15 19:12:17 +00:00
|
|
|
$fname = get_class($this) . '::doQuery';
|
2007-01-22 23:50:42 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2004-01-25 02:27:49 +00:00
|
|
|
|
2004-11-13 20:33:37 +00:00
|
|
|
$wgOut->setSyndicated( $this->isSyndicated() );
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2006-12-16 21:32:11 +00:00
|
|
|
if ( !$this->isCached() ) {
|
|
|
|
|
$sql = $this->getSQL();
|
|
|
|
|
} else {
|
|
|
|
|
# Get the cached result
|
|
|
|
|
$querycache = $dbr->tableName( 'querycache' );
|
2005-09-16 15:05:07 +00:00
|
|
|
$type = $dbr->strencode( $sname );
|
|
|
|
|
$sql =
|
|
|
|
|
"SELECT qc_type as type, qc_namespace as namespace,qc_title as title, qc_value as value
|
|
|
|
|
FROM $querycache WHERE qc_type='$type'";
|
2006-04-17 04:30:39 +00:00
|
|
|
|
2006-04-17 04:48:12 +00:00
|
|
|
if( !$this->listoutput ) {
|
|
|
|
|
|
|
|
|
|
# Fetch the timestamp of this update
|
|
|
|
|
$tRes = $dbr->select( 'querycache_info', array( 'qci_timestamp' ), array( 'qci_type' => $type ), $fname );
|
|
|
|
|
$tRow = $dbr->fetchObject( $tRes );
|
|
|
|
|
|
|
|
|
|
if( $tRow ) {
|
|
|
|
|
$updated = $wgLang->timeAndDate( $tRow->qci_timestamp, true, true );
|
|
|
|
|
$cacheNotice = wfMsg( 'perfcachedts', $updated );
|
2006-04-17 22:57:39 +00:00
|
|
|
$wgOut->addMeta( 'Data-Cache-Time', $tRow->qci_timestamp );
|
2007-04-01 16:10:50 +00:00
|
|
|
$wgOut->addInlineScript( "var dataCacheTime = '{$tRow->qci_timestamp}';" );
|
2006-04-17 04:48:12 +00:00
|
|
|
} else {
|
|
|
|
|
$cacheNotice = wfMsg( 'perfcached' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$wgOut->addWikiText( $cacheNotice );
|
2007-01-03 23:42:28 +00:00
|
|
|
|
|
|
|
|
# If updates on this page have been disabled, let the user know
|
|
|
|
|
# that the data set won't be refreshed for now
|
|
|
|
|
global $wgDisableQueryPageUpdate;
|
|
|
|
|
if( is_array( $wgDisableQueryPageUpdate ) && in_array( $this->getName(), $wgDisableQueryPageUpdate ) ) {
|
|
|
|
|
$wgOut->addWikiText( wfMsg( 'querypage-no-updates' ) );
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-17 04:48:12 +00:00
|
|
|
}
|
2006-04-17 04:30:39 +00:00
|
|
|
|
2004-01-25 02:27:49 +00:00
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-08-09 10:30:20 +00:00
|
|
|
$sql .= $this->getOrder();
|
|
|
|
|
$sql = $dbr->limitResult($sql, $limit, $offset);
|
2005-08-02 13:35:19 +00:00
|
|
|
$res = $dbr->query( $sql );
|
2005-06-23 18:25:00 +00:00
|
|
|
$num = $dbr->numRows($res);
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-09-11 12:33:59 +00:00
|
|
|
$this->preprocessResults( $dbr, $res );
|
2007-03-28 21:01:58 +00:00
|
|
|
$sk = $wgUser->getSkin();
|
|
|
|
|
|
|
|
|
|
# Top header and navigation
|
|
|
|
|
if( $shownavigation ) {
|
|
|
|
|
$wgOut->addHtml( $this->getPageHeader() );
|
|
|
|
|
if( $num > 0 ) {
|
|
|
|
|
$wgOut->addHtml( '<p>' . wfShowingResults( $offset, $num ) . '</p>' );
|
|
|
|
|
# Disable the "next" link when we reach the end
|
|
|
|
|
$paging = wfViewPrevNext( $offset, $limit, $wgContLang->specialPage( $sname ),
|
|
|
|
|
wfArrayToCGI( $this->linkParameters() ), ( $num < $limit ) );
|
|
|
|
|
$wgOut->addHtml( '<p>' . $paging . '</p>' );
|
|
|
|
|
} else {
|
|
|
|
|
# No results to show, so don't bother with "showing X of Y" etc.
|
|
|
|
|
# -- just let the user know and give up now
|
|
|
|
|
$wgOut->addHtml( '<p>' . wfMsgHtml( 'specialpage-empty' ) . '</p>' );
|
2007-02-21 10:42:04 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2005-05-28 17:17:27 +00:00
|
|
|
}
|
2007-03-28 21:01:58 +00:00
|
|
|
|
|
|
|
|
# The actual results; specialist subclasses will want to handle this
|
|
|
|
|
# with more than a straight list, so we hand them the info, plus
|
|
|
|
|
# an OutputPage, and let them get on with it
|
|
|
|
|
$this->outputResults( $wgOut,
|
|
|
|
|
$wgUser->getSkin(),
|
|
|
|
|
$dbr, # Should use a ResultWrapper for this
|
|
|
|
|
$res,
|
|
|
|
|
$dbr->numRows( $res ),
|
|
|
|
|
$offset );
|
|
|
|
|
|
|
|
|
|
# Repeat the paging links at the bottom
|
|
|
|
|
if( $shownavigation ) {
|
|
|
|
|
$wgOut->addHtml( '<p>' . $paging . '</p>' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $num;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Format and output report results using the given information plus
|
|
|
|
|
* OutputPage
|
|
|
|
|
*
|
|
|
|
|
* @param OutputPage $out OutputPage to print to
|
|
|
|
|
* @param Skin $skin User skin to use
|
|
|
|
|
* @param Database $dbr Database (read) connection to use
|
|
|
|
|
* @param int $res Result pointer
|
|
|
|
|
* @param int $num Number of available result rows
|
|
|
|
|
* @param int $offset Paging offset
|
|
|
|
|
*/
|
|
|
|
|
protected function outputResults( $out, $skin, $dbr, $res, $num, $offset ) {
|
|
|
|
|
global $wgContLang;
|
|
|
|
|
|
|
|
|
|
if( $num > 0 ) {
|
|
|
|
|
$html = array();
|
|
|
|
|
if( !$this->listoutput )
|
|
|
|
|
$html[] = $this->openList( $offset );
|
|
|
|
|
|
|
|
|
|
# $res might contain the whole 1,000 rows, so we read up to
|
|
|
|
|
# $num [should update this to use a Pager]
|
|
|
|
|
for( $i = 0; $i < $num && $row = $dbr->fetchObject( $res ); $i++ ) {
|
|
|
|
|
$line = $this->formatResult( $skin, $row );
|
|
|
|
|
if( $line ) {
|
|
|
|
|
$attr = ( isset( $obj->usepatrol ) && $obj->usepatrol && $obj->patrolled == 0 )
|
|
|
|
|
? ' class="not-patrolled"'
|
|
|
|
|
: '';
|
|
|
|
|
$html[] = $this->listoutput
|
|
|
|
|
? $format
|
|
|
|
|
: "<li{$attr}>{$line}</li>\n";
|
2005-02-01 01:41:30 +00:00
|
|
|
}
|
2005-01-16 02:57:30 +00:00
|
|
|
}
|
2007-03-28 21:01:58 +00:00
|
|
|
|
|
|
|
|
# Flush the final result
|
|
|
|
|
if( $this->tryLastResult() ) {
|
|
|
|
|
$row = null;
|
|
|
|
|
$line = $this->formatResult( $skin, $row );
|
|
|
|
|
if( $line ) {
|
|
|
|
|
$attr = ( isset( $obj->usepatrol ) && $obj->usepatrol && $obj->patrolled == 0 )
|
|
|
|
|
? ' class="not-patrolled"'
|
|
|
|
|
: '';
|
|
|
|
|
$html[] = $this->listoutput
|
|
|
|
|
? $format
|
|
|
|
|
: "<li{$attr}>{$line}</li>\n";
|
2005-02-01 02:02:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
2007-03-28 21:01:58 +00:00
|
|
|
|
|
|
|
|
if( !$this->listoutput )
|
|
|
|
|
$html[] = $this->closeList();
|
|
|
|
|
|
|
|
|
|
$html = $this->listoutput
|
|
|
|
|
? $wgContLang->listToText( $html )
|
|
|
|
|
: implode( '', $html );
|
|
|
|
|
|
|
|
|
|
$out->addHtml( $html );
|
2004-01-25 02:27:49 +00:00
|
|
|
}
|
I was adding a special page (dead-end pages), and I realized that almost all
the special query pages were pretty much identical. I copy-and-pasted one to
make the one I was working on, and I realized that that was Wrong.
So, I took the common elements and made them into a class, QueryPage.php.
Then, I derived each of the existing special pages from QueryPage, and
overrode places where they differed. This is a Recipe pattern, btw, for
those of you following along at home.
Anyways, the upshot is that the query pages are a lot shorter, with just the
essentials that make them different from other query pages, and there's one
place to make big UI changes for all queries.
2003-12-01 16:04:35 +00:00
|
|
|
}
|
2006-12-04 22:54:12 +00:00
|
|
|
|
|
|
|
|
function openList( $offset ) {
|
|
|
|
|
return "<ol start='" . ( $offset + 1 ) . "' class='special'>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function closeList() {
|
|
|
|
|
return '</ol>';
|
|
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2005-09-11 12:33:59 +00:00
|
|
|
/**
|
2005-12-04 20:56:20 +00:00
|
|
|
* Do any necessary preprocessing of the result object.
|
2006-11-29 05:45:03 +00:00
|
|
|
* You should pass this by reference: &$db , &$res [although probably no longer necessary in PHP5]
|
2005-09-11 12:33:59 +00:00
|
|
|
*/
|
2006-11-29 05:45:03 +00:00
|
|
|
function preprocessResults( &$db, &$res ) {}
|
2005-09-11 12:33:59 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Similar to above, but packaging in a syndicated feed instead of a web page
|
|
|
|
|
*/
|
2006-04-13 20:01:48 +00:00
|
|
|
function doFeed( $class = '', $limit = 50 ) {
|
2004-03-05 10:16:46 +00:00
|
|
|
global $wgFeedClasses;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2004-04-28 04:37:31 +00:00
|
|
|
if( isset($wgFeedClasses[$class]) ) {
|
|
|
|
|
$feed = new $wgFeedClasses[$class](
|
2004-03-05 10:16:46 +00:00
|
|
|
$this->feedTitle(),
|
|
|
|
|
$this->feedDesc(),
|
|
|
|
|
$this->feedUrl() );
|
|
|
|
|
$feed->outHeader();
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2007-01-22 23:50:42 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2005-08-09 10:32:59 +00:00
|
|
|
$sql = $this->getSQL() . $this->getOrder();
|
2006-04-13 20:01:48 +00:00
|
|
|
$sql = $dbr->limitResult( $sql, $limit, 0 );
|
2004-08-15 19:12:17 +00:00
|
|
|
$res = $dbr->query( $sql, 'QueryPage::doFeed' );
|
2004-07-10 03:09:26 +00:00
|
|
|
while( $obj = $dbr->fetchObject( $res ) ) {
|
2004-03-05 10:16:46 +00:00
|
|
|
$item = $this->feedResult( $obj );
|
|
|
|
|
if( $item ) $feed->outItem( $item );
|
|
|
|
|
}
|
2004-07-10 03:09:26 +00:00
|
|
|
$dbr->freeResult( $res );
|
2004-03-05 10:16:46 +00:00
|
|
|
|
|
|
|
|
$feed->outFooter();
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Override for custom handling. If the titles/links are ok, just do
|
|
|
|
|
* feedItemDesc()
|
|
|
|
|
*/
|
2004-03-05 11:21:43 +00:00
|
|
|
function feedResult( $row ) {
|
2004-05-09 01:30:34 +00:00
|
|
|
if( !isset( $row->title ) ) {
|
2004-03-05 10:16:46 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
2005-08-16 23:36:16 +00:00
|
|
|
$title = Title::MakeTitle( intval( $row->namespace ), $row->title );
|
2004-03-05 10:16:46 +00:00
|
|
|
if( $title ) {
|
2005-09-13 17:32:55 +00:00
|
|
|
$date = isset( $row->timestamp ) ? $row->timestamp : '';
|
2004-08-15 19:12:17 +00:00
|
|
|
$comments = '';
|
2004-04-29 01:14:32 +00:00
|
|
|
if( $title ) {
|
|
|
|
|
$talkpage = $title->getTalkPage();
|
|
|
|
|
$comments = $talkpage->getFullURL();
|
2004-04-28 04:37:31 +00:00
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-03-05 10:16:46 +00:00
|
|
|
return new FeedItem(
|
2005-03-18 06:49:14 +00:00
|
|
|
$title->getPrefixedText(),
|
2004-03-05 11:21:43 +00:00
|
|
|
$this->feedItemDesc( $row ),
|
2004-03-07 07:26:56 +00:00
|
|
|
$title->getFullURL(),
|
2004-03-19 05:31:18 +00:00
|
|
|
$date,
|
2004-04-28 04:37:31 +00:00
|
|
|
$this->feedItemAuthor( $row ),
|
|
|
|
|
$comments);
|
2004-03-05 10:16:46 +00:00
|
|
|
} else {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-03-05 10:16:46 +00:00
|
|
|
function feedItemDesc( $row ) {
|
2005-09-13 17:32:55 +00:00
|
|
|
return isset( $row->comment ) ? htmlspecialchars( $row->comment ) : '';
|
2004-03-19 05:31:18 +00:00
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-03-19 05:31:18 +00:00
|
|
|
function feedItemAuthor( $row ) {
|
2005-09-13 17:32:55 +00:00
|
|
|
return isset( $row->user_text ) ? $row->user_text : '';
|
2004-03-05 10:16:46 +00:00
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-03-05 10:16:46 +00:00
|
|
|
function feedTitle() {
|
2006-07-26 08:26:51 +00:00
|
|
|
global $wgContLanguageCode, $wgSitename;
|
2004-05-20 14:13:03 +00:00
|
|
|
$page = SpecialPage::getPage( $this->getName() );
|
|
|
|
|
$desc = $page->getDescription();
|
2006-07-26 08:26:51 +00:00
|
|
|
return "$wgSitename - $desc [$wgContLanguageCode]";
|
2004-03-05 10:16:46 +00:00
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-03-05 10:16:46 +00:00
|
|
|
function feedDesc() {
|
2004-09-03 21:29:06 +00:00
|
|
|
return wfMsg( 'tagline' );
|
2004-03-05 10:16:46 +00:00
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-03-05 10:16:46 +00:00
|
|
|
function feedUrl() {
|
2006-10-30 06:25:31 +00:00
|
|
|
$title = SpecialPage::getTitleFor( $this->getName() );
|
2004-03-08 09:09:35 +00:00
|
|
|
return $title->getFullURL();
|
2004-03-05 10:16:46 +00:00
|
|
|
}
|
I was adding a special page (dead-end pages), and I realized that almost all
the special query pages were pretty much identical. I copy-and-pasted one to
make the one I was working on, and I realized that that was Wrong.
So, I took the common elements and made them into a class, QueryPage.php.
Then, I derived each of the existing special pages from QueryPage, and
overrode places where they differed. This is a Recipe pattern, btw, for
those of you following along at home.
Anyways, the upshot is that the query pages are a lot shorter, with just the
essentials that make them different from other query pages, and there's one
place to make big UI changes for all queries.
2003-12-01 16:04:35 +00:00
|
|
|
}
|
|
|
|
|
|
2007-04-08 07:26:55 +00:00
|
|
|
?>
|