From: Tim Starling Date: Mon, 25 Feb 2008 16:38:25 +0000 (+0000) Subject: * Put both hidden categories and normal categories into the view page HTML, but with... X-Git-Tag: 1.31.0-rc.0~49360 X-Git-Url: http://git.cyclocoop.org/%22.%24image2.%22?a=commitdiff_plain;h=792e155bd22a3b9b6d2fd56f610e23b39d6b466b;p=lhc%2Fweb%2Fwiklou.git * Put both hidden categories and normal categories into the view page HTML, but with hidden categories being unconditionally hidden with CSS. A JS show/hide toggle can be added in user/site JS. * Add user preference to always show hidden categories * Add all hidden categories to [[Category:Hidden categories]], localised by hidden-category-category * Add wgVariantArticlePath and wgActionPaths to the JS variables script, needed to determine title from link href. --- diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index eee944f323..35d0a50979 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1326,7 +1326,7 @@ $wgCacheEpoch = '20030516000000'; * to ensure that client-side caches don't keep obsolete copies of global * styles. */ -$wgStyleVersion = '116'; +$wgStyleVersion = '117'; # Server-side caching: diff --git a/includes/OutputPage.php b/includes/OutputPage.php index d39b80ca80..2f8bf10407 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -271,14 +271,12 @@ class OutputPage { * Add an array of categories, with names in the keys */ public function addCategoryLinks( $categories ) { - global $wgUser, $wgContLang, $wgTitle; + global $wgUser, $wgContLang; - if ( !is_array( $categories ) ) { - return; - } - if ( count( $categories ) == 0 ) { + if ( !is_array( $categories ) || count( $categories ) == 0 ) { return; } + # Add the links to a LinkBatch $arr = array( NS_CATEGORY => $categories ); $lb = new LinkBatch; @@ -287,8 +285,8 @@ class OutputPage { # Fetch existence plus the hiddencat property $dbr = wfGetDB( DB_SLAVE ); $pageTable = $dbr->tableName( 'page' ); - $propsTable = $dbr->tableName( 'page_props' ); $where = $lb->constructSet( 'page', $dbr ); + $propsTable = $dbr->tableName( 'page_props' ); $sql = "SELECT page_id, page_namespace, page_title, pp_value FROM $pageTable LEFT JOIN $propsTable " . " ON pp_propname='hiddencat' AND pp_page=page_id WHERE $where"; $res = $dbr->query( $sql, __METHOD__ ); @@ -296,19 +294,23 @@ class OutputPage { # Add the results to the link cache $lb->addResultToCache( LinkCache::singleton(), $res ); - # Remove categories with hiddencat + # Set all the values to 'normal'. This can be done with array_fill_keys in PHP 5.2.0+ + $categories = array_combine( array_keys( $categories ), + array_fill( 0, count( $categories ), 'normal' ) ); + + # Mark hidden categories foreach ( $res as $row ) { - if ( isset( $row->pp_value ) and $wgTitle->getNamespace() != NS_CATEGORY ) { - unset( $categories[$row->page_title] ); + if ( isset( $row->pp_value ) ) { + $categories[$row->page_title] = 'hidden'; } } - + # Add the remaining categories to the skin $sk = $wgUser->getSkin(); - foreach ( $categories as $category => $unused ) { + foreach ( $categories as $category => $type ) { $title = Title::makeTitleSafe( NS_CATEGORY, $category ); $text = $wgContLang->convertHtml( $title->getText() ); - $this->mCategoryLinks[] = $sk->makeLinkObj( $title, $text ); + $this->mCategoryLinks[$type][] = $sk->makeLinkObj( $title, $text ); } } diff --git a/includes/Parser.php b/includes/Parser.php index d663783e16..81d182e7e0 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -3289,6 +3289,13 @@ class Parser } if ( isset( $this->mDoubleUnderscores['hiddencat'] ) ) { $this->mOutput->setProperty( 'hiddencat', 'y' ); + + $containerCategory = Title::makeTitleSafe( NS_CATEGORY, wfMsg( 'hidden-category-category' ) ); + if ( $containerCategory ) { + $this->mOutput->addCategory( $containerCategory->getDBkey(), $this->getDefaultSort() ); + } else { + wfDebug( __METHOD__.": [[MediaWiki:hidden-category-category]] is not a valid title!\n" ); + } } return $text; } diff --git a/includes/Skin.php b/includes/Skin.php index 30d2c2bcfe..1e6202859c 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -300,7 +300,7 @@ class Skin extends Linker { global $wgScript, $wgStylePath, $wgUser; global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang; global $wgTitle, $wgCanonicalNamespaceNames, $wgOut, $wgArticle; - global $wgBreakFrames, $wgRequest; + global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths; global $wgUseAjax, $wgAjaxWatch; global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI; @@ -313,6 +313,8 @@ class Skin extends Linker { 'wgArticlePath' => $wgArticlePath, 'wgScriptPath' => $wgScriptPath, 'wgScript' => $wgScript, + 'wgVariantArticlePath' => $wgVariantArticlePath, + 'wgActionPaths' => $wgActionPaths, 'wgServer' => $wgServer, 'wgCanonicalNamespace' => $nsname, 'wgCanonicalSpecialPageName' => SpecialPage::resolveAlias( $wgTitle->getDBkey() ), @@ -627,7 +629,7 @@ END; function getCategoryLinks () { global $wgOut, $wgTitle, $wgUseCategoryBrowser; - global $wgContLang; + global $wgContLang, $wgUser; if( count( $wgOut->mCategoryLinks ) == 0 ) return ''; @@ -639,11 +641,32 @@ END; $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr'; $embed = ""; $pop = ''; - $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $wgOut->mCategoryLinks ) . $pop; - $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escape' ), count( $wgOut->mCategoryLinks ) ); - $s = $this->makeLinkObj( Title::newFromText( wfMsgForContent('pagecategorieslink') ), $msg ) - . ': ' . $t; + $allCats = $wgOut->getCategoryLinks(); + $s = ''; + if ( !empty( $allCats['normal'] ) ) { + $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop; + + $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escape' ), count( $allCats['normal'] ) ); + $s .= ''; + } + + # Hidden categories + if ( isset( $allCats['hidden'] ) ) { + if ( $wgUser->getBoolOption( 'showhiddencats' ) ) { + $class ='mw-hidden-cats-user-shown'; + } elseif ( $wgTitle->getNamespace() == NS_CATEGORY ) { + $class = 'mw-hidden-cats-ns-shown'; + } else { + $class = 'mw-hidden-cats-hidden'; + } + $s .= "
" . + wfMsgExt( 'hidden-categories', array( 'parsemag', 'escape' ), count( $allCats['hidden'] ) ) . + ': ' . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop . + "
"; + } # optional 'dmoz-like' category browser. Will be shown under the list # of categories an article belong to @@ -690,7 +713,7 @@ END; function getCategories() { $catlinks=$this->getCategoryLinks(); if(!empty($catlinks)) { - return ""; + return ""; } } diff --git a/includes/User.php b/includes/User.php index 8e3c776a2f..08940a5ca2 100644 --- a/includes/User.php +++ b/includes/User.php @@ -76,6 +76,7 @@ class User { 'watchlisthideminor', 'ccmeonemails', 'diffonly', + 'showhiddencats', ); /** diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index a144f8f388..ab71381c5b 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -501,6 +501,7 @@ XHTML id names. 'tog-nolangconversion' => 'Disable variants conversion', # only translate this message to other languages if you have to change it 'tog-ccmeonemails' => 'Send me copies of emails I send to other users', 'tog-diffonly' => "Don't show page content below diffs", +'tog-showhiddencats' => 'Show hidden categories', 'underline-always' => 'Always', 'underline-never' => 'Never', @@ -568,6 +569,8 @@ XHTML id names. 'subcategories' => 'Subcategories', 'category-media-header' => 'Media in category "$1"', 'category-empty' => "''This category currently contains no pages or media.''", +'hidden-categories' => '{{PLURAL:$1|Hidden category|Hidden categories}}', +'hidden-category-category' => 'Hidden categories', # Name of the category where hidden categories will be listed 'linkprefix' => '/^(.*?)([a-zA-Z\x80-\xff]+)$/sD', # only translate this message to other languages if you have to change it 'mainpagetext' => "'''MediaWiki has been successfully installed.'''", diff --git a/skins/common/shared.css b/skins/common/shared.css index de02a10f72..8fed17188d 100644 --- a/skins/common/shared.css +++ b/skins/common/shared.css @@ -77,3 +77,8 @@ body.rtl .magnify { float:left; } body.ltr .thumbcaption { text-align:left; } body.ltr .magnify { float:right; } + +/** + * Hidden categories + */ +.mw-hidden-cats-hidden { display: none; }