From 733cda1c26d075c0c9504c0a493bb2b3ab293464 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Mon, 20 Nov 2006 05:15:51 +0000 Subject: [PATCH] * (bug 7918) Fix regression in display of "templates used on this page" for users with edit form before preview * Make section edits show templates used in the section, not the page Patch by Mark Haidar (Fyren). I didn't change the Boolean params to class constants because they're currently called as ($this->preview, $this->section != ''), which is much more readable than the alternative. --- RELEASE-NOTES | 4 ++-- includes/EditPage.php | 19 ++++++++++++------- includes/Linker.php | 7 ++++--- languages/messages/MessagesEn.php | 1 + 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index a1b5dcece6..893baf2fb0 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -196,8 +196,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN $wgUseSiteJs is enabled, in addition to (if applicable) MediaWiki:Monobook.js and user JS subpages. * (bug 7918) "Templates used on this page" changes during preview to reflect - any added or removed templates. -* (bug 7918) "Templates used on this page" is now shown for read-only pages. + any added or removed templates, and works as expected for section edits. +* (bug 7919) "Templates used on this page" is now shown for read-only pages. * (bug 7688) When viewing diff, section anchors in autosummary jump to section on current page instead of loading the latest version. * (bug 7970) Use current connection explicitly on Database::getServerVersion diff --git a/includes/EditPage.php b/includes/EditPage.php index f7ea86831c..762f0453e2 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -928,6 +928,10 @@ class EditPage { $wgOut->addWikiText( wfMsg( 'longpagewarning', $wgLang->formatNum( $this->kblength ) ) ); } + #need to parse the preview early so that we know which templates are used, + #otherwise users with "show preview after edit box" will get a blank list + $previewOutput = $this->getPreviewText(); + $rows = $wgUser->getIntOption( 'rows' ); $cols = $wgUser->getIntOption( 'cols' ); @@ -1005,7 +1009,7 @@ class EditPage { if ( $wgUser->getOption( 'previewontop' ) ) { if ( 'preview' == $this->formtype ) { - $this->showPreview(); + $this->showPreview( $previewOutput ); } else { $wgOut->addHTML( '
' ); } @@ -1035,7 +1039,8 @@ class EditPage { if( !$this->preview && !$this->diff ) { $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' ); } - $templates = $sk->formatTemplates( $this->preview ? $this->mPreviewTemplates : $this->mArticle->getUsedTemplates() ); + $templates = ($this->preview || $this->section) ? $this->mPreviewTemplates : $this->mArticle->getUsedTemplates(); + $templates = $sk->formatTemplates( $templates, $this->preview, $this->section != ''); global $wgUseMetadataEdit ; if ( $wgUseMetadataEdit ) { @@ -1223,7 +1228,7 @@ END if ( !$wgUser->getOption( 'previewontop' ) ) { if ( $this->formtype == 'preview') { - $this->showPreview(); + $this->showPreview( $previewOutput ); } else { $wgOut->addHTML( '
' ); } @@ -1240,17 +1245,17 @@ END /** * Append preview output to $wgOut. * Includes category rendering if this is a category page. - * @private + * + * @param string $text The HTML to be output for the preview. */ - function showPreview() { + private function showPreview( $text ) { global $wgOut; $wgOut->addHTML( '
' ); if($this->mTitle->getNamespace() == NS_CATEGORY) { $this->mArticle->openShowCategory(); } - $previewOutput = $this->getPreviewText(); - $wgOut->addHTML( $previewOutput ); + $wgOut->addHTML( $text ); if($this->mTitle->getNamespace() == NS_CATEGORY) { $this->mArticle->closeShowCategory(); } diff --git a/includes/Linker.php b/includes/Linker.php index 7be89e6b11..636aaf2970 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -16,7 +16,6 @@ * @package MediaWiki */ class Linker { - function Linker() {} /** @@ -1133,9 +1132,11 @@ class Linker { * * @param array $templates Array of templates from Article::getUsedTemplate * or similar + * @param bool $preview Whether this is for a preview + * @param bool $section Whether this is for a section edit * @return string HTML output */ - public function formatTemplates($templates) { + public function formatTemplates( $templates, $preview = false, $section = false) { global $wgUser; wfProfileIn( __METHOD__ ); @@ -1152,7 +1153,7 @@ class Linker { # Construct the HTML $outText = '
' . - wfMsgExt( 'templatesused', array( 'parse' ) ) . + wfMsgExt( 'templatesused' . ( $preview ? 'preview' : ( $section ? 'section' : '' ) ), array( 'parse' ) ) . '