Page MenuHomeGitPull.it

No OneTemporary

Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
diff --git "a/include/class-mw\\CompleteTitle.php" "b/include/class-mw\\CompleteTitle.php"
index 5d59ead..1a18318 100644
--- "a/include/class-mw\\CompleteTitle.php"
+++ "b/include/class-mw\\CompleteTitle.php"
@@ -1,135 +1,154 @@
<?php
# Boz-MW - Another MediaWiki API handler in PHP
# Copyright (C) 2019 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 MediaWiki complete title (with namespace)
*/
class CompleteTitle {
/**
* Which MediaWiki site
*
* @var object
*/
private $wiki;
/**
* @var object
*/
private $ns;
/**
* @var object
*/
private $title;
/**
* Constructor
*
* @param $wiki object
* @param $ns object
* @param $title object
*/
- public function __construct( $wiki, $ns, $title ) {
+ public function __construct( $wiki, Ns $ns, Title $title ) {
$this->wiki = $wiki;
$this->ns = $ns;
$this->title = $title;
}
/**
* Get the namespace object
*
* @return object
*/
public function getNs() {
return $this->ns;
}
/**
* Get the title object
*
* @return object
*/
public function getTitle() {
return $this->title;
}
+ /**
+ * Get the complete title, as displayed in a page
+ *
+ * @return string
+ */
+ public function getCompleteTitle() {
+ $title = $this->getTitle()->get();
+ $ns = $this->getNs()->getName();
+ if( $ns ) {
+ $ns .= ":";
+ }
+ return $ns . $title;
+ }
+
/**
* Get the regex able to match this complete title
*
* @param $args array
* ns-group-name: Name of the capturing group for the namespace
* title-group-name: Name of the capturing group for the title
* @return string
*/
public function getRegex( $args = [] ) {
// default options
$args = array_replace( [
+ 'wikilink' => true,
'ns-group-name' => null,
'title-group-name' => null,
], $args );
- // single regexes
- $ns = $this->getNs()->getRegex();
- $title = $this->title->getRegex();
+ // namespace regex
+ $ns = $this->getNs()->getRegex( [
+ 'wikilink' => $args[ 'wikilink' ],
+ ] );
+
+ // title regex
+ $title = $this->getTitle()->getRegex();
// eventually group
$ns = \regex\Generic::groupNamed( $ns, $args[ 'ns-group-name' ] );
$title = \regex\Generic::groupNamed( $title, $args[ 'title-group-name' ] );
return $ns . '[ _]*' . $title;
}
/**
* Static constructor parsing a string
*
* @param $wiki object
* @param $s string e.g. ' Mediawiki: test '
* @return self
*/
public static function createParsingTitle( $wiki, $s ) {
// split namespace and title
$ns_raw = '';
$tokens = explode( ':', $s, 2 );
if( count( $tokens ) === 2 ) {
$ns_raw = $tokens[ 0 ];
$title_raw = $tokens[ 1 ];
} else {
// no namespace? that's the main namespace!
$ns_raw = '';
$title_raw = $tokens[ 0 ];
}
// validate namespace
$ns = $wiki->findNamespace( $ns_raw );
if( ! $ns ) {
// that was the main namespace with a ':' in the title
$ns = $wiki->getNamespace( 0 );
$title_raw = "$ns_raw:$title_raw";
}
$title = new Title( $title_raw, $wiki );
return new self( $wiki, $ns, $title );
}
}

File Metadata

Mime Type
text/x-diff
Expires
Thu, Nov 19, 02:58 (4 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2263984
Default Alt Text
(3 KB)

Event Timeline