Code cleanup. Database code should not be in EditPage.php. Moved to Article.php
authorJens Frank <jeluf@users.mediawiki.org>
Sun, 3 Apr 2005 07:01:29 +0000 (07:01 +0000)
committerJens Frank <jeluf@users.mediawiki.org>
Sun, 3 Apr 2005 07:01:29 +0000 (07:01 +0000)
includes/Article.php
includes/EditPage.php

index 6bf2ca6..69833d3 100644 (file)
@@ -2269,6 +2269,35 @@ class Article {
                
                return array( 'edits' => $edits, 'authors' => $authors );
        }
+
+       /**
+        * Return a list of templates used by this article.
+        * Uses the links table to find the templates
+        *
+        * @return array
+        */
+       function getUsedTemplates() {
+               $result = array();
+               $id = $this->mTitle->getArticleID();
+
+               $db =& wfGetDB( DB_SLAVE );
+               $page = $db->tableName( 'page' );
+               $links = $db->tableName( 'links' );
+               $sql = "SELECT page_title ".
+                       "FROM $page,$links WHERE l_to=page_id AND l_from={$id} and page_namespace=".NS_TEMPLATE;
+               $res = $db->query( $sql, "Article:getUsedTemplates" );
+               if ( false !== $res ) {
+                       if ( $db->numRows( $res ) ) {
+                               while ( $row = $db->fetchObject( $res ) ) {
+                                       $result[] = $row->page_title;
+                               }
+                       }
+               }
+               $db->freeResult( $res );
+               return $result;
+       }
+
+
 }
 
 
index 7bfdcd6..1eb87ab 100644 (file)
@@ -612,26 +612,15 @@ class EditPage {
                }
                # Prepare a list of templates used by this page
                $templates = '';
-               $id = $this->mTitle->getArticleID();
-               if ( 0 !== $id ) {
-                       $db =& wfGetDB( DB_SLAVE );
-                       $page = $db->tableName( 'page' );
-                       $links = $db->tableName( 'links' );
-                       $sql = "SELECT page_namespace,page_title,page_id ".
-                               "FROM $page,$links WHERE l_to=page_id AND l_from={$id} and page_namespace=".NS_TEMPLATE;
-                       $res = $db->query( $sql, "EditPage::editform" );
-                       if ( false !== $res ) {
-                               if ( $db->numRows( $res ) ) {
-                                       $templates = '<br />'. wfMsg( 'templatesused' ) . '<ul>';
-                                       while ( $row = $db->fetchObject( $res ) ) {
-                                               if ( $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title ) ) {
-                                                       $templates .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>';
-                                               }
-                                       }
-                                       $templates .= '</ul>';
+               $articleTemplates = $this->mArticle->getUsedTemplates();
+               if ( count( $articleTemplates ) > 0 ) {
+                       $templates = '<br />'. wfMsg( 'templatesused' ) . '<ul>';
+                       foreach ( $articleTemplates as $tpl ) {
+                               if ( $titleObj = Title::makeTitle( NS_TEMPLATE, $tpl ) ) {
+                                       $templates .= '<li>' . $sk->makeLinkObj( $titleObj ) . '</li>';
                                }
-                               $db->freeResult( $res );
                        }
+                       $templates .= '</ul>';
                }
                
                global $wgLivePreview, $wgStylePath;