r43075 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r43074‎ | r43075 | r43076 >
Date:13:08, 2 November 2008
Author:siebrand
Status:old
Tags:
Comment:
Make username for creating category pages configurable from a message. Functionality by Tim Starling, copied from extension NewUserMessage.
Modified paths:
  • /trunk/extensions/uniwiki/AutoCreateCategoryPages/AutoCreateCategoryPages.i18n.php (modified) (history)
  • /trunk/extensions/uniwiki/AutoCreateCategoryPages/AutoCreateCategoryPages.php (modified) (history)

Diff [purge]

Index: trunk/extensions/uniwiki/AutoCreateCategoryPages/AutoCreateCategoryPages.php
@@ -21,9 +21,10 @@
2222
2323 /* ---- HOOKS ---- */
2424 $wgHooks['ArticleSaveComplete'][] = "UW_AutoCreateCategoryPages_Save";
 25+$wgHooks['UserGetReservedNames'][] = 'UW_OnUserGetReservedNames';
2526
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 ) {
2829 global $wgDBprefix;
2930
3031 /* after the page is saved, get all the categories
@@ -46,34 +47,48 @@
4748 $db = wfGetDB ( DB_MASTER );
4849 $results = $db->resultObject ( $db->query(
4950 "select distinct page_title from {$wgDBprefix}page " .
50 - "where page_namespace = '" . NS_CATEGORY . "'" ) );
 51+ "where page_namespace = '" . NS_CATEGORY . "'" )
 52+ );
5153
5254 $in_db = array();
5355 while ( $r = $results->next() )
5456 $in_db[] = $r->page_title;
5557
5658 /* 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 */
5860 foreach ( $on_page as $db_key ) {
5961 if ( !in_array( $db_key, $in_db ) ) {
6062
6163 wfLoadExtensionMessages( 'AutoCreateCategoryPages' );
6264
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
6473 $page_title = Title::newFromDBkey ( $db_key )->getText();
6574 $stub = wfMsgForContent ( 'autocreatecategorypages-stub', $page_title );
6675 $summary = wfMsgForContent ( 'autocreatecategorypages-createdby' );
6776 $article = new Article ( Title::newFromDBkey( "Category:$db_key" ) );
6877
6978 try {
70 - $article->doEdit ( $stub, $summary, EDIT_NEW & EDIT_SUPPRESS_RC );
 79+ $article->doEdit ( $stub, $summary, EDIT_NEW & EDIT_SUPPRESS_RC, false, $editor );
7180
7281 } catch ( MWException $e ) {
7382 /* fail silently...
74 - * todo: what can go wrong here? */
 83+ * todo: what can go wrong here? */
7584 }
7685 }
7786 }
7887
7988 return true;
8089 }
 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 @@
1414 'autocreatecategorypages-desc' => 'Create missing category pages automatically on save',
1515 'autocreatecategorypages-stub' => 'This is a category page.
1616 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
1819 );
1920
2021 $messages['es'] = array(

Status & tagging log