mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 01:39:30 +02:00
Merge pull request #53 from paladox/patch-1
Replace PageContentSave with MultiContentSave
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user