General cleanup of SQL in Title and File. Fixes bug 17392: 'FOR UPDATE' should be...
authorChad Horohoe <demon@users.mediawiki.org>
Tue, 17 Feb 2009 19:03:40 +0000 (19:03 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Tue, 17 Feb 2009 19:03:40 +0000 (19:03 +0000)
includes/Title.php
includes/filerepo/File.php

index c919ab0..ae0f986 100644 (file)
@@ -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);
index 47b1d4e..03a8322 100644 (file)
@@ -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 ) ) {