20 'wgExtraNamespaces' => $wgExtraNamespaces,
32 MWNamespace::getCanonicalNamespaces(
true ); # reset
namespace cache
42 $this->assertEquals(
$title, $extracted );
48 "== Test ==\n\nJust a test section.",
52 "An initial section, no header.",
56 "An initial section with a fake heder (bug 32617)\n\n== Test == ??\nwtf",
60 "== Section ==\nfollowed by a fake == Non-section == ??\nnoooo",
64 "== Section== \t\r\n followed by whitespace (bug 35051)",
73 $dbw->update(
'revision',
74 [
'rev_timestamp' => $dbw->timestamp(
$timestamp ) ],
75 [
'rev_id' =>
$page->getLatest() ] );
89 $this->assertEquals( rtrim( $expected ), rtrim( $actual ), $msg );
118 $expectedCode =
null, $expectedText =
null, $message =
null
120 if ( is_string(
$title ) ) {
124 $this->assertNotNull(
$title );
126 if ( is_string(
$user ) ) {
129 if (
$user->getId() === 0 ) {
130 $user->addToDatabase();
136 if ( $baseText !==
null ) {
145 # EditPage rtrim() the user input, so we alter our expected text
150 if (
$user ==
null ) {
156 if ( !isset( $edit[
'wpEditToken'] ) ) {
157 $edit[
'wpEditToken'] =
$user->getEditToken();
160 if ( !isset( $edit[
'wpEdittime'] ) ) {
161 $edit[
'wpEdittime'] =
$page->exists() ?
$page->getTimestamp() :
'';
164 if ( !isset( $edit[
'wpStarttime'] ) ) {
173 $ep->setContextTitle(
$title );
174 $ep->importFormData(
$req );
176 $bot = isset( $edit[
'bot'] ) ? (bool)$edit[
'bot'] :
false;
183 if ( $expectedCode !==
null ) {
185 $this->assertEquals( $expectedCode,
$status->value,
186 "Expected result code mismatch. $message" );
191 if ( $expectedText !==
null ) {
196 # EditPage rtrim() the user input, so we alter our expected text
199 "Expected article text mismatch. $message" );
207 [
'expected article being created',
208 'EditPageTest_testCreatePage',
214 [
'expected article not being created if empty',
215 'EditPageTest_testCreatePage',
221 [
'expected MediaWiki: page being created',
228 [
'expected not-registered MediaWiki: page not being created if empty',
229 'MediaWiki:EditPageTest_testCreatePage',
235 [
'expected registered MediaWiki: page being created even if empty',
242 [
'expected registered MediaWiki: page whose default content is empty'
243 .
' not being created if empty',
244 'MediaWiki:Ipb-default-expiry',
250 [
'expected MediaWiki: page not being created if text equals default message',
257 [
'expected empty article being created',
258 'EditPageTest_testCreatePage',
273 $desc, $pageTitle, $user, $editText, $expectedCode, $expectedText, $ignoreBlank =
false
278 'PageContentInsertComplete' => [
function (
284 'PageContentSaveComplete' => [
function (
288 )
use ( &$checkId ) {
289 $checkId =
$status->value[
'revision']->getId();
294 $edit = [
'wpTextbox1' => $editText ];
295 if ( $ignoreBlank ) {
296 $edit[
'wpIgnoreBlankArticle'] = 1;
299 $page = $this->
assertEdit( $pageTitle,
null,
$user, $edit, $expectedCode, $expectedText, $desc );
302 $latest =
$page->getLatest();
303 $page->doDeleteArticleReal( $pageTitle );
305 $this->assertGreaterThan( 0, $latest,
"Page revision ID updated in object" );
306 $this->assertEquals( $latest, $checkId,
"Revision in Status for hook" );
315 $desc, $pageTitle, $user, $editText, $expectedCode, $expectedText, $ignoreBlank =
false
319 'PageContentInsertComplete' => [
function (
325 'PageContentSaveComplete' => [
function (
329 )
use ( &$checkIds ) {
330 $checkIds[] =
$status->value[
'revision']->getId();
337 $edit = [
'wpTextbox1' => $editText ];
338 if ( $ignoreBlank ) {
339 $edit[
'wpIgnoreBlankArticle'] = 1;
343 $pageTitle,
null,
$user, $edit, $expectedCode, $expectedText, $desc );
345 $pageTitle2 = (
string)$pageTitle .
'/x';
347 $pageTitle2,
null,
$user, $edit, $expectedCode, $expectedText, $desc );
351 $this->assertEquals( 0, DeferredUpdates::pendingUpdatesCount(),
'No deferred updates' );
354 $latest =
$page->getLatest();
355 $page->doDeleteArticleReal( $pageTitle );
357 $this->assertGreaterThan( 0, $latest,
"Page #1 revision ID updated in object" );
358 $this->assertEquals( $latest, $checkIds[0],
"Revision #1 in Status for hook" );
360 $latest2 = $page2->getLatest();
361 $page2->doDeleteArticleReal( $pageTitle2 );
363 $this->assertGreaterThan( 0, $latest2,
"Page #2 revision ID updated in object" );
364 $this->assertEquals( $latest2, $checkIds[1],
"Revision #2 in Status for hook" );
372 'PageContentInsertComplete' => [
function (
378 'PageContentSaveComplete' => [
function (
382 )
use ( &$checkIds ) {
383 $checkIds[] =
$status->value[
'revision']->getId();
390 'wpTextbox1' => $text,
391 'wpSummary' =>
'first update',
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" );
403 'wpTextbox1' => $text,
404 'wpSummary' =>
'second update',
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" );
417 'wpTextbox1' => $text,
418 'wpSummary' =>
'first update',
421 $page = $this->
assertEdit(
'EditPageTest_testTrxUpdatePage',
"zero",
null, $edit,
423 "expected successfull update with given text" );
429 'PageContentSaveComplete' => [
function (
433 )
use ( &$checkIds ) {
434 $checkIds[] =
$status->value[
'revision']->getId();
443 'wpTextbox1' => $text,
444 'wpSummary' =>
'second update',
447 $this->
assertEdit(
'EditPageTest_testTrxUpdatePage',
null,
null, $edit,
449 "expected successfull update with given text" );
453 'wpTextbox1' => $text,
454 'wpSummary' =>
'third update',
457 $this->
assertEdit(
'EditPageTest_testTrxUpdatePage',
null,
null, $edit,
459 "expected successfull update with given text" );
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" );
478 $sectionOne =
'== one ==
482 $newSection =
'== new section ==
487 $textWithNewSectionOne = preg_replace(
488 '/== one ==.*== two ==/ms',
489 "$sectionOne\n== two ==", $text
492 $textWithNewSectionAdded =
"$text\n$newSection";
507 'replace first section',
508 $textWithNewSectionOne,
516 $textWithNewSectionAdded,
527 'wpTextbox1' => $text,
534 "expected successfull update of section" );
540 $tests[] = [ # 0:
plain conflict
541 "Elmo", # base edit
user
542 "one\n\ntwo\n\nthree\n",
545 'wpTextbox1
' => "ONE\n\ntwo\n\nthree\n",
549 'wpTextbox1' =>
"(one)\n\ntwo\n\nthree\n",
552 "ONE\n\ntwo\n\nthree\n", # expected
text
553 'expected edit conflict', #
message
556 $tests[] = [ # 1: successful
merge
557 "Elmo", # base edit
user
558 "one\n\ntwo\n\nthree\n",
561 'wpTextbox1
' => "ONE\n\ntwo\n\nthree\n",
565 'wpTextbox1' =>
"one\n\ntwo\n\nTHREE\n",
568 "ONE\n\ntwo\n\nTHREE\n", # expected
text
569 'expected automatic merge', #
message
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";
579 $section = preg_replace(
'/.*(== first section ==.*)== second section ==.*/sm',
'$1', $text );
582 $expected = str_replace(
'one',
'ONE', str_replace(
'three',
'THREE', $text ) );
584 $tests[] = [ # 2:
merge in section
585 "Elmo", # base edit
user
589 'wpTextbox1
' => str_replace( 'one
', 'ONE
', $section ),
594 'wpTextbox1' => str_replace(
'three',
'THREE',
$section ),
598 $expected, # expected
text
599 'expected automatic section merge', #
message
603 $testsWithAdam = array_map(
function ( $test ) {
608 $testsWithBerta = array_map(
function ( $test ) {
613 return array_merge( $tests, $testsWithAdam, $testsWithBerta );
621 $expectedCode, $expectedText, $message =
null
627 $title = Title::newFromText(
'EditPageTest_testAutoMerge', $ns );
630 if (
$page->exists() ) {
631 $page->doDeleteArticle(
"clean slate for testing" );
635 'wpTextbox1' => $text,
639 $baseUser, $baseEdit,
null,
null, __METHOD__ );
643 $edittime =
$page->getTimestamp();
646 if ( !isset( $adamsEdit[
'wpStarttime'] ) ) {
647 $adamsEdit[
'wpStarttime'] = 1;
650 if ( !isset( $bertasEdit[
'wpStarttime'] ) ) {
651 $bertasEdit[
'wpStarttime'] = 2;
664 $adamsEdit[
'wpStarttime'] = $adamsTime;
665 $bertasEdit[
'wpStarttime'] = $bertasTime;
667 $adamsEdit[
'wpSummary'] =
'Adam\'s edit';
668 $bertasEdit[
'wpSummary'] =
'Bertas\'s edit';
670 $adamsEdit[
'wpEdittime'] = $edittime;
671 $bertasEdit[
'wpEdittime'] = $edittime;
674 $this->
assertEdit(
'EditPageTest_testAutoMerge',
null,
'Adam', $adamsEdit,
678 $this->
assertEdit(
'EditPageTest_testAutoMerge',
null,
'Berta', $bertasEdit,
679 $expectedCode, $expectedText, $message );
686 $title = Title::newFromText(
'Dummy:NonTextPageForEditPage' );
692 $ep->setContextTitle(
$title );
697 'wpTextbox1' =>
serialize(
'non-text content' ),
698 'wpEditToken' =>
$user->getEditToken(),
704 $ep->importFormData(
$req );
706 $this->setExpectedException(
708 'This content model is not supported: testing'
711 $ep->internalAttemptSave(
$result,
false );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$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.
Class for viewing MediaWiki article and history.
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...
const AS_CONFLICT_DETECTED
Status: (non-resolvable) edit conflict.
const AS_BLANK_ARTICLE
Status: user tried to create a blank page and wpIgnoreBlankArticle == false.
static extractSectionTitle( $text)
Extract the section title from current section text, if any.
const AS_SUCCESS_UPDATE
Status: Article successfully updated.
const AS_SUCCESS_NEW_ARTICLE
Status: Article successfully created.
WebRequest clone which takes values from a provided array.
static clear( $name)
Clears hooks registered via Hooks::register().
Generic operation result class Has warning/error list, boolean status and arbitrary value.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Class representing a MediaWiki article and history.
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
when a variable name is used in a function
when a variable name is used in a it is silently declared as a new local masking the global
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
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
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
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
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
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
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
namespace and then decline to actually register it file or subcat img or subcat $title
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
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
null for the local wiki Added in
it s the revision text itself In either if gzip is the revision text is gzipped $flags
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
Using a hook running we can avoid having all this option specific stuff in our mainline code Using the function array $article
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
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template $section
processing should stop and the error should be shown to the user * false
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
Base interface for content objects.
you have access to all of the normal MediaWiki so you can get a DB use the cache
const TS_UNIX
Unix time - the number of seconds since 1970-01-01 00:00:00 UTC.
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)