Extension:Multiplicator/code/Multiplicator.page.php

Multiplicator.page.php
';		$form .= Xml::hidden( 'token', $wgUser->editToken( 'multiplicator' ) ); $form .= ' '; return $form; }

/**	 * Duplicate one page to another, including full histories * Does some basic error-catching, but not as much as the code above [should] *	 * @param $source Title to duplicate * @param $dest Title to save to	 * @return bool */		private function duplicate( &$source, &$dest ) { global $wgUser, $wgBot; if( !$source->exists || $dest->exists ) return false; # Source doesn't exist, or destination does $dbw = wfGetDB( DB_MASTER ); $dbw->begin; $sid = $source->getArticleID; # Create an article representing the destination page and save it			$destArticle = new Article( $dest ); $aid = $destArticle->insertOn( $dbw ); # Perform the revision duplication # An INSERT...SELECT here seems to fuck things up			$res = $dbw->select( 'revision', '*', array( 'rev_page' => $sid ), __METHOD__ ); if( $res && $dbw->numRows( $res ) > 0 ) { while( $row = $dbw->fetchObject( $res ) ) { $values['rev_page'] = $aid; $values['rev_text_id'] = $row->rev_text_id; $values['rev_comment'] = $row->rev_comment; $values['rev_user'] = $row->rev_user; $values['rev_user_text'] = $row->rev_user_text; $values['rev_timestamp'] = $row->rev_timestamp; $values['rev_minor_edit'] = $row->rev_minor_edit; $values['rev_deleted'] = $row->rev_deleted; $dbw->insert( 'revision', $values, __METHOD__ ); }				$dbw->freeResult( $res ); }			# Update page record $latest = $dbw->selectField( 'revision', 'MAX(rev_id)', array( 'rev_page' => $aid ), __METHOD__ ); $rev = Revision::newFromId( $latest ); $destArticle->updateRevisionOn( $dbw, $rev ); # Commit transaction $dbw->commit; # Create a null revision with an explanation; do cache clearances, etc.			$dbw->begin; $comment = wfMsgForContent( 'duplicator-summary', $source->getPrefixedText ); $nr = Revision::newNullRevision( $dbw, $aid, $comment, true ); $nid = $nr->insertOn( $dbw ); $destArticle->updateRevisionOn( $dbw, $nr ); $destArticle->createUpdates( $nr ); Article::onArticleCreate( $dest ); $bot = $wgUser->isAllowed( 'bot' ); RecentChange::notifyNew( $nr->getTimestamp, $dest, true, $wgUser, $comment, $bot ); $dest->invalidateCache; $dbw->commit; return true;

}	}