Add support for parse warnings. Currently only displayed on preview, but can be put...
authorTim Starling <tstarling@users.mediawiki.org>
Mon, 10 Dec 2007 06:02:29 +0000 (06:02 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Mon, 10 Dec 2007 06:02:29 +0000 (06:02 +0000)
includes/EditPage.php
includes/OutputPage.php
includes/Parser.php
includes/ParserOutput.php

index 8bb9a78..ba0482e 100644 (file)
@@ -1448,17 +1448,12 @@ END
 
                if ( $this->mTriedSave && !$this->mTokenOk ) {
                        if ( $this->mTokenOkExceptSuffix ) {
-                               $msg = 'token_suffix_mismatch';
+                               $note = wfMsg( 'token_suffix_mismatch' );
                        } else {
-                               $msg = 'session_fail_preview';
+                               $note = wfMsg( 'session_fail_preview' );
                        }
                } else {
-                       $msg = 'previewnote';
-               }
-               $previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" .
-                       "<div class='previewnote'>" . $wgOut->parse( wfMsg( $msg ) ) . "</div>\n";
-               if ( $this->isConflict ) {
-                       $previewhead.='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
+                       $note = wfMsg( 'previewnote' );
                }
 
                $parserOptions = ParserOptions::newFromUser( $wgUser );
@@ -1484,8 +1479,7 @@ END
                        $parserOptions->setTidy(true);
                        $parserOutput = $wgParser->parse( $previewtext , $this->mTitle, $parserOptions );
                        $wgOut->addHTML( $parserOutput->mText );
-                       wfProfileOut( $fname );
-                       return $previewhead;
+                       $previewHTML = '';
                } else {
                        $toparse = $this->textbox1;
 
@@ -1511,9 +1505,19 @@ END
                                foreach ( array_keys( $template ) as $dbk)
                                        $this->mPreviewTemplates[] = Title::makeTitle($ns, $dbk);
 
-                       wfProfileOut( $fname );
-                       return $previewhead . $previewHTML;
+                       if ( count( $parserOutput->getWarnings() ) ) {
+                               $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
+                       }
                }
+
+               $previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" .
+                       "<div class='previewnote'>" . $wgOut->parse( $note ) . "</div>\n";
+               if ( $this->isConflict ) {
+                       $previewhead.='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
+               }
+
+               wfProfileOut( $fname );
+               return $previewhead . $previewHTML;
        }
 
        /**
index 68ddb1d..f1738bb 100644 (file)
@@ -30,6 +30,7 @@ class OutputPage {
        var $mNewSectionLink = false;
        var $mNoGallery = false;
        var $mPageTitleActionText = '';
+       var $mParseWarnings = array();
 
        /**
         * Constructor
@@ -379,6 +380,7 @@ class OutputPage {
                $this->addCategoryLinks( $parserOutput->getCategories() );
                $this->mNewSectionLink = $parserOutput->getNewSection();
                $this->addKeywords( $parserOutput );
+               $this->mParseWarnings = $parserOutput->getWarnings();
                if ( $parserOutput->getCacheTime() == -1 ) {
                        $this->enableClientCache( false );
                }
@@ -1385,5 +1387,5 @@ class OutputPage {
                        $this->addHtml( "<div class=\"mw-{$message}\">\n{$warning}\n</div>\n" );
                }
        }
-       
+
 }
index b05d26a..5b7d637 100644 (file)
@@ -5248,6 +5248,7 @@ class StripState {
  */
 class PPFrame {
        var $parser, $title;
+       var $titleCache;
 
        const NO_ARGS = 1;
        const NO_TEMPLATES = 2;
@@ -5261,6 +5262,7 @@ class PPFrame {
        function __construct( $parser ) {
                $this->parser = $parser;
                $this->title = $parser->mTitle;
+               $this->titleCache = array( $this->title->getPrefixedDBkey() );
        }
 
        /**
@@ -5445,19 +5447,30 @@ class PPFrame {
        function __toString() {
                return 'frame{}';
        }
+
+       function getPDBK( $level = false ) {
+               if ( $level === false ) {
+                       return $this->title->getPrefixedDBkey();
+               } else {
+                       return isset( $this->titleCache[$level] ) ? $this->titleCache[$level] : false;
+               }
+       }
 }
 
 /**
  * Expansion frame with template arguments
  */
 class PPTemplateFrame extends PPFrame {
-       public $parser, $args, $parent, $serial;
+       var $parser, $args, $parent;
+       var $titleCache;
 
        function __construct( $parser, $parent = false, $args = array(), $title = false ) {
                $this->parser = $parser;
                $this->parent = $parent;
                $this->args = $args;
                $this->title = $title;
+               $this->titleCache = $parent->titleCache;
+               $this->titleCache[] = $title->getPrefixedDBkey();
        }
 
        function __toString() {
index 5b79593..e7164f3 100644 (file)
@@ -20,7 +20,8 @@ class ParserOutput
                $mNewSection,       # Show a new section link?
                $mNoGallery,        # No gallery on category page? (__NOGALLERY__)
                $mHeadItems,        # Items to put in the <head> section
-               $mOutputHooks;      # Hook tags as per $wgParserOutputHooks
+               $mOutputHooks,      # Hook tags as per $wgParserOutputHooks
+               $mWarnings;         # Warning text to be returned to the user. Wikitext formatted.
        
        /**
         * Overridden title for display
@@ -46,6 +47,7 @@ class ParserOutput
                $this->mHeadItems = array();
                $this->mTemplateIds = array();
                $this->mOutputHooks = array();
+               $this->mWarnings = array();
        }
 
        function getText()                   { return $this->mText; }
@@ -61,6 +63,7 @@ class ParserOutput
        function getNoGallery()              { return $this->mNoGallery; }
        function getSubtitle()               { return $this->mSubtitle; }
        function getOutputHooks()            { return (array)$this->mOutputHooks; }
+       function getWarnings()               { return isset( $this->mWarnings ) ? $this->mWarnings : array(); }
 
        function containsOldMagic()          { return $this->mContainsOldMagic; }
        function setText( $text )            { return wfSetVar( $this->mText, $text ); }
@@ -73,6 +76,7 @@ class ParserOutput
        function addCategory( $c, $sort )    { $this->mCategories[$c] = $sort; }
        function addLanguageLink( $t )       { $this->mLanguageLinks[] = $t; }
        function addExternalLink( $url )     { $this->mExternalLinks[$url] = 1; }
+       function addWarning( $s )            { $this->mWarnings[] = $s; }
 
        function addOutputHook( $hook, $data = false ) { 
                $this->mOutputHooks[] = array( $hook, $data );