diff --git a/.phpcs.xml b/.phpcs.xml
index 837e47b6..3073720d 100644
--- a/.phpcs.xml
+++ b/.phpcs.xml
@@ -4,7 +4,6 @@
-
.
diff --git a/extension.json b/extension.json
index 2e4ee55d..84a5ee94 100644
--- a/extension.json
+++ b/extension.json
@@ -9,7 +9,7 @@
"license-name": "GPL-2.0-or-later",
"type": "specialpage",
"requires": {
- "MediaWiki": ">= 1.31.0"
+ "MediaWiki": ">= 1.36.0"
},
"ExtensionMessagesFiles": {
"CiteThisPageAliases": "CiteThisPage.alias.php"
@@ -34,7 +34,14 @@
"remoteExtPath": "CiteThisPage/modules"
},
"SpecialPages": {
- "CiteThisPage": "MediaWiki\\Extension\\CiteThisPage\\SpecialCiteThisPage"
+ "CiteThisPage": {
+ "class": "MediaWiki\\Extension\\CiteThisPage\\SpecialCiteThisPage",
+ "services": [
+ "SearchEngineFactory",
+ "RevisionLookup",
+ "ParserFactory"
+ ]
+ }
},
"AutoloadNamespaces": {
"MediaWiki\\Extension\\CiteThisPage\\": "includes/"
diff --git a/includes/SpecialCiteThisPage.php b/includes/SpecialCiteThisPage.php
index d92dc429..7341d0fe 100644
--- a/includes/SpecialCiteThisPage.php
+++ b/includes/SpecialCiteThisPage.php
@@ -4,9 +4,11 @@ namespace MediaWiki\Extension\CiteThisPage;
use FormSpecialPage;
use HTMLForm;
-use MediaWiki\MediaWikiServices;
+use MediaWiki\Revision\RevisionLookup;
use Parser;
+use ParserFactory;
use ParserOptions;
+use SearchEngineFactory;
use Title;
class SpecialCiteThisPage extends FormSpecialPage {
@@ -21,8 +23,29 @@ class SpecialCiteThisPage extends FormSpecialPage {
*/
protected $title = false;
- public function __construct() {
+ /** @var SearchEngineFactory */
+ private $searchEngineFactory;
+
+ /** @var RevisionLookup */
+ private $revisionLookup;
+
+ /** @var ParserFactory */
+ private $parserFactory;
+
+ /**
+ * @param SearchEngineFactory $searchEngineFactory
+ * @param RevisionLookup $revisionLookup
+ * @param ParserFactory $parserFactory
+ */
+ public function __construct(
+ SearchEngineFactory $searchEngineFactory,
+ RevisionLookup $revisionLookup,
+ ParserFactory $parserFactory
+ ) {
parent::__construct( 'CiteThisPage' );
+ $this->searchEngineFactory = $searchEngineFactory;
+ $this->revisionLookup = $revisionLookup;
+ $this->parserFactory = $parserFactory;
}
/**
@@ -73,7 +96,7 @@ class SpecialCiteThisPage extends FormSpecialPage {
* @return string[] Matching subpages
*/
public function prefixSearchSubpages( $search, $limit, $offset ) {
- return $this->prefixSearchString( $search, $limit, $offset );
+ return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
}
protected function getGroupName() {
@@ -87,9 +110,7 @@ class SpecialCiteThisPage extends FormSpecialPage {
$out = $this->getOutput();
- $revTimestamp = MediaWikiServices::getInstance()
- ->getRevisionLookup()
- ->getTimestampFromId( $revId );
+ $revTimestamp = $this->revisionLookup->getTimestampFromId( $revId );
if ( !$revTimestamp ) {
$out->wrapWikiMsg( '
$1
',
@@ -101,13 +122,14 @@ class SpecialCiteThisPage extends FormSpecialPage {
// Set the overall timestamp to the revision's timestamp
$parserOptions->setTimestamp( $revTimestamp );
- $parser = $this->getParser();
+ $parser = $this->parserFactory->create();
// Register our tag which just parses using a different
// context
$parser->setHook( 'citation', [ $this, 'citationTag' ] );
+
// Also hold on to a separate Parser instance for tag parsing
// since we can't parse in a parse using the same Parser
- $this->citationParser = $this->getParser();
+ $this->citationParser = $this->parserFactory->create();
$ret = $parser->parse(
$this->getContentText(),
@@ -124,14 +146,6 @@ class SpecialCiteThisPage extends FormSpecialPage {
] );
}
- /**
- * @return Parser
- */
- private function getParser() {
- $parserFactory = MediaWikiServices::getInstance()->getParserFactory();
- return $parserFactory->create();
- }
-
/**
* Get the content to parse
*
@@ -144,10 +158,9 @@ class SpecialCiteThisPage extends FormSpecialPage {
# and the text moved into SpecialCite.i18n.php
# This code is kept for b/c in case an installation has its own file "citethispage-content-xx"
# for a previously not supported language.
- global $wgLanguageCode;
$dir = __DIR__ . '/../';
- $code = MediaWikiServices::getInstance()->getContentLanguage()
- ->lc( $wgLanguageCode );
+ $contentLang = $this->getContentLanguage();
+ $code = $contentLang->lc( $contentLang->getCode() );
if ( file_exists( "${dir}citethispage-content-$code" ) ) {
$msg = file_get_contents( "${dir}citethispage-content-$code" );
} elseif ( file_exists( "${dir}citethispage-content" ) ) {