MediaWiki REL1_28
EditPageTest.php
Go to the documentation of this file.
1<?php
2
13
14 protected function setUp() {
16
17 parent::setUp();
18
19 $this->setMwGlobals( [
20 'wgExtraNamespaces' => $wgExtraNamespaces,
21 'wgNamespaceContentModels' => $wgNamespaceContentModels,
22 'wgContentHandlers' => $wgContentHandlers,
23 'wgContLang' => $wgContLang,
24 ] );
25
26 $wgExtraNamespaces[12312] = 'Dummy';
27 $wgExtraNamespaces[12313] = 'Dummy_talk';
28
29 $wgNamespaceContentModels[12312] = "testing";
30 $wgContentHandlers["testing"] = 'DummyContentHandlerForTesting';
31
32 MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
33 $wgContLang->resetNamespaces(); # reset namespace cache
34 }
35
42 $this->assertEquals( $title, $extracted );
43 }
44
45 public static function provideExtractSectionTitle() {
46 return [
47 [
48 "== Test ==\n\nJust a test section.",
49 "Test"
50 ],
51 [
52 "An initial section, no header.",
53 false
54 ],
55 [
56 "An initial section with a fake heder (bug 32617)\n\n== Test == ??\nwtf",
57 false
58 ],
59 [
60 "== Section ==\nfollowed by a fake == Non-section == ??\nnoooo",
61 "Section"
62 ],
63 [
64 "== Section== \t\r\n followed by whitespace (bug 35051)",
65 'Section',
66 ],
67 ];
68 }
69
70 protected function forceRevisionDate( WikiPage $page, $timestamp ) {
71 $dbw = wfGetDB( DB_MASTER );
72
73 $dbw->update( 'revision',
74 [ 'rev_timestamp' => $dbw->timestamp( $timestamp ) ],
75 [ 'rev_id' => $page->getLatest() ] );
76
77 $page->clear();
78 }
79
88 protected function assertEditedTextEquals( $expected, $actual, $msg = '' ) {
89 $this->assertEquals( rtrim( $expected ), rtrim( $actual ), $msg );
90 }
91
117 protected function assertEdit( $title, $baseText, $user = null, array $edit,
118 $expectedCode = null, $expectedText = null, $message = null
119 ) {
120 if ( is_string( $title ) ) {
121 $ns = $this->getDefaultWikitextNS();
122 $title = Title::newFromText( $title, $ns );
123 }
124 $this->assertNotNull( $title );
125
126 if ( is_string( $user ) ) {
127 $user = User::newFromName( $user );
128
129 if ( $user->getId() === 0 ) {
130 $user->addToDatabase();
131 }
132 }
133
135
136 if ( $baseText !== null ) {
138 $page->doEditContent( $content, "base text for test" );
139 $this->forceRevisionDate( $page, '20120101000000' );
140
141 // sanity check
142 $page->clear();
143 $currentText = ContentHandler::getContentText( $page->getContent() );
144
145 # EditPage rtrim() the user input, so we alter our expected text
146 # to reflect that.
147 $this->assertEditedTextEquals( $baseText, $currentText );
148 }
149
150 if ( $user == null ) {
151 $user = $GLOBALS['wgUser'];
152 } else {
153 $this->setMwGlobals( 'wgUser', $user );
154 }
155
156 if ( !isset( $edit['wpEditToken'] ) ) {
157 $edit['wpEditToken'] = $user->getEditToken();
158 }
159
160 if ( !isset( $edit['wpEdittime'] ) ) {
161 $edit['wpEdittime'] = $page->exists() ? $page->getTimestamp() : '';
162 }
163
164 if ( !isset( $edit['wpStarttime'] ) ) {
165 $edit['wpStarttime'] = wfTimestampNow();
166 }
167
168 $req = new FauxRequest( $edit, true ); // session ??
169
170 $article = new Article( $title );
171 $article->getContext()->setTitle( $title );
172 $ep = new EditPage( $article );
173 $ep->setContextTitle( $title );
174 $ep->importFormData( $req );
175
176 $bot = isset( $edit['bot'] ) ? (bool)$edit['bot'] : false;
177
178 // this is where the edit happens!
179 // Note: don't want to use EditPage::AttemptSave, because it messes with $wgOut
180 // and throws exceptions like PermissionsError
181 $status = $ep->internalAttemptSave( $result, $bot );
182
183 if ( $expectedCode !== null ) {
184 // check edit code
185 $this->assertEquals( $expectedCode, $status->value,
186 "Expected result code mismatch. $message" );
187 }
188
190
191 if ( $expectedText !== null ) {
192 // check resulting page text
193 $content = $page->getContent();
195
196 # EditPage rtrim() the user input, so we alter our expected text
197 # to reflect that.
198 $this->assertEditedTextEquals( $expectedText, $text,
199 "Expected article text mismatch. $message" );
200 }
201
202 return $page;
203 }
204
205 public static function provideCreatePages() {
206 return [
207 [ 'expected article being created',
208 'EditPageTest_testCreatePage',
209 null,
210 'Hello World!',
212 'Hello World!'
213 ],
214 [ 'expected article not being created if empty',
215 'EditPageTest_testCreatePage',
216 null,
217 '',
219 null
220 ],
221 [ 'expected MediaWiki: page being created',
222 'MediaWiki:January',
223 'UTSysop',
224 'Not January',
226 'Not January'
227 ],
228 [ 'expected not-registered MediaWiki: page not being created if empty',
229 'MediaWiki:EditPageTest_testCreatePage',
230 'UTSysop',
231 '',
233 null
234 ],
235 [ 'expected registered MediaWiki: page being created even if empty',
236 'MediaWiki:January',
237 'UTSysop',
238 '',
240 ''
241 ],
242 [ 'expected registered MediaWiki: page whose default content is empty'
243 . ' not being created if empty',
244 'MediaWiki:Ipb-default-expiry',
245 'UTSysop',
246 '',
248 ''
249 ],
250 [ 'expected MediaWiki: page not being created if text equals default message',
251 'MediaWiki:January',
252 'UTSysop',
253 'January',
255 null
256 ],
257 [ 'expected empty article being created',
258 'EditPageTest_testCreatePage',
259 null,
260 '',
262 '',
263 true
264 ],
265 ];
266 }
267
272 public function testCreatePage(
273 $desc, $pageTitle, $user, $editText, $expectedCode, $expectedText, $ignoreBlank = false
274 ) {
275 $checkId = null;
276
277 $this->setMwGlobals( 'wgHooks', [
278 'PageContentInsertComplete' => [ function (
280 $summary, $minor, $u1, $u2, &$flags, Revision $revision
281 ) {
282 // types/refs checked
283 } ],
284 'PageContentSaveComplete' => [ function (
286 $summary, $minor, $u1, $u2, &$flags, Revision $revision,
287 Status &$status, $baseRevId
288 ) use ( &$checkId ) {
289 $checkId = $status->value['revision']->getId();
290 // types/refs checked
291 } ],
292 ] );
293
294 $edit = [ 'wpTextbox1' => $editText ];
295 if ( $ignoreBlank ) {
296 $edit['wpIgnoreBlankArticle'] = 1;
297 }
298
299 $page = $this->assertEdit( $pageTitle, null, $user, $edit, $expectedCode, $expectedText, $desc );
300
301 if ( $expectedCode != EditPage::AS_BLANK_ARTICLE ) {
302 $latest = $page->getLatest();
303 $page->doDeleteArticleReal( $pageTitle );
304
305 $this->assertGreaterThan( 0, $latest, "Page revision ID updated in object" );
306 $this->assertEquals( $latest, $checkId, "Revision in Status for hook" );
307 }
308 }
309
314 public function testCreatePageTrx(
315 $desc, $pageTitle, $user, $editText, $expectedCode, $expectedText, $ignoreBlank = false
316 ) {
317 $checkIds = [];
318 $this->setMwGlobals( 'wgHooks', [
319 'PageContentInsertComplete' => [ function (
321 $summary, $minor, $u1, $u2, &$flags, Revision $revision
322 ) {
323 // types/refs checked
324 } ],
325 'PageContentSaveComplete' => [ function (
327 $summary, $minor, $u1, $u2, &$flags, Revision $revision,
328 Status &$status, $baseRevId
329 ) use ( &$checkIds ) {
330 $checkIds[] = $status->value['revision']->getId();
331 // types/refs checked
332 } ],
333 ] );
334
335 wfGetDB( DB_MASTER )->begin( __METHOD__ );
336
337 $edit = [ 'wpTextbox1' => $editText ];
338 if ( $ignoreBlank ) {
339 $edit['wpIgnoreBlankArticle'] = 1;
340 }
341
342 $page = $this->assertEdit(
343 $pageTitle, null, $user, $edit, $expectedCode, $expectedText, $desc );
344
345 $pageTitle2 = (string)$pageTitle . '/x';
346 $page2 = $this->assertEdit(
347 $pageTitle2, null, $user, $edit, $expectedCode, $expectedText, $desc );
348
349 wfGetDB( DB_MASTER )->commit( __METHOD__ );
350
351 $this->assertEquals( 0, DeferredUpdates::pendingUpdatesCount(), 'No deferred updates' );
352
353 if ( $expectedCode != EditPage::AS_BLANK_ARTICLE ) {
354 $latest = $page->getLatest();
355 $page->doDeleteArticleReal( $pageTitle );
356
357 $this->assertGreaterThan( 0, $latest, "Page #1 revision ID updated in object" );
358 $this->assertEquals( $latest, $checkIds[0], "Revision #1 in Status for hook" );
359
360 $latest2 = $page2->getLatest();
361 $page2->doDeleteArticleReal( $pageTitle2 );
362
363 $this->assertGreaterThan( 0, $latest2, "Page #2 revision ID updated in object" );
364 $this->assertEquals( $latest2, $checkIds[1], "Revision #2 in Status for hook" );
365 }
366 }
367
368 public function testUpdatePage() {
369 $checkIds = [];
370
371 $this->setMwGlobals( 'wgHooks', [
372 'PageContentInsertComplete' => [ function (
374 $summary, $minor, $u1, $u2, &$flags, Revision $revision
375 ) {
376 // types/refs checked
377 } ],
378 'PageContentSaveComplete' => [ function (
380 $summary, $minor, $u1, $u2, &$flags, Revision $revision,
381 Status &$status, $baseRevId
382 ) use ( &$checkIds ) {
383 $checkIds[] = $status->value['revision']->getId();
384 // types/refs checked
385 } ],
386 ] );
387
388 $text = "one";
389 $edit = [
390 'wpTextbox1' => $text,
391 'wpSummary' => 'first update',
392 ];
393
394 $page = $this->assertEdit( 'EditPageTest_testUpdatePage', "zero", null, $edit,
396 "expected successfull update with given text" );
397 $this->assertGreaterThan( 0, $checkIds[0], "First event rev ID set" );
398
399 $this->forceRevisionDate( $page, '20120101000000' );
400
401 $text = "two";
402 $edit = [
403 'wpTextbox1' => $text,
404 'wpSummary' => 'second update',
405 ];
406
407 $this->assertEdit( 'EditPageTest_testUpdatePage', null, null, $edit,
409 "expected successfull update with given text" );
410 $this->assertGreaterThan( 0, $checkIds[1], "Second edit hook rev ID set" );
411 $this->assertGreaterThan( $checkIds[0], $checkIds[1], "Second event rev ID is higher" );
412 }
413
414 public function testUpdatePageTrx() {
415 $text = "one";
416 $edit = [
417 'wpTextbox1' => $text,
418 'wpSummary' => 'first update',
419 ];
420
421 $page = $this->assertEdit( 'EditPageTest_testTrxUpdatePage', "zero", null, $edit,
423 "expected successfull update with given text" );
424
425 $this->forceRevisionDate( $page, '20120101000000' );
426
427 $checkIds = [];
428 $this->setMwGlobals( 'wgHooks', [
429 'PageContentSaveComplete' => [ function (
431 $summary, $minor, $u1, $u2, &$flags, Revision $revision,
432 Status &$status, $baseRevId
433 ) use ( &$checkIds ) {
434 $checkIds[] = $status->value['revision']->getId();
435 // types/refs checked
436 } ],
437 ] );
438
439 wfGetDB( DB_MASTER )->begin( __METHOD__ );
440
441 $text = "two";
442 $edit = [
443 'wpTextbox1' => $text,
444 'wpSummary' => 'second update',
445 ];
446
447 $this->assertEdit( 'EditPageTest_testTrxUpdatePage', null, null, $edit,
449 "expected successfull update with given text" );
450
451 $text = "three";
452 $edit = [
453 'wpTextbox1' => $text,
454 'wpSummary' => 'third update',
455 ];
456
457 $this->assertEdit( 'EditPageTest_testTrxUpdatePage', null, null, $edit,
459 "expected successfull update with given text" );
460
461 wfGetDB( DB_MASTER )->commit( __METHOD__ );
462
463 $this->assertGreaterThan( 0, $checkIds[0], "First event rev ID set" );
464 $this->assertGreaterThan( 0, $checkIds[1], "Second edit hook rev ID set" );
465 $this->assertGreaterThan( $checkIds[0], $checkIds[1], "Second event rev ID is higher" );
466 }
467
468 public static function provideSectionEdit() {
469 $text = 'Intro
470
471== one ==
472first section.
473
474== two ==
475second section.
476';
477
478 $sectionOne = '== one ==
479hello
480';
481
482 $newSection = '== new section ==
483
484hello
485';
486
487 $textWithNewSectionOne = preg_replace(
488 '/== one ==.*== two ==/ms',
489 "$sectionOne\n== two ==", $text
490 );
491
492 $textWithNewSectionAdded = "$text\n$newSection";
493
494 return [
495 [ # 0
496 $text,
497 '',
498 'hello',
499 'replace all',
500 'hello'
501 ],
502
503 [ # 1
504 $text,
505 '1',
506 $sectionOne,
507 'replace first section',
508 $textWithNewSectionOne,
509 ],
510
511 [ # 2
512 $text,
513 'new',
514 'hello',
515 'new section',
516 $textWithNewSectionAdded,
517 ],
518 ];
519 }
520
525 public function testSectionEdit( $base, $section, $text, $summary, $expected ) {
526 $edit = [
527 'wpTextbox1' => $text,
528 'wpSummary' => $summary,
529 'wpSection' => $section,
530 ];
531
532 $this->assertEdit( 'EditPageTest_testSectionEdit', $base, null, $edit,
534 "expected successfull update of section" );
535 }
536
537 public static function provideAutoMerge() {
538 $tests = [];
539
540 $tests[] = [ # 0: plain conflict
541 "Elmo", # base edit user
542 "one\n\ntwo\n\nthree\n",
543 [ # adam's edit
544 'wpStarttime' => 1,
545 'wpTextbox1' => "ONE\n\ntwo\n\nthree\n",
546 ],
547 [ # berta's edit
548 'wpStarttime' => 2,
549 'wpTextbox1' => "(one)\n\ntwo\n\nthree\n",
550 ],
552 "ONE\n\ntwo\n\nthree\n", # expected text
553 'expected edit conflict', # message
554 ];
555
556 $tests[] = [ # 1: successful merge
557 "Elmo", # base edit user
558 "one\n\ntwo\n\nthree\n",
559 [ # adam's edit
560 'wpStarttime' => 1,
561 'wpTextbox1' => "ONE\n\ntwo\n\nthree\n",
562 ],
563 [ # berta's edit
564 'wpStarttime' => 2,
565 'wpTextbox1' => "one\n\ntwo\n\nTHREE\n",
566 ],
568 "ONE\n\ntwo\n\nTHREE\n", # expected text
569 'expected automatic merge', # message
570 ];
571
572 $text = "Intro\n\n";
573 $text .= "== first section ==\n\n";
574 $text .= "one\n\ntwo\n\nthree\n\n";
575 $text .= "== second section ==\n\n";
576 $text .= "four\n\nfive\n\nsix\n\n";
577
578 // extract the first section.
579 $section = preg_replace( '/.*(== first section ==.*)== second section ==.*/sm', '$1', $text );
580
581 // generate expected text after merge
582 $expected = str_replace( 'one', 'ONE', str_replace( 'three', 'THREE', $text ) );
583
584 $tests[] = [ # 2: merge in section
585 "Elmo", # base edit user
586 $text,
587 [ # adam's edit
588 'wpStarttime' => 1,
589 'wpTextbox1' => str_replace( 'one', 'ONE', $section ),
590 'wpSection' => '1'
591 ],
592 [ # berta's edit
593 'wpStarttime' => 2,
594 'wpTextbox1' => str_replace( 'three', 'THREE', $section ),
595 'wpSection' => '1'
596 ],
598 $expected, # expected text
599 'expected automatic section merge', # message
600 ];
601
602 // see whether it makes a difference who did the base edit
603 $testsWithAdam = array_map( function ( $test ) {
604 $test[0] = 'Adam'; // change base edit user
605 return $test;
606 }, $tests );
607
608 $testsWithBerta = array_map( function ( $test ) {
609 $test[0] = 'Berta'; // change base edit user
610 return $test;
611 }, $tests );
612
613 return array_merge( $tests, $testsWithAdam, $testsWithBerta );
614 }
615
620 public function testAutoMerge( $baseUser, $text, $adamsEdit, $bertasEdit,
621 $expectedCode, $expectedText, $message = null
622 ) {
624
625 // create page
626 $ns = $this->getDefaultWikitextNS();
627 $title = Title::newFromText( 'EditPageTest_testAutoMerge', $ns );
629
630 if ( $page->exists() ) {
631 $page->doDeleteArticle( "clean slate for testing" );
632 }
633
634 $baseEdit = [
635 'wpTextbox1' => $text,
636 ];
637
638 $page = $this->assertEdit( 'EditPageTest_testAutoMerge', null,
639 $baseUser, $baseEdit, null, null, __METHOD__ );
640
641 $this->forceRevisionDate( $page, '20120101000000' );
642
643 $edittime = $page->getTimestamp();
644
645 // start timestamps for conflict detection
646 if ( !isset( $adamsEdit['wpStarttime'] ) ) {
647 $adamsEdit['wpStarttime'] = 1;
648 }
649
650 if ( !isset( $bertasEdit['wpStarttime'] ) ) {
651 $bertasEdit['wpStarttime'] = 2;
652 }
653
655 $adamsTime = wfTimestamp(
656 TS_MW,
657 (int)wfTimestamp( TS_UNIX, $starttime ) + (int)$adamsEdit['wpStarttime']
658 );
659 $bertasTime = wfTimestamp(
660 TS_MW,
661 (int)wfTimestamp( TS_UNIX, $starttime ) + (int)$bertasEdit['wpStarttime']
662 );
663
664 $adamsEdit['wpStarttime'] = $adamsTime;
665 $bertasEdit['wpStarttime'] = $bertasTime;
666
667 $adamsEdit['wpSummary'] = 'Adam\'s edit';
668 $bertasEdit['wpSummary'] = 'Bertas\'s edit';
669
670 $adamsEdit['wpEdittime'] = $edittime;
671 $bertasEdit['wpEdittime'] = $edittime;
672
673 // first edit
674 $this->assertEdit( 'EditPageTest_testAutoMerge', null, 'Adam', $adamsEdit,
675 EditPage::AS_SUCCESS_UPDATE, null, "expected successfull update" );
676
677 // second edit
678 $this->assertEdit( 'EditPageTest_testAutoMerge', null, 'Berta', $bertasEdit,
679 $expectedCode, $expectedText, $message );
680 }
681
686 $title = Title::newFromText( 'Dummy:NonTextPageForEditPage' );
688
689 $article = new Article( $title );
690 $article->getContext()->setTitle( $title );
691 $ep = new EditPage( $article );
692 $ep->setContextTitle( $title );
693
694 $user = $GLOBALS['wgUser'];
695
696 $edit = [
697 'wpTextbox1' => serialize( 'non-text content' ),
698 'wpEditToken' => $user->getEditToken(),
699 'wpEdittime' => '',
700 'wpStarttime' => wfTimestampNow()
701 ];
702
703 $req = new FauxRequest( $edit, true );
704 $ep->importFormData( $req );
705
706 $this->setExpectedException(
707 'MWException',
708 'This content model is not supported: testing'
709 );
710
711 $ep->internalAttemptSave( $result, false );
712 }
713
714}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
serialize()
$GLOBALS['IP']
$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.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
$starttime
Definition api.php:40
Class for viewing MediaWiki article and history.
Definition Article.php:34
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
static getContentText(Content $content=null)
Convenience function for getting flat text from a Content object.
testAutoMerge( $baseUser, $text, $adamsEdit, $bertasEdit, $expectedCode, $expectedText, $message=null)
provideAutoMerge EditPage
assertEdit( $title, $baseText, $user=null, array $edit, $expectedCode=null, $expectedText=null, $message=null)
Performs an edit and checks the result.
testCreatePage( $desc, $pageTitle, $user, $editText, $expectedCode, $expectedText, $ignoreBlank=false)
provideCreatePages EditPage
forceRevisionDate(WikiPage $page, $timestamp)
assertEditedTextEquals( $expected, $actual, $msg='')
User input text is passed to rtrim() by edit page.
testCheckDirectEditingDisallowed_forNonTextContent()
@depends testAutoMerge
static provideCreatePages()
static provideSectionEdit()
static provideAutoMerge()
testSectionEdit( $base, $section, $text, $summary, $expected)
provideSectionEdit EditPage
testCreatePageTrx( $desc, $pageTitle, $user, $editText, $expectedCode, $expectedText, $ignoreBlank=false)
provideCreatePages EditPage
testExtractSectionTitle( $section, $title)
provideExtractSectionTitle EditPage::extractSectionTitle
static provideExtractSectionTitle()
The edit page/HTML interface (split from Article) The actual database and text munging is still in Ar...
Definition EditPage.php:42
const AS_CONFLICT_DETECTED
Status: (non-resolvable) edit conflict.
Definition EditPage.php:113
const AS_BLANK_ARTICLE
Status: user tried to create a blank page and wpIgnoreBlankArticle == false.
Definition EditPage.php:108
static extractSectionTitle( $text)
Extract the section title from current section text, if any.
const AS_SUCCESS_UPDATE
Status: Article successfully updated.
Definition EditPage.php:46
const AS_SUCCESS_NEW_ARTICLE
Status: Article successfully created.
Definition EditPage.php:51
WebRequest clone which takes values from a provided array.
static clear( $name)
Clears hooks registered via Hooks::register().
Definition Hooks.php:66
Base class that store and restore the Language objects.
getDefaultWikitextNS()
Returns the ID of a namespace that defaults to Wikitext.
setMwGlobals( $pairs, $value=null)
markTestSkippedIfNoDiff3()
Check, if $wgDiff3 is set and ready to merge Will mark the calling test as skipped,...
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:40
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:48
Class representing a MediaWiki article and history.
Definition WikiPage.php:32
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition WikiPage.php:115
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
Definition design.txt:57
when a variable name is used in a function
Definition design.txt:94
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition design.txt:18
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same user
Wikitext formatted, in the key only.
this hook is for auditing only $req
Definition hooks.txt:1010
and how to run hooks for an and one after Each event has a preferably in CamelCase For ArticleDelete hook A clump of code and data that should be run when an event happens This can be either a function and a chunk of or an object and a method hook function The function part of a third party developers and local administrators to define code that will be run at certain points in the mainline code
Definition hooks.txt:28
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition hooks.txt:1049
the array() calling protocol came about after MediaWiki 1.4rc1.
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
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:Associative array mapping language codes to prefixed links of the form "language:title". & $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:1937
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
Definition hooks.txt:183
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:986
either a plain
Definition hooks.txt:1990
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a message
Definition hooks.txt:2097
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content $content
Definition hooks.txt:1094
null for the local wiki Added in
Definition hooks.txt:1558
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition hooks.txt:2710
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition hooks.txt:1950
Using a hook running we can avoid having all this option specific stuff in our mainline code Using the function array $article
Definition hooks.txt:78
namespace are movable Hooks may change this value to override the return value of MWNamespace::isMovable(). 'NewDifferenceEngine' do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
Definition hooks.txt:2534
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template $section
Definition hooks.txt:2901
processing should stop and the error should be shown to the user * false
Definition hooks.txt:189
if( $limit) $timestamp
$summary
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to merge
Definition LICENSE.txt:11
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
Base interface for content objects.
Definition Content.php:34
you have access to all of the normal MediaWiki so you can get a DB use the cache
const DB_MASTER
Definition defines.php:23
const TS_UNIX
Unix time - the number of seconds since 1970-01-01 00:00:00 UTC.
Definition defines.php:6
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
Definition defines.php:11