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)
|
2010-12-22 14:16:25 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2007-02-21 17:37:25 +00:00
|
|
|
array( 'AncientPagesPage', 'Ancientpages' ),
|
|
|
|
|
array( 'BrokenRedirectsPage', 'BrokenRedirects' ),
|
|
|
|
|
array( 'DeadendPagesPage', 'Deadendpages' ),
|
|
|
|
|
array( 'DisambiguationsPage', 'Disambiguations' ),
|
|
|
|
|
array( 'DoubleRedirectsPage', 'DoubleRedirects' ),
|
2010-12-22 14:16:25 +00:00
|
|
|
array( 'FileDuplicateSearchPage', 'FileDuplicateSearch' ),
|
2008-09-14 19:51:25 +00:00
|
|
|
array( 'LinkSearchPage', 'LinkSearch' ),
|
2010-01-23 20:07:17 +00:00
|
|
|
array( 'ListredirectsPage', 'Listredirects' ),
|
2007-02-21 17:37:25 +00:00
|
|
|
array( 'LonelyPagesPage', 'Lonelypages' ),
|
|
|
|
|
array( 'LongPagesPage', 'Longpages' ),
|
2010-12-22 14:16:25 +00:00
|
|
|
array( 'MIMEsearchPage', 'MIMEsearch' ),
|
2007-02-21 17:37:25 +00:00
|
|
|
array( 'MostcategoriesPage', 'Mostcategories' ),
|
|
|
|
|
array( 'MostimagesPage', 'Mostimages' ),
|
|
|
|
|
array( 'MostlinkedCategoriesPage', 'Mostlinkedcategories' ),
|
2010-12-22 14:16:25 +00:00
|
|
|
array( 'MostlinkedtemplatesPage', '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' ),
|
2010-01-23 20:07:17 +00:00
|
|
|
array( 'UncategorizedImagesPage', 'Uncategorizedimages' ),
|
|
|
|
|
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' ),
|
2010-01-23 20:07:17 +00:00
|
|
|
array( 'WantedTemplatesPage', 'Wantedtemplates' ),
|
2007-02-21 17:37:25 +00:00
|
|
|
array( 'UnwatchedPagesPage', 'Unwatchedpages' ),
|
2010-01-23 20:07:17 +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 )
|
2010-12-22 14:16:25 +00:00
|
|
|
$wgQueryPages[] = array( 'PopularPagesPage', 'Popularpages' );
|
2005-10-19 01:39:12 +00:00
|
|
|
|
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
|
|
|
*/
|
2010-12-22 14:16:25 +00:00
|
|
|
abstract class QueryPage extends SpecialPage {
|
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
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
/**
|
|
|
|
|
* The number of rows returned by the query. Reading this variable
|
|
|
|
|
* only makes sense in functions that are run after the query has been
|
|
|
|
|
* done, such as preprocessResults() and formatRow().
|
|
|
|
|
*/
|
|
|
|
|
protected $numRows;
|
|
|
|
|
|
2010-12-22 20:43:22 +00:00
|
|
|
protected $cachedTimestamp = null;
|
|
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
/**
|
|
|
|
|
* Wheter to show prev/next links
|
|
|
|
|
*/
|
2010-12-22 17:29:31 +00:00
|
|
|
protected $shownavigation = true;
|
2010-12-22 14:16:25 +00:00
|
|
|
|
2005-10-16 02:03:21 +00:00
|
|
|
/**
|
|
|
|
|
* A mutator for $this->listoutput;
|
|
|
|
|
*
|
2010-01-23 20:07:17 +00:00
|
|
|
* @param $bool Boolean
|
2005-10-16 02:03:21 +00:00
|
|
|
*/
|
|
|
|
|
function setListoutput( $bool ) {
|
|
|
|
|
$this->listoutput = $bool;
|
|
|
|
|
}
|
2004-09-03 21:22:20 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2010-12-22 14:16:25 +00:00
|
|
|
* Subclasses return an SQL query here, formatted as an array with the
|
|
|
|
|
* following keys:
|
|
|
|
|
* tables => Table(s) for passing to Database::select()
|
|
|
|
|
* fields => Field(s) for passing to Database::select(), may be *
|
|
|
|
|
* conds => WHERE conditions
|
|
|
|
|
* options => options
|
|
|
|
|
* join_conds => JOIN conditions
|
2004-09-03 21:22:20 +00:00
|
|
|
*
|
2010-12-22 14:16:25 +00:00
|
|
|
* Note that the query itself should return the following three columns:
|
2010-12-22 19:57:31 +00:00
|
|
|
* 'namespace', 'title', and 'value'. 'value' is used for sorting.
|
2004-09-02 23:28:24 +00:00
|
|
|
*
|
|
|
|
|
* 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
|
2010-12-22 14:16:25 +00:00
|
|
|
* an integer; non-numeric values are useful only for sorting the
|
|
|
|
|
* initial query (except if they're timestamps, see usesTimestamps()).
|
2004-09-02 23:28:24 +00:00
|
|
|
*
|
2010-12-22 14:16:25 +00:00
|
|
|
* Don't include an ORDER or LIMIT clause, they will be added.
|
|
|
|
|
*
|
|
|
|
|
* If this function is not overridden or returns something other than
|
|
|
|
|
* an array, getSQL() will be used instead. This is for backwards
|
|
|
|
|
* compatibility only and is strongly deprecated.
|
|
|
|
|
* @return array
|
|
|
|
|
* @since 1.18
|
|
|
|
|
*/
|
|
|
|
|
function getQueryInfo() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2011-02-12 04:06:22 +00:00
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
/**
|
|
|
|
|
* For back-compat, subclasses may return a raw SQL query here, as a string.
|
|
|
|
|
* This is stronly deprecated; getQueryInfo() should be overridden instead.
|
|
|
|
|
* @return string
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2004-05-09 01:30:34 +00:00
|
|
|
function getSQL() {
|
2011-01-06 19:15:02 +00:00
|
|
|
/* Implement getQueryInfo() instead */
|
2010-12-22 14:16:25 +00:00
|
|
|
throw new MWException( "Bug in a QueryPage: doesn't implement getQueryInfo() nor getQuery() properly" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Subclasses return an array of fields to order by here. Don't append
|
|
|
|
|
* DESC to the field names, that'll be done automatically if
|
|
|
|
|
* sortDescending() returns true.
|
|
|
|
|
* @return array
|
|
|
|
|
* @since 1.18
|
|
|
|
|
*/
|
|
|
|
|
function getOrderFields() {
|
|
|
|
|
return array( 'value' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Does this query return timestamps rather than integers in its
|
|
|
|
|
* 'value' field? If true, this class will convert 'value' to a
|
|
|
|
|
* UNIX timestamp for caching.
|
|
|
|
|
* NOTE: formatRow() may get timestamps in TS_MW (mysql), TS_DB (pgsql)
|
|
|
|
|
* or TS_UNIX (querycache) format, so be sure to always run them
|
|
|
|
|
* through wfTimestamp()
|
|
|
|
|
* @return bool
|
2010-12-22 15:22:59 +00:00
|
|
|
* @since 1.18
|
2010-12-22 14:16:25 +00:00
|
|
|
*/
|
|
|
|
|
function usesTimestamps() {
|
|
|
|
|
return false;
|
2004-05-09 01:30:34 +00:00
|
|
|
}
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Override to sort by increasing values
|
2010-01-23 20:07:17 +00:00
|
|
|
*
|
|
|
|
|
* @return Boolean
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
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-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.
|
2010-01-23 20:07:17 +00:00
|
|
|
*
|
|
|
|
|
* @return Boolean
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2010-01-23 20:07:17 +00:00
|
|
|
function isExpensive() {
|
2004-01-25 02:27:49 +00:00
|
|
|
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
|
|
|
/**
|
2010-12-22 14:16:25 +00:00
|
|
|
* Is the output of this query cacheable? Non-cacheable expensive pages
|
|
|
|
|
* will be disabled in miser mode and will not have their results written
|
|
|
|
|
* to the querycache table.
|
|
|
|
|
* @return Boolean
|
2010-12-22 15:22:59 +00:00
|
|
|
* @since 1.18
|
2010-12-22 14:16:25 +00:00
|
|
|
*/
|
|
|
|
|
public function isCacheable() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether or not the output of the page in question is retrieved from
|
2005-09-16 15:05:07 +00:00
|
|
|
* the database cache.
|
|
|
|
|
*
|
2010-01-23 20:07:17 +00:00
|
|
|
* @return Boolean
|
2005-09-16 15:05:07 +00:00
|
|
|
*/
|
|
|
|
|
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.
|
2010-01-23 20:07:17 +00:00
|
|
|
*
|
|
|
|
|
* @return Boolean
|
2004-11-13 20:33:37 +00:00
|
|
|
*/
|
|
|
|
|
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.
|
2010-12-22 14:16:25 +00:00
|
|
|
* If the function returns false, the line output will be skipped.
|
|
|
|
|
* @param $skin Skin
|
|
|
|
|
* @param $result object Result row
|
|
|
|
|
* @return mixed String or false to skip
|
2010-01-23 20:07:17 +00:00
|
|
|
*
|
|
|
|
|
* @param $skin Skin object
|
|
|
|
|
* @param $result Object: database row
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2010-12-22 14:16:25 +00:00
|
|
|
abstract function formatResult( $skin, $result );
|
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
|
2010-01-23 20:07:17 +00:00
|
|
|
*
|
|
|
|
|
* @return String
|
2005-06-30 07:37:04 +00:00
|
|
|
*/
|
2010-01-23 20:07:17 +00:00
|
|
|
function getPageHeader() {
|
2004-08-15 19:22:40 +00:00
|
|
|
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).
|
2010-01-23 20:07:17 +00:00
|
|
|
*
|
|
|
|
|
* @return Array
|
2005-06-30 07:37:04 +00:00
|
|
|
*/
|
|
|
|
|
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.
|
2010-12-22 14:16:25 +00:00
|
|
|
* Setting this to return true will ensure formatResult() is called
|
|
|
|
|
* one more time to make sure that the very last result is formatted
|
|
|
|
|
* as well.
|
2005-02-01 02:02:14 +00:00
|
|
|
*/
|
2010-01-23 20:07:17 +00:00
|
|
|
function tryLastResult() {
|
2005-02-01 02:02:14 +00:00
|
|
|
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
|
2010-01-23 20:07:17 +00:00
|
|
|
*
|
|
|
|
|
* @param $limit Integer: limit for SQL statement
|
|
|
|
|
* @param $ignoreErrors Boolean: whether to ignore database errors
|
2005-04-24 08:31:12 +00:00
|
|
|
*/
|
2005-10-12 03:45:56 +00:00
|
|
|
function recache( $limit, $ignoreErrors = true ) {
|
2010-12-22 16:18:24 +00:00
|
|
|
if ( !$this->isCacheable() ) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2011-02-12 04:06:22 +00:00
|
|
|
|
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' ) );
|
2010-12-22 16:18:24 +00:00
|
|
|
if ( !$dbw || !$dbr ) {
|
2005-04-24 08:31:12 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
2010-12-22 14:16:25 +00:00
|
|
|
$res = $this->reallyDoQuery( $limit, false );
|
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 ) ) {
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( $this->usesTimestamps() ) {
|
|
|
|
|
$value = wfTimestamp( TS_UNIX,
|
|
|
|
|
$row->value );
|
|
|
|
|
} else {
|
|
|
|
|
$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
|
|
|
}
|
2010-12-22 14:16:25 +00:00
|
|
|
|
|
|
|
|
$vals[] = array( 'qc_type' => $this->getName(),
|
2009-03-30 20:04:34 +00:00
|
|
|
'qc_namespace' => $row->namespace,
|
|
|
|
|
'qc_title' => $row->title,
|
2010-12-22 14:16:25 +00:00
|
|
|
'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
|
2010-12-22 14:16:25 +00:00
|
|
|
$num = false;
|
2005-04-24 08:31:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
/**
|
|
|
|
|
* Run the query and return the result
|
|
|
|
|
* @param $limit mixed Numerical limit or false for no limit
|
|
|
|
|
* @param $offset mixed Numerical offset or false for no offset
|
|
|
|
|
* @return ResultWrapper
|
2010-12-22 15:22:59 +00:00
|
|
|
* @since 1.18
|
2010-12-22 14:16:25 +00:00
|
|
|
*/
|
|
|
|
|
function reallyDoQuery( $limit, $offset = false ) {
|
|
|
|
|
$fname = get_class( $this ) . "::reallyDoQuery";
|
2010-12-22 18:08:52 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2010-12-22 14:16:25 +00:00
|
|
|
$query = $this->getQueryInfo();
|
|
|
|
|
$order = $this->getOrderFields();
|
|
|
|
|
if ( $this->sortDescending() ) {
|
|
|
|
|
foreach ( $order as &$field ) {
|
|
|
|
|
$field .= ' DESC';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( is_array( $query ) ) {
|
|
|
|
|
$tables = isset( $query['tables'] ) ? (array)$query['tables'] : array();
|
|
|
|
|
$fields = isset( $query['fields'] ) ? (array)$query['fields'] : array();
|
|
|
|
|
$conds = isset( $query['conds'] ) ? (array)$query['conds'] : array();
|
|
|
|
|
$options = isset( $query['options'] ) ? (array)$query['options'] : array();
|
|
|
|
|
$join_conds = isset( $query['join_conds'] ) ? (array)$query['join_conds'] : array();
|
|
|
|
|
if ( count( $order ) ) {
|
|
|
|
|
$options['ORDER BY'] = implode( ', ', $order );
|
|
|
|
|
}
|
|
|
|
|
if ( $limit !== false ) {
|
|
|
|
|
$options['LIMIT'] = intval( $limit );
|
|
|
|
|
}
|
|
|
|
|
if ( $offset !== false ) {
|
|
|
|
|
$options['OFFSET'] = intval( $offset );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$res = $dbr->select( $tables, $fields, $conds, $fname,
|
|
|
|
|
$options, $join_conds
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
// Old-fashioned raw SQL style, deprecated
|
|
|
|
|
$sql = $this->getSQL();
|
|
|
|
|
$sql .= ' ORDER BY ' . implode( ', ', $order );
|
|
|
|
|
$sql = $dbr->limitResult( $sql, $limit, $offset );
|
2010-12-31 16:47:57 +00:00
|
|
|
$res = $dbr->query( $sql, $fname );
|
2010-12-22 14:16:25 +00:00
|
|
|
}
|
|
|
|
|
return $dbr->resultObject( $res );
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 15:22:59 +00:00
|
|
|
/**
|
|
|
|
|
* Parameters and order changed in 1.18
|
|
|
|
|
*/
|
2010-12-22 14:16:25 +00:00
|
|
|
function doQuery( $limit, $offset = false ) {
|
|
|
|
|
if ( $this->isCached() && $this->isCacheable() ) {
|
|
|
|
|
return $this->fetchFromCache( $limit, $offset );
|
|
|
|
|
} else {
|
|
|
|
|
return $this->reallyDoQuery( $limit, $offset );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetch the query results from the query cache
|
|
|
|
|
* @param $limit mixed Numerical limit or false for no limit
|
|
|
|
|
* @param $offset mixed Numerical offset or false for no offset
|
|
|
|
|
* @return ResultWrapper
|
2010-12-22 15:22:59 +00:00
|
|
|
* @since 1.18
|
2010-12-22 14:16:25 +00:00
|
|
|
*/
|
|
|
|
|
function fetchFromCache( $limit, $offset = false ) {
|
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
|
$options = array ();
|
|
|
|
|
if ( $limit !== false ) {
|
|
|
|
|
$options['LIMIT'] = intval( $limit );
|
|
|
|
|
}
|
|
|
|
|
if ( $offset !== false ) {
|
|
|
|
|
$options['OFFSET'] = intval( $offset );
|
|
|
|
|
}
|
2011-01-29 22:07:22 +00:00
|
|
|
if ( $this->sortDescending() ) {
|
|
|
|
|
$options['ORDER BY'] = 'qc_value DESC';
|
2011-02-02 14:26:12 +00:00
|
|
|
} else {
|
|
|
|
|
$options['ORDER BY'] = 'qc_value ASC';
|
2011-01-29 22:07:22 +00:00
|
|
|
}
|
2010-12-22 14:16:25 +00:00
|
|
|
$res = $dbr->select( 'querycache', array( 'qc_type',
|
|
|
|
|
'qc_namespace AS namespace',
|
|
|
|
|
'qc_title AS title',
|
|
|
|
|
'qc_value AS value' ),
|
|
|
|
|
array( 'qc_type' => $this->getName() ),
|
|
|
|
|
__METHOD__, $options
|
|
|
|
|
);
|
|
|
|
|
return $dbr->resultObject( $res );
|
|
|
|
|
}
|
2011-01-29 22:07:22 +00:00
|
|
|
|
2010-12-22 20:31:32 +00:00
|
|
|
public function getCachedTimestamp() {
|
2010-12-22 20:43:22 +00:00
|
|
|
if ( !is_null( $this->cachedTimestamp ) ) {
|
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
|
$fname = get_class( $this ) . '::getCachedTimestamp';
|
|
|
|
|
$this->cachedTimestamp = $dbr->selectField( 'querycache_info', 'qci_timestamp',
|
|
|
|
|
array( 'qci_type' => $this->getName() ), $fname );
|
|
|
|
|
}
|
|
|
|
|
return $this->cachedTimestamp;
|
2010-12-22 20:31:32 +00:00
|
|
|
}
|
2010-12-22 14:16:25 +00:00
|
|
|
|
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.
|
|
|
|
|
*/
|
2010-12-22 14:16:25 +00:00
|
|
|
function execute( $par ) {
|
|
|
|
|
global $wgUser, $wgOut, $wgLang;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( !$this->userCanExecute( $wgUser ) ) {
|
|
|
|
|
$this->displayRestrictionError();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2006-04-21 06:49:23 +00:00
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( $this->limit == 0 && $this->offset == 0 )
|
|
|
|
|
list( $this->limit, $this->offset ) = wfCheckLimits();
|
2007-01-22 23:50:42 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2004-01-25 02:27:49 +00:00
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
$this->setHeaders();
|
2009-07-14 08:44:58 +00:00
|
|
|
$wgOut->setSyndicated( $this->isSyndicated() );
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( $this->isCached() && !$this->isCacheable() ) {
|
|
|
|
|
$wgOut->setSyndicated( false );
|
|
|
|
|
$wgOut->addWikiMsg( 'querypage-disabled' );
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Use doQuery()
|
|
|
|
|
// $res = null;
|
2006-12-16 21:32:11 +00:00
|
|
|
if ( !$this->isCached() ) {
|
2010-12-22 14:16:25 +00:00
|
|
|
$res = $this->reallyDoQuery( $this->limit, $this->offset );
|
2006-12-16 21:32:11 +00:00
|
|
|
} else {
|
|
|
|
|
# Get the cached result
|
2010-12-22 14:16:25 +00:00
|
|
|
$res = $this->fetchFromCache( $this->limit, $this->offset );
|
|
|
|
|
if ( !$this->listoutput ) {
|
2006-04-17 04:48:12 +00:00
|
|
|
|
|
|
|
|
# Fetch the timestamp of this update
|
2010-12-22 20:31:32 +00:00
|
|
|
$ts = $this->getCachedTimestamp();
|
|
|
|
|
|
|
|
|
|
if ( $ts ) {
|
|
|
|
|
$updated = $wgLang->timeanddate( $ts, true, true );
|
|
|
|
|
$updateddate = $wgLang->date( $ts, true, true );
|
|
|
|
|
$updatedtime = $wgLang->time( $ts, true, true );
|
|
|
|
|
$wgOut->addMeta( 'Data-Cache-Time', $ts );
|
|
|
|
|
$wgOut->addInlineScript( "var dataCacheTime = '$ts';" );
|
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;
|
2010-12-22 14:16:25 +00:00
|
|
|
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
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
$this->numRows = $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
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
$wgOut->addHTML( Xml::openElement( 'div', array( 'class' => 'mw-spcontent' ) ) );
|
2009-07-14 08:44:58 +00:00
|
|
|
|
|
|
|
|
# Top header and navigation
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( $this->shownavigation ) {
|
2009-07-14 08:44:58 +00:00
|
|
|
$wgOut->addHTML( $this->getPageHeader() );
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( $this->numRows > 0 ) {
|
|
|
|
|
$wgOut->addHTML( '<p>' . wfShowingResults( $this->offset, $this->numRows ) . '</p>' );
|
2009-07-14 08:44:58 +00:00
|
|
|
# Disable the "next" link when we reach the end
|
2010-12-22 14:16:25 +00:00
|
|
|
$paging = wfViewPrevNext( $this->offset, $this->limit,
|
|
|
|
|
$this->getTitle( $par ),
|
|
|
|
|
wfArrayToCGI( $this->linkParameters() ), ( $this->numRows < $this->limit ) );
|
2009-07-14 08:44:58 +00:00
|
|
|
$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>' );
|
2010-07-27 18:33:04 +00:00
|
|
|
$wgOut->addHTML( Xml::closeElement( 'div' ) );
|
2009-07-14 08:44:58 +00:00
|
|
|
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,
|
2010-12-22 14:16:25 +00:00
|
|
|
$this->numRows,
|
|
|
|
|
$this->offset );
|
2009-07-14 08:44:58 +00:00
|
|
|
|
|
|
|
|
# Repeat the paging links at the bottom
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( $this->shownavigation ) {
|
2009-07-14 08:44:58 +00:00
|
|
|
$wgOut->addHTML( '<p>' . $paging . '</p>' );
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-27 18:33:04 +00:00
|
|
|
$wgOut->addHTML( Xml::closeElement( 'div' ) );
|
2009-07-14 08:44:58 +00:00
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
return $this->numRows;
|
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
|
|
|
|
|
*
|
2010-01-23 20:07:17 +00:00
|
|
|
* @param $out OutputPage to print to
|
|
|
|
|
* @param $skin Skin: user skin to use
|
|
|
|
|
* @param $dbr Database (read) connection to use
|
|
|
|
|
* @param $res Integer: result pointer
|
|
|
|
|
* @param $num Integer: number of available result rows
|
|
|
|
|
* @param $offset Integer: paging offset
|
2007-03-28 21:01:58 +00:00
|
|
|
*/
|
|
|
|
|
protected function outputResults( $out, $skin, $dbr, $res, $num, $offset ) {
|
|
|
|
|
global $wgContLang;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( $num > 0 ) {
|
2007-03-28 21:01:58 +00:00
|
|
|
$html = array();
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( !$this->listoutput )
|
2007-03-28 21:01:58 +00:00
|
|
|
$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]
|
2010-12-22 14:16:25 +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 );
|
2010-12-22 14:16:25 +00:00
|
|
|
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
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( $this->tryLastResult() ) {
|
2007-03-28 21:01:58 +00:00
|
|
|
$row = null;
|
|
|
|
|
$line = $this->formatResult( $skin, $row );
|
2010-12-22 14:16:25 +00:00
|
|
|
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
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( !$this->listoutput )
|
2007-03-28 21:01:58 +00:00
|
|
|
$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;
|
|
|
|
|
}
|
2010-12-22 14:16:25 +00:00
|
|
|
|
2008-05-16 21:34:46 +00:00
|
|
|
global $wgFeedLimit;
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( $limit > $wgFeedLimit ) {
|
2008-05-16 21:34:46 +00:00
|
|
|
$limit = $wgFeedLimit;
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( isset( $wgFeedClasses[$class] ) ) {
|
2004-04-28 04:37:31 +00:00
|
|
|
$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 );
|
2010-12-22 14:16:25 +00:00
|
|
|
$res = $this->reallyDoQuery( $limit, 0 );
|
2010-10-13 23:11:40 +00:00
|
|
|
foreach ( $res as $obj ) {
|
2004-03-05 10:16:46 +00:00
|
|
|
$item = $this->feedResult( $obj );
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( $item ) {
|
2010-10-13 23:11:40 +00:00
|
|
|
$feed->outItem( $item );
|
|
|
|
|
}
|
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 ) {
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( !isset( $row->title ) ) {
|
2009-12-11 21:07:27 +00:00
|
|
|
return null;
|
2004-03-05 10:16:46 +00:00
|
|
|
}
|
2005-08-16 23:36:16 +00:00
|
|
|
$title = Title::MakeTitle( intval( $row->namespace ), $row->title );
|
2010-12-22 14:16:25 +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 = '';
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( $title ) {
|
2004-04-29 01:14:32 +00:00
|
|
|
$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 ),
|
2010-12-22 14:16:25 +00:00
|
|
|
$comments );
|
2004-03-05 10:16:46 +00:00
|
|
|
} else {
|
2009-12-11 21:07:27 +00:00
|
|
|
return null;
|
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 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() {
|
2010-09-07 22:37:55 +00:00
|
|
|
global $wgLanguageCode, $wgSitename;
|
2004-05-20 14:13:03 +00:00
|
|
|
$page = SpecialPage::getPage( $this->getName() );
|
|
|
|
|
$desc = $page->getDescription();
|
2010-09-07 22:37:55 +00:00
|
|
|
return "$wgSitename - $desc [$wgLanguageCode]";
|
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;
|
2010-10-13 23:11:40 +00:00
|
|
|
foreach ( $res as $row ) {
|
2009-04-15 03:35:59 +00:00
|
|
|
$batch->add( $row->namespace, $row->title );
|
2010-10-13 23:11:40 +00:00
|
|
|
}
|
2009-04-15 03:35:59 +00:00
|
|
|
$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 );
|
|
|
|
|
}
|
2010-12-22 14:16:25 +00:00
|
|
|
|
2010-12-04 16:10:51 +00:00
|
|
|
/**
|
|
|
|
|
* Should formatResult() always check page existence, even if
|
|
|
|
|
* the results are fresh? This is a (hopefully temporary)
|
|
|
|
|
* kluge for Special:WantedFiles, which may contain false
|
|
|
|
|
* positives for files that exist e.g. in a shared repo (bug
|
|
|
|
|
* 6220).
|
|
|
|
|
*/
|
|
|
|
|
function forceExistenceCheck() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-15 03:35:59 +00:00
|
|
|
/**
|
|
|
|
|
* 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 );
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( $title instanceof Title ) {
|
|
|
|
|
if ( $this->isCached() || $this->forceExistenceCheck() ) {
|
2010-12-04 16:10:51 +00:00
|
|
|
$pageLink = $title->isKnown()
|
2010-07-23 16:59:29 +00:00
|
|
|
? '<del>' . $skin->link( $title ) . '</del>'
|
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
|
|
|
}
|
|
|
|
|
}
|
2010-12-22 14:16:25 +00:00
|
|
|
|
2009-04-15 03:35:59 +00:00
|
|
|
/**
|
|
|
|
|
* Make a "what links here" link for a given title
|
|
|
|
|
*
|
2009-10-04 21:21:30 +00:00
|
|
|
* @param $title Title to make the link for
|
|
|
|
|
* @param $skin Skin object to use
|
|
|
|
|
* @param $result Object: result row
|
2009-04-15 03:35:59 +00:00
|
|
|
* @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
|
|
|
}
|