Index: trunk/extensions/uniwiki/AutoCreateCategoryPages/AutoCreateCategoryPages.php |
— | — | @@ -21,9 +21,10 @@ |
22 | 22 | |
23 | 23 | /* ---- HOOKS ---- */ |
24 | 24 | $wgHooks['ArticleSaveComplete'][] = "UW_AutoCreateCategoryPages_Save"; |
| 25 | +$wgHooks['UserGetReservedNames'][] = 'UW_OnUserGetReservedNames'; |
25 | 26 | |
26 | | -function UW_AutoCreateCategoryPages_Save ( &$article, &$user, &$text, &$summary, &$minoredit, |
27 | | - &$watchthis, &$sectionanchor, &$flags, $revision ) { |
| 27 | +// FIXME: put methods in a class and their own file. |
| 28 | +function UW_AutoCreateCategoryPages_Save ( &$article, &$user, &$text, &$summary, &$minoredit, &$watchthis, &$sectionanchor, &$flags, $revision ) { |
28 | 29 | global $wgDBprefix; |
29 | 30 | |
30 | 31 | /* after the page is saved, get all the categories |
— | — | @@ -46,34 +47,48 @@ |
47 | 48 | $db = wfGetDB ( DB_MASTER ); |
48 | 49 | $results = $db->resultObject ( $db->query( |
49 | 50 | "select distinct page_title from {$wgDBprefix}page " . |
50 | | - "where page_namespace = '" . NS_CATEGORY . "'" ) ); |
| 51 | + "where page_namespace = '" . NS_CATEGORY . "'" ) |
| 52 | + ); |
51 | 53 | |
52 | 54 | $in_db = array(); |
53 | 55 | while ( $r = $results->next() ) |
54 | 56 | $in_db[] = $r->page_title; |
55 | 57 | |
56 | 58 | /* loop through the categories in the page and |
57 | | - * see if they already exist as a category page */ |
| 59 | + * see if they already exist as a category page */ |
58 | 60 | foreach ( $on_page as $db_key ) { |
59 | 61 | if ( !in_array( $db_key, $in_db ) ) { |
60 | 62 | |
61 | 63 | wfLoadExtensionMessages( 'AutoCreateCategoryPages' ); |
62 | 64 | |
63 | | - // if it doesn't exist, then create it here |
| 65 | + // Create a user object for the editing user and add it to the database |
| 66 | + // if it is not there already |
| 67 | + $editor = User::newFromName( wfMsgForContent( 'autocreatecategorypages-editor' ) ); |
| 68 | + if ( !$editor->isLoggedIn() ) { |
| 69 | + $editor->addToDatabase(); |
| 70 | + } |
| 71 | + |
| 72 | + // if it does not exist, then create it here |
64 | 73 | $page_title = Title::newFromDBkey ( $db_key )->getText(); |
65 | 74 | $stub = wfMsgForContent ( 'autocreatecategorypages-stub', $page_title ); |
66 | 75 | $summary = wfMsgForContent ( 'autocreatecategorypages-createdby' ); |
67 | 76 | $article = new Article ( Title::newFromDBkey( "Category:$db_key" ) ); |
68 | 77 | |
69 | 78 | try { |
70 | | - $article->doEdit ( $stub, $summary, EDIT_NEW & EDIT_SUPPRESS_RC ); |
| 79 | + $article->doEdit ( $stub, $summary, EDIT_NEW & EDIT_SUPPRESS_RC, false, $editor ); |
71 | 80 | |
72 | 81 | } catch ( MWException $e ) { |
73 | 82 | /* fail silently... |
74 | | - * todo: what can go wrong here? */ |
| 83 | + * todo: what can go wrong here? */ |
75 | 84 | } |
76 | 85 | } |
77 | 86 | } |
78 | 87 | |
79 | 88 | return true; |
80 | 89 | } |
| 90 | + |
| 91 | +function UW_OnUserGetReservedNames( &$names ) { |
| 92 | + wfLoadExtensionMessages( 'AutoCreateCategoryPages' ); |
| 93 | + $names[] = 'msg:autocreatecategorypages-editor'; |
| 94 | + return true; |
| 95 | +} |
Index: trunk/extensions/uniwiki/AutoCreateCategoryPages/AutoCreateCategoryPages.i18n.php |
— | — | @@ -13,7 +13,8 @@ |
14 | 14 | 'autocreatecategorypages-desc' => 'Create missing category pages automatically on save', |
15 | 15 | 'autocreatecategorypages-stub' => 'This is a category page. |
16 | 16 | It lists all of the pages in category "$1" as well as all subcategories of category "$1" if any exist.', |
17 | | - 'autocreatecategorypages-createdby' => 'Created automatically by the AutoCreateCategoryPages extension.' |
| 17 | + 'autocreatecategorypages-createdby' => 'Created automatically by the AutoCreateCategoryPages extension.', |
| 18 | + 'autocreatecategorypages-editor' => 'Automatic category creator', // The username used for the edit |
18 | 19 | ); |
19 | 20 | |
20 | 21 | $messages['es'] = array( |