X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FCategory.php;h=78567adddca52a6abe2f98f2337b31f7934a79e9;hb=08710fc1d13201f84f2966c205d8b2bb2663306e;hp=43864914e448c382fa9cbf2038cec61f46fb64fb;hpb=417f9de04e6a167879e6f4079c4fe4d6e2561dd2;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Category.php b/includes/Category.php index 43864914e4..78567adddc 100644 --- a/includes/Category.php +++ b/includes/Category.php @@ -1,6 +1,8 @@ mTitle ) { + # If there is a title object but no record in the category table, treat this as an empty category + $this->mID = false; + $this->mName = $this->mTitle->getDBKey(); + $this->mPages = 0; + $this->mSubcats = 0; + $this->mFiles = 0; + + return true; + } else { + return false; # Fail + } } $this->mID = $row->cat_id; $this->mName = $row->cat_title; @@ -68,7 +81,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 */ @@ -88,8 +101,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(); @@ -103,7 +116,7 @@ class Category { /** * Factory function. * - * @param array $id A category id + * @param $id Integer: a category id * @return Category */ public static function newFromID( $id ) { @@ -123,9 +136,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 @@ -181,6 +194,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() ) { @@ -217,7 +257,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',