r109628 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109627‎ | r109628 | r109629 >
Date:16:57, 20 January 2012
Author:nikerabbit
Status:ok
Tags:core, tstarling 
Comment:
Reducy query flood in r96546. Allow formatters to provide titles for LinkBatch.
Modified paths:
  • /trunk/phase3/includes/logging/LogFormatter.php (modified) (history)
  • /trunk/phase3/includes/logging/LogPager.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/logging/LogPager.php
@@ -297,6 +297,10 @@
298298 $lb->add( $row->log_namespace, $row->log_title );
299299 $lb->addObj( Title::makeTitleSafe( NS_USER, $row->user_name ) );
300300 $lb->addObj( Title::makeTitleSafe( NS_USER_TALK, $row->user_name ) );
 301+ $formatter = LogFormatter::newFromRow( $row );
 302+ foreach ( $formatter->getPreloadTitles() as $title ) {
 303+ $lb->addObj( $title );
 304+ }
301305 }
302306 $lb->execute();
303307 $this->mResult->seek( 0 );
Index: trunk/phase3/includes/logging/LogFormatter.php
@@ -153,25 +153,13 @@
154154 }
155155
156156 /**
157 - * Extract parameters intented for action message from
158 - * array of all parameters. There are three hardcoded
159 - * parameters (array zero-indexed, this list not):
160 - * - 1: user name with premade link
161 - * - 2: usable for gender magic function
162 - * - 3: target page with premade link
 157+ * Extracts the optional extra parameters for use in action messages.
 158+ * The array indexes start from number 3.
163159 * @return array
164160 */
165 - protected function getMessageParameters() {
166 - if ( isset( $this->parsedParameters ) ) {
167 - return $this->parsedParameters;
168 - }
169 -
 161+ protected function extractParameters() {
170162 $entry = $this->entry;
171 -
172163 $params = array();
173 - $params[0] = Message::rawParam( $this->getPerformerElement() );
174 - $params[1] = $entry->getPerformer()->getName();
175 - $params[2] = Message::rawParam( $this->makePageLink( $entry->getTarget() ) );
176164
177165 if ( $entry->isLegacy() ) {
178166 foreach ( $entry->getParameters() as $index => $value ) {
@@ -196,7 +184,31 @@
197185 $params[$i] = '';
198186 }
199187 }
 188+ return $params;
 189+ }
200190
 191+ /**
 192+ * Formats parameters intented for action message from
 193+ * array of all parameters. There are three hardcoded
 194+ * parameters (array is zero-indexed, this list not):
 195+ * - 1: user name with premade link
 196+ * - 2: usable for gender magic function
 197+ * - 3: target page with premade link
 198+ * @return array
 199+ */
 200+ protected function getMessageParameters() {
 201+ if ( isset( $this->parsedParameters ) ) {
 202+ return $this->parsedParameters;
 203+ }
 204+
 205+ $entry = $this->entry;
 206+ $params = $this->extractParameters();
 207+ $params[0] = Message::rawParam( $this->getPerformerElement() );
 208+ $params[1] = $entry->getPerformer()->getName();
 209+ $params[2] = Message::rawParam( $this->makePageLink( $entry->getTarget() ) );
 210+
 211+ // Bad things happens if the numbers are not in correct order
 212+ ksort( $params );
201213 return $this->parsedParameters = $params;
202214 }
203215
@@ -300,6 +312,13 @@
301313 return $element;
302314 }
303315
 316+ /**
 317+ * @return Array of titles that should be preloaded with LinkBatch.
 318+ */
 319+ public function getPreloadTitles() {
 320+ return array();
 321+ }
 322+
304323 }
305324
306325 /**
@@ -334,6 +353,11 @@
335354 * @since 1.19
336355 */
337356 class MoveLogFormatter extends LogFormatter {
 357+ public function getPreloadTitles() {
 358+ $params = $this->extractParameters();
 359+ return array( Title::newFromText( $params[3] ) );
 360+ }
 361+
338362 protected function getMessageKey() {
339363 $key = parent::getMessageKey();
340364 $params = $this->getMessageParameters();

Follow-up revisions

RevisionCommit summaryAuthorDate
r109636Can't PHP just DWIM? Ping r109628nikerabbit19:09, 20 January 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r96546Enabled MoveLogFormatter...nikerabbit09:09, 8 September 2011

Status & tagging log