From 62eb447b9be497a56d465d1903a91458f55fad7b Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Sun, 11 Sep 2011 02:20:20 +0000 Subject: [PATCH] (bug 16755) Add syntax to DEFAULTSORT - {{DEFAULTSORT:Foo|noerror}} and {{DEFAULTSORT:Bar|noreplace}} to in both cases prevent the "A sortkey already was specified earlier in the page, yadda yadda" message and in the second case, also do not replace the sortkey if one was already specified. --- RELEASE-NOTES-1.19 | 2 ++ includes/parser/CoreParserFunctions.php | 20 +++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index 4d396c89c1..a88fd1cea1 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -57,6 +57,8 @@ production. * (bug 30774) mediawiki.html: Add support for numbers and booleans in the attribute values and element contents. * Conversion script between Tifinagh and Latin for the Tachelhit language +* (bug 16755) Add options 'noreplace' and 'noerror' to {{DEFAULTSORT:...}} + to stop it from replace an already existing default sort, and suppress error. === Bug fixes in 1.19 === * $wgUploadNavigationUrl should be used for file redlinks if diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index 750587601a..54800bd2d7 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -677,23 +677,33 @@ class CoreParserFunctions { /** * @param $parser Parser - * @param $text + * @param $text String The sortkey to use + * @param $arg String Either "noreplace" or "noerror" + * both suppress errors, and noreplace does nothing if + * a default sortkey already exists. * @return string */ - public static function defaultsort( $parser, $text ) { + public static function defaultsort( $parser, $text, $arg = '' ) { $text = trim( $text ); + $arg = trim( strtolower( $arg ) ); if( strlen( $text ) == 0 ) return ''; $old = $parser->getCustomDefaultSort(); - $parser->setDefaultSort( $text ); - if( $old === false || $old == $text ) + if ( $old === false || $arg !== 'noreplace' ) { + $parser->setDefaultSort( $text ); + } + + if( $old === false || $old == $text || $arg === 'noreplace' + || $arg === 'noerror' ) + { return ''; - else + } else { return( '' . wfMsgForContent( 'duplicate-defaultsort', htmlspecialchars( $old ), htmlspecialchars( $text ) ) . '' ); + } } // Usage {{filepath|300}}, {{filepath|nowiki}}, {{filepath|nowiki|300}} or {{filepath|300|nowiki}} -- 2.20.1