Cleanup for r39054 "Bug 15079, 'Add class="ns-talk" / "ns-subject" to <body>', also...
authorBrion Vibber <brion@users.mediawiki.org>
Sun, 10 Aug 2008 19:48:30 +0000 (19:48 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sun, 10 Aug 2008 19:48:30 +0000 (19:48 +0000)
* Avoid code duplication between Skin and SkinTemplate
* Encapsulate namespace class logic into one function
* Split giant huge line of ?:s with legible code :)

includes/Skin.php
includes/SkinTemplate.php
skins/MonoBook.php

index d4d4bde..abf2bb7 100644 (file)
@@ -588,13 +588,25 @@ END;
                }
                $a['onload'] = $wgOut->getOnloadHandler();
                $a['class'] =
-                       'mediawiki ns-'.$wgTitle->getNamespace().
+                       'mediawiki' .
+                       ' '.$this->getNamespaceClasses( $wgTitle ) .
                        ' '.( $wgContLang->isRTL() ? "rtl" : "ltr" ).
                        ' '.Sanitizer::escapeClass( 'page-'.$wgTitle->getPrefixedText() ).
-                       ' '. $wgTitle->isTalkPage() ? "ns-talk" : ( $wgTitle->getNamespace() == NS_SPECIAL ? "ns-special" : "ns-subject" ) .
                        ' skin-'. Sanitizer::escapeClass( $this->getSkinName( ) );
                return $a;
        }
+       
+       function getNamespaceClasses( $title ) {
+               $numeric = 'ns-'.$title->getNamespace();
+               if( $title->getNamespace() == NS_SPECIAL ) {
+                       $type = "ns-special";
+               } elseif( $title->isTalkPage() ) {
+                       $type = "ns-talk";
+               } else {
+                       $type = "ns-subject";
+               }
+               return "$numeric $type";
+       }
 
        /**
         * URL to the logo
index cbe7a71..c1b7cf9 100644 (file)
@@ -192,7 +192,6 @@ class SkinTemplate extends Skin {
                $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
                $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle );
                $tpl->set( 'pageclass', Sanitizer::escapeClass( 'page-'.$this->mTitle->getPrefixedText() ) );
-               $tpl->set( 'talkclass', ( $wgTitle->isTalkPage() ? "ns-talk" : ( $wgTitle->getNamespace() == NS_SPECIAL ? "ns-special" : "ns-subject" ) ) );
                $tpl->set( 'skinnameclass', ( "skin-" . Sanitizer::escapeClass( $this->getSkinName ( ) ) ) );
 
                $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] ) ?
@@ -255,7 +254,7 @@ class SkinTemplate extends Skin {
                $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
                $tpl->set( 'csslinks', $this->buildCssLinks() );
                $tpl->setRef( 'loggedin', $this->loggedin );
-               $tpl->set('nsclass', 'ns-'.$this->mTitle->getNamespace());
+               $tpl->set( 'nsclass', $this->getNamespaceClasses( $this->mTitle ) );
                $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL);
                /* XXX currently unused, might get useful later
                $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
index fc37c99..00399b1 100644 (file)
@@ -104,7 +104,7 @@ class MonoBookTemplate extends QuickTemplate {
        </head>
 <body<?php if($this->data['body_ondblclick']) { ?> ondblclick="<?php $this->text('body_ondblclick') ?>"<?php } ?>
 <?php if($this->data['body_onload']) { ?> onload="<?php $this->text('body_onload') ?>"<?php } ?>
- class="mediawiki <?php $this->text('nsclass') ?> <?php $this->text('dir') ?> <?php $this->text('pageclass') ?> <?php $this->text('talkclass') ?> <?php $this->text('skinnameclass') ?>">
+ class="mediawiki <?php $this->text('nsclass') ?> <?php $this->text('dir') ?> <?php $this->text('pageclass') ?> <?php $this->text('skinnameclass') ?>">
        <div id="globalWrapper">
                <div id="column-content">
        <div id="content">