4 * Maintenance script allows creating or editing pages using
5 * the contents of a text file
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
23 * @ingroup Maintenance
24 * @author Rob Church <robchur@gmail.com>
27 $options = array( 'help', 'nooverwrite', 'norc' );
28 $optionsWithArgs = array( 'title', 'user', 'comment' );
29 require_once( dirname( __FILE__
) . '/commandLine.inc' );
30 echo( "Import Text File\n\n" );
32 if ( count( $args ) < 1 ||
isset( $options['help'] ) ) {
37 echo( "Using {$filename}..." );
38 if ( is_file( $filename ) ) {
40 $title = isset( $options['title'] ) ?
$options['title'] : titleFromFilename( $filename );
41 $title = Title
::newFromURL( $title );
43 if ( is_object( $title ) ) {
45 echo( "\nUsing title '" . $title->getPrefixedText() . "'..." );
46 if ( !$title->exists() ||
!isset( $options['nooverwrite'] ) ) {
48 $text = file_get_contents( $filename );
49 $user = isset( $options['user'] ) ?
$options['user'] : 'Maintenance script';
50 $user = User
::newFromName( $user );
52 if ( is_object( $user ) ) {
54 echo( "\nUsing username '" . $user->getName() . "'..." );
56 $comment = isset( $options['comment'] ) ?
$options['comment'] : 'Importing text file';
57 $flags = 0 |
( isset( $options['norc'] ) ? EDIT_SUPPRESS_RC
: 0 );
59 echo( "\nPerforming edit..." );
60 $page = WikiPage
::factory( $title );
61 $page->doEdit( $text, $comment, $flags, false, $user );
65 echo( "invalid username.\n" );
69 echo( "page exists.\n" );
73 echo( "invalid title.\n" );
77 echo( "does not exist.\n" );
82 function titleFromFilename( $filename ) {
83 $parts = explode( '/', $filename );
84 $parts = explode( '.', $parts[ count( $parts ) - 1 ] );
90 USAGE: php importTextFile.php <options> <filename>
92 <filename> : Path to the file containing page content to import
97 Title for the new page; default is to use the filename as a base
99 User to be associated with the edit
103 Don't overwrite existing content
105 Don't update recent changes
107 Show this information