Follow up on r49790. Fixed a bug on variant select.
[lhc/web/wiklou.git] / includes / Category.php
index 45d2afa..50efdbc 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 /**
- * Category objects are immutable, strictly speaking.  If you call methods that change the database, like to refresh link counts, the objects will be appropriately reinitialized.  Member variables are lazy-initialized.
+ * Category objects are immutable, strictly speaking. If you call methods that change the database, 
+ * like to refresh link counts, the objects will be appropriately reinitialized.
+ * Member variables are lazy-initialized.
  *
  * TODO: Move some stuff from CategoryPage.php to here, and use that.
  *
@@ -39,8 +41,7 @@ class Category {
                $dbr = wfGetDB( DB_SLAVE );
                $row = $dbr->selectRow(
                        'category',
-                       array( 'cat_id', 'cat_title', 'cat_pages', 'cat_subcats',
-                               'cat_files' ),
+                       array( 'cat_id', 'cat_title', 'cat_pages', 'cat_subcats', 'cat_files' ),
                        $where,
                        __METHOD__
                );
@@ -68,8 +69,7 @@ class Category {
                # (bug 13683) If the count is negative, then 1) it's obviously wrong
                # and should not be kept, and 2) we *probably* don't have to scan many
                # rows to obtain the correct figure, so let's risk a one-time recount.
-               if( $this->mPages < 0 || $this->mSubcats < 0 ||
-               $this->mFiles < 0 ) {
+               if( $this->mPages < 0 || $this->mSubcats < 0 || $this->mFiles < 0 ) {
                        $this->refreshCounts();
                }
 
@@ -79,7 +79,7 @@ class Category {
        /**
         * Factory function.
         *
-        * @param array $name A category name (no "Category:" prefix).  It need
+        * @param $name Array: A category name (no "Category:" prefix).  It need
         *   not be normalized, with spaces replaced by underscores.
         * @return mixed Category, or false on a totally invalid name
         */
@@ -99,8 +99,8 @@ class Category {
        /**
         * Factory function.
         *
-        * @param array $title Title for the category page
-        * @return mixed Category, or false on a totally invalid name
+        * @param $title Title for the category page
+        * @return Mixed: category, or false on a totally invalid name
         */
        public static function newFromTitle( $title ) {
                $cat = new self();
@@ -114,7 +114,7 @@ class Category {
        /**
         * Factory function.
         *
-        * @param array $id A category id
+        * @param $id Integer: a category id
         * @return Category
         */
        public static function newFromID( $id ) {
@@ -134,9 +134,9 @@ class Category {
         * @return Category
         */
        public static function newFromRow( $row, $title = null ) {
+               $cat = new self();
                $cat->mTitle = $title;
 
-               $cat = new self();
 
                # NOTE: the row often results from a LEFT JOIN on categorylinks. This may result in 
                #       all the cat_xxx fields being null, if the category page exists, but nothing
@@ -192,6 +192,33 @@ class Category {
                return $this->mTitle;
        }
 
+       /**
+        * Fetch a TitleArray of up to $limit category members, beginning after the
+        * category sort key $offset.
+        * @param $limit integer
+        * @param $offset string
+        * @return TitleArray object for category members.
+        */
+       public function getMembers( $limit = false, $offset = '' ) {
+               $dbr = wfGetDB( DB_SLAVE );
+
+               $conds = array( 'cl_to' => $this->getName(), 'cl_from = page_id' );
+               $options = array( 'ORDER BY' => 'cl_sortkey' );
+               if( $limit ) $options[ 'LIMIT' ] = $limit;
+               if( $offset !== '' ) $conds[] = 'cl_sortkey > ' . $dbr->addQuotes( $offset );
+
+               return TitleArray::newFromResult(
+                       $dbr->select(
+                               array( 'page', 'categorylinks' ),
+                               array( 'page_id', 'page_namespace','page_title', 'page_len',
+                                       'page_is_redirect', 'page_latest' ),
+                               $conds,
+                               __METHOD__,
+                               $options
+                       )
+               );
+       }
+
        /** Generic accessor */
        private function getX( $key ) {
                if( !$this->initialize() ) {
@@ -228,7 +255,7 @@ class Category {
                }
 
                $cond1 = $dbw->conditional( 'page_namespace='.NS_CATEGORY, 1, 'NULL' );
-               $cond2 = $dbw->conditional( 'page_namespace='.NS_IMAGE, 1, 'NULL' );
+               $cond2 = $dbw->conditional( 'page_namespace='.NS_FILE, 1, 'NULL' );
                $result = $dbw->selectRow(
                        array( 'categorylinks', 'page' ),
                        array( 'COUNT(*) AS pages',