From a1789ddde42033f1b05cc4929491214ee6e79383 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 17 Dec 2015 09:15:42 +0100 Subject: Update to MediaWiki 1.26.0 --- includes/content/ContentHandler.php | 54 +++++++++++++++++++-------- includes/content/CssContent.php | 44 ++++++++++++++++++++++ includes/content/CssContentHandler.php | 19 ++++++++++ includes/content/JavaScriptContent.php | 47 +++++++++++++++++++++++ includes/content/JavaScriptContentHandler.php | 18 +++++++++ includes/content/TextContentHandler.php | 9 +++++ includes/content/WikitextContent.php | 4 +- 7 files changed, 177 insertions(+), 18 deletions(-) (limited to 'includes/content') diff --git a/includes/content/ContentHandler.php b/includes/content/ContentHandler.php index 371b267e..bf91a4f0 100644 --- a/includes/content/ContentHandler.php +++ b/includes/content/ContentHandler.php @@ -207,26 +207,26 @@ abstract class ContentHandler { } } - // Could this page contain custom CSS or JavaScript, based on the title? - $isCssOrJsPage = NS_MEDIAWIKI == $ns && preg_match( '!\.(css|js)$!u', $title->getText(), $m ); - if ( $isCssOrJsPage ) { + // Could this page contain code based on the title? + $isCodePage = NS_MEDIAWIKI == $ns && preg_match( '!\.(css|js|json)$!u', $title->getText(), $m ); + if ( $isCodePage ) { $ext = $m[1]; } // Hook can force JS/CSS - Hooks::run( 'TitleIsCssOrJsPage', array( $title, &$isCssOrJsPage ), '1.25' ); + Hooks::run( 'TitleIsCssOrJsPage', array( $title, &$isCodePage ), '1.25' ); - // Is this a .css subpage of a user page? - $isJsCssSubpage = NS_USER == $ns - && !$isCssOrJsPage - && preg_match( "/\\/.*\\.(js|css)$/", $title->getText(), $m ); - if ( $isJsCssSubpage ) { + // Is this a user subpage containing code? + $isCodeSubpage = NS_USER == $ns + && !$isCodePage + && preg_match( "/\\/.*\\.(js|css|json)$/", $title->getText(), $m ); + if ( $isCodeSubpage ) { $ext = $m[1]; } // Is this wikitext, according to $wgNamespaceContentModels or the DefaultModelFor hook? $isWikitext = is_null( $model ) || $model == CONTENT_MODEL_WIKITEXT; - $isWikitext = $isWikitext && !$isCssOrJsPage && !$isJsCssSubpage; + $isWikitext = $isWikitext && !$isCodePage && !$isCodeSubpage; // Hook can override $isWikitext Hooks::run( 'TitleIsWikitextPage', array( $title, &$isWikitext ), '1.25' ); @@ -237,6 +237,8 @@ abstract class ContentHandler { return CONTENT_MODEL_JAVASCRIPT; case 'css': return CONTENT_MODEL_CSS; + case 'json': + return CONTENT_MODEL_JSON; default: return is_null( $model ) ? CONTENT_MODEL_TEXT : $model; } @@ -353,16 +355,20 @@ abstract class ContentHandler { * * @param string $name The content model ID, as given by a CONTENT_MODEL_XXX * constant or returned by Revision::getContentModel(). + * @param Language|null $lang The language to parse the message in (since 1.26) * * @throws MWException If the model ID isn't known. * @return string The content model's localized name. */ - public static function getLocalizedName( $name ) { + public static function getLocalizedName( $name, Language $lang = null ) { // Messages: content-model-wikitext, content-model-text, // content-model-javascript, content-model-css $key = "content-model-$name"; $msg = wfMessage( $key ); + if ( $lang ) { + $msg->inLanguage( $lang ); + } return $msg->exists() ? $msg->plain() : $name; } @@ -629,7 +635,7 @@ abstract class ContentHandler { // hook: get difference engine $differenceEngine = null; - if ( !wfRunHooks( 'GetDifferenceEngine', + if ( !Hooks::run( 'GetDifferenceEngine', array( $context, $old, $new, $refreshCache, $unhide, &$differenceEngine ) ) ) { return $differenceEngine; @@ -1021,7 +1027,7 @@ abstract class ContentHandler { /** * Returns true for content models that support caching using the - * ParserCache mechanism. See WikiPage::isParserCacheUsed(). + * ParserCache mechanism. See WikiPage::shouldCheckParserCache(). * * @since 1.21 * @@ -1057,6 +1063,24 @@ abstract class ContentHandler { return false; } + /** + * Return true if this content model supports direct editing, such as via EditPage. + * + * @return bool Default is false, and true for TextContent and it's derivatives. + */ + public function supportsDirectEditing() { + return false; + } + + /** + * Whether or not this content model supports direct editing via ApiEditPage + * + * @return bool Default is false, and true for TextContent and derivatives. + */ + public function supportsDirectApiEditing() { + return $this->supportsDirectEditing(); + } + /** * Logs a deprecation warning, visible if $wgDevelopmentWarnings, but only if * self::$enableDeprecationWarnings is set to true. @@ -1112,7 +1136,7 @@ abstract class ContentHandler { $handlers = Hooks::getHandlers( $event ); $handlerInfo = array(); - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); foreach ( $handlers as $handler ) { if ( is_array( $handler ) ) { @@ -1135,7 +1159,7 @@ abstract class ContentHandler { $handlerInfo[] = $info; } - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); wfWarn( "Using obsolete hook $event via ContentHandler::runLegacyHooks()! Handlers: " . implode( ', ', $handlerInfo ), 2 ); diff --git a/includes/content/CssContent.php b/includes/content/CssContent.php index 8290603c..b4f5196d 100644 --- a/includes/content/CssContent.php +++ b/includes/content/CssContent.php @@ -32,6 +32,11 @@ */ class CssContent extends TextContent { + /** + * @var bool|Title|null + */ + private $redirectTarget = false; + /** * @param string $text CSS code. * @param string $modelId the content content model @@ -74,4 +79,43 @@ class CssContent extends TextContent { return $html; } + /** + * @param Title $target + * @return CssContent + */ + public function updateRedirect( Title $target ) { + if ( !$this->isRedirect() ) { + return $this; + } + + return $this->getContentHandler()->makeRedirectContent( $target ); + } + + /** + * @return Title|null + */ + public function getRedirectTarget() { + if ( $this->redirectTarget !== false ) { + return $this->redirectTarget; + } + $this->redirectTarget = null; + $text = $this->getNativeData(); + if ( strpos( $text, '/* #REDIRECT */' ) === 0 ) { + // Extract the title from the url + preg_match( '/title=(.*?)&action=raw/', $text, $matches ); + if ( isset( $matches[1] ) ) { + $title = Title::newFromText( $matches[1] ); + if ( $title ) { + // Have a title, check that the current content equals what + // the redirect content should be + if ( $this->equals( $this->getContentHandler()->makeRedirectContent( $title ) ) ) { + $this->redirectTarget = $title; + } + } + } + } + + return $this->redirectTarget; + } + } diff --git a/includes/content/CssContentHandler.php b/includes/content/CssContentHandler.php index b2a8676b..ae5f742a 100644 --- a/includes/content/CssContentHandler.php +++ b/includes/content/CssContentHandler.php @@ -39,4 +39,23 @@ class CssContentHandler extends CodeContentHandler { protected function getContentClass() { return 'CssContent'; } + + public function supportsRedirects() { + return true; + } + + /** + * Create a redirect that is also valid CSS + * + * @param Title $destination + * @param string $text ignored + * @return CssContent + */ + public function makeRedirectContent( Title $destination, $text = '' ) { + // The parameters are passed as a string so the / is not url-encoded by wfArrayToCgi + $url = $destination->getFullURL( 'action=raw&ctype=text/css', false, PROTO_RELATIVE ); + $class = $this->getContentClass(); + return new $class( '/* #REDIRECT */@import ' . CSSMin::buildUrlValue( $url ) . ';' ); + } + } diff --git a/includes/content/JavaScriptContent.php b/includes/content/JavaScriptContent.php index c0194c2e..6d236560 100644 --- a/includes/content/JavaScriptContent.php +++ b/includes/content/JavaScriptContent.php @@ -32,6 +32,11 @@ */ class JavaScriptContent extends TextContent { + /** + * @var bool|Title|null + */ + private $redirectTarget = false; + /** * @param string $text JavaScript code. * @param string $modelId the content model name @@ -73,4 +78,46 @@ class JavaScriptContent extends TextContent { return $html; } + /** + * If this page is a redirect, return the content + * if it should redirect to $target instead + * + * @param Title $target + * @return JavaScriptContent + */ + public function updateRedirect( Title $target ) { + if ( !$this->isRedirect() ) { + return $this; + } + + return $this->getContentHandler()->makeRedirectContent( $target ); + } + + /** + * @return Title|null + */ + public function getRedirectTarget() { + if ( $this->redirectTarget !== false ) { + return $this->redirectTarget; + } + $this->redirectTarget = null; + $text = $this->getNativeData(); + if ( strpos( $text, '/* #REDIRECT */' ) === 0 ) { + // Extract the title from the url + preg_match( '/title=(.*?)\\\\u0026action=raw/', $text, $matches ); + if ( isset( $matches[1] ) ) { + $title = Title::newFromText( $matches[1] ); + if ( $title ) { + // Have a title, check that the current content equals what + // the redirect content should be + if ( $this->equals( $this->getContentHandler()->makeRedirectContent( $title ) ) ) { + $this->redirectTarget = $title; + } + } + } + } + + return $this->redirectTarget; + } + } diff --git a/includes/content/JavaScriptContentHandler.php b/includes/content/JavaScriptContentHandler.php index d2218971..65e3a6f0 100644 --- a/includes/content/JavaScriptContentHandler.php +++ b/includes/content/JavaScriptContentHandler.php @@ -41,4 +41,22 @@ class JavaScriptContentHandler extends CodeContentHandler { protected function getContentClass() { return 'JavaScriptContent'; } + + public function supportsRedirects() { + return true; + } + + /** + * Create a redirect that is also valid JavaScript + * + * @param Title $destination + * @param string $text ignored + * @return JavaScriptContent + */ + public function makeRedirectContent( Title $destination, $text = '' ) { + // The parameters are passed as a string so the / is not url-encoded by wfArrayToCgi + $url = $destination->getFullURL( 'action=raw&ctype=text/javascript', false, PROTO_RELATIVE ); + $class = $this->getContentClass(); + return new $class( '/* #REDIRECT */' . Xml::encodeJsCall( 'mw.loader.load', array( $url ) ) ); + } } diff --git a/includes/content/TextContentHandler.php b/includes/content/TextContentHandler.php index ffe1acbd..f5e87830 100644 --- a/includes/content/TextContentHandler.php +++ b/includes/content/TextContentHandler.php @@ -134,4 +134,13 @@ class TextContentHandler extends ContentHandler { return new $class( '' ); } + /** + * @see ContentHandler::supportsDirectEditing + * + * @return bool Default is true for TextContent and derivatives. + */ + public function supportsDirectEditing() { + return true; + } + } diff --git a/includes/content/WikitextContent.php b/includes/content/WikitextContent.php index dbe09f91..8beae393 100644 --- a/includes/content/WikitextContent.php +++ b/includes/content/WikitextContent.php @@ -82,7 +82,6 @@ class WikitextContent extends TextContent { $text = $with->getNativeData(); if ( strval( $sectionId ) === '' ) { - return $with; # XXX: copy first? } @@ -273,12 +272,11 @@ class WikitextContent extends TextContent { return false; } - $text = $this->getNativeData(); - switch ( $wgArticleCountMethod ) { case 'any': return true; case 'comma': + $text = $this->getNativeData(); return strpos( $text, ',' ) !== false; case 'link': if ( $hasLinks === null ) { # not known, find out -- cgit v1.2.3-54-g00ecf