summaryrefslogtreecommitdiff
path: root/includes/QueryPage.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/QueryPage.php')
-rw-r--r--includes/QueryPage.php178
1 files changed, 92 insertions, 86 deletions
diff --git a/includes/QueryPage.php b/includes/QueryPage.php
index ac559dc5..51b5706f 100644
--- a/includes/QueryPage.php
+++ b/includes/QueryPage.php
@@ -35,7 +35,6 @@ $wgQueryPages = array(
array( 'AncientPagesPage', 'Ancientpages' ),
array( 'BrokenRedirectsPage', 'BrokenRedirects' ),
array( 'DeadendPagesPage', 'Deadendpages' ),
- array( 'DisambiguationsPage', 'Disambiguations' ),
array( 'DoubleRedirectsPage', 'DoubleRedirects' ),
array( 'FileDuplicateSearchPage', 'FileDuplicateSearch' ),
array( 'LinkSearchPage', 'LinkSearch' ),
@@ -69,9 +68,9 @@ $wgQueryPages = array(
wfRunHooks( 'wgQueryPages', array( &$wgQueryPages ) );
global $wgDisableCounters;
-if ( !$wgDisableCounters )
+if ( !$wgDisableCounters ) {
$wgQueryPages[] = array( 'PopularPagesPage', 'Popularpages' );
-
+}
/**
* This is a class for doing query pages; since they're almost all the same,
@@ -90,7 +89,7 @@ abstract class QueryPage extends SpecialPage {
/**
* The offset and limit in use, as passed to the query() function
*
- * @var integer
+ * @var int
*/
var $offset = 0;
var $limit = 0;
@@ -112,7 +111,7 @@ abstract class QueryPage extends SpecialPage {
/**
* A mutator for $this->listoutput;
*
- * @param $bool Boolean
+ * @param bool $bool
*/
function setListoutput( $bool ) {
$this->listoutput = $bool;
@@ -150,7 +149,8 @@ abstract class QueryPage extends SpecialPage {
/**
* For back-compat, subclasses may return a raw SQL query here, as a string.
- * This is stronly deprecated; getQueryInfo() should be overridden instead.
+ * This is strongly deprecated; getQueryInfo() should be overridden instead.
+ * @throws MWException
* @return string
*/
function getSQL() {
@@ -186,7 +186,7 @@ abstract class QueryPage extends SpecialPage {
/**
* Override to sort by increasing values
*
- * @return Boolean
+ * @return bool
*/
function sortDescending() {
return true;
@@ -197,7 +197,7 @@ abstract class QueryPage extends SpecialPage {
* don't let it run in miser mode. $wgDisableQueryPages causes all query
* pages to be declared expensive. Some query pages are always expensive.
*
- * @return Boolean
+ * @return bool
*/
function isExpensive() {
global $wgDisableQueryPages;
@@ -208,7 +208,7 @@ abstract class QueryPage extends SpecialPage {
* Is the output of this query cacheable? Non-cacheable expensive pages
* will be disabled in miser mode and will not have their results written
* to the querycache table.
- * @return Boolean
+ * @return bool
* @since 1.18
*/
public function isCacheable() {
@@ -219,7 +219,7 @@ abstract class QueryPage extends SpecialPage {
* Whether or not the output of the page in question is retrieved from
* the database cache.
*
- * @return Boolean
+ * @return bool
*/
function isCached() {
global $wgMiserMode;
@@ -228,9 +228,9 @@ abstract class QueryPage extends SpecialPage {
}
/**
- * Sometime we dont want to build rss / atom feeds.
+ * Sometime we don't want to build rss / atom feeds.
*
- * @return Boolean
+ * @return bool
*/
function isSyndicated() {
return true;
@@ -241,19 +241,16 @@ abstract class QueryPage extends SpecialPage {
* 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.
* If the function returns false, the line output will be skipped.
- * @param $skin Skin
- * @param $result object Result row
- * @return mixed String or false to skip
- *
- * @param $skin Skin object
- * @param $result Object: database row
+ * @param Skin $skin
+ * @param object $result Result row
+ * @return string|bool String or false to skip
*/
abstract function formatResult( $skin, $result );
/**
* The content returned by this function will be output before any result
*
- * @return String
+ * @return string
*/
function getPageHeader() {
return '';
@@ -264,7 +261,7 @@ abstract class QueryPage extends SpecialPage {
* as an associative array. They will be encoded and added to the paging
* links (prev/next/lengths).
*
- * @return Array
+ * @return array
*/
function linkParameters() {
return array();
@@ -285,8 +282,9 @@ abstract class QueryPage extends SpecialPage {
/**
* Clear the cache and save new results
*
- * @param $limit Integer: limit for SQL statement
- * @param $ignoreErrors Boolean: whether to ignore database errors
+ * @param int|bool $limit Limit for SQL statement
+ * @param bool $ignoreErrors Whether to ignore database errors
+ * @throws DBError|Exception
* @return bool|int
*/
function recache( $limit, $ignoreErrors = true ) {
@@ -301,62 +299,58 @@ abstract class QueryPage extends SpecialPage {
return false;
}
- if ( $ignoreErrors ) {
- $ignoreW = $dbw->ignoreErrors( true );
- $ignoreR = $dbr->ignoreErrors( true );
- }
-
- # Clear out any old cached data
- $dbw->delete( 'querycache', array( 'qc_type' => $this->getName() ), $fname );
- # Do query
- $res = $this->reallyDoQuery( $limit, false );
- $num = false;
- if ( $res ) {
- $num = $res->numRows();
- # Fetch results
- $vals = array();
- while ( $res && $row = $dbr->fetchObject( $res ) ) {
- if ( isset( $row->value ) ) {
- if ( $this->usesTimestamps() ) {
- $value = wfTimestamp( TS_UNIX,
- $row->value );
+ try {
+ # Clear out any old cached data
+ $dbw->delete( 'querycache', array( 'qc_type' => $this->getName() ), $fname );
+ # Do query
+ $res = $this->reallyDoQuery( $limit, false );
+ $num = false;
+ if ( $res ) {
+ $num = $res->numRows();
+ # Fetch results
+ $vals = array();
+ while ( $res && $row = $dbr->fetchObject( $res ) ) {
+ if ( isset( $row->value ) ) {
+ if ( $this->usesTimestamps() ) {
+ $value = wfTimestamp( TS_UNIX,
+ $row->value );
+ } else {
+ $value = intval( $row->value ); // @bug 14414
+ }
} else {
- $value = intval( $row->value ); // @bug 14414
+ $value = 0;
}
- } else {
- $value = 0;
- }
- $vals[] = array( 'qc_type' => $this->getName(),
- 'qc_namespace' => $row->namespace,
- 'qc_title' => $row->title,
- 'qc_value' => $value );
- }
+ $vals[] = array( 'qc_type' => $this->getName(),
+ 'qc_namespace' => $row->namespace,
+ 'qc_title' => $row->title,
+ 'qc_value' => $value );
+ }
- # Save results into the querycache table on the master
- if ( count( $vals ) ) {
- if ( !$dbw->insert( 'querycache', $vals, __METHOD__ ) ) {
- // Set result to false to indicate error
- $num = false;
+ # Save results into the querycache table on the master
+ if ( count( $vals ) ) {
+ $dbw->insert( 'querycache', $vals, __METHOD__ );
}
+ # 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 );
}
- if ( $ignoreErrors ) {
- $dbw->ignoreErrors( $ignoreW );
- $dbr->ignoreErrors( $ignoreR );
+ } catch ( DBError $e ) {
+ if ( !$ignoreErrors ) {
+ throw $e; // report query error
}
-
- # 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 );
-
+ $num = false; // set result to false to indicate error
}
+
return $num;
}
/**
* Run the query and return the result
- * @param $limit mixed Numerical limit or false for no limit
- * @param $offset mixed Numerical offset or false for no offset
+ * @param int|bool $limit Numerical limit or false for no limit
+ * @param int|bool $offset Numerical offset or false for no offset
* @return ResultWrapper
* @since 1.18
*/
@@ -365,23 +359,28 @@ abstract class QueryPage extends SpecialPage {
$dbr = wfGetDB( DB_SLAVE );
$query = $this->getQueryInfo();
$order = $this->getOrderFields();
+
if ( $this->sortDescending() ) {
foreach ( $order as &$field ) {
$field .= ' DESC';
}
}
+
if ( is_array( $query ) ) {
$tables = isset( $query['tables'] ) ? (array)$query['tables'] : array();
$fields = isset( $query['fields'] ) ? (array)$query['fields'] : array();
$conds = isset( $query['conds'] ) ? (array)$query['conds'] : array();
$options = isset( $query['options'] ) ? (array)$query['options'] : array();
$join_conds = isset( $query['join_conds'] ) ? (array)$query['join_conds'] : array();
+
if ( count( $order ) ) {
$options['ORDER BY'] = $order;
}
+
if ( $limit !== false ) {
$options['LIMIT'] = intval( $limit );
}
+
if ( $offset !== false ) {
$options['OFFSET'] = intval( $offset );
}
@@ -396,11 +395,14 @@ abstract class QueryPage extends SpecialPage {
$sql = $dbr->limitResult( $sql, $limit, $offset );
$res = $dbr->query( $sql, $fname );
}
+
return $dbr->resultObject( $res );
}
/**
* Somewhat deprecated, you probably want to be using execute()
+ * @param int|bool $offset
+ * @oaram int|bool $limit
* @return ResultWrapper
*/
function doQuery( $offset = false, $limit = false ) {
@@ -413,14 +415,14 @@ abstract class QueryPage extends SpecialPage {
/**
* Fetch the query results from the query cache
- * @param $limit mixed Numerical limit or false for no limit
- * @param $offset mixed Numerical offset or false for no offset
+ * @param int|bool $limit Numerical limit or false for no limit
+ * @param int|bool $offset Numerical offset or false for no offset
* @return ResultWrapper
* @since 1.18
*/
function fetchFromCache( $limit, $offset = false ) {
$dbr = wfGetDB( DB_SLAVE );
- $options = array ();
+ $options = array();
if ( $limit !== false ) {
$options['LIMIT'] = intval( $limit );
}
@@ -455,6 +457,7 @@ abstract class QueryPage extends SpecialPage {
/**
* This is the actual workhorse. It does everything needed to make a
* real, honest-to-gosh query page.
+ * @para $par
* @return int
*/
function execute( $par ) {
@@ -566,12 +569,12 @@ abstract class QueryPage extends SpecialPage {
* Format and output report results using the given information plus
* OutputPage
*
- * @param $out OutputPage to print to
- * @param $skin Skin: user skin to use
- * @param $dbr Database (read) connection to use
- * @param $res Integer: result pointer
- * @param $num Integer: number of available result rows
- * @param $offset Integer: paging offset
+ * @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
*/
protected function outputResults( $out, $skin, $dbr, $res, $num, $offset ) {
global $wgContLang;
@@ -584,7 +587,7 @@ abstract class QueryPage extends SpecialPage {
# $res might contain the whole 1,000 rows, so we read up to
# $num [should update this to use a Pager]
- for ( $i = 0; $i < $num && $row = $dbr->fetchObject( $res ); $i++ ) {
+ for ( $i = 0; $i < $num && $row = $res->fetchObject(); $i++ ) {
$line = $this->formatResult( $skin, $row );
if ( $line ) {
$attr = ( isset( $row->usepatrol ) && $row->usepatrol && $row->patrolled == 0 )
@@ -639,25 +642,26 @@ abstract class QueryPage extends SpecialPage {
/**
* Do any necessary preprocessing of the result object.
+ * @param DatabaseBase $db
+ * @param ResultWrapper $res
*/
function preprocessResults( $db, $res ) {}
/**
* Similar to above, but packaging in a syndicated feed instead of a web page
+ * @param string $class
+ * @param int $limit
* @return bool
*/
function doFeed( $class = '', $limit = 50 ) {
- global $wgFeed, $wgFeedClasses;
+ global $wgFeed, $wgFeedClasses, $wgFeedLimit;
if ( !$wgFeed ) {
$this->getOutput()->addWikiMsg( 'feed-unavailable' );
- return;
+ return false;
}
- global $wgFeedLimit;
- if ( $limit > $wgFeedLimit ) {
- $limit = $wgFeedLimit;
- }
+ $limit = min( $limit, $wgFeedLimit );
if ( isset( $wgFeedClasses[$class] ) ) {
$feed = new $wgFeedClasses[$class](
@@ -684,6 +688,7 @@ abstract class QueryPage extends SpecialPage {
/**
* Override for custom handling. If the titles/links are ok, just do
* feedItemDesc()
+ * @param object $row
* @return FeedItem|null
*/
function feedResult( $row ) {
@@ -739,7 +744,6 @@ abstract class QueryPage extends SpecialPage {
* WantedPages, WantedTemplates, etc
*/
abstract class WantedQueryPage extends QueryPage {
-
function isExpensive() {
return true;
}
@@ -750,6 +754,8 @@ abstract class WantedQueryPage extends QueryPage {
/**
* Cache page existence for performance
+ * @param DatabaseBase $db
+ * @param ResultWrapper $res
*/
function preprocessResults( $db, $res ) {
if ( !$res->numRows() ) {
@@ -781,8 +787,8 @@ abstract class WantedQueryPage extends QueryPage {
/**
* Format an individual result
*
- * @param $skin Skin to use for UI elements
- * @param $result Result row
+ * @param Skin $skin Skin to use for UI elements
+ * @param object $result Result row
* @return string
*/
public function formatResult( $skin, $result ) {
@@ -816,8 +822,8 @@ abstract class WantedQueryPage extends QueryPage {
/**
* Make a "what links here" link for a given title
*
- * @param $title Title to make the link for
- * @param $result Object: result row
+ * @param Title $title Title to make the link for
+ * @param object $result Result row
* @return string
*/
private function makeWlhLink( $title, $result ) {