2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Contain a class for special pages
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @file
|
|
|
|
|
* @ingroup SpecialPages
|
2004-09-02 23:28:24 +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
|
|
|
|
2005-04-24 04:16:50 +00:00
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* List of query page classes and their associated special pages,
|
2007-02-21 17:37:25 +00:00
|
|
|
* for periodic updates.
|
|
|
|
|
*
|
2008-04-14 07:45:50 +00:00
|
|
|
* DO NOT CHANGE THIS LIST without testing that
|
2007-02-21 17:37:25 +00:00
|
|
|
* 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' ),
|
2008-09-14 19:51:25 +00:00
|
|
|
array( 'LinkSearchPage', 'LinkSearch' ),
|
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' ),
|
2007-06-04 21:39:12 +00:00
|
|
|
array( 'SpecialMostlinkedtemplates', 'Mostlinkedtemplates' ),
|
2007-02-21 17:37:25 +00:00
|
|
|
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( 'ShortPagesPage', 'Shortpages' ),
|
|
|
|
|
array( 'UncategorizedCategoriesPage', 'Uncategorizedcategories' ),
|
|
|
|
|
array( 'UncategorizedPagesPage', 'Uncategorizedpages' ),
|
2007-03-31 22:54:30 +00:00
|
|
|
array( 'UncategorizedImagesPage', 'Uncategorizedimages' ),
|
2007-06-11 07:04:25 +00:00
|
|
|
array( 'UncategorizedTemplatesPage', 'Uncategorizedtemplates' ),
|
2007-02-21 17:37:25 +00:00
|
|
|
array( 'UnusedCategoriesPage', 'Unusedcategories' ),
|
|
|
|
|
array( 'UnusedimagesPage', 'Unusedimages' ),
|
|
|
|
|
array( 'WantedCategoriesPage', 'Wantedcategories' ),
|
2008-09-11 22:30:27 +00:00
|
|
|
array( 'WantedFilesPage', 'Wantedfiles' ),
|
2007-02-21 17:37:25 +00:00
|
|
|
array( 'WantedPagesPage', 'Wantedpages' ),
|
2008-10-18 17:32:40 +00:00
|
|
|
array( 'WantedTemplatesPage', 'Wantedtemplates' ),
|
2007-02-21 17:37:25 +00:00
|
|
|
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.
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup SpecialPage
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
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 ) {
|
2009-02-21 17:30:59 +00:00
|
|
|
$fname = get_class( $this ) . '::recache';
|
2007-01-22 23:50:42 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
2009-03-30 20:04:34 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE, array( $this->getName(), __METHOD__, '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();
|
2009-02-21 17:30:59 +00:00
|
|
|
if ( $limit !== false )
|
|
|
|
|
$sql = $dbr->limitResult( $sql, $limit, 0 );
|
|
|
|
|
$res = $dbr->query( $sql, $fname );
|
2005-04-24 08:31:12 +00:00
|
|
|
$num = false;
|
|
|
|
|
if ( $res ) {
|
|
|
|
|
$num = $dbr->numRows( $res );
|
|
|
|
|
# Fetch results
|
2009-03-30 20:04:34 +00:00
|
|
|
$vals = array();
|
2005-04-24 08:31:12 +00:00
|
|
|
while ( $res && $row = $dbr->fetchObject( $res ) ) {
|
|
|
|
|
if ( isset( $row->value ) ) {
|
2009-02-21 17:30:59 +00:00
|
|
|
$value = intval( $row->value ); // @bug 14414
|
2005-04-24 08:31:12 +00:00
|
|
|
} else {
|
2008-06-05 17:20:26 +00:00
|
|
|
$value = 0;
|
2005-04-24 08:31:12 +00:00
|
|
|
}
|
2009-03-30 20:04:34 +00:00
|
|
|
|
|
|
|
|
$vals[] = array('qc_type' => $row->type,
|
|
|
|
|
'qc_namespace' => $row->namespace,
|
|
|
|
|
'qc_title' => $row->title,
|
|
|
|
|
'qc_value' => $value);
|
2005-04-24 08:31:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Save results into the querycache table on the master
|
2009-03-30 20:04:34 +00:00
|
|
|
if ( count( $vals ) ) {
|
2009-03-30 23:13:34 +00:00
|
|
|
if ( !$dbw->insert( 'querycache', $vals, __METHOD__ ) ) {
|
2005-04-24 08:31:12 +00:00
|
|
|
// 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;
|
|
|
|
|
|
2009-07-14 08:44:58 +00:00
|
|
|
$sname = $this->getName();
|
|
|
|
|
$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
|
|
|
|
2009-07-14 08:44:58 +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' );
|
2009-07-14 08:44:58 +00:00
|
|
|
$type = $dbr->strencode( $sname );
|
2005-09-16 15:05:07 +00:00
|
|
|
$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 );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2006-04-17 04:48:12 +00:00
|
|
|
if( $tRow ) {
|
2009-09-26 19:08:54 +00:00
|
|
|
$updated = $wgLang->timeanddate( $tRow->qci_timestamp, true, true );
|
|
|
|
|
$updateddate = $wgLang->date( $tRow->qci_timestamp, true, true );
|
|
|
|
|
$updatedtime = $wgLang->time( $tRow->qci_timestamp, true, true );
|
2009-07-14 08:44:58 +00:00
|
|
|
$wgOut->addMeta( 'Data-Cache-Time', $tRow->qci_timestamp );
|
|
|
|
|
$wgOut->addInlineScript( "var dataCacheTime = '{$tRow->qci_timestamp}';" );
|
2009-09-26 19:08:54 +00:00
|
|
|
$wgOut->addWikiMsg( 'perfcachedts', $updated, $updateddate, $updatedtime );
|
2006-04-17 04:48:12 +00:00
|
|
|
} else {
|
2009-07-14 08:44:58 +00:00
|
|
|
$wgOut->addWikiMsg( 'perfcached' );
|
2006-04-17 04:48:12 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
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 ) ) {
|
2009-07-14 08:44:58 +00:00
|
|
|
$wgOut->addWikiMsg( 'querypage-no-updates' );
|
2007-01-03 23:42:28 +00:00
|
|
|
}
|
2009-07-14 08:44:58 +00:00
|
|
|
|
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 );
|
2009-07-14 08:44:58 +00:00
|
|
|
|
|
|
|
|
$wgOut->addHTML( XML::openElement( 'div', array('class' => 'mw-spcontent') ) );
|
|
|
|
|
|
|
|
|
|
# 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>' );
|
|
|
|
|
$wgOut->addHTML( XML::closeElement( 'div' ) );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 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>' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$wgOut->addHTML( XML::closeElement( 'div' ) );
|
|
|
|
|
|
|
|
|
|
return $num;
|
2007-03-28 21:01:58 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-03-28 21:01:58 +00:00
|
|
|
/**
|
|
|
|
|
* 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;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-03-28 21:01:58 +00:00
|
|
|
if( $num > 0 ) {
|
|
|
|
|
$html = array();
|
|
|
|
|
if( !$this->listoutput )
|
|
|
|
|
$html[] = $this->openList( $offset );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-03-28 21:01:58 +00:00
|
|
|
# $res might contain the whole 1,000 rows, so we read up to
|
|
|
|
|
# $num [should update this to use a Pager]
|
2009-07-14 08:44:58 +00:00
|
|
|
for( $i = 0; $i < $num && $row = $dbr->fetchObject( $res ); $i++ ) {
|
2007-03-28 21:01:58 +00:00
|
|
|
$line = $this->formatResult( $skin, $row );
|
|
|
|
|
if( $line ) {
|
2008-04-13 21:01:06 +00:00
|
|
|
$attr = ( isset( $row->usepatrol ) && $row->usepatrol && $row->patrolled == 0 )
|
|
|
|
|
? ' class="not-patrolled"'
|
|
|
|
|
: '';
|
2007-03-28 21:01:58 +00:00
|
|
|
$html[] = $this->listoutput
|
2007-09-04 19:29:47 +00:00
|
|
|
? $line
|
2007-03-28 21:01:58 +00:00
|
|
|
: "<li{$attr}>{$line}</li>\n";
|
2005-02-01 01:41:30 +00:00
|
|
|
}
|
2005-01-16 02:57:30 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +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 ) {
|
2007-04-20 04:06:06 +00:00
|
|
|
$attr = ( isset( $row->usepatrol ) && $row->usepatrol && $row->patrolled == 0 )
|
2007-03-28 21:01:58 +00:00
|
|
|
? ' class="not-patrolled"'
|
|
|
|
|
: '';
|
|
|
|
|
$html[] = $this->listoutput
|
2007-09-04 19:29:47 +00:00
|
|
|
? $line
|
2007-03-28 21:01:58 +00:00
|
|
|
: "<li{$attr}>{$line}</li>\n";
|
2005-02-01 02:02:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-03-28 21:01:58 +00:00
|
|
|
if( !$this->listoutput )
|
|
|
|
|
$html[] = $this->closeList();
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-03-28 21:01:58 +00:00
|
|
|
$html = $this->listoutput
|
|
|
|
|
? $wgContLang->listToText( $html )
|
|
|
|
|
: implode( '', $html );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-11-06 22:20:29 +00:00
|
|
|
$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
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2006-12-04 22:54:12 +00:00
|
|
|
function openList( $offset ) {
|
2007-05-27 08:22:37 +00:00
|
|
|
return "\n<ol start='" . ( $offset + 1 ) . "' class='special'>\n";
|
2006-12-04 22:54:12 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2006-12-04 22:54:12 +00:00
|
|
|
function closeList() {
|
2007-05-27 08:22:37 +00:00
|
|
|
return "</ol>\n";
|
2006-12-04 22:54:12 +00:00
|
|
|
}
|
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.
|
2005-09-11 12:33:59 +00:00
|
|
|
*/
|
2008-02-12 02:43:25 +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 ) {
|
2008-02-22 12:33:51 +00:00
|
|
|
global $wgFeed, $wgFeedClasses;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-02-22 12:33:51 +00:00
|
|
|
if ( !$wgFeed ) {
|
|
|
|
|
global $wgOut;
|
|
|
|
|
$wgOut->addWikiMsg( 'feed-unavailable' );
|
|
|
|
|
return;
|
|
|
|
|
}
|
2008-05-16 21:34:46 +00:00
|
|
|
|
|
|
|
|
global $wgFeedLimit;
|
|
|
|
|
if( $limit > $wgFeedLimit ) {
|
|
|
|
|
$limit = $wgFeedLimit;
|
|
|
|
|
}
|
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() {
|
2008-12-19 08:54:51 +00:00
|
|
|
return wfMsgExt( 'tagline', 'parsemag' );
|
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
|
|
|
}
|
2009-04-15 03:35:59 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class definition for a wanted query page like
|
|
|
|
|
* WantedPages, WantedTemplates, etc
|
|
|
|
|
*/
|
|
|
|
|
abstract class WantedQueryPage extends QueryPage {
|
|
|
|
|
|
|
|
|
|
function isExpensive() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isSyndicated() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2009-06-13 12:39:00 +00:00
|
|
|
|
2009-04-15 03:35:59 +00:00
|
|
|
/**
|
|
|
|
|
* Cache page existence for performance
|
|
|
|
|
*/
|
|
|
|
|
function preprocessResults( $db, $res ) {
|
|
|
|
|
$batch = new LinkBatch;
|
|
|
|
|
while ( $row = $db->fetchObject( $res ) )
|
|
|
|
|
$batch->add( $row->namespace, $row->title );
|
|
|
|
|
$batch->execute();
|
|
|
|
|
|
|
|
|
|
// Back to start for display
|
|
|
|
|
if ( $db->numRows( $res ) > 0 )
|
|
|
|
|
// If there are no rows we get an error seeking.
|
|
|
|
|
$db->dataSeek( $res, 0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Format an individual result
|
|
|
|
|
*
|
|
|
|
|
* @param $skin Skin to use for UI elements
|
|
|
|
|
* @param $result Result row
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function formatResult( $skin, $result ) {
|
|
|
|
|
$title = Title::makeTitleSafe( $result->namespace, $result->title );
|
|
|
|
|
if( $title instanceof Title ) {
|
|
|
|
|
if( $this->isCached() ) {
|
|
|
|
|
$pageLink = $title->exists()
|
2009-05-08 23:24:31 +00:00
|
|
|
? '<s>' . $skin->link( $title ) . '</s>'
|
2009-06-13 12:39:00 +00:00
|
|
|
: $skin->link(
|
|
|
|
|
$title,
|
|
|
|
|
null,
|
|
|
|
|
array(),
|
|
|
|
|
array(),
|
|
|
|
|
array( 'broken' )
|
|
|
|
|
);
|
2009-04-15 03:35:59 +00:00
|
|
|
} else {
|
2009-06-13 12:39:00 +00:00
|
|
|
$pageLink = $skin->link(
|
|
|
|
|
$title,
|
|
|
|
|
null,
|
|
|
|
|
array(),
|
|
|
|
|
array(),
|
|
|
|
|
array( 'broken' )
|
|
|
|
|
);
|
2009-04-15 03:35:59 +00:00
|
|
|
}
|
|
|
|
|
return wfSpecialList( $pageLink, $this->makeWlhLink( $title, $skin, $result ) );
|
|
|
|
|
} else {
|
|
|
|
|
$tsafe = htmlspecialchars( $result->title );
|
2009-05-22 09:35:48 +00:00
|
|
|
return wfMsgHtml( 'wantedpages-badtitle', $tsafe );
|
2009-04-15 03:35:59 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Make a "what links here" link for a given title
|
|
|
|
|
*
|
|
|
|
|
* @param Title $title Title to make the link for
|
|
|
|
|
* @param Skin $skin Skin to use
|
|
|
|
|
* @param object $result Result row
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function makeWlhLink( $title, $skin, $result ) {
|
|
|
|
|
global $wgLang;
|
|
|
|
|
$wlh = SpecialPage::getTitleFor( 'Whatlinkshere' );
|
|
|
|
|
$label = wfMsgExt( 'nlinks', array( 'parsemag', 'escape' ),
|
|
|
|
|
$wgLang->formatNum( $result->value ) );
|
|
|
|
|
return $skin->link( $wlh, $label, array(), array( 'target' => $title->getPrefixedText() ) );
|
|
|
|
|
}
|
2009-09-10 06:43:01 +00:00
|
|
|
}
|