wiki.techinc.nl/tests/phpunit/includes/deferred/LinksUpdateTest.php

408 lines
10 KiB
PHP
Raw Normal View History

<?php
/**
* @group LinksUpdate
* @group Database
* ^--- make sure temporary tables are used.
*/
class LinksUpdateTest extends MediaWikiLangTestCase {
protected static $testingPageId;
function __construct( $name = null, array $data = [], $dataName = '' ) {
parent::__construct( $name, $data, $dataName );
$this->tablesUsed = array_merge( $this->tablesUsed,
[
'interwiki',
'page_props',
'pagelinks',
'categorylinks',
'langlinks',
'externallinks',
'imagelinks',
'templatelinks',
Enable users to watch category membership changes #2 This is part of a chain that reverts: e412ff5ecc900991cce4f99b7a069f625a5694b3. NOTE: - The feature is disabled by default - User settings default to hiding changes - T109707 Touching a file on wikisource adds and removes it from a category... Even when page has no changes.... WTF? See linked issue, marked as stalled with a possible way forward for this patch. @see https://gerrit.wikimedia.org/r/#/c/235467/ Changes since version 1: - T109604 - Page names in comment are no longer url encoded / have _'s - T109638 & T110338 - Reserved username now used when we can't determine a username for the change (we could perhaps set the user and id to be blank in the RC table, but who knows what this might do) - T109688 - History links are now disabled in RC.... (could be fine for the introduction and worked on more in the future) - Categorization changes are now always patrolled - Touching on T109672 in this change emails will never be sent regarding categorization changes. (this can of course be changed in a followup) - Added $wgRCWatchCategoryMembership defaulting to true for enabling / disabling the feature - T109700 - for cases when no revision was retrieved for a category change set the bot flag to true. This means all changes caused by parser functions & Lua will be marked as bot, as will changes that cant find their revision due to slave lag.. Bug: T9148 Bug: T109604 Bug: T109638 Bug: T109688 Bug: T109700 Bug: T110338 Bug: T110340 Change-Id: I51c2c1254de862f24a26ef9dbbf027c6c83e9063
2015-08-24 17:40:06 +00:00
'iwlinks',
'recentchanges',
]
);
}
Clean and repair many phpunit tests (+ fix implied configuration) This commit depends on the introduction of MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4. Various tests already set their globals, but forgot to restore them afterwards, or forgot to call the parent setUp, tearDown... Either way they won't have to anymore with setMwGlobals. Consistent use of function characteristics: * protected function setUp * protected function tearDown * public static function (provide..) (Matching the function signature with PHPUnit/Framework/TestCase.php) Replaces: * public function (setUp|tearDown)\( * protected function $1( * \tfunction (setUp|tearDown)\( * \tprotected function $1( * \tfunction (data|provide)\( * \tpublic static function $1\( Also renamed a few "data#", "provider#" and "provides#" functions to "provide#" for consistency. This also removes confusion where the /media tests had a few private methods called dataFile(), which were sometimes expected to be data providers. Fixes: TimestampTest often failed due to a previous test setting a different language (it tests "1 hour ago" so need to make sure it is set to English). MWNamespaceTest became a lot cleaner now that it executes with a known context. Though the now-redundant code that was removed didn't work anyway because wgContentNamespaces isn't keyed by namespace id, it had them was values... FileBackendTest: * Fixed: "PHP Fatal: Using $this when not in object context" HttpTest * Added comment about: "PHP Fatal: Call to protected MWHttpRequest::__construct()" (too much unrelated code to fix in this commit) ExternalStoreTest * Add an assertTrue as well, without it the test is useless because regardless of whether wgExternalStores is true or false it only uses it if it is an array. Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
2012-10-08 10:56:20 +00:00
protected function setUp() {
parent::setUp();
$dbw = wfGetDB( DB_MASTER );
$dbw->replace(
'interwiki',
[ 'iw_prefix' ],
[
'iw_prefix' => 'linksupdatetest',
'iw_url' => 'http://testing.com/wiki/$1',
'iw_api' => 'http://testing.com/w/api.php',
'iw_local' => 0,
'iw_trans' => 0,
'iw_wikiid' => 'linksupdatetest',
]
);
Enable users to watch category membership changes #2 This is part of a chain that reverts: e412ff5ecc900991cce4f99b7a069f625a5694b3. NOTE: - The feature is disabled by default - User settings default to hiding changes - T109707 Touching a file on wikisource adds and removes it from a category... Even when page has no changes.... WTF? See linked issue, marked as stalled with a possible way forward for this patch. @see https://gerrit.wikimedia.org/r/#/c/235467/ Changes since version 1: - T109604 - Page names in comment are no longer url encoded / have _'s - T109638 & T110338 - Reserved username now used when we can't determine a username for the change (we could perhaps set the user and id to be blank in the RC table, but who knows what this might do) - T109688 - History links are now disabled in RC.... (could be fine for the introduction and worked on more in the future) - Categorization changes are now always patrolled - Touching on T109672 in this change emails will never be sent regarding categorization changes. (this can of course be changed in a followup) - Added $wgRCWatchCategoryMembership defaulting to true for enabling / disabling the feature - T109700 - for cases when no revision was retrieved for a category change set the bot flag to true. This means all changes caused by parser functions & Lua will be marked as bot, as will changes that cant find their revision due to slave lag.. Bug: T9148 Bug: T109604 Bug: T109638 Bug: T109688 Bug: T109700 Bug: T110338 Bug: T110340 Change-Id: I51c2c1254de862f24a26ef9dbbf027c6c83e9063
2015-08-24 17:40:06 +00:00
$this->setMwGlobals( 'wgRCWatchCategoryMembership', true );
}
public function addDBDataOnce() {
$res = $this->insertPage( 'Testing' );
self::$testingPageId = $res['id'];
Enable users to watch category membership changes #2 This is part of a chain that reverts: e412ff5ecc900991cce4f99b7a069f625a5694b3. NOTE: - The feature is disabled by default - User settings default to hiding changes - T109707 Touching a file on wikisource adds and removes it from a category... Even when page has no changes.... WTF? See linked issue, marked as stalled with a possible way forward for this patch. @see https://gerrit.wikimedia.org/r/#/c/235467/ Changes since version 1: - T109604 - Page names in comment are no longer url encoded / have _'s - T109638 & T110338 - Reserved username now used when we can't determine a username for the change (we could perhaps set the user and id to be blank in the RC table, but who knows what this might do) - T109688 - History links are now disabled in RC.... (could be fine for the introduction and worked on more in the future) - Categorization changes are now always patrolled - Touching on T109672 in this change emails will never be sent regarding categorization changes. (this can of course be changed in a followup) - Added $wgRCWatchCategoryMembership defaulting to true for enabling / disabling the feature - T109700 - for cases when no revision was retrieved for a category change set the bot flag to true. This means all changes caused by parser functions & Lua will be marked as bot, as will changes that cant find their revision due to slave lag.. Bug: T9148 Bug: T109604 Bug: T109638 Bug: T109688 Bug: T109700 Bug: T110338 Bug: T110340 Change-Id: I51c2c1254de862f24a26ef9dbbf027c6c83e9063
2015-08-24 17:40:06 +00:00
$this->insertPage( 'Some_other_page' );
$this->insertPage( 'Template:TestingTemplate' );
}
protected function makeTitleAndParserOutput( $name, $id ) {
$t = Title::newFromText( $name );
$t->mArticleID = $id; # XXX: this is fugly
$po = new ParserOutput();
$po->setTitleText( $t->getPrefixedText() );
return [ $t, $po ];
}
/**
* @covers ParserOutput::addLink
*/
public function testUpdate_pagelinks() {
/** @var Title $t */
/** @var ParserOutput $po */
list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId );
$po->addLink( Title::newFromText( "Foo" ) );
$po->addLink( Title::newFromText( "Special:Foo" ) ); // special namespace should be ignored
$po->addLink( Title::newFromText( "linksupdatetest:Foo" ) ); // interwiki link should be ignored
$po->addLink( Title::newFromText( "#Foo" ) ); // hash link should be ignored
$update = $this->assertLinksUpdate(
$t,
$po,
'pagelinks',
'pl_namespace,
pl_title',
'pl_from = ' . self::$testingPageId,
[ [ NS_MAIN, 'Foo' ] ]
);
$this->assertArrayEquals( [
Title::makeTitle( NS_MAIN, 'Foo' ), // newFromText doesn't yield the same internal state....
], $update->getAddedLinks() );
$po = new ParserOutput();
$po->setTitleText( $t->getPrefixedText() );
$po->addLink( Title::newFromText( "Bar" ) );
$po->addLink( Title::newFromText( "Talk:Bar" ) );
$update = $this->assertLinksUpdate(
$t,
$po,
'pagelinks',
'pl_namespace,
pl_title',
'pl_from = ' . self::$testingPageId,
[
[ NS_MAIN, 'Bar' ],
[ NS_TALK, 'Bar' ],
]
);
$this->assertArrayEquals( [
Title::makeTitle( NS_MAIN, 'Bar' ),
Title::makeTitle( NS_TALK, 'Bar' ),
], $update->getAddedLinks() );
$this->assertArrayEquals( [
Title::makeTitle( NS_MAIN, 'Foo' ),
], $update->getRemovedLinks() );
}
/**
* @covers ParserOutput::addExternalLink
*/
public function testUpdate_externallinks() {
/** @var ParserOutput $po */
list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId );
$po->addExternalLink( "http://testing.com/wiki/Foo" );
$this->assertLinksUpdate(
$t,
$po,
'externallinks',
'el_to, el_index',
'el_from = ' . self::$testingPageId,
[
[ 'http://testing.com/wiki/Foo', 'http://com.testing./wiki/Foo' ],
]
);
}
/**
* @covers ParserOutput::addCategory
*/
public function testUpdate_categorylinks() {
/** @var ParserOutput $po */
$this->setMwGlobals( 'wgCategoryCollation', 'uppercase' );
list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId );
$po->addCategory( "Foo", "FOO" );
$this->assertLinksUpdate(
$t,
$po,
'categorylinks',
'cl_to, cl_sortkey',
'cl_from = ' . self::$testingPageId,
[ [ 'Foo', "FOO\nTESTING" ] ]
);
}
Enable users to watch category membership changes #2 This is part of a chain that reverts: e412ff5ecc900991cce4f99b7a069f625a5694b3. NOTE: - The feature is disabled by default - User settings default to hiding changes - T109707 Touching a file on wikisource adds and removes it from a category... Even when page has no changes.... WTF? See linked issue, marked as stalled with a possible way forward for this patch. @see https://gerrit.wikimedia.org/r/#/c/235467/ Changes since version 1: - T109604 - Page names in comment are no longer url encoded / have _'s - T109638 & T110338 - Reserved username now used when we can't determine a username for the change (we could perhaps set the user and id to be blank in the RC table, but who knows what this might do) - T109688 - History links are now disabled in RC.... (could be fine for the introduction and worked on more in the future) - Categorization changes are now always patrolled - Touching on T109672 in this change emails will never be sent regarding categorization changes. (this can of course be changed in a followup) - Added $wgRCWatchCategoryMembership defaulting to true for enabling / disabling the feature - T109700 - for cases when no revision was retrieved for a category change set the bot flag to true. This means all changes caused by parser functions & Lua will be marked as bot, as will changes that cant find their revision due to slave lag.. Bug: T9148 Bug: T109604 Bug: T109638 Bug: T109688 Bug: T109700 Bug: T110338 Bug: T110340 Change-Id: I51c2c1254de862f24a26ef9dbbf027c6c83e9063
2015-08-24 17:40:06 +00:00
public function testOnAddingAndRemovingCategory_recentChangesRowIsAdded() {
$this->setMwGlobals( 'wgCategoryCollation', 'uppercase' );
$title = Title::newFromText( 'Testing' );
$wikiPage = new WikiPage( $title );
$wikiPage->doEditContent( new WikitextContent( '[[Category:Foo]]' ), 'added category' );
$this->runAllRelatedJobs();
Enable users to watch category membership changes #2 This is part of a chain that reverts: e412ff5ecc900991cce4f99b7a069f625a5694b3. NOTE: - The feature is disabled by default - User settings default to hiding changes - T109707 Touching a file on wikisource adds and removes it from a category... Even when page has no changes.... WTF? See linked issue, marked as stalled with a possible way forward for this patch. @see https://gerrit.wikimedia.org/r/#/c/235467/ Changes since version 1: - T109604 - Page names in comment are no longer url encoded / have _'s - T109638 & T110338 - Reserved username now used when we can't determine a username for the change (we could perhaps set the user and id to be blank in the RC table, but who knows what this might do) - T109688 - History links are now disabled in RC.... (could be fine for the introduction and worked on more in the future) - Categorization changes are now always patrolled - Touching on T109672 in this change emails will never be sent regarding categorization changes. (this can of course be changed in a followup) - Added $wgRCWatchCategoryMembership defaulting to true for enabling / disabling the feature - T109700 - for cases when no revision was retrieved for a category change set the bot flag to true. This means all changes caused by parser functions & Lua will be marked as bot, as will changes that cant find their revision due to slave lag.. Bug: T9148 Bug: T109604 Bug: T109638 Bug: T109688 Bug: T109700 Bug: T110338 Bug: T110340 Change-Id: I51c2c1254de862f24a26ef9dbbf027c6c83e9063
2015-08-24 17:40:06 +00:00
$this->assertRecentChangeByCategorization(
$title,
$wikiPage->getParserOutput( new ParserOptions() ),
Title::newFromText( 'Category:Foo' ),
[ [ 'Foo', '[[:Testing]] added to category' ] ]
Enable users to watch category membership changes #2 This is part of a chain that reverts: e412ff5ecc900991cce4f99b7a069f625a5694b3. NOTE: - The feature is disabled by default - User settings default to hiding changes - T109707 Touching a file on wikisource adds and removes it from a category... Even when page has no changes.... WTF? See linked issue, marked as stalled with a possible way forward for this patch. @see https://gerrit.wikimedia.org/r/#/c/235467/ Changes since version 1: - T109604 - Page names in comment are no longer url encoded / have _'s - T109638 & T110338 - Reserved username now used when we can't determine a username for the change (we could perhaps set the user and id to be blank in the RC table, but who knows what this might do) - T109688 - History links are now disabled in RC.... (could be fine for the introduction and worked on more in the future) - Categorization changes are now always patrolled - Touching on T109672 in this change emails will never be sent regarding categorization changes. (this can of course be changed in a followup) - Added $wgRCWatchCategoryMembership defaulting to true for enabling / disabling the feature - T109700 - for cases when no revision was retrieved for a category change set the bot flag to true. This means all changes caused by parser functions & Lua will be marked as bot, as will changes that cant find their revision due to slave lag.. Bug: T9148 Bug: T109604 Bug: T109638 Bug: T109688 Bug: T109700 Bug: T110338 Bug: T110340 Change-Id: I51c2c1254de862f24a26ef9dbbf027c6c83e9063
2015-08-24 17:40:06 +00:00
);
$wikiPage->doEditContent( new WikitextContent( '[[Category:Bar]]' ), 'replaced category' );
$this->runAllRelatedJobs();
Enable users to watch category membership changes #2 This is part of a chain that reverts: e412ff5ecc900991cce4f99b7a069f625a5694b3. NOTE: - The feature is disabled by default - User settings default to hiding changes - T109707 Touching a file on wikisource adds and removes it from a category... Even when page has no changes.... WTF? See linked issue, marked as stalled with a possible way forward for this patch. @see https://gerrit.wikimedia.org/r/#/c/235467/ Changes since version 1: - T109604 - Page names in comment are no longer url encoded / have _'s - T109638 & T110338 - Reserved username now used when we can't determine a username for the change (we could perhaps set the user and id to be blank in the RC table, but who knows what this might do) - T109688 - History links are now disabled in RC.... (could be fine for the introduction and worked on more in the future) - Categorization changes are now always patrolled - Touching on T109672 in this change emails will never be sent regarding categorization changes. (this can of course be changed in a followup) - Added $wgRCWatchCategoryMembership defaulting to true for enabling / disabling the feature - T109700 - for cases when no revision was retrieved for a category change set the bot flag to true. This means all changes caused by parser functions & Lua will be marked as bot, as will changes that cant find their revision due to slave lag.. Bug: T9148 Bug: T109604 Bug: T109638 Bug: T109688 Bug: T109700 Bug: T110338 Bug: T110340 Change-Id: I51c2c1254de862f24a26ef9dbbf027c6c83e9063
2015-08-24 17:40:06 +00:00
$this->assertRecentChangeByCategorization(
$title,
$wikiPage->getParserOutput( new ParserOptions() ),
Title::newFromText( 'Category:Foo' ),
[
[ 'Foo', '[[:Testing]] added to category' ],
[ 'Foo', '[[:Testing]] removed from category' ],
]
Enable users to watch category membership changes #2 This is part of a chain that reverts: e412ff5ecc900991cce4f99b7a069f625a5694b3. NOTE: - The feature is disabled by default - User settings default to hiding changes - T109707 Touching a file on wikisource adds and removes it from a category... Even when page has no changes.... WTF? See linked issue, marked as stalled with a possible way forward for this patch. @see https://gerrit.wikimedia.org/r/#/c/235467/ Changes since version 1: - T109604 - Page names in comment are no longer url encoded / have _'s - T109638 & T110338 - Reserved username now used when we can't determine a username for the change (we could perhaps set the user and id to be blank in the RC table, but who knows what this might do) - T109688 - History links are now disabled in RC.... (could be fine for the introduction and worked on more in the future) - Categorization changes are now always patrolled - Touching on T109672 in this change emails will never be sent regarding categorization changes. (this can of course be changed in a followup) - Added $wgRCWatchCategoryMembership defaulting to true for enabling / disabling the feature - T109700 - for cases when no revision was retrieved for a category change set the bot flag to true. This means all changes caused by parser functions & Lua will be marked as bot, as will changes that cant find their revision due to slave lag.. Bug: T9148 Bug: T109604 Bug: T109638 Bug: T109688 Bug: T109700 Bug: T110338 Bug: T110340 Change-Id: I51c2c1254de862f24a26ef9dbbf027c6c83e9063
2015-08-24 17:40:06 +00:00
);
$this->assertRecentChangeByCategorization(
$title,
$wikiPage->getParserOutput( new ParserOptions() ),
Title::newFromText( 'Category:Bar' ),
[
[ 'Bar', '[[:Testing]] added to category' ],
]
Enable users to watch category membership changes #2 This is part of a chain that reverts: e412ff5ecc900991cce4f99b7a069f625a5694b3. NOTE: - The feature is disabled by default - User settings default to hiding changes - T109707 Touching a file on wikisource adds and removes it from a category... Even when page has no changes.... WTF? See linked issue, marked as stalled with a possible way forward for this patch. @see https://gerrit.wikimedia.org/r/#/c/235467/ Changes since version 1: - T109604 - Page names in comment are no longer url encoded / have _'s - T109638 & T110338 - Reserved username now used when we can't determine a username for the change (we could perhaps set the user and id to be blank in the RC table, but who knows what this might do) - T109688 - History links are now disabled in RC.... (could be fine for the introduction and worked on more in the future) - Categorization changes are now always patrolled - Touching on T109672 in this change emails will never be sent regarding categorization changes. (this can of course be changed in a followup) - Added $wgRCWatchCategoryMembership defaulting to true for enabling / disabling the feature - T109700 - for cases when no revision was retrieved for a category change set the bot flag to true. This means all changes caused by parser functions & Lua will be marked as bot, as will changes that cant find their revision due to slave lag.. Bug: T9148 Bug: T109604 Bug: T109638 Bug: T109688 Bug: T109700 Bug: T110338 Bug: T110340 Change-Id: I51c2c1254de862f24a26ef9dbbf027c6c83e9063
2015-08-24 17:40:06 +00:00
);
}
public function testOnAddingAndRemovingCategoryToTemplates_embeddingPagesAreIgnored() {
$this->setMwGlobals( 'wgCategoryCollation', 'uppercase' );
$templateTitle = Title::newFromText( 'Template:TestingTemplate' );
$templatePage = new WikiPage( $templateTitle );
$wikiPage = new WikiPage( Title::newFromText( 'Testing' ) );
$wikiPage->doEditContent( new WikitextContent( '{{TestingTemplate}}' ), 'added template' );
$this->runAllRelatedJobs();
Enable users to watch category membership changes #2 This is part of a chain that reverts: e412ff5ecc900991cce4f99b7a069f625a5694b3. NOTE: - The feature is disabled by default - User settings default to hiding changes - T109707 Touching a file on wikisource adds and removes it from a category... Even when page has no changes.... WTF? See linked issue, marked as stalled with a possible way forward for this patch. @see https://gerrit.wikimedia.org/r/#/c/235467/ Changes since version 1: - T109604 - Page names in comment are no longer url encoded / have _'s - T109638 & T110338 - Reserved username now used when we can't determine a username for the change (we could perhaps set the user and id to be blank in the RC table, but who knows what this might do) - T109688 - History links are now disabled in RC.... (could be fine for the introduction and worked on more in the future) - Categorization changes are now always patrolled - Touching on T109672 in this change emails will never be sent regarding categorization changes. (this can of course be changed in a followup) - Added $wgRCWatchCategoryMembership defaulting to true for enabling / disabling the feature - T109700 - for cases when no revision was retrieved for a category change set the bot flag to true. This means all changes caused by parser functions & Lua will be marked as bot, as will changes that cant find their revision due to slave lag.. Bug: T9148 Bug: T109604 Bug: T109638 Bug: T109688 Bug: T109700 Bug: T110338 Bug: T110340 Change-Id: I51c2c1254de862f24a26ef9dbbf027c6c83e9063
2015-08-24 17:40:06 +00:00
$otherWikiPage = new WikiPage( Title::newFromText( 'Some_other_page' ) );
$otherWikiPage->doEditContent( new WikitextContent( '{{TestingTemplate}}' ), 'added template' );
$this->runAllRelatedJobs();
$this->assertRecentChangeByCategorization(
$templateTitle,
$templatePage->getParserOutput( new ParserOptions() ),
Title::newFromText( 'Baz' ),
[]
);
$templatePage->doEditContent( new WikitextContent( '[[Category:Baz]]' ), 'added category' );
$this->runAllRelatedJobs();
Enable users to watch category membership changes #2 This is part of a chain that reverts: e412ff5ecc900991cce4f99b7a069f625a5694b3. NOTE: - The feature is disabled by default - User settings default to hiding changes - T109707 Touching a file on wikisource adds and removes it from a category... Even when page has no changes.... WTF? See linked issue, marked as stalled with a possible way forward for this patch. @see https://gerrit.wikimedia.org/r/#/c/235467/ Changes since version 1: - T109604 - Page names in comment are no longer url encoded / have _'s - T109638 & T110338 - Reserved username now used when we can't determine a username for the change (we could perhaps set the user and id to be blank in the RC table, but who knows what this might do) - T109688 - History links are now disabled in RC.... (could be fine for the introduction and worked on more in the future) - Categorization changes are now always patrolled - Touching on T109672 in this change emails will never be sent regarding categorization changes. (this can of course be changed in a followup) - Added $wgRCWatchCategoryMembership defaulting to true for enabling / disabling the feature - T109700 - for cases when no revision was retrieved for a category change set the bot flag to true. This means all changes caused by parser functions & Lua will be marked as bot, as will changes that cant find their revision due to slave lag.. Bug: T9148 Bug: T109604 Bug: T109638 Bug: T109688 Bug: T109700 Bug: T110338 Bug: T110340 Change-Id: I51c2c1254de862f24a26ef9dbbf027c6c83e9063
2015-08-24 17:40:06 +00:00
$this->assertRecentChangeByCategorization(
$templateTitle,
$templatePage->getParserOutput( new ParserOptions() ),
Title::newFromText( 'Baz' ),
[ [
'Baz',
'[[:Template:TestingTemplate]] and [[Special:WhatLinksHere/Template:TestingTemplate|2 pages]] '
. 'added to category'
] ]
Enable users to watch category membership changes #2 This is part of a chain that reverts: e412ff5ecc900991cce4f99b7a069f625a5694b3. NOTE: - The feature is disabled by default - User settings default to hiding changes - T109707 Touching a file on wikisource adds and removes it from a category... Even when page has no changes.... WTF? See linked issue, marked as stalled with a possible way forward for this patch. @see https://gerrit.wikimedia.org/r/#/c/235467/ Changes since version 1: - T109604 - Page names in comment are no longer url encoded / have _'s - T109638 & T110338 - Reserved username now used when we can't determine a username for the change (we could perhaps set the user and id to be blank in the RC table, but who knows what this might do) - T109688 - History links are now disabled in RC.... (could be fine for the introduction and worked on more in the future) - Categorization changes are now always patrolled - Touching on T109672 in this change emails will never be sent regarding categorization changes. (this can of course be changed in a followup) - Added $wgRCWatchCategoryMembership defaulting to true for enabling / disabling the feature - T109700 - for cases when no revision was retrieved for a category change set the bot flag to true. This means all changes caused by parser functions & Lua will be marked as bot, as will changes that cant find their revision due to slave lag.. Bug: T9148 Bug: T109604 Bug: T109638 Bug: T109688 Bug: T109700 Bug: T110338 Bug: T110340 Change-Id: I51c2c1254de862f24a26ef9dbbf027c6c83e9063
2015-08-24 17:40:06 +00:00
);
}
/**
* @covers ParserOutput::addInterwikiLink
*/
public function testUpdate_iwlinks() {
/** @var ParserOutput $po */
list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId );
$target = Title::makeTitleSafe( NS_MAIN, "Foo", '', 'linksupdatetest' );
$po->addInterwikiLink( $target );
$this->assertLinksUpdate(
$t,
$po,
'iwlinks',
'iwl_prefix, iwl_title',
'iwl_from = ' . self::$testingPageId,
[ [ 'linksupdatetest', 'Foo' ] ]
);
}
/**
* @covers ParserOutput::addTemplate
*/
public function testUpdate_templatelinks() {
/** @var ParserOutput $po */
list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId );
$po->addTemplate( Title::newFromText( "Template:Foo" ), 23, 42 );
$this->assertLinksUpdate(
$t,
$po,
'templatelinks',
'tl_namespace,
tl_title',
'tl_from = ' . self::$testingPageId,
[ [ NS_TEMPLATE, 'Foo' ] ]
);
}
/**
* @covers ParserOutput::addImage
*/
public function testUpdate_imagelinks() {
/** @var ParserOutput $po */
list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId );
$po->addImage( "Foo.png" );
$this->assertLinksUpdate(
$t,
$po,
'imagelinks',
'il_to',
'il_from = ' . self::$testingPageId,
[ [ 'Foo.png' ] ]
);
}
/**
* @covers ParserOutput::addLanguageLink
*/
public function testUpdate_langlinks() {
$this->setMwGlobals( [
'wgCapitalLinks' => true,
] );
/** @var ParserOutput $po */
list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId );
$po->addLanguageLink( Title::newFromText( "en:Foo" )->getFullText() );
$this->assertLinksUpdate(
$t,
$po,
'langlinks',
'll_lang, ll_title',
'll_from = ' . self::$testingPageId,
[ [ 'En', 'Foo' ] ]
);
}
/**
* @covers ParserOutput::setProperty
*/
public function testUpdate_page_props() {
global $wgPagePropsHaveSortkey;
/** @var ParserOutput $po */
list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId );
$fields = [ 'pp_propname', 'pp_value' ];
$expected = [];
$po->setProperty( "bool", true );
$expected[] = [ "bool", true ];
$po->setProperty( "float", 4.0 + 1.0 / 4.0 );
$expected[] = [ "float", 4.0 + 1.0 / 4.0 ];
$po->setProperty( "int", -7 );
$expected[] = [ "int", -7 ];
$po->setProperty( "string", "33 bar" );
$expected[] = [ "string", "33 bar" ];
// compute expected sortkey values
if ( $wgPagePropsHaveSortkey ) {
$fields[] = 'pp_sortkey';
foreach ( $expected as &$row ) {
$value = $row[1];
if ( is_int( $value ) || is_float( $value ) || is_bool( $value ) ) {
$row[] = floatval( $value );
} else {
$row[] = null;
}
}
}
$this->assertLinksUpdate(
$t, $po, 'page_props', $fields, 'pp_page = ' . self::$testingPageId, $expected );
}
public function testUpdate_page_props_without_sortkey() {
$this->setMwGlobals( 'wgPagePropsHaveSortkey', false );
$this->testUpdate_page_props();
}
// @todo test recursive, too!
protected function assertLinksUpdate( Title $title, ParserOutput $parserOutput,
$table, $fields, $condition, array $expectedRows
) {
$update = new LinksUpdate( $title, $parserOutput );
// NOTE: make sure LinksUpdate does not generate warnings when called inside a transaction.
$update->beginTransaction();
$update->doUpdate();
$update->commitTransaction();
$this->assertSelect( $table, $fields, $condition, $expectedRows );
return $update;
}
Enable users to watch category membership changes #2 This is part of a chain that reverts: e412ff5ecc900991cce4f99b7a069f625a5694b3. NOTE: - The feature is disabled by default - User settings default to hiding changes - T109707 Touching a file on wikisource adds and removes it from a category... Even when page has no changes.... WTF? See linked issue, marked as stalled with a possible way forward for this patch. @see https://gerrit.wikimedia.org/r/#/c/235467/ Changes since version 1: - T109604 - Page names in comment are no longer url encoded / have _'s - T109638 & T110338 - Reserved username now used when we can't determine a username for the change (we could perhaps set the user and id to be blank in the RC table, but who knows what this might do) - T109688 - History links are now disabled in RC.... (could be fine for the introduction and worked on more in the future) - Categorization changes are now always patrolled - Touching on T109672 in this change emails will never be sent regarding categorization changes. (this can of course be changed in a followup) - Added $wgRCWatchCategoryMembership defaulting to true for enabling / disabling the feature - T109700 - for cases when no revision was retrieved for a category change set the bot flag to true. This means all changes caused by parser functions & Lua will be marked as bot, as will changes that cant find their revision due to slave lag.. Bug: T9148 Bug: T109604 Bug: T109638 Bug: T109688 Bug: T109700 Bug: T110338 Bug: T110340 Change-Id: I51c2c1254de862f24a26ef9dbbf027c6c83e9063
2015-08-24 17:40:06 +00:00
protected function assertRecentChangeByCategorization(
Title $pageTitle, ParserOutput $parserOutput, Title $categoryTitle, $expectedRows
) {
$this->assertSelect(
'recentchanges',
'rc_title, rc_comment',
[
Enable users to watch category membership changes #2 This is part of a chain that reverts: e412ff5ecc900991cce4f99b7a069f625a5694b3. NOTE: - The feature is disabled by default - User settings default to hiding changes - T109707 Touching a file on wikisource adds and removes it from a category... Even when page has no changes.... WTF? See linked issue, marked as stalled with a possible way forward for this patch. @see https://gerrit.wikimedia.org/r/#/c/235467/ Changes since version 1: - T109604 - Page names in comment are no longer url encoded / have _'s - T109638 & T110338 - Reserved username now used when we can't determine a username for the change (we could perhaps set the user and id to be blank in the RC table, but who knows what this might do) - T109688 - History links are now disabled in RC.... (could be fine for the introduction and worked on more in the future) - Categorization changes are now always patrolled - Touching on T109672 in this change emails will never be sent regarding categorization changes. (this can of course be changed in a followup) - Added $wgRCWatchCategoryMembership defaulting to true for enabling / disabling the feature - T109700 - for cases when no revision was retrieved for a category change set the bot flag to true. This means all changes caused by parser functions & Lua will be marked as bot, as will changes that cant find their revision due to slave lag.. Bug: T9148 Bug: T109604 Bug: T109638 Bug: T109688 Bug: T109700 Bug: T110338 Bug: T110340 Change-Id: I51c2c1254de862f24a26ef9dbbf027c6c83e9063
2015-08-24 17:40:06 +00:00
'rc_type' => RC_CATEGORIZE,
'rc_namespace' => NS_CATEGORY,
'rc_title' => $categoryTitle->getDBkey()
],
Enable users to watch category membership changes #2 This is part of a chain that reverts: e412ff5ecc900991cce4f99b7a069f625a5694b3. NOTE: - The feature is disabled by default - User settings default to hiding changes - T109707 Touching a file on wikisource adds and removes it from a category... Even when page has no changes.... WTF? See linked issue, marked as stalled with a possible way forward for this patch. @see https://gerrit.wikimedia.org/r/#/c/235467/ Changes since version 1: - T109604 - Page names in comment are no longer url encoded / have _'s - T109638 & T110338 - Reserved username now used when we can't determine a username for the change (we could perhaps set the user and id to be blank in the RC table, but who knows what this might do) - T109688 - History links are now disabled in RC.... (could be fine for the introduction and worked on more in the future) - Categorization changes are now always patrolled - Touching on T109672 in this change emails will never be sent regarding categorization changes. (this can of course be changed in a followup) - Added $wgRCWatchCategoryMembership defaulting to true for enabling / disabling the feature - T109700 - for cases when no revision was retrieved for a category change set the bot flag to true. This means all changes caused by parser functions & Lua will be marked as bot, as will changes that cant find their revision due to slave lag.. Bug: T9148 Bug: T109604 Bug: T109638 Bug: T109688 Bug: T109700 Bug: T110338 Bug: T110340 Change-Id: I51c2c1254de862f24a26ef9dbbf027c6c83e9063
2015-08-24 17:40:06 +00:00
$expectedRows
);
}
private function runAllRelatedJobs() {
$queueGroup = JobQueueGroup::singleton();
while ( $job = $queueGroup->pop( 'refreshLinksPrioritized' ) ) {
$job->run();
$queueGroup->ack( $job );
}
while ( $job = $queueGroup->pop( 'categoryMembershipChange' ) ) {
$job->run();
$queueGroup->ack( $job );
}
}
}