Merge pull request #53 from paladox/patch-1

Replace PageContentSave with MultiContentSave
This commit is contained in:
Daniel Kraus
2021-04-06 20:26:47 +02:00
committed by GitHub
3 changed files with 44 additions and 8 deletions

View File

@ -21,8 +21,16 @@
*
* @author Daniel Kraus <bovender@bovender.de>
*/
namespace LinkTitles;
use CommentStoreComment;
use MediaWiki\Revision\RenderedRevision;
use MediaWiki\Revision\SlotRecord;
use Status;
use WikiPage;
use User;
/**
* Provides event handlers and entry points for the extension.
*/
@ -30,20 +38,36 @@ class Extension {
const URL = 'https://github.com/bovender/LinkTitles';
/**
* Event handler for the PageContentSave hook.
* Event handler for the MultiContentSave hook.
*
* This handler is used if the parseOnEdit configuration option is set.
*/
public static function onPageContentSave( &$wikiPage, &$user, &$content, &$summary,
$isMinor, $isWatch, $section, &$flags, &$status ) {
public static function onMultiContentSave(
RenderedRevision $renderedRevision,
User $user,
CommentStoreComment $summary,
$flags,
Status $hookStatus
) {
$isMinor = $flags & EDIT_MINOR;
$config = new Config();
if ( !$config->parseOnEdit || $isMinor ) return true;
$revision = $renderedRevision->getRevision();
$title = $revision->getPageAsLinkTarget();
$slots = $revision->getSlots();
$content = $slots->getContent( SlotRecord::MAIN );
$wikiPage = WikiPage::factory( $title );
$source = Source::createFromPageandContent( $wikiPage, $content, $config );
$linker = new Linker( $config );
$result = $linker->linkContent( $source );
if ( $result ) {
$content = $source->setText( $result );
$slots->setContent( 'main', $content );
}
return true;
}