MediaWiki  REL1_31
Go to the documentation of this file.
1 <?php
33  public static function provideValidNames() {
34  return [
35  [ 'foo' ],
36  [ 'foo-bar' ],
37  [ 'foo_bar' ],
38  [ 'FOO-BAR' ],
39  [ 'foo bar' ]
40  ];
41  }
43  public static function provideBadNames() {
44  return [ [ "foo<bar" ], [ "foo>bar" ], [ "foo\nbar" ], [ "foo\rbar" ] ];
45  }
47  private function getParserOptions() {
50  return $popt;
51  }
56  public function testTagHooks( $tag ) {
58  $parser = new Parser( $wgParserConf );
60  $parser->setHook( $tag, [ $this, 'tagCallback' ] );
61  $parserOutput = $parser->parse(
62  "Foo<$tag>Bar</$tag>Baz",
63  Title::newFromText( 'Test' ),
64  $this->getParserOptions()
65  );
66  $this->assertEquals( "<p>FooOneBaz\n</p>", $parserOutput->getText( [ 'unwrap' => true ] ) );
68  $parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle
69  }
75  public function testBadTagHooks( $tag ) {
77  $parser = new Parser( $wgParserConf );
79  $parser->setHook( $tag, [ $this, 'tagCallback' ] );
80  $parser->parse(
81  "Foo<$tag>Bar</$tag>Baz",
82  Title::newFromText( 'Test' ),
83  $this->getParserOptions()
84  );
85  $this->fail( 'Exception not thrown.' );
86  }
91  public function testFunctionTagHooks( $tag ) {
93  $parser = new Parser( $wgParserConf );
95  $parser->setFunctionTagHook( $tag, [ $this, 'functionTagCallback' ], 0 );
96  $parserOutput = $parser->parse(
97  "Foo<$tag>Bar</$tag>Baz",
98  Title::newFromText( 'Test' ),
99  $this->getParserOptions()
100  );
101  $this->assertEquals( "<p>FooOneBaz\n</p>", $parserOutput->getText( [ 'unwrap' => true ] ) );
103  $parser->mPreprocessor = null; # Break the Parser <-> Preprocessor cycle
104  }
110  public function testBadFunctionTagHooks( $tag ) {
112  $parser = new Parser( $wgParserConf );
114  $parser->setFunctionTagHook(
115  $tag,
116  [ $this, 'functionTagCallback' ],
118  );
119  $parser->parse(
120  "Foo<$tag>Bar</$tag>Baz",
121  Title::newFromText( 'Test' ),
122  $this->getParserOptions()
123  );
124  $this->fail( 'Exception not thrown.' );
125  }
127  function tagCallback( $text, $params, $parser ) {
128  return str_rot13( $text );
129  }
131  function functionTagCallback( &$parser, $frame, $code, $attribs ) {
132  return str_rot13( $code );
133  }
134 }
static provideValidNames()
Definition: TagHooksTest.php:33
testBadFunctionTagHooks( $tag)
provideBadNames MWException
Definition: TagHooksTest.php:110
Database Parser.
Definition: TagHooksTest.php:32
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:273
Parser configuration.
Definition: DefaultSettings.php:4170
tagCallback( $text, $params, $parser)
Definition: TagHooksTest.php:127
Definition: styleTest.css.php:40
Definition: Parser.php:86
testBadTagHooks( $tag)
provideBadNames MWException
Definition: TagHooksTest.php:75
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
Definition: Preprocessor.php:29
static newFromUserAndLang(User $user, Language $lang)
Get a ParserOptions object from a given user and language.
Definition: ParserOptions.php:992
do that in ParserLimitReportFormat instead $parser
Definition: hooks.txt:2603
Definition: MediaWikiTestCase.php:17
Definition: TagHooksTest.php:47
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:95
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 an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition: hooks.txt:2014
testFunctionTagHooks( $tag)
Definition: TagHooksTest.php:91
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
Definition: Parser.php:70
functionTagCallback(&$parser, $frame, $code, $attribs)
Definition: TagHooksTest.php:131
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
Definition: hooks.txt:865
testTagHooks( $tag)
Definition: TagHooksTest.php:56
static provideBadNames()
Definition: TagHooksTest.php:43
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:53
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:57