r47374 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47373‎ | r47374 | r47375 >
Date:19:03, 17 February 2009
Author:demon
Status:resolved (Comments)
Tags:
Comment:
General cleanup of SQL in Title and File. Fixes bug 17392: 'FOR UPDATE' should be passed in an array, not as a string.
Modified paths:
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/filerepo/File.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/File.php
@@ -865,22 +865,23 @@
866866 *
867867 * @deprecated Use HTMLCacheUpdate, this function uses too much memory
868868 */
869 - function getLinksTo( $options = '' ) {
 869+ function getLinksTo( $options = array() ) {
870870 wfProfileIn( __METHOD__ );
871871
872872 // Note: use local DB not repo DB, we want to know local links
873 - if ( $options ) {
 873+ if ( count( $options ) > 0 ) {
874874 $db = wfGetDB( DB_MASTER );
875875 } else {
876876 $db = wfGetDB( DB_SLAVE );
877877 }
878878 $linkCache = LinkCache::singleton();
879879
880 - list( $page, $imagelinks ) = $db->tableNamesN( 'page', 'imagelinks' );
881880 $encName = $db->addQuotes( $this->getName() );
882 - $sql = "SELECT page_namespace,page_title,page_id,page_len,page_is_redirect,
883 - FROM $page,$imagelinks WHERE page_id=il_from AND il_to=$encName $options";
884 - $res = $db->query( $sql, __METHOD__ );
 881+ $res = $db->select( array( 'page', 'imagelinks'),
 882+ array( 'page_namespace', 'page_title', 'page_id', 'page_len', 'page_is_redirect' ),
 883+ array( 'page_id' => 'il_from', 'il_to' => $encName ),
 884+ __METHOD__,
 885+ $options );
885886
886887 $retVal = array();
887888 if ( $db->numRows( $res ) ) {
Index: trunk/phase3/includes/Title.php
@@ -2418,13 +2418,13 @@
24192419 * WARNING: do not use this function on arbitrary user-supplied titles!
24202420 * On heavily-used templates it will max out the memory.
24212421 *
2422 - * @param $options \type{\string} may be FOR UPDATE
 2422+ * @param array $options may be FOR UPDATE
24232423 * @return \type{\arrayof{Title}} the Title objects linking here
24242424 */
2425 - public function getLinksTo( $options = '', $table = 'pagelinks', $prefix = 'pl' ) {
 2425+ public function getLinksTo( $options = array(), $table = 'pagelinks', $prefix = 'pl' ) {
24262426 $linkCache = LinkCache::singleton();
24272427
2428 - if ( $options ) {
 2428+ if ( count( $options ) > 0 ) {
24292429 $db = wfGetDB( DB_MASTER );
24302430 } else {
24312431 $db = wfGetDB( DB_SLAVE );
@@ -2459,10 +2459,10 @@
24602460 * WARNING: do not use this function on arbitrary user-supplied titles!
24612461 * On heavily-used templates it will max out the memory.
24622462 *
2463 - * @param $options \type{\string} may be FOR UPDATE
 2463+ * @param array $options may be FOR UPDATE
24642464 * @return \type{\arrayof{Title}} the Title objects linking here
24652465 */
2466 - public function getTemplateLinksTo( $options = '' ) {
 2466+ public function getTemplateLinksTo( $options = array() ) {
24672467 return $this->getLinksTo( $options, 'templatelinks', 'tl' );
24682468 }
24692469
@@ -2470,16 +2470,16 @@
24712471 * Get an array of Title objects referring to non-existent articles linked from this page
24722472 *
24732473 * @todo check if needed (used only in SpecialBrokenRedirects.php, and should use redirect table in this case)
2474 - * @param $options \type{\string} may be FOR UPDATE
 2474+ * @param array $options may be FOR UPDATE
24752475 * @return \type{\arrayof{Title}} the Title objects
24762476 */
2477 - public function getBrokenLinksFrom( $options = '' ) {
 2477+ public function getBrokenLinksFrom( $options = array() ) {
24782478 if ( $this->getArticleId() == 0 ) {
24792479 # All links from article ID 0 are false positives
24802480 return array();
24812481 }
24822482
2483 - if ( $options ) {
 2483+ if ( count( $options ) > 0 ) {
24842484 $db = wfGetDB( DB_MASTER );
24852485 } else {
24862486 $db = wfGetDB( DB_SLAVE );
@@ -3067,7 +3067,7 @@
30683068 array( 'page_is_redirect', 'page_latest', 'page_id' ),
30693069 $this->pageCond(),
30703070 __METHOD__,
3071 - 'FOR UPDATE'
 3071+ array( 'FOR UPDATE' )
30723072 );
30733073 # Cache some fields we may want
30743074 $this->mArticleID = $row ? intval($row->page_id) : 0;
@@ -3085,7 +3085,7 @@
30863086 'page_latest != rev_id'
30873087 ),
30883088 __METHOD__,
3089 - 'FOR UPDATE'
 3089+ array( 'FOR UPDATE' )
30903090 );
30913091 # Return true if there was no history
30923092 return ($row === false);

Follow-up revisions

RevisionCommit summaryAuthorDate
r47434Fixed Title::getBrokenLinksFrom(), totally broken by r47374. Caused breakage ...tstarling08:35, 18 February 2009

Comments

#Comment by Simetrical (talk | contribs)   23:33, 17 February 2009

IMO, a nicer fix would be to just allow passing a single string instead of an array. The appropriate DB method can do an extra $varname = (array)$varname;. Most of our "array of strings"-style parameters allow omitting the array bit if it's just a single parameter. See, for instance, Linker::link.

#Comment by P.Copp (talk | contribs)   08:34, 18 February 2009
-	public function getBrokenLinksFrom( $options = '' ) {
+	public function getBrokenLinksFrom( $options = array() ) {

This probably has broken Special:BrokenRedirects, as $options is inserted directly into the query here. See bug 17549.

#Comment by P.Copp (talk | contribs)   08:44, 18 February 2009

Never mind. This was already fixed with r47434.

Status & tagging log