r36892 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36891‎ | r36892 | r36893 >
Date:09:49, 2 July 2008
Author:daniel
Status:old
Tags:
Comment:
added inverse mode to navigate parent categories
Modified paths:
  • /trunk/extensions/CategoryTree/CategoryTree.i18n.php (modified) (history)
  • /trunk/extensions/CategoryTree/CategoryTree.js (modified) (history)
  • /trunk/extensions/CategoryTree/CategoryTree.php (modified) (history)
  • /trunk/extensions/CategoryTree/CategoryTreeFunctions.php (modified) (history)
  • /trunk/extensions/CategoryTree/CategoryTreePage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CategoryTree/CategoryTreePage.php
@@ -81,7 +81,7 @@
8282 $parents = $this->tree->renderParents( $title );
8383
8484 if ( $parents == '' ) {
85 - $wgOut->addHtml( wfMsgExt( 'categorytree-nothing-found', 'parseinline' ) );
 85+ $wgOut->addHtml( wfMsgExt( 'categorytree-no-parent-categories', 'parseinline' ) );
8686 } else {
8787 $wgOut->addHtml( $parents );
8888 }
Index: trunk/extensions/CategoryTree/CategoryTree.i18n.php
@@ -43,6 +43,7 @@
4444 'categorytree-loading' => 'loading…',
4545 'categorytree-nothing-found' => 'nothing found',
4646 'categorytree-no-subcategories' => 'no subcategories',
 47+ 'categorytree-no-parent-categories' => 'no parent categories',
4748 'categorytree-no-pages' => 'no pages or subcategories',
4849 'categorytree-not-found' => 'Category <i>$1</i> not found',
4950 'categorytree-error' => 'Problem loading data.',
@@ -610,6 +611,7 @@
611612 'categorytree-nothing-found' => 'Nichts gefunden',
612613 'categorytree-no-subcategories' => 'Keine Unterkategorien',
613614 'categorytree-no-pages' => 'Keine Seite oder Unterkategorien',
 615+ 'categorytree-no-parent-categories' => 'Keine Oberkategorien',
614616 'categorytree-not-found' => "Kategorie „$1“ nicht gefunden",
615617 'categorytree-error' => 'Probleme beim Laden der Daten.',
616618 'categorytree-retry' => 'Bitte warte einen Moment und versuche es dann erneut.',
Index: trunk/extensions/CategoryTree/CategoryTree.php
@@ -22,6 +22,7 @@
2323 define('CT_MODE_CATEGORIES', 0);
2424 define('CT_MODE_PAGES', 10);
2525 define('CT_MODE_ALL', 20);
 26+define('CT_MODE_PARENTS', 100);
2627
2728 /**
2829 * Constants for use with the hideprefix option,
@@ -64,6 +65,7 @@
6566
6667 $wgCategoryTreeExtPath = '/extensions/CategoryTree';
6768 $wgCategoryTreeVersion = '2'; #NOTE: bump this when you change the CSS or JS files!
 69+$wgCategoryTreeUseCategoryTable = version_compare( $wgVersion, "1.13", '>=' );
6870
6971 $wgCategoryTreeOmitNamespace = CT_HIDEPREFIX_CATEGORIES;
7072 $wgCategoryTreeDefaultMode = CT_MODE_CATEGORIES;
Index: trunk/extensions/CategoryTree/CategoryTree.js
@@ -133,6 +133,7 @@
134134
135135 if ( options.mode == 0 ) result= categoryTreeNoSubcategoriesMsg;
136136 else if ( options.mode == 10 ) result= categoryTreeNoPagesMsg;
 137+ else if ( options.mode == 100 ) result= categoryTreeNoParentCategoriesMsg;
137138 else result= categoryTreeNothingFoundMsg;
138139
139140 result+= '</i>';
Index: trunk/extensions/CategoryTree/CategoryTreeFunctions.php
@@ -31,6 +31,11 @@
3232 }
3333
3434 $this->mOptions['mode'] = self::decodeMode( $this->mOptions['mode'] );
 35+
 36+ if ( $this->mOptions['mode'] == CT_MODE_PARENTS ) {
 37+ $this->mOptions['namespaces'] = false; #namespace filter makes no sense with CT_MODE_PARENTS
 38+ }
 39+
3540 $this->mOptions['hideprefix'] = self::decodeHidePrefix( $this->mOptions['hideprefix'] );
3641 $this->mOptions['showcount'] = self::decodeBoolean( $this->mOptions['showcount'] );
3742 $this->mOptions['namespaces'] = self::decodeNamespaces( $this->mOptions['namespaces'] );
@@ -52,6 +57,10 @@
5358 return $this->mOptions[$name];
5459 }
5560
 61+ function isInverse( ) {
 62+ return $this->getOption('mode') == CT_MODE_PARENTS;
 63+ }
 64+
5665 static function decodeNamespaces( $nn ) {
5766 global $wgContLang;
5867
@@ -99,7 +108,8 @@
100109
101110 if ( $mode == 'all' ) $mode = CT_MODE_ALL;
102111 else if ( $mode == 'pages' ) $mode = CT_MODE_PAGES;
103 - else if ( $mode == 'categories' ) $mode = CT_MODE_CATEGORIES;
 112+ else if ( $mode == 'categories' || $mode == 'sub' ) $mode = CT_MODE_CATEGORIES;
 113+ else if ( $mode == 'parents' || $mode == 'super' || $mode == 'inverse' ) $mode = CT_MODE_PARENTS;
104114 else if ( $mode == 'default' ) $mode = $wgCategoryTreeDefaultOptions['mode'];
105115
106116 return (int)$mode;
@@ -188,6 +198,7 @@
189199 var categoryTreeLoadingMsg = \"".Xml::escapeJsString(wfMsgNoTrans('categorytree-loading'))."\";
190200 var categoryTreeNothingFoundMsg = \"".Xml::escapeJsString(wfMsgNoTrans('categorytree-nothing-found'))."\";
191201 var categoryTreeNoSubcategoriesMsg = \"".Xml::escapeJsString(wfMsgNoTrans('categorytree-no-subcategories'))."\";
 202+ var categoryTreeNoParentCategoriesMsg = \"".Xml::escapeJsString(wfMsgNoTrans('categorytree-no-parent-categories'))."\";
192203 var categoryTreeNoPagesMsg = \"".Xml::escapeJsString(wfMsgNoTrans('categorytree-no-pages'))."\";
193204 var categoryTreeErrorMsg = \"".Xml::escapeJsString(wfMsgNoTrans('categorytree-error'))."\";
194205 var categoryTreeRetryMsg = \"".Xml::escapeJsString(wfMsgNoTrans('categorytree-retry'))."\";
@@ -379,7 +390,7 @@
380391 * $title must be a Title object
381392 */
382393 function renderChildren( &$title, $depth=1 ) {
383 - global $wgCategoryTreeMaxChildren, $wgVersion;
 394+ global $wgCategoryTreeMaxChildren, $wgCategoryTreeUseCategoryTable;
384395
385396 if( $title->getNamespace() != NS_CATEGORY ) {
386397 // Non-categories can't have children. :)
@@ -388,20 +399,30 @@
389400
390401 $dbr =& wfGetDB( DB_SLAVE );
391402
392 -
 403+ $inverse = $this->isInverse();
393404 $mode = $this->getOption('mode');
394405 $namespaces = $this->getOption('namespaces');
395406
396 - #namespace filter.
397 - if ( $namespaces ) {
398 - #NOTE: we assume that the $namespaces array contains only integers!
399 - if ( sizeof( $namespaces ) === 1 ) $nsmatch = ' AND cat.page_namespace = ' . $namespaces[0] . ' ';
400 - else $nsmatch = ' AND cat.page_namespace IN ( ' . implode( ', ', $namespaces ) . ') ';
 407+ if ( $inverse ) {
 408+ $ctJoinCond = ' cl_to = cat.page_title AND cat.page_namespace = ' . NS_CATEGORY;
 409+ $ctWhere = " cl_from = " . $title->getArticleId();
 410+ $nsmatch = '';
401411 }
402412 else {
403 - if ( $mode == CT_MODE_ALL ) $nsmatch = '';
404 - else if ( $mode == CT_MODE_PAGES ) $nsmatch = ' AND cat.page_namespace != ' . NS_IMAGE;
405 - else $nsmatch = ' AND cat.page_namespace = ' . NS_CATEGORY;
 413+ $ctJoinCond = ' cl_from = cat.page_id ';
 414+ $ctWhere = " cl_to = " . $dbr->addQuotes( $title->getDBkey() );
 415+
 416+ #namespace filter.
 417+ if ( $namespaces ) {
 418+ #NOTE: we assume that the $namespaces array contains only integers! decodeNamepsaces makes it so.
 419+ if ( sizeof( $namespaces ) === 1 ) $nsmatch = ' AND cat.page_namespace = ' . $namespaces[0] . ' ';
 420+ else $nsmatch = ' AND cat.page_namespace IN ( ' . implode( ', ', $namespaces ) . ') ';
 421+ }
 422+ else {
 423+ if ( $mode == CT_MODE_ALL ) $nsmatch = '';
 424+ else if ( $mode == CT_MODE_PAGES ) $nsmatch = ' AND cat.page_namespace != ' . NS_IMAGE;
 425+ else $nsmatch = ' AND cat.page_namespace = ' . NS_CATEGORY;
 426+ }
406427 }
407428
408429 #additional stuff to be used if "transaltion" by interwiki-links is desired
@@ -410,7 +431,7 @@
411432 $transWhere = '';
412433
413434 # fetch member count if possible
414 - $doCount = version_compare( $wgVersion, "1.12", '>' );
 435+ $doCount = !$inverse && $wgCategoryTreeUseCategoryTable;
415436
416437 $countFields = '';
417438 $countJoin = '';
@@ -428,10 +449,10 @@
429450 $transFields
430451 $countFields
431452 FROM $page as cat
432 - JOIN $categorylinks ON cl_from = cat.page_id
 453+ JOIN $categorylinks ON $ctJoinCond
433454 $transJoin
434455 $countJoin
435 - WHERE cl_to = " . $dbr->addQuotes( $title->getDBkey() ) . "
 456+ WHERE $ctWhere
436457 $nsmatch
437458 "./*AND cat.page_is_redirect = 0*/"
438459 $transWhere
@@ -527,7 +548,11 @@
528549 * $title must be a Title object
529550 */
530551 function renderNode( $title, $children = 0, $loadchildren = false ) {
531 - if ( $title->getNamespace() == NS_CATEGORY ) $cat = Category::newFromTitle( $title );
 552+ global $wgCategoryTreeUseCategoryTable;
 553+
 554+ if ( $wgCategoryTreeUseCategoryTable && $title->getNamespace() == NS_CATEGORY && !$this->isInverse() ) {
 555+ $cat = Category::newFromTitle( $title );
 556+ }
532557 else $cat = NULL;
533558
534559 return $this->renderNodeInfo( $title, $cat, $children, $loadchildren );
@@ -658,6 +683,7 @@
659684 $s .= Xml::openElement( 'i', array( 'class' => 'CategoryTreeNotice' ) );
660685 if ( $mode == CT_MODE_CATEGORIES ) $s .= wfMsgExt( 'categorytree-no-subcategories', 'parsemag');
661686 else if ( $mode == CT_MODE_PAGES ) $s .= wfMsgExt( 'categorytree-no-pages', 'parsemag');
 687+ else if ( $mode == CT_MODE_PARENTS ) $s .= wfMsgExt( 'categorytree-no-parent-categories', 'parsemag');
662688 else $s .= wfMsgExt( 'categorytree-nothing-found', 'parsemag');
663689 $s .= Xml::closeElement( 'i' );
664690 } else {

Status & tagging log