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
|
|
|
|
2018-07-29 12:24:54 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2018-04-04 12:52:10 +00:00
|
|
|
use Wikimedia\Rdbms\IResultWrapper;
|
2017-02-10 18:09:05 +00:00
|
|
|
use Wikimedia\Rdbms\IDatabase;
|
2017-02-24 16:17:16 +00:00
|
|
|
use Wikimedia\Rdbms\DBError;
|
2017-02-19 05:03:13 +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 {
|
2014-05-12 14:42:51 +00:00
|
|
|
/** @var bool Whether or not we want plain listoutput rather than an ordered list */
|
|
|
|
|
protected $listoutput = false;
|
2007-01-20 13:34:31 +00:00
|
|
|
|
2014-05-12 14:42:51 +00:00
|
|
|
/** @var int The offset and limit in use, as passed to the query() function */
|
|
|
|
|
protected $offset = 0;
|
|
|
|
|
|
|
|
|
|
/** @var int */
|
|
|
|
|
protected $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
|
|
|
/**
|
2014-04-23 11:39:49 +00:00
|
|
|
* Whether to show prev/next links
|
2010-12-22 14:16:25 +00:00
|
|
|
*/
|
2010-12-22 17:29:31 +00:00
|
|
|
protected $shownavigation = true;
|
2010-12-22 14:16:25 +00:00
|
|
|
|
2014-02-04 19:50:11 +00:00
|
|
|
/**
|
|
|
|
|
* Get a list of query page classes and their associated special pages,
|
|
|
|
|
* for periodic updates.
|
|
|
|
|
*
|
|
|
|
|
* DO NOT CHANGE THIS LIST without testing that
|
|
|
|
|
* maintenance/updateSpecialPages.php still works.
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public static function getPages() {
|
|
|
|
|
static $qp = null;
|
|
|
|
|
|
|
|
|
|
if ( $qp === null ) {
|
|
|
|
|
// QueryPage subclass, Special page name
|
2016-02-17 09:09:32 +00:00
|
|
|
$qp = [
|
2018-01-13 00:02:09 +00:00
|
|
|
[ AncientPagesPage::class, 'Ancientpages' ],
|
|
|
|
|
[ BrokenRedirectsPage::class, 'BrokenRedirects' ],
|
|
|
|
|
[ DeadendPagesPage::class, 'Deadendpages' ],
|
|
|
|
|
[ DoubleRedirectsPage::class, 'DoubleRedirects' ],
|
|
|
|
|
[ FileDuplicateSearchPage::class, 'FileDuplicateSearch' ],
|
|
|
|
|
[ ListDuplicatedFilesPage::class, 'ListDuplicatedFiles' ],
|
|
|
|
|
[ LinkSearchPage::class, 'LinkSearch' ],
|
|
|
|
|
[ ListredirectsPage::class, 'Listredirects' ],
|
|
|
|
|
[ LonelyPagesPage::class, 'Lonelypages' ],
|
|
|
|
|
[ LongPagesPage::class, 'Longpages' ],
|
|
|
|
|
[ MediaStatisticsPage::class, 'MediaStatistics' ],
|
|
|
|
|
[ MIMEsearchPage::class, 'MIMEsearch' ],
|
|
|
|
|
[ MostcategoriesPage::class, 'Mostcategories' ],
|
|
|
|
|
[ MostimagesPage::class, 'Mostimages' ],
|
|
|
|
|
[ MostinterwikisPage::class, 'Mostinterwikis' ],
|
|
|
|
|
[ MostlinkedCategoriesPage::class, 'Mostlinkedcategories' ],
|
|
|
|
|
[ MostlinkedTemplatesPage::class, 'Mostlinkedtemplates' ],
|
|
|
|
|
[ MostlinkedPage::class, 'Mostlinked' ],
|
|
|
|
|
[ MostrevisionsPage::class, 'Mostrevisions' ],
|
|
|
|
|
[ FewestrevisionsPage::class, 'Fewestrevisions' ],
|
|
|
|
|
[ ShortPagesPage::class, 'Shortpages' ],
|
|
|
|
|
[ UncategorizedCategoriesPage::class, 'Uncategorizedcategories' ],
|
|
|
|
|
[ UncategorizedPagesPage::class, 'Uncategorizedpages' ],
|
|
|
|
|
[ UncategorizedImagesPage::class, 'Uncategorizedimages' ],
|
|
|
|
|
[ UncategorizedTemplatesPage::class, 'Uncategorizedtemplates' ],
|
|
|
|
|
[ UnusedCategoriesPage::class, 'Unusedcategories' ],
|
|
|
|
|
[ UnusedimagesPage::class, 'Unusedimages' ],
|
|
|
|
|
[ WantedCategoriesPage::class, 'Wantedcategories' ],
|
|
|
|
|
[ WantedFilesPage::class, 'Wantedfiles' ],
|
|
|
|
|
[ WantedPagesPage::class, 'Wantedpages' ],
|
|
|
|
|
[ WantedTemplatesPage::class, 'Wantedtemplates' ],
|
|
|
|
|
[ UnwatchedpagesPage::class, 'Unwatchedpages' ],
|
|
|
|
|
[ UnusedtemplatesPage::class, 'Unusedtemplates' ],
|
|
|
|
|
[ WithoutInterwikiPage::class, 'Withoutinterwiki' ],
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
|
|
|
|
Hooks::run( 'wgQueryPages', [ &$qp ] );
|
2014-02-04 19:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $qp;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
*/
|
2015-07-18 19:51:07 +00:00
|
|
|
public function getQueryInfo() {
|
2010-12-22 14:16:25 +00:00
|
|
|
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() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ 'value' ];
|
2010-12-22 14:16:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
*/
|
2015-07-18 19:51:07 +00:00
|
|
|
public function usesTimestamps() {
|
2010-12-22 14:16:25 +00:00
|
|
|
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
|
|
|
*/
|
2015-07-18 19:51:07 +00:00
|
|
|
public function isExpensive() {
|
2014-08-07 17:28:22 +00:00
|
|
|
return $this->getConfig()->get( 'DisableQueryPages' );
|
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
|
|
|
|
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
|
|
|
*/
|
2015-07-18 19:51:07 +00:00
|
|
|
public function isCached() {
|
2014-08-07 17:28:22 +00:00
|
|
|
return $this->isExpensive() && $this->getConfig()->get( 'MiserMode' );
|
2005-09-16 15:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2015-04-29 00:16:38 +00:00
|
|
|
/**
|
|
|
|
|
* Outputs some kind of an informative message (via OutputPage) to let the
|
|
|
|
|
* user know that the query returned nothing and thus there's nothing to
|
|
|
|
|
* show.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.26
|
|
|
|
|
*/
|
|
|
|
|
protected function showEmptyText() {
|
|
|
|
|
$this->getOutput()->addWikiMsg( 'specialpage-empty' );
|
|
|
|
|
}
|
|
|
|
|
|
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() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [];
|
2005-06-30 07:37:04 +00:00
|
|
|
}
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2005-02-01 02:02:14 +00:00
|
|
|
/**
|
2016-01-03 19:31:05 +00:00
|
|
|
* Some special pages (for example SpecialListusers used to) might not return the
|
2005-02-01 02:02:14 +00:00
|
|
|
* 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.
|
2016-01-03 19:31:05 +00:00
|
|
|
*
|
|
|
|
|
* @deprecated since 1.27
|
|
|
|
|
*
|
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
|
|
|
*/
|
2015-07-18 19:51:07 +00:00
|
|
|
public 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
|
|
|
|
2017-03-07 02:14:14 +00:00
|
|
|
$fname = static::class . '::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
|
2016-02-17 09:09:32 +00:00
|
|
|
$vals = [];
|
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 {
|
2017-02-20 22:44:19 +00:00
|
|
|
$value = intval( $row->value ); // T16414
|
2012-12-11 19:24:12 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$vals[] = [
|
2015-12-23 02:18:59 +00:00
|
|
|
'qc_type' => $this->getName(),
|
|
|
|
|
'qc_namespace' => $row->namespace,
|
|
|
|
|
'qc_title' => $row->title,
|
|
|
|
|
'qc_value' => $value
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2012-12-11 19:24:12 +00:00
|
|
|
}
|
2005-04-24 08:31:12 +00:00
|
|
|
|
2015-12-23 02:18:59 +00:00
|
|
|
$dbw->doAtomicSection(
|
|
|
|
|
__METHOD__,
|
2016-02-10 23:29:22 +00:00
|
|
|
function ( IDatabase $dbw, $fname ) use ( $vals ) {
|
2015-12-23 02:18:59 +00:00
|
|
|
# Clear out any old cached data
|
|
|
|
|
$dbw->delete( 'querycache',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'qc_type' => $this->getName() ],
|
2015-12-23 02:18:59 +00:00
|
|
|
$fname
|
|
|
|
|
);
|
|
|
|
|
# Save results into the querycache table on the master
|
|
|
|
|
if ( count( $vals ) ) {
|
|
|
|
|
$dbw->insert( 'querycache', $vals, $fname );
|
|
|
|
|
}
|
|
|
|
|
# Update the querycache_info record for the page
|
|
|
|
|
$dbw->delete( 'querycache_info',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'qci_type' => $this->getName() ],
|
2015-12-23 02:18:59 +00:00
|
|
|
$fname
|
|
|
|
|
);
|
|
|
|
|
$dbw->insert( 'querycache_info',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'qci_type' => $this->getName(),
|
|
|
|
|
'qci_timestamp' => $dbw->timestamp() ],
|
2015-12-23 02:18:59 +00:00
|
|
|
$fname
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
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
|
2014-12-09 09:05:22 +00:00
|
|
|
* @return IDatabase
|
2013-12-11 00:48:47 +00:00
|
|
|
*/
|
|
|
|
|
function getRecacheDB() {
|
2016-09-05 19:55:19 +00:00
|
|
|
return wfGetDB( DB_REPLICA, [ $this->getName(), 'QueryPage::recache', 'vslow' ] );
|
2013-12-11 00:48:47 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
2018-04-04 12:52:10 +00:00
|
|
|
* @return IResultWrapper
|
2010-12-22 15:22:59 +00:00
|
|
|
* @since 1.18
|
2010-12-22 14:16:25 +00:00
|
|
|
*/
|
2015-07-18 19:51:07 +00:00
|
|
|
public function reallyDoQuery( $limit, $offset = false ) {
|
2017-03-07 02:14:14 +00:00
|
|
|
$fname = static::class . '::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 ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$tables = isset( $query['tables'] ) ? (array)$query['tables'] : [];
|
|
|
|
|
$fields = isset( $query['fields'] ) ? (array)$query['fields'] : [];
|
|
|
|
|
$conds = isset( $query['conds'] ) ? (array)$query['conds'] : [];
|
|
|
|
|
$options = isset( $query['options'] ) ? (array)$query['options'] : [];
|
|
|
|
|
$join_conds = isset( $query['join_conds'] ) ? (array)$query['join_conds'] : [];
|
2013-04-14 19:18:38 +00:00
|
|
|
|
2017-03-22 20:11:11 +00:00
|
|
|
if ( $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
|
|
|
|
2014-09-12 04:12:38 +00:00
|
|
|
return $res;
|
2010-12-22 14:16:25 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
2018-04-04 12:52:10 +00:00
|
|
|
* @return IResultWrapper
|
2010-12-22 15:22:59 +00:00
|
|
|
*/
|
2015-07-18 19:51:07 +00:00
|
|
|
public 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
|
2018-04-04 12:52:10 +00:00
|
|
|
* @return IResultWrapper
|
2010-12-22 15:22:59 +00:00
|
|
|
* @since 1.18
|
2010-12-22 14:16:25 +00:00
|
|
|
*/
|
2015-07-18 19:51:07 +00:00
|
|
|
public function fetchFromCache( $limit, $offset = false ) {
|
2016-09-05 19:55:19 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2016-02-17 09:09:32 +00:00
|
|
|
$options = [];
|
2017-03-22 20:11:11 +00:00
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( $limit !== false ) {
|
|
|
|
|
$options['LIMIT'] = intval( $limit );
|
|
|
|
|
}
|
2017-03-22 20:11:11 +00:00
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( $offset !== false ) {
|
|
|
|
|
$options['OFFSET'] = intval( $offset );
|
|
|
|
|
}
|
2017-03-22 20:11:11 +00:00
|
|
|
|
|
|
|
|
$order = $this->getCacheOrderFields();
|
2017-03-15 19:29:04 +00:00
|
|
|
if ( $this->sortDescending() ) {
|
2017-03-22 20:11:11 +00:00
|
|
|
foreach ( $order as &$field ) {
|
|
|
|
|
$field .= " DESC";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( $order ) {
|
|
|
|
|
$options['ORDER BY'] = $order;
|
2011-01-29 22:07:22 +00:00
|
|
|
}
|
2017-03-22 20:11:11 +00:00
|
|
|
|
|
|
|
|
return $dbr->select( 'querycache',
|
|
|
|
|
[ 'qc_type',
|
2012-08-15 13:16:09 +00:00
|
|
|
'namespace' => 'qc_namespace',
|
|
|
|
|
'title' => 'qc_title',
|
2016-02-17 09:09:32 +00:00
|
|
|
'value' => 'qc_value' ],
|
|
|
|
|
[ 'qc_type' => $this->getName() ],
|
2017-03-22 20:11:11 +00:00
|
|
|
__METHOD__,
|
|
|
|
|
$options
|
2010-12-22 14:16:25 +00:00
|
|
|
);
|
|
|
|
|
}
|
2011-01-29 22:07:22 +00:00
|
|
|
|
2017-03-22 20:11:11 +00:00
|
|
|
/**
|
|
|
|
|
* Return the order fields for fetchFromCache. Default is to always use
|
|
|
|
|
* "ORDER BY value" which was the default prior to this function.
|
|
|
|
|
* @return array
|
|
|
|
|
* @since 1.29
|
|
|
|
|
*/
|
|
|
|
|
function getCacheOrderFields() {
|
|
|
|
|
return [ 'value' ];
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 20:31:32 +00:00
|
|
|
public function getCachedTimestamp() {
|
2011-09-29 15:16:35 +00:00
|
|
|
if ( is_null( $this->cachedTimestamp ) ) {
|
2016-09-05 19:55:19 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2017-03-07 02:14:14 +00:00
|
|
|
$fname = static::class . '::getCachedTimestamp';
|
2010-12-22 20:43:22 +00:00
|
|
|
$this->cachedTimestamp = $dbr->selectField( 'querycache_info', 'qci_timestamp',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ '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
|
|
|
|
2015-06-17 15:26:03 +00:00
|
|
|
/**
|
|
|
|
|
* Returns limit and offset, as returned by $this->getRequest()->getLimitOffset().
|
|
|
|
|
* Subclasses may override this to further restrict or modify limit and offset.
|
|
|
|
|
*
|
2015-11-03 23:59:45 +00:00
|
|
|
* @note Restricts the offset parameter, as most query pages have inefficient paging
|
2015-06-17 15:26:03 +00:00
|
|
|
*
|
2015-12-29 07:55:21 +00:00
|
|
|
* Its generally expected that the returned limit will not be 0, and the returned
|
|
|
|
|
* offset will be less than the max results.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.26
|
2015-06-17 15:26:03 +00:00
|
|
|
* @return int[] list( $limit, $offset )
|
|
|
|
|
*/
|
|
|
|
|
protected function getLimitOffset() {
|
2015-11-03 23:59:45 +00:00
|
|
|
list( $limit, $offset ) = $this->getRequest()->getLimitOffset();
|
2015-12-29 07:55:21 +00:00
|
|
|
if ( $this->getConfig()->get( 'MiserMode' ) ) {
|
2015-11-03 23:59:45 +00:00
|
|
|
$maxResults = $this->getMaxResults();
|
|
|
|
|
// Can't display more than max results on a page
|
|
|
|
|
$limit = min( $limit, $maxResults );
|
2015-12-29 07:55:21 +00:00
|
|
|
// Can't skip over more than the end of $maxResults
|
|
|
|
|
$offset = min( $offset, $maxResults + 1 );
|
2015-11-03 23:59:45 +00:00
|
|
|
}
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ $limit, $offset ];
|
2015-11-03 23:59:45 +00:00
|
|
|
}
|
|
|
|
|
|
2015-12-29 07:55:21 +00:00
|
|
|
/**
|
|
|
|
|
* What is limit to fetch from DB
|
|
|
|
|
*
|
|
|
|
|
* Used to make it appear the DB stores less results then it actually does
|
2016-04-30 10:10:17 +00:00
|
|
|
* @param int $uiLimit Limit from UI
|
|
|
|
|
* @param int $uiOffset Offset from UI
|
2015-12-29 07:55:21 +00:00
|
|
|
* @return int Limit to use for DB (not including extra row to see if at end)
|
|
|
|
|
*/
|
|
|
|
|
protected function getDBLimit( $uiLimit, $uiOffset ) {
|
|
|
|
|
$maxResults = $this->getMaxResults();
|
|
|
|
|
if ( $this->getConfig()->get( 'MiserMode' ) ) {
|
|
|
|
|
$limit = min( $uiLimit + 1, $maxResults - $uiOffset );
|
|
|
|
|
return max( $limit, 0 );
|
|
|
|
|
} else {
|
|
|
|
|
return $uiLimit + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-03 23:59:45 +00:00
|
|
|
/**
|
|
|
|
|
* Get max number of results we can return in miser mode.
|
|
|
|
|
*
|
|
|
|
|
* Most QueryPage subclasses use inefficient paging, so limit the max amount we return
|
|
|
|
|
* This matters for uncached query pages that might otherwise accept an offset of 3 million
|
|
|
|
|
*
|
|
|
|
|
* @since 1.27
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
protected function getMaxResults() {
|
2015-12-29 07:55:21 +00:00
|
|
|
// Max of 10000, unless we store more than 10000 in query cache.
|
2015-11-03 23:59:45 +00:00
|
|
|
return max( $this->getConfig()->get( 'QueryCacheLimit' ), 10000 );
|
2015-06-17 15:26:03 +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
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2015-07-18 19:51:07 +00:00
|
|
|
public function execute( $par ) {
|
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' );
|
2014-07-20 20:31:58 +00:00
|
|
|
return;
|
2010-12-22 14:16:25 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-29 22:02:27 +00:00
|
|
|
$out->setSyndicated( $this->isSyndicated() );
|
|
|
|
|
|
|
|
|
|
if ( $this->limit == 0 && $this->offset == 0 ) {
|
2015-06-17 15:26:03 +00:00
|
|
|
list( $this->limit, $this->offset ) = $this->getLimitOffset();
|
2012-01-29 22:02:27 +00:00
|
|
|
}
|
2015-12-29 07:55:21 +00:00
|
|
|
$dbLimit = $this->getDBLimit( $this->limit, $this->offset );
|
2014-05-12 14:42:51 +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
|
2015-12-29 07:55:21 +00:00
|
|
|
$res = $this->reallyDoQuery( $dbLimit, $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
|
2015-12-29 07:55:21 +00:00
|
|
|
$res = $this->fetchFromCache( $dbLimit, $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();
|
2014-08-07 17:28:22 +00:00
|
|
|
$maxResults = $lang->formatNum( $this->getConfig()->get( 'QueryCacheLimit' ) );
|
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
|
2014-08-07 17:28:22 +00:00
|
|
|
if ( is_array( $this->getConfig()->get( 'DisableQueryPageUpdate' ) )
|
|
|
|
|
&& in_array( $this->getName(), $this->getConfig()->get( 'DisableQueryPageUpdate' ) )
|
2013-12-08 09:48:36 +00:00
|
|
|
) {
|
|
|
|
|
$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
|
|
|
|
2015-04-10 09:31:35 +00:00
|
|
|
$dbr = $this->getRecacheDB();
|
2005-09-11 12:33:59 +00:00
|
|
|
$this->preprocessResults( $dbr, $res );
|
2009-07-14 08:44:58 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$out->addHTML( Xml::openElement( 'div', [ '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-03-20 18:59:20 +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
|
2015-12-29 07:55:21 +00:00
|
|
|
$miserMaxResults = $this->getConfig()->get( 'MiserMode' )
|
|
|
|
|
&& ( $this->offset + $this->limit >= $this->getMaxResults() );
|
|
|
|
|
$atEnd = ( $this->numRows <= $this->limit ) || $miserMaxResults;
|
2013-12-24 08:07:04 +00:00
|
|
|
$paging = $this->getLanguage()->viewPrevNext( $this->getPageTitle( $par ), $this->offset,
|
2015-11-03 23:59:45 +00:00
|
|
|
$this->limit, $this->linkParameters(), $atEnd );
|
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
|
2015-04-29 00:16:38 +00:00
|
|
|
$this->showEmptyText();
|
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' ) );
|
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
|
2014-12-09 09:05:22 +00:00
|
|
|
* @param IDatabase $dbr Database (read) connection to use
|
2018-04-04 12:52:10 +00:00
|
|
|
* @param IResultWrapper $res Result pointer
|
2013-04-14 19:18:38 +00:00
|
|
|
* @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 ) {
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( $num > 0 ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$html = [];
|
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]
|
2018-01-01 13:10:16 +00:00
|
|
|
// phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall
|
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 ) {
|
2007-03-28 21:01:58 +00:00
|
|
|
$html[] = $this->listoutput
|
2007-09-04 19:29:47 +00:00
|
|
|
? $line
|
2016-01-03 19:31:05 +00:00
|
|
|
: "<li>{$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-03-28 21:01:58 +00:00
|
|
|
$html[] = $this->listoutput
|
2007-09-04 19:29:47 +00:00
|
|
|
? $line
|
2016-01-03 19:31:05 +00:00
|
|
|
: "<li>{$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
|
2018-07-29 12:24:54 +00:00
|
|
|
? MediaWikiServices::getInstance()->getContentLanguage()->listToText( $html )
|
2007-03-28 21:01:58 +00:00
|
|
|
: 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
|
|
|
/**
|
2014-04-20 19:16:57 +00:00
|
|
|
* @param int $offset
|
2011-10-03 22:51:38 +00:00
|
|
|
* @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.
|
2014-12-09 09:05:22 +00:00
|
|
|
* @param IDatabase $db
|
2018-04-04 12:52:10 +00:00
|
|
|
* @param IResultWrapper $res
|
2005-09-11 12:33:59 +00:00
|
|
|
*/
|
2014-05-12 14:42:51 +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 ) {
|
2014-08-07 17:28:22 +00:00
|
|
|
if ( !$this->getConfig()->get( 'Feed' ) ) {
|
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
|
|
|
|
2014-08-07 17:28:22 +00:00
|
|
|
$limit = min( $limit, $this->getConfig()->get( 'FeedLimit' ) );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2014-08-07 17:28:22 +00:00
|
|
|
$feedClasses = $this->getConfig()->get( 'FeedClasses' );
|
|
|
|
|
if ( isset( $feedClasses[$class] ) ) {
|
2014-05-12 14:42:51 +00:00
|
|
|
/** @var RSSFeed|AtomFeed $feed */
|
2014-08-07 17:28:22 +00:00
|
|
|
$feed = new $feedClasses[$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 ) {
|
2017-10-06 22:17:58 +00:00
|
|
|
$date = $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 ) {
|
2017-10-06 22:17:58 +00:00
|
|
|
return $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() {
|
2011-04-17 10:44:44 +00:00
|
|
|
$desc = $this->getDescription();
|
2014-08-07 17:28:22 +00:00
|
|
|
$code = $this->getConfig()->get( 'LanguageCode' );
|
|
|
|
|
$sitename = $this->getConfig()->get( 'Sitename' );
|
|
|
|
|
return "$sitename - $desc [$code]";
|
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
|
|
|
}
|
2016-10-29 20:46:17 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new LinkBatch object, adds all pages from the passed ResultWrapper (MUST include
|
|
|
|
|
* title and optional the namespace field) and executes the batch. This operation will pre-cache
|
|
|
|
|
* LinkCache information like page existence and information for stub color and redirect hints.
|
|
|
|
|
*
|
2018-04-04 12:52:10 +00:00
|
|
|
* @param IResultWrapper $res The ResultWrapper object to process. Needs to include the title
|
2016-10-29 20:46:17 +00:00
|
|
|
* field and namespace field, if the $ns parameter isn't set.
|
|
|
|
|
* @param null $ns Use this namespace for the given titles in the ResultWrapper object,
|
|
|
|
|
* instead of the namespace value of $res.
|
|
|
|
|
*/
|
2018-04-04 12:52:10 +00:00
|
|
|
protected function executeLBFromResultWrapper( IResultWrapper $res, $ns = null ) {
|
2016-10-29 20:46:17 +00:00
|
|
|
if ( !$res->numRows() ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$batch = new LinkBatch;
|
|
|
|
|
foreach ( $res as $row ) {
|
2018-06-20 05:26:57 +00:00
|
|
|
$batch->add( $ns ?? $row->namespace, $row->title );
|
2016-10-29 20:46:17 +00:00
|
|
|
}
|
|
|
|
|
$batch->execute();
|
|
|
|
|
|
|
|
|
|
$res->seek( 0 );
|
|
|
|
|
}
|
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
|
|
|
}
|