22 'wgExtraNamespaces' => $wgExtraNamespaces,
23 'wgNamespaceContentModels' => $wgNamespaceContentModels,
33 $wgNamespaceContentModels[12312] =
"testing";
34 $wgNamespaceContentModels[12314] =
"testing-nontext";
39 MWNamespace::getCanonicalNamespaces(
true ); # reset
namespace cache
46 MWNamespace::getCanonicalNamespaces(
true ); # reset
namespace cache
51 $name =
'Help:ApiEditPageTest_testEdit';
54 $apiResult = $this->doApiRequestWithToken( [
57 'text' =>
'some text',
59 $apiResult = $apiResult[0];
62 $this->assertArrayHasKey(
'edit', $apiResult );
63 $this->assertArrayHasKey(
'result', $apiResult[
'edit'] );
64 $this->assertEquals(
'Success', $apiResult[
'edit'][
'result'] );
66 $this->assertArrayHasKey(
'new', $apiResult[
'edit'] );
67 $this->assertArrayNotHasKey(
'nochange', $apiResult[
'edit'] );
69 $this->assertArrayHasKey(
'pageid', $apiResult[
'edit'] );
72 $data = $this->doApiRequestWithToken( [
75 'text' =>
'some text',
78 $this->assertEquals(
'Success', $data[0][
'edit'][
'result'] );
80 $this->assertArrayNotHasKey(
'new', $data[0][
'edit'] );
81 $this->assertArrayHasKey(
'nochange', $data[0][
'edit'] );
84 $data = $this->doApiRequestWithToken( [
87 'text' =>
'different text'
90 $this->assertEquals(
'Success', $data[0][
'edit'][
'result'] );
92 $this->assertArrayNotHasKey(
'new', $data[0][
'edit'] );
93 $this->assertArrayNotHasKey(
'nochange', $data[0][
'edit'] );
95 $this->assertArrayHasKey(
'oldrevid', $data[0][
'edit'] );
96 $this->assertArrayHasKey(
'newrevid', $data[0][
'edit'] );
97 $this->assertNotEquals(
98 $data[0][
'edit'][
'newrevid'],
99 $data[0][
'edit'][
'oldrevid'],
100 "revision id should change after edit"
110 'foo',
'append',
'bar',
"foobar"
113 'foo',
'prepend',
'bar',
"barfoo"
115 [ # 2: append to empty page
116 '',
'append',
'foo',
"foo"
118 [ # 3: prepend to empty page
119 '',
'prepend',
'foo',
"foo"
121 [ # 4: append to non-existing page
122 null,
'append',
'foo',
"foo"
124 [ # 5: prepend to non-existing page
125 null,
'prepend',
'foo',
"foo"
138 $name =
"Help:ApiEditPageTest_testEditAppend_$count";
141 if ( $text !==
null ) {
145 'text' => $text, ] );
147 $this->assertEquals(
'Success', $re[
'edit'][
'result'] );
154 $op .
'text' => $append, ] );
156 $this->assertEquals(
'Success', $re[
'edit'][
'result'] );
159 $page =
new WikiPage( Title::newFromText( $name ) );
160 $content = $page->getContent();
161 $this->assertNotNull( $content,
'Page should have been created' );
163 $text = $content->getNativeData();
165 $this->assertEquals( $expected, $text );
172 $name =
'Help:ApiEditPageTest_testEditSection';
174 $text =
"==section 1==\ncontent 1\n==section 2==\ncontent2";
182 'text' =>
"==section 1==\nnew content 1",
184 $this->assertEquals(
'Success', $re[
'edit'][
'result'] );
188 $this->assertEquals(
"==section 1==\nnew content 1\n\n==section 2==\ncontent2", $newtext );
198 $this->fail(
"Should have raised an ApiUsageException" );
200 $this->assertTrue( self::apiExceptionHasCode(
$e,
'nosuchsection' ) );
211 $name =
'Help:ApiEditPageTest_testEditNewSection';
214 $this->assertFalse( Title::newFromText( $name )->exists() );
220 'summary' =>
'header',
223 $this->assertEquals(
'Success', $re[
'edit'][
'result'] );
228 $this->assertEquals(
"== header ==\n\ntest", $text );
231 $this->assertTrue( Title::newFromText( $name )->exists() );
237 'summary' =>
'header',
240 $this->assertEquals(
'Success', $re2[
'edit'][
'result'] );
244 $this->assertEquals(
"== header ==\n\ntest\n\n== header ==\n\ntest", $text );
255 $name =
"Help:ApiEditPageTest_testEdit_redirect_$count";
256 $title = Title::newFromText( $name );
259 $rname =
"Help:ApiEditPageTest_testEdit_redirect_r$count";
260 $rtitle = Title::newFromText( $rname );
265 "testing 1",
EDIT_NEW,
false, self::$users[
'sysop']->getUser() );
267 $baseTime = $page->getRevision()->getTimestamp();
271 "testing 1",
EDIT_NEW,
false, self::$users[
'sysop']->getUser() );
275 $rpage->doEditContent(
new WikitextContent(
"#REDIRECT [[$name]]\n\n[[Category:Test]]" ),
276 "testing 2",
EDIT_UPDATE, $page->getLatest(), self::$users[
'uploader']->getUser() );
283 'text' =>
'nix bar!',
284 'basetimestamp' => $baseTime,
287 ],
null, self::$users[
'sysop']->getUser() );
289 $this->assertEquals(
'Success', $re[
'edit'][
'result'],
290 "no problems expected when following redirect" );
301 $name =
"Help:ApiEditPageTest_testEdit_redirectText_$count";
302 $title = Title::newFromText( $name );
305 $rname =
"Help:ApiEditPageTest_testEdit_redirectText_r$count";
306 $rtitle = Title::newFromText( $rname );
311 "testing 1",
EDIT_NEW,
false, self::$users[
'sysop']->getUser() );
313 $baseTime = $page->getRevision()->getTimestamp();
317 "testing 1",
EDIT_NEW,
false, self::$users[
'sysop']->getUser() );
321 $rpage->doEditContent(
new WikitextContent(
"#REDIRECT [[$name]]\n\n[[Category:Test]]" ),
322 "testing 2",
EDIT_UPDATE, $page->getLatest(), self::$users[
'uploader']->getUser() );
330 'text' =>
'nix bar!',
331 'basetimestamp' => $baseTime,
333 ],
null, self::$users[
'sysop']->getUser() );
335 $this->fail(
'redirect-appendonly error expected' );
337 $this->assertTrue( self::apiExceptionHasCode( $ex,
'redirect-appendonly' ) );
346 $name =
"Help:ApiEditPageTest_testEditConflict_$count";
347 $title = Title::newFromText( $name );
353 "testing 1",
EDIT_NEW,
false, self::$users[
'sysop']->getUser() );
355 $baseTime = $page->getRevision()->getTimestamp();
359 "testing 2",
EDIT_UPDATE, $page->getLatest(), self::$users[
'uploader']->getUser() );
367 'text' =>
'nix bar!',
368 'basetimestamp' => $baseTime,
369 ],
null, self::$users[
'sysop']->getUser() );
371 $this->fail(
'edit conflict expected' );
373 $this->assertTrue( self::apiExceptionHasCode( $ex,
'editconflict' ) );
385 $name =
"Help:ApiEditPageTest_testEditConflict_newSection_$count";
386 $title = Title::newFromText( $name );
392 "testing 1",
EDIT_NEW,
false, self::$users[
'sysop']->getUser() );
394 $baseTime = $page->getRevision()->getTimestamp();
398 "testing 2",
EDIT_UPDATE, $page->getLatest(), self::$users[
'uploader']->getUser() );
405 'text' =>
'nix bar!',
406 'basetimestamp' => $baseTime,
408 ],
null, self::$users[
'sysop']->getUser() );
410 $this->assertEquals(
'Success', $re[
'edit'][
'result'],
411 "no edit conflict expected here" );
425 $name =
"Help:ApiEditPageTest_testEditConflict_redirect_bug41990_$count";
426 $title = Title::newFromText( $name );
429 $rname =
"Help:ApiEditPageTest_testEditConflict_redirect_bug41990_r$count";
430 $rtitle = Title::newFromText( $rname );
435 "testing 1",
EDIT_NEW,
false, self::$users[
'sysop']->getUser() );
440 "testing 1",
EDIT_NEW,
false, self::$users[
'sysop']->getUser() );
445 "testing 2",
EDIT_UPDATE, $page->getLatest(), self::$users[
'uploader']->getUser() );
452 'text' =>
'nix bar!',
455 ],
null, self::$users[
'sysop']->getUser() );
457 $this->assertEquals(
'Success', $re[
'edit'][
'result'],
458 "no edit conflict expected here" );
468 $dbw->update(
'revision',
469 [
'rev_timestamp' => $dbw->timestamp( $timestamp ) ],
476 $this->setExpectedException(
478 'Direct editing via API is not supported for content model ' .
479 'testing used by Dummy:ApiEditPageTest_nonTextPageEdit'
484 'title' =>
'Dummy:ApiEditPageTest_nonTextPageEdit',
485 'text' =>
'{"animals":["kittens!"]}'
490 $name =
'DummyNonText:ApiEditPageTest_testNonTextEdit';
491 $data =
serialize(
'some bla bla text' );
499 $apiResult = $result[0];
502 $this->assertArrayHasKey(
'edit', $apiResult );
503 $this->assertArrayHasKey(
'result', $apiResult[
'edit'] );
504 $this->assertEquals(
'Success', $apiResult[
'edit'][
'result'] );
506 $this->assertArrayHasKey(
'new', $apiResult[
'edit'] );
507 $this->assertArrayNotHasKey(
'nochange', $apiResult[
'edit'] );
509 $this->assertArrayHasKey(
'pageid', $apiResult[
'edit'] );
513 $this->assertEquals(
"testing-nontext", $page->getContentModel() );
514 $this->assertEquals( $data, $page->getContent()->serialize() );
523 $name =
'Help:' . __FUNCTION__;
524 $uploader = self::$users[
'uploader']->getUser();
525 $sysop = self::$users[
'sysop']->getUser();
529 'text' =>
'some text',
530 ],
null, $sysop )[0];
533 $this->assertArrayHasKey(
'edit', $apiResult );
534 $this->assertArrayHasKey(
'result', $apiResult[
'edit'] );
535 $this->assertEquals(
'Success', $apiResult[
'edit'][
'result'] );
536 $this->assertArrayHasKey(
'contentmodel', $apiResult[
'edit'] );
538 $this->assertEquals(
'wikitext', $apiResult[
'edit'][
'contentmodel'] );
545 'contentmodel' =>
'json',
546 ],
null, $uploader )[0];
549 $this->assertArrayHasKey(
'edit', $apiResult );
550 $this->assertArrayHasKey(
'result', $apiResult[
'edit'] );
551 $this->assertEquals(
'Success', $apiResult[
'edit'][
'result'] );
552 $this->assertArrayHasKey(
'contentmodel', $apiResult[
'edit'] );
553 $this->assertEquals(
'json', $apiResult[
'edit'][
'contentmodel'] );
558 'undo' => $apiResult[
'edit'][
'newrevid']
559 ],
null, $sysop )[0];
562 $this->assertArrayHasKey(
'edit', $apiResult );
563 $this->assertArrayHasKey(
'result', $apiResult[
'edit'] );
564 $this->assertEquals(
'Success', $apiResult[
'edit'][
'result'] );
565 $this->assertArrayHasKey(
'contentmodel', $apiResult[
'edit'] );
567 $this->assertEquals(
'wikitext', $apiResult[
'edit'][
'contentmodel'] );
$wgExtraNamespaces
Additional namespaces.
$wgNamespaceContentModels
Associative array mapping namespace IDs to the name of the content model pages in that namespace shou...
$wgContentHandlers
Plugins for page content model handling.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Tests for MediaWiki api.php?action=edit.
testEditSection()
Test editing of sections.
testEditConflict_bug41990()
testUndoAfterContentModelChange()
This test verifies that after changing the content model of a page, undoing that edit via the API wil...
testCheckDirectApiEditingDisallowed_forNonTextContent()
testEdit_redirectText()
Ensure we cannot edit through a redirect, if attempting to overwrite content.
testEditNewSection()
Test action=edit§ion=new Run it twice so we test adding a new section on a page that doesn't exis...
testEditConflict_newSection()
Ensure that editing using section=new will prevent simple conflicts.
testEdit_redirect()
Ensure we can edit through a redirect, if adding a section.
testEditAppend( $text, $op, $append, $expected)
provideEditAppend
testSupportsDirectApiEditing_withContentHandlerOverride()
forceRevisionDate(WikiPage $page, $timestamp)
static provideEditAppend()
doApiRequestWithToken(array $params, array $session=null, User $user=null)
Add an edit token to the API request This is cheating a bit – we grab a token in the correct format a...
doLogin( $testUser='sysop')
Exception used to abort API execution with an error.
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
Class representing a MediaWiki article and history.
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
getLatest()
Get the page_latest field.
Content object for wiki text pages.
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
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
when a variable name is used in a function
returning false will NOT prevent logging $e
you have access to all of the normal MediaWiki so you can get a DB use the cache