2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2012-05-11 08:34:29 +00:00
|
|
|
* Base code for "query" special pages.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
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
|
2012-02-09 09:34:47 +00:00
|
|
|
* @ingroup SpecialPage
|
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(
|
2013-12-08 09:48:36 +00:00
|
|
|
// QueryPage subclass, Special page name, Limit (false for none, none for the default)
|
2010-12-22 14:16:25 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2013-12-08 09:48:36 +00:00
|
|
|
array( 'AncientPagesPage', 'Ancientpages' ),
|
|
|
|
|
array( 'BrokenRedirectsPage', 'BrokenRedirects' ),
|
|
|
|
|
array( 'DeadendPagesPage', 'Deadendpages' ),
|
|
|
|
|
array( 'DoubleRedirectsPage', 'DoubleRedirects' ),
|
|
|
|
|
array( 'FileDuplicateSearchPage', 'FileDuplicateSearch' ),
|
|
|
|
|
array( 'LinkSearchPage', 'LinkSearch' ),
|
|
|
|
|
array( 'ListredirectsPage', 'Listredirects' ),
|
|
|
|
|
array( 'LonelyPagesPage', 'Lonelypages' ),
|
|
|
|
|
array( 'LongPagesPage', 'Longpages' ),
|
|
|
|
|
array( 'MIMEsearchPage', 'MIMEsearch' ),
|
|
|
|
|
array( 'MostcategoriesPage', 'Mostcategories' ),
|
|
|
|
|
array( 'MostimagesPage', 'Mostimages' ),
|
|
|
|
|
array( 'MostinterwikisPage', 'Mostinterwikis' ),
|
|
|
|
|
array( 'MostlinkedCategoriesPage', 'Mostlinkedcategories' ),
|
|
|
|
|
array( 'MostlinkedtemplatesPage', 'Mostlinkedtemplates' ),
|
|
|
|
|
array( 'MostlinkedPage', 'Mostlinked' ),
|
|
|
|
|
array( 'MostrevisionsPage', 'Mostrevisions' ),
|
|
|
|
|
array( 'FewestrevisionsPage', 'Fewestrevisions' ),
|
|
|
|
|
array( 'ShortPagesPage', 'Shortpages' ),
|
|
|
|
|
array( 'UncategorizedCategoriesPage', 'Uncategorizedcategories' ),
|
|
|
|
|
array( 'UncategorizedPagesPage', 'Uncategorizedpages' ),
|
|
|
|
|
array( 'UncategorizedImagesPage', 'Uncategorizedimages' ),
|
|
|
|
|
array( 'UncategorizedTemplatesPage', 'Uncategorizedtemplates' ),
|
|
|
|
|
array( 'UnusedCategoriesPage', 'Unusedcategories' ),
|
|
|
|
|
array( 'UnusedimagesPage', 'Unusedimages' ),
|
|
|
|
|
array( 'WantedCategoriesPage', 'Wantedcategories' ),
|
|
|
|
|
array( 'WantedFilesPage', 'Wantedfiles' ),
|
|
|
|
|
array( 'WantedPagesPage', 'Wantedpages' ),
|
|
|
|
|
array( 'WantedTemplatesPage', 'Wantedtemplates' ),
|
|
|
|
|
array( 'UnwatchedPagesPage', 'Unwatchedpages' ),
|
|
|
|
|
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;
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( !$wgDisableCounters ) {
|
2010-12-22 14:16:25 +00:00
|
|
|
$wgQueryPages[] = array( 'PopularPagesPage', 'Popularpages' );
|
2013-04-20 22:49:30 +00:00
|
|
|
}
|
2005-10-19 01:39:12 +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
|
|
|
|
|
*
|
2013-04-14 19:18:38 +00:00
|
|
|
* @var int
|
2006-04-21 06:49:23 +00:00
|
|
|
*/
|
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;
|
|
|
|
|
*
|
2013-04-14 19:18:38 +00:00
|
|
|
* @param bool $bool
|
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.
|
2013-03-13 07:42:41 +00:00
|
|
|
* This is strongly deprecated; getQueryInfo() should be overridden instead.
|
2012-10-07 23:35:26 +00:00
|
|
|
* @throws MWException
|
2010-12-22 14:16:25 +00:00
|
|
|
* @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 */
|
2013-12-08 09:48:36 +00:00
|
|
|
throw new MWException( "Bug in a QueryPage: doesn't implement getQueryInfo() nor "
|
|
|
|
|
. "getQuery() properly" );
|
2010-12-22 14:16:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
*
|
2013-04-14 19:18:38 +00:00
|
|
|
* @return bool
|
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
|
|
|
*
|
2013-04-14 19:18:38 +00:00
|
|
|
* @return bool
|
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.
|
2013-04-14 19:18:38 +00:00
|
|
|
* @return bool
|
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.
|
|
|
|
|
*
|
2013-04-14 19:18:38 +00:00
|
|
|
* @return bool
|
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
|
|
|
/**
|
2013-03-13 07:42:41 +00:00
|
|
|
* Sometime we don't want to build rss / atom feeds.
|
2010-01-23 20:07:17 +00:00
|
|
|
*
|
2013-04-14 19:18:38 +00:00
|
|
|
* @return bool
|
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.
|
2013-04-14 19:18:38 +00:00
|
|
|
* @param Skin $skin
|
|
|
|
|
* @param object $result Result row
|
|
|
|
|
* @return string|bool String or false to skip
|
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
|
|
|
*
|
2013-04-14 19:18:38 +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
|
|
|
*
|
2013-04-14 19:18:38 +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.
|
2012-02-09 21:36:14 +00:00
|
|
|
* @return bool
|
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
|
|
|
*
|
2013-04-14 19:18:38 +00:00
|
|
|
* @param int|bool $limit Limit for SQL statement
|
|
|
|
|
* @param bool $ignoreErrors Whether to ignore database errors
|
|
|
|
|
* @throws DBError|Exception
|
2012-02-09 21:36:14 +00:00
|
|
|
* @return bool|int
|
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 );
|
2013-12-11 00:48:47 +00:00
|
|
|
if ( !$dbw ) {
|
2005-04-24 08:31:12 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-11 19:24:12 +00:00
|
|
|
try {
|
|
|
|
|
# Do query
|
|
|
|
|
$res = $this->reallyDoQuery( $limit, false );
|
|
|
|
|
$num = false;
|
|
|
|
|
if ( $res ) {
|
|
|
|
|
$num = $res->numRows();
|
|
|
|
|
# Fetch results
|
|
|
|
|
$vals = array();
|
2013-12-11 00:48:47 +00:00
|
|
|
foreach ( $res as $row ) {
|
2012-12-11 19:24:12 +00:00
|
|
|
if ( isset( $row->value ) ) {
|
|
|
|
|
if ( $this->usesTimestamps() ) {
|
|
|
|
|
$value = wfTimestamp( TS_UNIX,
|
|
|
|
|
$row->value );
|
|
|
|
|
} else {
|
|
|
|
|
$value = intval( $row->value ); // @bug 14414
|
|
|
|
|
}
|
2010-12-22 14:16:25 +00:00
|
|
|
} else {
|
2012-12-11 19:24:12 +00:00
|
|
|
$value = 0;
|
2010-12-22 14:16:25 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-11 19:24:12 +00:00
|
|
|
$vals[] = array( 'qc_type' => $this->getName(),
|
|
|
|
|
'qc_namespace' => $row->namespace,
|
|
|
|
|
'qc_title' => $row->title,
|
|
|
|
|
'qc_value' => $value );
|
|
|
|
|
}
|
2005-04-24 08:31:12 +00:00
|
|
|
|
2013-12-11 00:57:00 +00:00
|
|
|
$dbw->begin( __METHOD__ );
|
|
|
|
|
# Clear out any old cached data
|
|
|
|
|
$dbw->delete( 'querycache', array( 'qc_type' => $this->getName() ), $fname );
|
2012-12-11 19:24:12 +00:00
|
|
|
# Save results into the querycache table on the master
|
|
|
|
|
if ( count( $vals ) ) {
|
|
|
|
|
$dbw->insert( 'querycache', $vals, __METHOD__ );
|
2005-04-24 08:31:12 +00:00
|
|
|
}
|
2012-12-11 19:24:12 +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 );
|
2013-12-11 00:57:00 +00:00
|
|
|
$dbw->commit( __METHOD__ );
|
2005-04-24 08:31:12 +00:00
|
|
|
}
|
2012-12-11 19:24:12 +00:00
|
|
|
} catch ( DBError $e ) {
|
|
|
|
|
if ( !$ignoreErrors ) {
|
|
|
|
|
throw $e; // report query error
|
2005-04-24 08:31:12 +00:00
|
|
|
}
|
2012-12-11 19:24:12 +00:00
|
|
|
$num = false; // set result to false to indicate error
|
2005-04-24 08:31:12 +00:00
|
|
|
}
|
2012-12-11 19:24:12 +00:00
|
|
|
|
2005-04-24 08:31:12 +00:00
|
|
|
return $num;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-11 00:48:47 +00:00
|
|
|
/**
|
|
|
|
|
* Get a DB connection to be used for slow recache queries
|
|
|
|
|
*/
|
|
|
|
|
function getRecacheDB() {
|
|
|
|
|
return wfGetDB( DB_SLAVE, array( $this->getName(), 'QueryPage::recache', 'vslow' ) );
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
/**
|
|
|
|
|
* Run the query and return the result
|
2013-04-14 19:18:38 +00:00
|
|
|
* @param int|bool $limit Numerical limit or false for no limit
|
|
|
|
|
* @param int|bool $offset Numerical offset or false for no offset
|
2010-12-22 14:16:25 +00:00
|
|
|
* @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";
|
2013-12-11 00:48:47 +00:00
|
|
|
$dbr = $this->getRecacheDB();
|
2010-12-22 14:16:25 +00:00
|
|
|
$query = $this->getQueryInfo();
|
|
|
|
|
$order = $this->getOrderFields();
|
2013-04-14 19:18:38 +00:00
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( $this->sortDescending() ) {
|
|
|
|
|
foreach ( $order as &$field ) {
|
|
|
|
|
$field .= ' DESC';
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-04-14 19:18:38 +00:00
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
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();
|
2013-04-14 19:18:38 +00:00
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( count( $order ) ) {
|
2012-05-12 22:06:48 +00:00
|
|
|
$options['ORDER BY'] = $order;
|
2010-12-22 14:16:25 +00:00
|
|
|
}
|
2013-04-14 19:18:38 +00:00
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( $limit !== false ) {
|
|
|
|
|
$options['LIMIT'] = intval( $limit );
|
|
|
|
|
}
|
2013-04-14 19:18:38 +00:00
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
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
|
|
|
}
|
2013-04-14 19:18:38 +00:00
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
return $dbr->resultObject( $res );
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 15:22:59 +00:00
|
|
|
/**
|
2011-02-22 23:22:09 +00:00
|
|
|
* Somewhat deprecated, you probably want to be using execute()
|
2013-04-14 19:18:38 +00:00
|
|
|
* @param int|bool $offset
|
2014-01-26 19:49:25 +00:00
|
|
|
* @param int|bool $limit
|
2012-02-13 16:35:59 +00:00
|
|
|
* @return ResultWrapper
|
2010-12-22 15:22:59 +00:00
|
|
|
*/
|
2011-02-22 23:40:48 +00:00
|
|
|
function doQuery( $offset = false, $limit = false ) {
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( $this->isCached() && $this->isCacheable() ) {
|
|
|
|
|
return $this->fetchFromCache( $limit, $offset );
|
|
|
|
|
} else {
|
|
|
|
|
return $this->reallyDoQuery( $limit, $offset );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetch the query results from the query cache
|
2013-04-14 19:18:38 +00:00
|
|
|
* @param int|bool $limit Numerical limit or false for no limit
|
|
|
|
|
* @param int|bool $offset Numerical offset or false for no offset
|
2010-12-22 14:16:25 +00:00
|
|
|
* @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 );
|
2013-04-14 19:57:46 +00:00
|
|
|
$options = array();
|
2010-12-22 14:16:25 +00:00
|
|
|
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',
|
2012-08-15 13:16:09 +00:00
|
|
|
'namespace' => 'qc_namespace',
|
|
|
|
|
'title' => 'qc_title',
|
|
|
|
|
'value' => 'qc_value' ),
|
2011-04-18 19:00:48 +00:00
|
|
|
array( 'qc_type' => $this->getName() ),
|
2010-12-22 14:16:25 +00:00
|
|
|
__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() {
|
2011-09-29 15:16:35 +00:00
|
|
|
if ( is_null( $this->cachedTimestamp ) ) {
|
2010-12-22 20:43:22 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
|
$fname = get_class( $this ) . '::getCachedTimestamp';
|
|
|
|
|
$this->cachedTimestamp = $dbr->selectField( 'querycache_info', 'qci_timestamp',
|
2011-04-18 19:00:48 +00:00
|
|
|
array( 'qci_type' => $this->getName() ), $fname );
|
2010-12-22 20:43:22 +00:00
|
|
|
}
|
|
|
|
|
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.
|
2013-12-27 16:57:19 +00:00
|
|
|
* @param string $par
|
2012-02-09 21:36:14 +00:00
|
|
|
* @return int
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2010-12-22 14:16:25 +00:00
|
|
|
function execute( $par ) {
|
2012-01-29 22:02:27 +00:00
|
|
|
global $wgQueryCacheLimit, $wgDisableQueryPageUpdate;
|
2012-01-27 07:23:55 +00:00
|
|
|
|
|
|
|
|
$user = $this->getUser();
|
|
|
|
|
if ( !$this->userCanExecute( $user ) ) {
|
2010-12-22 14:16:25 +00:00
|
|
|
$this->displayRestrictionError();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2006-04-21 06:49:23 +00:00
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
$this->setHeaders();
|
2012-01-27 07:15:18 +00:00
|
|
|
$this->outputHeader();
|
|
|
|
|
|
2011-08-08 21:07:17 +00:00
|
|
|
$out = $this->getOutput();
|
2004-08-09 05:38:11 +00:00
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( $this->isCached() && !$this->isCacheable() ) {
|
2011-08-08 21:07:17 +00:00
|
|
|
$out->addWikiMsg( 'querypage-disabled' );
|
2010-12-22 14:16:25 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-29 22:02:27 +00:00
|
|
|
$out->setSyndicated( $this->isSyndicated() );
|
|
|
|
|
|
|
|
|
|
if ( $this->limit == 0 && $this->offset == 0 ) {
|
|
|
|
|
list( $this->limit, $this->offset ) = $this->getRequest()->getLimitOffset();
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
// TODO: Use doQuery()
|
2006-12-16 21:32:11 +00:00
|
|
|
if ( !$this->isCached() ) {
|
2012-07-28 23:05:38 +00:00
|
|
|
# select one extra row for navigation
|
|
|
|
|
$res = $this->reallyDoQuery( $this->limit + 1, $this->offset );
|
2006-12-16 21:32:11 +00:00
|
|
|
} else {
|
2012-07-28 23:05:38 +00:00
|
|
|
# Get the cached result, select one extra row for navigation
|
|
|
|
|
$res = $this->fetchFromCache( $this->limit + 1, $this->offset );
|
2010-12-22 14:16:25 +00:00
|
|
|
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();
|
2012-01-05 16:14:52 +00:00
|
|
|
$lang = $this->getLanguage();
|
|
|
|
|
$maxResults = $lang->formatNum( $wgQueryCacheLimit );
|
2010-12-22 20:31:32 +00:00
|
|
|
|
|
|
|
|
if ( $ts ) {
|
2012-01-27 07:23:55 +00:00
|
|
|
$updated = $lang->userTimeAndDate( $ts, $user );
|
|
|
|
|
$updateddate = $lang->userDate( $ts, $user );
|
|
|
|
|
$updatedtime = $lang->userTime( $ts, $user );
|
2011-08-08 21:07:17 +00:00
|
|
|
$out->addMeta( 'Data-Cache-Time', $ts );
|
2012-05-19 17:44:09 +00:00
|
|
|
$out->addJsConfigVars( 'dataCacheTime', $ts );
|
2012-01-05 16:14:52 +00:00
|
|
|
$out->addWikiMsg( 'perfcachedts', $updated, $updateddate, $updatedtime, $maxResults );
|
2006-04-17 04:48:12 +00:00
|
|
|
} else {
|
2012-01-05 16:14:52 +00:00
|
|
|
$out->addWikiMsg( 'perfcached', $maxResults );
|
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
|
2013-12-08 09:48:36 +00:00
|
|
|
if ( is_array( $wgDisableQueryPageUpdate )
|
|
|
|
|
&& in_array( $this->getName(), $wgDisableQueryPageUpdate )
|
|
|
|
|
) {
|
|
|
|
|
$out->wrapWikiMsg(
|
|
|
|
|
"<div class=\"mw-querypage-no-updates\">\n$1\n</div>",
|
|
|
|
|
'querypage-no-updates'
|
|
|
|
|
);
|
2007-01-03 23:42:28 +00:00
|
|
|
}
|
2006-04-17 04:48:12 +00:00
|
|
|
}
|
2004-01-25 02:27:49 +00:00
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2012-01-29 22:02:27 +00:00
|
|
|
$this->numRows = $res->numRows();
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2012-01-29 22:02:27 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2005-09-11 12:33:59 +00:00
|
|
|
$this->preprocessResults( $dbr, $res );
|
2009-07-14 08:44:58 +00:00
|
|
|
|
2011-08-08 21:07:17 +00:00
|
|
|
$out->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 ) {
|
2011-08-08 21:07:17 +00:00
|
|
|
$out->addHTML( $this->getPageHeader() );
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( $this->numRows > 0 ) {
|
2014-02-04 21:27:16 +00:00
|
|
|
$out->addHTML( $this->msg( 'showingresultsinrange' )->numParams(
|
2012-08-16 15:40:28 +00:00
|
|
|
min( $this->numRows, $this->limit ), # do not show the one extra row, if exist
|
2014-02-04 21:27:16 +00:00
|
|
|
$this->offset + 1, (min( $this->numRows, $this->limit ) + $this->offset) )->parseAsBlock() );
|
2009-07-14 08:44:58 +00:00
|
|
|
# Disable the "next" link when we reach the end
|
2013-12-24 08:07:04 +00:00
|
|
|
$paging = $this->getLanguage()->viewPrevNext( $this->getPageTitle( $par ), $this->offset,
|
2012-07-28 23:05:38 +00:00
|
|
|
$this->limit, $this->linkParameters(), ( $this->numRows <= $this->limit ) );
|
2011-08-08 21:07:17 +00:00
|
|
|
$out->addHTML( '<p>' . $paging . '</p>' );
|
2009-07-14 08:44:58 +00:00
|
|
|
} else {
|
|
|
|
|
# No results to show, so don't bother with "showing X of Y" etc.
|
|
|
|
|
# -- just let the user know and give up now
|
2011-10-14 14:57:06 +00:00
|
|
|
$out->addWikiMsg( 'specialpage-empty' );
|
2011-08-08 21:07:17 +00:00
|
|
|
$out->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
|
2011-08-08 21:07:17 +00:00
|
|
|
$this->outputResults( $out,
|
2011-07-01 02:25:19 +00:00
|
|
|
$this->getSkin(),
|
2009-07-14 08:44:58 +00:00
|
|
|
$dbr, # Should use a ResultWrapper for this
|
|
|
|
|
$res,
|
2012-07-28 23:05:38 +00:00
|
|
|
min( $this->numRows, $this->limit ), # do not format the one extra row, if exist
|
2010-12-22 14:16:25 +00:00
|
|
|
$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 ) {
|
2011-08-08 21:07:17 +00:00
|
|
|
$out->addHTML( '<p>' . $paging . '</p>' );
|
2009-07-14 08:44:58 +00:00
|
|
|
}
|
|
|
|
|
|
2011-08-08 21:07:17 +00:00
|
|
|
$out->addHTML( Xml::closeElement( 'div' ) );
|
2009-07-14 08:44:58 +00:00
|
|
|
|
2012-08-16 15:40:28 +00:00
|
|
|
return min( $this->numRows, $this->limit ); # do not return the one extra row, if exist
|
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
|
|
|
|
|
*
|
2013-04-14 19:18:38 +00:00
|
|
|
* @param OutputPage $out OutputPage to print to
|
|
|
|
|
* @param Skin $skin User skin to use
|
|
|
|
|
* @param DatabaseBase $dbr Database (read) connection to use
|
|
|
|
|
* @param int $res Result pointer
|
|
|
|
|
* @param int $num Number of available result rows
|
|
|
|
|
* @param int $offset 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();
|
2011-02-22 23:22:09 +00:00
|
|
|
if ( !$this->listoutput ) {
|
2007-03-28 21:01:58 +00:00
|
|
|
$html[] = $this->openList( $offset );
|
2011-02-22 23:22:09 +00:00
|
|
|
}
|
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]
|
2013-06-07 17:29:56 +00:00
|
|
|
for ( $i = 0; $i < $num && $row = $res->fetchObject(); $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
|
|
|
|
2011-02-22 23:22:09 +00:00
|
|
|
if ( !$this->listoutput ) {
|
2007-03-28 21:01:58 +00:00
|
|
|
$html[] = $this->closeList();
|
2011-02-22 23:22:09 +00:00
|
|
|
}
|
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
|
|
|
|
2011-10-03 22:51:38 +00:00
|
|
|
/**
|
|
|
|
|
* @param $offset
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
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
|
|
|
|
2011-10-03 22:51:38 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
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.
|
2013-04-14 19:18:38 +00:00
|
|
|
* @param DatabaseBase $db
|
|
|
|
|
* @param ResultWrapper $res
|
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
|
2013-04-14 19:18:38 +00:00
|
|
|
* @param string $class
|
|
|
|
|
* @param int $limit
|
2012-02-09 21:36:14 +00:00
|
|
|
* @return bool
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2006-04-13 20:01:48 +00:00
|
|
|
function doFeed( $class = '', $limit = 50 ) {
|
2013-07-07 18:39:53 +00:00
|
|
|
global $wgFeed, $wgFeedClasses, $wgFeedLimit;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-02-22 12:33:51 +00:00
|
|
|
if ( !$wgFeed ) {
|
2011-08-08 21:07:17 +00:00
|
|
|
$this->getOutput()->addWikiMsg( 'feed-unavailable' );
|
2012-12-09 02:59:04 +00:00
|
|
|
return false;
|
2008-02-22 12:33:51 +00:00
|
|
|
}
|
2010-12-22 14:16:25 +00:00
|
|
|
|
2013-07-07 18:39:53 +00:00
|
|
|
$limit = min( $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
|
|
|
|
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()
|
2013-04-14 19:18:38 +00:00
|
|
|
* @param object $row
|
2012-02-09 21:36:14 +00:00
|
|
|
* @return FeedItem|null
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
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
|
|
|
}
|
2012-05-05 14:08:47 +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;
|
2011-04-17 10:44:44 +00:00
|
|
|
$desc = $this->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() {
|
2011-10-14 14:57:06 +00:00
|
|
|
return $this->msg( 'tagline' )->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 feedUrl() {
|
2013-12-24 08:07:04 +00:00
|
|
|
return $this->getPageTitle()->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
|
2013-04-14 19:18:38 +00:00
|
|
|
* @param DatabaseBase $db
|
|
|
|
|
* @param ResultWrapper $res
|
2009-04-15 03:35:59 +00:00
|
|
|
*/
|
|
|
|
|
function preprocessResults( $db, $res ) {
|
2012-03-02 20:35:01 +00:00
|
|
|
if ( !$res->numRows() ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-15 03:35:59 +00:00
|
|
|
$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
|
2012-03-02 20:35:01 +00:00
|
|
|
$res->seek( 0 );
|
2009-04-15 03:35:59 +00:00
|
|
|
}
|
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).
|
2012-02-09 21:36:14 +00:00
|
|
|
* @return bool
|
2010-12-04 16:10:51 +00:00
|
|
|
*/
|
|
|
|
|
function forceExistenceCheck() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-15 03:35:59 +00:00
|
|
|
/**
|
|
|
|
|
* Format an individual result
|
|
|
|
|
*
|
2013-04-14 19:18:38 +00:00
|
|
|
* @param Skin $skin Skin to use for UI elements
|
|
|
|
|
* @param object $result Result row
|
2009-04-15 03:35:59 +00:00
|
|
|
* @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()
|
2011-10-14 14:20:02 +00:00
|
|
|
? '<del>' . Linker::link( $title ) . '</del>'
|
|
|
|
|
: Linker::link(
|
2009-06-13 12:39:00 +00:00
|
|
|
$title,
|
|
|
|
|
null,
|
|
|
|
|
array(),
|
|
|
|
|
array(),
|
|
|
|
|
array( 'broken' )
|
|
|
|
|
);
|
2009-04-15 03:35:59 +00:00
|
|
|
} else {
|
2011-10-14 14:20:02 +00:00
|
|
|
$pageLink = Linker::link(
|
2009-06-13 12:39:00 +00:00
|
|
|
$title,
|
|
|
|
|
null,
|
|
|
|
|
array(),
|
|
|
|
|
array(),
|
|
|
|
|
array( 'broken' )
|
|
|
|
|
);
|
2009-04-15 03:35:59 +00:00
|
|
|
}
|
2011-11-21 16:13:21 +00:00
|
|
|
return $this->getLanguage()->specialList( $pageLink, $this->makeWlhLink( $title, $result ) );
|
2009-04-15 03:35:59 +00:00
|
|
|
} else {
|
2011-10-14 14:20:02 +00:00
|
|
|
return $this->msg( 'wantedpages-badtitle', $result->title )->escaped();
|
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
|
|
|
|
|
*
|
2013-04-14 19:18:38 +00:00
|
|
|
* @param Title $title Title to make the link for
|
|
|
|
|
* @param object $result Result row
|
2009-04-15 03:35:59 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2011-10-14 14:20:02 +00:00
|
|
|
private function makeWlhLink( $title, $result ) {
|
|
|
|
|
$wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() );
|
|
|
|
|
$label = $this->msg( 'nlinks' )->numParams( $result->value )->escaped();
|
|
|
|
|
return Linker::link( $wlh, $label );
|
2009-04-15 03:35:59 +00:00
|
|
|
}
|
2009-09-10 06:43:01 +00:00
|
|
|
}
|