Merge "- Fix bug 35076 - More tests, test comments"
[lhc/web/wiklou.git] / includes / QueryPage.php
index c119b85..151cc76 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * Contain a class for special pages
  * @file
- * @ingroup SpecialPages
+ * @ingroup SpecialPage
  */
 
 /**
@@ -259,6 +259,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 +270,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 +295,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 ) ) {
@@ -382,6 +384,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,30 +438,34 @@ 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 ) {
-               if ( !$this->userCanExecute( $this->getUser() ) ) {
+               global $wgQueryCacheLimit, $wgDisableQueryPageUpdate;
+
+               $user = $this->getUser();
+               if ( !$this->userCanExecute( $user ) ) {
                        $this->displayRestrictionError();
                        return;
                }
 
-               if ( $this->limit == 0 && $this->offset == 0 ) {
-                       list( $this->limit, $this->offset ) = $this->getRequest()->getLimitOffset();
-               }
-               $dbr = wfGetDB( DB_SLAVE );
-
                $this->setHeaders();
+               $this->outputHeader();
+
                $out = $this->getOutput();
-               $out->setSyndicated( $this->isSyndicated() );
 
                if ( $this->isCached() && !$this->isCacheable() ) {
-                       $out->setSyndicated( false );
                        $out->addWikiMsg( 'querypage-disabled' );
                        return 0;
                }
 
+               $out->setSyndicated( $this->isSyndicated() );
+
+               if ( $this->limit == 0 && $this->offset == 0 ) {
+                       list( $this->limit, $this->offset ) = $this->getRequest()->getLimitOffset();
+               }
+
                // TODO: Use doQuery()
-               // $res = null;
                if ( !$this->isCached() ) {
                        $res = $this->reallyDoQuery( $this->limit, $this->offset );
                } else {
@@ -468,32 +475,31 @@ abstract class QueryPage extends SpecialPage {
 
                                # Fetch the timestamp of this update
                                $ts = $this->getCachedTimestamp();
+                               $lang = $this->getLanguage();
+                               $maxResults = $lang->formatNum( $wgQueryCacheLimit );
 
                                if ( $ts ) {
-                                       $lang = $this->getLang();
-                                       $updated = $lang->timeanddate( $ts, true, true );
-                                       $updateddate = $lang->date( $ts, true, true );
-                                       $updatedtime = $lang->time( $ts, true, true );
+                                       $updated = $lang->userTimeAndDate( $ts, $user );
+                                       $updateddate = $lang->userDate( $ts, $user );
+                                       $updatedtime = $lang->userTime( $ts, $user );
                                        $out->addMeta( 'Data-Cache-Time', $ts );
                                        $out->addInlineScript( "var dataCacheTime = '$ts';" );
-                                       $out->addWikiMsg( 'perfcachedts', $updated, $updateddate, $updatedtime );
+                                       $out->addWikiMsg( 'perfcachedts', $updated, $updateddate, $updatedtime, $maxResults );
                                } else {
-                                       $out->addWikiMsg( 'perfcached' );
+                                       $out->addWikiMsg( 'perfcached', $maxResults );
                                }
 
                                # If updates on this page have been disabled, let the user know
                                # that the data set won't be refreshed for now
-                               global $wgDisableQueryPageUpdate;
                                if ( is_array( $wgDisableQueryPageUpdate ) && in_array( $this->getName(), $wgDisableQueryPageUpdate ) ) {
                                        $out->addWikiMsg( 'querypage-no-updates' );
                                }
-
                        }
-
                }
 
-               $this->numRows = $dbr->numRows( $res );
+               $this->numRows = $res->numRows();
 
+               $dbr = wfGetDB( DB_SLAVE );
                $this->preprocessResults( $dbr, $res );
 
                $out->addHTML( Xml::openElement( 'div', array( 'class' => 'mw-spcontent' ) ) );
@@ -502,16 +508,16 @@ abstract class QueryPage extends SpecialPage {
                if ( $this->shownavigation ) {
                        $out->addHTML( $this->getPageHeader() );
                        if ( $this->numRows > 0 ) {
-                               $out->addHTML( '<p>' . wfShowingResults( $this->offset, $this->numRows ) . '</p>' );
+                               $out->addHTML( $this->msg( 'showingresults' )->numParams(
+                                       $this->numRows, $this->offset + 1 )->parseAsBlock() );
                                # Disable the "next" link when we reach the end
-                               $paging = wfViewPrevNext( $this->offset, $this->limit,
-                                       $this->getTitle( $par ),
-                                       wfArrayToCGI( $this->linkParameters() ), ( $this->numRows < $this->limit ) );
+                               $paging = $this->getLanguage()->viewPrevNext( $this->getTitle( $par ), $this->offset,
+                                       $this->limit, $this->linkParameters(), ( $this->numRows < $this->limit ) );
                                $out->addHTML( '<p>' . $paging . '</p>' );
                        } else {
                                # No results to show, so don't bother with "showing X of Y" etc.
                                # -- just let the user know and give up now
-                               $out->addHTML( '<p>' . wfMsgHtml( 'specialpage-empty' ) . '</p>' );
+                               $out->addWikiMsg( 'specialpage-empty' );
                                $out->addHTML( Xml::closeElement( 'div' ) );
                                return;
                        }
@@ -619,6 +625,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;
@@ -658,6 +665,7 @@ 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 ) ) {
@@ -699,7 +707,7 @@ abstract class QueryPage extends SpecialPage {
        }
 
        function feedDesc() {
-               return wfMsgExt( 'tagline', 'parsemag' );
+               return $this->msg( 'tagline' )->text();
        }
 
        function feedUrl() {
@@ -725,6 +733,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 );
@@ -732,9 +744,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 );
        }
 
        /**
@@ -743,6 +753,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;
@@ -777,7 +788,7 @@ abstract class WantedQueryPage extends QueryPage {
                                        array( 'broken' )
                                );
                        }
-                       return $this->getLang()->specialList( $pageLink, $this->makeWlhLink( $title, $result ) );
+                       return $this->getLanguage()->specialList( $pageLink, $this->makeWlhLink( $title, $result ) );
                } else {
                        return $this->msg( 'wantedpages-badtitle', $result->title )->escaped();
                }