MediaWiki  1.30.0
ApiEditPageTest.php
Go to the documentation of this file.
1 <?php
2 
15 
16  protected function setUp() {
18 
19  parent::setUp();
20 
21  $this->setMwGlobals( [
22  'wgExtraNamespaces' => $wgExtraNamespaces,
23  'wgNamespaceContentModels' => $wgNamespaceContentModels,
24  'wgContentHandlers' => $wgContentHandlers,
25  'wgContLang' => $wgContLang,
26  ] );
27 
28  $wgExtraNamespaces[12312] = 'Dummy';
29  $wgExtraNamespaces[12313] = 'Dummy_talk';
30  $wgExtraNamespaces[12314] = 'DummyNonText';
31  $wgExtraNamespaces[12315] = 'DummyNonText_talk';
32 
33  $wgNamespaceContentModels[12312] = "testing";
34  $wgNamespaceContentModels[12314] = "testing-nontext";
35 
36  $wgContentHandlers["testing"] = 'DummyContentHandlerForTesting';
37  $wgContentHandlers["testing-nontext"] = 'DummyNonTextContentHandler';
38 
39  MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
40  $wgContLang->resetNamespaces(); # reset namespace cache
41 
42  $this->doLogin();
43  }
44 
45  protected function tearDown() {
46  MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
47  parent::tearDown();
48  }
49 
50  public function testEdit() {
51  $name = 'Help:ApiEditPageTest_testEdit'; // assume Help namespace to default to wikitext
52 
53  // -- test new page --------------------------------------------
54  $apiResult = $this->doApiRequestWithToken( [
55  'action' => 'edit',
56  'title' => $name,
57  'text' => 'some text',
58  ] );
59  $apiResult = $apiResult[0];
60 
61  // Validate API result data
62  $this->assertArrayHasKey( 'edit', $apiResult );
63  $this->assertArrayHasKey( 'result', $apiResult['edit'] );
64  $this->assertEquals( 'Success', $apiResult['edit']['result'] );
65 
66  $this->assertArrayHasKey( 'new', $apiResult['edit'] );
67  $this->assertArrayNotHasKey( 'nochange', $apiResult['edit'] );
68 
69  $this->assertArrayHasKey( 'pageid', $apiResult['edit'] );
70 
71  // -- test existing page, no change ----------------------------
72  $data = $this->doApiRequestWithToken( [
73  'action' => 'edit',
74  'title' => $name,
75  'text' => 'some text',
76  ] );
77 
78  $this->assertEquals( 'Success', $data[0]['edit']['result'] );
79 
80  $this->assertArrayNotHasKey( 'new', $data[0]['edit'] );
81  $this->assertArrayHasKey( 'nochange', $data[0]['edit'] );
82 
83  // -- test existing page, with change --------------------------
84  $data = $this->doApiRequestWithToken( [
85  'action' => 'edit',
86  'title' => $name,
87  'text' => 'different text'
88  ] );
89 
90  $this->assertEquals( 'Success', $data[0]['edit']['result'] );
91 
92  $this->assertArrayNotHasKey( 'new', $data[0]['edit'] );
93  $this->assertArrayNotHasKey( 'nochange', $data[0]['edit'] );
94 
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"
101  );
102  }
103 
107  public static function provideEditAppend() {
108  return [
109  [ # 0: append
110  'foo', 'append', 'bar', "foobar"
111  ],
112  [ # 1: prepend
113  'foo', 'prepend', 'bar', "barfoo"
114  ],
115  [ # 2: append to empty page
116  '', 'append', 'foo', "foo"
117  ],
118  [ # 3: prepend to empty page
119  '', 'prepend', 'foo', "foo"
120  ],
121  [ # 4: append to non-existing page
122  null, 'append', 'foo', "foo"
123  ],
124  [ # 5: prepend to non-existing page
125  null, 'prepend', 'foo', "foo"
126  ],
127  ];
128  }
129 
133  public function testEditAppend( $text, $op, $append, $expected ) {
134  static $count = 0;
135  $count++;
136 
137  // assume NS_HELP defaults to wikitext
138  $name = "Help:ApiEditPageTest_testEditAppend_$count";
139 
140  // -- create page (or not) -----------------------------------------
141  if ( $text !== null ) {
142  list( $re ) = $this->doApiRequestWithToken( [
143  'action' => 'edit',
144  'title' => $name,
145  'text' => $text, ] );
146 
147  $this->assertEquals( 'Success', $re['edit']['result'] ); // sanity
148  }
149 
150  // -- try append/prepend --------------------------------------------
151  list( $re ) = $this->doApiRequestWithToken( [
152  'action' => 'edit',
153  'title' => $name,
154  $op . 'text' => $append, ] );
155 
156  $this->assertEquals( 'Success', $re['edit']['result'] );
157 
158  // -- validate -----------------------------------------------------
159  $page = new WikiPage( Title::newFromText( $name ) );
160  $content = $page->getContent();
161  $this->assertNotNull( $content, 'Page should have been created' );
162 
163  $text = $content->getNativeData();
164 
165  $this->assertEquals( $expected, $text );
166  }
167 
171  public function testEditSection() {
172  $name = 'Help:ApiEditPageTest_testEditSection';
174  $text = "==section 1==\ncontent 1\n==section 2==\ncontent2";
175  // Preload the page with some text
176  $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), 'summary' );
177 
178  list( $re ) = $this->doApiRequestWithToken( [
179  'action' => 'edit',
180  'title' => $name,
181  'section' => '1',
182  'text' => "==section 1==\nnew content 1",
183  ] );
184  $this->assertEquals( 'Success', $re['edit']['result'] );
186  ->getContent( Revision::RAW )
187  ->getNativeData();
188  $this->assertEquals( "==section 1==\nnew content 1\n\n==section 2==\ncontent2", $newtext );
189 
190  // Test that we raise a 'nosuchsection' error
191  try {
192  $this->doApiRequestWithToken( [
193  'action' => 'edit',
194  'title' => $name,
195  'section' => '9999',
196  'text' => 'text',
197  ] );
198  $this->fail( "Should have raised an ApiUsageException" );
199  } catch ( ApiUsageException $e ) {
200  $this->assertTrue( self::apiExceptionHasCode( $e, 'nosuchsection' ) );
201  }
202  }
203 
210  public function testEditNewSection() {
211  $name = 'Help:ApiEditPageTest_testEditNewSection';
212 
213  // Test on a page that does not already exist
214  $this->assertFalse( Title::newFromText( $name )->exists() );
215  list( $re ) = $this->doApiRequestWithToken( [
216  'action' => 'edit',
217  'title' => $name,
218  'section' => 'new',
219  'text' => 'test',
220  'summary' => 'header',
221  ] );
222 
223  $this->assertEquals( 'Success', $re['edit']['result'] );
224  // Check the page text is correct
226  ->getContent( Revision::RAW )
227  ->getNativeData();
228  $this->assertEquals( "== header ==\n\ntest", $text );
229 
230  // Now on one that does
231  $this->assertTrue( Title::newFromText( $name )->exists() );
232  list( $re2 ) = $this->doApiRequestWithToken( [
233  'action' => 'edit',
234  'title' => $name,
235  'section' => 'new',
236  'text' => 'test',
237  'summary' => 'header',
238  ] );
239 
240  $this->assertEquals( 'Success', $re2['edit']['result'] );
242  ->getContent( Revision::RAW )
243  ->getNativeData();
244  $this->assertEquals( "== header ==\n\ntest\n\n== header ==\n\ntest", $text );
245  }
246 
250  public function testEdit_redirect() {
251  static $count = 0;
252  $count++;
253 
254  // assume NS_HELP defaults to wikitext
255  $name = "Help:ApiEditPageTest_testEdit_redirect_$count";
257  $page = WikiPage::factory( $title );
258 
259  $rname = "Help:ApiEditPageTest_testEdit_redirect_r$count";
260  $rtitle = Title::newFromText( $rname );
261  $rpage = WikiPage::factory( $rtitle );
262 
263  // base edit for content
264  $page->doEditContent( new WikitextContent( "Foo" ),
265  "testing 1", EDIT_NEW, false, self::$users['sysop']->getUser() );
266  $this->forceRevisionDate( $page, '20120101000000' );
267  $baseTime = $page->getRevision()->getTimestamp();
268 
269  // base edit for redirect
270  $rpage->doEditContent( new WikitextContent( "#REDIRECT [[$name]]" ),
271  "testing 1", EDIT_NEW, false, self::$users['sysop']->getUser() );
272  $this->forceRevisionDate( $rpage, '20120101000000' );
273 
274  // conflicting edit to redirect
275  $rpage->doEditContent( new WikitextContent( "#REDIRECT [[$name]]\n\n[[Category:Test]]" ),
276  "testing 2", EDIT_UPDATE, $page->getLatest(), self::$users['uploader']->getUser() );
277  $this->forceRevisionDate( $rpage, '20120101020202' );
278 
279  // try to save edit, following the redirect
280  list( $re, , ) = $this->doApiRequestWithToken( [
281  'action' => 'edit',
282  'title' => $rname,
283  'text' => 'nix bar!',
284  'basetimestamp' => $baseTime,
285  'section' => 'new',
286  'redirect' => true,
287  ], null, self::$users['sysop']->getUser() );
288 
289  $this->assertEquals( 'Success', $re['edit']['result'],
290  "no problems expected when following redirect" );
291  }
292 
296  public function testEdit_redirectText() {
297  static $count = 0;
298  $count++;
299 
300  // assume NS_HELP defaults to wikitext
301  $name = "Help:ApiEditPageTest_testEdit_redirectText_$count";
303  $page = WikiPage::factory( $title );
304 
305  $rname = "Help:ApiEditPageTest_testEdit_redirectText_r$count";
306  $rtitle = Title::newFromText( $rname );
307  $rpage = WikiPage::factory( $rtitle );
308 
309  // base edit for content
310  $page->doEditContent( new WikitextContent( "Foo" ),
311  "testing 1", EDIT_NEW, false, self::$users['sysop']->getUser() );
312  $this->forceRevisionDate( $page, '20120101000000' );
313  $baseTime = $page->getRevision()->getTimestamp();
314 
315  // base edit for redirect
316  $rpage->doEditContent( new WikitextContent( "#REDIRECT [[$name]]" ),
317  "testing 1", EDIT_NEW, false, self::$users['sysop']->getUser() );
318  $this->forceRevisionDate( $rpage, '20120101000000' );
319 
320  // conflicting edit to redirect
321  $rpage->doEditContent( new WikitextContent( "#REDIRECT [[$name]]\n\n[[Category:Test]]" ),
322  "testing 2", EDIT_UPDATE, $page->getLatest(), self::$users['uploader']->getUser() );
323  $this->forceRevisionDate( $rpage, '20120101020202' );
324 
325  // try to save edit, following the redirect but without creating a section
326  try {
327  $this->doApiRequestWithToken( [
328  'action' => 'edit',
329  'title' => $rname,
330  'text' => 'nix bar!',
331  'basetimestamp' => $baseTime,
332  'redirect' => true,
333  ], null, self::$users['sysop']->getUser() );
334 
335  $this->fail( 'redirect-appendonly error expected' );
336  } catch ( ApiUsageException $ex ) {
337  $this->assertTrue( self::apiExceptionHasCode( $ex, 'redirect-appendonly' ) );
338  }
339  }
340 
341  public function testEditConflict() {
342  static $count = 0;
343  $count++;
344 
345  // assume NS_HELP defaults to wikitext
346  $name = "Help:ApiEditPageTest_testEditConflict_$count";
348 
349  $page = WikiPage::factory( $title );
350 
351  // base edit
352  $page->doEditContent( new WikitextContent( "Foo" ),
353  "testing 1", EDIT_NEW, false, self::$users['sysop']->getUser() );
354  $this->forceRevisionDate( $page, '20120101000000' );
355  $baseTime = $page->getRevision()->getTimestamp();
356 
357  // conflicting edit
358  $page->doEditContent( new WikitextContent( "Foo bar" ),
359  "testing 2", EDIT_UPDATE, $page->getLatest(), self::$users['uploader']->getUser() );
360  $this->forceRevisionDate( $page, '20120101020202' );
361 
362  // try to save edit, expect conflict
363  try {
364  $this->doApiRequestWithToken( [
365  'action' => 'edit',
366  'title' => $name,
367  'text' => 'nix bar!',
368  'basetimestamp' => $baseTime,
369  ], null, self::$users['sysop']->getUser() );
370 
371  $this->fail( 'edit conflict expected' );
372  } catch ( ApiUsageException $ex ) {
373  $this->assertTrue( self::apiExceptionHasCode( $ex, 'editconflict' ) );
374  }
375  }
376 
380  public function testEditConflict_newSection() {
381  static $count = 0;
382  $count++;
383 
384  // assume NS_HELP defaults to wikitext
385  $name = "Help:ApiEditPageTest_testEditConflict_newSection_$count";
387 
388  $page = WikiPage::factory( $title );
389 
390  // base edit
391  $page->doEditContent( new WikitextContent( "Foo" ),
392  "testing 1", EDIT_NEW, false, self::$users['sysop']->getUser() );
393  $this->forceRevisionDate( $page, '20120101000000' );
394  $baseTime = $page->getRevision()->getTimestamp();
395 
396  // conflicting edit
397  $page->doEditContent( new WikitextContent( "Foo bar" ),
398  "testing 2", EDIT_UPDATE, $page->getLatest(), self::$users['uploader']->getUser() );
399  $this->forceRevisionDate( $page, '20120101020202' );
400 
401  // try to save edit, expect no conflict
402  list( $re, , ) = $this->doApiRequestWithToken( [
403  'action' => 'edit',
404  'title' => $name,
405  'text' => 'nix bar!',
406  'basetimestamp' => $baseTime,
407  'section' => 'new',
408  ], null, self::$users['sysop']->getUser() );
409 
410  $this->assertEquals( 'Success', $re['edit']['result'],
411  "no edit conflict expected here" );
412  }
413 
414  public function testEditConflict_bug41990() {
415  static $count = 0;
416  $count++;
417 
418  /*
419  * T43990: if the target page has a newer revision than the redirect, then editing the
420  * redirect while specifying 'redirect' and *not* specifying 'basetimestamp' erroneously
421  * caused an edit conflict to be detected.
422  */
423 
424  // assume NS_HELP defaults to wikitext
425  $name = "Help:ApiEditPageTest_testEditConflict_redirect_bug41990_$count";
427  $page = WikiPage::factory( $title );
428 
429  $rname = "Help:ApiEditPageTest_testEditConflict_redirect_bug41990_r$count";
430  $rtitle = Title::newFromText( $rname );
431  $rpage = WikiPage::factory( $rtitle );
432 
433  // base edit for content
434  $page->doEditContent( new WikitextContent( "Foo" ),
435  "testing 1", EDIT_NEW, false, self::$users['sysop']->getUser() );
436  $this->forceRevisionDate( $page, '20120101000000' );
437 
438  // base edit for redirect
439  $rpage->doEditContent( new WikitextContent( "#REDIRECT [[$name]]" ),
440  "testing 1", EDIT_NEW, false, self::$users['sysop']->getUser() );
441  $this->forceRevisionDate( $rpage, '20120101000000' );
442 
443  // new edit to content
444  $page->doEditContent( new WikitextContent( "Foo bar" ),
445  "testing 2", EDIT_UPDATE, $page->getLatest(), self::$users['uploader']->getUser() );
446  $this->forceRevisionDate( $rpage, '20120101020202' );
447 
448  // try to save edit; should work, following the redirect.
449  list( $re, , ) = $this->doApiRequestWithToken( [
450  'action' => 'edit',
451  'title' => $rname,
452  'text' => 'nix bar!',
453  'section' => 'new',
454  'redirect' => true,
455  ], null, self::$users['sysop']->getUser() );
456 
457  $this->assertEquals( 'Success', $re['edit']['result'],
458  "no edit conflict expected here" );
459  }
460 
465  protected function forceRevisionDate( WikiPage $page, $timestamp ) {
466  $dbw = wfGetDB( DB_MASTER );
467 
468  $dbw->update( 'revision',
469  [ 'rev_timestamp' => $dbw->timestamp( $timestamp ) ],
470  [ 'rev_id' => $page->getLatest() ] );
471 
472  $page->clear();
473  }
474 
476  $this->setExpectedException(
477  'ApiUsageException',
478  'Direct editing via API is not supported for content model ' .
479  'testing used by Dummy:ApiEditPageTest_nonTextPageEdit'
480  );
481 
482  $this->doApiRequestWithToken( [
483  'action' => 'edit',
484  'title' => 'Dummy:ApiEditPageTest_nonTextPageEdit',
485  'text' => '{"animals":["kittens!"]}'
486  ] );
487  }
488 
490  $name = 'DummyNonText:ApiEditPageTest_testNonTextEdit';
491  $data = serialize( 'some bla bla text' );
492 
493  $result = $this->doApiRequestWithToken( [
494  'action' => 'edit',
495  'title' => $name,
496  'text' => $data,
497  ] );
498 
499  $apiResult = $result[0];
500 
501  // Validate API result data
502  $this->assertArrayHasKey( 'edit', $apiResult );
503  $this->assertArrayHasKey( 'result', $apiResult['edit'] );
504  $this->assertEquals( 'Success', $apiResult['edit']['result'] );
505 
506  $this->assertArrayHasKey( 'new', $apiResult['edit'] );
507  $this->assertArrayNotHasKey( 'nochange', $apiResult['edit'] );
508 
509  $this->assertArrayHasKey( 'pageid', $apiResult['edit'] );
510 
511  // validate resulting revision
513  $this->assertEquals( "testing-nontext", $page->getContentModel() );
514  $this->assertEquals( $data, $page->getContent()->serialize() );
515  }
516 
523  $name = 'Help:' . __FUNCTION__;
524  $uploader = self::$users['uploader']->getUser();
525  $sysop = self::$users['sysop']->getUser();
526  $apiResult = $this->doApiRequestWithToken( [
527  'action' => 'edit',
528  'title' => $name,
529  'text' => 'some text',
530  ], null, $sysop )[0];
531 
532  // Check success
533  $this->assertArrayHasKey( 'edit', $apiResult );
534  $this->assertArrayHasKey( 'result', $apiResult['edit'] );
535  $this->assertEquals( 'Success', $apiResult['edit']['result'] );
536  $this->assertArrayHasKey( 'contentmodel', $apiResult['edit'] );
537  // Content model is wikitext
538  $this->assertEquals( 'wikitext', $apiResult['edit']['contentmodel'] );
539 
540  // Convert the page to JSON
541  $apiResult = $this->doApiRequestWithToken( [
542  'action' => 'edit',
543  'title' => $name,
544  'text' => '{}',
545  'contentmodel' => 'json',
546  ], null, $uploader )[0];
547 
548  // Check success
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'] );
554 
555  $apiResult = $this->doApiRequestWithToken( [
556  'action' => 'edit',
557  'title' => $name,
558  'undo' => $apiResult['edit']['newrevid']
559  ], null, $sysop )[0];
560 
561  // Check success
562  $this->assertArrayHasKey( 'edit', $apiResult );
563  $this->assertArrayHasKey( 'result', $apiResult['edit'] );
564  $this->assertEquals( 'Success', $apiResult['edit']['result'] );
565  $this->assertArrayHasKey( 'contentmodel', $apiResult['edit'] );
566  // Check that the contentmodel is back to wikitext now.
567  $this->assertEquals( 'wikitext', $apiResult['edit']['contentmodel'] );
568  }
569 }
function
when a variable name is used in a function
Definition: design.txt:93
$wgNamespaceContentModels
$wgNamespaceContentModels
Associative array mapping namespace IDs to the name of the content model pages in that namespace shou...
Definition: DefaultSettings.php:8448
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:268
ApiUsageException
Exception used to abort API execution with an error.
Definition: ApiUsageException.php:104
ApiEditPageTest\testEditConflict_newSection
testEditConflict_newSection()
Ensure that editing using section=new will prevent simple conflicts.
Definition: ApiEditPageTest.php:380
ApiEditPageTest\testEditAppend
testEditAppend( $text, $op, $append, $expected)
provideEditAppend
Definition: ApiEditPageTest.php:133
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1963
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:37
serialize
serialize()
Definition: ApiMessage.php:177
page
target page
Definition: All_system_messages.txt:1267
ApiEditPageTest\provideEditAppend
static provideEditAppend()
Definition: ApiEditPageTest.php:107
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
ApiEditPageTest\testSupportsDirectApiEditing_withContentHandlerOverride
testSupportsDirectApiEditing_withContentHandlerOverride()
Definition: ApiEditPageTest.php:489
cache
you have access to all of the normal MediaWiki so you can get a DB use the cache
Definition: maintenance.txt:52
ApiEditPageTest
Tests for MediaWiki api.php?action=edit.
Definition: ApiEditPageTest.php:14
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
ApiEditPageTest\setUp
setUp()
Definition: ApiEditPageTest.php:16
ApiEditPageTest\testEditSection
testEditSection()
Test editing of sections.
Definition: ApiEditPageTest.php:171
ApiEditPageTest\testEditConflict_bug41990
testEditConflict_bug41990()
Definition: ApiEditPageTest.php:414
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:932
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:121
$wgContentHandlers
$wgContentHandlers
Plugins for page content model handling.
Definition: DefaultSettings.php:988
ApiEditPageTest\testEdit_redirect
testEdit_redirect()
Ensure we can edit through a redirect, if adding a section.
Definition: ApiEditPageTest.php:250
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2856
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:672
ApiEditPageTest\testEdit
testEdit()
Definition: ApiEditPageTest.php:50
ApiEditPageTest\testEditConflict
testEditConflict()
Definition: ApiEditPageTest.php:341
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
WikiPage\getLatest
getLatest()
Get the page_latest field.
Definition: WikiPage.php:572
DB_MASTER
const DB_MASTER
Definition: defines.php:26
WikitextContent
Content object for wiki text pages.
Definition: WikitextContent.php:33
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:129
ApiTestCase\doLogin
doLogin( $testUser='sysop')
Definition: ApiTestCase.php:152
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2141
ApiTestCase
Definition: ApiTestCase.php:3
EDIT_UPDATE
const EDIT_UPDATE
Definition: Defines.php:154
ApiEditPageTest\testUndoAfterContentModelChange
testUndoAfterContentModelChange()
This test verifies that after changing the content model of a page, undoing that edit via the API wil...
Definition: ApiEditPageTest.php:522
ApiEditPageTest\testEdit_redirectText
testEdit_redirectText()
Ensure we cannot edit through a redirect, if attempting to overwrite content.
Definition: ApiEditPageTest.php:296
Revision\RAW
const RAW
Definition: Revision.php:100
EDIT_NEW
const EDIT_NEW
Definition: Defines.php:153
MWNamespace\getCanonicalNamespaces
static getCanonicalNamespaces( $rebuild=false)
Returns array of all defined namespaces with their canonical (English) names.
Definition: MWNamespace.php:207
ApiEditPageTest\testEditNewSection
testEditNewSection()
Test action=edit&section=new Run it twice so we test adding a new section on a page that doesn't exis...
Definition: ApiEditPageTest.php:210
ApiTestCase\doApiRequestWithToken
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...
Definition: ApiTestCase.php:127
ApiEditPageTest\testCheckDirectApiEditingDisallowed_forNonTextContent
testCheckDirectApiEditingDisallowed_forNonTextContent()
Definition: ApiEditPageTest.php:475
ApiEditPageTest\tearDown
tearDown()
Definition: ApiEditPageTest.php:45
ApiEditPageTest\forceRevisionDate
forceRevisionDate(WikiPage $page, $timestamp)
Definition: ApiEditPageTest.php:465
$wgExtraNamespaces
$wgExtraNamespaces
Additional namespaces.
Definition: DefaultSettings.php:3893
WikiPage\clear
clear()
Clear the object.
Definition: WikiPage.php:247
$wgContLang
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 content language as $wgContLang
Definition: design.txt:56