Start on compatibility with PHPTAL 1.0 (on PHP5).
authorBrion Vibber <brion@users.mediawiki.org>
Sun, 26 Sep 2004 01:56:43 +0000 (01:56 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sun, 26 Sep 2004 01:56:43 +0000 (01:56 +0000)
Currently requires that PHPTAL 1.0.0d2 be separately installed and hacked up a little, and $wgUsePHPTal manually enabled.

includes/SkinPHPTal.php
skins/MonoBook.pt

index fee3ea0..dc18f99 100644 (file)
 if( defined( 'MEDIAWIKI' ) ) {
 
 require_once 'GlobalFunctions.php';
-global $IP;
-require_once $IP.'/PHPTAL-NP-0.7.0/libs/PHPTAL.php';
+
+if( version_compare( phpversion(), "5.0", "lt" ) ) {
+       define( 'OLD_PHPTAL', true );
+       global $IP;
+       require_once $IP.'/PHPTAL-NP-0.7.0/libs/PHPTAL.php';
+} else {
+       define( 'NEW_PHPTAL', true );
+       # 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
  */
-class MediaWiki_I18N extends PHPTAL_I18N {
+//class MediaWiki_I18N extends PHPTAL_I18N {
+class MediaWiki_I18N {
        var $_context = array();
 
        function set($varName, $value) {
@@ -63,8 +75,18 @@ class MediaWiki_I18N extends PHPTAL_I18N {
                }
                return $value;
        }
-}
 
+       /* For PHPTAL 1.0: */
+       function setLanguage( $langCode ) {
+       }
+       
+       function setDomain( $domain ) {
+       }
+       
+       function setVar( $key, $value ) {
+               $this->set( $key, $value );
+       }
+}
 /**
  *
  * @package MediaWiki
@@ -102,6 +124,20 @@ class SkinPHPTal extends Skin {
                $this->template  = 'MonoBook';
        }
 
+       /**
+        * If using PHPTAL 0.7 on PHP 4.x, return a PHPTAL template object.
+        * If using PHPTAL 1.0 on PHP 5.x, return a bridge object.
+        * @return object
+        * @access private
+        */
+       function &setupTemplate( $file, $repository=false, $cache_dir=false ) {
+               if( NEW_PHPTAL ) {
+                       return new PHPTAL_version_bridge( $file, $repository, $cache_dir );
+               } else {
+                       return new PHPTAL( $file, $repository, $cache_dir );
+               }
+       }
+       
        /**
         * initialize various variables and generate the template
         */
@@ -115,7 +151,7 @@ class SkinPHPTal extends Skin {
                extract( $wgRequest->getValues( 'oldid', 'diff' ) );
 
                $this->initPage( $out );
-               $tpl = new PHPTAL($this->template . '.pt', 'skins');
+               $tpl =& $this->setupTemplate( $this->template . '.pt', 'skins' );
 
                #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
                $tpl->setTranslator(new MediaWiki_I18N());
@@ -163,6 +199,8 @@ class SkinPHPTal extends Skin {
                                );
                        }
                        $tpl->setRef( 'feeds', $feeds );
+               } else {
+                       $tpl->set( 'feeds', false );
                }
                $tpl->setRef( 'mimetype', $wgMimeType );
                $tpl->setRef( 'charset', $wgOutputEncoding );
@@ -228,19 +266,27 @@ class SkinPHPTal extends Skin {
                                }
                        }
                        $tpl->set('lastmod', $this->lastModified());
-                               $tpl->set('copyright',$this->getCopyright());
+                       $tpl->set('copyright',$this->getCopyright());
 
-                               $this->credits = false;
+                       $this->credits = false;
 
-                               if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
-                                       require_once("Credits.php");
-                                       $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
-                               }
+                       if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
+                               require_once("Credits.php");
+                               $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
+                       }
 
-                                       $tpl->setRef( 'credits', $this->credits );
+                       $tpl->setRef( 'credits', $this->credits );
 
                } elseif ( isset( $oldid ) && !isset( $diff ) ) {
                        $tpl->set('copyright', $this->getCopyright());
+                       $tpl->set('viewcount', false);
+                       $tpl->set('lastmod', false);
+                       $tpl->set('credits', false);
+               } else {
+                       $tpl->set('copyright', false);
+                       $tpl->set('viewcount', false);
+                       $tpl->set('lastmod', false);
+                       $tpl->set('credits', false);
                }
 
                $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
@@ -274,9 +320,9 @@ class SkinPHPTal extends Skin {
                // XXX: attach this from javascript, same with section editing
                if($this->iseditable && $wgUser->getOption("editondblclick") )
                {
-                       $tpl->set('body-ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
+                       $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
                } else {
-                       $tpl->set('body-ondblclick', false);
+                       $tpl->set('body_ondblclick', false);
                }
                $tpl->set( 'nav_urls', $this->buildNavUrls() );
 
@@ -527,14 +573,16 @@ class SkinPHPTal extends Skin {
                $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'] = (wfMsgForContent('currentevents') != '-') ? array('href' => htmlspecialchars( $this->makeI18nUrl('currentevents'))) : false;
-               $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ? array('href' => htmlspecialchars( $this->makeI18nUrl('portal-url'))) : false;
+               $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')));
                if( $this->loggedin && !$wgDisableUploads ) {
                        $nav_urls['upload'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Upload')));
+               } else {
+                       $nav_urls['upload'] = false;
                }
                $nav_urls['specialpages'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Specialpages')));
 
@@ -555,7 +603,10 @@ class SkinPHPTal extends Skin {
                        $nav_urls['contributions'] = array(
                                'href' => htmlspecialchars( $this->makeSpecialUrl('Contributions', "target=" . $wgTitle->getPartialURL() ) )
                        );
+               } else {
+                       $nav_urls['contributions'] = false;
                }
+               $nav_urls['emailuser'] = false;
                if ( 0 != $wgUser->getID() ) { # show only to signed in users
                        if($id) {       # can only email non-anons
                                $nav_urls['emailuser'] = array(
@@ -678,5 +729,41 @@ class SkinPHPTal extends Skin {
        }
 }
 
+class PHPTAL_version_bridge {
+       function PHPTAL_version_bridge( $file, $repository=false, $cache_dir=false ) {
+               $this->tpl =& new PHPTAL( $file );
+               if( $repository ) {
+                       $this->tpl->setTemplateRepository( $repository );
+               }
+       }
+       
+       function set( $name, $value ) {
+               $this->tpl->$name = $value;
+       }
+       
+       function setRef($name, &$value) {
+               $this->set( $name, $value );
+       }
+       
+       function setTranslator( &$t ) {
+               $this->tpl->setTranslator( $t );
+       }
+       
+       function execute() {
+               /*
+               try {
+               */
+                       return $this->tpl->execute();
+               /*
+               }
+               catch (Exception $e) {
+                       echo "<div class='error' style='background: white; white-space: pre; position: absolute; z-index: 9999; border: solid 2px black; padding: 4px;'>We caught an exception...\n ";
+                       echo $e;
+                       echo "</div>";
+               }
+               */
+       }
+}
+
 } // end of if( defined( 'MEDIAWIKI' ) ) 
 ?>
index 199ddf8..a076a85 100644 (file)
     <script type="text/javascript" tal:attributes="src jsvarurl"></script>
     <script type="text/javascript" src="${stylepath}/common/wikibits.js"></script>
     <style tal:condition="usercss" type="text/css">/*<![CDATA[*/ ${usercss} /*]]>*/</style>
-    <script tal:condition="userjs" type="text/javascript" tal:attributes="src userjs"></script><script 
+    <script tal:condition="userjs" type="text/javascript" tal:attributes="src userjs">/**/</script><script 
       tal:condition="userjsprev" type="text/javascript">/*<![CDATA[*/${userjsprev}/*]]>*/</script>
   </head>
-  <body tal:attributes="ondblclick body-ondblclick|default; class nsclass|default">
+  <body tal:attributes="ondblclick body_ondblclick|default; class nsclass|default">
     <div id="globalWrapper">
       <div id="column-content">
        <div id="content">
-         <a name="top" id="contentTop"></a>
+         <a name="top" id="contentTop"><!-- buffer for PHPTAL --></a>
          <div id="siteNotice" tal:condition="sitenotice" tal:content="structure sitenotice"></div>
          <h1 class="firstHeading" tal:content="title">Leonardo da Vinci</h1>
          <div id="bodyContent">
@@ -31,7 +31,7 @@
            ${bodytext}
            <div tal:condition="catlinks" id="catlinks" tal:content="structure catlinks"></div>
            <!-- end content -->
-           <div class="visualClear"></div>
+           <div class="visualClear"><!-- --></div>
          </div>
        </div>
       </div>
                  tal:attributes="href feed/href;"
                  tal:content="feed/text">rss</a>&nbsp;</span>
              </li>
-             <li id="t-contributions" tal:condition="nav_urls/contributions/href"><a href="${nav_urls/contributions/href}"
+             <li id="t-contributions" tal:condition="nav_urls/contributions"><a href="${nav_urls/contributions/href}"
                i18n:translate="string:contributions">Contributions</a></li>
-             <li id="t-emailuser" tal:condition="nav_urls/emailuser/href"><a href="${nav_urls/emailuser/href}"
+             <li id="t-emailuser" tal:condition="nav_urls/emailuser"><a href="${nav_urls/emailuser/href}"
                i18n:translate="string:emailuser">Email this user</a></li>
-             <li id="t-upload" tal:condition="nav_urls/upload/href"><a href="${nav_urls/upload/href}"
+             <li id="t-upload" tal:condition="nav_urls/upload"><a href="${nav_urls/upload/href}"
                i18n:translate="string:upload">Upload a file</a></li>
              <li id="t-specialpages"><a href="${nav_urls/specialpages/href}"
                i18n:translate="string:specialpages">Special Pages</a></li>