+ /**
+ * 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
+ * @return ResultWrapper
+ */
+ function reallyDoQuery( $limit, $offset = false ) {
+ $fname = get_class( $this ) . "::reallyDoQuery";
+ $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'] = implode( ', ', $order );
+ }
+ if ( $limit !== false ) {
+ $options['LIMIT'] = intval( $limit );
+ }
+ if ( $offset !== false ) {
+ $options['OFFSET'] = intval( $offset );
+ }
+
+ $dbr = wfGetDB( DB_SLAVE );
+ $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 );
+ $res = $dbr->query( $sql );
+ }
+ return $dbr->resultObject( $res );
+ }
+
+ function doQuery( $limit, $offset = false ) {
+ if ( $this->isCached() && $this->isCacheable() ) {
+ return $this->fetchFromCache( $limit, $offset );
+ } else {
+ return $this->reallyDoQuery( $limit, $offset );
+ }
+ }
+
+ /**
+ * 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
+ * @return ResultWrapper
+ */
+ function fetchFromCache( $limit, $offset = false ) {
+ $dbr = wfGetDB( DB_SLAVE );
+ $options = array ();
+ if ( $limit !== false ) {
+ $options['LIMIT'] = intval( $limit );
+ }
+ if ( $offset !== false ) {
+ $options['OFFSET'] = intval( $offset );
+ }
+ $res = $dbr->select( 'querycache', array( 'qc_type',
+ 'qc_namespace AS namespace',
+ 'qc_title AS title',
+ 'qc_value AS value' ),
+ array( 'qc_type' => $this->getName() ),
+ __METHOD__, $options
+ );
+ return $dbr->resultObject( $res );
+ }
+