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
This commit is contained in:
daniel 2012-10-11 17:36:42 +02:00
parent fe70b85c4b
commit 09c607f7b9
8 changed files with 68 additions and 27 deletions

View file

@ -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;

View file

@ -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 );

View file

@ -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;
}

View file

@ -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 );
}

View file

@ -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();
}

View file

@ -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 );

View file

@ -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 ( !Hooks::isRegistered( $event ) && empty( $wgHooks[$event] ) ) {
if ( $warn === null ) {
$warn = self::$enableDeprecationWarnings;
}
if ( !Hooks::isRegistered( $event ) ) {
return true; // nothing to do here
}

View file

@ -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() );