Page MenuHomeGitPull.it

No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
diff --git "a/include/class-mw\\TitlePart.php" "b/include/class-mw\\TitlePart.php"
index faa851a..36fa118 100644
--- "a/include/class-mw\\TitlePart.php"
+++ "b/include/class-mw\\TitlePart.php"
@@ -1,73 +1,81 @@
<?php
# Boz-MW - Another MediaWiki API handler in PHP
# Copyright (C) 2017 Valerio Bozzolan
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# MediaWiki
namespace mw;
/**
* A string part of a wikilink, a namespace, etc.
*/
class TitlePart {
private $s;
public function __construct( $s ) {
$this->set( $s );
}
public static function factory( $s ) {
return new static( $s );
}
public function get() {
return $this->s;
}
public function set( $s ) {
$this->s = static::normalize( $s );
return $this;
}
public function isEmpty() {
return '' === $this->get();
}
public function getRegex( $delimiter = null ) {
return self::regex( $this->get(), $delimiter );
}
public static function normalize( $s ) {
$s = trim( $s );
$s = self::underscore2space( $s );
return $s;
}
public static function underscore2space( $s ) {
return str_replace('_', ' ', $s);
}
- public static function regex( $s, $delimiter ) {
+ /**
+ * Create a regex matching this title
+ *
+ * Spaces will be converted into optional tabs/spaces.
+ *
+ * @param $s string
+ * @param $delimiter string
+ * @return string
+ */
+ public static function regex( $s, $delimiter = null ) {
$s = preg_quote( $s, $delimiter );
// These are all valids
// [[Main page]]
- // [[Main page]]
- // [[Main______page]]
- // [[Main_ _ _ page]]
- return str_replace( ' ', '[ _]*', $s );
+ // [[Main _ page]]
+ // [[_ _ Main_ _ _ page _ _ ]]
+ return str_replace( ' ', '[ _]+', $s );
}
}

File Metadata

Mime Type
text/x-diff
Expires
Thu, Nov 19, 03:27 (17 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2264474
Default Alt Text
(2 KB)

Event Timeline