diff --git "a/include/class-wb\\DataValueCommonsCategory.php" "b/include/class-wb\\DataValueCommonsCategory.php" index c6a26ba..4fc16de 100644 --- "a/include/class-wb\\DataValueCommonsCategory.php" +++ "b/include/class-wb\\DataValueCommonsCategory.php" @@ -1,35 +1,59 @@ . # Wikibase namespace wb; /** * A DataValue for a Wikimedia Commons category * * There is no special datavalue for a Wikimedia Commons file :^) */ class DataValueCommonsCategory extends DataValueString { /** * @return string */ public function __toString() { - return "[[c:Category:{$this->getValue()}]]"; + return $this->toPrintableWikitext(); + } + + /** + * Get a wikitext-compatible version of this value + * + * This may be awared about which is the wiki that will contain this value, + * in order to properly choose a correct permalink in wikilinks etc. + * + * See https://gitpull.it/T221 + * + * @param $site You can eventually specify in which site you want to print this value + */ + public function toPrintableWikitext( \mw\Site $site = null ) { + + // commons prefix + $prefix = 'c:Category:'; + + // stupid way to create a simple wikilink + // that's good enough for an automatically generated edit summary + return sprintf( + '[[%s%s]]', + $prefix, + $this->getValue() + ); } } diff --git "a/include/class-wb\\DataValueCommonsMedia.php" "b/include/class-wb\\DataValueCommonsMedia.php" index 3842fb6..c4b101e 100644 --- "a/include/class-wb\\DataValueCommonsMedia.php" +++ "b/include/class-wb\\DataValueCommonsMedia.php" @@ -1,35 +1,58 @@ . # Wikibase namespace wb; /** * A DataValue for a Wikimedia Commons file. * * There is no special datavalue for a Wikimedia Commons file :^) */ class DataValueCommonsMedia extends DataValueString { /** * @return string */ public function __toString() { return "[[c:File:{$this->getValue()}]]"; } + /** + * Get a wikitext-compatible version of this value + * + * This may be awared about which is the wiki that will contain this value, + * in order to properly choose a correct permalink in wikilinks etc. + * + * See https://gitpull.it/T221 + * + * @param $site You can eventually specify in which site you want to print this value + */ + public function toPrintableWikitext( \mw\Site $site = null ) { + + // commons prefix + $prefix = 'c:File:'; + + // stupid way to create a simple wikilink + // that's good enough for an automatically generated edit summary + return sprintf( + '[[%s%s]]', + $prefix, + $this->getValue() + ); + } } diff --git "a/include/class-wb\\DataValueString.php" "b/include/class-wb\\DataValueString.php" index 6e437a2..3651d50 100644 --- "a/include/class-wb\\DataValueString.php" +++ "b/include/class-wb\\DataValueString.php" @@ -1,32 +1,47 @@ . # Wikibase namespace wb; /** * A DataValue for a string. */ class DataValueString extends DataValue { /** * @param $value string Value */ public function __construct( $value ) { parent::__construct( DataType::STRING, $value ); } + + /** + * Get a wikitext-compatible version of this value + * + * This may be awared about which is the wiki that will contain this value, + * in order to properly choose a correct permalink in wikilinks etc. + * + * See https://gitpull.it/T221 + * + * @param $site You can eventually specify in which site you want to print this value + */ + public function toPrintableWikitext( \mw\Site $site = null ) { + return $this->getValue(); + } + }