Compare commits

..

6 Commits

Author SHA1 Message Date
b55f6ea5c1 Fixing for new MediaWiki Titles 2025-07-06 23:21:53 +02:00
9ec3c49f50 Fixing for new MediaWiki Titles 2025-07-06 23:20:44 +02:00
255a5ca9a8 Merge pull request #1 from hallowelt/main
Replace deprecated wfGetDB
2025-07-06 23:17:30 +02:00
05030e02ba more testing for new mediawiki titles 2025-07-06 22:49:16 +02:00
87de424161 Testing old and new title fix 2025-07-06 22:44:30 +02:00
hslater
e4432c18b2 Replace deprecated wfGetDB
Prevents
PHP Deprecated:  Use of wfGetDB was deprecated in MediaWiki 1.39
when running update.php

Compatible with MW 1.35.0
2025-03-05 20:07:45 +13:00
13 changed files with 29 additions and 42 deletions

View File

@@ -1,17 +1,16 @@
# This Dockerfile can be used to create a Docker image/container
# that runs the unit tests on the LinkTitles extension.
FROM mediawiki:1.44
FROM mediawiki:1.37
LABEL "MAINTAINER" Daniel Kraus (https://www.bovender.de)
RUN apt-get update -yqq && \
apt-get install -yqq \
php7.4-sqlite \
sqlite3 \
unzip \
zip
WORKDIR /var/www/html
ADD install-composer.sh install-composer.sh
RUN sed -i 's/\r$//' install-composer.sh
RUN chmod +x install-composer.sh
RUN ./install-composer.sh

View File

@@ -39,9 +39,6 @@
"LinkTitlesTargetNamespaces": [],
"LinkTitlesSameNamespace": true
},
"AutoloadNamespaces": {
"LinkTitles\\": "includes/"
},
"AutoloadClasses": {
"LinkTitles\\Extension": "includes/Extension.php",
"LinkTitles\\Linker": "includes/Linker.php",

View File

@@ -29,7 +29,6 @@ use CommentStoreComment;
use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\RenderedRevision;
use MediaWiki\Revision\SlotRecord;
use MediaWiki\Title\Title as MWTitle;
use Status;
use WikiPage;
use User;
@@ -65,7 +64,7 @@ class Extension {
// MW 1.36+
if ( method_exists( MediaWikiServices::class, 'getWikiPageFactory' ) ) {
$wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory();
$wikiPage = $wikiPageFactory->newFromLinkTarget( $title );
$wikiPage = $wikiPageFactory->newFromTitle( $title );
} else {
$wikiPage = WikiPage::factory( $title );
}
@@ -103,11 +102,11 @@ class Extension {
*
* Entry point for the SpecialLinkTitles class and the LinkTitlesJob class.
*
* @param MWTitle $title MWTitle object.
* @param \Title $title Title object.
* @param \RequestContext $context Current request context. If in doubt, call MediaWiki's `RequestContext::getMain()` to obtain such an object.
* @return bool True if the page exists, false if the page does not exist
*/
public static function processPage( MWTitle $title, \RequestContext $context ) {
public static function processPage( \Title $title, \RequestContext $context ) {
$config = new Config();
$source = Source::createFromTitle( $title, $config );
if ( $source->hasContent() ) {

View File

@@ -24,8 +24,6 @@
*/
namespace LinkTitles;
use MediaWiki\Title\Title as MWTitle;
/**
* Performs the actual linking of content to existing pages.
*/
@@ -63,12 +61,12 @@ class Linker {
/**
* Core function of the extension, performs the actual parsing of the content.
*
* This method receives a MWTitle object and the string representation of the
* This method receives a Title object and the string representation of the
* source page. It does not work on a WikiPage object directly because the
* callbacks in the Extension class do not always get a WikiPage object in the
* first place.
*
* @param MWTitle &$title MWTitle object for the current page.
* @param \Title &$title Title object for the current page.
* @param String $text String that holds the article content
* @return String|null Source page text with links to target pages, or null if no links were added
*/

View File

@@ -25,7 +25,6 @@
namespace LinkTitles;
use MediaWiki\MediaWikiServices;
use MediaWiki\Title\Title as MWTitle;
/**
* Represents a page that is a potential link target.
@@ -47,11 +46,11 @@ class Source {
private $content;
/**
* Creates a Source object from a Title.
* @param MWTitle $title MWTitle object from which to create the Source.
* Creates a Source object from a \Title.
* @param \Title $title Title object from which to create the Source.
* @return Source Source object created from the title.
*/
public static function createFromTitle( MWTitle $title, Config $config ) {
public static function createFromTitle( \Title $title, Config $config ) {
$source = new Source( $config );
$source->title = $title;
return $source;
@@ -63,12 +62,12 @@ class Source {
* This factory can be called e.g. from a onPageContentSave event handler
* which knows both these parameters.
*
* @param MWTitle $title MWTitle of the source page
* @param \Title $title Title of the source page
* @param String $text String representation of the page content
* @param Config $config LinkTitles configuration
* @return Source Source object created from the title and the text
*/
public static function createFromTitleAndText( MWTitle $title, $text, Config $config ) {
public static function createFromTitleAndText( \Title $title, $text, Config $config ) {
$source = Source::createFromTitle( $title, $config);
$source->text = $text;
return $source;
@@ -159,7 +158,7 @@ class Source {
/**
* Gets the title.
*
* @return MWTitle MWTitle of the source page.
* @return \Title Title of the source page.
*/
public function getTitle() {
if ( $this->title === null ) {
@@ -250,7 +249,7 @@ class Source {
/**
* Obtain a WikiPage object.
* Workaround for MediaWiki 1.36+ which deprecated Wikipage::factory.
* @param MWTitle $title
* @param \Title $title
* @return WikiPage object
*/
private static function getPageObject( $title ) {

View File

@@ -26,14 +26,13 @@ namespace LinkTitles;
use MediaWiki\MediaWikiServices;
use MediaWiki\Title\Title as MWTitle;
/**
* Represents a page that is a potential link target.
*/
class Target {
/**
* A MWTitle object for the target page currently being examined.
* @var MWTitle $title
* A Title object for the target page currently being examined.
* @var MediaWiki\Title\Title $title
*/
private $title;
@@ -253,7 +252,7 @@ class Target {
/**
* Obtain a page's content.
* Workaround for MediaWiki 1.36+ which deprecated Wikipage::factory.
* @param MWTitle $title
* @param \Title $title
* @return Content content object of the page
*/
private static function getPageContents( $title ) {

View File

@@ -24,7 +24,6 @@
*/
namespace LinkTitles;
use MediaWiki\Title\Title as MWTitle;
use MediaWiki\MediaWikiServices;
/**
@@ -44,7 +43,7 @@ class Targets {
* @param String $sourceNamespace The namespace of the current page.
* @param Config $config LinkTitles configuration.
*/
public static function singleton( MWTitle $title, Config $config ) {
public static function singleton( \MediaWiki\Title\Title $title, Config $config ) {
if ( ( self::$instance === null ) || ( self::$instance->sourceNamespace != $title->getNamespace() ) ) {
self::$instance = new Targets( $title, $config );
}
@@ -86,9 +85,9 @@ class Targets {
/**
* The constructor is private to enforce using the singleton pattern.
* @param MWTitle $title
* @param Mediawiki\Title\Title $title
*/
private function __construct( MWTitle $title, Config $config) {
private function __construct( \MediaWiki\Title\Title $title, Config $config) {
$this->config = $config;
$this->sourceNamespace = $title->getNamespace();
$this->fetch();

View File

@@ -16,7 +16,7 @@ then
fi
# May need to remove the explicit pinning of version 1 in the future
php composer-setup.php --quiet
php composer-setup.php --quiet --1
RESULT=$?
rm composer-setup.php
exit $RESULT

View File

@@ -23,8 +23,6 @@
*/
namespace LinkTitles;
use MediaWiki\Title\Title;
// Attempt to include the maintenance base class from:
// $wgScriptPath/maintenance/Maintenance.php
// Our script is normally located at:
@@ -145,7 +143,7 @@ class Cli extends \Maintenance {
private function singlePage() {
$pageName = strval( $this->getOption( 'page' ) );
$this->output( "Processing single page: '$pageName'\n" );
$title = Title::newFromText( $pageName );
$title = \Title::newFromText( $pageName );
$success = Extension::processPage( $title, \RequestContext::getMain() );
if ( $success ) {
$this->output( "Finished.\n" );
@@ -186,7 +184,7 @@ class Cli extends \Maintenance {
$numProcessed = 0;
foreach ( $res as $row ) {
$title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
$title = \Title::makeTitleSafe( $row->page_namespace, $row->page_title );
$numProcessed += 1;
$index += 1;
if ( $verbose ) {

View File

@@ -26,8 +26,8 @@
*
* @group bovender
*/
class SplitterTest extends LinkTitles\TestCase {
class SplitterTest extends \MediaWikiTestCase
{
/**
* @dataProvider provideSplitData
*/

View File

@@ -24,8 +24,8 @@
/**
* @group bovender
*/
class TargetTest extends LinkTitles\TestCase {
class TargetTest extends \MediaWikiTestCase
{
/**
* @dataProvider provideStartOnly

View File

@@ -36,7 +36,7 @@ class TargetsTest extends LinkTitles\TestCase {
// LinkTitlesLinkerTest::testLinkContentTargetNamespaces() is every changed,
// this test will fail.
$config->targetNamespaces = [ 4000 ];
$title = Title::newFromText( 'link target' );
$title = \Title::newFromText( 'link target' );
$targets = LinkTitles\Targets::singleton( $title, $config );
// Count number of articles: Inspired by updateArticleCount.php maintenance

View File

@@ -21,9 +21,8 @@
* @author Daniel Kraus <bovender@bovender.de>
*/
namespace LinkTitles;
use MediaWikiIntegrationTestCase;
abstract class TestCase extends MediaWikiIntegrationTestCase {
abstract class TestCase extends \MediaWikiTestCase {
protected function setUp(): void
{
parent::setUp();