https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113888
Revision: 113888
Author: saper
Date: 2012-03-15 01:52:38 +0000 (Thu, 15 Mar 2012)
Log Message:
-----------
Unbreak maintenance/deleteDefaultMessages.php for PostgreSQL
deleteDefaultMessages.php was failing during upgrade
from MediaWiki 1.7.3 with a databaser error.
A stub user:
$user = User::newFromName( 'MediaWiki default' );
has user ID 0, so that $user->isAnon() is true.
Unfortunately, ManualLogEntry::publish() from r96441
tries to insert $user->getName() ("MediaWiki default")
into rc_ip.
PostgreSQL won't allow this, because rc_ip is of
Postgres-specific CIDR type.
Traceback:
Checking existence of old default messages...
...deleting old default messages (this may take a long time!)...A database
query syntax error has occurred.
The last attempted database query was:
"INSERT INTO "recentchanges"
(rc_timestamp,rc_cur_time,rc_namespace,rc_title,rc_type,rc_minor,rc_user,rc_user_text,rc_comment,rc_this_oldid,rc_last_oldid,rc_bot,rc_moved_to_ns,rc_moved_to_title,rc_ip,rc_patrolled,rc_new,rc_old_len,rc_new_len,rc_deleted,rc_logid,rc_log_type,rc_log_action,rc_params,rc_id)
VALUES ('2012-03-14 21:51:05 GMT','2012-03-14 21:51:05
GMT','8','1movedto2','3','0','0','MediaWiki default','No longer
required','0','0',1,'0','','MediaWiki
default','1','0',NULL,NULL,'0','1','delete','delete','a:0:{}','1')"
from within function "RecentChange::save".
MySQL returned error "1: ERROR: invalid input syntax for type cidr: "MediaWiki
default"
LINE 1: ...ki default','No longer required','0','0',1,'0','','MediaWiki...
^"
Backtrace:
#0 /usr/home/saper/public_html/pg/w/includes/db/DatabasePostgres.php(332):
DatabaseBase->reportQueryError('ERROR: invalid...', 1, 'INSERT INTO "re...',
'RecentChange::s...', '')
#1 /usr/home/saper/public_html/pg/w/includes/db/Database.php(904):
DatabasePostgres->reportQueryError('ERROR: invalid...', 1, 'INSERT INTO
"re...', 'RecentChange::s...', '')
#2 /usr/home/saper/public_html/pg/w/includes/db/DatabasePostgres.php(604):
DatabaseBase->query('INSERT INTO "re...', 'RecentChange::s...', '')
#3 /usr/home/saper/public_html/pg/w/includes/RecentChange.php(199):
DatabasePostgres->insert('recentchanges', Array, 'RecentChange::s...')
#4 /usr/home/saper/public_html/pg/w/includes/logging/LogEntry.php(479):
RecentChange->save('pleasedontudp')
#5 /usr/home/saper/public_html/pg/w/includes/WikiPage.php(2042):
ManualLogEntry->publish('1')
#6 /usr/home/saper/public_html/pg/w/includes/WikiPage.php(1937):
WikiPage->doDeleteArticleReal('No longer requi...', false, 0, false, '',
Object(User))
#7 /usr/home/saper/public_html/pg/w/maintenance/deleteDefaultMessages.php(73):
WikiPage->doDeleteArticle('No longer requi...', false, 0, false, '',
Object(User))
#8 /usr/home/saper/public_html/pg/w/maintenance/update.php(128):
DeleteDefaultMessages->execute()
#9 /usr/home/saper/public_html/pg/w/maintenance/doMaintenance.php(105):
UpdateMediaWiki->execute()
#10 /usr/home/saper/public_html/pg/w/maintenance/update.php(151):
require_once('/usr/home/saper...')
#11 {main}
Modified Paths:
--------------
trunk/phase3/includes/RecentChange.php
trunk/phase3/includes/logging/LogEntry.php
trunk/phase3/maintenance/deleteDefaultMessages.php
Modified: trunk/phase3/includes/RecentChange.php
===================================================================
--- trunk/phase3/includes/RecentChange.php 2012-03-15 01:43:17 UTC (rev
113887)
+++ trunk/phase3/includes/RecentChange.php 2012-03-15 01:52:38 UTC (rev
113888)
@@ -382,12 +382,6 @@
*/
public static function notifyEdit( $timestamp, &$title, $minor, &$user,
$comment, $oldId,
$lastTimestamp, $bot, $ip='', $oldSize=0, $newSize=0, $newId=0,
$patrol=0 ) {
- global $wgRequest;
- if( !$ip ) {
- $ip = $wgRequest->getIP();
- if( !$ip ) $ip = '';
- }
-
$rc = new RecentChange;
$rc->mAttribs = array(
'rc_timestamp' => $timestamp,
@@ -405,7 +399,7 @@
'rc_bot' => $bot ? 1 : 0,
'rc_moved_to_ns' => 0,
'rc_moved_to_title' => '',
- 'rc_ip' => $ip,
+ 'rc_ip' => self::checkIPAddress( $ip ),
'rc_patrolled' => intval($patrol),
'rc_new' => 0, # obsolete
'rc_old_len' => $oldSize,
@@ -446,14 +440,6 @@
*/
public static function notifyNew( $timestamp, &$title, $minor, &$user,
$comment, $bot,
$ip='', $size=0, $newId=0, $patrol=0 ) {
- global $wgRequest;
- if( !$ip ) {
- $ip = $wgRequest->getIP();
- if( !$ip ) {
- $ip = '';
- }
- }
-
$rc = new RecentChange;
$rc->mAttribs = array(
'rc_timestamp' => $timestamp,
@@ -471,7 +457,7 @@
'rc_bot' => $bot ? 1 : 0,
'rc_moved_to_ns' => 0,
'rc_moved_to_title' => '',
- 'rc_ip' => $ip,
+ 'rc_ip' => self::checkIPAddress( $ip ),
'rc_patrolled' => intval($patrol),
'rc_new' => 1, # obsolete
'rc_old_len' => 0,
@@ -540,12 +526,6 @@
public static function newLogEntry( $timestamp, &$title, &$user,
$actionComment, $ip,
$type, $action, $target, $logComment, $params, $newId=0,
$actionCommentIRC='' ) {
global $wgRequest;
- if( !$ip ) {
- $ip = $wgRequest->getIP();
- if( !$ip ) {
- $ip = '';
- }
- }
$rc = new RecentChange;
$rc->mAttribs = array(
@@ -564,7 +544,7 @@
'rc_bot' => $user->isAllowed( 'bot' ) ?
$wgRequest->getBool( 'bot', true ) : 0,
'rc_moved_to_ns' => 0,
'rc_moved_to_title' => '',
- 'rc_ip' => $ip,
+ 'rc_ip' => self::checkIPAddress( $ip ),
'rc_patrolled' => 1,
'rc_new' => 0, # obsolete
'rc_old_len' => null,
@@ -575,6 +555,8 @@
'rc_log_action' => $action,
'rc_params' => $params
);
+ wfDebug(__METHOD__ . ": " . var_export($rc->mAttribs, TRUE) .
"\n");
+
$rc->mExtra = array(
'prefixedDBkey' => $title->getPrefixedDBkey(),
'lastTimestamp' => 0,
@@ -769,4 +751,18 @@
}
return ChangesList::showCharacterDifference( $old, $new );
}
+
+ public static function checkIPAddress( $ip ) {
+ global $wgRequest;
+ if ( $ip ) {
+ if ( !IP::isIPAddress( $ip ) ) {
+ throw new MWException( "Attempt to write \"" .
$ip . "\" as an IP address into recent changes" );
+ }
+ } else {
+ $ip = $wgRequest->getIP();
+ if( !$ip )
+ $ip = '';
+ }
+ return $ip;
+ }
}
Modified: trunk/phase3/includes/logging/LogEntry.php
===================================================================
--- trunk/phase3/includes/logging/LogEntry.php 2012-03-15 01:43:17 UTC (rev
113887)
+++ trunk/phase3/includes/logging/LogEntry.php 2012-03-15 01:52:38 UTC (rev
113888)
@@ -458,12 +458,22 @@
$logpage = SpecialPage::getTitleFor( 'Log', $this->getType() );
$user = $this->getPerformer();
+ $ip = "";
+ if ( $user->isAnon() ) {
+ /*
+ * "MediaWiki default" and friends may have
+ * no IP address in their name
+ */
+ if ( IP::isIPAddress( $user->getName() ) ) {
+ $ip = $user->getName();
+ }
+ }
$rc = RecentChange::newLogEntry(
$this->getTimestamp(),
$logpage,
$user,
$formatter->getPlainActionText(),
- $user->isAnon() ? $user->getName() : '',
+ $ip,
$this->getType(),
$this->getSubtype(),
$this->getTarget(),
Modified: trunk/phase3/maintenance/deleteDefaultMessages.php
===================================================================
--- trunk/phase3/maintenance/deleteDefaultMessages.php 2012-03-15 01:43:17 UTC
(rev 113887)
+++ trunk/phase3/maintenance/deleteDefaultMessages.php 2012-03-15 01:52:38 UTC
(rev 113888)
@@ -74,7 +74,7 @@
$dbw->commit( __METHOD__ );
}
- $this->output( 'done!', 'msg' );
+ $this->output( 'done!\n', 'msg' );
}
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs