From 09c607f7b9c997a908b8389137f9ab412ca141a9 Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 11 Oct 2012 17:36:42 +0200 Subject: [PATCH] Silence warnings about deprecation by ContentHandler. The introduction of the ContentHandler caused quite a few functions and hooks to become deprecated. Usage of these has been removed in core, but is still present in extensions. Extensions should be fixed after ContentHandler has settled in a bit, but for now we need a way to silence the warnings. Change-Id: Ia223243222675f778e8f8c32923f956790db0b4f --- includes/Article.php | 4 +-- includes/EditPage.php | 12 ++++---- includes/Import.php | 2 +- includes/Revision.php | 4 +-- includes/Title.php | 6 ++++ includes/WikiPage.php | 17 ++++++----- includes/content/ContentHandler.php | 46 +++++++++++++++++++++++++---- includes/diff/DifferenceEngine.php | 4 +-- 8 files changed, 68 insertions(+), 27 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 736781225a..0eb0c68b08 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -243,7 +243,7 @@ class Article extends Page { * @return string Return the text of this revision */ public function getContent() { - wfDeprecated( __METHOD__, '1.21' ); + ContentHandler::deprecated( __METHOD__, '1.21' ); $content = $this->getContentObject(); return ContentHandler::getContentText( $content ); } @@ -377,7 +377,7 @@ class Article extends Page { * @deprecated in 1.21, use WikiPage::getContent() instead */ function fetchContent() { #BC cruft! - wfDeprecated( __METHOD__, '1.21' ); + ContentHandler::deprecated( __METHOD__, '1.21' ); if ( $this->mContentLoaded && $this->mContent ) { return $this->mContent; diff --git a/includes/EditPage.php b/includes/EditPage.php index f7d9e3f182..9827b2764a 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -806,10 +806,10 @@ class EditPage { * @param $def_text string * @return mixed string on success, $def_text for invalid sections * @private - * @deprecated since 1.21 + * @deprecated since 1.21, get WikiPage::getContent() instead. */ function getContent( $def_text = false ) { - wfDeprecated( __METHOD__, '1.21' ); + ContentHandler::deprecated( __METHOD__, '1.21' ); if ( $def_text !== null && $def_text !== false && $def_text !== '' ) { $def_content = $this->toEditContent( $def_text ); @@ -989,10 +989,10 @@ class EditPage { * Use this method before edit() to preload some text into the edit box * * @param $text string - * @deprecated since 1.21 + * @deprecated since 1.21, use setPreloadedContent() instead. */ public function setPreloadedText( $text ) { - wfDeprecated( __METHOD__, "1.21" ); + ContentHandler::deprecated( __METHOD__, "1.21" ); $content = $this->toEditContent( $text ); @@ -1021,7 +1021,7 @@ class EditPage { * @deprecated since 1.21, use getPreloadedContent() instead */ protected function getPreloadedText( $preload ) { - wfDeprecated( __METHOD__, "1.21" ); + ContentHandler::deprecated( __METHOD__, "1.21" ); $content = $this->getPreloadedContent( $preload ); $text = $this->toEditText( $content ); @@ -1643,7 +1643,7 @@ class EditPage { * @deprecated since 1.21, use mergeChangesIntoContent() instead */ function mergeChangesInto( &$editText ){ - wfDebug( __METHOD__, "1.21" ); + ContentHandler::deprecated( __METHOD__, "1.21" ); $editContent = $this->toEditContent( $editText ); diff --git a/includes/Import.php b/includes/Import.php index c9b09975fd..7cc6fb1eeb 100644 --- a/includes/Import.php +++ b/includes/Import.php @@ -1215,7 +1215,7 @@ class WikiRevision { * @deprecated Since 1.21, use getContent() instead. */ function getText() { - wfDeprecated( "Use getContent() instead." ); + ContentHandler::deprecated( __METHOD__, '1.21' ); return $this->text; } diff --git a/includes/Revision.php b/includes/Revision.php index 4874490f82..2bc98c6468 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -892,7 +892,7 @@ class Revision implements IDBAccessObject { * @return String */ public function getText( $audience = self::FOR_PUBLIC, User $user = null ) { - wfDeprecated( __METHOD__, '1.21' ); + ContentHandler::deprecated( __METHOD__, '1.21' ); $content = $this->getContent( $audience, $user ); return ContentHandler::getContentText( $content ); # returns the raw content text, if applicable @@ -942,7 +942,7 @@ class Revision implements IDBAccessObject { * or Revision::getSerializedData() as appropriate. */ public function getRawText() { - wfDeprecated( __METHOD__, "1.21" ); + ContentHandler::deprecated( __METHOD__, "1.21" ); return $this->getText( self::RAW ); } diff --git a/includes/Title.php b/includes/Title.php index 3212f542cc..9f19e44e67 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -387,6 +387,8 @@ class Title { * @deprecated since 1.21, use Content::getRedirectTarget instead. */ public static function newFromRedirect( $text ) { + ContentHandler::deprecated( __METHOD__, '1.21' ); + $content = ContentHandler::makeContent( $text, null, CONTENT_MODEL_WIKITEXT ); return $content->getRedirectTarget(); } @@ -402,6 +404,8 @@ class Title { * @deprecated since 1.21, use Content::getUltimateRedirectTarget instead. */ public static function newFromRedirectRecurse( $text ) { + ContentHandler::deprecated( __METHOD__, '1.21' ); + $content = ContentHandler::makeContent( $text, null, CONTENT_MODEL_WIKITEXT ); return $content->getUltimateRedirectTarget(); } @@ -417,6 +421,8 @@ class Title { * @deprecated since 1.21, use Content::getRedirectChain instead. */ public static function newFromRedirectArray( $text ) { + ContentHandler::deprecated( __METHOD__, '1.21' ); + $content = ContentHandler::makeContent( $text, null, CONTENT_MODEL_WIKITEXT ); return $content->getRedirectChain(); } diff --git a/includes/WikiPage.php b/includes/WikiPage.php index 770c37a2a4..88cf62f4c4 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -631,7 +631,8 @@ class WikiPage extends Page implements IDBAccessObject { * @deprecated as of 1.21, getContent() should be used instead. */ public function getText( $audience = Revision::FOR_PUBLIC, User $user = null ) { #@todo: deprecated, replace usage! - wfDeprecated( __METHOD__, '1.21' ); + ContentHandler::deprecated( __METHOD__, '1.21' ); + $this->loadLastEdit(); if ( $this->mLastRevision ) { return $this->mLastRevision->getText( $audience, $user ); @@ -646,7 +647,7 @@ class WikiPage extends Page implements IDBAccessObject { * @deprecated as of 1.21, getContent() should be used instead. */ public function getRawText() { - wfDeprecated( __METHOD__, '1.21' ); + ContentHandler::deprecated( __METHOD__, '1.21' ); return $this->getText( Revision::RAW ); } @@ -1381,7 +1382,7 @@ class WikiPage extends Page implements IDBAccessObject { * @deprecated since 1.21: use ContentHandler::getUndoContent() instead. */ public function getUndoText( Revision $undo, Revision $undoafter = null ) { - wfDeprecated( __METHOD__, '1.21' ); + ContentHandler::deprecated( __METHOD__, '1.21' ); $this->loadLastEdit(); @@ -1413,7 +1414,7 @@ class WikiPage extends Page implements IDBAccessObject { * @deprecated since 1.21, use replaceSectionContent() instead */ public function replaceSection( $section, $text, $sectionTitle = '', $edittime = null ) { - wfDeprecated( __METHOD__, '1.21' ); + ContentHandler::deprecated( __METHOD__, '1.21' ); if ( strval( $section ) == '' ) { //NOTE: keep condition in sync with condition in replaceSectionContent! // Whole-page edit; let the whole text through @@ -1561,7 +1562,7 @@ class WikiPage extends Page implements IDBAccessObject { * @deprecated since 1.21: use doEditContent() instead. */ public function doEdit( $text, $summary, $flags = 0, $baseRevId = false, $user = null ) { - wfDeprecated( __METHOD__, '1.21' ); + ContentHandler::deprecated( __METHOD__, '1.21' ); $content = ContentHandler::makeContent( $text, $this->getTitle() ); @@ -1934,7 +1935,7 @@ class WikiPage extends Page implements IDBAccessObject { * @deprecated in 1.21: use prepareContentForEdit instead. */ public function prepareTextForEdit( $text, $revid = null, User $user = null ) { - wfDeprecated( __METHOD__, '1.21' ); + ContentHandler::deprecated( __METHOD__, '1.21' ); $content = ContentHandler::makeContent( $text, $this->getTitle() ); return $this->prepareContentForEdit( $content, $revid , $user ); } @@ -2136,7 +2137,7 @@ class WikiPage extends Page implements IDBAccessObject { * @deprecated since 1.21, use doEditContent() instead. */ public function doQuickEdit( $text, User $user, $comment = '', $minor = 0 ) { - wfDeprecated( __METHOD__, "1.21" ); + ContentHandler::deprecated( __METHOD__, "1.21" ); $content = ContentHandler::makeContent( $text, $this->getTitle() ); return $this->doQuickEditContent( $content, $user, $comment , $minor ); @@ -2937,7 +2938,7 @@ class WikiPage extends Page implements IDBAccessObject { public static function getAutosummary( $oldtext, $newtext, $flags ) { # NOTE: stub for backwards-compatibility. assumes the given text is wikitext. will break horribly if it isn't. - wfDeprecated( __METHOD__, '1.21' ); + ContentHandler::deprecated( __METHOD__, '1.21' ); $handler = ContentHandler::getForModelID( CONTENT_MODEL_WIKITEXT ); $oldContent = is_null( $oldtext ) ? null : $handler->unserializeContent( $oldtext ); diff --git a/includes/content/ContentHandler.php b/includes/content/ContentHandler.php index 00761cfe1e..1d1dad0cd3 100644 --- a/includes/content/ContentHandler.php +++ b/includes/content/ContentHandler.php @@ -28,6 +28,15 @@ class MWContentSerializationException extends MWException { */ abstract class ContentHandler { + /** + * Switch for enabling deprecation warnings. Used by ContentHandler::deprecated() + * and ContentHandler::runLegacyHooks(). + * + * Once the ContentHandler code has settled in a bit, this should be set to true to + * make extensions etc. show warnings when using deprecated functions and hooks. + */ + protected static $enableDeprecationWarnings = false; + /** * Convenience function for getting flat text from a Content object. This * should only be used in the context of backwards compatibility with code @@ -50,7 +59,6 @@ abstract class ContentHandler { * - otherwise, the behaviour is undefined. * * @since 1.21 - * @deprecated since 1.21. Always try to use the content object. * * @static * @param $content Content|null @@ -951,6 +959,25 @@ abstract class ContentHandler { return false; } + /** + * Logs a deprecation warning, visible if $wgDevelopmentWarnings, but only if + * self::$enableDeprecationWarnings is set to true. + * + * @param String $func The name of the deprecated function + * @param string $version The version since the method is deprecated. Usually 1.21 + * for ContentHandler related stuff. + * @param String|bool $component: Component to which the function belongs. + * If false, it is assumed the function is in MediaWiki core. + * + * @see ContentHandler::$enableDeprecationWarnings + * @see wfDeprecated + */ + public static function deprecated( $func, $version, $component = false ) { + if ( self::$enableDeprecationWarnings ) { + wfDeprecated( $func, $version, $component, 3 ); + } + } + /** * Call a legacy hook that uses text instead of Content objects. * Will log a warning when a matching hook function is registered. @@ -960,15 +987,22 @@ abstract class ContentHandler { * * @param $event String: event name * @param $args Array: parameters passed to hook functions - * @param $warn bool: whether to log a warning (default: true). Should generally be true, - * may be set to false for testing. + * @param $warn bool: whether to log a warning. + * Default to self::$enableDeprecationWarnings. + * May be set to false for testing. * * @return Boolean True if no handler aborted the hook + * + * @see ContentHandler::$enableDeprecationWarnings */ - public static function runLegacyHooks( $event, $args = array(), $warn = true ) { - global $wgHooks; //@todo: once I39bd5de2 is merged, direct access to $wgHooks is no longer needed. + public static function runLegacyHooks( $event, $args = array(), + $warn = null ) { + + if ( $warn === null ) { + $warn = self::$enableDeprecationWarnings; + } - if ( !Hooks::isRegistered( $event ) && empty( $wgHooks[$event] ) ) { + if ( !Hooks::isRegistered( $event ) ) { return true; // nothing to do here } diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php index d638c48ba8..4ca8263134 100644 --- a/includes/diff/DifferenceEngine.php +++ b/includes/diff/DifferenceEngine.php @@ -746,7 +746,7 @@ class DifferenceEngine extends ContextSource { * @deprecated since 1.21, use generateContentDiffBody() instead! */ function generateDiffBody( $otext, $ntext ) { - wfDeprecated( __METHOD__, "1.21" ); + ContentHandler::deprecated( __METHOD__, "1.21" ); return $this->generateTextDiffBody( $otext, $ntext ); } @@ -1018,7 +1018,7 @@ class DifferenceEngine extends ContextSource { * @deprecated since 1.21, use setContent() instead. */ function setText( $oldText, $newText ) { - wfDeprecated( __METHOD__, "1.21" ); + ContentHandler::deprecated( __METHOD__, "1.21" ); $oldContent = ContentHandler::makeContent( $oldText, $this->getTitle() ); $newContent = ContentHandler::makeContent( $newText, $this->getTitle() ); -- 2.20.1