r69171 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69170‎ | r69171 | r69172 >
Date:08:11, 8 July 2010
Author:nikerabbit
Status:resolved (Comments)
Tags:
Comment:
Little debugging help for LinkBatch
Modified paths:
  • /trunk/phase3/includes/LinkBatch.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/LinkBatch.php
@@ -12,12 +12,26 @@
1313 */
1414 var $data = array();
1515
 16+ /**
 17+ * For debugging which method is using this class.
 18+ */
 19+ protected $caller;
 20+
1621 function __construct( $arr = array() ) {
1722 foreach( $arr as $item ) {
1823 $this->addObj( $item );
1924 }
2025 }
2126
 27+ /**
 28+ * Use ->setCaller( __METHOD__ ) to indicate which code is using this
 29+ * class. Only used in debugging output.
 30+ * @since 1.17
 31+ */
 32+ public function setCaller( $caller ) {
 33+ $this->caller = $caller;
 34+ }
 35+
2236 public function addObj( $title ) {
2337 if ( is_object( $title ) ) {
2438 $this->add( $title->getNamespace(), $title->getDBkey() );
@@ -134,7 +148,8 @@
135149 $sql = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect, page_latest FROM $page WHERE $set";
136150
137151 // Do query
138 - $res = $dbr->query( $sql, __METHOD__ );
 152+ $caller = $this->caller ? __METHOD__ . " (for {$this->caller})" : __METHOD__;
 153+ $res = $dbr->query( $sql, $caller );
139154 wfProfileOut( __METHOD__ );
140155 return $res;
141156 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r69225Tweak comparison in r69171nikerabbit07:36, 10 July 2010

Comments

#Comment by Simetrical (talk | contribs)   22:20, 9 July 2010

Shouldn't you be doing "$caller = is_null( $this->caller ) ? ..." instead of "$caller = $this->caller ? ..."? Your current code looks like it will raise E_NOTICEs if $this->caller is uninitialized, and also act weird if $this->caller happens to be or '0' or 0 or false or whatever.

#Comment by Nikerabbit (talk | contribs)   07:37, 10 July 2010

As far as I know member variables are always initialized and we don't want to display anything that the user can't read.

#Comment by Simetrical (talk | contribs)   17:54, 11 July 2010

Okay, I guess that's true, since a method name is unlikely to be named '0'.

#Comment by Simetrical (talk | contribs)   17:55, 11 July 2010

(I mean, methods can't be named '0', and no one is likely to pass that in as an argument to setCaller() for other reasons.)

Status & tagging log