Record a log entry on page creation
authorkaldari <kaldari@gmail.com>
Fri, 22 Dec 2017 20:40:13 +0000 (12:40 -0800)
committerKaldari <kaldari@gmail.com>
Tue, 29 May 2018 16:10:40 +0000 (09:10 -0700)
This is controlled by a new config variable, $wgPageCreationLog,
which is set to false by default.

Bug: T12331
Change-Id: Ie3f6cc5ece0134433d5e4a572ea5eb0c3b700b8c

RELEASE-NOTES-1.32
includes/DefaultSettings.php
includes/Setup.php
includes/page/WikiPage.php
languages/i18n/en.json
languages/i18n/qqq.json
tests/phpunit/includes/page/WikiPageDbTestBase.php

index 62e3df8..7db0dd7 100644 (file)
@@ -25,6 +25,8 @@ production.
 === New features in 1.32 ===
 * (T112474) Generalized the ResourceLoader mechanism for overriding modules
   using a particular page during edit previews.
+* (T12331) You can now log page creation events by setting $wgPageCreationLog
+  to true.
 * Added 'ApiParseMakeOutputPage' hook.
 * (T174313) Added checkbox on Special:ListUsers to display only users in temporary
   user groups.
index 87ca016..82a3b29 100644 (file)
@@ -7888,10 +7888,16 @@ $wgActionFilteredLogs = [
 ];
 
 /**
- * Maintain a log of newusers at Log/newusers?
+ * Maintain a log of newusers at Special:Log/newusers?
  */
 $wgNewUserLog = true;
 
+/**
+ * Maintain a log of page creations at Special:Log/create?
+ * @since 1.32
+ */
+$wgPageCreationLog = false;
+
 /** @} */ # end logging }
 
 /*************************************************************************//**
index 5cc9a96..ccaa9ba 100644 (file)
@@ -531,7 +531,7 @@ if ( $wgInvalidateCacheOnLocalSettingsChange ) {
 }
 
 if ( $wgNewUserLog ) {
-       // Add a new log type
+       // Add new user log type
        $wgLogTypes[] = 'newusers';
        $wgLogNames['newusers'] = 'newuserlogpage';
        $wgLogHeaders['newusers'] = 'newuserlogpagetext';
@@ -542,6 +542,12 @@ if ( $wgNewUserLog ) {
        $wgLogActionsHandlers['newusers/autocreate'] = NewUsersLogFormatter::class;
 }
 
+if ( $wgPageCreationLog ) {
+       // Add page creation log type
+       $wgLogTypes[] = 'create';
+       $wgLogActionsHandlers['create/create'] = LogFormatter::class;
+}
+
 if ( $wgPageLanguageUseDB ) {
        $wgLogTypes[] = 'pagelang';
        $wgLogActionsHandlers['pagelang/pagelang'] = PageLangLogFormatter::class;
index cbce884..24dc680 100644 (file)
@@ -1874,7 +1874,7 @@ class WikiPage implements Page, IDBAccessObject {
        private function doCreate(
                Content $content, $flags, User $user, $summary, array $meta
        ) {
-               global $wgUseRCPatrol, $wgUseNPPatrol;
+               global $wgUseRCPatrol, $wgUseNPPatrol, $wgPageCreationLog;
 
                $status = Status::newGood( [ 'new' => true, 'revision' => null ] );
 
@@ -1950,6 +1950,21 @@ class WikiPage implements Page, IDBAccessObject {
 
                $user->incEditCount();
 
+               if ( $wgPageCreationLog ) {
+                       // Log the page creation
+                       // @TODO: Do we want a 'recreate' action?
+                       $logEntry = new ManualLogEntry( 'create', 'create' );
+                       $logEntry->setPerformer( $user );
+                       $logEntry->setTarget( $this->mTitle );
+                       $logEntry->setComment( $summary );
+                       $logEntry->setTimestamp( $now );
+                       $logEntry->setAssociatedRevId( $revisionId );
+                       $logid = $logEntry->insert();
+                       // Note that we don't publish page creation events to recentchanges
+                       // (i.e. $logEntry->publish()) since this would create duplicate entries,
+                       // one for the edit and one for the page creation.
+               }
+
                $dbw->endAtomic( __METHOD__ );
                $this->mTimestamp = $now;
 
index 00756df..58e47d1 100644 (file)
        "dellogpage": "Deletion log",
        "dellogpagetext": "Below is a list of the most recent deletions.",
        "deletionlog": "deletion log",
+       "log-name-create": "Page creation log",
+       "log-description-create": "Below is a list of the most recent page creations.",
+       "logentry-create-create": "$1 {{GENDER:$2|created}} page $3",
        "reverted": "Reverted to earlier revision",
        "deletecomment": "Reason:",
        "deleteotherreason": "Other/additional reason:",
index 12de8bf..e3f780a 100644 (file)
        "dellogpage": "{{doc-logpage}}\n\nThe name of the deletion log. Used as heading on [[Special:Log/delete]] and in the drop down menu for selecting logs on [[Special:Log]].\n{{Identical|Deletion log}}",
        "dellogpagetext": "Text in [[Special:Log/delete]].",
        "deletionlog": "Used as text for the link which points to the deletion log:\n* Used as <code>$1</code> in {{msg-mw|Filewasdeleted}}\n* Used as <code>$2</code> in {{msg-mw|Deletedtext}}\n* Used in log lines on [[Special:DeletedContributions]]\n{{Identical|Deletion log}}",
+       "log-name-create": "{{doc-logpage}}\n\nThe name of the page creation log. Used as heading on [[Special:Log/create]] and in the drop down menu for selecting logs on [[Special:Log]].",
+       "log-description-create": "Text in [[Special:Log/create]].",
+       "logentry-create-create": "{{Logentry|[[Special:Log/create]]}}",
        "reverted": "{{Identical|Revert}}",
        "deletecomment": "{{Identical|Reason}}",
        "deleteotherreason": "{{Identical|Other/additional reason}}",
index 40c4e1e..68539b5 100644 (file)
@@ -96,6 +96,8 @@ abstract class WikiPageDbTestBase extends MediaWikiLangTestCase {
         * @covers WikiPage::doEditUpdates
         */
        public function testDoEditContent() {
+               $this->setMwGlobals( 'wgPageCreationLog', true );
+
                $page = $this->newPage( __METHOD__ );
                $title = $page->getTitle();
 
@@ -108,13 +110,21 @@ abstract class WikiPageDbTestBase extends MediaWikiLangTestCase {
 
                $page->doEditContent( $content, "[[testing]] 1" );
 
+               $id = $page->getId();
+
+               // Test page creation logging
+               $this->assertSelect(
+                       'logging',
+                       [ 'log_type', 'log_action' ],
+                       [ 'log_page' => $id ],
+                       [ [ 'create', 'create' ] ]
+               );
+
                $this->assertTrue( $title->getArticleID() > 0, "Title object should have new page id" );
-               $this->assertTrue( $page->getId() > 0, "WikiPage should have new page id" );
+               $this->assertTrue( $id > 0, "WikiPage should have new page id" );
                $this->assertTrue( $title->exists(), "Title object should indicate that the page now exists" );
                $this->assertTrue( $page->exists(), "WikiPage object should indicate that the page now exists" );
 
-               $id = $page->getId();
-
                # ------------------------
                $dbr = wfGetDB( DB_REPLICA );
                $res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $id ] );