Revert r106521: creates lots of long, unwrappable lines in help output
[lhc/web/wiklou.git] / includes / api / ApiQueryRandom.php
index 85863ab..2e9e2dd 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 
 /**
- * Created on Monday, January 28, 2008
  *
- * API for MediaWiki 1.8+
+ *
+ * Created on Monday, January 28, 2008
  *
  * Copyright © 2008 Brent Garber
  *
  *
  * 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.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       // Eclipse helper - will be ignored in production
-       require_once( 'ApiQueryBase.php' );
-}
-
 /**
  * Query module to get list of random pages
  *
  * @ingroup API
  */
 
- class ApiQueryRandom extends ApiQueryGeneratorBase {
+class ApiQueryRandom extends ApiQueryGeneratorBase {
 
        public function __construct( $query, $moduleName ) {
                parent::__construct( $query, $moduleName, 'rn' );
@@ -48,6 +45,14 @@ if ( !defined( 'MEDIAWIKI' ) ) {
                $this->run( $resultPageSet );
        }
 
+       /**
+        * @param  $randstr
+        * @param  $limit
+        * @param  $namespace
+        * @param $resultPageSet ApiPageSet
+        * @param  $redirect
+        * @return void
+        */
        protected function prepareQuery( $randstr, $limit, $namespace, &$resultPageSet, $redirect ) {
                $this->resetQueryParams();
                $this->addTables( 'page' );
@@ -63,11 +68,14 @@ if ( !defined( 'MEDIAWIKI' ) ) {
                }
        }
 
-       protected function runQuery( &$resultPageSet ) {
-               $db = $this->getDB();
+       /**
+        * @param $resultPageSet ApiPageSet
+        * @return int
+        */
+       protected function runQuery( $resultPageSet = null ) {
                $res = $this->select( __METHOD__ );
                $count = 0;
-               while ( $row = $db->fetchObject( $res ) ) {
+               foreach ( $res as $row ) {
                        $count++;
                        if ( is_null( $resultPageSet ) ) {
                                // Prevent duplicates
@@ -87,10 +95,14 @@ if ( !defined( 'MEDIAWIKI' ) ) {
                                $resultPageSet->processDbRow( $row );
                        }
                }
-               $db->freeResult( $res );
+
                return $count;
        }
 
+       /**
+        * @param $resultPageSet ApiPageSet
+        * @return void
+        */
        public function run( $resultPageSet = null ) {
                $params = $this->extractRequestParams();
                $result = $this->getResult();
@@ -120,6 +132,10 @@ if ( !defined( 'MEDIAWIKI' ) ) {
                return $vals;
        }
 
+       public function getCacheMode( $params ) {
+               return 'public';
+       }
+
        public function getAllowedParams() {
                return array(
                        'namespace' => array(
@@ -154,11 +170,11 @@ if ( !defined( 'MEDIAWIKI' ) ) {
                );
        }
 
-       protected function getExamples() {
+       public function getExamples() {
                return 'api.php?action=query&list=random&rnnamespace=0&rnlimit=2';
        }
 
        public function getVersion() {
                return __CLASS__ . ': $Id: ApiQueryRandom.php overlordq$';
        }
-}
\ No newline at end of file
+}