From 9f52185cec2416605af287b898ac1c5c95e37ac1 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Mon, 10 Dec 2007 06:02:29 +0000 Subject: [PATCH] Add support for parse warnings. Currently only displayed on preview, but can be put in other places if desired. --- includes/EditPage.php | 28 ++++++++++++++++------------ includes/OutputPage.php | 4 +++- includes/Parser.php | 15 ++++++++++++++- includes/ParserOutput.php | 6 +++++- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 8bb9a78a42..ba0482e945 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -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 = '

' . htmlspecialchars( wfMsg( 'preview' ) ) . "

\n" . - "
" . $wgOut->parse( wfMsg( $msg ) ) . "
\n"; - if ( $this->isConflict ) { - $previewhead.='

' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "

\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 = '

' . htmlspecialchars( wfMsg( 'preview' ) ) . "

\n" . + "
" . $wgOut->parse( $note ) . "
\n"; + if ( $this->isConflict ) { + $previewhead.='

' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "

\n"; + } + + wfProfileOut( $fname ); + return $previewhead . $previewHTML; } /** diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 68ddb1dbd4..f1738bb9a3 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -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( "
\n{$warning}\n
\n" ); } } - + } diff --git a/includes/Parser.php b/includes/Parser.php index b05d26a5f7..5b7d637647 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -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() { diff --git a/includes/ParserOutput.php b/includes/ParserOutput.php index 5b795939b4..e7164f3549 100644 --- a/includes/ParserOutput.php +++ b/includes/ParserOutput.php @@ -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 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 ); -- 2.20.1