(k) fix minor glitch in installExtension.php
[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 # Touch links etc.
40 Article::onArticleCreate( $title );
41 $article->editUpdates( $text, $comment, false, $dbw->timestamp(), $revisionId );
42 return true;
43 } else {
44 # Title exists; touch nothing
45 return false;
46 }
47 }
48
49 /**
50 * Turn a filename into a title
51 *
52 * @param $filename Filename to be transformed
53 * @return Title
54 */
55 function titleFromFilename( $filename ) {
56 $parts = explode( '/', $filename );
57 $parts = explode( '.', $parts[ count( $parts ) - 1 ] );
58 return Title::newFromText( $parts[0] );
59 }
60
61 /**
62 * Update recent changes with the page creation event
63 *
64 * @param $dbw Database in use
65 * @param $title Title of the new page
66 * @param $user User responsible for the creation
67 * @param $comment Edit summary associated with the edit
68 * @param $size Size of the page
69 * @param $articleId Article identifier
70 */
71 function updateRecentChanges( &$dbw, &$title, &$user, $comment, $size, $articleId ) {
72 RecentChange::notifyNew( $dbw->timestamp(), $title, false, $user, $comment, 'default', '', $size, $articleId );
73 }
74
75 ?>