Implementing user levels management. This is only a very basic interface and several...
[lhc/web/wiklou.git] / includes / SkinPHPTal.php
index dc18f99..9a68314 100644 (file)
@@ -47,14 +47,13 @@ if( version_compare( phpversion(), "5.0", "lt" ) ) {
        # For now, PHPTAL 1.0.x must be installed via PEAR in system dir.
        require_once 'PEAR.php';
        require_once 'PHPTAL.php';
-       require_once 'PHPTAL/Attribute.php';
-       require_once 'PHPTAL/Attribute/I18N/Attributes.php';
 }
 
 /**
  * @todo document
  * @package MediaWiki
  */
+// PHPTAL 1.0 no longer has the PHPTAL_I18N stub class.
 //class MediaWiki_I18N extends PHPTAL_I18N {
 class MediaWiki_I18N {
        var $_context = array();
@@ -64,6 +63,9 @@ class MediaWiki_I18N {
        }
 
        function translate($value) {
+               // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
+               $value = preg_replace( '/^string:/', '', $value );
+               
                $value = wfMsg( $value );
                // interpolate variables
                while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
@@ -75,17 +77,6 @@ class MediaWiki_I18N {
                }
                return $value;
        }
-
-       /* For PHPTAL 1.0: */
-       function setLanguage( $langCode ) {
-       }
-       
-       function setDomain( $domain ) {
-       }
-       
-       function setVar( $key, $value ) {
-               $this->set( $key, $value );
-       }
 }
 /**
  *
@@ -131,7 +122,7 @@ class SkinPHPTal extends Skin {
         * @access private
         */
        function &setupTemplate( $file, $repository=false, $cache_dir=false ) {
-               if( NEW_PHPTAL ) {
+               if( defined( 'NEW_PHPTAL' ) ) {
                        return new PHPTAL_version_bridge( $file, $repository, $cache_dir );
                } else {
                        return new PHPTAL( $file, $repository, $cache_dir );
@@ -217,7 +208,6 @@ class SkinPHPTal extends Skin {
                $tpl->set( "watch", $wgTitle->userIsWatching() ? "unwatch" : "watch" );
                $tpl->set( "protect", count($wgTitle->getRestrictions()) ? "unprotect" : "protect" );
                $tpl->set( "helppage", wfMsg('helppage'));
-               $tpl->set( "sysop", $wgUser->isSysop() );
                */
                $tpl->set( 'searchaction', $this->escapeSearchLink() );
                $tpl->setRef( 'stylepath', $wgStylePath );
@@ -263,6 +253,8 @@ class SkinPHPTal extends Skin {
                                $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
                                if ( $viewcount ) {
                                        $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
+                               } else {
+                                       $tpl->set('viewcount', false);
                                }
                        }
                        $tpl->set('lastmod', $this->lastModified());
@@ -302,6 +294,7 @@ class SkinPHPTal extends Skin {
                $out->mBodytext .= $printfooter ;
                $tpl->setRef( 'bodytext', $out->mBodytext );
 
+               # Language links
                $language_urls = array();
                foreach( $wgOut->getLanguageLinks() as $l ) {
                        $nt = Title::newFromText( $l );
@@ -314,6 +307,8 @@ class SkinPHPTal extends Skin {
                } else {
                        $tpl->set('language_urls', false);
                }
+
+               # Personal toolbar
                $tpl->set('personal_urls', $this->buildPersonalUrls());
                $content_actions = $this->buildContentActionUrls();
                $tpl->setRef('content_actions', $content_actions);
@@ -324,6 +319,7 @@ class SkinPHPTal extends Skin {
                } else {
                        $tpl->set('body_ondblclick', false);
                }
+               $tpl->set( 'navigation_urls', $this->buildNavigationUrls() );
                $tpl->set( 'nav_urls', $this->buildNavUrls() );
 
                // execute template
@@ -441,7 +437,7 @@ class SkinPHPTal extends Skin {
                        }
 
                        if ( $wgTitle->userCanEdit() ) {
-                               $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.$oldid : false;
+                               $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.IntVal( $oldid ) : false;
                                $istalk = ( Namespace::isTalk( $wgTitle->getNamespace()) );
                                $istalkclass = $istalk?' istalk':'';
                                $content_actions['edit'] = array(
@@ -457,7 +453,7 @@ class SkinPHPTal extends Skin {
                                        );
                                }
                        } else {
-                                       $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.$oldid : '';
+                                       $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.IntVal( $oldid ) : '';
                                $content_actions['viewsource'] = array('class' => ($action == 'edit') ? 'selected' : false,
                                'text' => wfMsg('viewsource'),
                                'href' => $this->makeUrl($this->thispage, 'action=edit'.$oid));
@@ -477,9 +473,10 @@ class SkinPHPTal extends Skin {
                                        'href' => $this->makeUrl($this->thispage, 'action=rollback'),
                                        'ttip' => wfMsg('tooltip-rollback'),
                                        'akey' => wfMsg('accesskey-rollback'));
-                               }*/
+                               }
+                               */
 
-                               if($wgUser->isSysop()){
+                               if($wgUser->isAllowed('protect')){
                                        if(!$wgTitle->isProtected()){
                                                $content_actions['protect'] = array(
                                                        'class' => ($action == 'protect') ? 'selected' : false,
@@ -494,6 +491,8 @@ class SkinPHPTal extends Skin {
                                                        'href' => $this->makeUrl($this->thispage, 'action=unprotect')
                                                );
                                        }
+                               }
+                               if($wgUser->isAllowed('delete')){
                                        $content_actions['delete'] = array(
                                                'class' => ($action == 'delete') ? 'selected' : false,
                                                'text' => wfMsg('delete'),
@@ -506,18 +505,13 @@ class SkinPHPTal extends Skin {
                                                'text' => wfMsg('move'),
                                                'href' => $this->makeSpecialUrl('Movepage', 'target='. urlencode( $this->thispage ))
                                        );
-                                       } else {
-                                               $content_actions['move'] = array('class' => 'inactive',
-                                               'text' => wfMsg('move'),
-                                               'href' => false);
-
                                        }
                                }
                        } else {
                                //article doesn't exist or is deleted
-                               if($wgUser->isSysop()){
+                               if($wgUser->isAllowed('delete')){
                                        if( $n = $wgTitle->isDeleted() ) {
-                                               $content_actions['delete'] = array(
+                                               $content_actions['undelete'] = array(
                                                        'class' => false,
                                                        'text' => wfMsg( "undelete_short", $n ),
                                                        'href' => $this->makeSpecialUrl('Undelete/'.$this->thispage)
@@ -558,6 +552,24 @@ class SkinPHPTal extends Skin {
                return $content_actions;
        }
 
+       /**
+        * build array of global navigation links
+        */ 
+       function buildNavigationUrls () {
+               global $wgNavigationLinks;
+               $result = array();
+               foreach ( $wgNavigationLinks as $link ) {
+                       if (wfMsg( $link['text'] ) != '-') {
+                           $result[] = array(
+                                                                 'text' => wfMsg( $link['text'] ),
+                                                                 'href' => $this->makeInternalOrExternalUrl( wfMsgForContent( $link['href'] ) ),
+                                                                 'id' => 'n-'.$link['text']
+                                                                 );
+                       }
+               }
+               return $result;
+       }
+
        /**
         * build array of common navigation links
         */
@@ -570,25 +582,25 @@ class SkinPHPTal extends Skin {
                $diff = $wgRequest->getVal( 'diff' );
                // XXX: remove htmlspecialchars when tal:attributes works with i18n:attributes
                $nav_urls = array();
-               $nav_urls['mainpage'] = array('href' => htmlspecialchars( $this->makeI18nUrl('mainpage')));
-               $nav_urls['randompage'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Randompage')));
-               $nav_urls['recentchanges'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Recentchanges')));
-               $nav_urls['currentevents'] = (wfMsg('currentevents') != '-') ? array('href' => htmlspecialchars( $this->makeI18nUrl('currentevents'))) : false;
-               $nav_urls['portal'] = (wfMsg('portal') != '-') ? array('href' => htmlspecialchars( $this->makeI18nUrl('portal-url'))) : false;
-               $nav_urls['bugreports'] = array('href' => htmlspecialchars( $this->makeI18nUrl('bugreportspage')));
-               // $nav_urls['sitesupport'] = array('href' => htmlspecialchars( $this->makeI18nUrl('sitesupportpage')));
-               $nav_urls['sitesupport'] = array('href' => htmlspecialchars( $wgSiteSupportPage));
-               $nav_urls['help'] = array('href' => htmlspecialchars( $this->makeI18nUrl('helppage')));
+               $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
+               $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Randompage'));
+               $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
+               $nav_urls['currentevents'] = (wfMsg('currentevents') != '-') ? array('href' => $this->makeI18nUrl('currentevents')) : false;
+               $nav_urls['portal'] =  (wfMsg('portal') != '-') ? array('href' => $this->makeI18nUrl('portal-url')) : false;
+               $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
+               // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
+               $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
+               $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
                if( $this->loggedin && !$wgDisableUploads ) {
-                       $nav_urls['upload'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Upload')));
+                       $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
                } else {
                        $nav_urls['upload'] = false;
                }
-               $nav_urls['specialpages'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Specialpages')));
+               $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
 
                if( $wgTitle->getNamespace() != NS_SPECIAL) {
-               $nav_urls['whatlinkshere'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Whatlinkshere', 'target='.urlencode( $this->thispage ))));
-               $nav_urls['recentchangeslinked'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Recentchangeslinked', 'target='.urlencode( $this->thispage ))));
+               $nav_urls['whatlinkshere'] = array('href' => $this->makeSpecialUrl('Whatlinkshere', 'target='.urlencode( $this->thispage)));
+               $nav_urls['recentchangeslinked'] = array('href' => $this->makeSpecialUrl('Recentchangeslinked', 'target='.urlencode( $this->thispage)));
                }
 
                if( $wgTitle->getNamespace() == NS_USER || $wgTitle->getNamespace() == NS_USER_TALK ) {
@@ -601,7 +613,7 @@ class SkinPHPTal extends Skin {
 
                if($id || $ip) { # both anons and non-anons have contri list
                        $nav_urls['contributions'] = array(
-                               'href' => htmlspecialchars( $this->makeSpecialUrl('Contributions', "target=" . $wgTitle->getPartialURL() ) )
+                               'href' => $this->makeSpecialUrl('Contributions', "target=" . $wgTitle->getPartialURL() )
                        );
                } else {
                        $nav_urls['contributions'] = false;
@@ -610,7 +622,7 @@ class SkinPHPTal extends Skin {
                if ( 0 != $wgUser->getID() ) { # show only to signed in users
                        if($id) {       # can only email non-anons
                                $nav_urls['emailuser'] = array(
-                                       'href' => htmlspecialchars( $this->makeSpecialUrl('Emailuser', "target=" . $wgTitle->getPartialURL() ) )
+                                       'href' => $this->makeSpecialUrl('Emailuser', "target=" . $wgTitle->getPartialURL() )
                                );
                        }
                }
@@ -687,6 +699,10 @@ class SkinPHPTal extends Skin {
                                $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype=text/javascript&dontcountme=s');
                        }
                }
+               $this->usercss = '/*<![CDATA[*/ ' . $this->usercss . ' /*]]>*/';
+               if( $this->userjsprev ) {
+                       $this->userjsprev = '/*<![CDATA[*/ ' . $this->userjsprev . ' /*]]>*/';
+               }
        }
        
        /**