diff options
author | Marcin Cieślak <saper@users.mediawiki.org> | 2012-03-15 01:52:38 +0000 |
---|---|---|
committer | Marcin Cieślak <saper@users.mediawiki.org> | 2012-03-15 01:52:38 +0000 |
commit | de5222aedf3110d60201944c1d4a8143eea0260b (patch) | |
tree | 692240bdf8f067b81631b49338f1fc957f120763 /includes/RecentChange.php | |
parent | 428934f41e6177326f5d14088f1c7770654bb3ca (diff) | |
download | mediawikicore-de5222aedf3110d60201944c1d4a8143eea0260b.tar.gz mediawikicore-de5222aedf3110d60201944c1d4a8143eea0260b.zip |
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}
Notes
Notes:
http://mediawiki.org/wiki/Special:Code/MediaWiki/113888
Diffstat (limited to 'includes/RecentChange.php')
-rw-r--r-- | includes/RecentChange.php | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/includes/RecentChange.php b/includes/RecentChange.php index 9fcdbcd251c7..444e40fbd1c5 100644 --- a/includes/RecentChange.php +++ b/includes/RecentChange.php @@ -382,12 +382,6 @@ class RecentChange { */ 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 @@ class RecentChange { '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 @@ class RecentChange { */ 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 @@ class RecentChange { '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 @@ class RecentChange { 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 @@ class RecentChange { '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 @@ class RecentChange { '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 @@ class RecentChange { } 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; + } } |