4 * Support functions for the importTextFile script
7 * @subpackage Maintenance
8 * @author Rob Church <robchur@gmail.com>
12 * Insert a new article
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
20 function insertNewArticle( &$title, $text, &$user, $comment ) {
21 if( !$title->exists() ) {
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();
35 # Title exists; touch nothing
41 * Turn a filename into a title
43 * @param $filename Filename to be transformed
46 function titleFromFilename( $filename ) {
47 $parts = explode( '/', $filename );
48 $parts = explode( '.', $parts[ count( $parts ) - 1 ] );
49 return( Title::newFromText( $parts[0] ) );