From dfd903ce581b74a020f7903d5f6aa957cfe4287f Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Tue, 17 Feb 2009 19:03:40 +0000 Subject: [PATCH] General cleanup of SQL in Title and File. Fixes bug 17392: 'FOR UPDATE' should be passed in an array, not as a string. --- includes/Title.php | 20 ++++++++++---------- includes/filerepo/File.php | 13 +++++++------ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index c919ab0d8a..ae0f9867d8 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -2418,13 +2418,13 @@ class Title { * WARNING: do not use this function on arbitrary user-supplied titles! * On heavily-used templates it will max out the memory. * - * @param $options \type{\string} may be FOR UPDATE + * @param array $options may be FOR UPDATE * @return \type{\arrayof{Title}} the Title objects linking here */ - public function getLinksTo( $options = '', $table = 'pagelinks', $prefix = 'pl' ) { + public function getLinksTo( $options = array(), $table = 'pagelinks', $prefix = 'pl' ) { $linkCache = LinkCache::singleton(); - if ( $options ) { + if ( count( $options ) > 0 ) { $db = wfGetDB( DB_MASTER ); } else { $db = wfGetDB( DB_SLAVE ); @@ -2459,10 +2459,10 @@ class Title { * WARNING: do not use this function on arbitrary user-supplied titles! * On heavily-used templates it will max out the memory. * - * @param $options \type{\string} may be FOR UPDATE + * @param array $options may be FOR UPDATE * @return \type{\arrayof{Title}} the Title objects linking here */ - public function getTemplateLinksTo( $options = '' ) { + public function getTemplateLinksTo( $options = array() ) { return $this->getLinksTo( $options, 'templatelinks', 'tl' ); } @@ -2470,16 +2470,16 @@ class Title { * Get an array of Title objects referring to non-existent articles linked from this page * * @todo check if needed (used only in SpecialBrokenRedirects.php, and should use redirect table in this case) - * @param $options \type{\string} may be FOR UPDATE + * @param array $options may be FOR UPDATE * @return \type{\arrayof{Title}} the Title objects */ - public function getBrokenLinksFrom( $options = '' ) { + public function getBrokenLinksFrom( $options = array() ) { if ( $this->getArticleId() == 0 ) { # All links from article ID 0 are false positives return array(); } - if ( $options ) { + if ( count( $options ) > 0 ) { $db = wfGetDB( DB_MASTER ); } else { $db = wfGetDB( DB_SLAVE ); @@ -3067,7 +3067,7 @@ class Title { array( 'page_is_redirect', 'page_latest', 'page_id' ), $this->pageCond(), __METHOD__, - 'FOR UPDATE' + array( 'FOR UPDATE' ) ); # Cache some fields we may want $this->mArticleID = $row ? intval($row->page_id) : 0; @@ -3085,7 +3085,7 @@ class Title { 'page_latest != rev_id' ), __METHOD__, - 'FOR UPDATE' + array( 'FOR UPDATE' ) ); # Return true if there was no history return ($row === false); diff --git a/includes/filerepo/File.php b/includes/filerepo/File.php index 47b1d4e55b..03a8322030 100644 --- a/includes/filerepo/File.php +++ b/includes/filerepo/File.php @@ -865,22 +865,23 @@ abstract class File { * * @deprecated Use HTMLCacheUpdate, this function uses too much memory */ - function getLinksTo( $options = '' ) { + function getLinksTo( $options = array() ) { wfProfileIn( __METHOD__ ); // Note: use local DB not repo DB, we want to know local links - if ( $options ) { + if ( count( $options ) > 0 ) { $db = wfGetDB( DB_MASTER ); } else { $db = wfGetDB( DB_SLAVE ); } $linkCache = LinkCache::singleton(); - list( $page, $imagelinks ) = $db->tableNamesN( 'page', 'imagelinks' ); $encName = $db->addQuotes( $this->getName() ); - $sql = "SELECT page_namespace,page_title,page_id,page_len,page_is_redirect, - FROM $page,$imagelinks WHERE page_id=il_from AND il_to=$encName $options"; - $res = $db->query( $sql, __METHOD__ ); + $res = $db->select( array( 'page', 'imagelinks'), + array( 'page_namespace', 'page_title', 'page_id', 'page_len', 'page_is_redirect' ), + array( 'page_id' => 'il_from', 'il_to' => $encName ), + __METHOD__, + $options ); $retVal = array(); if ( $db->numRows( $res ) ) { -- 2.20.1