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

12
NEWS.md
View File

@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
For changes prior to version 6.0.0, please see [`NEWS.old`](news.old). For changes prior to version 6.0.0, please see [`NEWS.old`](news.old).
## [7.1.0][] - 2021-03-21
### Changed
- The minimum required version of MediaWiki is now 1.35.
### Fixed
- Replace PageContentSave with MultiContentSave to fix compatibility with MediaWiki 1.35.
- The default value for wgLinkTitlesParseOnRender is change back to `false` as support
for MediaWiki 1.35+ is fixed.
## [7.0.0][] - 2020-12-23 ## [7.0.0][] - 2020-12-23
### Changed ### Changed

View File

@ -11,15 +11,15 @@
], ],
"type": "parserhook", "type": "parserhook",
"url": "https://www.mediawiki.org/wiki/Extension:LinkTitles", "url": "https://www.mediawiki.org/wiki/Extension:LinkTitles",
"version": "6.0.0", "version": "7.1.0",
"license-name": "GPL-2.0+", "license-name": "GPL-2.0+",
"descriptionmsg": "linktitles-desc", "descriptionmsg": "linktitles-desc",
"requires": { "requires": {
"MediaWiki": ">= 1.32.0" "MediaWiki": ">= 1.35.0"
}, },
"config": { "config": {
"LinkTitlesParseOnEdit": true, "LinkTitlesParseOnEdit": true,
"LinkTitlesParseOnRender": true, "LinkTitlesParseOnRender": false,
"LinkTitlesParseHeadings": false, "LinkTitlesParseHeadings": false,
"LinkTitlesSkipTemplates": true, "LinkTitlesSkipTemplates": true,
"LinkTitlesPreferShortTitles": true, "LinkTitlesPreferShortTitles": true,
@ -59,8 +59,8 @@
} }
}, },
"Hooks": { "Hooks": {
"PageContentSave": [ "MultiContentSave": [
"LinkTitles\\Extension::onPageContentSave" "LinkTitles\\Extension::onMultiContentSave"
], ],
"InternalParseBeforeLinks": [ "InternalParseBeforeLinks": [
"LinkTitles\\Extension::onInternalParseBeforeLinks" "LinkTitles\\Extension::onInternalParseBeforeLinks"

View File

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