Merge "Some more editor files to ignore."
[lhc/web/wiklou.git] / includes / QueryPage.php
index 31df316..a93639a 100644 (file)
@@ -69,9 +69,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 +90,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 +112,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 +150,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 +187,7 @@ abstract class QueryPage extends SpecialPage {
        /**
         * Override to sort by increasing values
         *
-        * @return Boolean
+        * @return bool
         */
        function sortDescending() {
                return true;
@@ -198,7 +198,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 +209,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 +220,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 +229,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 +242,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 +262,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 +283,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 ) {
@@ -302,62 +300,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
         */
@@ -366,23 +360,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 );
                        }
@@ -397,11 +396,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 ) {
@@ -414,14 +416,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 );
                }
@@ -456,6 +458,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 ) {
@@ -567,12 +570,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;
@@ -640,11 +643,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 ) {
@@ -685,6 +692,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 ) {
@@ -740,7 +748,6 @@ abstract class QueryPage extends SpecialPage {
  * WantedPages, WantedTemplates, etc
  */
 abstract class WantedQueryPage extends QueryPage {
-
        function isExpensive() {
                return true;
        }
@@ -751,6 +758,8 @@ abstract class WantedQueryPage extends QueryPage {
 
        /**
         * Cache page existence for performance
+        * @param DatabaseBase $db
+        * @param ResultWrapper $res
         */
        function preprocessResults( $db, $res ) {
                if ( !$res->numRows() ) {
@@ -782,8 +791,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 ) {
@@ -817,8 +826,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 ) {