From 183851b06bd6c52f3cae5375f433da720d410447 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Wed, 11 Oct 2006 18:12:39 +0000 Subject: MediaWiki 1.7.1 wiederhergestellt --- maintenance/importTextFile.inc | 75 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 maintenance/importTextFile.inc (limited to 'maintenance/importTextFile.inc') diff --git a/maintenance/importTextFile.inc b/maintenance/importTextFile.inc new file mode 100644 index 00000000..50b936c1 --- /dev/null +++ b/maintenance/importTextFile.inc @@ -0,0 +1,75 @@ + + */ + +require_once( "$IP/includes/RecentChange.php" ); + +/** + * Insert a new article + * + * @param $title Title of the article + * @param $text Text of the article + * @param $user User associated with the edit + * @param $comment Edit summary + * @param $rc Whether or not to add a recent changes event + * @return bool + */ +function insertNewArticle( &$title, $text, &$user, $comment, $rc ) { + if( !$title->exists() ) { + # Create the article + $dbw =& wfGetDB( DB_MASTER ); + $dbw->immediateBegin(); + $article = new Article( $title ); + $articleId = $article->insertOn( $dbw ); + # Prepare and save associated revision + $revision = new Revision( array( 'page' => $articleId, 'text' => $text, 'user' => $user->mId, 'user_text' => $user->getName(), 'comment' => $comment ) ); + $revisionId = $revision->insertOn( $dbw ); + # Make it the current revision + $article->updateRevisionOn( $dbw, $revision ); + $dbw->immediateCommit(); + # Update recent changes if appropriate + if( $rc ) + updateRecentChanges( $dbw, $title, $user, $comment, strlen( $text ), $articleId ); + # Touch links etc. + Article::onArticleCreate( $title ); + $article->editUpdates( $text, $comment, false, $dbw->timestamp(), $revisionId ); + return true; + } else { + # Title exists; touch nothing + return false; + } +} + +/** + * Turn a filename into a title + * + * @param $filename Filename to be transformed + * @return Title + */ +function titleFromFilename( $filename ) { + $parts = explode( '/', $filename ); + $parts = explode( '.', $parts[ count( $parts ) - 1 ] ); + return Title::newFromText( $parts[0] ); +} + +/** + * Update recent changes with the page creation event + * + * @param $dbw Database in use + * @param $title Title of the new page + * @param $user User responsible for the creation + * @param $comment Edit summary associated with the edit + * @param $size Size of the page + * @param $articleId Article identifier + */ +function updateRecentChanges( &$dbw, &$title, &$user, $comment, $size, $articleId ) { + RecentChange::notifyNew( $dbw->timestamp(), $title, false, $user, $comment, 'default', '', $size, $articleId ); +} + +?> \ No newline at end of file -- cgit v1.2.3-54-g00ecf