Clean up last commit: OutputPage::formatTemplates + EditPage::formatTemplates ->...
authorAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 17 Nov 2006 03:42:23 +0000 (03:42 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 17 Nov 2006 03:42:23 +0000 (03:42 +0000)
includes/EditPage.php
includes/Linker.php
includes/OutputPage.php

index a98cc60..f7ea868 100644 (file)
@@ -1035,7 +1035,7 @@ class EditPage {
                if( !$this->preview && !$this->diff ) {
                        $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
                }
-               $templates = $this->formatTemplates();
+               $templates = $sk->formatTemplates( $this->preview ? $this->mPreviewTemplates : $this->mArticle->getUsedTemplates() );
 
                global $wgUseMetadataEdit ;
                if ( $wgUseMetadataEdit ) {
@@ -1257,41 +1257,6 @@ END
                $wgOut->addHTML( '</div>' );
        }
 
-       /**
-        * Prepare a list of templates used by this page.
-        *
-        * @return string HTML
-        * @todo Merge with OutputPage::formatTemplates()
-        */
-       function formatTemplates() {
-               global $wgUser;
-               wfProfileIn( __METHOD__  );
-
-               $sk =& $wgUser->getSkin();
-
-               $outText = '';
-               $templates = ( $this->preview ? $this->mPreviewTemplates : $this->mArticle->getUsedTemplates() );
-               if ( count( $templates ) > 0 ) {
-                       # Do a batch existence check
-                       $batch = new LinkBatch;
-                       foreach( $templates as $title ) {
-                               $batch->addObj( $title );
-                       }
-                       $batch->execute();
-
-                       # Construct the HTML
-                       $outText = '<div class="mw-templatesUsedExplanation">' .
-                               wfMsgExt( ( $this->preview ? 'templatesusedpreview' : 'templatesused' ), array( 'parse' ) ) .
-                               '</div><ul>';
-                       foreach ( $templates as $titleObj ) {
-                               $outText .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>';
-                       }
-                       $outText .= '</ul>';
-               }
-               wfProfileOut( __METHOD__  );
-               return $outText;
-       }
-
        /**
         * Live Preview lets us fetch rendered preview page content and
         * add it to the page without refreshing the whole page.
index ff86912..a1b48ab 100644 (file)
@@ -1119,5 +1119,40 @@ class Linker {
                        wfMsg('rollbacklink'),
                        'action=rollback&from=' . urlencode( $rev->getUserText() ) . $extraRollback ) .']</span>';
        }
+
+       /**
+        * Returns HTML for the "templates used on this page" list.
+        *
+        * @param array $templates Array of templates from Article::getUsedTemplate
+        * or similar
+        * @return string HTML output
+        */
+       public function formatTemplates($templates) {
+               global $wgUser;
+               wfProfileIn( __METHOD__ );
+
+               $sk =& $wgUser->getSkin();
+
+               $outText = '';
+               if ( count( $templates ) > 0 ) {
+                       # Do a batch existence check
+                       $batch = new LinkBatch;
+                       foreach( $templates as $title ) {
+                               $batch->addObj( $title );
+                       }
+                       $batch->execute();
+
+                       # Construct the HTML
+                       $outText = '<div class="mw-templatesUsedExplanation">' .
+                               wfMsgExt( 'templatesused', array( 'parse' ) ) .
+                               '</div><ul>';
+                       foreach ( $templates as $titleObj ) {
+                               $outText .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>';
+                       }
+                       $outText .= '</ul>';
+               }
+               wfProfileOut( __METHOD__  );
+               return $outText;
+       }
 }
 ?>
index cea0011..b1bc128 100644 (file)
@@ -854,12 +854,12 @@ class OutputPage {
         */
        public function readOnlyPage( $source = null, $protected = false ) {
                global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
+               $skin = $wgUser->getSkin();
 
                $this->setRobotpolicy( 'noindex,nofollow' );
                $this->setArticleRelated( false );
 
                if( $protected ) {
-                       $skin = $wgUser->getSkin();
                        $this->setPageTitle( wfMsg( 'viewsource' ) );
                        $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) );
 
@@ -896,7 +896,8 @@ class OutputPage {
                                htmlspecialchars( $source ) . "\n</textarea>";
                        $this->addHTML( $text );
                }
-               $this->formatTemplates();
+               $article = new Article($wgTitle);
+               $this->addHTML( $skin->formatTemplates($article->getUsedTemplates()) );
 
                $this->returnToMain( false );
        }
@@ -1135,44 +1136,5 @@ class OutputPage {
        public function showNewSectionLink() {
                return $this->mNewSectionLink;
        }
-
-       /**
-        * Outputs the "templates used on this page" list.
-        *
-        * Stolen from EditPage::formatTemplates.  Should be merged, but there are
-        * slightly fiddly bits involving previews and so on that will have to be
-        * dealt with, so I'll just copy it for now because I'm lazy.
-        *
-        * @return nothing
-        */
-       function formatTemplates() {
-               global $wgUser, $wgTitle;
-               wfProfileIn( __METHOD__ );
-
-               $sk =& $wgUser->getSkin();
-
-               $outText = '';
-               $article = new Article($wgTitle);
-               $templates = $article->getUsedTemplates();
-               if ( count( $templates ) > 0 ) {
-                       # Do a batch existence check
-                       $batch = new LinkBatch;
-                       foreach( $templates as $title ) {
-                               $batch->addObj( $title );
-                       }
-                       $batch->execute();
-
-                       # Construct the HTML
-                       $outText = '<div class="mw-templatesUsedExplanation">' .
-                               wfMsgExt( 'templatesused', array( 'parse' ) ) .
-                               '</div><ul>';
-                       foreach ( $templates as $titleObj ) {
-                               $outText .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>';
-                       }
-                       $outText .= '</ul>';
-               }
-               wfProfileOut( __METHOD__  );
-               $this->addHTML($outText);
-       }
 }
 ?>