This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2008-05-22 17:24:46 +00:00
|
|
|
* 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.
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
*
|
|
|
|
|
* TODO: Move some stuff from CategoryPage.php to here, and use that.
|
|
|
|
|
*
|
|
|
|
|
* @author Simetrical
|
|
|
|
|
*/
|
|
|
|
|
|
2008-05-22 17:24:46 +00:00
|
|
|
class Category {
|
|
|
|
|
/** Name of the category, normalized to DB-key form */
|
|
|
|
|
private $mName = null;
|
|
|
|
|
private $mID = null;
|
2008-06-30 14:06:36 +00:00
|
|
|
/** Category page title */
|
|
|
|
|
private $mTitle = null;
|
2008-05-22 17:24:46 +00:00
|
|
|
/** Counts of membership (cat_pages, cat_subcats, cat_files) */
|
|
|
|
|
private $mPages = null, $mSubcats = null, $mFiles = null;
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
|
2008-05-22 17:24:46 +00:00
|
|
|
private function __construct() {}
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set up all member variables using a database query.
|
|
|
|
|
* @return bool True on success, false on failure.
|
|
|
|
|
*/
|
|
|
|
|
protected function initialize() {
|
2008-06-30 14:06:36 +00:00
|
|
|
if ( $this->mName === null && $this->mTitle )
|
|
|
|
|
$this->mName = $title->getDBKey();
|
|
|
|
|
|
2008-05-22 17:24:46 +00:00
|
|
|
if( $this->mName === null && $this->mID === null ) {
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
throw new MWException( __METHOD__.' has both names and IDs null' );
|
2008-06-30 14:06:36 +00:00
|
|
|
} elseif( $this->mID === null ) {
|
2008-05-22 17:24:46 +00:00
|
|
|
$where = array( 'cat_title' => $this->mName );
|
|
|
|
|
} elseif( $this->mName === null ) {
|
|
|
|
|
$where = array( 'cat_id' => $this->mID );
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
} else {
|
|
|
|
|
# Already initialized
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2008-06-30 14:06:36 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2008-05-22 17:24:46 +00:00
|
|
|
$row = $dbr->selectRow(
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
'category',
|
|
|
|
|
array( 'cat_id', 'cat_title', 'cat_pages', 'cat_subcats',
|
|
|
|
|
'cat_files' ),
|
|
|
|
|
$where,
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
2008-05-22 17:24:46 +00:00
|
|
|
if( !$row ) {
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
# Okay, there were no contents. Nothing to initialize.
|
2008-07-01 20:49:23 +00:00
|
|
|
if ( $this->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 is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
}
|
2008-05-22 17:24:46 +00:00
|
|
|
$this->mID = $row->cat_id;
|
|
|
|
|
$this->mName = $row->cat_title;
|
|
|
|
|
$this->mPages = $row->cat_pages;
|
|
|
|
|
$this->mSubcats = $row->cat_subcats;
|
|
|
|
|
$this->mFiles = $row->cat_files;
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
|
2008-05-22 17:24:46 +00:00
|
|
|
# (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 ) {
|
|
|
|
|
$this->refreshCounts();
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
}
|
|
|
|
|
|
2008-05-22 17:24:46 +00:00
|
|
|
return true;
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Factory function.
|
|
|
|
|
*
|
|
|
|
|
* @param array $name 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
|
|
|
|
|
*/
|
|
|
|
|
public static function newFromName( $name ) {
|
|
|
|
|
$cat = new self();
|
2008-06-30 14:06:36 +00:00
|
|
|
$title = Title::makeTitleSafe( NS_CATEGORY, $name );
|
2008-05-22 17:24:46 +00:00
|
|
|
if( !is_object( $title ) ) {
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2008-06-30 14:06:36 +00:00
|
|
|
|
|
|
|
|
$cat->mTitle = $title;
|
|
|
|
|
$cat->mName = $title->getDBKey();
|
|
|
|
|
|
|
|
|
|
return $cat;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Factory function.
|
|
|
|
|
*
|
|
|
|
|
* @param array $title Title for the category page
|
|
|
|
|
* @return mixed Category, or false on a totally invalid name
|
|
|
|
|
*/
|
|
|
|
|
public static function newFromTitle( $title ) {
|
|
|
|
|
$cat = new self();
|
|
|
|
|
|
|
|
|
|
$cat->mTitle = $title;
|
2008-05-22 17:24:46 +00:00
|
|
|
$cat->mName = $title->getDBKey();
|
|
|
|
|
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
return $cat;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Factory function.
|
|
|
|
|
*
|
|
|
|
|
* @param array $id A category id
|
|
|
|
|
* @return Category
|
|
|
|
|
*/
|
2008-05-22 17:24:46 +00:00
|
|
|
public static function newFromID( $id ) {
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
$cat = new self();
|
2008-05-22 17:24:46 +00:00
|
|
|
$cat->mID = intval( $id );
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
return $cat;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-30 14:06:36 +00:00
|
|
|
/**
|
|
|
|
|
* Factory function, for constructing a Category object from a result set
|
|
|
|
|
*
|
|
|
|
|
* @param $row result set row, must contain the cat_xxx fields. If the fields are null,
|
|
|
|
|
* the resulting Category object will represent an empty category if a title object
|
|
|
|
|
* was given. If the fields are null and no title was given, this method fails and returns false.
|
|
|
|
|
* @param $title optional title object for the category represented by the given row.
|
|
|
|
|
* May be provided if it is already known, to avoid having to re-create a title object later.
|
|
|
|
|
* @return Category
|
|
|
|
|
*/
|
|
|
|
|
public static function newFromRow( $row, $title = null ) {
|
2008-07-05 13:13:29 +00:00
|
|
|
$cat = new self();
|
2008-06-30 14:06:36 +00:00
|
|
|
$cat->mTitle = $title;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
# was ever added to the category. This case should be treated linke an empty
|
|
|
|
|
# category, if possible.
|
|
|
|
|
|
|
|
|
|
if ( $row->cat_title === null ) {
|
|
|
|
|
if ( $title === null ) {
|
|
|
|
|
# the name is probably somewhere in the row, for example as page_title,
|
|
|
|
|
# but we can't know that here...
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
$cat->mName = $title->getDBKey(); # if we have a title object, fetch the category name from there
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$cat->mID = false;
|
|
|
|
|
$cat->mSubcats = 0;
|
|
|
|
|
$cat->mPages = 0;
|
|
|
|
|
$cat->mFiles = 0;
|
|
|
|
|
} else {
|
|
|
|
|
$cat->mName = $row->cat_title;
|
|
|
|
|
$cat->mID = $row->cat_id;
|
|
|
|
|
$cat->mSubcats = $row->cat_subcats;
|
|
|
|
|
$cat->mPages = $row->cat_pages;
|
|
|
|
|
$cat->mFiles = $row->cat_files;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $cat;
|
|
|
|
|
}
|
|
|
|
|
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
/** @return mixed DB key name, or false on failure */
|
2008-05-22 17:24:46 +00:00
|
|
|
public function getName() { return $this->getX( 'mName' ); }
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
/** @return mixed Category ID, or false on failure */
|
2008-05-22 17:24:46 +00:00
|
|
|
public function getID() { return $this->getX( 'mID' ); }
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
/** @return mixed Total number of member pages, or false on failure */
|
|
|
|
|
public function getPageCount() { return $this->getX( 'mPages' ); }
|
|
|
|
|
/** @return mixed Number of subcategories, or false on failure */
|
|
|
|
|
public function getSubcatCount() { return $this->getX( 'mSubcats' ); }
|
|
|
|
|
/** @return mixed Number of member files, or false on failure */
|
|
|
|
|
public function getFileCount() { return $this->getX( 'mFiles' ); }
|
2008-03-20 16:39:02 +00:00
|
|
|
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
/**
|
|
|
|
|
* @return mixed The Title for this category, or false on failure.
|
|
|
|
|
*/
|
|
|
|
|
public function getTitle() {
|
2008-06-30 14:06:36 +00:00
|
|
|
if( $this->mTitle ) return $this->mTitle;
|
|
|
|
|
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
if( !$this->initialize() ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2008-06-30 14:06:36 +00:00
|
|
|
|
|
|
|
|
$this->mTitle = Title::makeTitleSafe( NS_CATEGORY, $this->mName );
|
|
|
|
|
return $this->mTitle;
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Generic accessor */
|
|
|
|
|
private function getX( $key ) {
|
|
|
|
|
if( !$this->initialize() ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2008-05-22 17:24:46 +00:00
|
|
|
return $this->{$key};
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Refresh the counts for this category.
|
|
|
|
|
*
|
|
|
|
|
* @return bool True on success, false on failure
|
|
|
|
|
*/
|
|
|
|
|
public function refreshCounts() {
|
|
|
|
|
if( wfReadOnly() ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
|
|
|
|
$dbw->begin();
|
|
|
|
|
# Note, we must use names for this, since categorylinks does.
|
2008-05-22 17:24:46 +00:00
|
|
|
if( $this->mName === null ) {
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
if( !$this->initialize() ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
# Let's be sure that the row exists in the table. We don't need to
|
|
|
|
|
# do this if we got the row from the table in initialization!
|
|
|
|
|
$dbw->insert(
|
|
|
|
|
'category',
|
2008-05-22 17:24:46 +00:00
|
|
|
array( 'cat_title' => $this->mName ),
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
__METHOD__,
|
|
|
|
|
'IGNORE'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-19 13:15:09 +00:00
|
|
|
$cond1 = $dbw->conditional( 'page_namespace='.NS_CATEGORY, 1, 'NULL' );
|
|
|
|
|
$cond2 = $dbw->conditional( 'page_namespace='.NS_IMAGE, 1, 'NULL' );
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
$result = $dbw->selectRow(
|
|
|
|
|
array( 'categorylinks', 'page' ),
|
|
|
|
|
array( 'COUNT(*) AS pages',
|
2008-03-19 13:15:09 +00:00
|
|
|
"COUNT($cond1) AS subcats",
|
|
|
|
|
"COUNT($cond2) AS files"
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
),
|
2008-05-22 17:24:46 +00:00
|
|
|
array( 'cl_to' => $this->mName, 'page_id = cl_from' ),
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
__METHOD__,
|
|
|
|
|
'LOCK IN SHARE MODE'
|
|
|
|
|
);
|
|
|
|
|
$ret = $dbw->update(
|
|
|
|
|
'category',
|
|
|
|
|
array(
|
|
|
|
|
'cat_pages' => $result->pages,
|
|
|
|
|
'cat_subcats' => $result->subcats,
|
|
|
|
|
'cat_files' => $result->files
|
|
|
|
|
),
|
2008-05-22 17:24:46 +00:00
|
|
|
array( 'cat_title' => $this->mName ),
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
|
|
|
|
$dbw->commit();
|
|
|
|
|
|
|
|
|
|
# Now we should update our local counts.
|
2008-05-22 17:24:46 +00:00
|
|
|
$this->mPages = $result->pages;
|
|
|
|
|
$this->mSubcats = $result->subcats;
|
|
|
|
|
$this->mFiles = $result->files;
|
This is a schema change. It's only a table creation, but the table must be created on Wikimedia servers before this revision goes live. The maintenance script populateCategory.php should be run when convenient. If it's not run, there's only one substantial case where display will be harmed: the page of a category with more than 200 net pages added since the patch goes live will give an erroneously low count. In other cases category pages will just be better-worded, and it will recognize the count in the table is bogus.
* Adds Category and CategoryList classes to represent categories themselves.
* Adds a category table, giving each category a name, ID, and counts of all members, subcats only, and files.
* Adds a maintenance script to populate the category table efficiently. This script is careful to wait for slaves and should be safe to run on a live database. The maintenance script's includes file is called by update.php.
* Until the category table is populated, the patch handles weird category table rows gracefully. It detects whether they're obviously impossible, and if so, it outputs appropriate messages.
2008-03-18 00:17:28 +00:00
|
|
|
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
}
|