From 5ff39d3b93b78fe0a0f014eb4093fb0fc568a6be Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Sun, 14 Sep 2008 00:49:52 +0000 Subject: [PATCH] Make sure to pass the right types to LinkBegin If Linker::link() is passed an invalid Title, now that it fails gracefully, we should fail gracefully before passing over to the hook. In theory some hooks might want to override this, but it's unlikely, because any caller that passes a non-Title is probably buggy and should be fixed anyway. This saves unexpected fatal errors and/or having to add "if( !$target instanceof Title ) return true;" to the beginning of every function hooking into this. Also ensure that $options is an array before passing to the hook, just for convenience. --- docs/hooks.txt | 2 +- includes/Linker.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/hooks.txt b/docs/hooks.txt index 440b251395..9f6b3abcd4 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -782,7 +782,7 @@ $target: the Title that the link is pointing to fault values, with a value of false meaning to suppress the attribute. &$query: the query string to add to the generated URL (the bit after the "?"), in associative array form, with keys and values unescaped. -&$options: the options. Can include 'known', 'broken', 'noclasses'. +&$options: array of options. Can include 'known', 'broken', 'noclasses'. &$ret: the value to return if your hook returns false. 'LinkEnd': Used when generating internal and interwiki links in Linker::link(), diff --git a/includes/Linker.php b/includes/Linker.php index ea7c38758f..54f5633dad 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -170,6 +170,11 @@ class Linker { */ public function link( $target, $text = null, $customAttribs = array(), $query = array(), $options = array() ) { wfProfileIn( __METHOD__ ); + if( !$target instanceof Title ) { + return "$text"; + } + $options = (array)$options; + $ret = null; if( !wfRunHooks( 'LinkBegin', array( $this, $target, &$text, &$customAttribs, &$query, &$options, &$ret ) ) ) { @@ -177,11 +182,6 @@ class Linker { return $ret; } - if( !$target instanceof Title ) { - return "$text"; - } - $options = (array)$options; - # Normalize the Title if it's a special page $target = $this->normaliseSpecialPage( $target ); -- 2.20.1