r105653 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105652‎ | r105653 | r105654 >
Date:05:38, 9 December 2011
Author:yaron
Status:resolved (Comments)
Tags:
Comment:
Added handling for new $sdgHideCategoriesByDefault setting variable
Modified paths:
  • /trunk/extensions/SemanticDrilldown/SemanticDrilldown.php (modified) (history)
  • /trunk/extensions/SemanticDrilldown/includes/SD_Utils.php (modified) (history)
  • /trunk/extensions/SemanticDrilldown/specials/SD_BrowseData.php (modified) (history)
  • /trunk/extensions/SemanticDrilldown/specials/SD_CreateFilter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticDrilldown/specials/SD_CreateFilter.php
@@ -162,7 +162,7 @@
163163 <select id="category_dropdown" name="category_name">
164164
165165 END;
166 - $categories = SDUtils::getTopLevelCategories();
 166+ $categories = SDUtils::getCategoriesForBrowsing();
167167 foreach ( $categories as $category ) {
168168 $category = str_replace( '_', ' ', $category );
169169 $text .= " <option>$category</option>\n";
Index: trunk/extensions/SemanticDrilldown/specials/SD_BrowseData.php
@@ -83,7 +83,7 @@
8484 // if no category was specified, go with the first
8585 // category on the site, alphabetically
8686 if ( ! $category ) {
87 - $categories = SDUtils::getTopLevelCategories();
 87+ $categories = SDUtils::getCategoriesForBrowsing();
8888 if ( count( $categories ) > 0 ) {
8989 $category = $categories[0];
9090 }
@@ -856,7 +856,7 @@
857857 global $sdgFiltersSmallestFontSize, $sdgFiltersLargestFontSize;
858858
859859 $skin = $wgUser->getSkin();
860 - $categories = SDUtils::getTopLevelCategories();
 860+ $categories = SDUtils::getCategoriesForBrowsing();
861861 // if there are no categories, escape quickly
862862 if ( count( $categories ) == 0 ) {
863863 return "";
Index: trunk/extensions/SemanticDrilldown/includes/SD_Utils.php
@@ -79,6 +79,41 @@
8080 }
8181
8282 /**
 83+ * Gets the list of names of only those categories in the wiki
 84+ * that have a __SHOWINDRILLDOWN__ declaration on their page.
 85+ */
 86+ static function getOnlyExplicitlyShownCategories() {
 87+ $shown_cats = array();
 88+ $dbr = wfGetDB( DB_SLAVE );
 89+ extract( $dbr->tableNames( 'page', 'page_props' ) );
 90+ $cat_ns = NS_CATEGORY;
 91+ $sql = "SELECT p.page_title FROM $page p JOIN $page_props pp ON p.page_id = pp.pp_page WHERE p.page_namespace = $cat_ns AND pp.pp_propname = 'showindrilldown' AND pp.pp_value = 'y'";
 92+ $res = $dbr->query( $sql );
 93+
 94+ while ( $row = $dbr->fetchRow( $res ) ) {
 95+ $shown_cats[] = str_replace( '_', ' ', $row[0] );
 96+ }
 97+ $dbr->freeResult( $res );
 98+
 99+ sort( $shown_cats );
 100+ return $shown_cats;
 101+ }
 102+
 103+ /**
 104+ * Returns the list of categories that will show up in the
 105+ * header/sidebar of the 'BrowseData' special page.
 106+ */
 107+ public static function getCategoriesForBrowsing() {
 108+ global $sdgHideCategoriesByDefault;
 109+
 110+ if ( $sdgHideCategoriesByDefault ) {
 111+ return self::getOnlyExplicitlyShownCategories();
 112+ } else {
 113+ return self::getTopLevelCategories();
 114+ }
 115+ }
 116+
 117+ /**
83118 * Gets a list of the names of all properties in the wiki
84119 */
85120 static function getSemanticProperties() {
Index: trunk/extensions/SemanticDrilldown/SemanticDrilldown.php
@@ -100,6 +100,9 @@
101101 # ##
102102 # # Variables for display
103103 # ##
 104+// Set to true to have Special:BrowseData show only categories that have
 105+// __SHOWINDRILLDOWN__ set.
 106+$sdgHideCategoriesByDefault = false;
104107 $sdgNumResultsPerPage = 250;
105108 // set these to a positive value to trigger the "tag cloud" display
106109 $sdgFiltersSmallestFontSize = - 1;

Follow-up revisions

RevisionCommit summaryAuthorDate
r105696Replaced hardcoded SQL with a Database::select() callyaron19:16, 9 December 2011

Comments

#Comment by Nikerabbit (talk | contribs)   08:45, 9 December 2011

Should use query construction methods and perhaps TitleArray class.

#Comment by Yaron Koren (talk | contribs)   19:22, 9 December 2011

Good idea - I replaced the hardcoded SQL with a select() call. Setting this back to "new".

#Comment by Nikerabbit (talk | contribs)   00:14, 11 December 2011

Good enough.

Status & tagging log