* @ingroup Content
*/
class MWContentSerializationException extends MWException {
-
}
/**
* @ingroup Content
*/
abstract class ContentHandler {
-
/**
* Switch for enabling deprecation warnings. Used by ContentHandler::deprecated()
* and ContentHandler::runLegacyHooks().
* not be unserialized using $format.
*/
public static function makeContent( $text, Title $title = null,
- $modelId = null, $format = null )
- {
+ $modelId = null, $format = null
+ ) {
if ( is_null( $modelId ) ) {
if ( is_null( $title ) ) {
throw new MWException( "Must provide a Title object or a content model ID." );
}
$handler = ContentHandler::getForModelID( $modelId );
+
return $handler->unserializeContent( $text, $format );
}
*/
public static function getForTitle( Title $title ) {
$modelId = $title->getContentModel();
+
return ContentHandler::getForModelID( $modelId );
}
*/
public static function getForContent( Content $content ) {
$modelId = $content->getModel();
+
return ContentHandler::getForModelID( $modelId );
}
/**
- * @var Array A Cache of ContentHandler instances by model id
+ * @var array A Cache of ContentHandler instances by model id
*/
- static $handlers;
+ protected static $handlers;
/**
* Returns the ContentHandler singleton for the given model ID. Use the
$handler = new $class( $modelId );
if ( !( $handler instanceof ContentHandler ) ) {
- throw new MWException( "$class from \$wgContentHandlers is not compatible with ContentHandler" );
+ throw new MWException( "$class from \$wgContentHandlers is not " .
+ "compatible with ContentHandler" );
}
}
wfDebugLog( 'ContentHandler', 'Created handler for ' . $modelId
- . ': ' . get_class( $handler ) );
+ . ': ' . get_class( $handler ) );
ContentHandler::$handlers[$modelId] = $handler;
+
return ContentHandler::$handlers[$modelId];
}
* @param string $name The content model ID, as given by a CONTENT_MODEL_XXX
* constant or returned by Revision::getContentModel().
*
- * @return string The content format's localized name.
+ * @return string The content model's localized name.
* @throws MWException if the model id isn't known.
*/
public static function getLocalizedName( $name ) {
}
$formats = array_unique( $formats );
+
return $formats;
}
/**
* Get the language in which the content of the given page is written.
*
- * This default implementation just returns $wgContLang (except for pages in the MediaWiki namespace)
+ * This default implementation just returns $wgContLang (except for pages
+ * in the MediaWiki namespace)
*
- * Note that the pages language is not cacheable, since it may in some cases depend on user settings.
+ * Note that the pages language is not cacheable, since it may in some
+ * cases depend on user settings.
*
* Also note that the page language may or may not depend on the actual content of the page,
* that is, this method may load the content in order to determine the language.
*
* @since 1.21
*
- * @param Title $title the page to determine the language for.
+ * @param Title $title the page to determine the language for.
* @param Content|null $content the page's content, if you have it handy, to avoid reloading it.
*
* @return Language the page's language
}
wfRunHooks( 'PageContentLanguage', array( $title, &$pageLang, $wgLang ) );
+
return wfGetLangObj( $pageLang );
}
*
* @since 1.21
*
- * @param Title $title the page to determine the language for.
+ * @param Title $title the page to determine the language for.
* @param Content|null $content the page's content, if you have it handy, to avoid reloading it.
*
* @return Language the page's language for viewing
* typically based on the namespace or some other aspect of the title, such as a special suffix
* (e.g. ".svg" for SVG content).
*
+ * @note: this calls the ContentHandlerCanBeUsedOn hook which may be used to override which
+ * content model can be used where.
+ *
* @param Title $title the page's title.
*
* @return bool true if content of this kind can be used on the given page, false otherwise.
*/
public function canBeUsedOn( Title $title ) {
- return true;
+ $ok = true;
+
+ wfRunHooks( 'ContentModelCanBeUsedOn', array( $this->getModelID(), $title, &$ok ) );
+
+ return $ok;
}
/**
if ( is_object( $rt ) ) {
if ( !is_object( $ot )
|| !$rt->equals( $ot )
- || $ot->getFragment() != $rt->getFragment() )
- {
+ || $ot->getFragment() != $rt->getFragment()
+ ) {
$truncatedtext = $newContent->getTextForSummary(
250
- - strlen( wfMessage( 'autoredircomment' )->inContentLanguage()->text() )
- - strlen( $rt->getFullText() ) );
+ - strlen( wfMessage( 'autoredircomment' )->inContentLanguage()->text() )
+ - strlen( $rt->getFullText() ) );
return wfMessage( 'autoredircomment', $rt->getFullText() )
- ->rawParams( $truncatedtext )->inContentLanguage()->text();
+ ->rawParams( $truncatedtext )->inContentLanguage()->text();
}
}
200 - strlen( wfMessage( 'autosumm-new' )->inContentLanguage()->text() ) );
return wfMessage( 'autosumm-new' )->rawParams( $truncatedtext )
- ->inContentLanguage()->text();
+ ->inContentLanguage()->text();
}
// Blanking auto-summaries
return wfMessage( 'autosumm-blank' )->inContentLanguage()->text();
} elseif ( !empty( $oldContent )
&& $oldContent->getSize() > 10 * $newContent->getSize()
- && $newContent->getSize() < 500 )
- {
+ && $newContent->getSize() < 500
+ ) {
// Removing more than 90% of the article
$truncatedtext = $newContent->getTextForSummary(
200 - strlen( wfMessage( 'autosumm-replace' )->inContentLanguage()->text() ) );
return wfMessage( 'autosumm-replace' )->rawParams( $truncatedtext )
- ->inContentLanguage()->text();
+ ->inContentLanguage()->text();
}
// If we reach this point, there's no applicable auto-summary for our
}
/**
- * Get parser options suitable for rendering the primary article wikitext
+ * Get parser options suitable for rendering and caching the article
*
* @param IContextSource|User|string $context One of the following:
* - IContextSource: Use the User and the Language of the provided
* - 'canonical': Canonical options (anonymous user with default
* preferences and content language).
*
- * @param IContextSource|User|string $context
- *
* @throws MWException
* @return ParserOptions
*/
* 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.
+ * @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
* @see ContentHandler::$enableDeprecationWarnings
*/
public static function runLegacyHooks( $event, $args = array(),
- $warn = null ) {
+ $warn = null
+ ) {
if ( $warn === null ) {
$warn = self::$enableDeprecationWarnings;
wfRestoreWarnings();
- wfWarn( "Using obsolete hook $event via ContentHandler::runLegacyHooks()! Handlers: " . implode( ', ', $handlerInfo ), 2 );
+ wfWarn( "Using obsolete hook $event via ContentHandler::runLegacyHooks()! Handlers: " .
+ implode( ', ', $handlerInfo ), 2 );
}
// convert Content objects to text