For pages with hidden categories, add a list of these categories down the bottom...
authorAndrew Garrett <werdna@users.mediawiki.org>
Mon, 25 Feb 2008 13:38:21 +0000 (13:38 +0000)
committerAndrew Garrett <werdna@users.mediawiki.org>
Mon, 25 Feb 2008 13:38:21 +0000 (13:38 +0000)
includes/Article.php
includes/EditPage.php
includes/Linker.php
languages/messages/MessagesEn.php

index 6d893d6..68e561a 100644 (file)
@@ -3071,6 +3071,36 @@ class Article {
                return $result;
        }
 
+       /**
+        * Returns a list of hidden categories this page is a member of.
+        * Uses the page_props and categorylinks tables.
+        *
+        * @return array Array of Title objects
+        */
+       function getHiddenCategories() {
+               $result = array();
+               $id = $this->mTitle->getArticleID();
+               if( $id == 0 ) {
+                       return array();
+               }
+
+               $dbr = wfGetDB( DB_SLAVE );
+               $res = $dbr->select( array( 'categorylinks', 'page_props', 'page' ),
+                       array( 'cl_to' ),
+                       array( 'cl_from' => $id, 'pp_page=page_id', 'pp_propname' => 'hiddencat', 
+                               'page_namespace' => NS_CATEGORY, 'page_title=cl_to'),
+                       'Article:getHiddenCategories' );
+               if ( false !== $res ) {
+                       if ( $dbr->numRows( $res ) ) {
+                               while ( $row = $dbr->fetchObject( $res ) ) {
+                                       $result[] = Title::makeTitle( NS_CATEGORY, $row->cl_to );
+                               }
+                       }
+               }
+               $dbr->freeResult( $res );
+               return $result;
+       }
+
        /**
         * Return an auto-generated summary if the text provided is a redirect.
         *
index 45ca48d..2bb9e72 100644 (file)
@@ -1248,6 +1248,9 @@ class EditPage {
                $templates = ($this->preview || $this->section != '') ? $this->mPreviewTemplates : $this->mArticle->getUsedTemplates();
                $formattedtemplates = $sk->formatTemplates( $templates, $this->preview, $this->section != '');
 
+               $hiddencats = $this->mArticle->getHiddenCategories();
+               $formattedhiddencats = $sk->formatHiddenCategories( $hiddencats );
+
                global $wgUseMetadataEdit ;
                if ( $wgUseMetadataEdit ) {
                        $metadata = $this->mMetaData ;
@@ -1346,7 +1349,10 @@ END
 <div class='templatesUsed'>
 {$formattedtemplates}
 </div>
-" );
+<div class='hiddencats'>
+{$formattedhiddencats}
+</div>
+");
 
                /**
                 * To make it harder for someone to slip a user a page
index ea74fa5..a27c6c7 100644 (file)
@@ -1359,6 +1359,35 @@ class Linker {
                wfProfileOut( __METHOD__  );
                return $outText;
        }
+
+       /**
+        * Returns HTML for the "hidden categories on this page" list.
+        *
+        * @param array $hiddencats Array of hidden categories from Article::getHiddenCategories
+        * or similar
+        * @return string HTML output
+        */
+       public function formatHiddenCategories( $hiddencats) {
+               global $wgUser;
+               wfProfileIn( __METHOD__ );
+
+               $sk = $wgUser->getSkin();
+
+               $outText = '';
+               if ( count( $hiddencats ) > 0 ) {
+                       # Construct the HTML
+                       $outText = '<div class="mw-hiddenCategoriesExplanation">';
+                       $outText .= wfMsgExt( 'hiddencategories', array( 'parse' ) );
+                       $outText .= '</div><ul>';
+
+                       foreach ( $hiddencats as $titleObj ) {
+                               $outText .= '<li>' . $sk->makeKnownLinkObj( $titleObj ) . '</li>'; # If it's hidden, it must exist - no need to check with a LinkBatch
+                       }
+                       $outText .= '</ul>';
+               }
+               wfProfileOut( __METHOD__  );
+               return $outText;
+       }
        
        /**
         * Format a size in bytes for output, using an appropriate
index 5249ef7..a144f8f 100644 (file)
@@ -1063,6 +1063,7 @@ Please consider breaking the page into smaller sections.</strong>',
 'templatesusedsection'      => 'Templates used in this section:',
 'template-protected'        => '(protected)',
 'template-semiprotected'    => '(semi-protected)',
+'hiddencategories'         => 'Hidden categories this page is a member of:',
 'edittools'                 => '<!-- Text here will be shown below edit and upload forms. -->', # only translate this message to other languages if you have to change it
 'nocreatetitle'             => 'Page creation limited',
 'nocreatetext'              => '{{SITENAME}} has restricted the ability to create new pages.