From ee07b5c53c0cadf31e14c4c45d2358f51139aa7c Mon Sep 17 00:00:00 2001 From: Rob Church Date: Fri, 14 Apr 2006 17:36:52 +0000 Subject: [PATCH] Update recent changes with an event upon page import; can be switched off with --norc --- maintenance/importTextFile.inc | 24 ++++++++++++++++++++++-- maintenance/importTextFile.php | 14 +++++++++++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/maintenance/importTextFile.inc b/maintenance/importTextFile.inc index 7794827068..804a9088a7 100644 --- a/maintenance/importTextFile.inc +++ b/maintenance/importTextFile.inc @@ -7,7 +7,9 @@ * @subpackage Maintenance * @author Rob Church */ - + +require_once( "$IP/includes/RecentChange.php" ); + /** * Insert a new article * @@ -15,9 +17,10 @@ * @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 ) { +function insertNewArticle( &$title, $text, &$user, $comment, $rc ) { if( !$title->exists() ) { # Create the article $dbw =& wfGetDB( DB_MASTER ); @@ -30,6 +33,9 @@ function insertNewArticle( &$title, $text, &$user, $comment ) { # 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 ); return( true ); } else { # Title exists; touch nothing @@ -49,4 +55,18 @@ function titleFromFilename( $filename ) { 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 diff --git a/maintenance/importTextFile.php b/maintenance/importTextFile.php index c8b00cb2a3..d925edc65b 100644 --- a/maintenance/importTextFile.php +++ b/maintenance/importTextFile.php @@ -8,7 +8,7 @@ * @author Rob Church */ -$options = array( 'help' ); +$options = array( 'help', 'norc' ); $optionsWithArgs = array( 'title', 'user', 'comment' ); require_once( 'commandLine.inc' ); require_once( 'importTextFile.inc' ); @@ -62,9 +62,16 @@ if( !isset( $options['help'] ) || !$options['help'] ) { } echo( "Using edit summary '{$comment}'.\n" ); + # Do we need to update recent changes? + if( isset( $options['norc'] ) && $options['norc'] ) { + $rc = false; + } else { + $rc = true; + } + # Attempt the insertion echo( "Attempting to insert page..." ); - $success = insertNewArticle( $title, $text, $user, $comment ); + $success = insertNewArticle( $title, $text, $user, $comment, $rc ); if( $success ) { echo( "done.\n" ); } else { @@ -89,12 +96,13 @@ if( !isset( $options['help'] ) || !$options['help'] ) { } else { # Show help echo( "Imports the contents of a text file into a wiki page.\n\n" ); - echo( "USAGE: php importTextFile.php [--help|--title |--user <user>|--comment <comment>] <filename>\n\n" ); + echo( "USAGE: php importTextFile.php [--help|--title <title>|--user <user>|--comment <comment>|--norc] <filename>\n\n" ); echo( " --help: Show this help information\n" ); echo( " --title <title> : Title for the new page; if not supplied, the filename is used as a base for the title\n" ); echo( " --user <user> : User to be associated with the edit; if not supplied, a default is used\n" ); echo( "--comment <comment> : Edit summary to be associated with the edit; underscores are transformed into spaces; if not supplied, a default is used\n" ); echo( " <filename> : Path to the file containing the wikitext to import\n" ); + echo( " --norc : Do not add a page creation event to recent changes\n" ); } echo( "\n" ); -- 2.20.1