MediaWiki REL1_30
PageArchiveTest.php
Go to the documentation of this file.
1<?php
2
18
23 private $ipEditor;
24
29 private $ipRevId;
30
31 function __construct( $name = null, array $data = [], $dataName = '' ) {
32 parent::__construct( $name, $data, $dataName );
33
34 $this->tablesUsed = array_merge(
35 $this->tablesUsed,
36 [
37 'page',
38 'revision',
39 'ip_changes',
40 'text',
41 'archive',
42 'recentchanges',
43 'logging',
44 'page_props',
45 ]
46 );
47 }
48
49 protected function setUp() {
50 parent::setUp();
51
52 // First create our dummy page
53 $page = Title::newFromText( 'PageArchiveTest_thePage' );
54 $page = new WikiPage( $page );
56 'testing',
57 $page->getTitle(),
59 );
60 $page->doEditContent( $content, 'testing', EDIT_NEW );
61
62 // Insert IP revision
63 $this->ipEditor = '2600:387:ed7:947e:8c16:a1ad:dd34:1dd7';
64 $rev = new Revision( [
65 'text' => 'Lorem Ipsum',
66 'comment' => 'just a test',
67 'page' => $page->getId(),
68 'user_text' => $this->ipEditor,
69 ] );
70 $dbw = wfGetDB( DB_MASTER );
71 $this->ipRevId = $rev->insertOn( $dbw );
72
73 // Delete the page
74 $page->doDeleteArticleReal( 'Just a test deletion' );
75
76 $this->archivedPage = new PageArchive( $page->getTitle() );
77 }
78
82 public function testUndeleteRevisions() {
83 // First make sure old revisions are archived
85 $res = $dbr->select( 'archive', '*', [ 'ar_rev_id' => $this->ipRevId ] );
86 $row = $res->fetchObject();
87 $this->assertEquals( $this->ipEditor, $row->ar_user_text );
88
89 // Should not be in revision
90 $res = $dbr->select( 'revision', '*', [ 'rev_id' => $this->ipRevId ] );
91 $this->assertFalse( $res->fetchObject() );
92
93 // Should not be in ip_changes
94 $res = $dbr->select( 'ip_changes', '*', [ 'ipc_rev_id' => $this->ipRevId ] );
95 $this->assertFalse( $res->fetchObject() );
96
97 // Restore the page
98 $this->archivedPage->undelete( [] );
99
100 // Should be back in revision
101 $res = $dbr->select( 'revision', '*', [ 'rev_id' => $this->ipRevId ] );
102 $row = $res->fetchObject();
103 $this->assertEquals( $this->ipEditor, $row->rev_user_text );
104
105 // Should be back in ip_changes
106 $res = $dbr->select( 'ip_changes', '*', [ 'ipc_rev_id' => $this->ipRevId ] );
107 $row = $res->fetchObject();
108 $this->assertEquals( IP::toHex( $this->ipEditor ), $row->ipc_hex );
109 }
110}
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
Test class for page archiving.
$ipEditor
A logged out user who edited the page before it was archived.
__construct( $name=null, array $data=[], $dataName='')
$ipRevId
Revision ID of the IP edit.
testUndeleteRevisions()
PageArchive::undelete.
Used to show archived pages and eventually restore them.
Class representing a MediaWiki article and history.
Definition WikiPage.php:37
$res
Definition database.txt:21
const CONTENT_MODEL_WIKITEXT
Definition Defines.php:236
const EDIT_NEW
Definition Defines.php:153
the array() calling protocol came about after MediaWiki 1.4rc1.
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:302
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition hooks.txt:1760
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:37
const DB_REPLICA
Definition defines.php:25
const DB_MASTER
Definition defines.php:26