preview status in page title
[lhc/web/wiklou.git] / includes / OutputPage.php
index ee10dcc..7d514cf 100644 (file)
@@ -44,7 +44,19 @@ 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( $linkarr ) {
+               # note: buggy CC software only reads first "meta" link
+               static $haveMeta = false;
+               $linkarr["rel"] = ($haveMeta) ? "alternate meta" : "meta";
+               $this->addLink( $linkarr );
+               $haveMeta = true;
+       }
 
        # checkLastModified tells the client to use the client-cached page if
        # possible. If sucessful, the OutputPage is disabled so that
@@ -239,7 +251,7 @@ class OutputPage {
        {
                global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
                global $wgInputEncoding, $wgOutputEncoding, $wgLanguageCode;
-               global $wgDebugRedirects;
+               global $wgDebugRedirects, $wgMimeType;
                if( $this->mDoNothing ){
                        return;
                }
@@ -277,7 +289,7 @@ class OutputPage {
                
                $this->sendCacheControl();
                
-               header( "Content-type: text/html; charset={$wgOutputEncoding}" );
+               header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
                header( "Content-language: {$wgLanguageCode}" );
 
                $exp = time() + $wgCookieExpiration;
@@ -379,7 +391,7 @@ class OutputPage {
                $this->enableClientCache( false );
 
                $this->mBodytext = "";
-               $this->addHTML( "<p>" . wfMsg( $msg ) . "\n" );
+               $this->addHTML( "<p>" . wfMsg( $msg ) . "</p>\n" );
                $this->returnToMain( false );
 
                $this->output();
@@ -490,7 +502,7 @@ class OutputPage {
                if($source) {
                        $rows = $wgUser->getOption( "rows" );
                        $cols = $wgUser->getOption( "cols" );
-                       $text .= "</p>\n<textarea cols='$cols' rows='$rows' readonly>" .
+                       $text = "</p>\n<textarea cols='$cols' rows='$rows' readonly>" .
                                htmlspecialchars( $source ) . "\n</textarea>";
                        $this->addHTML( $text );
                }
@@ -535,9 +547,13 @@ class OutputPage {
                $this->fatalError( wfMsg( "filenotfound", $name ) );
        }
 
-       function returnToMain( $auto = true )
+       function returnToMain( $auto = true, $returnto = NULL )
        {
-               global $wgUser, $wgOut, $returnto;
+               global $wgUser, $wgOut, $wgRequest;
+               
+               if ( $returnto == NULL ) {
+                       $returnto = $wgRequest->getText( 'returnto' );
+               }
 
                $sk = $wgUser->getSkin();
                if ( "" == $returnto ) {
@@ -550,7 +566,7 @@ class OutputPage {
                        $titleObj = Title::newFromText( $returnto );
                        $wgOut->addMeta( "http:Refresh", "10;url=" . $titleObj->escapeFullURL() );
                }
-               $wgOut->addHTML( "\n<p>$r\n" );
+               $wgOut->addHTML( "\n<p>$r</p>\n" );
        }
 
        # This function takes the existing and broken links for the page
@@ -563,21 +579,63 @@ 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 ) ;
        }
 
        /* private */ function headElement()
        {
-               global $wgDocType, $wgDTD, $wgUser, $wgLanguageCode, $wgOutputEncoding, $wgLang, $wgRequest;
+               global $wgDocType, $wgDTD, $wgLanguageCode, $wgOutputEncoding, $wgMimeType;
+               global $wgUser, $wgLang, $wgRequest;
 
-               $ret = "<!DOCTYPE HTML PUBLIC \"$wgDocType\"\n        \"$wgDTD\">\n";
+               $xml = ($wgMimeType == 'text/xml');
+               if( $xml ) {
+                       $ret = "<" . "?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?" . ">\n";
+               } else {
+                       $ret = "";
+               }
+               
+               $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\"";
+               } else {
+                       $xmlbits = "";
                }
                $rtl = $wgLang->isRTL() ? " dir='RTL'" : "";
-               $ret .= "<html lang=\"$wgLanguageCode\"$rtl><head><title>{$this->mHTMLtitle}</title>\n";
-               array_push( $this->mMetatags, array( "http:Content-type", "text/html; charset={$wgOutputEncoding}" ) );
+               $ret .= "<html $xmlbits lang=\"$wgLanguageCode\" $rtl>\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 $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";
+               return $ret;
+       }
+       
+       function getHeadLinks() {
+               global $wgRequest, $wgStyleSheetPath;
+               $ret = "";
                foreach ( $this->mMetatags as $tag ) {
                        if ( 0 == strcasecmp( "http:", substr( $tag[0], 0, 5 ) ) ) {
                                $a = "http-equiv";
@@ -585,42 +643,34 @@ class OutputPage {
                        } else {
                                $a = "name";
                        }
-                       $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\">\n";
+                       $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
                }
                $p = $this->mRobotpolicy;
                if ( "" == $p ) { $p = "index,follow"; }
-               $ret .= "<meta name=\"robots\" content=\"$p\">\n";
+               $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() ) {
                        $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' 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( $wgStyleSheetPath . "/ie-png-fix.js" );
+               # $ret .= "<!--[if gte IE 5.5000]><script type='text/javascript' src='$fix'></script><![endif]-->";
                return $ret;
        }
 }