From: Kunal Mehta Date: Thu, 29 Jan 2015 04:42:25 +0000 (-0800) Subject: Move "Replacers" into includes/libs/replacers/ X-Git-Tag: 1.31.0-rc.0~12574 X-Git-Url: http://git.cyclocoop.org/%24href?a=commitdiff_plain;h=2659a67054aba27230a96f0a3ca643918f6f3c54;p=lhc%2Fweb%2Fwiklou.git Move "Replacers" into includes/libs/replacers/ Split into separate files while we're at it Change-Id: I0bba4dcea686de088bd96964833fe6fb649a41e9 --- diff --git a/autoload.php b/autoload.php index 2015f5941b..5d382b2d30 100644 --- a/autoload.php +++ b/autoload.php @@ -332,7 +332,7 @@ $wgAutoloadLocalClasses = array( 'DjVuImage' => __DIR__ . '/includes/media/DjVuImage.php', 'DoubleRedirectJob' => __DIR__ . '/includes/jobqueue/jobs/DoubleRedirectJob.php', 'DoubleRedirectsPage' => __DIR__ . '/includes/specials/SpecialDoubleRedirects.php', - 'DoubleReplacer' => __DIR__ . '/includes/utils/StringUtils.php', + 'DoubleReplacer' => __DIR__ . '/includes/libs/replacers/DoubleReplacer.php', 'DummyLinker' => __DIR__ . '/includes/Linker.php', 'DummyTermColorer' => __DIR__ . '/maintenance/term/MWTerm.php', 'Dump7ZipOutput' => __DIR__ . '/includes/Export.php', @@ -495,7 +495,7 @@ $wgAutoloadLocalClasses = array( 'HashBagOStuff' => __DIR__ . '/includes/objectcache/HashBagOStuff.php', 'HashConfig' => __DIR__ . '/includes/config/HashConfig.php', 'HashRing' => __DIR__ . '/includes/libs/HashRing.php', - 'HashtableReplacer' => __DIR__ . '/includes/utils/StringUtils.php', + 'HashtableReplacer' => __DIR__ . '/includes/libs/replacers/HashtableReplacer.php', 'HistoryAction' => __DIR__ . '/includes/actions/HistoryAction.php', 'HistoryBlob' => __DIR__ . '/includes/HistoryBlob.php', 'HistoryBlobCurStub' => __DIR__ . '/includes/HistoryBlob.php', @@ -952,13 +952,13 @@ $wgAutoloadLocalClasses = array( 'RefreshLinks' => __DIR__ . '/maintenance/refreshLinks.php', 'RefreshLinksJob' => __DIR__ . '/includes/jobqueue/jobs/RefreshLinksJob.php', 'RefreshLinksJob2' => __DIR__ . '/includes/jobqueue/jobs/RefreshLinksJob2.php', - 'RegexlikeReplacer' => __DIR__ . '/includes/utils/StringUtils.php', + 'RegexlikeReplacer' => __DIR__ . '/includes/libs/replacers/RegexlikeReplacer.php', 'RemoveInvalidEmails' => __DIR__ . '/maintenance/removeInvalidEmails.php', 'RemoveUnusedAccounts' => __DIR__ . '/maintenance/removeUnusedAccounts.php', 'RenameDbPrefix' => __DIR__ . '/maintenance/renameDbPrefix.php', 'RenderAction' => __DIR__ . '/includes/actions/RenderAction.php', 'ReplacementArray' => __DIR__ . '/includes/utils/StringUtils.php', - 'Replacer' => __DIR__ . '/includes/utils/StringUtils.php', + 'Replacer' => __DIR__ . '/includes/libs/replacers/Replacer.php', 'RepoGroup' => __DIR__ . '/includes/filerepo/RepoGroup.php', 'RequestContext' => __DIR__ . '/includes/context/RequestContext.php', 'ResetUserTokens' => __DIR__ . '/maintenance/resetUserTokens.php', diff --git a/includes/libs/replacers/DoubleReplacer.php b/includes/libs/replacers/DoubleReplacer.php new file mode 100644 index 0000000000..ab8ce95906 --- /dev/null +++ b/includes/libs/replacers/DoubleReplacer.php @@ -0,0 +1,43 @@ +from = $from; + $this->to = $to; + $this->index = $index; + } + + /** + * @param array $matches + * @return mixed + */ + function replace( $matches ) { + return str_replace( $this->from, $this->to, $matches[$this->index] ); + } +} diff --git a/includes/libs/replacers/HashtableReplacer.php b/includes/libs/replacers/HashtableReplacer.php new file mode 100644 index 0000000000..1bb6fbc269 --- /dev/null +++ b/includes/libs/replacers/HashtableReplacer.php @@ -0,0 +1,44 @@ +table = $table; + $this->index = $index; + } + + /** + * @param array $matches + * @return mixed + */ + function replace( $matches ) { + return $this->table[$matches[$this->index]]; + } +} + diff --git a/includes/libs/replacers/RegexlikeReplacer.php b/includes/libs/replacers/RegexlikeReplacer.php new file mode 100644 index 0000000000..2923f5b719 --- /dev/null +++ b/includes/libs/replacers/RegexlikeReplacer.php @@ -0,0 +1,46 @@ +r = $r; + } + + /** + * @param array $matches + * @return string + */ + function replace( $matches ) { + $pairs = array(); + foreach ( $matches as $i => $match ) { + $pairs["\$$i"] = $match; + } + + return strtr( $this->r, $pairs ); + } +} diff --git a/includes/libs/replacers/Replacer.php b/includes/libs/replacers/Replacer.php new file mode 100644 index 0000000000..96f1660dc3 --- /dev/null +++ b/includes/libs/replacers/Replacer.php @@ -0,0 +1,32 @@ +r = $r; - } - - /** - * @param array $matches - * @return string - */ - function replace( $matches ) { - $pairs = array(); - foreach ( $matches as $i => $match ) { - $pairs["\$$i"] = $match; - } - - return strtr( $this->r, $pairs ); - } -} - -/** - * Class to perform secondary replacement within each replacement string - */ -class DoubleReplacer extends Replacer { - /** - * @param mixed $from - * @param mixed $to - * @param int $index - */ - function __construct( $from, $to, $index = 0 ) { - $this->from = $from; - $this->to = $to; - $this->index = $index; - } - - /** - * @param array $matches - * @return mixed - */ - function replace( $matches ) { - return str_replace( $this->from, $this->to, $matches[$this->index] ); - } -} - -/** - * Class to perform replacement based on a simple hashtable lookup - */ -class HashtableReplacer extends Replacer { - private $table, $index; - - /** - * @param array $table - * @param int $index - */ - function __construct( $table, $index = 0 ) { - $this->table = $table; - $this->index = $index; - } - - /** - * @param array $matches - * @return mixed - */ - function replace( $matches ) { - return $this->table[$matches[$this->index]]; - } -} - /** * Replacement array for FSS with fallback to strtr() * Supports lazy initialisation of FSS resource