MediaWiki  1.33.0
RefreshLinksPartitionTest.php
Go to the documentation of this file.
1 <?php
2 
9  public function __construct( $name = null, array $data = [], $dataName = '' ) {
10  parent::__construct( $name, $data, $dataName );
11 
12  $this->tablesUsed[] = 'page';
13  $this->tablesUsed[] = 'revision';
14  $this->tablesUsed[] = 'pagelinks';
15  }
16 
21  public function testRefreshLinks( $ns, $dbKey, $pages ) {
22  $title = Title::makeTitle( $ns, $dbKey );
23 
24  foreach ( $pages as $page ) {
25  list( $bns, $bdbkey ) = $page;
26  $bpage = WikiPage::factory( Title::makeTitle( $bns, $bdbkey ) );
27  $content = ContentHandler::makeContent( "[[{$title->getPrefixedText()}]]", $bpage->getTitle() );
28  $bpage->doEditContent( $content, "test" );
29  }
30 
31  $title->getBacklinkCache()->clear();
32  $this->assertEquals(
33  20,
34  $title->getBacklinkCache()->getNumLinks( 'pagelinks' ),
35  'Correct number of backlinks'
36  );
37 
38  $job = new RefreshLinksJob( $title, [ 'recursive' => true, 'table' => 'pagelinks' ]
39  + Job::newRootJobParams( "refreshlinks:pagelinks:{$title->getPrefixedText()}" ) );
40  $extraParams = $job->getRootJobParams();
41  $jobs = BacklinkJobUtils::partitionBacklinkJob( $job, 9, 1, [ 'params' => $extraParams ] );
42 
43  $this->assertEquals( 10, count( $jobs ), 'Correct number of sub-jobs' );
44  $this->assertEquals( $pages[0], current( $jobs[0]->params['pages'] ),
45  'First job is leaf job with proper title' );
46  $this->assertEquals( $pages[8], current( $jobs[8]->params['pages'] ),
47  'Last leaf job is leaf job with proper title' );
48  $this->assertEquals( true, isset( $jobs[9]->params['recursive'] ),
49  'Last job is recursive sub-job' );
50  $this->assertEquals( true, $jobs[9]->params['recursive'],
51  'Last job is recursive sub-job' );
52  $this->assertEquals( true, is_array( $jobs[9]->params['range'] ),
53  'Last job is recursive sub-job' );
54  $this->assertEquals( $title->getPrefixedText(), $jobs[0]->getTitle()->getPrefixedText(),
55  'Base job title retainend in leaf job' );
56  $this->assertEquals( $title->getPrefixedText(), $jobs[9]->getTitle()->getPrefixedText(),
57  'Base job title retainend recursive sub-job' );
58  $this->assertEquals( $extraParams['rootJobSignature'], $jobs[0]->params['rootJobSignature'],
59  'Leaf job has root params' );
60  $this->assertEquals( $extraParams['rootJobSignature'], $jobs[9]->params['rootJobSignature'],
61  'Recursive sub-job has root params' );
62 
64  $jobs[9],
65  9,
66  1,
67  [ 'params' => $extraParams ]
68  );
69 
70  $this->assertEquals( 10, count( $jobs2 ), 'Correct number of sub-jobs' );
71  $this->assertEquals( $pages[9], current( $jobs2[0]->params['pages'] ),
72  'First job is leaf job with proper title' );
73  $this->assertEquals( $pages[17], current( $jobs2[8]->params['pages'] ),
74  'Last leaf job is leaf job with proper title' );
75  $this->assertEquals( true, isset( $jobs2[9]->params['recursive'] ),
76  'Last job is recursive sub-job' );
77  $this->assertEquals( true, $jobs2[9]->params['recursive'],
78  'Last job is recursive sub-job' );
79  $this->assertEquals( true, is_array( $jobs2[9]->params['range'] ),
80  'Last job is recursive sub-job' );
81  $this->assertEquals( $extraParams['rootJobSignature'], $jobs2[0]->params['rootJobSignature'],
82  'Leaf job has root params' );
83  $this->assertEquals( $extraParams['rootJobSignature'], $jobs2[9]->params['rootJobSignature'],
84  'Recursive sub-job has root params' );
85 
87  $jobs2[9],
88  9,
89  1,
90  [ 'params' => $extraParams ]
91  );
92 
93  $this->assertEquals( 2, count( $jobs3 ), 'Correct number of sub-jobs' );
94  $this->assertEquals( $pages[18], current( $jobs3[0]->params['pages'] ),
95  'First job is leaf job with proper title' );
96  $this->assertEquals( $extraParams['rootJobSignature'], $jobs3[0]->params['rootJobSignature'],
97  'Leaf job has root params' );
98  $this->assertEquals( $pages[19], current( $jobs3[1]->params['pages'] ),
99  'Last job is leaf job with proper title' );
100  $this->assertEquals( $extraParams['rootJobSignature'], $jobs3[1]->params['rootJobSignature'],
101  'Last leaf job has root params' );
102  }
103 
104  public static function provider_backlinks() {
105  $pages = [];
106  for ( $i = 0; $i < 20; ++$i ) {
107  $pages[] = [ 0, "Page-$i" ];
108  }
109  return [
110  [ 10, 'Bang', $pages ]
111  ];
112  }
113 }
RefreshLinksPartitionTest
JobQueue medium Database.
Definition: RefreshLinksPartitionTest.php:8
captcha-old.count
count
Definition: captcha-old.py:249
RefreshLinksPartitionTest\provider_backlinks
static provider_backlinks()
Definition: RefreshLinksPartitionTest.php:104
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
BacklinkJobUtils\partitionBacklinkJob
static partitionBacklinkJob(Job $job, $bSize, $cSize, $opts=[])
Break down $job into approximately ($bSize/$cSize) leaf jobs and a single partition job that covers t...
Definition: BacklinkJobUtils.php:87
$data
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
Definition: generatePhpCharToUpperMappings.php:13
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:138
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
RefreshLinksPartitionTest\__construct
__construct( $name=null, array $data=[], $dataName='')
Definition: RefreshLinksPartitionTest.php:9
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:576
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
Job\newRootJobParams
static newRootJobParams( $key)
Get "root job" parameters for a task.
Definition: Job.php:311
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
ContentHandler\makeContent
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
Definition: ContentHandler.php:133
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
RefreshLinksJob
Job to update link tables for pages.
Definition: RefreshLinksJob.php:39
$job
if(count( $args)< 1) $job
Definition: recompressTracked.php:49
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
$content
$content
Definition: pageupdater.txt:72
RefreshLinksPartitionTest\testRefreshLinks
testRefreshLinks( $ns, $dbKey, $pages)
provider_backlinks BacklinkJobUtils::partitionBacklinkJob
Definition: RefreshLinksPartitionTest.php:21