r31262 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r31261‎ | r31262 | r31263 >
Date:16:38, 25 February 2008
Author:tstarling
Status:old
Tags:
Comment:
* 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.
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Parser.php (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/skins/common/shared.css (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/shared.css
@@ -77,3 +77,8 @@
7878
7979 body.ltr .thumbcaption { text-align:left; }
8080 body.ltr .magnify { float:right; }
 81+
 82+/**
 83+ * Hidden categories
 84+ */
 85+.mw-hidden-cats-hidden { display: none; }
Index: trunk/phase3/includes/User.php
@@ -76,6 +76,7 @@
7777 'watchlisthideminor',
7878 'ccmeonemails',
7979 'diffonly',
 80+ 'showhiddencats',
8081 );
8182
8283 /**
Index: trunk/phase3/includes/Parser.php
@@ -3289,6 +3289,13 @@
32903290 }
32913291 if ( isset( $this->mDoubleUnderscores['hiddencat'] ) ) {
32923292 $this->mOutput->setProperty( 'hiddencat', 'y' );
 3293+
 3294+ $containerCategory = Title::makeTitleSafe( NS_CATEGORY, wfMsg( 'hidden-category-category' ) );
 3295+ if ( $containerCategory ) {
 3296+ $this->mOutput->addCategory( $containerCategory->getDBkey(), $this->getDefaultSort() );
 3297+ } else {
 3298+ wfDebug( __METHOD__.": [[MediaWiki:hidden-category-category]] is not a valid title!\n" );
 3299+ }
32933300 }
32943301 return $text;
32953302 }
Index: trunk/phase3/includes/OutputPage.php
@@ -271,14 +271,12 @@
272272 * Add an array of categories, with names in the keys
273273 */
274274 public function addCategoryLinks( $categories ) {
275 - global $wgUser, $wgContLang, $wgTitle;
 275+ global $wgUser, $wgContLang;
276276
277 - if ( !is_array( $categories ) ) {
 277+ if ( !is_array( $categories ) || count( $categories ) == 0 ) {
278278 return;
279279 }
280 - if ( count( $categories ) == 0 ) {
281 - return;
282 - }
 280+
283281 # Add the links to a LinkBatch
284282 $arr = array( NS_CATEGORY => $categories );
285283 $lb = new LinkBatch;
@@ -287,8 +285,8 @@
288286 # Fetch existence plus the hiddencat property
289287 $dbr = wfGetDB( DB_SLAVE );
290288 $pageTable = $dbr->tableName( 'page' );
 289+ $where = $lb->constructSet( 'page', $dbr );
291290 $propsTable = $dbr->tableName( 'page_props' );
292 - $where = $lb->constructSet( 'page', $dbr );
293291 $sql = "SELECT page_id, page_namespace, page_title, pp_value FROM $pageTable LEFT JOIN $propsTable " .
294292 " ON pp_propname='hiddencat' AND pp_page=page_id WHERE $where";
295293 $res = $dbr->query( $sql, __METHOD__ );
@@ -296,19 +294,23 @@
297295 # Add the results to the link cache
298296 $lb->addResultToCache( LinkCache::singleton(), $res );
299297
300 - # Remove categories with hiddencat
 298+ # Set all the values to 'normal'. This can be done with array_fill_keys in PHP 5.2.0+
 299+ $categories = array_combine( array_keys( $categories ),
 300+ array_fill( 0, count( $categories ), 'normal' ) );
 301+
 302+ # Mark hidden categories
301303 foreach ( $res as $row ) {
302 - if ( isset( $row->pp_value ) and $wgTitle->getNamespace() != NS_CATEGORY ) {
303 - unset( $categories[$row->page_title] );
 304+ if ( isset( $row->pp_value ) ) {
 305+ $categories[$row->page_title] = 'hidden';
304306 }
305307 }
306 -
 308+
307309 # Add the remaining categories to the skin
308310 $sk = $wgUser->getSkin();
309 - foreach ( $categories as $category => $unused ) {
 311+ foreach ( $categories as $category => $type ) {
310312 $title = Title::makeTitleSafe( NS_CATEGORY, $category );
311313 $text = $wgContLang->convertHtml( $title->getText() );
312 - $this->mCategoryLinks[] = $sk->makeLinkObj( $title, $text );
 314+ $this->mCategoryLinks[$type][] = $sk->makeLinkObj( $title, $text );
313315 }
314316 }
315317
Index: trunk/phase3/includes/DefaultSettings.php
@@ -1326,7 +1326,7 @@
13271327 * to ensure that client-side caches don't keep obsolete copies of global
13281328 * styles.
13291329 */
1330 -$wgStyleVersion = '116';
 1330+$wgStyleVersion = '117';
13311331
13321332
13331333 # Server-side caching:
Index: trunk/phase3/includes/Skin.php
@@ -300,7 +300,7 @@
301301 global $wgScript, $wgStylePath, $wgUser;
302302 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
303303 global $wgTitle, $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
304 - global $wgBreakFrames, $wgRequest;
 304+ global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths;
305305 global $wgUseAjax, $wgAjaxWatch;
306306 global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI;
307307
@@ -313,6 +313,8 @@
314314 'wgArticlePath' => $wgArticlePath,
315315 'wgScriptPath' => $wgScriptPath,
316316 'wgScript' => $wgScript,
 317+ 'wgVariantArticlePath' => $wgVariantArticlePath,
 318+ 'wgActionPaths' => $wgActionPaths,
317319 'wgServer' => $wgServer,
318320 'wgCanonicalNamespace' => $nsname,
319321 'wgCanonicalSpecialPageName' => SpecialPage::resolveAlias( $wgTitle->getDBkey() ),
@@ -627,7 +629,7 @@
628630
629631 function getCategoryLinks () {
630632 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
631 - global $wgContLang;
 633+ global $wgContLang, $wgUser;
632634
633635 if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
634636
@@ -639,12 +641,33 @@
640642 $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
641643 $embed = "<span dir='$dir'>";
642644 $pop = '</span>';
643 - $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $wgOut->mCategoryLinks ) . $pop;
644645
645 - $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escape' ), count( $wgOut->mCategoryLinks ) );
646 - $s = $this->makeLinkObj( Title::newFromText( wfMsgForContent('pagecategorieslink') ), $msg )
647 - . ': ' . $t;
 646+ $allCats = $wgOut->getCategoryLinks();
 647+ $s = '';
 648+ if ( !empty( $allCats['normal'] ) ) {
 649+ $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
 650+
 651+ $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escape' ), count( $allCats['normal'] ) );
 652+ $s .= '<div id="mw-normal-catlinks">' .
 653+ $this->makeLinkObj( Title::newFromText( wfMsgForContent('pagecategorieslink') ), $msg )
 654+ . ': ' . $t . '</div>';
 655+ }
648656
 657+ # Hidden categories
 658+ if ( isset( $allCats['hidden'] ) ) {
 659+ if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
 660+ $class ='mw-hidden-cats-user-shown';
 661+ } elseif ( $wgTitle->getNamespace() == NS_CATEGORY ) {
 662+ $class = 'mw-hidden-cats-ns-shown';
 663+ } else {
 664+ $class = 'mw-hidden-cats-hidden';
 665+ }
 666+ $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
 667+ wfMsgExt( 'hidden-categories', array( 'parsemag', 'escape' ), count( $allCats['hidden'] ) ) .
 668+ ': ' . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
 669+ "</div>";
 670+ }
 671+
649672 # optional 'dmoz-like' category browser. Will be shown under the list
650673 # of categories an article belong to
651674 if($wgUseCategoryBrowser) {
@@ -690,7 +713,7 @@
691714 function getCategories() {
692715 $catlinks=$this->getCategoryLinks();
693716 if(!empty($catlinks)) {
694 - return "<p class='catlinks'>{$catlinks}</p>";
 717+ return "<div class='catlinks'>{$catlinks}</div>";
695718 }
696719 }
697720
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -501,6 +501,7 @@
502502 'tog-nolangconversion' => 'Disable variants conversion', # only translate this message to other languages if you have to change it
503503 'tog-ccmeonemails' => 'Send me copies of emails I send to other users',
504504 'tog-diffonly' => "Don't show page content below diffs",
 505+'tog-showhiddencats' => 'Show hidden categories',
505506
506507 'underline-always' => 'Always',
507508 'underline-never' => 'Never',
@@ -568,6 +569,8 @@
569570 'subcategories' => 'Subcategories',
570571 'category-media-header' => 'Media in category "$1"',
571572 'category-empty' => "''This category currently contains no pages or media.''",
 573+'hidden-categories' => '{{PLURAL:$1|Hidden category|Hidden categories}}',
 574+'hidden-category-category' => 'Hidden categories', # Name of the category where hidden categories will be listed
572575
573576 'linkprefix' => '/^(.*?)([a-zA-Z\x80-\xff]+)$/sD', # only translate this message to other languages if you have to change it
574577 'mainpagetext' => "<big>'''MediaWiki has been successfully installed.'''</big>",

Status & tagging log