r13643 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r13642‎ | r13643 | r13644 >
Date:17:36, 14 April 2006
Author:robchurch
Status:old
Tags:
Comment:
Update recent changes with an event upon page import; can be switched off with --norc
Modified paths:
  • /trunk/phase3/maintenance/importTextFile.inc (modified) (history)
  • /trunk/phase3/maintenance/importTextFile.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/importTextFile.inc
@@ -7,7 +7,9 @@
88 * @subpackage Maintenance
99 * @author Rob Church <robchur@gmail.com>
1010 */
11 -
 11+
 12+require_once( "$IP/includes/RecentChange.php" );
 13+
1214 /**
1315 * Insert a new article
1416 *
@@ -15,9 +17,10 @@
1618 * @param $text Text of the article
1719 * @param $user User associated with the edit
1820 * @param $comment Edit summary
 21+ * @param $rc Whether or not to add a recent changes event
1922 * @return bool
2023 */
21 -function insertNewArticle( &$title, $text, &$user, $comment ) {
 24+function insertNewArticle( &$title, $text, &$user, $comment, $rc ) {
2225 if( !$title->exists() ) {
2326 # Create the article
2427 $dbw =& wfGetDB( DB_MASTER );
@@ -30,6 +33,9 @@
3134 # Make it the current revision
3235 $article->updateRevisionOn( $dbw, $revision );
3336 $dbw->immediateCommit();
 37+ # Update recent changes if appropriate
 38+ if( $rc )
 39+ updateRecentChanges( $dbw, $title, $user, $comment, strlen( $text ), $articleId );
3440 return( true );
3541 } else {
3642 # Title exists; touch nothing
@@ -49,4 +55,18 @@
5056 return( Title::newFromText( $parts[0] ) );
5157 }
5258
 59+/**
 60+ * Update recent changes with the page creation event
 61+ *
 62+ * @param $dbw Database in use
 63+ * @param $title Title of the new page
 64+ * @param $user User responsible for the creation
 65+ * @param $comment Edit summary associated with the edit
 66+ * @param $size Size of the page
 67+ * @param $articleId Article identifier
 68+ */
 69+function updateRecentChanges( &$dbw, &$title, &$user, $comment, $size, $articleId ) {
 70+ RecentChange::notifyNew( $dbw->timestamp(), $title, false, $user, $comment, 'default', '', $size, $articleId );
 71+}
 72+
5373 ?>
\ No newline at end of file
Index: trunk/phase3/maintenance/importTextFile.php
@@ -8,7 +8,7 @@
99 * @author Rob Church <robchur@gmail.com>
1010 */
1111
12 -$options = array( 'help' );
 12+$options = array( 'help', 'norc' );
1313 $optionsWithArgs = array( 'title', 'user', 'comment' );
1414 require_once( 'commandLine.inc' );
1515 require_once( 'importTextFile.inc' );
@@ -62,9 +62,16 @@
6363 }
6464 echo( "Using edit summary '{$comment}'.\n" );
6565
 66+ # Do we need to update recent changes?
 67+ if( isset( $options['norc'] ) && $options['norc'] ) {
 68+ $rc = false;
 69+ } else {
 70+ $rc = true;
 71+ }
 72+
6673 # Attempt the insertion
6774 echo( "Attempting to insert page..." );
68 - $success = insertNewArticle( $title, $text, $user, $comment );
 75+ $success = insertNewArticle( $title, $text, $user, $comment, $rc );
6976 if( $success ) {
7077 echo( "done.\n" );
7178 } else {
@@ -89,12 +96,13 @@
9097 } else {
9198 # Show help
9299 echo( "Imports the contents of a text file into a wiki page.\n\n" );
93 - echo( "USAGE: php importTextFile.php [--help|--title <title>|--user <user>|--comment <comment>] <filename>\n\n" );
 100+ echo( "USAGE: php importTextFile.php [--help|--title <title>|--user <user>|--comment <comment>|--norc] <filename>\n\n" );
94101 echo( " --help: Show this help information\n" );
95102 echo( " --title <title> : Title for the new page; if not supplied, the filename is used as a base for the title\n" );
96103 echo( " --user <user> : User to be associated with the edit; if not supplied, a default is used\n" );
97104 echo( "--comment <comment> : Edit summary to be associated with the edit; underscores are transformed into spaces; if not supplied, a default is used\n" );
98105 echo( " <filename> : Path to the file containing the wikitext to import\n" );
 106+ echo( " --norc : Do not add a page creation event to recent changes\n" );
99107
100108 }
101109 echo( "\n" );

Status & tagging log