MediaWiki r14373 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r14372‎ | r14373 (on ViewVC)‎ | r14374 >
Date:07:37, 25 May 2006
Author:brion
Status:old
Tags:
Comment:
To simplify the lives of extension developers, the logging type arrays can now be appended to directly by an extension setup function. It is no longer necessary to write four separate functions just to add a custom log type.
The old hooks for this are retained for backwards compatibility, but are deprecated.
Modified paths:

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES
@@ -328,6 +328,10 @@
329329 * (bug 6061) Improper escaping in some html forms
330330 * (bug 6065) Remove underscore when using NAMESPACE and TALKSPACE magics.
331331 * (bug 6074) Correct squid purging of offsite upload URLs
 332+* To simplify the lives of extension developers, the logging type arrays
 333+ can now be appended to directly by an extension setup function. It is
 334+ no longer necessary to write four separate functions just to add a
 335+ custom log type.
332336
333337
334338 == Compatibility ==
Index: trunk/phase3/includes/DefaultSettings.php
@@ -1712,6 +1712,70 @@
17131713 $wgHooks = array();
17141714
17151715 /**
 1716+ * The logging system has two levels: an event type, which describes the
 1717+ * general category and can be viewed as a named subset of all logs; and
 1718+ * an action, which is a specific kind of event that can exist in that
 1719+ * log type.
 1720+ */
 1721+$wgLogTypes = array( '', 'block', 'protect', 'rights', 'delete', 'upload', 'move' );
 1722+
 1723+/**
 1724+ * Lists the message key string for each log type. The localized messages
 1725+ * will be listed in the user interface.
 1726+ *
 1727+ * Extensions with custom log types may add to this array.
 1728+ */
 1729+$wgLogNames = array(
 1730+ '' => 'log',
 1731+ 'block' => 'blocklogpage',
 1732+ 'protect' => 'protectlogpage',
 1733+ 'rights' => 'rightslog',
 1734+ 'delete' => 'dellogpage',
 1735+ 'upload' => 'uploadlogpage',
 1736+ 'move' => 'movelogpage' );
 1737+
 1738+/**
 1739+ * Lists the message key string for descriptive text to be shown at the
 1740+ * top of each log type.
 1741+ *
 1742+ * Extensions with custom log types may add to this array.
 1743+ */
 1744+$wgLogHeaders = array(
 1745+ '' => 'alllogstext',
 1746+ 'block' => 'blocklogtext',
 1747+ 'protect' => 'protectlogtext',
 1748+ 'rights' => 'rightslogtext',
 1749+ 'delete' => 'dellogpagetext',
 1750+ 'upload' => 'uploadlogpagetext',
 1751+ 'move' => 'movelogpagetext' );
 1752+
 1753+/**
 1754+ * Lists the message key string for formatting individual events of each
 1755+ * type and action when listed in the logs.
 1756+ *
 1757+ * Extensions with custom log types may add to this array.
 1758+ */
 1759+$wgLogActions = array(
 1760+ 'block/block' => 'blocklogentry',
 1761+ 'block/unblock' => 'unblocklogentry',
 1762+ 'protect/protect' => 'protectedarticle',
 1763+ 'protect/unprotect' => 'unprotectedarticle',
 1764+
 1765+ // TODO: This whole section should be moved to extensions/Makesysop/SpecialMakesysop.php
 1766+ 'rights/rights' => 'rightslogentry',
 1767+ 'rights/addgroup' => 'addgrouplogentry',
 1768+ 'rights/rngroup' => 'renamegrouplogentry',
 1769+ 'rights/chgroup' => 'changegrouplogentry',
 1770+
 1771+ 'delete/delete' => 'deletedarticle',
 1772+ 'delete/restore' => 'undeletedarticle',
 1773+ 'delete/revision' => 'revdelete-logentry',
 1774+ 'upload/upload' => 'uploadedimage',
 1775+ 'upload/revert' => 'uploadedimage',
 1776+ 'move/move' => '1movedto2',
 1777+ 'move/move_redir' => '1movedto2_redir' );
 1778+
 1779+/**
17161780 * Experimental preview feature to fetch rendered text
17171781 * over an XMLHttpRequest from JavaScript instead of
17181782 * forcing a submit and reload of the whole page.
Index: trunk/phase3/includes/LogPage.php
@@ -94,9 +94,8 @@
9595 * @static
9696 */
9797 function validTypes() {
98 - static $types = array( '', 'block', 'protect', 'rights', 'delete', 'upload', 'move' );
99 - wfRunHooks( 'LogPageValidTypes', array( &$types ) );
100 - return $types;
 98+ global $wgLogTypes;
 99+ return $wgLogTypes;
101100 }
102101
103102 /**
@@ -110,19 +109,10 @@
111110 * @static
112111 */
113112 function logName( $type ) {
114 - static $typeText = array(
115 - '' => 'log',
116 - 'block' => 'blocklogpage',
117 - 'protect' => 'protectlogpage',
118 - 'rights' => 'rightslog',
119 - 'delete' => 'dellogpage',
120 - 'upload' => 'uploadlogpage',
121 - 'move' => 'movelogpage'
122 - );
123 - wfRunHooks( 'LogPageLogName', array( &$typeText ) );
 113+ global $wgLogNames;
124114
125 - if( isset( $typeText[$type] ) ) {
126 - return str_replace( '_', ' ', wfMsg( $typeText[$type] ) );
 115+ if( isset( $wgLogNames[$type] ) ) {
 116+ return str_replace( '_', ' ', wfMsg( $wgLogNames[$type] ) );
127117 } else {
128118 // Bogus log types? Perhaps an extension was removed.
129119 return $type;
@@ -130,54 +120,24 @@
131121 }
132122
133123 /**
 124+ * @fixme: handle missing log types
134125 * @static
135126 */
136127 function logHeader( $type ) {
137 - static $headerText = array(
138 - '' => 'alllogstext',
139 - 'block' => 'blocklogtext',
140 - 'protect' => 'protectlogtext',
141 - 'rights' => 'rightslogtext',
142 - 'delete' => 'dellogpagetext',
143 - 'upload' => 'uploadlogpagetext',
144 - 'move' => 'movelogpagetext'
145 - );
146 - wfRunHooks( 'LogPageLogHeader', array( &$headerText ) );
147 -
148 - return wfMsg( $headerText[$type] );
 128+ global $wgLogHeaders;
 129+ return wfMsg( $wgLogHeaders[$type] );
149130 }
150131
151132 /**
152133 * @static
153134 */
154135 function actionText( $type, $action, $title = NULL, $skin = NULL, $params = array(), $filterWikilinks=false, $translate=false ) {
155 - global $wgLang, $wgContLang;
156 - static $actions = array(
157 - 'block/block' => 'blocklogentry',
158 - 'block/unblock' => 'unblocklogentry',
159 - 'protect/protect' => 'protectedarticle',
160 - 'protect/unprotect' => 'unprotectedarticle',
 136+ global $wgLang, $wgContLang, $wgLogActions;
161137
162 - // TODO: This whole section should be moved to extensions/Makesysop/SpecialMakesysop.php
163 - 'rights/rights' => 'rightslogentry',
164 - 'rights/addgroup' => 'addgrouplogentry',
165 - 'rights/rngroup' => 'renamegrouplogentry',
166 - 'rights/chgroup' => 'changegrouplogentry',
167 -
168 - 'delete/delete' => 'deletedarticle',
169 - 'delete/restore' => 'undeletedarticle',
170 - 'delete/revision' => 'revdelete-logentry',
171 - 'upload/upload' => 'uploadedimage',
172 - 'upload/revert' => 'uploadedimage',
173 - 'move/move' => '1movedto2',
174 - 'move/move_redir' => '1movedto2_redir'
175 - );
176 - wfRunHooks( 'LogPageActionText', array( &$actions ) );
177 -
178138 $key = "$type/$action";
179 - if( isset( $actions[$key] ) ) {
 139+ if( isset( $wgLogActions[$key] ) ) {
180140 if( is_null( $title ) ) {
181 - $rv=wfMsg( $actions[$key] );
 141+ $rv=wfMsg( $wgLogActions[$key] );
182142 } else {
183143 if( $skin ) {
184144
@@ -209,16 +169,16 @@
210170 }
211171 if( count( $params ) == 0 ) {
212172 if ( $skin ) {
213 - $rv = wfMsg( $actions[$key], $titleLink );
 173+ $rv = wfMsg( $wgLogActions[$key], $titleLink );
214174 } else {
215 - $rv = wfMsgForContent( $actions[$key], $titleLink );
 175+ $rv = wfMsgForContent( $wgLogActions[$key], $titleLink );
216176 }
217177 } else {
218178 array_unshift( $params, $titleLink );
219179 if ( $translate && $key == 'block/block' ) {
220180 $params[1] = $wgLang->translateBlockExpiry($params[1]);
221181 }
222 - $rv = wfMsgReal( $actions[$key], $params, true, !$skin );
 182+ $rv = wfMsgReal( $wgLogActions[$key], $params, true, !$skin );
223183 }
224184 }
225185 } else {
Index: trunk/phase3/includes/Setup.php
@@ -320,6 +320,13 @@
321321 call_user_func( $func );
322322 }
323323
 324+// For compatibility
 325+wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) );
 326+wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) );
 327+wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) );
 328+wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) );
 329+
 330+
324331 wfDebug( "\n" );
325332 $wgFullyInitialised = true;
326333 wfProfileOut( $fname.'-extensions' );
Index: trunk/phase3/docs/hooks.txt
@@ -346,15 +346,18 @@
347347 $url: string value as output (out parameter, can modify)
348348 $query: query options passed to Title::getFullURL()
349349
350 -'LogPageValidTypes': action being logged.
351 -$type: array of strings
 350+'LogPageValidTypes': action being logged. DEPRECATED: Use $wgLogTypes
 351+&$type: array of strings
352352
353 -'LogPageLogName': name of the logging page(s).
354 -$typeText: array of strings
 353+'LogPageLogName': name of the logging page(s). DEPRECATED: Use $wgLogNames
 354+&$typeText: array of strings
355355
356 -'LogPageLogHeader': strings used by wfMsg as a header.
357 -$headerText: array of strings
 356+'LogPageLogHeader': strings used by wfMsg as a header. DEPRECATED: Use $wgLogHeaders
 357+&$headerText: array of strings
358358
 359+'LogPageActionText': strings used by wfMsg as a header. DEPRECATED: Use $wgLogActions
 360+&$actionText: array of strings
 361+
359362 'MarkPatrolled': before an edit is marked patrolled
360363 $rcid: ID of the revision to be marked patrolled
361364 $user: the user (object) marking the revision as patrolled

Status & tagging log

  • 01:58, 13 October 2010 ^demon (talk | contribs) changed the status of r14373 [removed: new added: old]