Index: trunk/extensions/ParserFunctions/ParserFunctions.php |
— | — | @@ -224,17 +224,23 @@ |
225 | 225 | * @param Parser $parser Parent parser |
226 | 226 | * @param string $title Title to split |
227 | 227 | * @param int $parts Number of parts to keep |
| 228 | + * @param int $offset Offset starting at 1 |
228 | 229 | * @return string |
229 | 230 | */ |
230 | | - public function titleparts( $parser, $title = '', $parts = -1 ) { |
| 231 | + public function titleparts( $parser, $title = '', $parts = -1, $offset = 1 ) { |
231 | 232 | $parts = intval( $parts ); |
| 233 | + $offset = intval( $offset ) - 1; |
232 | 234 | $ntitle = Title::newFromText( $title ); |
233 | 235 | if( $ntitle instanceof Title ) { |
234 | 236 | $bits = explode( '/', $ntitle->getPrefixedText() ); |
235 | 237 | if( $parts <= 0 || $parts > count( $bits ) ) { |
236 | 238 | return $ntitle->getPrefixedText(); |
| 239 | + } elseif( $offset < 0 || $offset > count( $bits ) ) { |
| 240 | + return $ntitle->getPrefixedText(); |
237 | 241 | } else { |
238 | 242 | $keep = array(); |
| 243 | + for( $i = 0; $i < $offset; $i++ ) |
| 244 | + array_shift( $bits ); |
239 | 245 | for( $i = 0; $i < $parts; $i++ ) |
240 | 246 | $keep[] = array_shift( $bits ); |
241 | 247 | return implode( '/', $keep ); |