Add new ArticleParserOptions hook
This hook allows discussion tools to toggle a parser option based on artice title (namespace) and user identity. In particular, it sets a flag to generates reply links (a) on talk pages (b) if the user's preferences opt in to discussion tools. Other extensions may also wish to be able to customize article parsing based on title or user. Change-Id: I883a37fd67108243e7a20683b1a5d59fd0f6e39f
This commit is contained in:
parent
c33d27fa7f
commit
8fe7e1d26a
4 changed files with 46 additions and 0 deletions
|
|
@ -71,6 +71,9 @@ For notes on 1.35.x and older releases, see HISTORY.
|
|||
unknown tags is numeric formatting; non-EXIF tags which are non-numeric
|
||||
should always use this method to specify the desired formatting.
|
||||
* The new 'title' type can be used to validate action API and REST API inputs.
|
||||
* The new ArticleParserOptions hook allows customizing the parser options
|
||||
used to parse wikitext for an article, based on user preferences, title,
|
||||
etc.
|
||||
* The new 'raw' type can be used to validate action API inputs. It bypasses
|
||||
the Unicode NFC normalization done on inputs of type 'string', so it more
|
||||
suitable when the input is binary or may contain deprecated Unicode
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@
|
|||
|
||||
namespace MediaWiki\HookContainer;
|
||||
|
||||
use Article;
|
||||
use Config;
|
||||
use IContextSource;
|
||||
use MediaWiki\Linker\LinkRenderer;
|
||||
use ParserOptions;
|
||||
use ResourceLoaderContext;
|
||||
use Skin;
|
||||
use SpecialPage;
|
||||
|
|
@ -434,6 +436,7 @@ class HookRunner implements
|
|||
\MediaWiki\Page\Hook\ArticleFromTitleHook,
|
||||
\MediaWiki\Page\Hook\ArticlePageDataAfterHook,
|
||||
\MediaWiki\Page\Hook\ArticlePageDataBeforeHook,
|
||||
\MediaWiki\Page\Hook\ArticleParserOptionsHook,
|
||||
\MediaWiki\Page\Hook\ArticleProtectCompleteHook,
|
||||
\MediaWiki\Page\Hook\ArticleProtectHook,
|
||||
\MediaWiki\Page\Hook\ArticlePurgeHook,
|
||||
|
|
@ -781,6 +784,13 @@ class HookRunner implements
|
|||
);
|
||||
}
|
||||
|
||||
public function onArticleParserOptions( Article $article, ParserOptions $popts ) {
|
||||
return $this->container->run(
|
||||
'ArticleParserOptions',
|
||||
[ $article, $popts ]
|
||||
);
|
||||
}
|
||||
|
||||
public function onArticlePrepareTextForEdit( $wikiPage, $popts ) {
|
||||
return $this->container->run(
|
||||
'ArticlePrepareTextForEdit',
|
||||
|
|
|
|||
|
|
@ -538,6 +538,8 @@ class Article implements Page {
|
|||
|
||||
$parserOptions = $this->getParserOptions();
|
||||
$poOptions = [];
|
||||
# Allow extensions to vary parser options used for article rendering
|
||||
Hooks::runner()->onArticleParserOptions( $this, $parserOptions );
|
||||
# Render printable version, use printable version cache
|
||||
if ( $outputPage->isPrintable() ) {
|
||||
$parserOptions->setIsPrintable( true );
|
||||
|
|
|
|||
31
includes/page/Hook/ArticleParserOptionsHook.php
Normal file
31
includes/page/Hook/ArticleParserOptionsHook.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Page\Hook;
|
||||
|
||||
use Article;
|
||||
use ParserOptions;
|
||||
|
||||
/**
|
||||
* This is a hook handler interface, see docs/Hooks.md.
|
||||
* Use the hook name "ArticleParserOptions" to register handlers implementing this interface.
|
||||
*
|
||||
* @stable to implement
|
||||
* @ingroup Hooks
|
||||
*/
|
||||
interface ArticleParserOptionsHook {
|
||||
/**
|
||||
* This hook is called before parsing wikitext for an article, and allows
|
||||
* setting particular parser options based on title, user preferences,
|
||||
* etc.
|
||||
*
|
||||
* @since 1.36
|
||||
*
|
||||
* @param Article $article Article about to be parsed
|
||||
* @param ParserOptions $popts Mutable parser options
|
||||
* @return bool|void True or no return value to continue or false to abort
|
||||
*/
|
||||
public function onArticleParserOptions(
|
||||
Article $article, ParserOptions $popts
|
||||
);
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue