Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/187399
Change subject: Move "Replacers" into includes/libs/replacers/
......................................................................
Move "Replacers" into includes/libs/replacers/
Split into separate files while we're at it
Change-Id: I0bba4dcea686de088bd96964833fe6fb649a41e9
---
M autoload.php
A includes/libs/replacers/DoubleReplacer.php
A includes/libs/replacers/HashtableReplacer.php
A includes/libs/replacers/RegexlikeReplacer.php
A includes/libs/replacers/Replacer.php
M includes/utils/StringUtils.php
6 files changed, 169 insertions(+), 92 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/99/187399/1
diff --git a/autoload.php b/autoload.php
index 2015f59..5d382b2 100644
--- a/autoload.php
+++ b/autoload.php
@@ -332,7 +332,7 @@
'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 @@
'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 @@
'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 0000000..ab8ce95
--- /dev/null
+++ b/includes/libs/replacers/DoubleReplacer.php
@@ -0,0 +1,43 @@
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * 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] );
+ }
+}
diff --git a/includes/libs/replacers/HashtableReplacer.php
b/includes/libs/replacers/HashtableReplacer.php
new file mode 100644
index 0000000..1bb6fbc
--- /dev/null
+++ b/includes/libs/replacers/HashtableReplacer.php
@@ -0,0 +1,44 @@
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * 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]];
+ }
+}
+
diff --git a/includes/libs/replacers/RegexlikeReplacer.php
b/includes/libs/replacers/RegexlikeReplacer.php
new file mode 100644
index 0000000..2923f5b
--- /dev/null
+++ b/includes/libs/replacers/RegexlikeReplacer.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * Class to replace regex matches with a string similar to that used in
preg_replace()
+ */
+class RegexlikeReplacer extends Replacer {
+ private $r;
+
+ /**
+ * @param string $r
+ */
+ function __construct( $r ) {
+ $this->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 0000000..96f1660
--- /dev/null
+++ b/includes/libs/replacers/Replacer.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * Base class for "replacers", objects used in preg_replace_callback() and
+ * StringUtils::delimiterReplaceCallback()
+ */
+class Replacer {
+ /**
+ * @return array
+ */
+ function cb() {
+ return array( &$this, 'replace' );
+ }
+}
diff --git a/includes/utils/StringUtils.php b/includes/utils/StringUtils.php
index c71e315..a07e03f 100644
--- a/includes/utils/StringUtils.php
+++ b/includes/utils/StringUtils.php
@@ -317,94 +317,6 @@
}
/**
- * Base class for "replacers", objects used in preg_replace_callback() and
- * StringUtils::delimiterReplaceCallback()
- */
-class Replacer {
- /**
- * @return array
- */
- function cb() {
- return array( &$this, 'replace' );
- }
-}
-
-/**
- * Class to replace regex matches with a string similar to that used in
preg_replace()
- */
-class RegexlikeReplacer extends Replacer {
- private $r;
-
- /**
- * @param string $r
- */
- function __construct( $r ) {
- $this->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
*/
--
To view, visit https://gerrit.wikimedia.org/r/187399
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0bba4dcea686de088bd96964833fe6fb649a41e9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits