diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-06-04 07:31:04 +0200 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-06-04 07:58:39 +0200 |
commit | f6d65e533c62f6deb21342d4901ece24497b433e (patch) | |
tree | f28adf0362d14bcd448f7b65a7aaf38650f923aa /extensions/Cite/Cite_body.php | |
parent | c27b2e832fe25651ef2410fae85b41072aae7519 (diff) |
Update to MediaWiki 1.25.1
Diffstat (limited to 'extensions/Cite/Cite_body.php')
-rw-r--r-- | extensions/Cite/Cite_body.php | 108 |
1 files changed, 62 insertions, 46 deletions
diff --git a/extensions/Cite/Cite_body.php b/extensions/Cite/Cite_body.php index 496e32d8..6072cdfc 100644 --- a/extensions/Cite/Cite_body.php +++ b/extensions/Cite/Cite_body.php @@ -17,7 +17,17 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later */ +/** + * WARNING: MediaWiki core hardcodes this class name to check if the + * Cite extension is installed. See T89151. + */ class Cite { + + /** + * @todo document + */ + const DEFAULT_GROUP = ''; + /**#@+ * @access private */ @@ -158,19 +168,24 @@ class Cite { function ref( $str, $argv, $parser, $frame ) { if ( $this->mInCite ) { return htmlspecialchars( "<ref>$str</ref>" ); - } else { - $this->mCallCnt++; - $this->mInCite = true; - $ret = $this->guardedRef( $str, $argv, $parser ); - $this->mInCite = false; - $parserOutput = $parser->getOutput(); - $parserOutput->addModules( 'ext.cite' ); - $parserOutput->addModuleStyles( 'ext.rtlcite' ); - if ( is_callable( array( $frame, 'setVolatile' ) ) ) { - $frame->setVolatile(); - } - return $ret; } + + $this->mCallCnt++; + $this->mInCite = true; + + $ret = $this->guardedRef( $str, $argv, $parser ); + + $this->mInCite = false; + + $parserOutput = $parser->getOutput(); + $parserOutput->addModules( 'ext.cite' ); + $parserOutput->addModuleStyles( 'ext.rtlcite' ); + + if ( is_callable( array( $frame, 'setVolatile' ) ) ) { + $frame->setVolatile(); + } + + return $ret; } /** @@ -180,7 +195,7 @@ class Cite { * @param $default_group string * @return string */ - function guardedRef( $str, $argv, $parser, $default_group = CITE_DEFAULT_GROUP ) { + function guardedRef( $str, $argv, $parser, $default_group = self::DEFAULT_GROUP ) { $this->mParser = $parser; # The key here is the "name" attribute. @@ -296,7 +311,7 @@ class Cite { # Not clear how we could get here, but something is probably # wrong with the types. Let's fail fast. - throw new MWException( 'Invalid $str and/or $key: ' . serialize( array( $str, $key ) ) ); + throw new Exception( 'Invalid $str and/or $key: ' . serialize( array( $str, $key ) ) ); } /** @@ -386,18 +401,19 @@ class Cite { $this->mRefs[$group][$follow]['text'] = $this->mRefs[$group][$follow]['text'] . ' ' . $str; } else { // insert part of note at the beginning of the group - for ( $k = 0 ; $k < count( $this->mRefs[$group] ) ; $k++ ) { - if ( $this->mRefs[$group][$k]['follow'] == null ) { + $groupsCount = count( $this->mRefs[$group] ); + for ( $k = 0; $k < $groupsCount; $k++ ) { + if ( !isset( $this->mRefs[$group][$k]['follow'] ) ) { break; } } array_splice( $this->mRefs[$group], $k, 0, - array( array( 'count' => - 1, - 'text' => $str, - 'key' => ++$this->mOutCnt , - 'follow' => $follow ) ) ); + array( array( 'count' => - 1, + 'text' => $str, + 'key' => ++$this->mOutCnt , + 'follow' => $follow ) ) ); array_splice( $this->mRefCallStack, $k, 0, - array( array( 'new', $call, $str, $key, $group, $this->mOutCnt ) ) ); + array( array( 'new', $call, $str, $key, $group, $this->mOutCnt ) ) ); } // return an empty string : this is not a reference return ''; @@ -450,7 +466,7 @@ class Cite { ); } } else { - throw new MWException( 'Invalid stack key: ' . serialize( $key ) ); + throw new Exception( 'Invalid stack key: ' . serialize( $key ) ); } } @@ -556,7 +572,7 @@ class Cite { * @param $group string * @return string */ - function guardedReferences( $str, $argv, $parser, $group = CITE_DEFAULT_GROUP ) { + function guardedReferences( $str, $argv, $parser, $group = self::DEFAULT_GROUP ) { global $wgAllowCiteGroups; $this->mParser = $parser; @@ -635,7 +651,6 @@ class Cite { return ''; } - wfProfileIn( __METHOD__ ); wfProfileIn( __METHOD__ . '-entries' ); $ent = array(); foreach ( $this->mRefs[$group] as $k => $v ) { @@ -646,7 +661,8 @@ class Cite { $suffix = wfMessage( 'cite_references_suffix' )->inContentLanguage()->plain(); $content = implode( "\n", $ent ); - // Prepare the parser input. We add new lines between the pieces to avoid a confused tidy (bug 13073) + // Prepare the parser input. + // We add new lines between the pieces to avoid a confused tidy (bug 13073). $parserInput = $prefix . "\n" . $content . "\n" . $suffix; // Let's try to cache it. @@ -679,8 +695,6 @@ class Cite { $ret = $this->mParser->unserializeHalfParsedText( $data ); } - wfProfileOut( __METHOD__ ); - // done, clean up so we can reuse the group unset( $this->mRefs[$group] ); unset( $this->mGroupCnt[$group] ); @@ -713,7 +727,7 @@ class Cite { $this->referencesKey( $val['follow'] ), $text )->inContentLanguage()->plain(); - } elseif ( $val['text'] == '' ) { + } elseif ( !isset( $val['text'] ) ) { return wfMessage( 'cite_references_link_one', $this->referencesKey( $key ), @@ -772,7 +786,7 @@ class Cite { * @return String */ function referenceText( $key, $text ) { - if ( $text == '' ) { + if ( !isset( $text ) || $text === '' ) { return $this->error( 'cite_error_references_no_text', $key, 'noparse' ); } return '<span class="reference-text">' . rtrim( $text, "\n" ) . "</span>\n"; @@ -921,7 +935,7 @@ class Cite { $this->refKey( $key, $count ), $this->referencesKey( $key . $subkey ), $this->getLinkLabel( $label, $group, - ( ( $group == CITE_DEFAULT_GROUP ) ? '' : "$group " ) . $wgContLang->formatNum( $label ) ) + ( ( $group == self::DEFAULT_GROUP ) ? '' : "$group " ) . $wgContLang->formatNum( $label ) ) )->inContentLanguage()->plain() ); } @@ -959,11 +973,9 @@ class Cite { * arbitrary number of tokens separated by [\t\n ] */ function genBacklinkLabels() { - wfProfileIn( __METHOD__ ); $text = wfMessage( 'cite_references_link_many_format_backlink_labels' ) ->inContentLanguage()->plain(); $this->mBacklinkLabels = preg_split( '#[\n\t ]#', $text ); - wfProfileOut( __METHOD__ ); } /** @@ -975,14 +987,12 @@ class Cite { * @param $message */ function genLinkLabels( $group, $message ) { - wfProfileIn( __METHOD__ ); $text = false; $msg = wfMessage( $message )->inContentLanguage(); if ( $msg->exists() ) { $text = $msg->plain(); } - $this->mLinkLabels[$group] = ( $text == '' ) ? false : preg_split( '#[\n\t ]#', $text ); - wfProfileOut( __METHOD__ ); + $this->mLinkLabels[$group] = ( !$text ) ? false : preg_split( '#[\n\t ]#', $text ); } /** @@ -1027,8 +1037,8 @@ class Cite { } $parser->extCite = clone $this; - $parser->setHook( 'ref' , array( $parser->extCite, 'ref' ) ); - $parser->setHook( 'references' , array( $parser->extCite, 'references' ) ); + $parser->setHook( 'ref', array( $parser->extCite, 'ref' ) ); + $parser->setHook( 'references', array( $parser->extCite, 'references' ) ); // Clear the state, making sure it will actually work. $parser->extCite->mInCite = false; @@ -1067,18 +1077,20 @@ class Cite { if ( count( $refs ) == 0 ) { continue; } - if ( $group == CITE_DEFAULT_GROUP ) { + if ( $group == self::DEFAULT_GROUP ) { $text .= $this->referencesFormat( $group, '', '' ); } else { - $text .= "\n<br />" . $this->error( 'cite_error_group_refs_without_references', htmlspecialchars( $group ) ); + $text .= "\n<br />" . + $this->error( 'cite_error_group_refs_without_references', htmlspecialchars( $group ) ); } } return true; } /** - * Hook for the InlineEditor extension. If any ref or reference reference tag is in the text, the entire - * page should be reparsed, so we return false in that case. + * Hook for the InlineEditor extension. + * If any ref or reference reference tag is in the text, + * the entire page should be reparsed, so we return false in that case. * * @param $output * @@ -1110,8 +1122,8 @@ class Cite { $wgHooks['InlineEditorPartialAfterParse'][] = array( $parser->extCite, 'checkAnyCalls' ); Cite::$hooksInstalled = true; } - $parser->setHook( 'ref' , array( $parser->extCite, 'ref' ) ); - $parser->setHook( 'references' , array( $parser->extCite, 'references' ) ); + $parser->setHook( 'ref', array( $parser->extCite, 'ref' ) ); + $parser->setHook( 'references', array( $parser->extCite, 'references' ) ); return true; } @@ -1128,12 +1140,16 @@ class Cite { # We rely on the fact that PHP is okay with passing unused argu- # ments to functions. If $1 is not used in the message, wfMessage will # just ignore the extra parameter. - $ret = '<strong class="error mw-ext-cite-error">' . - wfMessage( 'cite_error', wfMessage( $key, $param )->inContentLanguage()->plain() )->inContentLanguage()->plain() . - '</strong>'; + $msg = wfMessage( 'cite_error', wfMessage( $key, $param )->inContentLanguage()->plain() ) + ->inContentLanguage() + ->plain(); + + $ret = '<strong class="error mw-ext-cite-error">' . $msg . '</strong>'; + if ( $parse == 'parse' ) { $ret = $this->mParser->recursiveTagParse( $ret ); } + return $ret; } |