From 0267606f57a816725c2a2e177a303fdd2c15d065 Mon Sep 17 00:00:00 2001 From: Jens Frank Date: Sun, 3 Apr 2005 07:01:29 +0000 Subject: [PATCH] Code cleanup. Database code should not be in EditPage.php. Moved to Article.php --- includes/Article.php | 29 +++++++++++++++++++++++++++++ includes/EditPage.php | 25 +++++++------------------ 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 6bf2ca654f..69833d3e88 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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; + } + + } diff --git a/includes/EditPage.php b/includes/EditPage.php index 7bfdcd6f7e..1eb87ab937 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -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 = '
'. wfMsg( 'templatesused' ) . ''; + $articleTemplates = $this->mArticle->getUsedTemplates(); + if ( count( $articleTemplates ) > 0 ) { + $templates = '
'. wfMsg( 'templatesused' ) . ''; } global $wgLivePreview, $wgStylePath; -- 2.20.1