r71157 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71156‎ | r71157 | r71158 >
Date:12:05, 16 August 2010
Author:thomasv
Status:resolved (Comments)
Tags:
Comment:
Support for references spread on multiple transcluded pages, using the 'follow' parameter.
Modified paths:
  • /trunk/extensions/Cite/Cite.i18n.php (modified) (history)
  • /trunk/extensions/Cite/Cite_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Cite/Cite_body.php
@@ -167,7 +167,7 @@
168168 $this->mParser = $parser;
169169
170170 # The key here is the "name" attribute.
171 - list( $key, $group ) = $this->refArg( $argv );
 171+ list( $key, $group, $follow ) = $this->refArg( $argv );
172172
173173 # Split these into groups.
174174 if ( $group === null ) {
@@ -238,7 +238,7 @@
239239 return $this->error( 'cite_error_ref_no_key' );
240240 }
241241
242 - if ( preg_match( '/^[0-9]+$/', $key ) ) {
 242+ if ( preg_match( '/^[0-9]+$/', $key ) || preg_match( '/^[0-9]+$/', $follow ) ) {
243243 # Numeric names mess up the resulting id's, potentially produ-
244244 # cing duplicate id's in the XHTML. The Right Thing To Do
245245 # would be to mangle them, but it's not really high-priority
@@ -274,7 +274,7 @@
275275 # we'll figure that out later. Likewise it's definitely valid
276276 # if there's any content, regardless of key.
277277
278 - return $this->stack( $str, $key, $group, $argv );
 278+ return $this->stack( $str, $key, $group, $follow, $argv );
279279 }
280280
281281 # Not clear how we could get here, but something is probably
@@ -284,6 +284,10 @@
285285
286286 /**
287287 * Parse the arguments to the <ref> tag
 288+ *
 289+ * "name" : Key of the reference.
 290+ * "group" : Group to which it belongs. Needs to be passed to <references /> too.
 291+ * "follow" : If the current reference is the continuation of another, key of that reference.
288292 *
289293 * @static
290294 *
@@ -296,18 +300,28 @@
297301 $cnt = count( $argv );
298302 $group = null;
299303 $key = null;
 304+ $follow = null;
300305
301306 if ( $cnt > 2 )
302 - // There should only be one key and one group
 307+ // There should only be one key or follow parameter, and one group parameter
303308 // FIXME : this looks inconsistent, it should probably return a tuple
304309 return false;
305310 else if ( $cnt >= 1 ) {
 311+ if ( isset( $argv['name'] ) && isset( $argv['follow'] ) ) {
 312+ return array( false, false, false );
 313+ }
306314 if ( isset( $argv['name'] ) ) {
307315 // Key given.
308316 $key = Sanitizer::escapeId( $argv['name'], 'noninitial' );
309317 unset( $argv['name'] );
310318 --$cnt;
311319 }
 320+ if ( isset( $argv['follow'] ) ) {
 321+ // Follow given.
 322+ $follow = Sanitizer::escapeId( $argv['follow'], 'noninitial' );
 323+ unset( $argv['follow'] );
 324+ --$cnt;
 325+ }
312326 if ( isset( $argv['group'] ) ) {
313327 if ( ! $wgAllowCiteGroups ) return array( false ); // remove when groups are fully tested.
314328 // Group given.
@@ -317,14 +331,14 @@
318332 }
319333
320334 if ( $cnt == 0 )
321 - return array ( $key, $group );
 335+ return array ( $key, $group, $follow );
322336 else
323337 // Invalid key
324 - return array( false, false );
 338+ return array( false, false, false );
325339 }
326340 else
327341 // No key
328 - return array( null, $group );
 342+ return array( null, $group, false );
329343 }
330344
331345 /**
@@ -334,12 +348,33 @@
335349 * @param mixed $key Argument to the <ref> tag as returned by $this->refArg()
336350 * @return string
337351 */
338 - function stack( $str, $key = null, $group, $call ) {
 352+ function stack( $str, $key = null, $group, $follow, $call ) {
339353 if ( ! isset( $this->mRefs[$group] ) )
340354 $this->mRefs[$group] = array();
341355 if ( ! isset( $this->mGroupCnt[$group] ) )
342356 $this->mGroupCnt[$group] = 0;
343357
 358+ if ( $follow != null ) {
 359+ if ( isset( $this->mRefs[$group][$follow] ) && is_array( $this->mRefs[$group][$follow] ) ) {
 360+ // add text to the note that is being followed
 361+ $this->mRefs[$group][$follow]['text'] = $this->mRefs[$group][$follow]['text'] . ' '. $str;
 362+ } else {
 363+ // insert part of note at the beginning of the group
 364+ for( $k=0 ; $k< count( $this->mRefs[$group] ) ; $k++) {
 365+ if( $this->mRefs[$group][$k]['follow'] == null ) break;
 366+ }
 367+ array_splice( $this->mRefs[$group], $k, 0,
 368+ array( array( 'count' => - 1,
 369+ 'text' => $str,
 370+ 'key' => ++$this->mOutCnt ,
 371+ 'follow' => $follow) ) );
 372+ array_splice( $this->mRefCallStack, $k, 0,
 373+ array( array( 'new', $call, $str, $key, $group, $this->mOutCnt ) ) );
 374+ $this->mInCnt++;
 375+ }
 376+ // return an empty string : this is not a reference
 377+ return '';
 378+ }
344379 if ( $key === null ) {
345380 // No key
346381 // $this->mRefs[$group][] = $str;
@@ -608,6 +643,13 @@
609644 $this->refKey( $key ),
610645 $val
611646 );
 647+ else if ( $val['follow'] )
 648+ return
 649+ wfMsgForContentNoTrans(
 650+ 'cite_references_no_link',
 651+ $this->referencesKey( $val['follow'] ),
 652+ $val['text']
 653+ );
612654 else if ( $val['text'] == '' ) return
613655 wfMsgForContentNoTrans(
614656 'cite_references_link_one',
Index: trunk/extensions/Cite/Cite.i18n.php
@@ -65,6 +65,7 @@
6666 'cite_references_link_suffix' => '',
6767
6868 'cite_reference_link' => '<sup id="$1" class="reference">[[#$2|<nowiki>[</nowiki>$3<nowiki>]</nowiki>]]</sup>',
 69+ 'cite_references_no_link' => '<p id="$1">$2</p>',
6970 'cite_references_link_one' => '<li id="$1">[[#$2|↑]] $3</li>',
7071 'cite_references_link_many' => '<li id="$1">↑ $2 $3</li>',
7172 'cite_references_link_many_format' => '<sup>[[#$1|$2]]</sup>',
@@ -150,6 +151,7 @@
151152 'cite_references_link_prefix' => '{{optional}}',
152153 'cite_references_link_suffix' => '{{optional}}',
153154 'cite_reference_link' => '{{optional}}',
 155+ 'cite_references_no_link' => '{{optional}}',
154156 'cite_references_link_one' => '{{optional}}',
155157 'cite_references_link_many' => '{{optional}}',
156158 'cite_references_link_many_format' => '{{optional}}',

Follow-up revisions

RevisionCommit summaryAuthorDate
r71465follow-up to r71157thomasv08:19, 23 August 2010

Comments

#Comment by Platonides (talk | contribs)   17:35, 20 August 2010

You are producing lots of

PHP Notice:  Undefined index: follow in Cite/Cite_body.php on line 646

Status & tagging log