Chad has uploaded a new change for review.
https://gerrit.wikimedia.org/r/111567
Change subject: Move blame for $wgTitle up one level to getUserSig()
......................................................................
Move blame for $wgTitle up one level to getUserSig()
cleanSig() doesn't have any callers outside of this class
and tests, so it's easily fixed to not use the $wgTitle.
getUserSig() has a bunch of callers, none of which have ever
used the optional second or third parameters, so remove them.
Instead, add a new optional second parameter for a Title so
we can eventually get rid of $wgTitle here too.
Change-Id: Ie2e841622c331fb2cc3b4ff3d5a6bbebb83a7352
---
M includes/parser/Parser.php
M tests/phpunit/includes/ExtraParserTest.php
2 files changed, 16 insertions(+), 23 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/67/111567/1
diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php
index 340f462..1d560a9 100644
--- a/includes/parser/Parser.php
+++ b/includes/parser/Parser.php
@@ -4678,27 +4678,16 @@
* Do not reuse this parser instance after calling getUserSig(),
* as it may have changed if it's the $wgParser.
*
- * @param $user User
- * @param string|bool $nickname nickname to use or false to use user's
default nickname
- * @param $fancySig Boolean|null whether the nicknname is the complete
signature
- * or null to use default value
+ * @param User $user User to build the signature for
+ * @param Title|null $title Title to parse with
* @return string
*/
- function getUserSig( &$user, $nickname = false, $fancySig = null ) {
+ function getUserSig( &$user, $title = null ) {
global $wgMaxSigChars;
$username = $user->getName();
-
- # If not given, retrieve from the user object.
- if ( $nickname === false ) {
- $nickname = $user->getOption( 'nickname' );
- }
-
- if ( is_null( $fancySig ) ) {
- $fancySig = $user->getBoolOption( 'fancysig' );
- }
-
- $nickname = $nickname == null ? $username : $nickname;
+ $nickname = $user->getOption( 'nickname', $username );
+ $fancySig = $user->getBoolOption( 'fancysig' );
if ( mb_strlen( $nickname ) > $wgMaxSigChars ) {
$nickname = $username;
@@ -4707,7 +4696,11 @@
# Sig. might contain markup; validate this
if ( $this->validateSig( $nickname ) !== false ) {
# Validated; clean up (if needed) and return it
- return $this->cleanSig( $nickname, true );
+ if ( !$title ) {
+ global $wgTitle;
+ $title = $wgTitle;
+ }
+ return $this->cleanSig( $nickname, $wgTitle,
true );
} else {
# Failed to validate; fall back to the default
$nickname = $username;
@@ -4742,14 +4735,14 @@
* 1) Strip ~~~, ~~~~ and ~~~~~ out of signatures @see cleanSigInSig
* 2) Substitute all transclusions
*
- * @param $text String
+ * @param string $text
+ * @param Title $title
* @param bool $parsing Whether we're cleaning (preferences save) or
parsing
* @return String: signature text
*/
- public function cleanSig( $text, $parsing = false ) {
+ public function cleanSig( $text, $title, $parsing = false ) {
if ( !$parsing ) {
- global $wgTitle;
- $this->startParse( $wgTitle, new ParserOptions,
self::OT_PREPROCESS, true );
+ $this->startParse( $title, new ParserOptions,
self::OT_PREPROCESS, true );
}
# Option to disable this feature
diff --git a/tests/phpunit/includes/ExtraParserTest.php
b/tests/phpunit/includes/ExtraParserTest.php
index dc19154..8163982 100644
--- a/tests/phpunit/includes/ExtraParserTest.php
+++ b/tests/phpunit/includes/ExtraParserTest.php
@@ -82,7 +82,7 @@
*/
public function testCleanSig() {
$title = Title::newFromText( __FUNCTION__ );
- $outputText = $this->parser->cleanSig( "{{Foo}} ~~~~" );
+ $outputText = $this->parser->cleanSig( "{{Foo}} ~~~~", $title );
$this->assertEquals( "{{SUBST:Foo}} ", $outputText );
}
@@ -95,7 +95,7 @@
$this->setMwGlobals( 'wgCleanSignatures', false );
$title = Title::newFromText( __FUNCTION__ );
- $outputText = $this->parser->cleanSig( "{{Foo}} ~~~~" );
+ $outputText = $this->parser->cleanSig( "{{Foo}} ~~~~", $title );
$this->assertEquals( "{{Foo}} ~~~~", $outputText );
}
--
To view, visit https://gerrit.wikimedia.org/r/111567
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie2e841622c331fb2cc3b4ff3d5a6bbebb83a7352
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Chad <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits