* Put both hidden categories and normal categories into the view page HTML, but with...
authorTim Starling <tstarling@users.mediawiki.org>
Mon, 25 Feb 2008 16:38:25 +0000 (16:38 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Mon, 25 Feb 2008 16:38:25 +0000 (16:38 +0000)
* 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.

includes/DefaultSettings.php
includes/OutputPage.php
includes/Parser.php
includes/Skin.php
includes/User.php
languages/messages/MessagesEn.php
skins/common/shared.css

index eee944f..35d0a50 100644 (file)
@@ -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:
index d39b80c..2f8bf10 100644 (file)
@@ -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 );
                }
        }
 
index d663783..81d182e 100644 (file)
@@ -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;
        }
index 30d2c2b..1e62028 100644 (file)
@@ -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 = "<span dir='$dir'>";
                $pop = '</span>';
-               $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 .= '<div id="mw-normal-catlinks">' .
+                               $this->makeLinkObj( Title::newFromText( wfMsgForContent('pagecategorieslink') ), $msg )
+                               . ': ' . $t . '</div>';
+               }
+
+               # 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 .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" . 
+                               wfMsgExt( 'hidden-categories', array( 'parsemag', 'escape' ), count( $allCats['hidden'] ) ) . 
+                               ': ' . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
+                               "</div>";
+               }
 
                # 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 "<p class='catlinks'>{$catlinks}</p>";
+                       return "<div class='catlinks'>{$catlinks}</div>";
                }
        }
 
index 8e3c776..08940a5 100644 (file)
@@ -76,6 +76,7 @@ class User {
                'watchlisthideminor',
                'ccmeonemails',
                'diffonly',
+               'showhiddencats',
        );
 
        /**
index a144f8f..ab71381 100644 (file)
@@ -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'      => "<big>'''MediaWiki has been successfully installed.'''</big>",
index de02a10..8fed171 100644 (file)
@@ -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; }