Index: trunk/phase3/maintenance/importLogs.inc |
— | — | @@ -1,144 +0,0 @@ |
2 | | -<?php |
3 | | -# Copyright (C) 2004 Brion Vibber <brion@pobox.com> |
4 | | -# http://www.mediawiki.org/ |
5 | | -# |
6 | | -# This program is free software; you can redistribute it and/or modify |
7 | | -# it under the terms of the GNU General Public License as published by |
8 | | -# the Free Software Foundation; either version 2 of the License, or |
9 | | -# (at your option) any later version. |
10 | | -# |
11 | | -# This program is distributed in the hope that it will be useful, |
12 | | -# but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | -# GNU General Public License for more details. |
15 | | -# |
16 | | -# You should have received a copy of the GNU General Public License along |
17 | | -# with this program; if not, write to the Free Software Foundation, Inc., |
18 | | -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
19 | | -# http://www.gnu.org/copyleft/gpl.html |
20 | | - |
21 | | -/** |
22 | | - * Attempt to import existing log pages into the log tables. |
23 | | - * |
24 | | - * Not yet complete. |
25 | | - * |
26 | | - * @file |
27 | | - * @todo document |
28 | | - * @ingroup Maintenance |
29 | | - */ |
30 | | - |
31 | | -/** */ |
32 | | -require_once( 'GlobalFunctions.php' ); |
33 | | -require_once( 'Database.php' ); |
34 | | -require_once( 'Article.php' ); |
35 | | -require_once( 'LogPage.php' ); |
36 | | - |
37 | | -/** |
38 | | - * Log importer |
39 | | - * @todo document |
40 | | - * @ingroup Maintenance |
41 | | - */ |
42 | | -class LogImporter { |
43 | | - var $dummy = false; |
44 | | - |
45 | | - function LogImporter( $type ) { |
46 | | - $this->type = $type; |
47 | | - $this->db = wfGetDB( DB_MASTER ); |
48 | | - $this->actions = $this->setupActions(); |
49 | | - } |
50 | | - |
51 | | - function setupActions() { |
52 | | - $actions = array(); |
53 | | - foreach( LogPage::validActions( $this->type ) as $action ) { |
54 | | - $key = "{$this->type}/$action"; |
55 | | - $actions[$key] = $this->makeLineRegexp( $this->type, $action ); |
56 | | - } |
57 | | - return $actions; |
58 | | - } |
59 | | - |
60 | | - function makeLineRegexp( $type, $action ) { |
61 | | - $linkRegexp = '(?:\[\[)?([^|\]]+?)(?:\|[^\]]+?)?(?:\]\])?'; |
62 | | - $linkRegexp2 = '\[\[([^|\]]+?)(?:\|[^\]]+?)?\]\]'; |
63 | | - |
64 | | - $text = LogPage::actionText( $type, $action ); |
65 | | - $text = preg_quote( $text, '/' ); |
66 | | - $text = str_replace( '\$1', $linkRegexp, $text ); |
67 | | - $text = '^(.*?) ' . $linkRegexp2 . ' ' . $text; |
68 | | - $text .= '(?: <em>\((.*)\)<\/em>)?'; |
69 | | - $text = "/$text/"; |
70 | | - return $text; |
71 | | - } |
72 | | - |
73 | | - function importText( $text ) { |
74 | | - if( $this->dummy ) { |
75 | | - print $text; |
76 | | - var_dump( $this->actions ); |
77 | | - } |
78 | | - $lines = explode( '<li>', $text ); |
79 | | - foreach( $lines as $line ) { |
80 | | - $matches = array(); |
81 | | - if( preg_match( '!^(.*)</li>!', $line, $matches ) ) { |
82 | | - $this->importLine( $matches[1] ); |
83 | | - } |
84 | | - } |
85 | | - } |
86 | | - |
87 | | - function fixDate( $date ) { |
88 | | - # Yuck! Parsing multilingual date formats??!!!!???!!??! |
89 | | - # 01:55, 23 Aug 2004 - won't take in strtotimr |
90 | | - # "Aug 23 2004 01:55" - seems ok |
91 | | - # TODO: multilingual attempt to extract from the data in Language |
92 | | - $matches = array(); |
93 | | - if( preg_match( '/^(\d+:\d+(?::\d+)?), (.*)$/', $date, $matches ) ) { |
94 | | - $date = $matches[2] . ' ' . $matches[1]; |
95 | | - } |
96 | | - $n = strtotime( $date ) + date("Z"); |
97 | | - # print gmdate( 'D, d M Y H:i:s T', $n ) . "\n"; |
98 | | - $timestamp = wfTimestamp( TS_MW, $n ); |
99 | | - return $timestamp; |
100 | | - } |
101 | | - |
102 | | - function importLine( $line ) { |
103 | | - foreach( $this->actions as $action => $regexp ) { |
104 | | - $matches = array(); |
105 | | - if( preg_match( $regexp, $line, $matches ) ) { |
106 | | - if( $this->dummy ) { |
107 | | - #var_dump( $matches ); |
108 | | - } |
109 | | - $date = $this->fixDate( $matches[1] ); |
110 | | - $user = Title::newFromText( $matches[2] ); |
111 | | - $target = Title::newFromText( $matches[3] ); |
112 | | - if( isset( $matches[4] ) ) { |
113 | | - $comment = $matches[4]; |
114 | | - } else { |
115 | | - $comment = ''; |
116 | | - } |
117 | | - |
118 | | - $insert = array( |
119 | | - 'log_type' => $this->type, |
120 | | - 'log_action' => preg_replace( '!^.*/!', '', $action ), |
121 | | - 'log_timestamp' => $date, |
122 | | - 'log_user' => intval( User::idFromName( $user->getText() ) ), |
123 | | - 'log_namespace' => $target->getNamespace(), |
124 | | - 'log_title' => $target->getDBkey(), |
125 | | - 'log_comment' => wfUnescapeWikiText( $comment ), |
126 | | - ); |
127 | | - if( $this->dummy ) { |
128 | | - var_dump( $insert ); |
129 | | - } else { |
130 | | - # FIXME: avoid duplicates! |
131 | | - $this->db->insert( 'logging', $insert ); |
132 | | - } |
133 | | - break; |
134 | | - } |
135 | | - } |
136 | | - } |
137 | | -} |
138 | | - |
139 | | -function wfUnescapeWikiText( $text ) { |
140 | | - $text = str_replace( |
141 | | - array( '[', '|', ''', 'ISBN ', '://' , "\n=", '{{' ), |
142 | | - array( '[', '|', "'", 'ISBN ' , '://' , "\n=", '{{' ), |
143 | | - $text ); |
144 | | - return $text; |
145 | | -} |
Index: trunk/phase3/maintenance/importLogs.php |
— | — | @@ -1,27 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * @todo document |
5 | | - * @file |
6 | | - * @ingroup Maintenance |
7 | | - */ |
8 | | - |
9 | | -/** */ |
10 | | -require_once( "commandLine.inc" ); |
11 | | -require_once( "importLogs.inc" ); |
12 | | - |
13 | | -#print $text; |
14 | | -#exit(); |
15 | | - |
16 | | -foreach( LogPage::validTypes() as $type ) { |
17 | | - if( $type == '' ) continue; |
18 | | - |
19 | | - $page = LogPage::logName( $type ); |
20 | | - $log = new Article( Title::makeTitleSafe( NS_PROJECT, $page ) ); |
21 | | - $text = $log->fetchContent(); |
22 | | - |
23 | | - $importer = new LogImporter( $type ); |
24 | | - $importer->dummy = true; |
25 | | - $importer->importText( $text ); |
26 | | -} |
27 | | - |
28 | | - |