20 'wgExtraNamespaces' => [
22 12313 =>
'Dummy_talk',
23 12314 =>
'DummyNonText',
24 12315 =>
'DummyNonText_talk',
26 'wgNamespaceContentModels' => [
28 12314 =>
'testing-nontext',
32 'testing' =>
'DummyContentHandlerForTesting',
33 'testing-nontext' =>
'DummyNonTextContentHandler',
34 'testing-serialize-error' =>
'DummySerializeErrorContentHandler',
38 [
'change_tag',
'change_tag_def',
'logging' ]
43 $name =
'Help:ApiEditPageTest_testEdit';
49 'text' =>
'some text',
51 $apiResult = $apiResult[0];
56 $this->
assertSame(
'Success', $apiResult[
'edit'][
'result'] );
67 'text' =>
'some text',
79 'text' =>
'different text'
90 $data[0][
'edit'][
'newrevid'],
91 $data[0][
'edit'][
'oldrevid'],
92 "revision id should change after edit"
102 'foo',
'append',
'bar',
"foobar"
105 'foo',
'prepend',
'bar',
"barfoo"
107 [ # 2: append to empty page
108 '',
'append',
'foo',
"foo"
110 [ # 3: prepend to empty page
111 '',
'prepend',
'foo',
"foo"
113 [ # 4: append to non-existing page
114 null,
'append',
'foo',
"foo"
116 [ # 5: prepend to non-existing page
117 null,
'prepend',
'foo',
"foo"
130 $name =
"Help:ApiEditPageTest_testEditAppend_$count";
133 if ( $text !==
null ) {
137 'text' => $text, ] );
139 $this->
assertSame(
'Success', $re[
'edit'][
'result'] );
146 $op .
'text' => $append, ] );
148 $this->
assertSame(
'Success', $re[
'edit'][
'result'] );
151 $page =
new WikiPage( Title::newFromText( $name ) );
164 $name =
'Help:ApiEditPageTest_testEditSection';
165 $page = WikiPage::factory( Title::newFromText( $name ) );
166 $text =
"==section 1==\ncontent 1\n==section 2==\ncontent2";
168 $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ),
'summary' );
174 'text' =>
"==section 1==\nnew content 1",
176 $this->
assertSame(
'Success', $re[
'edit'][
'result'] );
177 $newtext = WikiPage::factory( Title::newFromText( $name ) )
180 $this->
assertSame(
"==section 1==\nnew content 1\n\n==section 2==\ncontent2", $newtext );
190 $this->fail(
"Should have raised an ApiUsageException" );
192 $this->
assertTrue( self::apiExceptionHasCode(
$e,
'nosuchsection' ) );
203 $name =
'Help:ApiEditPageTest_testEditNewSection';
206 $this->
assertFalse( Title::newFromText( $name )->exists() );
212 'summary' =>
'header',
215 $this->
assertSame(
'Success', $re[
'edit'][
'result'] );
217 $text = WikiPage::factory( Title::newFromText( $name ) )
220 $this->
assertSame(
"== header ==\n\ntest", $text );
223 $this->
assertTrue( Title::newFromText( $name )->exists() );
229 'summary' =>
'header',
232 $this->
assertSame(
'Success', $re2[
'edit'][
'result'] );
233 $text = WikiPage::factory( Title::newFromText( $name ) )
236 $this->
assertSame(
"== header ==\n\ntest\n\n== header ==\n\ntest", $text );
247 $name =
"Help:ApiEditPageTest_testEdit_redirect_$count";
248 $title = Title::newFromText( $name );
249 $page = WikiPage::factory( $title );
251 $rname =
"Help:ApiEditPageTest_testEdit_redirect_r$count";
252 $rtitle = Title::newFromText( $rname );
253 $rpage = WikiPage::factory( $rtitle );
257 "testing 1",
EDIT_NEW,
false, self::$users[
'sysop']->getUser() );
259 $baseTime = $page->getRevision()->getTimestamp();
263 "testing 1",
EDIT_NEW,
false, self::$users[
'sysop']->getUser() );
267 $rpage->doEditContent(
new WikitextContent(
"#REDIRECT [[$name]]\n\n[[Category:Test]]" ),
268 "testing 2",
EDIT_UPDATE, $page->getLatest(), self::$users[
'uploader']->getUser() );
275 'text' =>
'nix bar!',
276 'basetimestamp' => $baseTime,
281 $this->
assertSame(
'Success', $re[
'edit'][
'result'],
282 "no problems expected when following redirect" );
293 $name =
"Help:ApiEditPageTest_testEdit_redirectText_$count";
294 $title = Title::newFromText( $name );
295 $page = WikiPage::factory( $title );
297 $rname =
"Help:ApiEditPageTest_testEdit_redirectText_r$count";
298 $rtitle = Title::newFromText( $rname );
299 $rpage = WikiPage::factory( $rtitle );
303 "testing 1",
EDIT_NEW,
false, self::$users[
'sysop']->getUser() );
305 $baseTime = $page->getRevision()->getTimestamp();
309 "testing 1",
EDIT_NEW,
false, self::$users[
'sysop']->getUser() );
313 $rpage->doEditContent(
new WikitextContent(
"#REDIRECT [[$name]]\n\n[[Category:Test]]" ),
314 "testing 2",
EDIT_UPDATE, $page->getLatest(), self::$users[
'uploader']->getUser() );
322 'text' =>
'nix bar!',
323 'basetimestamp' => $baseTime,
327 $this->fail(
'redirect-appendonly error expected' );
329 $this->
assertTrue( self::apiExceptionHasCode( $ex,
'redirect-appendonly' ) );
338 $name =
"Help:ApiEditPageTest_testEditConflict_$count";
339 $title = Title::newFromText( $name );
341 $page = WikiPage::factory( $title );
345 "testing 1",
EDIT_NEW,
false, self::$users[
'sysop']->getUser() );
347 $baseTime = $page->getRevision()->getTimestamp();
351 "testing 2",
EDIT_UPDATE, $page->getLatest(), self::$users[
'uploader']->getUser() );
359 'text' =>
'nix bar!',
360 'basetimestamp' => $baseTime,
363 $this->fail(
'edit conflict expected' );
365 $this->
assertTrue( self::apiExceptionHasCode( $ex,
'editconflict' ) );
377 $name =
"Help:ApiEditPageTest_testEditConflict_newSection_$count";
378 $title = Title::newFromText( $name );
380 $page = WikiPage::factory( $title );
384 "testing 1",
EDIT_NEW,
false, self::$users[
'sysop']->getUser() );
386 $baseTime = $page->getRevision()->getTimestamp();
390 "testing 2",
EDIT_UPDATE, $page->getLatest(), self::$users[
'uploader']->getUser() );
397 'text' =>
'nix bar!',
398 'basetimestamp' => $baseTime,
402 $this->
assertSame(
'Success', $re[
'edit'][
'result'],
403 "no edit conflict expected here" );
417 $name =
"Help:ApiEditPageTest_testEditConflict_redirect_T43990_$count";
418 $title = Title::newFromText( $name );
419 $page = WikiPage::factory( $title );
421 $rname =
"Help:ApiEditPageTest_testEditConflict_redirect_T43990_r$count";
422 $rtitle = Title::newFromText( $rname );
423 $rpage = WikiPage::factory( $rtitle );
427 "testing 1",
EDIT_NEW,
false, self::$users[
'sysop']->getUser() );
432 "testing 1",
EDIT_NEW,
false, self::$users[
'sysop']->getUser() );
437 "testing 2",
EDIT_UPDATE, $page->getLatest(), self::$users[
'uploader']->getUser() );
444 'text' =>
'nix bar!',
449 $this->
assertSame(
'Success', $re[
'edit'][
'result'],
450 "no edit conflict expected here" );
460 $dbw->update(
'revision',
461 [
'rev_timestamp' => $dbw->timestamp( $timestamp ) ],
462 [
'rev_id' => $page->getLatest() ] );
469 ApiUsageException::class,
470 'Direct editing via API is not supported for content model ' .
471 'testing used by Dummy:ApiEditPageTest_nonTextPageEdit'
476 'title' =>
'Dummy:ApiEditPageTest_nonTextPageEdit',
477 'text' =>
'{"animals":["kittens!"]}'
482 $name =
'DummyNonText:ApiEditPageTest_testNonTextEdit';
491 $apiResult = $result[0];
496 $this->
assertSame(
'Success', $apiResult[
'edit'][
'result'] );
504 $page = WikiPage::factory( Title::newFromText( $name ) );
505 $this->
assertSame(
"testing-nontext", $page->getContentModel() );
516 $uploader = self::$users[
'uploader']->getUser();
517 $sysop = self::$users[
'sysop']->getUser();
522 'text' =>
'some text',
523 ],
null, $sysop )[0];
528 $this->
assertSame(
'Success', $apiResult[
'edit'][
'result'] );
531 $this->
assertSame(
'wikitext', $apiResult[
'edit'][
'contentmodel'] );
538 'contentmodel' =>
'json',
539 ],
null, $uploader )[0];
544 $this->
assertSame(
'Success', $apiResult[
'edit'][
'result'] );
546 $this->
assertSame(
'json', $apiResult[
'edit'][
'contentmodel'] );
551 'undo' => $apiResult[
'edit'][
'newrevid']
552 ],
null, $sysop )[0];
557 $this->
assertSame(
'Success', $apiResult[
'edit'][
'result'] );
560 $this->
assertSame(
'wikitext', $apiResult[
'edit'][
'contentmodel'] );
567 $name =
'Help:' . ucfirst( __FUNCTION__ );
572 'text' =>
'some text',
573 'contentmodel' =>
'wikitext',
574 'contentformat' =>
'text/x-wiki',
577 $this->
assertTrue( Title::newFromText( $name )->exists() );
581 $name =
'Help:' . ucfirst( __FUNCTION__ );
584 'Unrecognized value for parameter "contentformat": nonexistent format.' );
590 'text' =>
'some text',
591 'contentformat' =>
'nonexistent format',
594 $this->
assertFalse( Title::newFromText( $name )->exists() );
599 $name =
'Help:' . ucfirst( __FUNCTION__ );
602 'The requested format text/plain is not supported for content ' .
603 "model wikitext used by $name." );
609 'text' =>
'some text',
610 'contentmodel' =>
'wikitext',
611 'contentformat' =>
'text/plain',
614 $this->
assertFalse( Title::newFromText( $name )->exists() );
619 $name =
'Help:' . ucfirst( __FUNCTION__ );
621 $revId = $this->
editPage( $name,
'Some text' )->value[
'revision']
626 "There is no revision with ID $revId." );
649 $name =
'Help:' . ucfirst( __FUNCTION__ );
650 $titleObj = Title::newFromText( $name );
652 $revId1 = $this->
editPage( $name,
'1' )->value[
'revision']->getId();
653 $revId2 = $this->
editPage( $name,
'2' )->value[
'revision']->getId();
654 $revId3 = $this->
editPage( $name,
'3' )->value[
'revision']->getId();
658 $dbw->delete(
'revision', [
'rev_id' => $revId2 ], __METHOD__ );
659 $dbw->update(
'revision', [
'rev_parent_id' => $revId1 ],
660 [
'rev_id' => $revId3 ], __METHOD__ );
663 "There is no revision with ID $revId2." );
669 'undoafter' => $revId2,
678 $name =
'Help:' . ucfirst( __FUNCTION__ );
679 $titleObj = Title::newFromText( $name );
683 $revId1 = $this->
editPage( $name,
'1' )->value[
'revision']->getId();
685 $revId2 = $this->
editPage( $name,
'2' )->value[
'revision']->getId();
689 RequestContext::getMain(), $titleObj, [ $revId1 ] );
690 $list->setVisibility( [
692 'comment' =>
'Bye-bye',
696 "There is no revision with ID $revId1." );
702 'undoafter' => $revId1,
711 $name =
'Help:' . ucfirst( __FUNCTION__ );
712 $titleObj = Title::newFromText( $name );
716 $revId2 = $this->
editPage( $name,
'2' )->value[
'revision']->getId();
718 $revId1 = $this->
editPage( $name,
'1' )->value[
'revision']->getId();
724 [
'rev_timestamp' => $dbw->timestamp( time() - 86400 ) ],
725 [
'rev_id' => $revId1 ],
733 'undoafter' => $revId1,
736 $text = (
new WikiPage( $titleObj ) )->getContent()->getText();
746 $name =
'Help:' . ucfirst( __FUNCTION__ );
749 'The edit could not be undone due to conflicting intermediate edits.' );
753 $revId = $this->
editPage( $name,
'2' )->value[
'revision']->getId();
763 $text = (
new WikiPage( Title::newFromText( $name ) ) )->getContent()
773 $name =
'Help:' . ucfirst( __FUNCTION__ );
776 $revId1 = $this->
editPage( $name,
'1' )->value[
'revision']->getId();
777 $revId2 = $this->
editPage( $name,
'2' )->value[
'revision']->getId();
783 'undoafter' => $revId2,
786 $text = (
new WikiPage( Title::newFromText( $name ) ) )->getContent()
792 $name =
'Help:' . ucfirst( __FUNCTION__ );
794 $this->
editPage(
"$name-1",
'Some text' );
795 $revId = $this->
editPage(
"$name-1",
'Some more text' )
796 ->value[
'revision']->getId();
798 $this->
editPage(
"$name-2",
'Some text' );
801 "r$revId is not a revision of $name-2." );
805 'title' =>
"$name-2",
811 $name =
'Help:' . ucfirst( __FUNCTION__ );
813 $revId1 = $this->
editPage(
"$name-1",
'Some text' )
814 ->value[
'revision']->getId();
816 $revId2 = $this->
editPage(
"$name-2",
'Some text' )
817 ->value[
'revision']->getId();
820 "r$revId1 is not a revision of $name-2." );
824 'title' =>
"$name-2",
826 'undoafter' => $revId1,
831 $name =
'Help:' . ucfirst( __FUNCTION__ );
833 $this->
assertFalse( Title::newFromText( $name )->exists() );
838 'text' =>
'Some text',
839 'md5' =>
md5(
'Some text' ),
842 $this->
assertTrue( Title::newFromText( $name )->exists() );
846 $name =
'Help:' . ucfirst( __FUNCTION__ );
848 $this->
editPage( $name,
'Some text' );
853 'prependtext' =>
'Alert: ',
854 'md5' =>
md5(
'Alert: ' ),
857 $text = (
new WikiPage( Title::newFromText( $name ) ) )
858 ->getContent()->getText();
859 $this->
assertSame(
'Alert: Some text', $text );
863 $name =
'Help:' . ucfirst( __FUNCTION__ );
865 $this->
editPage( $name,
'Some text' );
870 'appendtext' =>
' is nice',
871 'md5' =>
md5(
' is nice' ),
874 $text = (
new WikiPage( Title::newFromText( $name ) ) )
875 ->getContent()->getText();
876 $this->
assertSame(
'Some text is nice', $text );
880 $name =
'Help:' . ucfirst( __FUNCTION__ );
882 $this->
editPage( $name,
'Some text' );
887 'prependtext' =>
'Alert: ',
888 'appendtext' =>
' is nice',
889 'md5' =>
md5(
'Alert: is nice' ),
892 $text = (
new WikiPage( Title::newFromText( $name ) ) )
893 ->getContent()->getText();
894 $this->
assertSame(
'Alert: Some text is nice', $text );
898 $name =
'Help:' . ucfirst( __FUNCTION__ );
901 'The supplied MD5 hash was incorrect.' );
906 'text' =>
'Some text',
912 $name =
'Help:' . ucfirst( __FUNCTION__ );
915 'The supplied MD5 hash was incorrect.' );
920 'prependtext' =>
'Some ',
921 'appendtext' =>
'text',
922 'md5' =>
md5(
'Some ' ),
927 $name =
'Help:' . ucfirst( __FUNCTION__ );
930 'The supplied MD5 hash was incorrect.' );
935 'prependtext' =>
'Some ',
936 'appendtext' =>
'text',
937 'md5' =>
md5(
'text' ),
942 $name =
'Help:' . ucfirst( __FUNCTION__ );
945 'The article you tried to create has been created already.' );
947 $this->
editPage( $name,
'Some text' );
948 $this->
assertTrue( Title::newFromText( $name )->exists() );
954 'text' =>
'Some more text',
959 $text = (
new WikiPage( Title::newFromText( $name ) ) )
960 ->getContent()->getText();
967 $name =
'Help:' . ucfirst( __FUNCTION__ );
970 "The page you specified doesn't exist." );
972 $this->
assertFalse( Title::newFromText( $name )->exists() );
978 'text' =>
'Some text',
982 $this->
assertFalse( Title::newFromText( $name )->exists() );
992 $name =
'MediaWiki:' . ucfirst( __FUNCTION__ );
995 "Can't append to pages using content model testing-nontext." );
998 function (
Title $title, &$model ) use ( $name ) {
999 if ( $title->getPrefixedText() === $name ) {
1000 $model =
'testing-nontext';
1009 'appendtext' =>
'Some text',
1014 $name =
'MediaWiki:' . ucfirst( __FUNCTION__ );
1016 $this->
assertFalse( Title::newFromText( $name )->exists() );
1021 'appendtext' =>
'Some text',
1024 $this->
assertTrue( Title::newFromText( $name )->exists() );
1028 $name =
'MediaWiki:' . ucfirst( __FUNCTION__ );
1031 'Content serialization failed: Could not unserialize content' );
1034 function (
Title $title, &$model ) use ( $name ) {
1035 if ( $title->getPrefixedText() === $name ) {
1036 $model =
'testing-serialize-error';
1045 'appendtext' =>
'Some text',
1050 $name =
'Help:' . ucfirst( __FUNCTION__ );
1052 $this->
editPage( $name,
'Initial content' );
1057 'appendtext' =>
'== New section ==',
1061 $text = (
new WikiPage( Title::newFromText( $name ) ) )
1062 ->getContent()->getText();
1064 $this->
assertSame(
"Initial content\n\n== New section ==", $text );
1068 $name =
'Help:' . ucfirst( __FUNCTION__ );
1071 'Sections are not supported for content model text.' );
1073 $this->
editPage( $name,
'Initial content' );
1078 'appendtext' =>
'== New section ==',
1080 'contentmodel' =>
'text',
1085 $name =
'Help:' . ucfirst( __FUNCTION__ );
1087 $this->
editPage( $name,
'Initial content' );
1092 'sectiontitle' =>
'My section',
1093 'appendtext' =>
'More content',
1097 $page =
new WikiPage( Title::newFromText( $name ) );
1099 $this->
assertSame(
"Initial content\n\n== My section ==\n\nMore content",
1100 $page->getContent()->getText() );
1101 $this->
assertSame(
'/* My section */ new section',
1102 $page->getRevision()->getComment() );
1106 $name =
'Help:' . ucfirst( __FUNCTION__ );
1108 $this->
editPage( $name,
'Initial content' );
1113 'appendtext' =>
'More content',
1115 'summary' =>
'Add new section',
1118 $page =
new WikiPage( Title::newFromText( $name ) );
1120 $this->
assertSame(
"Initial content\n\n== Add new section ==\n\nMore content",
1121 $page->getContent()->getText() );
1123 $this->
assertSame(
'/* Add new section */ new section',
1124 $page->getRevision()->getComment() );
1128 $name =
'Help:' . ucfirst( __FUNCTION__ );
1130 $this->
editPage( $name,
'Initial content' );
1135 'sectiontitle' =>
'My section',
1136 'appendtext' =>
'More content',
1138 'summary' =>
'Add new section',
1141 $page =
new WikiPage( Title::newFromText( $name ) );
1143 $this->
assertSame(
"Initial content\n\n== My section ==\n\nMore content",
1144 $page->getContent()->getText() );
1146 $page->getRevision()->getComment() );
1150 $name =
'Help:' . ucfirst( __FUNCTION__ );
1152 $this->
editPage( $name,
"== Section 1 ==\n\nContent\n\n" .
1153 "== Section 2 ==\n\nFascinating!" );
1158 'appendtext' =>
' and more content',
1162 $text = (
new WikiPage( Title::newFromText( $name ) ) )
1163 ->getContent()->getText();
1165 $this->
assertSame(
"== Section 1 ==\n\nContent and more content\n\n" .
1166 "== Section 2 ==\n\nFascinating!", $text );
1170 $name =
'Help:' . ucfirst( __FUNCTION__ );
1172 $this->
editPage( $name,
"Content\n\n== Section 1 ==\n\nFascinating!" );
1177 'appendtext' =>
' and more content',
1181 $text = (
new WikiPage( Title::newFromText( $name ) ) )
1182 ->getContent()->getText();
1184 $this->
assertSame(
"Content and more content\n\n== Section 1 ==\n\n" .
1185 "Fascinating!", $text );
1189 $name =
'Help:' . ucfirst( __FUNCTION__ );
1193 $this->
editPage( $name,
'Content' );
1199 'appendtext' =>
' and more content',
1203 $text = (
new WikiPage( Title::newFromText( $name ) ) )
1204 ->getContent()->getText();
1211 $name =
'Help:' . ucfirst( __FUNCTION__ );
1214 'The "section" parameter must be a valid section ID or "new".' );
1215 $this->
editPage( $name,
'Content' );
1221 'text' =>
'Different content',
1222 'section' =>
'It is unlikely that this is valid',
1225 $text = (
new WikiPage( Title::newFromText( $name ) ) )
1226 ->getContent()->getText();
1233 $name =
'Help:' . ucfirst( __FUNCTION__ );
1235 'The page has been deleted since you fetched its timestamp.' );
1237 $startTime = MWTimestamp::convert( TS_MW, time() - 1 );
1239 $this->
editPage( $name,
'Some text' );
1241 $pageObj =
new WikiPage( Title::newFromText( $name ) );
1242 $pageObj->doDeleteArticle(
'Bye-bye' );
1250 'text' =>
'Different text',
1251 'starttimestamp' => $startTime,
1259 $name =
'Help:' . ucfirst( __FUNCTION__ );
1261 $this->
editPage( $name,
'Some text' );
1266 'text' =>
'Different text',
1270 $revisionStore = \MediaWiki\MediaWikiServices::getInstance()->getRevisionStore();
1271 $revision = $revisionStore->getRevisionByTitle( Title::newFromText( $name ) );
1276 $name =
'Help:' . ucfirst( __FUNCTION__ );
1278 $startTime = MWTimestamp::convert( TS_MW, time() - 1 );
1280 $this->
editPage( $name,
'Some text' );
1282 $pageObj =
new WikiPage( Title::newFromText( $name ) );
1283 $pageObj->doDeleteArticle(
'Bye-bye' );
1290 'text' =>
'Different text',
1291 'starttimestamp' => $startTime,
1295 $this->
assertTrue( Title::newFromText( $name )->exists() );
1299 $name =
'Help:' . ucfirst( __FUNCTION__ );
1300 $user = self::$users[
'sysop']->getUser();
1305 'text' =>
'Some text',
1309 $this->
assertTrue( Title::newFromText( $name )->exists() );
1310 $this->
assertTrue( $user->isWatched( Title::newFromText( $name ) ) );
1314 $name =
'Help:' . ucfirst( __FUNCTION__ );
1315 $user = self::$users[
'sysop']->getUser();
1316 $titleObj = Title::newFromText( $name );
1318 $user->addWatch( $titleObj );
1321 $this->
assertTrue( $user->isWatched( $titleObj ) );
1326 'text' =>
'Some text',
1331 $this->
assertFalse( $user->isWatched( $titleObj ) );
1335 $name =
'Help:' . ucfirst( __FUNCTION__ );
1342 'text' =>
'Some text',
1343 'tags' =>
'custom tag',
1344 ] )[0][
'edit'][
'newrevid'];
1347 $this->
assertSame(
'custom tag', $dbw->selectField(
1348 [
'change_tag',
'change_tag_def' ],
1350 [
'ct_rev_id' => $revId ],
1352 [
'change_tag_def' => [
'JOIN',
'ctd_id = ct_tag_id' ] ]
1358 $name =
'Help:' . ucfirst( __FUNCTION__ );
1361 'You do not have permission to apply change tags along with your changes.' );
1363 $this->
assertFalse( Title::newFromText( $name )->exists() );
1367 [
'user' => [
'applychangetags' =>
true ] ] );
1372 'text' =>
'Some text',
1373 'tags' =>
'custom tag',
1376 $this->
assertFalse( Title::newFromText( $name )->exists() );
1381 $name =
'Help:' . ucfirst( __FUNCTION__ );
1384 'The modification you tried to make was aborted by an extension.' );
1387 'hook-APIEditBeforeSave-closure)' );
1399 'text' =>
'Some text',
1402 $this->
assertFalse( Title::newFromText( $name )->exists() );
1407 $name =
'Help:' . ucfirst( __FUNCTION__ );
1410 'hook-APIEditBeforeSave-closure)' );
1413 function ( $unused1, $unused2, &$r ) {
1414 $r[
'msg'] =
'Some message';
1421 'text' =>
'Some text',
1425 $this->
assertSame( [
'msg' =>
'Some message',
'result' =>
'Failure' ],
1426 $result[0][
'edit'] );
1428 $this->
assertFalse( Title::newFromText( $name )->exists() );
1432 $name =
'Help:' . ucfirst( __FUNCTION__ );
1436 $status->apiHookResult = [
'msg' =>
'A message for you!' ];
1443 'text' =>
'Some text',
1446 $this->
assertFalse( Title::newFromText( $name )->exists() );
1447 $this->
assertSame( [
'edit' => [
'msg' =>
'A message for you!',
1448 'result' =>
'Failure' ] ], $res[0] );
1452 $name =
'Help:' . ucfirst( __FUNCTION__ );
1455 'The modification you tried to make was aborted by an extension.' );
1467 'text' =>
'Some text',
1470 $this->
assertFalse( Title::newFromText( $name )->exists() );
1475 $name =
'Help:' . ucfirst( __FUNCTION__ );
1479 $block =
new Block( [
1480 'address' => self::$users[
'sysop']->getUser()->getName(),
1481 'by' => self::$users[
'sysop']->getUser()->getId(),
1482 'reason' =>
'Capriciousness',
1483 'timestamp' =>
'19370101000000',
1484 'expiry' =>
'infinity',
1485 'enableAutoblock' =>
true,
1493 'text' =>
'Some text',
1495 $this->fail(
'Expected exception not thrown' );
1497 $this->
assertSame(
'You have been blocked from editing.', $ex->getMessage() );
1501 self::$users[
'sysop']->getUser()->clearInstanceCache();
1506 $name =
'Help:' . ucfirst( __FUNCTION__ );
1509 'The wiki is currently in read-only mode.' );
1511 $svc = \MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode();
1512 $svc->setReason(
"Read-only for testing" );
1518 'text' =>
'Some text',
1521 $svc->setReason(
false );
1526 $name =
'File:' . ucfirst( __FUNCTION__ );
1529 "Anonymous users can't create image redirects." );
1534 'text' =>
'#REDIRECT [[File:Other file.png]]',
1535 ],
null,
new User() );
1539 $name =
'File:' . ucfirst( __FUNCTION__ );
1542 "You don't have permission to create image redirects." );
1545 [
'user' => [
'upload' =>
true ] ] );
1550 'text' =>
'#REDIRECT [[File:Other file.png]]',
1555 $name =
'Help:' . ucfirst( __FUNCTION__ );
1558 'The content you supplied exceeds the article size limit of 1 kilobyte.' );
1572 $name =
'Help:' . ucfirst( __FUNCTION__ );
1575 'The action you have requested is limited to users in the group: ' );
1577 $this->
setMwGlobals(
'wgRevokePermissions', [
'*' => [
'edit' =>
true ] ] );
1582 'text' =>
'Some text',
1583 ],
null,
new User() );
1587 $name =
'Help:' . ucfirst( __FUNCTION__ );
1590 "You don't have permission to change the content model of a page." );
1593 [
'user' => [
'editcontentmodel' =>
true ] ] );
1598 'text' =>
'Some text',
1599 'contentmodel' =>
'json',
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Tests for MediaWiki api.php?action=edit.
testUnsupportedContentFormat()
testEditSection()
Test editing of sections.
testIncorrectMd5PrependText()
testAppendToFirstSection()
testUndoToRevFromDifferentPage()
testProhibitedChangeContentModel()
testUndoAfterToRevFromDifferentPage()
testAppendNewSectionWithInvalidContentModel()
testAppendInMediaWikiNamespaceWithSerializationError()
testEditAbortedByEditPageHookWithNoResult()
testAppendInMediaWikiNamespace()
testEditConflict_T43990()
testUndoAfterContentModelChange()
This test verifies that after changing the content model of a page, undoing that edit via the API wil...
testAppendNewSectionWithTitle()
testIncorrectMd5AppendText()
testCheckDirectApiEditingDisallowed_forNonTextContent()
testCreateImageRedirectLoggedIn()
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...
testAppendWithNonTextContentHandler()
Appending/prepending is currently only supported for TextContent.
testEditMalformedSection()
testMd5PrependAndAppendText()
testEditWithoutTagPermission()
testUndoWithSwappedRevisions()
Test undo when a revision with a higher id has an earlier timestamp.
testEditAbortedByHookWithCustomOutput()
testAppendNewSectionWithSummary()
testEditConflict_newSection()
Ensure that editing using section=new will prevent simple conflicts.
testReversedUndoAfter()
undoafter is supposed to be less than undo.
testEditAbortedByEditPageHookWithResult()
testEditWithStartTimestamp()
testProhibitedAnonymousEdit()
testEdit_redirect()
Ensure we can edit through a redirect, if adding a section.
testCreateImageRedirectAnon()
testEditAppend( $text, $op, $append, $expected)
provideEditAppend
testUndoAfterToHiddenRev()
Tests what happens if the undo parameter is a valid revision, but undoafter is hidden (rev_deleted).
testAppendToNonexistentSection()
testSupportsDirectApiEditing_withContentHandlerOverride()
testAppendNewSectionWithTitleAndSummary()
forceRevisionDate(WikiPage $page, $timestamp)
testUndoAfterToInvalidRev()
Tests what happens if the undo parameter is a valid revision, but the undoafter parameter doesn't ref...
static provideEditAppend()
testMismatchedContentFormat()
testCorrectContentFormat()
doApiRequestWithToken(array $params, array $session=null, User $user=null, $tokenType='auto')
Convenience function to access the token parameter of doApiRequest() more succinctly.
Exception used to abort API execution with an error.
static newFromTarget( $specificTarget, $vagueTarget=null, $fromMaster=false)
Given a target and the target's type, get an existing Block object if possible.
static createList( $typeName, IContextSource $context, Title $title, array $ids)
Instantiate the appropriate list class for a given list of IDs.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Represents a title within MediaWiki.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Class representing a MediaWiki article and history.
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
Status::newGood()` to allow deletion, and then `return false` from the hook function. Ensure you consume the 'ChangeTagAfterDelete' hook to carry out custom deletion actions. $tag:name of the tag $user:user initiating the action & $status:Status object. See above. 'ChangeTagsListActive':Allows you to nominate which of the tags your extension uses are in active use. & $tags:list of all active tags. Append to this array. 'ChangeTagsAfterUpdateTags':Called after tags have been updated with the ChangeTags::updateTags function. Params:$addedTags:tags effectively added in the update $removedTags:tags effectively removed in the update $prevTags:tags that were present prior to the update $rc_id:recentchanges table id $rev_id:revision table id $log_id:logging table id $params:tag params $rc:RecentChange being tagged when the tagging accompanies the action, or null $user:User who performed the tagging when the tagging is subsequent to the action, or null 'ChangeTagsAllowedAdd':Called when checking if a user can add tags to a change. & $allowedTags:List of all the tags the user is allowed to add. Any tags the user wants to add( $addTags) that are not in this array will cause it to fail. You may add or remove tags to this array as required. $addTags:List of tags user intends to add. $user:User who is adding the tags. 'ChangeUserGroups':Called before user groups are changed. $performer:The User who will perform the change $user:The User whose groups will be changed & $add:The groups that will be added & $remove:The groups that will be removed 'Collation::factory':Called if $wgCategoryCollation is an unknown collation. $collationName:Name of the collation in question & $collationObject:Null. Replace with a subclass of the Collation class that implements the collation given in $collationName. 'ConfirmEmailComplete':Called after a user 's email has been confirmed successfully. $user:user(object) whose email is being confirmed 'ContentAlterParserOutput':Modify parser output for a given content object. Called by Content::getParserOutput after parsing has finished. Can be used for changes that depend on the result of the parsing but have to be done before LinksUpdate is called(such as adding tracking categories based on the rendered HTML). $content:The Content to render $title:Title of the page, as context $parserOutput:ParserOutput to manipulate 'ContentGetParserOutput':Customize parser output for a given content object, called by AbstractContent::getParserOutput. May be used to override the normal model-specific rendering of page content. $content:The Content to render $title:Title of the page, as context $revId:The revision ID, as context $options:ParserOptions for rendering. To avoid confusing the parser cache, the output can only depend on parameters provided to this hook function, not on global state. $generateHtml:boolean, indicating whether full HTML should be generated. If false, generation of HTML may be skipped, but other information should still be present in the ParserOutput object. & $output:ParserOutput, to manipulate or replace 'ContentHandlerDefaultModelFor':Called when the default content model is determined for a given title. May be used to assign a different model for that title. $title:the Title in question & $model:the model name. Use with CONTENT_MODEL_XXX constants. 'ContentHandlerForModelID':Called when a ContentHandler is requested for a given content model name, but no entry for that model exists in $wgContentHandlers. Note:if your extension implements additional models via this hook, please use GetContentModels hook to make them known to core. $modeName:the requested content model name & $handler:set this to a ContentHandler object, if desired. 'ContentModelCanBeUsedOn':Called to determine whether that content model can be used on a given page. This is especially useful to prevent some content models to be used in some special location. $contentModel:ID of the content model in question $title:the Title in question. & $ok:Output parameter, whether it is OK to use $contentModel on $title. Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok. 'ContribsPager::getQueryInfo':Before the contributions query is about to run & $pager:Pager object for contributions & $queryInfo:The query for the contribs Pager 'ContribsPager::reallyDoQuery':Called before really executing the query for My Contributions & $data:an array of results of all contribs queries $pager:The ContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'ContributionsLineEnding':Called before a contributions HTML line is finished $page:SpecialPage object for contributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'ContributionsToolLinks':Change tool links above Special:Contributions $id:User identifier $title:User page title & $tools:Array of tool links $specialPage:SpecialPage instance for context and services. Can be either SpecialContributions or DeletedContributionsPage. Extensions should type hint against a generic SpecialPage though. 'ConvertContent':Called by AbstractContent::convert when a conversion to another content model is requested. Handler functions that modify $result should generally return false to disable further attempts at conversion. $content:The Content object to be converted. $toModel:The ID of the content model to convert to. $lossy: boolean indicating whether lossy conversion is allowed. & $result:Output parameter, in case the handler function wants to provide a converted Content object. Note that $result->getContentModel() must return $toModel. 'ContentSecurityPolicyDefaultSource':Modify the allowed CSP load sources. This affects all directives except for the script directive. If you want to add a script source, see ContentSecurityPolicyScriptSource hook. & $defaultSrc:Array of Content-Security-Policy allowed sources $policyConfig:Current configuration for the Content-Security-Policy header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyDirectives':Modify the content security policy directives. Use this only if ContentSecurityPolicyDefaultSource and ContentSecurityPolicyScriptSource do not meet your needs. & $directives:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyScriptSource':Modify the allowed CSP script sources. Note that you also have to use ContentSecurityPolicyDefaultSource if you want non-script sources to be loaded from whatever you add. & $scriptSrc:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'CustomEditor':When invoking the page editor Return true to allow the normal editor to be used, or false if implementing a custom editor, e.g. for a special namespace, etc. $article:Article being edited $user:User performing the edit 'DatabaseOraclePostInit':Called after initialising an Oracle database $db:the DatabaseOracle object 'DeletedContribsPager::reallyDoQuery':Called before really executing the query for Special:DeletedContributions Similar to ContribsPager::reallyDoQuery & $data:an array of results of all contribs queries $pager:The DeletedContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'DeletedContributionsLineEnding':Called before a DeletedContributions HTML line is finished. Similar to ContributionsLineEnding $page:SpecialPage object for DeletedContributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'DeleteUnknownPreferences':Called by the cleanupPreferences.php maintenance script to build a WHERE clause with which to delete preferences that are not known about. This hook is used by extensions that have dynamically-named preferences that should not be deleted in the usual cleanup process. For example, the Gadgets extension creates preferences prefixed with 'gadget-', and so anything with that prefix is excluded from the deletion. &where:An array that will be passed as the $cond parameter to IDatabase::select() to determine what will be deleted from the user_properties table. $db:The IDatabase object, useful for accessing $db->buildLike() etc. 'DifferenceEngineAfterLoadNewText':called in DifferenceEngine::loadNewText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before returning true from this function. $differenceEngine:DifferenceEngine object 'DifferenceEngineLoadTextAfterNewContentIsLoaded':called in DifferenceEngine::loadText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before checking if the variable 's value is null. This hook can be used to inject content into said class member variable. $differenceEngine:DifferenceEngine object 'DifferenceEngineMarkPatrolledLink':Allows extensions to change the "mark as
patrolled" link which is shown both on the diff header as well as on the bottom of a page, usually wrapped in a span element which has class="patrollink". $differenceEngine:DifferenceEngine object & $markAsPatrolledLink:The "mark as patrolled" link HTML(string) $rcid:Recent change ID(rc_id) for this change(int) 'DifferenceEngineMarkPatrolledRCID':Allows extensions to possibly change the rcid parameter. For example the rcid might be set to zero due to the user being the same as the performer of the change but an extension might still want to show it under certain conditions. & $rcid:rc_id(int) of the change or 0 $differenceEngine:DifferenceEngine object $change:RecentChange object $user:User object representing the current user 'DifferenceEngineNewHeader':Allows extensions to change the $newHeader variable, which contains information about the new revision, such as the revision 's author, whether the revision was marked as a minor edit or not, etc. $differenceEngine:DifferenceEngine object & $newHeader:The string containing the various #mw-diff-otitle[1-5] divs, which include things like revision author info, revision comment, RevisionDelete link and more $formattedRevisionTools:Array containing revision tools, some of which may have been injected with the DiffRevisionTools hook $nextlink:String containing the link to the next revision(if any) $status
returning false will NOT prevent logging $e
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)