MediaWiki REL1_28
ApiRevisionDeleteTest.php
Go to the documentation of this file.
1<?php
2
11
12 public static $page = 'Help:ApiRevDel_test';
13 public $revs = [];
14
15 protected function setUp() {
16 // Needs to be before setup since this gets cached
18 'wgGroupPermissions',
19 [ 'sysop' => [ 'deleterevision' => true ] ]
20 );
21 parent::setUp();
22 // Make a few edits for us to play with
23 for ( $i = 1; $i <= 5; $i++ ) {
24 self::editPage( self::$page, MWCryptRand::generateHex( 10 ), 'summary' );
25 $this->revs[] = Title::newFromText( self::$page )
26 ->getLatestRevID( Title::GAID_FOR_UPDATE );
27 }
28
29 }
30
31 public function testHidingRevisions() {
32 $user = self::$users['sysop']->getUser();
33 $revid = array_shift( $this->revs );
34 $out = $this->doApiRequest( [
35 'action' => 'revisiondelete',
36 'type' => 'revision',
37 'target' => self::$page,
38 'ids' => $revid,
39 'hide' => 'content|user|comment',
40 'token' => $user->getEditToken(),
41 ] );
42 // Check the output
43 $out = $out[0]['revisiondelete'];
44 $this->assertEquals( $out['status'], 'Success' );
45 $this->assertArrayHasKey( 'items', $out );
46 $item = $out['items'][0];
47 $this->assertArrayHasKey( 'userhidden', $item );
48 $this->assertArrayHasKey( 'commenthidden', $item );
49 $this->assertArrayHasKey( 'texthidden', $item );
50 $this->assertEquals( $item['id'], $revid );
51
52 // Now check that that revision was actually hidden
53 $rev = Revision::newFromId( $revid );
54 $this->assertEquals( $rev->getContent( Revision::FOR_PUBLIC ), null );
55 $this->assertEquals( $rev->getComment( Revision::FOR_PUBLIC ), '' );
56 $this->assertEquals( $rev->getUser( Revision::FOR_PUBLIC ), 0 );
57
58 // Now test unhiding!
59 $out2 = $this->doApiRequest( [
60 'action' => 'revisiondelete',
61 'type' => 'revision',
62 'target' => self::$page,
63 'ids' => $revid,
64 'show' => 'content|user|comment',
65 'token' => $user->getEditToken(),
66 ] );
67
68 // Check the output
69 $out2 = $out2[0]['revisiondelete'];
70 $this->assertEquals( $out2['status'], 'Success' );
71 $this->assertArrayHasKey( 'items', $out2 );
72 $item = $out2['items'][0];
73
74 $this->assertArrayNotHasKey( 'userhidden', $item );
75 $this->assertArrayNotHasKey( 'commenthidden', $item );
76 $this->assertArrayNotHasKey( 'texthidden', $item );
77
78 $this->assertEquals( $item['id'], $revid );
79
80 $rev = Revision::newFromId( $revid );
81 $this->assertNotEquals( $rev->getContent( Revision::FOR_PUBLIC ), null );
82 $this->assertNotEquals( $rev->getComment( Revision::FOR_PUBLIC ), '' );
83 $this->assertNotEquals( $rev->getUser( Revision::FOR_PUBLIC ), 0 );
84 }
85
86 public function testUnhidingOutput() {
87 $user = self::$users['sysop']->getUser();
88 $revid = array_shift( $this->revs );
89 // Hide revisions
90 $this->doApiRequest( [
91 'action' => 'revisiondelete',
92 'type' => 'revision',
93 'target' => self::$page,
94 'ids' => $revid,
95 'hide' => 'content|user|comment',
96 'token' => $user->getEditToken(),
97 ] );
98
99 $out = $this->doApiRequest( [
100 'action' => 'revisiondelete',
101 'type' => 'revision',
102 'target' => self::$page,
103 'ids' => $revid,
104 'show' => 'comment',
105 'token' => $user->getEditToken(),
106 ] );
107 $out = $out[0]['revisiondelete'];
108 $this->assertEquals( $out['status'], 'Success' );
109 $this->assertArrayHasKey( 'items', $out );
110 $item = $out['items'][0];
111 // Check it has userhidden & texthidden keys
112 // but no commenthidden key
113 $this->assertArrayHasKey( 'userhidden', $item );
114 $this->assertArrayNotHasKey( 'commenthidden', $item );
115 $this->assertArrayHasKey( 'texthidden', $item );
116 $this->assertEquals( $item['id'], $revid );
117 }
118}
Tests for action=revisiondelete APIRevisionDelete API medium Database.
editPage( $pageName, $text, $summary='', $defaultNs=NS_MAIN)
Edits or creates a page/revision.
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=null)
Does the API request and returns the result.
static generateHex( $chars, $forceStrong=false)
Generate a run of (ideally) cryptographically random data and return it in hexadecimal string format.
mergeMwGlobalArrayValue( $name, $values)
Merges the given values into a MW global array variable.
const FOR_PUBLIC
Definition Revision.php:92
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
Definition Revision.php:110
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition hooks.txt:249
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition hooks.txt:886
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:1734
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