r43026 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r43025‎ | r43026 | r43027 >
Date:21:03, 1 November 2008
Author:siebrand
Status:old
Tags:
Comment:
Update for uniwiki/AutoCreateCategoryPages:
* standard i18n, change message IDs
* use wfMsgForContent in edit summaries and page creation
* complete extension credits
* update indentation, remove trailing whitespace, stylize.php
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
@@ -3,32 +3,27 @@
44 * http://www.mediawiki.org/wiki/Extension:Uniwiki_Auto_Create_Category_Pages
55 * http://www.gnu.org/licenses/gpl-3.0.txt */
66
7 -if (!defined('MEDIAWIKI'))
 7+if ( !defined( 'MEDIAWIKI' ) )
88 die();
99
1010 /* ---- CREDITS ---- */
1111 $wgExtensionCredits['other'][] = array(
12 - 'name' => "AutoCreateCategoryPages",
13 - 'author' => "Merrick Schaefer, Mark Johnston, Evan Wheeler and Adam Mckaig (at UNICEF)",
14 - 'description' => "Create stub Category pages automatically"
 12+ 'name' => 'AutoCreateCategoryPages',
 13+ 'author' => 'Merrick Schaefer, Mark Johnston, Evan Wheeler and Adam Mckaig (at UNICEF)',
 14+ 'description' => 'Create stub Category pages automatically',
 15+ 'url' => 'http://www.mediawiki.org/wiki/Extension:Uniwiki/AutoCreateCategoryPages',
 16+ 'svn-date' => '$LastChangedDate$',
 17+ 'svn-revision' => '$LastChangedRevision$',
 18+ 'descriptionmsg' => 'autocreatecategorypages-desc',
1519 );
1620
17 -/* ---- INTERNATIONALIZATION ---- */
 21+$wgExtensionMessagesFiles['AutoCreateCategoryPages'] = dirname( __FILE__ ) . '/AutoCreateCategoryPages.i18n.php';
1822
19 -require_once ("AutoCreateCategoryPages.i18n.php");
20 -$wgExtensionFunctions[] = "AutoCreateCategoryPages_i18n";
21 -
22 -function AutoCreateCategoryPages_i18n() {
23 - // add this extension's messages to the message cache
24 - global $wgMessageCache, $wgAutoCreateCategoryPagesMessages;
25 - foreach ($wgAutoCreateCategoryPagesMessages as $lang => $messages)
26 - $wgMessageCache->addMessages ($messages, $lang);
27 -}
28 -
2923 /* ---- HOOKS ---- */
3024 $wgHooks['ArticleSaveComplete'][] = "UW_AutoCreateCategoryPages_Save";
31 -function UW_AutoCreateCategoryPages_Save (&$article, &$user, &$text, &$summary, &$minoredit,
32 - &$watchthis, &$sectionanchor, &$flags, $revision) {
 25+
 26+function UW_AutoCreateCategoryPages_Save ( &$article, &$user, &$text, &$summary, &$minoredit,
 27+ &$watchthis, &$sectionanchor, &$flags, $revision ) {
3328 global $wgDBprefix;
3429
3530 /* after the page is saved, get all the categories
@@ -37,38 +32,38 @@
3833
3934 // extract the categories on this page
4035 $regex = "/\[\[category:(.+?)(?:\|.*)?\]\]/i";
41 - preg_match_all ($regex, $text, $matches);
 36+ preg_match_all ( $regex, $text, $matches );
4237
4338 // array of the categories on the page (in db form)
4439 $on_page = array();
45 - foreach ($matches[1] as $cat)
46 - $on_page[] = Title::newFromText ($cat)->getDBkey();
 40+ foreach ( $matches[1] as $cat )
 41+ $on_page[] = Title::newFromText ( $cat )->getDBkey();
4742
4843 // array of the categories in the db
49 - $db = wfGetDB (DB_MASTER);
50 - $results = $db->resultObject ($db->query(
 44+ $db = wfGetDB ( DB_MASTER );
 45+ $results = $db->resultObject ( $db->query(
5146 "select distinct page_title from {$wgDBprefix}page " .
52 - "where page_namespace = '".NS_CATEGORY."'"));
 47+ "where page_namespace = '" . NS_CATEGORY . "'" ) );
5348
5449 $in_db = array();
55 - while ($r = $results->next())
 50+ while ( $r = $results->next() )
5651 $in_db[] = $r->page_title;
5752
5853 /* loop through the categories in the page and
5954 * see if they already exist as a category page */
60 - foreach ($on_page as $db_key) {
61 - if (!in_array( $db_key, $in_db)) {
 55+ foreach ( $on_page as $db_key ) {
 56+ if ( !in_array( $db_key, $in_db ) ) {
6257
6358 // if it doesn't exist, then create it here
64 - $page_title = Title::newFromDBkey ($db_key)->getText();
65 - $stub = wfMsg ("accp_stub", $page_title);
66 - $summary = wfMsg ("accp_createdby");
67 - $article = new Article (Title::newFromDBkey("Category:$db_key"));
 59+ $page_title = Title::newFromDBkey ( $db_key )->getText();
 60+ $stub = wfMsgForContent ( 'autocreatecategorypages-stub', $page_title );
 61+ $summary = wfMsgForContent ( 'autocreatecategorypages-createdby' );
 62+ $article = new Article ( Title::newFromDBkey( "Category:$db_key" ) );
6863
6964 try {
70 - $article->doEdit ($stub, $summary, EDIT_NEW & EDIT_SUPPRESS_RC);
 65+ $article->doEdit ( $stub, $summary, EDIT_NEW & EDIT_SUPPRESS_RC );
7166
72 - } catch (MWException $e) {
 67+ } catch ( MWException $e ) {
7368 /* fail silently...
7469 * todo: what can go wrong here? */
7570 }
Property changes on: trunk/extensions/uniwiki/AutoCreateCategoryPages/AutoCreateCategoryPages.php
___________________________________________________________________
Added: svn:keywords
7671 + LastChangedDate LastChangedRevision
Index: trunk/extensions/uniwiki/AutoCreateCategoryPages/AutoCreateCategoryPages.i18n.php
@@ -1,28 +1,35 @@
22 <?php
3 -/* vim: noet ts=4 sw=4
4 - * http://www.mediawiki.org/wiki/Extension:Uniwiki_Auto_Create_Category_Pages
5 - * http://www.gnu.org/licenses/gpl-3.0.txt */
 3+/**
 4+ * Internationalisation for Uniwiki/AutoCreateCategoryPages extension
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
69
7 -if (!defined("MEDIAWIKI"))
8 - die();
 10+$messages = array();
911
10 -$wgAutoCreateCategoryPagesMessages = array();
11 -$wgAutoCreateCategoryPagesMessages['en'] = array(
12 - 'accp_stub' => "This is a category page. It lists all of the pages in category \"$1\" as well as all subcategories of category \"$1\" if any exist.",
13 - 'accp_createdby' => "Created automatically by the AutoCreateCategoryPage extension."
 12+/** English */
 13+$messages['en'] = array(
 14+ 'autocreatecategorypages-desc' => 'Create missing category pages automatically on save',
 15+ 'autocreatecategorypages-stub' => 'This is a category page.
 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.'
1418 );
1519
16 -$wgAutoCreateCategoryPagesMessages['es'] = array(
17 - 'accp_stub' => "Esta es una página de categorías. Aquí se enumeran todas las páginas en la categoría \"$1\" así como todas las subcategorías en la categoría \"$1\" si las hubiere.",
18 - 'accp_createdby' => "Creado automáticamente por la extensión AutoCreateCategoryPe."
 20+$messages['es'] = array(
 21+ 'autocreatecategorypages-stub' => 'Esta es una página de categorías.
 22+Aqx se enumeran todas las páginas en la categoría "$1" asx como todas las subcategorías en la categoría "$1" si las hubiere.',
 23+ 'autocreatecategorypages-createdby' => 'Creado automáticamente por la extensión AutoCreateCategoryPages.'
1924 );
2025
21 -$wgAutoCreateCategoryPagesMessages['de'] = array(
22 - 'accp_stub' => "Dies ist eine Kategorie Übersicht. Es listet alle Seiten in der Kategorie \"$1\" sowie alle Unterkategorien der Kategorie \"$1\" wenn sie existiert.",
23 - 'accp_createdby' => "Erstellt automatisch von der AutoCreateCategoryPage Erweiterung"
 26+$messages['de'] = array(
 27+ 'autocreatecategorypages-stub' => 'Dies ist eine Kategorie Übersicht.
 28+Es listet alle Seiten in der Kategorie "$1" sowie alle Unterkategorien der Kategorie "$1" wenn sie existiert.',
 29+ 'autocreatecategorypages-createdby' => 'Erstellt automatisch von der AutoCreateCategoryPages Erweiterung'
2430 );
2531
26 -$wgAutoCreateCategoryPagesMessages['pt-br'] = array(
27 - 'accp_stub' => "Esta é uma página de categoria. Ela lista todas as páginas da categoria \"$1\", bem como todas as subcategorias da categoria \"$1\", se existirem.",
28 - 'accp_createdby' => "Gerada automaticamente pela extensão AutoCreateCategoryPag."
 32+$messages['pt-br'] = array(
 33+ 'autocreatecategorypages-stub' => 'Esta é uma página de categoria.
 34+Ela lista todas as páginas da categoria "$1", bem como todas as subcategorias da categoria "$1", se existirem.',
 35+ 'autocreatecategorypages-createdby' => 'Gerada automaticamente pela extensxo AutoCreateCategoryPages.'
2936 );

Status & tagging log