r66987 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66986‎ | r66987 | r66988 >
Date:02:15, 28 May 2010
Author:tstarling
Status:ok (Comments)
Tags:
Comment:
* (bug 23682) Don't allow people to expand subtree when it's known to be empty, this is inefficient.
* Fixed a bug causing the "+" link to be shown even when the number of subcategories is zero, due to the DBMS returning a string instead of an integer, causing triple-equals comparison to fail.
Modified paths:
  • /trunk/extensions/CategoryTree/CategoryTree.css (modified) (history)
  • /trunk/extensions/CategoryTree/CategoryTree.php (modified) (history)
  • /trunk/extensions/CategoryTree/CategoryTreeFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CategoryTree/CategoryTree.php
@@ -65,7 +65,7 @@
6666 $wgCategoryTreeHijackPageCategories = false; # EXPERIMENTAL! NOT YET FOR PRODUCTION USE! Main problem is general HTML/CSS layout cruftiness.
6767
6868 $wgCategoryTreeExtPath = '/extensions/CategoryTree';
69 -$wgCategoryTreeVersion = '5'; # NOTE: bump this when you change the CSS or JS files!
 69+$wgCategoryTreeVersion = '6'; # NOTE: bump this when you change the CSS or JS files!
7070 $wgCategoryTreeUseCategoryTable = version_compare( $wgVersion, "1.13", '>=' );
7171
7272 $wgCategoryTreeOmitNamespace = CT_HIDEPREFIX_CATEGORIES;
Index: trunk/extensions/CategoryTree/CategoryTree.css
@@ -21,6 +21,9 @@
2222 cursor: pointer;
2323 cursor: hand; /* hack for MSIE 5.0 and 5.5 */
2424 }
 25+.CategoryTreeEmptyBullet {
 26+ cursor: default;
 27+}
2528
2629 .CategoryTreeBullet a,
2730 .CategoryTreeBullet a:link,
Index: trunk/extensions/CategoryTree/CategoryTreeFunctions.php
@@ -674,7 +674,6 @@
675675 $s .= Xml::openElement( 'div', array( 'class' => 'CategoryTreeItem' ) );
676676
677677 $attr = array( 'class' => 'CategoryTreeBullet' );
678 - $s .= Xml::openElement( 'span', $attr );
679678
680679 if ( $ns == NS_CATEGORY ) {
681680 if ( $cat ) {
@@ -685,44 +684,45 @@
686685 } else {
687686 $count = $cat->getPageCount();
688687 }
 688+ # Fix conversion to string for ===
 689+ $count = intval( $count );
689690 }
 691+ if ( $count === 0 ) {
 692+ $bullet = wfMsgNoTrans( 'categorytree-empty-bullet' ) . ' ';
 693+ $attr['class'] = 'CategoryTreeEmptyBullet';
 694+ } else {
 695+ $linkattr = array( );
 696+ if ( $load ) {
 697+ $linkattr[ 'id' ] = $load;
 698+ }
690699
691 - $linkattr = array( );
692 - if ( $load ) {
693 - $linkattr[ 'id' ] = $load;
694 - }
 700+ $linkattr[ 'class' ] = "CategoryTreeToggle";
 701+ $linkattr['style'] = 'display: none;'; // Unhidden by JS
695702
696 - $linkattr[ 'class' ] = "CategoryTreeToggle";
697 - $linkattr['style'] = 'display: none;'; // Unhidden by JS
698 -
699 - if ( $children == 0 || $loadchildren ) {
700 - $tag = 'span';
701 - if ( $count === 0 ) {
702 - $txt = wfMsgNoTrans( 'categorytree-empty-bullet' );
 703+ if ( $children == 0 || $loadchildren ) {
 704+ $tag = 'span';
 705+ $txt = wfMsgNoTrans( 'categorytree-expand-bullet' );
 706+ $linkattr[ 'onclick' ] = "if (this.href) this.href='javascript:void(0)'; categoryTreeExpandNode('" . Xml::escapeJsString( $key ) . "'," . $this->getOptionsAsJsStructure() . ",this);";
 707+ # Don't load this message for ajax requests, so that we don't have to initialise $wgLang
 708+ $linkattr[ 'title' ] = $this->mIsAjaxRequest ? '##LOAD##' : wfMsgNoTrans( 'categorytree-expand' );
703709 } else {
704 - $txt = wfMsgNoTrans( 'categorytree-expand-bullet' );
 710+ $tag = 'span';
 711+ $txt = wfMsgNoTrans( 'categorytree-collapse-bullet' );
 712+ $linkattr[ 'onclick' ] = "if (this.href) this.href='javascript:void(0)'; categoryTreeCollapseNode('" . Xml::escapeJsString( $key ) . "'," . $this->getOptionsAsJsStructure() . ",this);";
 713+ $linkattr[ 'title' ] = wfMsgNoTrans( 'categorytree-collapse' );
 714+ $linkattr[ 'class' ] .= ' CategoryTreeLoaded';
705715 }
706 - $linkattr[ 'onclick' ] = "if (this.href) this.href='javascript:void(0)'; categoryTreeExpandNode('" . Xml::escapeJsString( $key ) . "'," . $this->getOptionsAsJsStructure() . ",this);";
707 - # Don't load this message for ajax requests, so that we don't have to initialise $wgLang
708 - $linkattr[ 'title' ] = $this->mIsAjaxRequest ? '##LOAD##' : wfMsgNoTrans( 'categorytree-expand' );
709 - } else {
710 - $tag = 'span';
711 - $txt = wfMsgNoTrans( 'categorytree-collapse-bullet' );
712 - $linkattr[ 'onclick' ] = "if (this.href) this.href='javascript:void(0)'; categoryTreeCollapseNode('" . Xml::escapeJsString( $key ) . "'," . $this->getOptionsAsJsStructure() . ",this);";
713 - $linkattr[ 'title' ] = wfMsgNoTrans( 'categorytree-collapse' );
714 - $linkattr[ 'class' ] .= ' CategoryTreeLoaded';
715 - }
716716
717 - if ( $tag == 'a' ) {
718 - $linkattr[ 'href' ] = $wikiLink;
 717+ if ( $tag == 'a' ) {
 718+ $linkattr[ 'href' ] = $wikiLink;
 719+ }
 720+ $bullet = Xml::openElement( $tag, $linkattr ) . $txt . Xml::closeElement( $tag ) . ' ';
719721 }
720 - $s .= Xml::openElement( $tag, $linkattr ) . $txt . Xml::closeElement( $tag ) . ' ';
721722 } else {
722 - $s .= wfMsgNoTrans( 'categorytree-page-bullet' );
 723+ $bullet = wfMsgNoTrans( 'categorytree-page-bullet' );
723724 }
 725+ $s .= Xml::tags( 'span', $attr, $bullet );
724726
725 - $s .= Xml::closeElement( 'span' );
726 -
727727 $s .= Xml::openElement( 'a', array( 'class' => $labelClass, 'href' => $wikiLink ) ) . $label . Xml::closeElement( 'a' );
728728
729729 if ( $count !== false && $this->getOption( 'showcount' ) ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r67179* Per Aryeh's suggestion on CR r66987, treat categories larger than a certain...tstarling08:58, 1 June 2010
r67181Merged all changes from r62820 to r67179 from trunk, to get r66987 and r67179...tstarling11:58, 1 June 2010
r71174Adapt CategoryTree to the new schema...simetrical21:57, 16 August 2010

Comments

#Comment by Midom (talk | contribs)   05:16, 28 May 2010

what is this patch supposed to fix?

#Comment by Aaron Schulz (talk | contribs)   17:07, 28 May 2010

Reduce useless query load? It's not a DB schema fix of course.

#Comment by Simetrical (talk | contribs)   17:17, 28 May 2010

It would be easy to adapt this to skip big categories entirely. Just skip if ( $cat->getPageCount() > 10000 ) or something. Of course, this would disable functionality, but not nearly so much.

Status & tagging log