From 2fb7f4fdb2029c9280eb1b0ee94ff1f0fa4c0492 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 25 May 2006 07:37:20 +0000 Subject: [PATCH] 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. --- RELEASE-NOTES | 4 +++ docs/hooks.txt | 15 ++++---- includes/DefaultSettings.php | 64 +++++++++++++++++++++++++++++++++ includes/LogPage.php | 68 ++++++++---------------------------- includes/Setup.php | 7 ++++ 5 files changed, 98 insertions(+), 60 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 3c544749d3..ec88ea0c7d 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -328,6 +328,10 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 6061) Improper escaping in some html forms * (bug 6065) Remove underscore when using NAMESPACE and TALKSPACE magics. * (bug 6074) Correct squid purging of offsite upload URLs +* 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. == Compatibility == diff --git a/docs/hooks.txt b/docs/hooks.txt index 48b8e17f78..b2ee82a667 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -346,14 +346,17 @@ $title: Title object of page $url: string value as output (out parameter, can modify) $query: query options passed to Title::getFullURL() -'LogPageValidTypes': action being logged. -$type: array of strings +'LogPageValidTypes': action being logged. DEPRECATED: Use $wgLogTypes +&$type: array of strings -'LogPageLogName': name of the logging page(s). -$typeText: array of strings +'LogPageLogName': name of the logging page(s). DEPRECATED: Use $wgLogNames +&$typeText: array of strings -'LogPageLogHeader': strings used by wfMsg as a header. -$headerText: array of strings +'LogPageLogHeader': strings used by wfMsg as a header. DEPRECATED: Use $wgLogHeaders +&$headerText: array of strings + +'LogPageActionText': strings used by wfMsg as a header. DEPRECATED: Use $wgLogActions +&$actionText: array of strings 'MarkPatrolled': before an edit is marked patrolled $rcid: ID of the revision to be marked patrolled diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 16db781bfc..7037288364 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1711,6 +1711,70 @@ $wgAuth = null; */ $wgHooks = array(); +/** + * The logging system has two levels: an event type, which describes the + * general category and can be viewed as a named subset of all logs; and + * an action, which is a specific kind of event that can exist in that + * log type. + */ +$wgLogTypes = array( '', 'block', 'protect', 'rights', 'delete', 'upload', 'move' ); + +/** + * Lists the message key string for each log type. The localized messages + * will be listed in the user interface. + * + * Extensions with custom log types may add to this array. + */ +$wgLogNames = array( + '' => 'log', + 'block' => 'blocklogpage', + 'protect' => 'protectlogpage', + 'rights' => 'rightslog', + 'delete' => 'dellogpage', + 'upload' => 'uploadlogpage', + 'move' => 'movelogpage' ); + +/** + * Lists the message key string for descriptive text to be shown at the + * top of each log type. + * + * Extensions with custom log types may add to this array. + */ +$wgLogHeaders = array( + '' => 'alllogstext', + 'block' => 'blocklogtext', + 'protect' => 'protectlogtext', + 'rights' => 'rightslogtext', + 'delete' => 'dellogpagetext', + 'upload' => 'uploadlogpagetext', + 'move' => 'movelogpagetext' ); + +/** + * Lists the message key string for formatting individual events of each + * type and action when listed in the logs. + * + * Extensions with custom log types may add to this array. + */ +$wgLogActions = array( + 'block/block' => 'blocklogentry', + 'block/unblock' => 'unblocklogentry', + 'protect/protect' => 'protectedarticle', + 'protect/unprotect' => 'unprotectedarticle', + + // TODO: This whole section should be moved to extensions/Makesysop/SpecialMakesysop.php + 'rights/rights' => 'rightslogentry', + 'rights/addgroup' => 'addgrouplogentry', + 'rights/rngroup' => 'renamegrouplogentry', + 'rights/chgroup' => 'changegrouplogentry', + + 'delete/delete' => 'deletedarticle', + 'delete/restore' => 'undeletedarticle', + 'delete/revision' => 'revdelete-logentry', + 'upload/upload' => 'uploadedimage', + 'upload/revert' => 'uploadedimage', + 'move/move' => '1movedto2', + 'move/move_redir' => '1movedto2_redir' ); + /** * Experimental preview feature to fetch rendered text * over an XMLHttpRequest from JavaScript instead of diff --git a/includes/LogPage.php b/includes/LogPage.php index 5741e0cee7..c3b236762a 100644 --- a/includes/LogPage.php +++ b/includes/LogPage.php @@ -94,9 +94,8 @@ class LogPage { * @static */ function validTypes() { - static $types = array( '', 'block', 'protect', 'rights', 'delete', 'upload', 'move' ); - wfRunHooks( 'LogPageValidTypes', array( &$types ) ); - return $types; + global $wgLogTypes; + return $wgLogTypes; } /** @@ -110,19 +109,10 @@ class LogPage { * @static */ function logName( $type ) { - static $typeText = array( - '' => 'log', - 'block' => 'blocklogpage', - 'protect' => 'protectlogpage', - 'rights' => 'rightslog', - 'delete' => 'dellogpage', - 'upload' => 'uploadlogpage', - 'move' => 'movelogpage' - ); - wfRunHooks( 'LogPageLogName', array( &$typeText ) ); + global $wgLogNames; - if( isset( $typeText[$type] ) ) { - return str_replace( '_', ' ', wfMsg( $typeText[$type] ) ); + if( isset( $wgLogNames[$type] ) ) { + return str_replace( '_', ' ', wfMsg( $wgLogNames[$type] ) ); } else { // Bogus log types? Perhaps an extension was removed. return $type; @@ -130,54 +120,24 @@ class LogPage { } /** + * @fixme: handle missing log types * @static */ function logHeader( $type ) { - static $headerText = array( - '' => 'alllogstext', - 'block' => 'blocklogtext', - 'protect' => 'protectlogtext', - 'rights' => 'rightslogtext', - 'delete' => 'dellogpagetext', - 'upload' => 'uploadlogpagetext', - 'move' => 'movelogpagetext' - ); - wfRunHooks( 'LogPageLogHeader', array( &$headerText ) ); - - return wfMsg( $headerText[$type] ); + global $wgLogHeaders; + return wfMsg( $wgLogHeaders[$type] ); } /** * @static */ function actionText( $type, $action, $title = NULL, $skin = NULL, $params = array(), $filterWikilinks=false, $translate=false ) { - global $wgLang, $wgContLang; - static $actions = array( - 'block/block' => 'blocklogentry', - 'block/unblock' => 'unblocklogentry', - 'protect/protect' => 'protectedarticle', - 'protect/unprotect' => 'unprotectedarticle', - - // TODO: This whole section should be moved to extensions/Makesysop/SpecialMakesysop.php - 'rights/rights' => 'rightslogentry', - 'rights/addgroup' => 'addgrouplogentry', - 'rights/rngroup' => 'renamegrouplogentry', - 'rights/chgroup' => 'changegrouplogentry', - - 'delete/delete' => 'deletedarticle', - 'delete/restore' => 'undeletedarticle', - 'delete/revision' => 'revdelete-logentry', - 'upload/upload' => 'uploadedimage', - 'upload/revert' => 'uploadedimage', - 'move/move' => '1movedto2', - 'move/move_redir' => '1movedto2_redir' - ); - wfRunHooks( 'LogPageActionText', array( &$actions ) ); + global $wgLang, $wgContLang, $wgLogActions; $key = "$type/$action"; - if( isset( $actions[$key] ) ) { + if( isset( $wgLogActions[$key] ) ) { if( is_null( $title ) ) { - $rv=wfMsg( $actions[$key] ); + $rv=wfMsg( $wgLogActions[$key] ); } else { if( $skin ) { @@ -209,16 +169,16 @@ class LogPage { } if( count( $params ) == 0 ) { if ( $skin ) { - $rv = wfMsg( $actions[$key], $titleLink ); + $rv = wfMsg( $wgLogActions[$key], $titleLink ); } else { - $rv = wfMsgForContent( $actions[$key], $titleLink ); + $rv = wfMsgForContent( $wgLogActions[$key], $titleLink ); } } else { array_unshift( $params, $titleLink ); if ( $translate && $key == 'block/block' ) { $params[1] = $wgLang->translateBlockExpiry($params[1]); } - $rv = wfMsgReal( $actions[$key], $params, true, !$skin ); + $rv = wfMsgReal( $wgLogActions[$key], $params, true, !$skin ); } } } else { diff --git a/includes/Setup.php b/includes/Setup.php index 59aff89154..4c4328dd40 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -320,6 +320,13 @@ foreach ( $wgExtensionFunctions as $func ) { call_user_func( $func ); } +// For compatibility +wfRunHooks( 'LogPageValidTypes', array( &$wgLogTypes ) ); +wfRunHooks( 'LogPageLogName', array( &$wgLogNames ) ); +wfRunHooks( 'LogPageLogHeader', array( &$wgLogHeaders ) ); +wfRunHooks( 'LogPageActionText', array( &$wgLogActions ) ); + + wfDebug( "\n" ); $wgFullyInitialised = true; wfProfileOut( $fname.'-extensions' ); -- 2.20.1