\n" ) { # For now, assume title is correct dbkey # and log pages always go in Wikipedia namespace $this->mTitle = str_replace( " ", "_", $title ); $this->mId = 0; $this->mUpdateRecentChanges = true ; $this->mContentLoaded = false; $this->getContent( $defaulttext ); } function getContent( $defaulttext = "" ) { $fname = 'LogPage::getContent'; $dbw =& wfGetDB( DB_MASTER ); $s = $dbw->getArray( 'cur', array( 'cur_id','cur_text','cur_timestamp' ), array( 'cur_namespace' => Namespace::getWikipedia(), 'cur_title' => $this->mTitle ), $fname, 'FOR UPDATE' ); if( $s !== false ) { $this->mId = $s->cur_id; $this->mContent = $s->cur_text; $this->mTimestamp = $s->cur_timestamp; } else { $this->mId = 0; $this->mContent = $defaulttext; $this->mTimestamp = wfTimestampNow(); } $this->mContentLoaded = true; # Well, sort of return $this->mContent; } function getTimestamp() { if( !$this->mContentLoaded ) { $this->getContent(); } return $this->mTimestamp; } function saveContent() { if( wfReadOnly() ) return; global $wgUser; $fname = "LogPage::saveContent"; $dbw =& wfGetDB( DB_MASTER ); $uid = $wgUser->getID(); if( !$this->mContentLoaded ) return false; $this->mTimestamp = $now = wfTimestampNow(); $won = wfInvertTimestamp( $now ); if($this->mId == 0) { $seqVal = $dbw->nextSequenceValue( 'cur_cur_id_seq' ); # Note: this query will deadlock if another thread has called getContent(), # at least in MySQL 4.0.17 InnoDB $dbw->insertArray( 'cur', array( 'cur_id' => $seqVal, 'cur_timestamp' => $now, 'cur_user' => $uid, 'cur_user_text' => $wgUser->getName(), 'cur_namespace' => NS_WIKIPEDIA, 'cur_title' => $this->mTitle, 'cur_text' => $this->mContent, 'cur_comment' => $this->mComment, 'cur_restrictions' => 'sysop', 'inverse_timestamp' => $won, 'cur_touched' => $now, ), $fname ); $this->mId = $dbw->insertId(); } else { $dbw->updateArray( 'cur', array( /* SET */ 'cur_timestamp' => $now, 'cur_user' => $uid, 'cur_user_text' => $wgUser->getName(), 'cur_text' => $this->mContent, 'cur_comment' => $this->mComment, 'cur_restrictions' => 'sysop', 'inverse_timestamp' => $won, 'cur_touched' => $now, ), array( /* WHERE */ 'cur_id' => $this->mId ), $fname ); } # And update recentchanges if ( $this->mUpdateRecentChanges ) { $titleObj = Title::makeTitle( Namespace::getWikipedia(), $this->mTitle ); RecentChange::notifyLog( $now, $titleObj, $wgUser, $this->mComment ); } return true; } function addEntry( $action, $comment, $textaction = "" ) { global $wgLang, $wgUser; $comment_esc = wfEscapeWikiText( $comment ); $this->getContent(); $ut = $wgUser->getName(); $uid = $wgUser->getID(); if( $uid ) { $ul = "[[" . $wgLang->getNsText( Namespace::getUser() ) . ":{$ut}|{$ut}]]"; } else { $ul = $ut; } $d = $wgLang->timeanddate( wfTimestampNow(), false ); if( preg_match( "/^(.*?)