fix line endings
authorBrion Vibber <brion@users.mediawiki.org>
Tue, 18 Apr 2006 00:10:54 +0000 (00:10 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Tue, 18 Apr 2006 00:10:54 +0000 (00:10 +0000)
maintenance/fixTimestamps.php
maintenance/importTextFile.inc
maintenance/importTextFile.php

index 9889a63..784e35c 100644 (file)
-<?php\r
-\r
-/**\r
- * This script fixes timestamp corruption caused by one or more webservers \r
- * temporarily being set to the wrong time. The time offset must be known and\r
- * consistent. Start and end times (in 14-character format) restrict the search, \r
- * and must bracket the damage. There must be a majority of good timestamps in the \r
- * search period.\r
- */\r
-\r
-require_once( 'commandLine.inc' );\r
-\r
-if ( count( $args ) < 3 ) {\r
-       echo "Usage: php fixTimestamps.php <offset in hours> <start time> <end time>\n";\r
-       exit(1);\r
-}\r
-\r
-$offset = $args[0] * 3600;\r
-$start = $args[1];\r
-$end = $args[2];\r
-$fname = 'fixTimestamps.php';\r
-$grace = 60; // maximum normal clock offset\r
-\r
-# Find bounding revision IDs\r
-$dbw =& wfGetDB( DB_MASTER );\r
-$revisionTable = $dbw->tableName( 'revision' );\r
-$res = $dbw->query( "SELECT MIN(rev_id) as minrev, MAX(rev_id) as maxrev FROM $revisionTable " .\r
-       "WHERE rev_timestamp BETWEEN '{$start}' AND '{$end}'", $fname );\r
-$row = $dbw->fetchObject( $res );\r
-\r
-if ( is_null( $row->minrev ) ) {\r
-       echo "No revisions in search period.\n";\r
-       exit(0);\r
-}\r
-\r
-$minRev = $row->minrev;\r
-$maxRev = $row->maxrev;\r
-\r
-# Select all timestamps and IDs\r
-$sql = "SELECT rev_id, rev_timestamp FROM $revisionTable " .\r
-       "WHERE rev_id BETWEEN $minRev AND $maxRev";\r
-if ( $offset > 0 ) {\r
-       $sql .= " ORDER BY rev_id DESC";\r
-       $expectedSign = -1;\r
-} else {\r
-       $expectedSign = 1;\r
-}\r
-\r
-$res = $dbw->query( $sql, $fname );\r
-\r
-$lastNormal = 0;\r
-$badRevs = array();\r
-$numGoodRevs = 0;\r
-\r
-while ( $row = $dbw->fetchObject( $res ) ) {\r
-       $timestamp = wfTimestamp( TS_UNIX, $row->rev_timestamp );\r
-       $delta = $timestamp - $lastNormal;\r
-       $sign = $delta == 0 ? 0 : $delta / abs( $delta );\r
-       if ( $sign == 0 || $sign == $expectedSign ) {\r
-               // Monotonic change\r
-               $lastNormal = $timestamp;\r
-               ++ $numGoodRevs;\r
-               continue;\r
-       } elseif ( abs( $delta ) <= $grace ) {\r
-               // Non-monotonic change within grace interval\r
-               ++ $numGoodRevs;\r
-               continue;\r
-       } else {\r
-               // Non-monotonic change larger than grace interval\r
-               $badRevs[] = $row->rev_id;\r
-       }\r
-}\r
-$dbw->freeResult( $res );\r
-\r
-$numBadRevs = count( $badRevs );\r
-if ( $numBadRevs > $numGoodRevs ) {\r
-       echo \r
-"The majority of revisions in the search interval are marked as bad.\r
-\r
-Are you sure the offset ($offset) has the right sign? Positive means the clock \r
-was incorrectly set forward, negative means the clock was incorrectly set back.\r
-\r
-If the offset is right, then increase the search interval until there are enough \r
-good revisions to provide a majority reference.\r
-";\r
-\r
-       exit(1);\r
-} elseif ( $numBadRevs == 0 ) {\r
-       echo "No bad revisions found.\n";\r
-       exit(0);\r
-}\r
-\r
-printf( "Fixing %d revisions (%.2f%% of revisions in search interval)\n", \r
-       $numBadRevs, $numBadRevs / ($numGoodRevs + $numBadRevs) * 100 );\r
-\r
-$fixup = -$offset;\r
-$sql = "UPDATE $revisionTable " .\r
-       "SET rev_timestamp=DATE_FORMAT(DATE_ADD(rev_timestamp, INTERVAL $fixup SECOND), '%Y%m%d%H%i%s') " .\r
-       "WHERE rev_id IN (" . $dbw->makeList( $badRevs ) . ')';\r
-//echo "$sql\n";\r
-$dbw->query( $sql, $fname );\r
-echo "Done\n";\r
-\r
-?>\r
+<?php
+
+/**
+ * This script fixes timestamp corruption caused by one or more webservers 
+ * temporarily being set to the wrong time. The time offset must be known and
+ * consistent. Start and end times (in 14-character format) restrict the search, 
+ * and must bracket the damage. There must be a majority of good timestamps in the 
+ * search period.
+ */
+
+require_once( 'commandLine.inc' );
+
+if ( count( $args ) < 3 ) {
+       echo "Usage: php fixTimestamps.php <offset in hours> <start time> <end time>\n";
+       exit(1);
+}
+
+$offset = $args[0] * 3600;
+$start = $args[1];
+$end = $args[2];
+$fname = 'fixTimestamps.php';
+$grace = 60; // maximum normal clock offset
+
+# Find bounding revision IDs
+$dbw =& wfGetDB( DB_MASTER );
+$revisionTable = $dbw->tableName( 'revision' );
+$res = $dbw->query( "SELECT MIN(rev_id) as minrev, MAX(rev_id) as maxrev FROM $revisionTable " .
+       "WHERE rev_timestamp BETWEEN '{$start}' AND '{$end}'", $fname );
+$row = $dbw->fetchObject( $res );
+
+if ( is_null( $row->minrev ) ) {
+       echo "No revisions in search period.\n";
+       exit(0);
+}
+
+$minRev = $row->minrev;
+$maxRev = $row->maxrev;
+
+# Select all timestamps and IDs
+$sql = "SELECT rev_id, rev_timestamp FROM $revisionTable " .
+       "WHERE rev_id BETWEEN $minRev AND $maxRev";
+if ( $offset > 0 ) {
+       $sql .= " ORDER BY rev_id DESC";
+       $expectedSign = -1;
+} else {
+       $expectedSign = 1;
+}
+
+$res = $dbw->query( $sql, $fname );
+
+$lastNormal = 0;
+$badRevs = array();
+$numGoodRevs = 0;
+
+while ( $row = $dbw->fetchObject( $res ) ) {
+       $timestamp = wfTimestamp( TS_UNIX, $row->rev_timestamp );
+       $delta = $timestamp - $lastNormal;
+       $sign = $delta == 0 ? 0 : $delta / abs( $delta );
+       if ( $sign == 0 || $sign == $expectedSign ) {
+               // Monotonic change
+               $lastNormal = $timestamp;
+               ++ $numGoodRevs;
+               continue;
+       } elseif ( abs( $delta ) <= $grace ) {
+               // Non-monotonic change within grace interval
+               ++ $numGoodRevs;
+               continue;
+       } else {
+               // Non-monotonic change larger than grace interval
+               $badRevs[] = $row->rev_id;
+       }
+}
+$dbw->freeResult( $res );
+
+$numBadRevs = count( $badRevs );
+if ( $numBadRevs > $numGoodRevs ) {
+       echo 
+"The majority of revisions in the search interval are marked as bad.
+
+Are you sure the offset ($offset) has the right sign? Positive means the clock 
+was incorrectly set forward, negative means the clock was incorrectly set back.
+
+If the offset is right, then increase the search interval until there are enough 
+good revisions to provide a majority reference.
+";
+
+       exit(1);
+} elseif ( $numBadRevs == 0 ) {
+       echo "No bad revisions found.\n";
+       exit(0);
+}
+
+printf( "Fixing %d revisions (%.2f%% of revisions in search interval)\n", 
+       $numBadRevs, $numBadRevs / ($numGoodRevs + $numBadRevs) * 100 );
+
+$fixup = -$offset;
+$sql = "UPDATE $revisionTable " .
+       "SET rev_timestamp=DATE_FORMAT(DATE_ADD(rev_timestamp, INTERVAL $fixup SECOND), '%Y%m%d%H%i%s') " .
+       "WHERE rev_id IN (" . $dbw->makeList( $badRevs ) . ')';
+//echo "$sql\n";
+$dbw->query( $sql, $fname );
+echo "Done\n";
+
+?>
index 165d884..00efc5c 100644 (file)
@@ -1,74 +1,74 @@
-<?php\r
-\r
-/**\r
- * Support functions for the importTextFile script\r
- *\r
- * @package MediaWiki\r
- * @subpackage Maintenance\r
- * @author Rob Church <robchur@gmail.com>\r
- */\r
-\r
-require_once( "$IP/includes/RecentChange.php" );\r
-\r
-/**\r
- * Insert a new article\r
- *\r
- * @param $title Title of the article\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, $rc ) {\r
-       if( !$title->exists() ) {\r
-               # Create the article\r
-               $dbw =& wfGetDB( DB_MASTER );\r
-               $dbw->immediateBegin();\r
-               $article = new Article( $title );\r
-               $articleId = $article->insertOn( $dbw );\r
-               # Prepare and save associated revision\r
-               $revision = new Revision( array( 'page' => $articleId, 'text' => $text, 'user' => $user->mId, 'user_text' => $user->getName(), 'comment' => $comment ) );\r
-               $revisionId = $revision->insertOn( $dbw );\r
-               # 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
-               # Touch links etc.\r
-               Article::onArticleCreate( $title );     \r
-               return( true );\r
-       } else {\r
-               # Title exists; touch nothing\r
-               return( false );\r
-       }\r
-}\r
-\r
-/**\r
- * Turn a filename into a title\r
- *\r
- * @param $filename Filename to be transformed\r
- * @return Title\r
- */\r
-function titleFromFilename( $filename ) {\r
-       $parts = explode( '/', $filename );\r
-       $parts = explode( '.', $parts[ count( $parts ) - 1 ] );\r
-       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
+<?php
+
+/**
+ * Support functions for the importTextFile script
+ *
+ * @package MediaWiki
+ * @subpackage Maintenance
+ * @author Rob Church <robchur@gmail.com>
+ */
+
+require_once( "$IP/includes/RecentChange.php" );
+
+/**
+ * Insert a new article
+ *
+ * @param $title Title of the article
+ * @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, $rc ) {
+       if( !$title->exists() ) {
+               # Create the article
+               $dbw =& wfGetDB( DB_MASTER );
+               $dbw->immediateBegin();
+               $article = new Article( $title );
+               $articleId = $article->insertOn( $dbw );
+               # Prepare and save associated revision
+               $revision = new Revision( array( 'page' => $articleId, 'text' => $text, 'user' => $user->mId, 'user_text' => $user->getName(), 'comment' => $comment ) );
+               $revisionId = $revision->insertOn( $dbw );
+               # 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 );
+               # Touch links etc.
+               Article::onArticleCreate( $title );     
+               return( true );
+       } else {
+               # Title exists; touch nothing
+               return( false );
+       }
+}
+
+/**
+ * Turn a filename into a title
+ *
+ * @param $filename Filename to be transformed
+ * @return Title
+ */
+function titleFromFilename( $filename ) {
+       $parts = explode( '/', $filename );
+       $parts = explode( '.', $parts[ count( $parts ) - 1 ] );
+       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
index d925edc..7f6d8ca 100644 (file)
-<?php\r
-\r
-/**\r
- * Maintenance script to insert an article, importing text from a file\r
- *\r
- * @package MediaWiki\r
- * @subpackage Maintenance\r
- * @author Rob Church <robchur@gmail.com>\r
- */\r
-\r
-$options = array( 'help', 'norc' ); \r
-$optionsWithArgs = array( 'title', 'user', 'comment' );\r
-require_once( 'commandLine.inc' );\r
-require_once( 'importTextFile.inc' );\r
-echo( "Import Text File\n\n" );\r
-\r
-if( !isset( $options['help'] ) || !$options['help'] ) {\r
-\r
-       # Check file existence\r
-       $filename = $args[0];\r
-       echo( "Using file '{$filename}'..." );\r
-       if( file_exists( $filename ) ) {\r
-               echo( "found.\n" );\r
-       \r
-               # Work out the title for the page       \r
-               if( isset( $option['title'] ) || trim( $options['title'] ) != '' ) {\r
-                       $titleText = $options['title'];\r
-                       # Use the supplied title\r
-                       echo( "Using title '{$titleText}'..." );\r
-                       $title = Title::newFromText( $options['title'] );\r
-               } else {\r
-                       # Attempt to make a title out of the filename\r
-                       echo( "Using title from filename..." );\r
-                       $title = titleFromFilename( $filename );\r
-               }\r
-               \r
-               # Check the title's valid\r
-               if( !is_null( $title ) && is_object( $title ) ) {\r
-                       echo( "ok.\n" );\r
-               \r
-                       # Read in the text\r
-                       $text = file_get_contents( $filename );\r
-                       \r
-                       # Check the supplied user and fall back to a default if needed\r
-                       if( isset( $options['user'] ) && trim( $options['user'] ) != '' ) {\r
-                               $username = $options['user'];\r
-                       } else {\r
-                               $username = 'MediaWiki default';\r
-                       }\r
-                       echo( "Using user '{$username}'..." );\r
-                       $user = User::newFromName( $username );\r
-                       \r
-                       # Check the user's valid\r
-                       if( !is_null( $user ) && is_object( $user ) ) {\r
-                               echo( "ok.\n" );\r
-                       \r
-                               # If a comment was supplied, use it (replace _ with spaces ) else use a default\r
-                               if( isset( $options['comment'] ) || trim( $options['comment'] != '' ) ) {\r
-                                       $comment = str_replace( '_', ' ', $options['comment'] );\r
-                               } else {\r
-                                       $comment = 'Importing text file';\r
-                               }\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, $rc );\r
-                               if( $success ) {\r
-                                       echo( "done.\n" );\r
-                               } else {\r
-                                       echo( "failed. Title exists.\n" );\r
-                               }\r
-                       \r
-                       } else {\r
-                               # Dud user\r
-                               echo( "invalid username.\n" );\r
-                       }\r
-                       \r
-               } else {\r
-                       # Dud title\r
-                       echo( "invalid title.\n" );\r
-               }\r
-               \r
-       } else {\r
-               # File not found\r
-               echo( "not found.\n" );\r
-       }\r
-\r
-} 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>|--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
-\r
+<?php
+
+/**
+ * Maintenance script to insert an article, importing text from a file
+ *
+ * @package MediaWiki
+ * @subpackage Maintenance
+ * @author Rob Church <robchur@gmail.com>
+ */
+
+$options = array( 'help', 'norc' ); 
+$optionsWithArgs = array( 'title', 'user', 'comment' );
+require_once( 'commandLine.inc' );
+require_once( 'importTextFile.inc' );
+echo( "Import Text File\n\n" );
+
+if( !isset( $options['help'] ) || !$options['help'] ) {
+
+       # Check file existence
+       $filename = $args[0];
+       echo( "Using file '{$filename}'..." );
+       if( file_exists( $filename ) ) {
+               echo( "found.\n" );
+       
+               # Work out the title for the page       
+               if( isset( $option['title'] ) || trim( $options['title'] ) != '' ) {
+                       $titleText = $options['title'];
+                       # Use the supplied title
+                       echo( "Using title '{$titleText}'..." );
+                       $title = Title::newFromText( $options['title'] );
+               } else {
+                       # Attempt to make a title out of the filename
+                       echo( "Using title from filename..." );
+                       $title = titleFromFilename( $filename );
+               }
+               
+               # Check the title's valid
+               if( !is_null( $title ) && is_object( $title ) ) {
+                       echo( "ok.\n" );
+               
+                       # Read in the text
+                       $text = file_get_contents( $filename );
+                       
+                       # Check the supplied user and fall back to a default if needed
+                       if( isset( $options['user'] ) && trim( $options['user'] ) != '' ) {
+                               $username = $options['user'];
+                       } else {
+                               $username = 'MediaWiki default';
+                       }
+                       echo( "Using user '{$username}'..." );
+                       $user = User::newFromName( $username );
+                       
+                       # Check the user's valid
+                       if( !is_null( $user ) && is_object( $user ) ) {
+                               echo( "ok.\n" );
+                       
+                               # If a comment was supplied, use it (replace _ with spaces ) else use a default
+                               if( isset( $options['comment'] ) || trim( $options['comment'] != '' ) ) {
+                                       $comment = str_replace( '_', ' ', $options['comment'] );
+                               } else {
+                                       $comment = 'Importing text file';
+                               }
+                               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, $rc );
+                               if( $success ) {
+                                       echo( "done.\n" );
+                               } else {
+                                       echo( "failed. Title exists.\n" );
+                               }
+                       
+                       } else {
+                               # Dud user
+                               echo( "invalid username.\n" );
+                       }
+                       
+               } else {
+                       # Dud title
+                       echo( "invalid title.\n" );
+               }
+               
+       } else {
+               # File not found
+               echo( "not found.\n" );
+       }
+
+} else {
+       # Show help
+       echo( "Imports the contents of a text file into a wiki page.\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" );  
+
 ?>
\ No newline at end of file