TTO has uploaded a new change for review.
https://gerrit.wikimedia.org/r/194698
Change subject: Demo of Core change tags
......................................................................
Demo of Core change tags
Change-Id: I032d38beaa8d4e5d09451ba963292f89c04dced8
---
M autoload.php
M includes/ChangeTags.php
A includes/CoreChangeTags.php
M includes/DefaultSettings.php
M includes/api/ApiQueryTags.php
M includes/page/WikiPage.php
6 files changed, 127 insertions(+), 12 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/98/194698/2
diff --git a/autoload.php b/autoload.php
index c206414..5d707c6 100644
--- a/autoload.php
+++ b/autoload.php
@@ -257,6 +257,7 @@
'CopyFileBackend' => __DIR__ . '/maintenance/copyFileBackend.php',
'CopyFileOp' => __DIR__ . '/includes/filebackend/FileOp.php',
'CopyJobQueue' => __DIR__ . '/maintenance/copyJobQueue.php',
+ 'CoreChangeTags' => __DIR__ . '/includes/CoreChangeTags.php',
'CoreParserFunctions' => __DIR__ .
'/includes/parser/CoreParserFunctions.php',
'CoreTagHooks' => __DIR__ . '/includes/parser/CoreTagHooks.php',
'CreateAndPromote' => __DIR__ . '/maintenance/createAndPromote.php',
diff --git a/includes/ChangeTags.php b/includes/ChangeTags.php
index 89a2540..3f2107b 100644
--- a/includes/ChangeTags.php
+++ b/includes/ChangeTags.php
@@ -974,8 +974,8 @@
return Status::newFatal( 'tags-delete-too-many-uses',
$tag, self::MAX_DELETE_USES );
}
- $extensionDefined = self::listExtensionDefinedTags();
- if ( in_array( $tag, $extensionDefined ) ) {
+ $automaticTags = self::listAutomaticTags();
+ if ( in_array( $tag, $automaticTags ) ) {
// extension-defined tags can't be deleted unless the
extension
// specifically allows it
$status = Status::newFatal( 'tags-delete-not-allowed' );
@@ -1055,13 +1055,13 @@
/**
* Basically lists defined tags which count even if they aren't applied
to anything.
* It returns a union of the results of listExplicitlyDefinedTags() and
- * listExtensionDefinedTags().
+ * listAutomaticTags().
*
* @return string[] Array of strings: tags
*/
public static function listDefinedTags() {
$tags1 = self::listExplicitlyDefinedTags();
- $tags2 = self::listExtensionDefinedTags();
+ $tags2 = self::listAutomaticTags();
return array_values( array_unique( array_merge( $tags1, $tags2
) ) );
}
@@ -1101,15 +1101,17 @@
}
/**
- * Lists tags defined by extensions using the ListDefinedTags hook.
- * Extensions need only define those tags they deem to be in active use.
+ * Lists tags defined by MediaWiki core and by extensions using the
+ * ListDefinedTags hook.
+ * Extensions should define all tags that could be used again in the
+ * future, even if the tag is not currently active.
*
* Tries memcached first.
*
* @return string[] Array of strings: tags
* @since 1.25
*/
- public static function listExtensionDefinedTags() {
+ public static function listAutomaticTags() {
// Caching...
global $wgMemc;
$key = wfMemcKey( 'valid-tags-hook' );
@@ -1118,7 +1120,7 @@
return $tags;
}
- $emptyTags = array();
+ $emptyTags = CoreChangeTags::listTags();
Hooks::run( 'ListDefinedTags', array( &$emptyTags ) );
$emptyTags = array_filter( array_unique( $emptyTags ) );
diff --git a/includes/CoreChangeTags.php b/includes/CoreChangeTags.php
new file mode 100644
index 0000000..0a2e120
--- /dev/null
+++ b/includes/CoreChangeTags.php
@@ -0,0 +1,90 @@
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation,
Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * Implementation of some basic change tags.
+ *
+ * This class applies very simple and frequently requested change tags,
+ * including those that would be difficult to implement using the AbuseFilter
+ * extension. More complex, wiki-specific change tags should be left for users
+ * to implement using AbuseFilter.
+ *
+ * This is very much an internal class; functions in here should not be called
+ * by extensions.
+ *
+ * @since 1.25
+ */
+class CoreChangeTags {
+ /**
+ * Lists the change tags that may be automatically applied by MediaWiki
core.
+ * If core change tagging is disabled, an empty array is returned.
+ *
+ * @return array
+ */
+ public static function listTags() {
+ global $wgUseCoreChangeTags;
+ if ( !$wgUseCoreChangeTags ) {
+ return array();
+ }
+
+ return array(
+ 'mw-redirected',
+ 'mw-redirect-removed',
+ );
+ }
+
+ /**
+ * Applies core change tags to the given revision/Recent Changes entry,
if
+ * this feature is enabled.
+ *
+ * @param Revision $revision The revision to apply tags to
+ * @param RecentChange|null $rc The recent change entry to apply tags
to,
+ * or null if not applicable
+ * @param Content|null $oldContent The content of the revision before
changes
+ * were made, or null if the page is newly created (has no previous
revision)
+ * @param Content $content The content of the revision as it is now
+ */
+ public static function addToRevision( Revision $revision, $rc,
$oldContent,
+ Content $content ) {
+
+ global $wgUseCoreChangeTags;
+ if ( !$wgUseCoreChangeTags ) {
+ return;
+ }
+
+ $tags = array();
+
+ // Redirection tags, only for pre-existing pages
+ if ( $oldContent !== null ) {
+ $oldIsRedirect = $oldContent->isRedirect();
+ $newIsRedirect = $content->isRedirect();
+ if ( $oldIsRedirect && !$newIsRedirect ) {
+ $tags[] = 'mw-redirect-removed';
+ } elseif ( !$oldIsRedirect && $newIsRedirect ) {
+ $tags[] = 'mw-redirected';
+ }
+ }
+
+ if ( $tags ) {
+ $rc_id = $rc ? $rc->mAttribs['rc_id'] : null;
+ ChangeTags::addTags( $tags, $rc_id, $revision->getId()
);
+ }
+ }
+}
diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index cdc5d19..38efb5a 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -6046,6 +6046,11 @@
),
);
+/**
+ * bla
+ */
+$wgUseCoreChangeTags = false;
+
/** @} */ # end RC/watchlist }
/************************************************************************//**
diff --git a/includes/api/ApiQueryTags.php b/includes/api/ApiQueryTags.php
index 0e3307b..d64fec7 100644
--- a/includes/api/ApiQueryTags.php
+++ b/includes/api/ApiQueryTags.php
@@ -50,11 +50,17 @@
$limit = $params['limit'];
$result = $this->getResult();
- $extensionDefinedTags = array_fill_keys(
ChangeTags::listExtensionDefinedTags(), 0 );
+ global $wgUseCoreChangeTags;
+ if ( $wgUseCoreChangeTags ) {
+ $coreTags = array_fill_keys(
CoreChangeTags::listTags(), 0 );
+ } else {
+ $coreTags = array();
+ }
+ $automaticTags = array_fill_keys(
ChangeTags::listAutomaticTags(), 0 );
$explicitlyDefinedTags = array_fill_keys(
ChangeTags::listExplicitlyDefinedTags(), 0 );
$extensionActivatedTags = array_fill_keys(
ChangeTags::listExtensionActivatedTags(), 0 );
- $definedTags = array_merge( $extensionDefinedTags,
$explicitlyDefinedTags );
+ $definedTags = array_merge( $automaticTags,
$explicitlyDefinedTags );
# Fetch defined tags that aren't past the continuation
if ( $params['continue'] !== null ) {
@@ -105,7 +111,8 @@
$tag['hitcount'] = $hitcount;
}
- $isExtension = isset( $extensionDefinedTags[$tagName] );
+ $isCore = isset( $coreTags[$tagName] );
+ $isExtension = isset( $automaticTags[$tagName] ) &&
!$isCore;
$isExplicit = isset( $explicitlyDefinedTags[$tagName] );
if ( $fld_defined && ( $isExtension || $isExplicit ) ) {
@@ -115,6 +122,9 @@
if ( $fld_source ) {
$tag['source'] = array();
if ( $isExtension ) {
+ $tag['source'][] = 'builtin';
+ }
+ if ( $isExtension ) {
$tag['source'][] = 'extension';
}
if ( $isExplicit ) {
diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php
index fe61f6f..079dd19 100644
--- a/includes/page/WikiPage.php
+++ b/includes/page/WikiPage.php
@@ -1765,6 +1765,7 @@
$dbw = wfGetDB( DB_MASTER );
$now = wfTimestampNow();
$this->mTimestamp = $now;
+ $rc = null;
if ( $flags & EDIT_UPDATE ) {
// Update article, but only if changed.
@@ -1867,7 +1868,10 @@
)
);
- if ( !$changed ) {
+ if ( $changed ) {
+ // Add change tags
+ CoreChangeTags::addToRevision( $revision, $rc,
$old_content, $content );
+ } else {
$status->warning( 'edit-no-change' );
$revision = null;
// Update page_touched, this is usually
implicit in the page update
@@ -1956,6 +1960,9 @@
// Update links, etc.
$this->doEditUpdates( $revision, $user, array(
'created' => true ) );
+ // Add change tags
+ CoreChangeTags::addToRevision( $revision, $rc, null,
$content );
+
$hook_args = array( &$this, &$user, $content, $summary,
$flags &
EDIT_MINOR, null, null, &$flags, $revision );
--
To view, visit https://gerrit.wikimedia.org/r/194698
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I032d38beaa8d4e5d09451ba963292f89c04dced8
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: TTO <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: TTO <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits