From 9c387f5036456a777775c2279b18ffabc6e400d9 Mon Sep 17 00:00:00 2001 From: kaldari Date: Fri, 22 Dec 2017 12:40:13 -0800 Subject: [PATCH] Record a log entry on page creation 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 | 2 ++ includes/DefaultSettings.php | 8 +++++++- includes/Setup.php | 8 +++++++- includes/page/WikiPage.php | 17 ++++++++++++++++- languages/i18n/en.json | 3 +++ languages/i18n/qqq.json | 3 +++ .../includes/page/WikiPageDbTestBase.php | 16 +++++++++++++--- 7 files changed, 51 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES-1.32 b/RELEASE-NOTES-1.32 index 62e3df88bf..7db0dd733e 100644 --- a/RELEASE-NOTES-1.32 +++ b/RELEASE-NOTES-1.32 @@ -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. diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 87ca0168bd..82a3b29903 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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 } /*************************************************************************//** diff --git a/includes/Setup.php b/includes/Setup.php index 5cc9a96aa3..ccaa9baa4d 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -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; diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index cbce884dfc..24dc680239 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -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; diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 00756df5da..58e47d1130 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -2334,6 +2334,9 @@ "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:", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 12de8bf427..e3f780a6d1 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -2532,6 +2532,9 @@ "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 $1 in {{msg-mw|Filewasdeleted}}\n* Used as $2 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}}", diff --git a/tests/phpunit/includes/page/WikiPageDbTestBase.php b/tests/phpunit/includes/page/WikiPageDbTestBase.php index 40c4e1ecd3..68539b5ec7 100644 --- a/tests/phpunit/includes/page/WikiPageDbTestBase.php +++ b/tests/phpunit/includes/page/WikiPageDbTestBase.php @@ -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 ] ); -- 2.20.1