r60085 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60084‎ | r60085 | r60086 >
Date:18:53, 15 December 2009
Author:yaron
Status:deferred
Tags:
Comment:
Added handling for __HIDEFROMDRILLDOWN__ and __SHOWINDRILLDOWN__ magic words
Modified paths:
  • /trunk/extensions/SemanticDrilldown/includes/SD_Utils.inc (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticDrilldown/includes/SD_Utils.inc
@@ -31,12 +31,14 @@
3232
3333 /**
3434 * 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.
3638 */
3739 function getTopLevelCategories() {
3840 $categories = array();
3941 $dbr = wfGetDB( DB_SLAVE );
40 - extract($dbr->tableNames('page', 'categorylinks'));
 42+ extract($dbr->tableNames('page', 'categorylinks', 'page_props'));
4143 $cat_ns = NS_CATEGORY;
4244 $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";
4345 $res = $dbr->query($sql);
@@ -46,6 +48,29 @@
4749 }
4850 }
4951 $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);
5075 return $categories;
5176 }
5277
@@ -314,4 +339,42 @@
315340 return $text;
316341 }
317342
 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+
318381 }

Status & tagging log