r86706 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86705‎ | r86706 | r86707 >
Date:13:48, 22 April 2011
Author:svip
Status:deferred
Tags:
Comment:
Continued follow up to r86440 and r86472, now using the sections array entirely and not additioning to the output string as we go along.
Modified paths:
  • /trunk/extensions/TemplateAdventures/Templates/Citation.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TemplateAdventures/Templates/Citation.php
@@ -112,11 +112,14 @@
113113 *
114114 * @param $content The content of section.
115115 * @param $tags [default: array()] Some information regarding the content.
 116+ * @param $separator [default: true] Whether it shall have a separator at
 117+ * the end.
116118 */
117 - private function addCiteSection ( $content, $tags = array () ) {
 119+ private function addSection ( $content, $tags = array (), $separator = true ) {
118120 $this->mSections[] = array (
 121+ $content,
119122 $tags,
120 - $content
 123+ $separator
121124 );
122125 $this->mTags = array_merge ( $this->mTags, $tags );
123126 }
@@ -136,8 +139,8 @@
137140 private function isTagInSections ( $tag, $parent = null ) {
138141 if ( $this->notNull ( $parent ) ) {
139142 foreach ( $this->mSection as $section ) {
140 - if ( in_array ( $tag, $section[0] )
141 - && $section[0][0] == $parent )
 143+ if ( in_array ( $tag, $section[1] )
 144+ && $section[1][0] == $parent )
142145 return true;
143146 }
144147 return false;
@@ -152,16 +155,6 @@
153156 * TODO: Clean this baby up, probably be assigning some help functions.
154157 */
155158 public function render() {
156 - # boolean variables to keep track of output
157 - # TODO: Once the section system is entirely written into this function,
158 - # these can be replaced by the isTagInSections() function.
159 - $urlDisplayed = false; # whether the url has been displayed
160 - $authorDisplayed = false; # whether authors or editors have been
161 - # displayed
162 - $publisherDisplayed = false; # whether publisher have been displayed
163 - $languageDisplayed = false;
164 - # output
165 - $this->mOutput = '';
166159 # authors
167160 if ( count( $this->dAuthors ) > 1 ) {
168161 # remember element 0 is always set
@@ -185,9 +178,6 @@
186179 $this->dYearNote );
187180 }
188181 $this->addSection ( $authorArea, array ( 'writer', 'author' ) );
189 - # TODO: remove this
190 - $this->mOutput .= $authorArea . $this->getSeparator ( 'section' );
191 - $authorDisplayed = true;
192182 # editors
193183 } elseif ( count ( $this->dEditors ) > 1 ) {
194184 # remember element 0 is always set
@@ -210,9 +200,6 @@
211201 $editorArea, $this->dYearNote );
212202 }
213203 $this->addSection ( $editorArea, array ( 'writer', 'editor' ) );
214 - # TODO: remove this
215 - $this->mOutput .= $editorArea . $this->getSeparator ( 'section' );
216 - $authorDisplayed = true;
217204 }
218205 # included work title
219206 if ( $this->notNull( $this->dWorkTitle['includedwork'] )
@@ -251,9 +238,6 @@
252239 }
253240 $this->addSection ( $this->makeLink ( $url, $title ),
254241 array ( 'title', 'includedlink' ) );
255 - # TODO: Remove this
256 - $this->mOutput .= $this->makeLink ( $url, $title ) . $this->getSeparator( 'section' );
257 - $urlDisplayed = true;
258242 } else if ( $this->notNull ( $this->dWorkTitle['title'] ) ) {
259243 # if only the title is set, assume url is the URL of the title
260244 $url = $this->dWorkLink['url'];
@@ -265,37 +249,28 @@
266250 $this->addSection ( wfMsg ( 'ta-citeinlanguage',
267251 $this->makeLink ( $url, $title ), $this->dLanguage ),
268252 array ( 'title', 'transtitle', 'language' ) );
269 - # TODO: Remove this
270 - $this->mOutput .= wfMsg ( 'ta-citeinlanguage', $this->makeLink ( $url, $title ), $this->dLanguage ) . $this->getSeparator( 'section' );
271 - $languageDisplayed = true;
272253 } else {
273254 $this->addSection ( $this->makeLink ( $url, $title ),
274255 array ( 'title', 'transtitle' ) );
275 - # TODO: Remove this
276 - $this->mOutput .= $this->makeLink ( $url, $title ) . $this->getSeparator( 'section' );
277256 }
278257 } else {
279258 $title = $this->dWorkTitle['title'];
280259 $this->addSection ( $this->makeLink ( $url, $title ),
281260 array ( 'title' ) );
282 - # TODO: Remove this
283 - $this->mOutput .= $this->makeLink ( $url, $title ) . $this->getSeparator( 'section' );
284261 }
285262 $urlDisplayed = true;
286263 } else if ( $this->citeType == 'book'
287264 && $this->notNull ( $this->dBook['title'] ) ) {
288265 $this->addSection ( wfMsg ( 'ta-citebooktitle', $this->dBook['title'] ),
289266 array ( 'title', 'book' ) );
290 - # TODO: Remove this
291 - $this->mOutput .= wfMsg ( 'ta-citebooktitle', $this->dBook['title'] ) .$this->getSeparator ( 'section' );
292267 }
293268 # place, but only if different from publication place.
294 - if ( $this->notNull( $this->dPlace )
 269+ if ( $this->notNull ( $this->dPlace )
295270 && (
296271 !$this->notNull ( $this->dPublication['place'] )
297272 || $this->dPlace != $this->dPublication['place']
298273 ) && (
299 - $authorDisplayed
 274+ $this->isTagInSections ( 'writer' )
300275 || $this->notNull ( $this->dWorkTitle['includedwork'] )
301276 ) && ( !in_array ( $this->citeType, array ( 'news', 'book' ) ) )
302277 ) {
@@ -304,44 +279,51 @@
305280 $this->addSection ( wfMsg ( 'ta-citeplacepublisher',
306281 $this->dPlace, $this->dPublisher ),
307282 array ( 'place', 'publisher' ) );
308 - # TODO: Remove this
309 - $this->mOutput .= wfMsg ( 'ta-citeplacepublisher', $this->dPlace,$this->dPublisher ) . $this->getSeparator ( 'section' );
310 - $publisherDisplayed = true;
311283 } else {
312284 $this->addSection ( wfMsg ( 'ta-citewrittenat', $this->dPlace ),
313285 array ( 'place' ) );
314 - # TODO: Remove this
315 - $this->mOutput .= wfMsg ( 'ta-citewrittenat', $this->dPlace ) . $this->getSeparator ( 'section' );
316286 }
317287 }
318288 if ( ( $this->citeType == 'news' )
319289 && $this->notNull ( $this->dPublisher ) ) {
320290 if ( $this->notNull ( $this->dPlace ) ) {
321 - $this->mOutput .= wfMsg ( 'ta-citenewspublisherplace', $this->dPublisher, $this->dPlace ) . $this->getSeparator ( 'section' );
 291+ $this->addSection ( wfMsg ( 'ta-citenewspublisherplace',
 292+ $this->dPublisher, $this->dPlace ),
 293+ array ( 'publisher', 'place', 'news' ) );
322294 } else {
323 - $this->mOutput .= wfMsg ( 'ta-citenewspublisher', $this->dPublisher ) . $this->getSeparator ( 'section' );
 295+ $this->addSection ( wfMsg ( 'ta-citenewspublisher',
 296+ $this->dPublisher ),
 297+ array ( 'publisher', 'news' ) );
324298 }
325299 }
326300 if ( ( $this->citeType == 'journal' )
327301 && $this->notNull ( $this->dJournal['title'] ) ) {
328302 if ( $this->notNull ( $this->dJournal['page'] ) ) {
329 - $this->mOutput .= wfMsg ( 'ta-citejournalpage',
 303+ $this->addSection ( wfMsg ( 'ta-citejournalpage',
330304 $this->dJournal['title'],
331 - $this->dJournal['page'] ) . $this->getSeparator ( 'section' );
 305+ $this->dJournal['page'] ),
 306+ array ( 'journal', 'page' ) );
332307 } else {
333 - $this->mOutput .= wfMsg ( 'ta-citejournal',
334 - $this->dJournal['title'] ) . $this->getSeparator ( 'section' );
 308+ $this->addSection ( wfMsg ( 'ta-citejournal',
 309+ $this->dJournal['title'] ),
 310+ array ( 'journal' ) );
335311 }
336312 }
337313 if ( ( $this->citeType == 'book' )
338314 && $this->notNull ( $this->dPublisher ) ) {
339315 if ( $this->notNull ( $this->dPlace ) ) {
340 - $this->mOutput .= wfMsg ( 'ta-citebookpubplace', $this->dPlace, $this->dPublisher ) . $this->getSeparator ( 'section' );
 316+ $this->addSection ( wfMsg ( 'ta-citebookpubplace',
 317+ $this->dPlace, $this->dPublisher ),
 318+ array ( 'publisher', 'place', 'book' ) );
341319 } else {
342 - $this->mOutput .= wfMsg ( 'ta-citebookpublisher', $this->dPublisher ) . $this->getSeparator ( 'section' );
 320+ $this->addSection ( wfMsg ( 'ta-citebookpublisher',
 321+ $this->dPublisher ),
 322+ array ( 'publisher', 'book' ) );
343323 }
344324 if ( $this->notNull ( $this->dBook['page'] ) ) {
345 - $this->mOutput .= wfMsg ( 'ta-citebookpage', $this->dBook['page'] ) . $this->getSeparator ( 'section' );
 325+ $this->addSection ( wfMsg ( 'ta-citebookpage',
 326+ $this->dBook['page'] ),
 327+ array ( 'page', 'book' ) );
346328 }
347329 }
348330 # editor of complication... eerrr...
@@ -395,17 +377,19 @@
396378 $perArea .= $this->dWorkTitle['note'] . $this->getSeparator ( 'section' );
397379 }
398380 }
399 - $this->mOutput .= $perArea;
 381+ $this->addSection ( $perArea,
 382+ array ( 'title', 'periodicals' ) );
400383 }
401384 # language
402385 if ( $this->notNull ( $this->dLanguage )
403 - && !$languageDisplayed ) {
404 - $this->mOutput .= wfMsg ( 'ta-citeinlanguage', $this->dLanguage );
405 - $languageDisplayed = true;
 386+ && !$this->isTagInSections ( 'language' ) ) {
 387+ $this->addSection ( wfMsg ( 'ta-citeinlanguage',
 388+ $this->dLanguage ), array ( 'language' ) );
406389 }
407390 # format
408391 if ( $this->notNull ( $this->dFormat ) ) {
409 - $this->mOutput .= wfMsg ( 'ta-citeformatrender', $this->dFormat );
 392+ $this->addSection ( wfMsg ( 'ta-citeformatrender',
 393+ $this->dFormat ), array ( 'format' ) );
410394 }
411395 # more periodical!
412396 if ( $this->notNull ( $this->dPeriodical['name'] ) ) {
@@ -500,41 +484,46 @@
501485 }
502486 $newPerArea .= $sep . wfMsg ( 'ta-citepublisherrender', $this->dPublisher );
503487 }
504 - $this->mOutput .= $newPerArea . $this->getSeparator ( 'section' );
 488+ $this->addSection ( $newPerArea,
 489+ array ( 'details', 'periodicals' ) );
505490 }
506491 # date if no author/editor
507 - if ( !$authorDisplayed ) {
 492+ if ( !$this->isTagInSections ( 'writer' ) ) {
508493 if ( $this->notNull ( $this->dDate )
509494 || $this->notNull ( $this->dYear ) ) {
510495 $tmp = wfMsg ( 'ta-citealonedate', $this->notNull ( $this->dDate ) ? $this->dDate : $this->dYear );
511496 if ( $this->notNull ( $this->dYearNote ) ) {
512497 $tmp = wfMsg ( 'ta-citeauthoryearnote', $tmp, $this->dYearNote );
513498 }
514 - $this->mOutput .= $tmp . $this->getSeparator ( 'section' );
 499+ $this->addSection ( $tmp, array ( 'date' ) );
515500 }
516501 }
517502 # publication date
518503 if ( $this->notNull ( $this->dPublication['date'] )
519504 && $this->dPublication['date'] != $this->dDate ) {
520 - if ( isset ( $this->dEditors[1] ) ) {
521 - if ( isset ( $this->dAuthors[1] ) ) {
522 - $this->mOutput .= wfMsg ( 'ta-citepublicationdate', $this->dPublication['date'] );
 505+ if ( $this->isTagInSections ( 'editor' ) ) {
 506+ if ( $this->isTagInSections ( 'author' ) ) {
 507+ $this->addSection ( wfMsg ( 'ta-citepublicationdate', $this->dPublication['date'] ),
 508+ array ( 'publication date', 'periodical' ) );
523509 } else {
524 - $this->mOutput .= wfMsg ( 'ta-citepublished', $this->dPublication['date'] );
 510+ $this->addSection ( wfMsg ( 'ta-citepublished', $this->dPublication['date'] ),
 511+ array ( 'publication date', 'periodical' ) );
525512 }
526513 } else {
527514 if ( $this->notNull ( $this->dPeriodical['name'] ) ) {
528 - $this->mOutput .= wfMsg ( 'ta-citepublicationdate', $this->dPublication['date'] );
 515+ $this->addSection ( wfMsg ( 'ta-citepublicationdate', $this->dPublication['date'] ),
 516+ array ( 'publication date', 'periodical' ) );
529517 } else {
530 - $this->mOutput .= wfMsg ( 'ta-citepublished', $this->dPublication['date'] );
 518+ $this->addSection ( wfMsg ( 'ta-citepublished', $this->dPublication['date'] ),
 519+ array ( 'publication date', 'periodical' ) );
531520 }
532521 }
533 - $this->mOutput .= $this->getSeparator ( 'section' );
534522 }
535523 # page within included work
536524 if ( !$this->notNull ( $this->dPeriodical['name'] )
537525 && $this->notNull ( $this->dAt ) ) {
538 - $this->mOutput .= wfMsg ( 'ta-citeatseparated', $this->dAt );
 526+ $this->addSection ( wfMsg ( 'ta-citeatseparated', $this->dAt ),
 527+ array ( 'at', 'periodical' ) );
539528 }
540529 # doi
541530 # TODO: I'll do this code later:
@@ -551,10 +540,10 @@
552541 # isbn
553542 if ( $this->citeType == 'book'
554543 && $this->notNull ( $this->dBook['isbn'] ) ) {
555 - $this->mOutput .= wfMsg ( 'ta-citebookisbn',
556 - $this->dBook['isbn'],
557 - $this->createDisplayISBN ( $this->dBook['isbn'] )
558 - ) . $this->getSeparator ( 'section' );
 544+ $this->addSection ( wfMsg ( 'ta-citebookisbn',
 545+ $this->dBook['isbn'],
 546+ $this->createDisplayISBN ( $this->dBook['isbn'] ) ),
 547+ array ( 'isbn' ) );
559548 }
560549
561550 # more identifiers:
@@ -596,15 +585,19 @@
597586 if ( $this->notNull ( $this->dWorkTitle['title'] )
598587 || $this->notNull ( $this->dWorkTitle['includedwork'] )
599588 || $this->notNull ( $this->dWorkTitle['transtitle'] ) ) {
600 - $this->mOutput .= $this->printOnly (
 589+ $this->addSection ( $this->printOnly (
601590 ( $this->notNull ( $this->dWorkLink['includedwork'] )
602591 ? $this->dWorkLink['includedwork']
603 - : $this->dWorkLink['url'] ) );
 592+ : $this->dWorkLink['url'] ) ),
 593+ array ( 'url', 'printonly' ),
 594+ false );
604595 } else {
605 - $this->mOutput .=
 596+ $this->addSection (
606597 ( $this->notNull ( $this->dWorkLink['includedwork'] )
607598 ? $this->dWorkLink['includedwork']
608 - : $this->dWorkLink['url'] );
 599+ : $this->dWorkLink['url'] ),
 600+ array ( 'url' ),
 601+ false );
609602 }
610603 }
611604 if ( $this->notNull ( $this->dAccessDate ) ) {
@@ -612,7 +605,8 @@
613606 $tmp = wfMsg ( 'ta-citeretrievedupper', $this->dAccessDate );
614607 else
615608 $tmp = wfMsg ( 'ta-citeretrievedlower', $this->dAccessDate );
616 - $this->mOutput .= wfMsg ( 'ta-citeaccessdatespan', $tmp );
 609+ $this->addSection ( wfMsg ( 'ta-citeaccessdatespan', $tmp ),
 610+ array ( 'accessdate' ) );
617611 }
618612 }
619613
@@ -625,12 +619,20 @@
626620 # some other shit nobody cares about.
627621 # COinS? waaaaat
628622 # TODO
629 - $this->mOutput = trim($this->mOutput);
630 - if ( $this->mOutput[strlen($this->mOutput)-1] == $this->getSeparator ( 'section', false ) ) {
631 - $this->mOutput[strlen($this->mOutput)-1] = $this->getSeparator ( 'end', false );
632 - } elseif ( $this->mOutput[strlen($this->mOutput)-1] != $this->getSeparator ( 'end', false ) ) {
633 - $this->mOutput .= $this->getSeparator ( 'end', false );
 623+
 624+ $this->mOutput = '';
 625+
 626+ $len = count ( $this->mSections );
 627+
 628+ foreach ( $this->mSections as $i => $section ) {
 629+ $this->mOutput .= $section[0];
 630+ if ( ( $i + 1 < $len )
 631+ && $section[2] )
 632+ $this->mOutput .= $this->getSeparator ( 'section' );
634633 }
 634+
 635+ $this->mOutput .= $this->getSeparator ( 'end' );
 636+
635637 # if the end 'separator' is blank, so we trim
636638 $this->mOutput = wfMsg ( 'ta-citationspan', trim($this->mOutput), $this->citeType );
637639 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r86440Follow up to r86340. Added more functionality to Citation.php. STill not done.svip22:19, 19 April 2011
r86472Follow up to r86440: In an effort to clean up the code, sections are now in a...svip12:22, 20 April 2011

Status & tagging log