804a9088a792ab71d39e6988c354f12782cf3f09
[lhc/web/wiklou.git] / maintenance / importTextFile.inc
1 <?php
2
3 /**
4 * Support functions for the importTextFile script
5 *
6 * @package MediaWiki
7 * @subpackage Maintenance
8 * @author Rob Church <robchur@gmail.com>
9 */
10
11 require_once( "$IP/includes/RecentChange.php" );
12
13 /**
14 * Insert a new article
15 *
16 * @param $title Title of the article
17 * @param $text Text of the article
18 * @param $user User associated with the edit
19 * @param $comment Edit summary
20 * @param $rc Whether or not to add a recent changes event
21 * @return bool
22 */
23 function insertNewArticle( &$title, $text, &$user, $comment, $rc ) {
24 if( !$title->exists() ) {
25 # Create the article
26 $dbw =& wfGetDB( DB_MASTER );
27 $dbw->immediateBegin();
28 $article = new Article( $title );
29 $articleId = $article->insertOn( $dbw );
30 # Prepare and save associated revision
31 $revision = new Revision( array( 'page' => $articleId, 'text' => $text, 'user' => $user->mId, 'user_text' => $user->getName(), 'comment' => $comment ) );
32 $revisionId = $revision->insertOn( $dbw );
33 # Make it the current revision
34 $article->updateRevisionOn( $dbw, $revision );
35 $dbw->immediateCommit();
36 # Update recent changes if appropriate
37 if( $rc )
38 updateRecentChanges( $dbw, $title, $user, $comment, strlen( $text ), $articleId );
39 return( true );
40 } else {
41 # Title exists; touch nothing
42 return( false );
43 }
44 }
45
46 /**
47 * Turn a filename into a title
48 *
49 * @param $filename Filename to be transformed
50 * @return Title
51 */
52 function titleFromFilename( $filename ) {
53 $parts = explode( '/', $filename );
54 $parts = explode( '.', $parts[ count( $parts ) - 1 ] );
55 return( Title::newFromText( $parts[0] ) );
56 }
57
58 /**
59 * Update recent changes with the page creation event
60 *
61 * @param $dbw Database in use
62 * @param $title Title of the new page
63 * @param $user User responsible for the creation
64 * @param $comment Edit summary associated with the edit
65 * @param $size Size of the page
66 * @param $articleId Article identifier
67 */
68 function updateRecentChanges( &$dbw, &$title, &$user, $comment, $size, $articleId ) {
69 RecentChange::notifyNew( $dbw->timestamp(), $title, false, $user, $comment, 'default', '', $size, $articleId );
70 }
71
72 ?>