From: jenkins-bot Date: Sat, 10 May 2014 14:50:40 +0000 (+0000) Subject: Merge "Adds an --extension option to generateJsonI18n" X-Git-Tag: 1.31.0-rc.0~15794 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=12857afcdb162d984951b0401b93a0d2c8d8af3a;hp=68bdc4f7f4eb1109e27fad33676010276853d58f;p=lhc%2Fweb%2Fwiklou.git Merge "Adds an --extension option to generateJsonI18n" --- diff --git a/docs/hooks.txt b/docs/hooks.txt index 688e0cd91b..87eca8d9f2 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -887,6 +887,19 @@ $title: the Title in question. Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok. +'ContentGetParserOutput': Customize parser output for a given content object, +called by AbstractContent::getParserOutput. May be used to override the normal +model-specific rendering of page content. +$content: The Content to render +$title: Title of the page, as context +$revId: The revision ID, as context +$options: ParserOptions for rendering. To avoid confusing the parser cache, +the output can only depend on parameters provided to this hook function, not on global state. +$generateHtml: boolean, indicating whether full HTML should be generated. If false, +generation of HTML may be skipped, but other information should still be present in the +ParserOutput object. +&$output: ParserOutput, to manipulate or replace + 'ConvertContent': Called by AbstractContent::convert when a conversion to another content model is requested. $content: The Content object to be converted. @@ -2171,7 +2184,7 @@ $title : Current Title object being displayed in search results. $article: The article object corresponding to the page 'ShowRawCssJs': Customise the output of raw CSS and JavaScript in page views. -DEPRECATED, use the ContentHandler facility to handle CSS and JavaScript! +DEPRECATED, use the ContentGetParserOutput hook instead! $text: Text being shown $title: Title of the custom script/stylesheet page $output: Current OutputPage object diff --git a/includes/Article.php b/includes/Article.php index 0a4b5ee30e..3bb1563f7a 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -832,8 +832,9 @@ class Article implements Page { * Show a page view for a page formatted as CSS or JavaScript. To be called by * Article::view() only. * - * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these - * page views. + * This exists mostly to serve the deprecated ShowRawCssJs hook (used to customize these views). + * It has been replaced by the ContentGetParserOutput hook, which lets you do the same but with + * more flexibility. * * @param bool $showCacheHint Whether to show a message telling the user * to clear the browser cache (default: true). diff --git a/includes/api/ApiFeedContributions.php b/includes/api/ApiFeedContributions.php index 6f7121b8ac..afd5a1320c 100644 --- a/includes/api/ApiFeedContributions.php +++ b/includes/api/ApiFeedContributions.php @@ -112,7 +112,7 @@ class ApiFeedContributions extends ApiBase { return new FeedItem( $title->getPrefixedText(), $this->feedItemDesc( $revision ), - $title->getFullURL(), + $title->getFullURL( array( 'diff' => $revision->getId() ) ), $date, $this->feedItemAuthor( $revision ), $comments diff --git a/includes/content/AbstractContent.php b/includes/content/AbstractContent.php index 77d354294d..8ba43f68ab 100644 --- a/includes/content/AbstractContent.php +++ b/includes/content/AbstractContent.php @@ -450,4 +450,69 @@ abstract class AbstractContent implements Content { return $result; } + + /** + * Returns a ParserOutput object containing information derived from this content. + * Most importantly, unless $generateHtml was false, the return value contains an + * HTML representation of the content. + * + * Subclasses that want to control the parser output may override this, but it is + * preferred to override fillParserOutput() instead. + * + * Subclasses that override getParserOutput() itself should take care to call the + * ContentGetParserOutput hook. + * + * @since 1.24 + * + * @param Title $title Context title for parsing + * @param int|null $revId Revision ID (for {{REVISIONID}}) + * @param ParserOptions|null $options Parser options + * @param bool $generateHtml Whether or not to generate HTML + * + * @return ParserOutput Containing information derived from this content. + */ + public function getParserOutput( Title $title, $revId = null, + ParserOptions $options = null, $generateHtml = true + ) { + if ( $options === null ) { + $options = $this->getContentHandler()->makeParserOptions( 'canonical' ); + } + + $po = new ParserOutput(); + + if ( wfRunHooks( 'ContentGetParserOutput', + array( $this, $title, $revId, $options, $generateHtml, &$po ) ) ) { + + $this->fillParserOutput( $title, $revId, $options, $generateHtml, $po ); + } + + return $po; + } + + /** + * Fills the provided ParserOutput with information derived from the content. + * Unless $generateHtml was false, this includes an HTML representation of the content. + * + * This is called by getParserOutput() after consulting the ContentGetParserOutput hook. + * Subclasses are expected to override this method (or getParserOutput(), if need be). + * Subclasses of TextContent should generally override getHtml() instead. + * + * This placeholder implementation always throws an exception. + * + * @since 1.24 + * + * @param Title $title Context title for parsing + * @param int|null $revId Revision ID (for {{REVISIONID}}) + * @param ParserOptions|null $options Parser options + * @param bool $generateHtml Whether or not to generate HTML + * @param ParserOutput &$output The output object to fill (reference). + * + * @throws MWException + */ + protected function fillParserOutput( Title $title, $revId, + ParserOptions $options, $generateHtml, ParserOutput &$output + ) { + // Don't make abstract, so subclasses that override getParserOutput() directly don't fail. + throw new MWException( 'Subclasses of AbstractContent must override fillParserOutput!' ); + } } diff --git a/includes/content/TextContent.php b/includes/content/TextContent.php index 4c95d3c977..b772f176d3 100644 --- a/includes/content/TextContent.php +++ b/includes/content/TextContent.php @@ -201,30 +201,30 @@ class TextContent extends AbstractContent { } /** - * Returns a generic ParserOutput object, wrapping the HTML returned by - * getHtml(). + * Fills the provided ParserOutput object with information derived from the content. + * Unless $generateHtml was false, this includes an HTML representation of the content + * provided by getHtml(). + * + * For content models listed in $wgTextModelsToParse, this method will call the MediaWiki + * wikitext parser on the text to extract any (wikitext) links, magic words, etc. + * + * Subclasses may override this to provide custom content processing. + * For custom HTML generation alone, it is sufficient to override getHtml(). * * @param Title $title Context title for parsing * @param int $revId Revision ID (for {{REVISIONID}}) * @param ParserOptions $options Parser options * @param bool $generateHtml Whether or not to generate HTML - * - * @return ParserOutput Representing the HTML form of the text. + * @param ParserOutput $output The output object to fill (reference). */ - public function getParserOutput( Title $title, $revId = null, - ParserOptions $options = null, $generateHtml = true ) { + protected function fillParserOutput( Title $title, $revId, + ParserOptions $options, $generateHtml, ParserOutput &$output + ) { global $wgParser, $wgTextModelsToParse; - if ( !$options ) { - //NOTE: use canonical options per default to produce cacheable output - $options = $this->getContentHandler()->makeParserOptions( 'canonical' ); - } - if ( in_array( $this->getModel(), $wgTextModelsToParse ) ) { - // parse just to get links etc into the database - $po = $wgParser->parse( $this->getNativeData(), $title, $options, true, true, $revId ); - } else { - $po = new ParserOutput(); + // parse just to get links etc into the database, HTML is replaced below. + $output = $wgParser->parse( $this->getNativeData(), $title, $options, true, true, $revId ); } if ( $generateHtml ) { @@ -233,18 +233,16 @@ class TextContent extends AbstractContent { $html = ''; } - $po->setText( $html ); - - return $po; + $output->setText( $html ); } /** * Generates an HTML version of the content, for display. Used by - * getParserOutput() to construct a ParserOutput object. + * fillParserOutput() to provide HTML for the ParserOutput object. * * Subclasses may override this to provide a custom HTML rendering. * If further information is to be derived from the content (such as - * categories), the getParserOutput() method can be overridden instead. + * categories), the fillParserOutput() method can be overridden instead. * * For backwards-compatibility, this default implementation just calls * getHighlightHtml(). diff --git a/includes/content/WikitextContent.php b/includes/content/WikitextContent.php index dba0205920..ccea91655c 100644 --- a/includes/content/WikitextContent.php +++ b/includes/content/WikitextContent.php @@ -311,41 +311,33 @@ class WikitextContent extends TextContent { * Returns a ParserOutput object resulting from parsing the content's text * using $wgParser. * - * @since 1.21 - * * @param Title $title * @param int $revId Revision to pass to the parser (default: null) * @param ParserOptions $options (default: null) * @param bool $generateHtml (default: true) - * - * @return ParserOutput Representing the HTML form of the text + * @param &$output ParserOutput representing the HTML form of the text, + * may be manipulated or replaced. */ - public function getParserOutput( Title $title, $revId = null, - ParserOptions $options = null, $generateHtml = true ) { + protected function fillParserOutput( Title $title, $revId, + ParserOptions $options, $generateHtml, ParserOutput &$output + ) { global $wgParser; - if ( !$options ) { - //NOTE: use canonical options per default to produce cacheable output - $options = $this->getContentHandler()->makeParserOptions( 'canonical' ); - } - list( $redir, $text ) = $this->getRedirectTargetAndText(); - $po = $wgParser->parse( $text, $title, $options, true, true, $revId ); + $output = $wgParser->parse( $text, $title, $options, true, true, $revId ); // Add redirect indicator at the top if ( $redir ) { // Make sure to include the redirect link in pagelinks - $po->addLink( $redir ); + $output->addLink( $redir ); if ( $generateHtml ) { $chain = $this->getRedirectChain(); - $po->setText( + $output->setText( Article::getRedirectHeaderHtml( $title->getPageLanguage(), $chain, false ) . - $po->getText() + $output->getText() ); } } - - return $po; } /** diff --git a/maintenance/pageExists.php b/maintenance/pageExists.php new file mode 100644 index 0000000000..c4b208a59c --- /dev/null +++ b/maintenance/pageExists.php @@ -0,0 +1,54 @@ +mDescription = "Report whether a specific page exists"; + $this->addArg( 'title', 'Page title to check whether it exists' ); + } + + public function execute() { + $titleArg = $this->getArg(); + $title = Title::newFromText( $titleArg ); + $pageExists = $title && $title->exists(); + + $text = ''; + $code = 0; + if ( $pageExists ) { + $text = "{$title} exists."; + } else { + $text = "{$title} doesn't exist."; + $code = 1; + } + $this->output( $text ); + $this->error( '', $code ); + } +} + +$maintClass = "PageExists"; +require_once RUN_MAINTENANCE_IF_MAIN; + diff --git a/tests/phpunit/includes/content/ContentHandlerTest.php b/tests/phpunit/includes/content/ContentHandlerTest.php index ecfcfa3e80..2add9f23b6 100644 --- a/tests/phpunit/includes/content/ContentHandlerTest.php +++ b/tests/phpunit/includes/content/ContentHandlerTest.php @@ -491,4 +491,18 @@ class DummyContentForTesting extends AbstractContent { ) { return new ParserOutput( $this->getNativeData() ); } + + /** + * @see AbstractContent::fillParserOutput() + * + * @param Title $title Context title for parsing + * @param int|null $revId Revision ID (for {{REVISIONID}}) + * @param ParserOptions|null $options Parser options + * @param bool $generateHtml Whether or not to generate HTML + * @param ParserOutput &$output The output object to fill (reference). + */ + protected function fillParserOutput( Title $title, $revId, + ParserOptions $options, $generateHtml, ParserOutput &$output ) { + $output = new ParserOutput( $this->getNativeData() ); + } } diff --git a/tests/phpunit/includes/content/CssContentTest.php b/tests/phpunit/includes/content/CssContentTest.php index bd6d41fe6f..40484d3a0e 100644 --- a/tests/phpunit/includes/content/CssContentTest.php +++ b/tests/phpunit/includes/content/CssContentTest.php @@ -5,7 +5,7 @@ * @group Database * ^--- needed, because we do need the database to test link updates */ -class CssContentTest extends MediaWikiTestCase { +class CssContentTest extends JavaScriptContentTest { protected function setUp() { parent::setUp(); diff --git a/tests/phpunit/includes/content/TextContentTest.php b/tests/phpunit/includes/content/TextContentTest.php index 253a03542c..03cbbc0153 100644 --- a/tests/phpunit/includes/content/TextContentTest.php +++ b/tests/phpunit/includes/content/TextContentTest.php @@ -7,14 +7,21 @@ */ class TextContentTest extends MediaWikiLangTestCase { protected $context; + protected $savedContentGetParserOutput; protected function setUp() { + global $wgHooks; + parent::setUp(); // Anon user $user = new User(); $user->setName( '127.0.0.1' ); + $this->context = new RequestContext( new FauxRequest() ); + $this->context->setTitle( Title::newFromText( 'Test' ) ); + $this->context->setUser( $user ); + $this->setMwGlobals( array( 'wgUser' => $user, 'wgTextModelsToParse' => array( @@ -26,9 +33,22 @@ class TextContentTest extends MediaWikiLangTestCase { 'wgAlwaysUseTidy' => false, ) ); - $this->context = new RequestContext( new FauxRequest() ); - $this->context->setTitle( Title::newFromText( 'Test' ) ); - $this->context->setUser( $user ); + // bypass hooks that force custom rendering + if ( isset( $wgHooks['ContentGetParserOutput'] ) ) { + $this->savedContentGetParserOutput = $wgHooks['ContentGetParserOutput']; + unset( $wgHooks['ContentGetParserOutput'] ); + } + } + + public function teardown() { + global $wgHooks; + + // restore hooks that force custom rendering + if ( $this->savedContentGetParserOutput !== null ) { + $wgHooks['ContentGetParserOutput'] = $this->savedContentGetParserOutput; + } + + parent::teardown(); } public function newContent( $text ) {