* @return mixed Normalized name, or false if the name was invalid.
*/
private static function setNamesCallback( $name ) {
- $title = Title::newFromText( $name );
+ $title = Title::newFromText( "Category:$name" );
if( !is_object( $title ) ) {
return false;
}
public function getSubcatCount() { return $this->getX( 'mSubcats' ); }
/** @return mixed Number of member files, or false on failure */
public function getFileCount() { return $this->getX( 'mFiles' ); }
+
/**
* This is not implemented in the base class, because arrays of Titles are
* evil.
if( !$this->initialize() ) {
return false;
}
- # FIXME is there a better way to do this?
- return Title::newFromText( "Category:{$this->mNames[0]}" );
+ return Title::makeTitleSafe( NS_CATEGORY, $this->mNames[0] );
}
/** Generic accessor */
*/
protected function initialize() {
parent::initialize();
+
+ # (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] < 0 || $this->mSubcats[0] < 0 ||
+ $this->mFiles[0] < 0 ) {
+ $this->refreshCounts();
+ }
+
if( count( $this->mNames ) != 1 || count( $this->mIDs ) != 1 ) {
return false;
}
);
}
+ $cond1 = $dbw->conditional( 'page_namespace='.NS_CATEGORY, 1, 'NULL' );
+ $cond2 = $dbw->conditional( 'page_namespace='.NS_IMAGE, 1, 'NULL' );
$result = $dbw->selectRow(
array( 'categorylinks', 'page' ),
array( 'COUNT(*) AS pages',
- 'COUNT(IF(page_namespace='.NS_CATEGORY.',1,NULL)) AS subcats',
- 'COUNT(IF(page_namespace='.NS_IMAGE.',1,NULL)) AS files'
+ "COUNT($cond1) AS subcats",
+ "COUNT($cond2) AS files"
),
array( 'cl_to' => $this->mNames[0], 'page_id = cl_from' ),
__METHOD__,