Add LinkTarget interface
authoraddshore <addshorewiki@gmail.com>
Tue, 26 Jan 2016 20:24:27 +0000 (21:24 +0100)
committeraddshore <addshorewiki@gmail.com>
Fri, 29 Jan 2016 11:48:21 +0000 (12:48 +0100)
To be used by things that do not care if they are
passed a Title or TitleValue so long as it has a
dbkey, namespace, possible fragment and text

Example uses include:
 LinkBatch::addObj
 MediaWikiPageLinkRenderer methods
 MediaWikiTitleCodec methods
 PageLinkRenderer methods
 TitleFormatter methods

Change-Id: I2aa1a82129bb01155924a8e6a403c7a47391432f

autoload.php
includes/LinkTarget.php [new file with mode: 0644]
includes/Title.php
includes/title/TitleValue.php

index 24a4d72..11dc7e1 100644 (file)
@@ -560,6 +560,7 @@ $wgAutoloadLocalClasses = array(
        'IPSet' => __DIR__ . '/includes/compat/IPSetCompat.php',
        'IPTC' => __DIR__ . '/includes/media/IPTC.php',
        'IRCColourfulRCFeedFormatter' => __DIR__ . '/includes/rcfeed/IRCColourfulRCFeedFormatter.php',
+       'LinkTarget' => __DIR__ . '/includes/LinkTarget.php',
        'IcuCollation' => __DIR__ . '/includes/Collation.php',
        'IdentityCollation' => __DIR__ . '/includes/Collation.php',
        'ImageBuilder' => __DIR__ . '/maintenance/rebuildImages.php',
diff --git a/includes/LinkTarget.php b/includes/LinkTarget.php
new file mode 100644 (file)
index 0000000..1ce5f32
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+
+/**
+ * @author Addshore
+ *
+ * @since 1.27
+ */
+interface LinkTarget {
+
+       /**
+        * Get the namespace index
+        *
+        * @return int Namespace index
+        */
+       public function getNamespace();
+
+       /**
+        * Get the link fragment (i.e.\ the bit after the #) in text form
+        *
+        * @return string link fragment
+        */
+       public function getFragment();
+
+       /**
+        * Get the main part with underscores
+        *
+        * @return string Main part of the link, with underscores (for use in hrf attributes)
+        */
+       public function getDBkey();
+
+       /**
+        * Returns the link in text form,
+        * without namespace prefix or fragment.
+        *
+        * This is computed from the DB key by replacing any underscores with spaces.
+        *
+        * @return string
+        */
+       public function getText();
+
+}
index e549037..f2a33e2 100644 (file)
@@ -30,7 +30,7 @@
  * @note Consider using a TitleValue object instead. TitleValue is more lightweight
  *       and does not rely on global state or the database.
  */
-class Title {
+class Title implements LinkTarget {
        /** @var HashBagOStuff */
        static private $titleCache = null;
 
index a0f3b6f..c8ebc2a 100644 (file)
@@ -35,7 +35,7 @@ use Wikimedia\Assert\Assert;
  * @see https://www.mediawiki.org/wiki/Requests_for_comment/TitleValue
  * @since 1.23
  */
-class TitleValue {
+class TitleValue implements LinkTarget {
        /**
         * @var int
         */