* (bug 7918) Fix regression in display of "templates used on this page" for users...
authorAryeh Gregor <simetrical@users.mediawiki.org>
Mon, 20 Nov 2006 05:15:51 +0000 (05:15 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Mon, 20 Nov 2006 05:15:51 +0000 (05:15 +0000)
* 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
includes/EditPage.php
includes/Linker.php
languages/messages/MessagesEn.php

index a1b5dce..893baf2 100644 (file)
@@ -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
index f7ea868..762f045 100644 (file)
@@ -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( '<div id="wikiPreview"></div>' );
                        }
@@ -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( '<div id="wikiPreview"></div>' );
                        }
@@ -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( '<div id="wikiPreview">' );
                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();
                }
index 7be89e6..636aaf2 100644 (file)
@@ -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 = '<div class="mw-templatesUsedExplanation">' .
-                               wfMsgExt( 'templatesused', array( 'parse' ) ) .
+                               wfMsgExt( 'templatesused' . ( $preview ? 'preview' : ( $section ? 'section' : '' ) ), array( 'parse' ) ) .
                                '</div><ul>';
                        foreach ( $templates as $titleObj ) {
                                $outText .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>';
index bbcbce1..82daa7f 100644 (file)
@@ -979,6 +979,7 @@ the text into a text file and save it for later.</strong>',
 'semiprotectedpagewarning' => "'''Note:''' This page has been locked so that only registered users can edit it.",
 'templatesused'        => 'Templates used on this page:',
 'templatesusedpreview' => 'Templates used in this preview:',
+'templatesusedsection' => 'Templates used in this section:',
 'edittools' => '<!-- Text here will be shown below edit and upload forms. -->',
 'nocreatetitle' => 'Page creation limited',
 'nocreatetext' => 'This site has restricted the ability to create new pages.