return false;
}
+ /**
+ * Return type of change if one exists for the given edit.
+ *
+ * @since 1.31
+ *
+ * @param Content|null $oldContent The previous text of the page.
+ * @param Content|null $newContent The submitted text of the page.
+ * @param int $flags Bit mask: a bit mask of flags submitted for the edit.
+ *
+ * @return string|null String key representing type of change, or null.
+ */
+ private function getChangeType(
+ Content $oldContent = null,
+ Content $newContent = null,
+ $flags = 0
+ ) {
+ $oldTarget = $oldContent !== null ? $oldContent->getRedirectTarget() : null;
+ $newTarget = $newContent !== null ? $newContent->getRedirectTarget() : null;
+
+ // We check for the type of change in the given edit, and return string key accordingly
+
+ // Blanking of a page
+ if ( $oldContent && $oldContent->getSize() > 0 &&
+ $newContent && $newContent->getSize() === 0
+ ) {
+ return 'blank';
+ }
+
+ // Redirects
+ if ( $newTarget ) {
+ if ( !$oldTarget ) {
+ // New redirect page (by creating new page or by changing content page)
+ return 'new-redirect';
+ } elseif ( !$newTarget->equals( $oldTarget ) ||
+ $oldTarget->getFragment() !== $newTarget->getFragment()
+ ) {
+ // Redirect target changed
+ return 'changed-redirect-target';
+ }
+ } elseif ( $oldTarget ) {
+ // Changing an existing redirect into a non-redirect
+ return 'removed-redirect';
+ }
+
+ // New page created
+ if ( $flags & EDIT_NEW && $newContent ) {
+ if ( $newContent->getSize() === 0 ) {
+ // New blank page
+ return 'newblank';
+ } else {
+ return 'newpage';
+ }
+ }
+
+ // Removing more than 90% of the page
+ if ( $oldContent && $newContent && $oldContent->getSize() > 10 * $newContent->getSize() ) {
+ return 'replace';
+ }
+
+ // Content model changed
+ if ( $oldContent && $newContent && $oldContent->getModel() !== $newContent->getModel() ) {
+ return 'contentmodelchange';
+ }
+
+ return null;
+ }
+
/**
* Return an applicable auto-summary if one exists for the given edit.
*
* @since 1.21
*
- * @param Content $oldContent The previous text of the page.
- * @param Content $newContent The submitted text of the page.
+ * @param Content|null $oldContent The previous text of the page.
+ * @param Content|null $newContent The submitted text of the page.
* @param int $flags Bit mask: a bit mask of flags submitted for the edit.
*
* @return string An appropriate auto-summary, or an empty string.
*/
- public function getAutosummary( Content $oldContent = null, Content $newContent = null,
- $flags ) {
- // Decide what kind of auto-summary is needed.
-
- // Redirect auto-summaries
-
- /**
- * @var $ot Title
- * @var $rt Title
- */
+ public function getAutosummary(
+ Content $oldContent = null,
+ Content $newContent = null,
+ $flags = 0
+ ) {
+ $changeType = $this->getChangeType( $oldContent, $newContent, $flags );
- $ot = !is_null( $oldContent ) ? $oldContent->getRedirectTarget() : null;
- $rt = !is_null( $newContent ) ? $newContent->getRedirectTarget() : null;
+ // There's no applicable auto-summary for our case, so our auto-summary is empty.
+ if ( !$changeType ) {
+ return '';
+ }
- if ( is_object( $rt ) ) {
- if ( !is_object( $ot )
- || !$rt->equals( $ot )
- || $ot->getFragment() != $rt->getFragment()
- ) {
+ // Decide what kind of auto-summary is needed.
+ switch ( $changeType ) {
+ case 'new-redirect':
+ $newTarget = $newContent->getRedirectTarget();
$truncatedtext = $newContent->getTextForSummary(
250
- strlen( wfMessage( 'autoredircomment' )->inContentLanguage()->text() )
- - strlen( $rt->getFullText() ) );
+ - strlen( $newTarget->getFullText() )
+ );
- return wfMessage( 'autoredircomment', $rt->getFullText() )
- ->rawParams( $truncatedtext )->inContentLanguage()->text();
- }
- }
+ return wfMessage( 'autoredircomment', $newTarget->getFullText() )
+ ->plaintextParams( $truncatedtext )->inContentLanguage()->text();
+ case 'changed-redirect-target':
+ $oldTarget = $oldContent->getRedirectTarget();
+ $newTarget = $newContent->getRedirectTarget();
- // New page auto-summaries
- if ( $flags & EDIT_NEW && $newContent->getSize() > 0 ) {
- // If they're making a new article, give its text, truncated, in
- // the summary.
+ $truncatedtext = $newContent->getTextForSummary(
+ 250
+ - strlen( wfMessage( 'autosumm-changed-redirect-target' )
+ ->inContentLanguage()->text() )
+ - strlen( $oldTarget->getFullText() )
+ - strlen( $newTarget->getFullText() )
+ );
+
+ return wfMessage( 'autosumm-changed-redirect-target',
+ $oldTarget->getFullText(),
+ $newTarget->getFullText() )
+ ->rawParams( $truncatedtext )->inContentLanguage()->text();
+ case 'removed-redirect':
+ $oldTarget = $oldContent->getRedirectTarget();
+ $truncatedtext = $newContent->getTextForSummary(
+ 250
+ - strlen( wfMessage( 'autosumm-removed-redirect' )
+ ->inContentLanguage()->text() )
+ - strlen( $oldTarget->getFullText() ) );
- $truncatedtext = $newContent->getTextForSummary(
- 200 - strlen( wfMessage( 'autosumm-new' )->inContentLanguage()->text() ) );
+ return wfMessage( 'autosumm-removed-redirect', $oldTarget->getFullText() )
+ ->rawParams( $truncatedtext )->inContentLanguage()->text();
+ case 'newpage':
+ // If they're making a new article, give its text, truncated, in the summary.
+ $truncatedtext = $newContent->getTextForSummary(
+ 200 - strlen( wfMessage( 'autosumm-new' )->inContentLanguage()->text() ) );
- return wfMessage( 'autosumm-new' )->rawParams( $truncatedtext )
- ->inContentLanguage()->text();
+ return wfMessage( 'autosumm-new' )->rawParams( $truncatedtext )
+ ->inContentLanguage()->text();
+ case 'blank':
+ return wfMessage( 'autosumm-blank' )->inContentLanguage()->text();
+ case 'replace':
+ $truncatedtext = $newContent->getTextForSummary(
+ 200 - strlen( wfMessage( 'autosumm-replace' )->inContentLanguage()->text() ) );
+
+ return wfMessage( 'autosumm-replace' )->rawParams( $truncatedtext )
+ ->inContentLanguage()->text();
+ case 'newblank':
+ return wfMessage( 'autosumm-newblank' )->inContentLanguage()->text();
+ default:
+ return '';
}
+ }
- // Blanking auto-summaries
- if ( !empty( $oldContent ) && $oldContent->getSize() > 0 && $newContent->getSize() == 0 ) {
- return wfMessage( 'autosumm-blank' )->inContentLanguage()->text();
- } elseif ( !empty( $oldContent )
- && $oldContent->getSize() > 10 * $newContent->getSize()
- && $newContent->getSize() < 500
- ) {
- // Removing more than 90% of the article
-
- $truncatedtext = $newContent->getTextForSummary(
- 200 - strlen( wfMessage( 'autosumm-replace' )->inContentLanguage()->text() ) );
+ /**
+ * Return an applicable tag if one exists for the given edit or return null.
+ *
+ * @since 1.31
+ *
+ * @param Content|null $oldContent The previous text of the page.
+ * @param Content|null $newContent The submitted text of the page.
+ * @param int $flags Bit mask: a bit mask of flags submitted for the edit.
+ *
+ * @return string|null An appropriate tag, or null.
+ */
+ public function getChangeTag(
+ Content $oldContent = null,
+ Content $newContent = null,
+ $flags = 0
+ ) {
+ $changeType = $this->getChangeType( $oldContent, $newContent, $flags );
- return wfMessage( 'autosumm-replace' )->rawParams( $truncatedtext )
- ->inContentLanguage()->text();
+ // There's no applicable tag for this change.
+ if ( !$changeType ) {
+ return null;
}
- // New blank article auto-summary
- if ( $flags & EDIT_NEW && $newContent->isEmpty() ) {
- return wfMessage( 'autosumm-newblank' )->inContentLanguage()->text();
+ // Core tags use the same keys as ones returned from $this->getChangeType()
+ // but prefixed with pseudo namespace 'mw-', so we add the prefix before checking
+ // if this type of change should be tagged
+ $tag = 'mw-' . $changeType;
+
+ // Not all change types are tagged, so we check against the list of defined tags.
+ if ( in_array( $tag, ChangeTags::getSoftwareTags() ) ) {
+ return $tag;
}
- // If we reach this point, there's no applicable auto-summary for our
- // case, so our auto-summary is empty.
- return '';
+ return null;
}
/**
/**
* Add new field definition to array.
- * @param SearchIndexField[] $fields
- * @param SearchEngine $engine
- * @param string $name
- * @param int $type
+ * @param SearchIndexField[] &$fields
+ * @param SearchEngine $engine
+ * @param string $name
+ * @param int $type
* @return SearchIndexField[] new field defs
* @since 1.28
*/
* as representation of this document.
* Overriding class should call parent function or take care of calling
* the SearchDataForIndex hook.
- * @param WikiPage $page Page to index
+ * @param WikiPage $page Page to index
* @param ParserOutput $output
* @param SearchEngine $engine Search engine for which we are indexing
* @return array Map of name=>value for fields
*
* Specific content handlers may override it if they need different content handling.
*
- * @param WikiPage $page
+ * @param WikiPage $page
* @param ParserCache $cache
* @return ParserOutput
*/