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
|
2012-05-21 19:56:04 +00:00
|
|
|
/**
|
|
|
|
|
* Representation for a category.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* 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.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @author Simetrical
|
|
|
|
|
*/
|
|
|
|
|
|
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
|
|
|
/**
|
2010-02-14 22:07:30 +00:00
|
|
|
* Category objects are immutable, strictly speaking. If you call methods that change the database,
|
2008-11-19 00:02:23 +00:00
|
|
|
* 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
|
|
|
*
|
2014-03-23 01:28:57 +00:00
|
|
|
* @todo Move some stuff from CategoryPage.php to here, and use that.
|
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
|
|
|
class Category {
|
|
|
|
|
/** Name of the category, normalized to DB-key form */
|
|
|
|
|
private $mName = null;
|
|
|
|
|
private $mID = null;
|
2011-03-08 20:17:48 +00:00
|
|
|
/**
|
|
|
|
|
* Category page title
|
|
|
|
|
* @var Title
|
|
|
|
|
*/
|
2008-06-30 14:06:36 +00:00
|
|
|
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
|
|
|
|
2013-04-11 05:29:05 +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.
|
2012-10-07 23:35:26 +00:00
|
|
|
* @throws MWException
|
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 bool True on success, false on failure.
|
|
|
|
|
*/
|
|
|
|
|
protected function initialize() {
|
2010-02-14 22:07:30 +00:00
|
|
|
if ( $this->mName === null && $this->mID === null ) {
|
|
|
|
|
throw new MWException( __METHOD__ . ' has both names and IDs null' );
|
|
|
|
|
} elseif ( $this->mID === null ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$where = [ 'cat_title' => $this->mName ];
|
2010-02-14 22:07:30 +00:00
|
|
|
} elseif ( $this->mName === null ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$where = [ '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;
|
|
|
|
|
}
|
2012-10-08 13:44:44 +00:00
|
|
|
|
2016-09-05 19:55:19 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
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',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'cat_id', 'cat_title', 'cat_pages', 'cat_subcats', '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
|
|
|
$where,
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
2010-02-14 22:07:30 +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 ) {
|
2014-03-23 01:28:57 +00:00
|
|
|
# If there is a title object but no record in the category table,
|
|
|
|
|
# treat this as an empty category.
|
2013-02-03 20:05:24 +00:00
|
|
|
$this->mID = false;
|
|
|
|
|
$this->mName = $this->mTitle->getDBkey();
|
|
|
|
|
$this->mPages = 0;
|
2008-07-01 20:49:23 +00:00
|
|
|
$this->mSubcats = 0;
|
2013-02-03 20:05:24 +00:00
|
|
|
$this->mFiles = 0;
|
2008-07-01 20:49:23 +00:00
|
|
|
|
2016-07-13 15:30:37 +00:00
|
|
|
# If the title exists, call refreshCounts to add a row for it.
|
|
|
|
|
if ( $this->mTitle->exists() ) {
|
|
|
|
|
DeferredUpdates::addCallableUpdate( [ $this, 'refreshCounts' ] );
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-01 20:49:23 +00:00
|
|
|
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
|
|
|
}
|
2010-02-14 22:07:30 +00:00
|
|
|
|
2013-02-03 20:05:24 +00:00
|
|
|
$this->mID = $row->cat_id;
|
|
|
|
|
$this->mName = $row->cat_title;
|
|
|
|
|
$this->mPages = $row->cat_pages;
|
2008-05-22 17:24:46 +00:00
|
|
|
$this->mSubcats = $row->cat_subcats;
|
2013-02-03 20:05:24 +00:00
|
|
|
$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
|
|
|
|
2017-02-20 22:44:19 +00:00
|
|
|
# (T15683) If the count is negative, then 1) it's obviously wrong
|
2008-05-22 17:24:46 +00:00
|
|
|
# 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.
|
2010-02-14 22:07:30 +00:00
|
|
|
if ( $this->mPages < 0 || $this->mSubcats < 0 || $this->mFiles < 0 ) {
|
2016-06-03 05:07:58 +00:00
|
|
|
$this->mPages = max( $this->mPages, 0 );
|
|
|
|
|
$this->mSubcats = max( $this->mSubcats, 0 );
|
|
|
|
|
$this->mFiles = max( $this->mFiles, 0 );
|
|
|
|
|
|
|
|
|
|
DeferredUpdates::addCallableUpdate( [ $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.
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param array $name A category name (no "Category:" prefix). It need
|
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
|
|
|
* 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 );
|
2010-02-14 22:07:30 +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;
|
2009-05-24 08:29:10 +00:00
|
|
|
$cat->mName = $title->getDBkey();
|
2008-06-30 14:06:36 +00:00
|
|
|
|
|
|
|
|
return $cat;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Factory function.
|
|
|
|
|
*
|
2014-04-20 19:16:57 +00:00
|
|
|
* @param Title $title Title for the category page
|
|
|
|
|
* @return Category|bool On a totally invalid name
|
2008-06-30 14:06:36 +00:00
|
|
|
*/
|
|
|
|
|
public static function newFromTitle( $title ) {
|
|
|
|
|
$cat = new self();
|
|
|
|
|
|
|
|
|
|
$cat->mTitle = $title;
|
2009-05-24 08:29:10 +00:00
|
|
|
$cat->mName = $title->getDBkey();
|
2008-05-22 17:24:46 +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 $cat;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Factory function.
|
|
|
|
|
*
|
2014-04-20 19:16:57 +00:00
|
|
|
* @param int $id A category 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 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
|
|
|
|
|
*
|
2014-04-20 19:16:57 +00:00
|
|
|
* @param object $row Result set row, must contain the cat_xxx fields. If the
|
2014-03-23 01:28:57 +00:00
|
|
|
* 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.
|
2014-04-20 19:16:57 +00:00
|
|
|
* @param Title $title Optional title object for the category represented by
|
2014-03-23 01:28:57 +00:00
|
|
|
* the given row. May be provided if it is already known, to avoid having
|
|
|
|
|
* to re-create a title object later.
|
2016-12-08 05:04:53 +00:00
|
|
|
* @return Category|false
|
2008-06-30 14:06:36 +00:00
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
|
|
2010-02-14 22:07:30 +00:00
|
|
|
# NOTE: the row often results from a LEFT JOIN on categorylinks. This may result in
|
2008-06-30 14:06:36 +00:00
|
|
|
# all the cat_xxx fields being null, if the category page exists, but nothing
|
2013-03-13 07:42:41 +00:00
|
|
|
# was ever added to the category. This case should be treated link an empty
|
2008-06-30 14:06:36 +00:00
|
|
|
# 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 {
|
2014-03-23 01:28:57 +00:00
|
|
|
# if we have a title object, fetch the category name from there
|
|
|
|
|
$cat->mName = $title->getDBkey();
|
2008-06-30 14:06:36 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-03 20:05:24 +00:00
|
|
|
$cat->mID = false;
|
2008-06-30 14:06:36 +00:00
|
|
|
$cat->mSubcats = 0;
|
2013-02-03 20:05:24 +00:00
|
|
|
$cat->mPages = 0;
|
|
|
|
|
$cat->mFiles = 0;
|
2008-06-30 14:06:36 +00:00
|
|
|
} else {
|
2013-02-03 20:05:24 +00:00
|
|
|
$cat->mName = $row->cat_title;
|
|
|
|
|
$cat->mID = $row->cat_id;
|
2008-06-30 14:06:36 +00:00
|
|
|
$cat->mSubcats = $row->cat_subcats;
|
2013-02-03 20:05:24 +00:00
|
|
|
$cat->mPages = $row->cat_pages;
|
|
|
|
|
$cat->mFiles = $row->cat_files;
|
2008-06-30 14:06:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $cat;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-15 20:13:54 +00:00
|
|
|
/**
|
|
|
|
|
* @return mixed DB key name, or false on failure
|
|
|
|
|
*/
|
2012-10-08 13:44:44 +00:00
|
|
|
public function getName() {
|
|
|
|
|
return $this->getX( 'mName' );
|
|
|
|
|
}
|
2010-02-14 22:07:30 +00:00
|
|
|
|
2014-03-15 20:13:54 +00:00
|
|
|
/**
|
|
|
|
|
* @return mixed Category ID, or false on failure
|
|
|
|
|
*/
|
2012-10-08 13:44:44 +00:00
|
|
|
public function getID() {
|
|
|
|
|
return $this->getX( 'mID' );
|
|
|
|
|
}
|
2010-02-14 22:07:30 +00:00
|
|
|
|
2014-03-15 20:13:54 +00:00
|
|
|
/**
|
|
|
|
|
* @return mixed Total number of member pages, or false on failure
|
|
|
|
|
*/
|
2012-10-08 13:44:44 +00:00
|
|
|
public function getPageCount() {
|
|
|
|
|
return $this->getX( 'mPages' );
|
|
|
|
|
}
|
2010-02-14 22:07:30 +00:00
|
|
|
|
2014-03-15 20:13:54 +00:00
|
|
|
/**
|
|
|
|
|
* @return mixed Number of subcategories, or false on failure
|
|
|
|
|
*/
|
2012-10-08 13:44:44 +00:00
|
|
|
public function getSubcatCount() {
|
|
|
|
|
return $this->getX( 'mSubcats' );
|
|
|
|
|
}
|
2010-02-14 22:07:30 +00:00
|
|
|
|
2014-03-15 20:13:54 +00:00
|
|
|
/**
|
|
|
|
|
* @return mixed Number of member files, or false on failure
|
|
|
|
|
*/
|
2012-10-08 13:44:44 +00:00
|
|
|
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
|
|
|
/**
|
2012-02-09 17:42:35 +00:00
|
|
|
* @return Title|bool Title for this category, or false on failure.
|
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
|
|
|
*/
|
|
|
|
|
public function getTitle() {
|
2012-10-08 13:44:44 +00:00
|
|
|
if ( $this->mTitle ) {
|
|
|
|
|
return $this->mTitle;
|
|
|
|
|
}
|
2010-02-14 22:07:30 +00:00
|
|
|
|
|
|
|
|
if ( !$this->initialize() ) {
|
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
|
|
|
|
|
|
|
|
$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
|
|
|
}
|
|
|
|
|
|
2008-07-28 19:02:40 +00:00
|
|
|
/**
|
|
|
|
|
* Fetch a TitleArray of up to $limit category members, beginning after the
|
|
|
|
|
* category sort key $offset.
|
2014-04-20 19:16:57 +00:00
|
|
|
* @param int $limit
|
|
|
|
|
* @param string $offset
|
|
|
|
|
* @return TitleArray TitleArray object for category members.
|
2008-07-28 19:02:40 +00:00
|
|
|
*/
|
|
|
|
|
public function getMembers( $limit = false, $offset = '' ) {
|
2012-10-08 13:44:44 +00:00
|
|
|
|
2016-09-05 19:55:19 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2008-07-28 19:02:40 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$conds = [ 'cl_to' => $this->getName(), 'cl_from = page_id' ];
|
|
|
|
|
$options = [ 'ORDER BY' => 'cl_sortkey' ];
|
2010-02-14 22:07:30 +00:00
|
|
|
|
|
|
|
|
if ( $limit ) {
|
2012-10-08 13:44:44 +00:00
|
|
|
$options['LIMIT'] = $limit;
|
2010-02-14 22:07:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $offset !== '' ) {
|
|
|
|
|
$conds[] = 'cl_sortkey > ' . $dbr->addQuotes( $offset );
|
|
|
|
|
}
|
2008-07-28 19:02:40 +00:00
|
|
|
|
2012-10-08 13:44:44 +00:00
|
|
|
$result = TitleArray::newFromResult(
|
2008-07-28 19:02:40 +00:00
|
|
|
$dbr->select(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'page', 'categorylinks' ],
|
|
|
|
|
[ 'page_id', 'page_namespace', 'page_title', 'page_len',
|
|
|
|
|
'page_is_redirect', 'page_latest' ],
|
2008-07-28 19:02:40 +00:00
|
|
|
$conds,
|
|
|
|
|
__METHOD__,
|
|
|
|
|
$options
|
|
|
|
|
)
|
|
|
|
|
);
|
2012-10-08 13:44:44 +00:00
|
|
|
|
|
|
|
|
return $result;
|
2008-07-28 19:02:40 +00:00
|
|
|
}
|
|
|
|
|
|
2012-02-09 21:33:27 +00:00
|
|
|
/**
|
|
|
|
|
* Generic accessor
|
2014-08-14 18:22:52 +00:00
|
|
|
* @param string $key
|
2012-02-09 21:33:27 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
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
|
|
|
private function getX( $key ) {
|
2010-02-14 22:07:30 +00:00
|
|
|
if ( !$this->initialize() ) {
|
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;
|
|
|
|
|
}
|
2012-10-08 13:44:44 +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() {
|
2010-02-14 22:07:30 +00:00
|
|
|
if ( wfReadOnly() ) {
|
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;
|
|
|
|
|
}
|
2010-09-07 20:11:53 +00:00
|
|
|
|
2015-08-28 07:57:01 +00:00
|
|
|
# If we have just a category name, find out whether there is an
|
|
|
|
|
# existing row. Or if we have just an ID, get the name, because
|
|
|
|
|
# that's what categorylinks uses.
|
|
|
|
|
if ( !$this->initialize() ) {
|
|
|
|
|
return false;
|
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
|
|
|
}
|
|
|
|
|
|
2010-09-07 20:11:53 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
2017-04-20 03:43:56 +00:00
|
|
|
# Avoid excess contention on the same category (T162121)
|
|
|
|
|
$name = __METHOD__ . ':' . md5( $this->mName );
|
|
|
|
|
$scopedLock = $dbw->getScopedLockAndFlush( $name, __METHOD__, 1 );
|
|
|
|
|
if ( !$scopedLock ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-25 01:07:55 +00:00
|
|
|
$dbw->startAtomic( __METHOD__ );
|
2010-09-07 20:11:53 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$cond1 = $dbw->conditional( [ 'page_namespace' => NS_CATEGORY ], 1, 'NULL' );
|
|
|
|
|
$cond2 = $dbw->conditional( [ 'page_namespace' => NS_FILE ], 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(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'categorylinks', 'page' ],
|
|
|
|
|
[ 'pages' => 'COUNT(*)',
|
2012-10-08 13:44:44 +00:00
|
|
|
'subcats' => "COUNT($cond1)",
|
|
|
|
|
'files' => "COUNT($cond2)"
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[ '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__,
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'LOCK IN SHARE MODE' ]
|
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
|
|
|
);
|
2015-08-28 07:57:01 +00:00
|
|
|
|
2016-07-13 15:30:37 +00:00
|
|
|
$shouldExist = $result->pages > 0 || $this->getTitle()->exists();
|
|
|
|
|
|
2015-10-29 21:36:29 +00:00
|
|
|
if ( $this->mID ) {
|
2016-07-13 15:30:37 +00:00
|
|
|
if ( $shouldExist ) {
|
|
|
|
|
# The category row already exists, so do a plain UPDATE instead
|
|
|
|
|
# of INSERT...ON DUPLICATE KEY UPDATE to avoid creating a gap
|
|
|
|
|
# in the cat_id sequence. The row may or may not be "affected".
|
|
|
|
|
$dbw->update(
|
|
|
|
|
'category',
|
|
|
|
|
[
|
|
|
|
|
'cat_pages' => $result->pages,
|
|
|
|
|
'cat_subcats' => $result->subcats,
|
|
|
|
|
'cat_files' => $result->files
|
|
|
|
|
],
|
|
|
|
|
[ 'cat_title' => $this->mName ],
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
# The category is empty and has no description page, delete it
|
|
|
|
|
$dbw->delete(
|
|
|
|
|
'category',
|
|
|
|
|
[ 'cat_title' => $this->mName ],
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
|
|
|
|
$this->mID = false;
|
|
|
|
|
}
|
|
|
|
|
} elseif ( $shouldExist ) {
|
|
|
|
|
# The category row doesn't exist but should, so create it. Use
|
|
|
|
|
# upsert in case of races.
|
2015-08-28 07:57:01 +00:00
|
|
|
$dbw->upsert(
|
|
|
|
|
'category',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2015-08-28 07:57:01 +00:00
|
|
|
'cat_title' => $this->mName,
|
|
|
|
|
'cat_pages' => $result->pages,
|
|
|
|
|
'cat_subcats' => $result->subcats,
|
|
|
|
|
'cat_files' => $result->files
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[ 'cat_title' ],
|
|
|
|
|
[
|
2015-08-28 07:57:01 +00:00
|
|
|
'cat_pages' => $result->pages,
|
|
|
|
|
'cat_subcats' => $result->subcats,
|
|
|
|
|
'cat_files' => $result->files
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2015-08-28 07:57:01 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
2016-07-13 15:30:37 +00:00
|
|
|
// @todo: Should we update $this->mID here? Or not since Category
|
|
|
|
|
// objects tend to be short lived enough to not matter?
|
2015-08-28 07:57:01 +00:00
|
|
|
}
|
2015-08-28 07:57:01 +00:00
|
|
|
|
2014-06-25 01:07:55 +00:00
|
|
|
$dbw->endAtomic( __METHOD__ );
|
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
|
|
|
|
|
|
|
|
# Now we should update our local counts.
|
2013-02-03 20:05:24 +00:00
|
|
|
$this->mPages = $result->pages;
|
2008-05-22 17:24:46 +00:00
|
|
|
$this->mSubcats = $result->subcats;
|
2013-02-03 20:05:24 +00:00
|
|
|
$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
|
|
|
|
2015-08-28 07:57:01 +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
|
|
|
}
|
|
|
|
|
}
|