diff --git a/Cite.php b/Cite.php index 19cd62bb1..f00b8e9f7 100644 --- a/Cite.php +++ b/Cite.php @@ -21,9 +21,10 @@ if ( ! defined( 'MEDIAWIKI' ) ) $wgExtensionFunctions[] = 'wfCite'; $wgExtensionCredits['parserhook'][] = array( 'name' => 'Cite', + 'version' => '1.1', 'author' => 'Ævar Arnfjörð Bjarmason', 'description' => 'Adds and tags, for citations', - 'url' => 'http://www.mediawiki.org/wiki/Extension:Cite/Cite.php' + 'url' => 'http://www.mediawiki.org/wiki/Extension:Cite/Cite.php', ); $wgParserTestFiles[] = dirname( __FILE__ ) . "/citeParserTests.txt"; @@ -65,12 +66,12 @@ function wfCite() { foreach( $wgCiteMessages as $key => $value ) { $wgMessageCache->addMessages( $wgCiteMessages[$key], $key ); } - + class Cite { /**#@+ * @access private */ - + /** * Datastructure representing input, in the format of: * @@ -103,7 +104,7 @@ function wfCite() { * @var array **/ var $mRefs = array(); - + /** * Count for user displayed output (ref[1], ref[2], ...) * @@ -128,20 +129,20 @@ function wfCite() { * @var array */ var $mBacklinkLabels; - + /** * @var object */ var $mParser; - + /** * True when a or tag is being processed. * Used to avoid infinite recursion - * + * * @var boolean */ var $mInCite = false; - + /**#@-*/ /** @@ -170,11 +171,11 @@ function wfCite() { return $ret; } } - + function guardedRef( $str, $argv, $parser ) { $this->mParser = $parser; $key = $this->refArg( $argv ); - + if ( $str !== null ) { if ( $str === '' ) return $this->error( CITE_ERROR_REF_NO_INPUT ); @@ -204,7 +205,7 @@ function wfCite() { return $this->error( CITE_ERROR_REF_NO_KEY ); else $this->croak( CITE_ERROR_KEY_INVALID_2, serialize( $key ) ); - + } else $this->croak( CITE_ERROR_STR_INVALID, serialize( $str ) ); } @@ -221,7 +222,7 @@ function wfCite() { function refArg( $argv ) { $cnt = count( $argv ); - + if ( $cnt > 1 ) // There should only be one key return false; @@ -236,7 +237,7 @@ function wfCite() { // No key return null; } - + /** * Since the key name is used in an XHTML id attribute, it must * conform to the validity rules. The restriction to begin with @@ -268,7 +269,7 @@ function wfCite() { * * @param string $str Input from the tag * @param mixed $key Argument to the tag as returned by $this->refArg() - * @return string + * @return string */ function stack( $str, $key = null ) { if ( $key === null ) { @@ -296,7 +297,7 @@ function wfCite() { // If no text found before, use this text $this->mRefs[$key]['text'] = $str; }; - return + return $this->linkRef( $key, ++$this->mRefs[$key]['count'], @@ -305,7 +306,7 @@ function wfCite() { else $this->croak( CITE_ERROR_STACK_INVALID_INPUT, serialize( array( $key, $str ) ) ); } - + /** * Callback function for * @@ -327,7 +328,7 @@ function wfCite() { return $ret; } } - + function guardedReferences( $str, $argv, $parser ) { $this->mParser = $parser; if ( $str !== null ) @@ -346,15 +347,15 @@ function wfCite() { function referencesFormat() { if ( count( $this->mRefs ) == 0 ) return ''; - + $ent = array(); foreach ( $this->mRefs as $k => $v ) $ent[] = $this->referencesFormatEntry( $k, $v ); - + $prefix = wfMsgForContentNoTrans( 'cite_references_prefix' ); $suffix = wfMsgForContentNoTrans( 'cite_references_suffix' ); $content = implode( "\n", $ent ); - + // Live hack: parse() adds two newlines on WM, can't reproduce it locally -ævar return rtrim( $this->parse( $prefix . $content . $suffix ), "\n" ); } @@ -479,7 +480,7 @@ function wfCite() { $suffix = wfMsgForContent( 'cite_reference_link_suffix' ); if ( isset( $num ) ) $key = wfMsgForContentNoTrans( 'cite_reference_link_key_with_num', $key, $num ); - + return $prefix . $key . $suffix; } @@ -499,7 +500,7 @@ function wfCite() { $suffix = wfMsgForContent( 'cite_references_link_suffix' ); if ( isset( $num ) ) $key = wfMsgForContentNoTrans( 'cite_reference_link_key_with_num', $key, $num ); - + return $prefix . $key . $suffix; } @@ -582,7 +583,7 @@ function wfCite() { false ); $text = $ret->getText(); - + return $this->fixTidy( $text ); } } @@ -605,7 +606,7 @@ function wfCite() { $text = preg_replace( '~^

\s*~', '', $text ); $text = preg_replace( '~\s*

\s*~', '', $text ); $text = preg_replace( '~\n$~', '', $text ); - + return $text; } } @@ -638,7 +639,7 @@ function wfCite() { */ function setHooks() { global $wgParser, $wgHooks; - + $wgParser->setHook( 'ref' , array( &$this, 'ref' ) ); $wgParser->setHook( 'references' , array( &$this, 'references' ) ); @@ -654,7 +655,7 @@ function wfCite() { function error( $id ) { if ( $id > 0 ) // User errors are positive - return + return $this->parse( '' . wfMsg( 'cite_error', $id, wfMsg( "cite_error_$id" ) ) . @@ -680,6 +681,3 @@ function wfCite() { new Cite; } - -/**#@-*/ -