Index: trunk/extensions/SemanticDrilldown/includes/SD_Utils.inc |
— | — | @@ -31,12 +31,14 @@ |
32 | 32 | |
33 | 33 | /** |
34 | 34 | * Gets a list of the names of all categories in the wiki that aren't |
35 | | - * children of some other category |
| 35 | + * children of some other category - this list additionally includes, |
| 36 | + * and excludes, categories that are manually set with |
| 37 | + * 'SHOWINDRILLDOWN' and 'HIDEFROMDRILLDOWN', respectively. |
36 | 38 | */ |
37 | 39 | function getTopLevelCategories() { |
38 | 40 | $categories = array(); |
39 | 41 | $dbr = wfGetDB( DB_SLAVE ); |
40 | | - extract($dbr->tableNames('page', 'categorylinks')); |
| 42 | + extract($dbr->tableNames('page', 'categorylinks', 'page_props')); |
41 | 43 | $cat_ns = NS_CATEGORY; |
42 | 44 | $sql = "SELECT page_title FROM $page p LEFT OUTER JOIN $categorylinks cl ON p.page_id = cl.cl_from WHERE p.page_namespace = $cat_ns AND cl.cl_to IS NULL"; |
43 | 45 | $res = $dbr->query($sql); |
— | — | @@ -46,6 +48,29 @@ |
47 | 49 | } |
48 | 50 | } |
49 | 51 | $dbr->freeResult($res); |
| 52 | + |
| 53 | + // get 'hide' and 'show' categories |
| 54 | + $hidden_cats = $shown_cats = array(); |
| 55 | + $sql2 = "SELECT p.page_title, pp.pp_propname FROM $page p JOIN $page_props pp ON p.page_id = pp.pp_page WHERE p.page_namespace = $cat_ns AND (pp.pp_propname = 'hidefromdrilldown' OR pp.pp_propname = 'showindrilldown') AND pp.pp_value = 'y'"; |
| 56 | + $res2 = $dbr->query($sql2); |
| 57 | + if ($dbr->numRows( $res2 ) > 0) { |
| 58 | + while ($row = $dbr->fetchRow($res2)) { |
| 59 | + if ($row[1] == 'hidefromdrilldown') |
| 60 | + $hidden_cats[] = str_replace('_', ' ', $row[0]); |
| 61 | + else |
| 62 | + $shown_cats[] = str_replace('_', ' ', $row[0]); |
| 63 | + } |
| 64 | + } |
| 65 | + $dbr->freeResult($res2); |
| 66 | + $categories = array_merge($categories, $shown_cats); |
| 67 | + foreach ($hidden_cats as $hidden_cat) { |
| 68 | + foreach ($categories as $i => $cat) { |
| 69 | + if ($cat == $hidden_cat) { |
| 70 | + unset($categories[$i]); |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | + sort($categories); |
50 | 75 | return $categories; |
51 | 76 | } |
52 | 77 | |
— | — | @@ -314,4 +339,42 @@ |
315 | 340 | return $text; |
316 | 341 | } |
317 | 342 | |
| 343 | + /** |
| 344 | + * Register magic-word variable IDs |
| 345 | + */ |
| 346 | + function addMagicWordVariableIDs(&$magicWordVariableIDs) { |
| 347 | + $magicWordVariableIDs[] = 'MAG_HIDEFROMDRILLDOWN'; |
| 348 | + $magicWordVariableIDs[] = 'MAG_SHOWINDRILLDOWN'; |
| 349 | + return true; |
| 350 | + } |
| 351 | + |
| 352 | + /** |
| 353 | + * Set the actual value of the magic words |
| 354 | + */ |
| 355 | + function addMagicWordLanguage(&$magicWords, $langCode) { |
| 356 | + switch($langCode) { |
| 357 | + default: |
| 358 | + $magicWords['MAG_HIDEFROMDRILLDOWN'] = array(0, '__HIDEFROMDRILLDOWN__'); |
| 359 | + $magicWords['MAG_SHOWINDRILLDOWN'] = array(0, '__SHOWINDRILLDOWN__'); |
| 360 | + } |
| 361 | + return true; |
| 362 | + } |
| 363 | + |
| 364 | + /** |
| 365 | + * Set values in the page_props table based on the presence of the |
| 366 | + * 'HIDEFROMDRILLDOWN' and 'SHOWINDRILLDOWN' magic words in a page |
| 367 | + */ |
| 368 | + function handleShowAndHide(&$parser, &$text) { |
| 369 | + global $wgOut, $wgAction; |
| 370 | + $mw_hide = MagicWord::get('MAG_HIDEFROMDRILLDOWN'); |
| 371 | + if ($mw_hide->matchAndRemove($text)) { |
| 372 | + $parser->mOutput->setProperty( 'hidefromdrilldown', 'y' ); |
| 373 | + } |
| 374 | + $mw_show = MagicWord::get('MAG_SHOWINDRILLDOWN'); |
| 375 | + if ($mw_show->matchAndRemove($text)) { |
| 376 | + $parser->mOutput->setProperty( 'showindrilldown', 'y' ); |
| 377 | + } |
| 378 | + return true; |
| 379 | + } |
| 380 | + |
318 | 381 | } |