summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/src/Maintenance/MaintenanceLogger.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/src/Maintenance/MaintenanceLogger.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/src/Maintenance/MaintenanceLogger.php72
1 files changed, 72 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/src/Maintenance/MaintenanceLogger.php b/www/wiki/extensions/SemanticMediaWiki/src/Maintenance/MaintenanceLogger.php
new file mode 100644
index 00000000..7255fb45
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/src/Maintenance/MaintenanceLogger.php
@@ -0,0 +1,72 @@
+<?php
+
+namespace SMW\Maintenance;
+
+use RuntimeException;
+use SMW\MediaWiki\ManualEntryLogger;
+
+/**
+ * @license GNU GPL v2+
+ * @since 2.4
+ *
+ * @author mwjames
+ */
+class MaintenanceLogger {
+
+ /**
+ * @var string
+ */
+ private $performer = '';
+
+ /**
+ * @var ManualEntryLogger
+ */
+ private $manualEntryLogger;
+
+ /**
+ * @var integer
+ */
+ private $maxNameChars = 255;
+
+ /**
+ * @since 2.4
+ *
+ * @param string $performer
+ * @param ManualEntryLogger $manualEntryLogger
+ */
+ public function __construct( $performer, ManualEntryLogger $manualEntryLogger ) {
+ $this->performer = $performer;
+ $this->manualEntryLogger = $manualEntryLogger;
+ $this->manualEntryLogger->registerLoggableEventType( 'maintenance' );
+ }
+
+ /**
+ * @since 2.5
+ *
+ * @param integer $maxNameChars
+ */
+ public function setMaxNameChars( $maxNameChars ) {
+ $this->maxNameChars = $maxNameChars;
+ }
+
+ /**
+ * @since 2.4
+ *
+ * @param string $message
+ * @param string $target
+ */
+ public function log( $message, $target = '' ) {
+
+ if ( $target === '' ) {
+ $target = $this->performer;
+ }
+
+ // #1983
+ if ( $this->maxNameChars < strlen( $target ) ) {
+ throw new RuntimeException( 'wgMaxNameChars requires at least ' . strlen( $target ) );
+ }
+
+ $this->manualEntryLogger->log( 'maintenance', $this->performer, $target, $message );
+ }
+
+}