Update recent changes with an event upon page import; can be switched off with -...
authorRob Church <robchurch@users.mediawiki.org>
Fri, 14 Apr 2006 17:36:52 +0000 (17:36 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Fri, 14 Apr 2006 17:36:52 +0000 (17:36 +0000)
maintenance/importTextFile.inc
maintenance/importTextFile.php

index 7794827..804a908 100644 (file)
@@ -7,7 +7,9 @@
  * @subpackage Maintenance\r
  * @author Rob Church <robchur@gmail.com>\r
  */\r
\r
+\r
+require_once( "$IP/includes/RecentChange.php" );\r
+\r
 /**\r
  * Insert a new article\r
  *\r
  * @param $text Text of the article\r
  * @param $user User associated with the edit\r
  * @param $comment Edit summary\r
+ * @param $rc Whether or not to add a recent changes event\r
  * @return bool\r
  */\r
-function insertNewArticle( &$title, $text, &$user, $comment ) {\r
+function insertNewArticle( &$title, $text, &$user, $comment, $rc ) {\r
        if( !$title->exists() ) {\r
                # Create the article\r
                $dbw =& wfGetDB( DB_MASTER );\r
@@ -30,6 +33,9 @@ function insertNewArticle( &$title, $text, &$user, $comment ) {
                # Make it the current revision\r
                $article->updateRevisionOn( $dbw, $revision );\r
                $dbw->immediateCommit();\r
+               # Update recent changes if appropriate\r
+               if( $rc )\r
+                       updateRecentChanges( $dbw, $title, $user, $comment, strlen( $text ), $articleId );              \r
                return( true );\r
        } else {\r
                # Title exists; touch nothing\r
@@ -49,4 +55,18 @@ function titleFromFilename( $filename ) {
        return( Title::newFromText( $parts[0] ) );\r
 }\r
 \r
+/**\r
+ * Update recent changes with the page creation event\r
+ *\r
+ * @param $dbw Database in use\r
+ * @param $title Title of the new page\r
+ * @param $user User responsible for the creation\r
+ * @param $comment Edit summary associated with the edit\r
+ * @param $size Size of the page\r
+ * @param $articleId Article identifier\r
+ */ \r
+function updateRecentChanges( &$dbw, &$title, &$user, $comment, $size, $articleId ) {\r
+       RecentChange::notifyNew( $dbw->timestamp(), $title, false, $user, $comment, 'default', '', $size, $articleId );\r
+}\r
+\r
 ?>
\ No newline at end of file
index c8b00cb..d925edc 100644 (file)
@@ -8,7 +8,7 @@
  * @author Rob Church <robchur@gmail.com>\r
  */\r
 \r
-$options = array( 'help' ); \r
+$options = array( 'help', 'norc' ); \r
 $optionsWithArgs = array( 'title', 'user', 'comment' );\r
 require_once( 'commandLine.inc' );\r
 require_once( 'importTextFile.inc' );\r
@@ -62,9 +62,16 @@ if( !isset( $options['help'] ) || !$options['help'] ) {
                                }\r
                                echo( "Using edit summary '{$comment}'.\n" );\r
                        \r
+                               # Do we need to update recent changes?\r
+                               if( isset( $options['norc'] ) && $options['norc'] ) {\r
+                                       $rc = false;\r
+                               } else {\r
+                                       $rc = true;\r
+                               }\r
+                       \r
                                # Attempt the insertion\r
                                echo( "Attempting to insert page..." );\r
-                               $success = insertNewArticle( $title, $text, $user, $comment );\r
+                               $success = insertNewArticle( $title, $text, $user, $comment, $rc );\r
                                if( $success ) {\r
                                        echo( "done.\n" );\r
                                } else {\r
@@ -89,12 +96,13 @@ if( !isset( $options['help'] ) || !$options['help'] ) {
 } else {\r
        # Show help\r
        echo( "Imports the contents of a text file into a wiki page.\n\n" );\r
-       echo( "USAGE: php importTextFile.php [--help|--title <title>|--user <user>|--comment <comment>] <filename>\n\n" );\r
+       echo( "USAGE: php importTextFile.php [--help|--title <title>|--user <user>|--comment <comment>|--norc] <filename>\n\n" );\r
        echo( "              --help: Show this help information\n" );\r
        echo( "    --title <title> : Title for the new page; if not supplied, the filename is used as a base for the title\n" );\r
        echo( "      --user <user> : User to be associated with the edit; if not supplied, a default is used\n" );\r
        echo( "--comment <comment> : Edit summary to be associated with the edit; underscores are transformed into spaces; if not supplied, a default is used\n" );\r
        echo( "         <filename> : Path to the file containing the wikitext to import\n" );\r
+       echo( "             --norc : Do not add a page creation event to recent changes\n" );\r
 \r
 }\r
 echo( "\n" );  \r