r37126 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37125‎ | r37126 | r37127 >
Date:19:06, 5 July 2008
Author:nicdumz
Status:old
Tags:
Comment:
Implementing basic naive category redirect handling :
* redirect=no is not yet handled for categories
* category counts only reflect inline membership
Modified paths:
  • /branches/category-redirects/includes/Article.php (modified) (history)
  • /branches/category-redirects/includes/Category.php (modified) (history)
  • /branches/category-redirects/includes/CategoryPage.php (modified) (history)
  • /branches/category-redirects/includes/Categoryfinder.php (modified) (history)
  • /branches/category-redirects/includes/HTMLCacheUpdate.php (modified) (history)
  • /branches/category-redirects/includes/Namespace.php (modified) (history)
  • /branches/category-redirects/includes/api/ApiQueryCategoryMembers.php (modified) (history)
  • /branches/category-redirects/includes/specials/SpecialExport.php (modified) (history)
  • /branches/category-redirects/includes/specials/SpecialMostlinkedcategories.php (modified) (history)
  • /branches/category-redirects/includes/specials/SpecialRecentchangeslinked.php (modified) (history)
  • /branches/category-redirects/includes/specials/SpecialUnusedcategories.php (modified) (history)
  • /branches/category-redirects/includes/specials/SpecialWantedcategories.php (modified) (history)

Diff [purge]

Index: branches/category-redirects/includes/api/ApiQueryCategoryMembers.php
@@ -79,17 +79,17 @@
8080 {
8181 $this->addOption('USE INDEX', 'cl_timestamp');
8282 // cl_timestamp will be added by addWhereRange() later
83 - $this->addOption('ORDER BY', 'cl_inline');
 83+ $this->addOption('ORDER BY', 'cl_target');
8484 }
8585 else
8686 {
8787 $dir = ($params['dir'] == 'desc' ? ' DESC' : '');
88 - $this->addOption('USE INDEX', 'cl_sortkey_inline');
89 - $this->addOption('ORDER BY', 'cl_inline, cl_sortkey' . $dir . ', cl_from' . $dir);
 88+ $this->addOption('USE INDEX', 'cl_sortkey_target');
 89+ $this->addOption('ORDER BY', 'cl_target, cl_sortkey' . $dir . ', cl_from' . $dir);
9090 }
9191
9292 $this->addWhere('cl_from=page_id');
93 - $this->addWhere('cat_id=cl_inline');
 93+ $this->addWhere('cat_id=cl_target');
9494 $this->setContinuation($params['continue'], $params['dir']);
9595 $this->addWhereFld('cat_title', $categoryTitle->getDBkey());
9696 $this->addWhereFld('page_namespace', $params['namespace']);
Index: branches/category-redirects/includes/HTMLCacheUpdate.php
@@ -122,7 +122,7 @@
123123 case 'imagelinks':
124124 return array( 'il_to' => $this->mTitle->getDBkey() );
125125 case 'categorylinks':
126 - return array( 'cat_title' => $this->mTitle->getDBkey(), 'cat_id=cl_inline' );
 126+ return array( 'cat_title' => $this->mTitle->getDBkey(), 'cat_id=cl_target' );
127127 }
128128 throw new MWException( 'Invalid table type in ' . __CLASS__ );
129129 }
Index: branches/category-redirects/includes/Namespace.php
@@ -53,7 +53,7 @@
5454 */
5555 public static function isMovable( $index ) {
5656 global $wgAllowImageMoving;
57 - return !( $index < NS_MAIN || ($index == NS_IMAGE && !$wgAllowImageMoving) || $index == NS_CATEGORY );
 57+ return !( $index < NS_MAIN || ($index == NS_IMAGE && !$wgAllowImageMoving) );
5858 }
5959
6060 /**
Index: branches/category-redirects/includes/specials/SpecialUnusedcategories.php
@@ -27,7 +27,7 @@
2828 {$NScat} as namespace, page_title as title, page_title as value
2929 FROM $page
3030 INNER JOIN $category ON cat_title=page_title
31 - LEFT JOIN $categorylinks ON cl_inline=cat_id
 31+ LEFT JOIN $categorylinks ON cl_target=cat_id
3232 WHERE cl_from IS NULL
3333 AND page_namespace = {$NScat}
3434 AND page_is_redirect = 0";
Index: branches/category-redirects/includes/specials/SpecialExport.php
@@ -31,7 +31,7 @@
3232 list( $page, $categorylinks, $cat ) = $dbr->tableNamesN( 'page', 'categorylinks', 'category' );
3333 $sql = "SELECT page_namespace, page_title FROM $page" .
3434 "JOIN $categorylinks ON page_id=cl_from " .
35 - "JOIN $cat ON cl_inline=cat_id " .
 35+ "JOIN $cat ON cl_target=cat_id " .
3636 "WHERE cat_title = " . $dbr->addQuotes( $name );
3737
3838 $pages = array();
Index: branches/category-redirects/includes/specials/SpecialWantedcategories.php
@@ -41,7 +41,7 @@
4242 FROM $categorylinks, $category
4343 LEFT JOIN $page ON cat_title = page_title AND page_namespace = ". NS_CATEGORY ."
4444 WHERE page_title IS NULL
45 - AND cat_id=cl_inline
 45+ AND cat_id=cl_target
4646 GROUP BY 1,2,3
4747 ";
4848 }
Index: branches/category-redirects/includes/specials/SpecialMostlinkedcategories.php
@@ -31,7 +31,7 @@
3232 cat_title as title,
3333 COUNT(*) as value
3434 FROM $categorylinks, $category
35 - WHERE cat_id=cl_inline
 35+ WHERE cat_id=cl_target
3636 GROUP BY 1,2,3
3737 ";
3838 }
Index: branches/category-redirects/includes/specials/SpecialRecentchangeslinked.php
@@ -69,7 +69,7 @@
7070 $tables[] = 'category';
7171 $conds['cat_title'] = $title->getDBkey();
7272 $join_conds['categorylinks'] = array( 'LEFT JOIN', 'cl_from=rc_cur_id' );
73 - $join_conds['category'] = array( 'INNER JOIN', 'cat_id=cl_inline');
 73+ $join_conds['category'] = array( 'INNER JOIN', 'cat_id=cl_target');
7474 } else {
7575 if( $showlinkedto ) {
7676 if( $title->getNamespace() == NS_TEMPLATE ){
Index: branches/category-redirects/includes/Category.php
@@ -11,6 +11,7 @@
1212 /** Name of the category, normalized to DB-key form */
1313 private $mName = null;
1414 private $mID = null;
 15+ private $mRedir = null;
1516 /** Category page title */
1617 private $mTitle = null;
1718 /** Counts of membership (cat_pages, cat_subcats, cat_files) */
@@ -39,7 +40,7 @@
4041 $dbr = wfGetDB( DB_SLAVE );
4142 $row = $dbr->selectRow(
4243 'category',
43 - array( 'cat_id', 'cat_title', 'cat_pages', 'cat_subcats',
 44+ array( 'cat_id', 'cat_title', 'cat_redir', 'cat_pages', 'cat_subcats',
4445 'cat_files' ),
4546 $where,
4647 __METHOD__
@@ -49,6 +50,7 @@
5051 if ( $this->mTitle ) {
5152 # If there is a title object but no record in the category table, treat this as an empty category
5253 $this->mID = false;
 54+ $this->mRedir = false;
5355 $this->mName = $this->mTitle->getDBKey();
5456 $this->mPages = 0;
5557 $this->mSubcats = 0;
@@ -60,6 +62,7 @@
6163 }
6264 }
6365 $this->mID = $row->cat_id;
 66+ $this->mRedir = $row->cat_redir;
6467 $this->mName = $row->cat_title;
6568 $this->mPages = $row->cat_pages;
6669 $this->mSubcats = $row->cat_subcats;
@@ -151,13 +154,15 @@
152155 $cat->mName = $title->getDBKey(); # if we have a title object, fetch the category name from there
153156 }
154157
155 - $cat->mID = false;
 158+ $cat->mID = false;
 159+ $cat->mRedir = false;
156160 $cat->mSubcats = 0;
157161 $cat->mPages = 0;
158162 $cat->mFiles = 0;
159163 } else {
160164 $cat->mName = $row->cat_title;
161165 $cat->mID = $row->cat_id;
 166+ $cat->mRedir = $row->cat_redir;
162167 $cat->mSubcats = $row->cat_subcats;
163168 $cat->mPages = $row->cat_pages;
164169 $cat->mFiles = $row->cat_files;
@@ -170,6 +175,8 @@
171176 public function getName() { return $this->getX( 'mName' ); }
172177 /** @return mixed Category ID, or false on failure */
173178 public function getID() { return $this->getX( 'mID' ); }
 179+ /** @return mixed Category redirect ID (may be null), or false on failure */
 180+ public function getRedir() { return $this->getX( 'mRedir' ); }
174181 /** @return mixed Total number of member pages, or false on failure */
175182 public function getPageCount() { return $this->getX( 'mPages' ); }
176183 /** @return mixed Number of subcategories, or false on failure */
@@ -234,7 +241,7 @@
235242 "COUNT($cond1) AS subcats",
236243 "COUNT($cond2) AS files"
237244 ),
238 - array( 'cl_inline' => $this->mID, 'page_id = cl_from' ),
 245+ array( 'cl_target' => $this->mID, 'page_id = cl_from' ),
239246 __METHOD__,
240247 'LOCK IN SHARE MODE'
241248 );
Index: branches/category-redirects/includes/Categoryfinder.php
@@ -140,7 +140,7 @@
141141 $res = $this->dbr->select(
142142 /* FROM */ array( 'categorylinks', 'category' ),
143143 /* SELECT */ array( 'cl_from', 'cat_title' ),
144 - /* WHERE */ array( 'cl_from' => $this->next, 'cl_inline=cat_id' ),
 144+ /* WHERE */ array( 'cl_from' => $this->next, 'cl_target=cat_id' ),
145145 $fname."-1"
146146 );
147147 while ( $o = $this->dbr->fetchObject( $res ) ) {
Index: branches/category-redirects/includes/CategoryPage.php
@@ -19,6 +19,7 @@
2020
2121 if ( isset( $diff ) && $diffOnly )
2222 return Article::view();
 23+
2324
2425 if(!wfRunHooks('CategoryPageView', array(&$this))) return;
2526
@@ -224,12 +225,12 @@
225226 $res = $dbr->select(
226227 array( 'page', 'categorylinks', 'category' ),
227228 array( 'page_title', 'page_namespace', 'page_len', 'page_is_redirect', 'cl_sortkey',
228 - 'cat_id', 'cat_title', 'cat_subcats', 'cat_pages', 'cat_files' ),
 229+ 'cat_id', 'cat_redir', 'cat_title', 'cat_subcats', 'cat_pages', 'cat_files' ),
229230 array( $pageCondition,
230 - 'cl_inline' => $this->cat->getID() ),
 231+ 'cl_target' => $this->cat->getID() ),
231232 __METHOD__,
232233 array( 'ORDER BY' => $this->flip ? 'cl_sortkey DESC' : 'cl_sortkey',
233 - 'USE INDEX' => array( 'categorylinks' => 'cl_sortkey_inline' ),
 234+ 'USE INDEX' => array( 'categorylinks' => 'cl_sortkey_target' ),
234235 'LIMIT' => $this->limit + 1 ),
235236 array( 'categorylinks' => array( 'INNER JOIN', 'cl_from = page_id' ),
236237 'category' => array( 'LEFT JOIN', 'cat_title = page_title AND page_namespace = ' . NS_CATEGORY ) ) );
@@ -248,7 +249,10 @@
249250
250251 if( $title->getNamespace() == NS_CATEGORY ) {
251252 $cat = Category::newFromRow( $x, $title );
252 - $this->addSubcategoryObject( $cat, $x->cl_sortkey, $x->page_len );
 253+ if ( $cat->getRedir() == null ) {
 254+ # Show only non-redirects
 255+ $this->addSubcategoryObject( $cat, $x->cl_sortkey, $x->page_len );
 256+ }
253257 } elseif( $this->showGallery && $title->getNamespace() == NS_IMAGE ) {
254258 $this->addImage( $title, $x->cl_sortkey, $x->page_len, $x->page_is_redirect );
255259 } else {
Index: branches/category-redirects/includes/Article.php
@@ -3302,7 +3302,7 @@
33033303 $res = $dbr->select( array( 'categorylinks', 'category', 'page_props', 'page' ),
33043304 array( 'cat_title' ),
33053305 array( 'cl_from' => $id, 'pp_page=page_id', 'pp_propname' => 'hiddencat',
3306 - 'page_namespace' => NS_CATEGORY, 'page_title=cat_title', 'cat_id=cl_inline'),
 3306+ 'page_namespace' => NS_CATEGORY, 'page_title=cat_title', 'cat_id=cl_target'),
33073307 'Article:getHiddenCategories' );
33083308 if ( false !== $res ) {
33093309 if ( $dbr->numRows( $res ) ) {

Status & tagging log