Add a way for packagers to override some installation details
[lhc/web/wiklou.git] / includes / QueryPage.php
index 3383551..4440aac 100644 (file)
@@ -1,6 +1,22 @@
 <?php
 /**
- * Contain a class for special pages
+ * 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
+ *
  * @file
  * @ingroup SpecialPage
  */
@@ -259,6 +275,7 @@ abstract class QueryPage extends SpecialPage {
         * 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.
+        * @return bool
         */
        function tryLastResult() {
                return false;
@@ -269,6 +286,7 @@ abstract class QueryPage extends SpecialPage {
         *
         * @param $limit Integer: limit for SQL statement
         * @param $ignoreErrors Boolean: whether to ignore database errors
+        * @return bool|int
         */
        function recache( $limit, $ignoreErrors = true ) {
                if ( !$this->isCacheable() ) {
@@ -293,7 +311,7 @@ abstract class QueryPage extends SpecialPage {
                $res = $this->reallyDoQuery( $limit, false );
                $num = false;
                if ( $res ) {
-                       $num = $dbr->numRows( $res );
+                       $num = $res->numRows();
                        # Fetch results
                        $vals = array();
                        while ( $res && $row = $dbr->fetchObject( $res ) ) {
@@ -358,7 +376,7 @@ abstract class QueryPage extends SpecialPage {
                        $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 );
+                               $options['ORDER BY'] = $order;
                        }
                        if ( $limit !== false ) {
                                $options['LIMIT'] = intval( $limit );
@@ -382,6 +400,7 @@ abstract class QueryPage extends SpecialPage {
 
        /**
         * Somewhat deprecated, you probably want to be using execute()
+        * @return ResultWrapper
         */
        function doQuery( $offset = false, $limit = false ) {
                if ( $this->isCached() && $this->isCacheable() ) {
@@ -435,6 +454,7 @@ abstract class QueryPage extends SpecialPage {
        /**
         * This is the actual workhorse. It does everything needed to make a
         * real, honest-to-gosh query page.
+        * @return int
         */
        function execute( $par ) {
                global $wgQueryCacheLimit, $wgDisableQueryPageUpdate;
@@ -479,7 +499,7 @@ abstract class QueryPage extends SpecialPage {
                                        $updateddate = $lang->userDate( $ts, $user );
                                        $updatedtime = $lang->userTime( $ts, $user );
                                        $out->addMeta( 'Data-Cache-Time', $ts );
-                                       $out->addInlineScript( "var dataCacheTime = '$ts';" );
+                                       $out->addJsConfigVars( 'dataCacheTime', $ts );
                                        $out->addWikiMsg( 'perfcachedts', $updated, $updateddate, $updatedtime, $maxResults );
                                } else {
                                        $out->addWikiMsg( 'perfcached', $maxResults );
@@ -488,7 +508,7 @@ abstract class QueryPage extends SpecialPage {
                                # If updates on this page have been disabled, let the user know
                                # that the data set won't be refreshed for now
                                if ( is_array( $wgDisableQueryPageUpdate ) && in_array( $this->getName(), $wgDisableQueryPageUpdate ) ) {
-                                       $out->addWikiMsg( 'querypage-no-updates' );
+                                       $out->wrapWikiMsg( "<div class=\"mw-querypage-no-updates\">\n$1\n</div>", 'querypage-no-updates' );
                                }
                        }
                }
@@ -621,6 +641,7 @@ abstract class QueryPage extends SpecialPage {
 
        /**
         * Similar to above, but packaging in a syndicated feed instead of a web page
+        * @return bool
         */
        function doFeed( $class = '', $limit = 50 ) {
                global $wgFeed, $wgFeedClasses;
@@ -660,12 +681,13 @@ abstract class QueryPage extends SpecialPage {
        /**
         * Override for custom handling. If the titles/links are ok, just do
         * feedItemDesc()
+        * @return FeedItem|null
         */
        function feedResult( $row ) {
                if ( !isset( $row->title ) ) {
                        return null;
                }
-               $title = Title::MakeTitle( intval( $row->namespace ), $row->title );
+               $title = Title::makeTitle( intval( $row->namespace ), $row->title );
                if ( $title ) {
                        $date = isset( $row->timestamp ) ? $row->timestamp : '';
                        $comments = '';
@@ -727,6 +749,10 @@ abstract class WantedQueryPage extends QueryPage {
         * Cache page existence for performance
         */
        function preprocessResults( $db, $res ) {
+               if ( !$res->numRows() ) {
+                       return;
+               }
+
                $batch = new LinkBatch;
                foreach ( $res as $row ) {
                        $batch->add( $row->namespace, $row->title );
@@ -734,9 +760,7 @@ abstract class WantedQueryPage extends QueryPage {
                $batch->execute();
 
                // Back to start for display
-               if ( $db->numRows( $res ) > 0 )
-                       // If there are no rows we get an error seeking.
-                       $db->dataSeek( $res, 0 );
+               $res->seek( 0 );
        }
 
        /**
@@ -745,6 +769,7 @@ abstract class WantedQueryPage extends QueryPage {
         * kluge for Special:WantedFiles, which may contain false
         * positives for files that exist e.g. in a shared repo (bug
         * 6220).
+        * @return bool
         */
        function forceExistenceCheck() {
                return false;