Maintenance script to import the contents of a text file into a wiki page
[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 /**
12 * Insert a new article
13 *
14 * @param $title Title of the article
15 * @param $text Text of the article
16 * @param $user User associated with the edit
17 * @param $comment Edit summary
18 * @return bool
19 */
20 function insertNewArticle( &$title, $text, &$user, $comment ) {
21 if( !$title->exists() ) {
22 # Create the article
23 $dbw =& wfGetDB( DB_MASTER );
24 $dbw->immediateBegin();
25 $article = new Article( $title );
26 $articleId = $article->insertOn( $dbw );
27 # Prepare and save associated revision
28 $revision = new Revision( array( 'page' => $articleId, 'text' => $text, 'user' => $user->mId, 'user_text' => $user->getName(), 'comment' => $comment ) );
29 $revisionId = $revision->insertOn( $dbw );
30 # Make it the current revision
31 $article->updateRevisionOn( $dbw, $revision );
32 $dbw->immediateCommit();
33 return( true );
34 } else {
35 # Title exists; touch nothing
36 return( false );
37 }
38 }
39
40 /**
41 * Turn a filename into a title
42 *
43 * @param $filename Filename to be transformed
44 * @return Title
45 */
46 function titleFromFilename( $filename ) {
47 $parts = explode( '/', $filename );
48 $parts = explode( '.', $parts[ count( $parts ) - 1 ] );
49 return( Title::newFromText( $parts[0] ) );
50 }
51
52 ?>