r105377 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105376‎ | r105377 | r105378 >
Date:23:07, 6 December 2011
Author:demon
Status:ok
Tags:
Comment:
Minor tweaks to cleanSig(inSig)
* Make cleanSig public, since it's a declared entry point per class docs
* Make cleanSigInSig public static, added 2 more test cases for it
Modified paths:
  • /trunk/phase3/includes/Preferences.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/ExtraParserTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/ExtraParserTest.php
@@ -93,14 +93,20 @@
9494
9595 /**
9696 * cleanSigInSig() just removes tildes
 97+ * @dataProvider provideStringsForCleanSigInSig
9798 */
98 - function testCleanSigInSig() {
99 - $title = Title::newFromText( __FUNCTION__ );
100 - $outputText = $this->parser->cleanSigInSig( "{{Foo}} ~~~~" );
101 -
102 - $this->assertEquals( "{{Foo}} ", $outputText );
 99+ function testCleanSigInSig( $in, $out ) {
 100+ $this->assertEquals( Parser::cleanSigInSig( $in), $out );
103101 }
104102
 103+ function provideStringsForCleanSigInSig() {
 104+ return array(
 105+ array( "{{Foo}} ~~~~", "{{Foo}} " ),
 106+ array( "~~~", "" ),
 107+ array( "~~~~~", "" ),
 108+ );
 109+ }
 110+
105111 function testGetSection() {
106112 $outputText2 = $this->parser->getSection( "Section 0\n== Heading 1 ==\nSection 1\n=== Heading 2 ===\nSection 2\n== Heading 3 ==\nSection 3\n", 2 );
107113 $outputText1 = $this->parser->getSection( "Section 0\n== Heading 1 ==\nSection 1\n=== Heading 2 ===\nSection 2\n== Heading 3 ==\nSection 3\n", 1 );
Index: trunk/phase3/includes/parser/Parser.php
@@ -4417,7 +4417,7 @@
44184418 }
44194419
44204420 # Make sure nickname doesnt get a sig in a sig
4421 - $nickname = $this->cleanSigInSig( $nickname );
 4421+ $nickname = self::cleanSigInSig( $nickname );
44224422
44234423 # If we're still here, make it a link to the user page
44244424 $userText = wfEscapeWikiText( $username );
@@ -4447,7 +4447,7 @@
44484448 * @param $parsing bool Whether we're cleaning (preferences save) or parsing
44494449 * @return String: signature text
44504450 */
4451 - function cleanSig( $text, $parsing = false ) {
 4451+ public function cleanSig( $text, $parsing = false ) {
44524452 if ( !$parsing ) {
44534453 global $wgTitle;
44544454 $this->startParse( $wgTitle, new ParserOptions, self::OT_PREPROCESS, true );
@@ -4465,7 +4465,7 @@
44664466 $substText = '{{' . $substWord->getSynonym( 0 );
44674467
44684468 $text = preg_replace( $substRegex, $substText, $text );
4469 - $text = $this->cleanSigInSig( $text );
 4469+ $text = self::cleanSigInSig( $text );
44704470 $dom = $this->preprocessToDom( $text );
44714471 $frame = $this->getPreprocessor()->newFrame();
44724472 $text = $frame->expand( $dom );
@@ -4483,7 +4483,7 @@
44844484 * @param $text String
44854485 * @return String: signature text with /~{3,5}/ removed
44864486 */
4487 - function cleanSigInSig( $text ) {
 4487+ public static function cleanSigInSig( $text ) {
44884488 $text = preg_replace( '/~{3,5}/', '', $text );
44894489 return $text;
44904490 }
Index: trunk/phase3/includes/Preferences.php
@@ -1186,12 +1186,12 @@
11871187 * @return string
11881188 */
11891189 static function cleanSignature( $signature, $alldata, $form ) {
1190 - global $wgParser;
11911190 if ( isset( $alldata['fancysig'] ) && $alldata['fancysig'] ) {
 1191+ global $wgParser;
11921192 $signature = $wgParser->cleanSig( $signature );
11931193 } else {
11941194 // When no fancy sig used, make sure ~{3,5} get removed.
1195 - $signature = $wgParser->cleanSigInSig( $signature );
 1195+ $signature = Parser::cleanSigInSig( $signature );
11961196 }
11971197
11981198 return $signature;

Follow-up revisions

RevisionCommit summaryAuthorDate
r105378Use static Parser::cleanSigInSig() rather than $wgParser object, ping r105377demon23:09, 6 December 2011
r1062581.18wmf1: MFT r105377catrope22:16, 14 December 2011

Status & tagging log