Merge "Add non DBMS depending SQL tests for DatabaseBase"
[lhc/web/wiklou.git] / includes / QueryPage.php
index a01ac68..a4a1ffb 100644 (file)
@@ -72,7 +72,6 @@ global $wgDisableCounters;
 if ( !$wgDisableCounters )
        $wgQueryPages[] = array( 'PopularPagesPage', 'Popularpages' );
 
-
 /**
  * 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
@@ -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,7 @@ 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
         */
@@ -187,7 +186,7 @@ abstract class QueryPage extends SpecialPage {
        /**
         * Override to sort by increasing values
         *
-        * @return Boolean
+        * @return bool
         */
        function sortDescending() {
                return true;
@@ -198,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;
@@ -209,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() {
@@ -220,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;
@@ -229,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;
@@ -242,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 '';
@@ -265,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();
@@ -286,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 ) {
@@ -352,8 +349,8 @@ abstract class QueryPage extends SpecialPage {
 
        /**
         * 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
         */
@@ -362,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 );
                        }
@@ -393,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 ) {
@@ -410,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 );
                }
@@ -452,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 ) {
@@ -563,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;
@@ -636,11 +642,15 @@ 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 ) {
@@ -681,6 +691,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 ) {
@@ -736,7 +747,6 @@ abstract class QueryPage extends SpecialPage {
  * WantedPages, WantedTemplates, etc
  */
 abstract class WantedQueryPage extends QueryPage {
-
        function isExpensive() {
                return true;
        }
@@ -747,6 +757,8 @@ abstract class WantedQueryPage extends QueryPage {
 
        /**
         * Cache page existence for performance
+        * @param DatabaseBase $db
+        * @param ResultWrapper $res
         */
        function preprocessResults( $db, $res ) {
                if ( !$res->numRows() ) {
@@ -778,8 +790,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 ) {
@@ -813,8 +825,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 ) {