Board of Trustees vote
[lhc/web/wiklou.git] / includes / OutputPage.php
index f42c9f8..e859ed2 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 # See design.doc
 
-if($wgUseTeX) include_once( "Math.php" );
+if($wgUseTeX) require_once( "Math.php" );
 
 class OutputPage {
        var $mHeaders, $mCookies, $mMetatags, $mKeywords;
@@ -44,11 +44,17 @@ class OutputPage {
        # To add an http-equiv meta tag, precede the name with "http:"
        function addMeta( $name, $val ) { array_push( $this->mMetatags, array( $name, $val ) ); }
        function addKeyword( $text ) { array_push( $this->mKeywords, $text ); }
-       function addLink( $rel, $rev, $target, $type="", $media="" ) { array_push( $this->mLinktags, array( $rel, $rev, $target, $type, $media ) ); }
+       
+       function addLink( $linkarr ) {
+               # $linkarr should be an associative array of attributes. We'll escape on output.
+               array_push( $this->mLinktags, $linkarr );
+       }
 
-       function addMetadataLink( $type, $target ) {
+       function addMetadataLink( $linkarr ) {
+               # note: buggy CC software only reads first "meta" link
                static $haveMeta = false;
-               $this->addLink( ($haveMeta) ? "alternate meta" : "meta", "", $target, $type );
+               $linkarr["rel"] = ($haveMeta) ? "alternate meta" : "meta";
+               $this->addLink( $linkarr );
                $haveMeta = true;
        }
 
@@ -103,9 +109,43 @@ class OutputPage {
                }
        }
 
+       function getPageTitleActionText () {
+               global $action;
+               switch($action) {
+                       case 'edit':
+                               return  wfMsg('edit');
+                       case 'history':
+                               return wfMsg('history_short');
+                       case 'protect':
+                               return wfMsg('unprotect');
+                       case 'unprotect':
+                               return wfMsg('unprotect');
+                       case 'delete':
+                               return wfMsg('delete');
+                       case 'watch':
+                               return wfMsg('watch');
+                       case 'unwatch':
+                               return wfMsg('unwatch');
+                       case 'submit':
+                               return wfMsg('preview');
+                       default:
+                               return '';
+               }
+       }
        function setRobotpolicy( $str ) { $this->mRobotpolicy = $str; }
-       function setHTMLtitle( $name ) { $this->mHTMLtitle = $name; }
-       function setPageTitle( $name ) { $this->mPagetitle = $name; }
+       function setHTMLTitle( $name ) {$this->mHTMLtitle = $name; }
+       function setPageTitle( $name ) {
+               global $action;
+               $this->mPagetitle = $name;
+               if(!empty($action)) {
+                       $taction =  $this->getPageTitleActionText();
+                       if( !empty( $taction ) ) {
+                               $name .= " - $taction";
+                       }
+               }
+               $this->setHTMLTitle( $name . " - " . wfMsg( "wikititlesuffix" ) );
+       }
+       function getHTMLTitle() { return $this->mHTMLtitle; }
        function getPageTitle() { return $this->mPagetitle; }
        function setSubtitle( $str ) { $this->mSubtitle = $str; }
        function getSubtitle() { return $this->mSubtitle; }
@@ -378,8 +418,8 @@ class OutputPage {
 
                $this->mDebugtext .= "Original title: " .
                  $wgTitle->getPrefixedText() . "\n";
-               $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
                $this->setPageTitle( wfMsg( $title ) );
+               $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
                $this->setRobotpolicy( "noindex,nofollow" );
                $this->setArticleRelated( false );
                $this->enableClientCache( false );
@@ -396,8 +436,8 @@ class OutputPage {
        {
                global $wgUser;
 
-               $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
                $this->setPageTitle( wfMsg( "sysoptitle" ) );
+               $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
                $this->setRobotpolicy( "noindex,nofollow" );
                $this->setArticleRelated( false );
                $this->mBodytext = "";
@@ -412,8 +452,8 @@ class OutputPage {
        {
                global $wgUser;
 
-               $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
                $this->setPageTitle( wfMsg( "developertitle" ) );
+               $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
                $this->setRobotpolicy( "noindex,nofollow" );
                $this->setArticleRelated( false );
                $this->mBodytext = "";
@@ -428,8 +468,8 @@ class OutputPage {
        {
                global $wgUser, $wgTitle, $wgLang;
 
-               $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
                $this->setPageTitle( wfMsg( "loginreqtitle" ) );
+               $this->setHTMLTitle( wfMsg( "errorpagetitle" ) );
                $this->setRobotpolicy( "noindex,nofollow" );
                $this->setArticleFlag( false );
                $this->mBodytext = "";
@@ -477,7 +517,7 @@ class OutputPage {
                wfAbruptExit();
        }
 
-       function readOnlyPage( $source = "", $protected = false )
+       function readOnlyPage( $source = null, $protected = false )
        {
                global $wgUser, $wgReadOnlyFile;
 
@@ -490,13 +530,16 @@ class OutputPage {
                } else {
                        $this->setPageTitle( wfMsg( "readonly" ) );
                        $reason = file_get_contents( $wgReadOnlyFile );
-                       $this->addHTML( wfMsg( "readonlytext", $reason ) );
+                       $this->addWikiText( wfMsg( "readonlytext", $reason ) );
                }
                
-               if($source) {
+               if( is_string( $source ) ) {
+                       if( strcmp( $source, "" ) == 0 ) {
+                               $source = wfMsg( "noarticletext" );
+                       }
                        $rows = $wgUser->getOption( "rows" );
                        $cols = $wgUser->getOption( "cols" );
-                       $text .= "</p>\n<textarea cols='$cols' rows='$rows' readonly>" .
+                       $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
                                htmlspecialchars( $source ) . "\n</textarea>";
                        $this->addHTML( $text );
                }
@@ -573,6 +616,12 @@ class OutputPage {
                $a = array_merge ( $good , $bad ) ;
                $a = array_slice ( $a , 0 , 10 ) ; # 10 keywords max
                $a = implode ( "," , $a ) ;
+               $strip = array(
+                       "/<.*?>/" => '',
+                       "/[_]/" => ' '
+               );
+               $a = htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),$a ));
+               
                $wgOut->addMeta ( "KEYWORDS" , $a ) ;
        }
 
@@ -588,10 +637,10 @@ class OutputPage {
                        $ret = "";
                }
                
-               $ret .= "<!DOCTYPE HTML PUBLIC \"$wgDocType\"\n        \"$wgDTD\">\n";
+               $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n        \"$wgDTD\">\n";
 
                if ( "" == $this->mHTMLtitle ) {
-                       $this->mHTMLtitle = $this->mPagetitle;
+                       $this->mHTMLtitle = wfMsg( "pagetitle", $this->mPagetitle );
                }
                if( $xml ) {
                        $xmlbits = "xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\"";
@@ -600,8 +649,30 @@ class OutputPage {
                }
                $rtl = $wgLang->isRTL() ? " dir='RTL'" : "";
                $ret .= "<html $xmlbits lang=\"$wgLanguageCode\" $rtl>\n";
-               $ret .= "<head>\n<title>{$this->mHTMLtitle}</title>\n";
+               $ret .= "<head>\n<title>" . htmlspecialchars( $this->mHTMLtitle ) . "</title>\n";
                array_push( $this->mMetatags, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
+               
+               $ret .= $this->getHeadLinks();
+               global $wgStylePath;
+               if( $this->isPrintable() ) {
+                       $media = "";
+               } else {
+                       $media = "media='print'";
+               }
+               $printsheet = htmlspecialchars( "$wgStylePath/wikiprintable.css" );
+               $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
+
+               $sk = $wgUser->getSkin();
+               $ret .= $sk->getHeadScripts();
+               $ret .= $sk->getUserStyles();
+
+               $ret .= "</head>\n";
+               return $ret;
+       }
+       
+       function getHeadLinks() {
+               global $wgRequest, $wgStylePath;
+               $ret = "";
                foreach ( $this->mMetatags as $tag ) {
                        if ( 0 == strcasecmp( "http:", substr( $tag[0], 0, 5 ) ) ) {
                                $a = "http-equiv";
@@ -616,35 +687,30 @@ class OutputPage {
                $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
 
                if ( count( $this->mKeywords ) > 0 ) {
+                       $strip = array(
+                               "/<.*?>/" => '',
+                               "/[_]/" => ' '
+                       );
                        $ret .= "<meta name=\"keywords\" content=\"" .
-                         implode( ",", $this->mKeywords ) . "\" />\n";
+                         htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords ))) . "\" />\n";
                }
                foreach ( $this->mLinktags as $tag ) {
-                       $ret .= "<link ";
-                       if ( "" != $tag[0] ) { $ret .= "rel=\"{$tag[0]}\" "; }
-                       if ( "" != $tag[1] ) { $ret .= "rev=\"{$tag[1]}\" "; }
-                       if ( !empty( $tag[3] ) ) { $ret .= "type=\"{$tag[3]}\" "; }
-                       if ( !empty( $tag[4] ) ) { $ret .= "media=\"{$tag[4]}\" "; }
-                       $ret .= "href=\"{$tag[2]}\" />\n";
+                       $ret .= "<link";
+                       foreach( $tag as $attr => $val ) {
+                               $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
+                       }
+                       $ret .= " />\n";
                }
                if( $this->isSyndicated() ) {
+                       # FIXME: centralize the mime-type and name information in Feed.php
                        $link = $wgRequest->escapeAppendQuery( "feed=rss" );
-                       $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS' href='$link' />\n";
+                       $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
+                       $link = $wgRequest->escapeAppendQuery( "feed=atom" );
+                       $ret .= "<link rel='alternate' type='application/rss+atom' title='Atom 0.3' href='$link' />\n";
                }
-               global $wgStyleSheetPath;
-               if( $this->isPrintable() ) {
-                       $media = "";
-               } else {
-                       $media = "media='print'";
-               }
-               $printsheet = htmlspecialchars( "$wgStyleSheetPath/wikiprintable.css" );
-               $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
-
-               $sk = $wgUser->getSkin();
-               $ret .= $sk->getHeadScripts();
-               $ret .= $sk->getUserStyles();
-
-               $ret .= "</head>\n";
+               # FIXME: get these working
+               # $fix = htmlspecialchars( $wgStylePath . "/ie-png-fix.js" );
+               # $ret .= "<!--[if gte IE 5.5000]><script type='text/javascript' src='$fix'></script><![endif]-->";
                return $ret;
        }
 }