r86340 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86339‎ | r86340 | r86341 >
Date:20:21, 18 April 2011
Author:svip
Status:deferred
Tags:
Comment:
Added support for 'citation types' among other things.
Modified paths:
  • /trunk/extensions/TemplateAdventures/TemplateAdventures.i18n.magic.php (modified) (history)
  • /trunk/extensions/TemplateAdventures/TemplateAdventures.i18n.php (modified) (history)
  • /trunk/extensions/TemplateAdventures/TemplateAdventures.php (modified) (history)
  • /trunk/extensions/TemplateAdventures/Templates/Citation.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TemplateAdventures/TemplateAdventures.i18n.magic.php
@@ -22,6 +22,9 @@
2323 'ta_cc_transitalic' => array( 0, 'transitalic' ),
2424 'ta_cc_transtitle' => array( 0, 'transtitle' ),
2525 'ta_cc_year' => array( 0, 'year' ),
26 - 'ta_cc_publisher' => array( 0, 'publisher' ),
27 - 'ta_cc_place' => array( 0, 'place' ),
 26+ 'ta_cc_publisher' => array( 0, 'publisher', 'newspaper' ),
 27+ 'ta_cc_place' => array( 0, 'place', 'location' ),
 28+ 'ta_cc_transtitle' => array( 0, 'transtitle', 'trans_title' ),
 29+ 'ta_cc_language' => array( 0, 'language' ),
 30+ 'ta_cc_date' => array( 0, 'date' ),
2831 );
Index: trunk/extensions/TemplateAdventures/TemplateAdventures.i18n.php
@@ -29,7 +29,10 @@
3030 'ta-citeplacepublisher' => '$1: $2', # $1 = place, $2 = publisher
3131 'ta-citeother' => '$1',
3232 'ta-citeinlanguage' => '$1 (in $2)', # $1 = title/link
 33+ 'ta-citetitletrans' => '"$1 [$2]"', # $1 = title/link, $2 = transtitle
3334 'ta-citeformatrender' => '$1 ($2)', # $1 = title/link
 35+ 'ta-newspublisherplace' => "''$1'' ($2)",
 36+ 'ta-newspublisher' => "''$1''",
3437 'ta-citeperiodical' => "''$1''",
3538 'ta-citeperiodicaltitle' => "''$1''",
3639 'ta-series' => '$1',
@@ -49,6 +52,7 @@
5053 'ta-citeretrievedlower' => 'retrieved $1',
5154
5255 # citation span messages
 56+ 'ta-citationspan' => '<span class="citation $2">$1</span>',
5357 'ta-citeprintonlyspan' => '<span class="printonly">$1</span>',
5458 'ta-citeaccessdatespan' => '<span class="reference-accessdate">$1</span>',
5559 );
Index: trunk/extensions/TemplateAdventures/TemplateAdventures.php
@@ -131,7 +131,7 @@
132132 # first input is a bit different than the rest,
133133 # so we'll treat that differently
134134 $primary = trim( $this->mFrame->expand( array_shift( $args ) ) );
135 - $primary = $this->handleInputItem( $primary );
 135+ $primary = $this->handlePrimaryItem( $primary );
136136
137137 # check the rest for options
138138 foreach( $args as $arg ) {
@@ -172,6 +172,17 @@
173173 }
174174
175175 /**
 176+ * This functions handles the primary item. It is supposed to be
 177+ * overwriteable
 178+ *
 179+ * @param $arg String Argument
 180+ * @return String if understood, else return false
 181+ */
 182+ protected function handlePrimaryItem( $arg ) {
 183+ return false;
 184+ }
 185+
 186+ /**
176187 * Parse the option.
177188 * This should be rewritten in classes inheriting this class.
178189 *
Index: trunk/extensions/TemplateAdventures/Templates/Citation.php
@@ -2,6 +2,8 @@
33
44 class Citation extends TemplateAdventureBasic {
55
 6+ private $citeType = null; # type of citation, e.g. 'news'
 7+ # currently only 'news' supported.
68 private $dSeparators = array( # separators between names, items, etc.
79 'section' => ',',
810 'end' => '.',
@@ -103,6 +105,7 @@
104106 $authorDisplayed = false; # whether authors or editors have been
105107 # displayed
106108 $publisherDisplayed = false; # whether publisher have been displayed
 109+ $languageDisplayed = false;
107110 # output
108111 $this->mOutput = '';
109112 # authors
@@ -175,8 +178,18 @@
176179 } else if ( $this->notNull ( $this->dWorkTitle['title'] ) ) {
177180 # if only the title is set, assume url is the URL of the title
178181 $url = $this->dWorkLink['url'];
179 - $title = $this->dWorkTitle['title'];
180 - $this->mOutput .= $this->makeLink ( $url, $title ) . $this->getSeparator( 'section' );
 182+ if ( $this->notNull ( $this->dWorkTitle['transtitle'] ) ) {
 183+ $title = wfMsg ( 'ta-citetitletrans', $this->dWorkTitle['title'], $this->dWorkTitle['transtitle'] );
 184+ if ( $this->notNull ( $this->dLanguage ) ) {
 185+ $this->mOutput .= wfMsg ( 'ta-citeinlanguage', $this->makeLink ( $url, $title ), $this->dLanguage ) . $this->getSeparator( 'section' );
 186+ $languageDisplayed = true;
 187+ } else {
 188+ $this->mOutput .= $this->makeLink ( $url, $title ) . $this->getSeparator( 'section' );
 189+ }
 190+ } else {
 191+ $title = $this->dWorkTitle['title'];
 192+ $this->mOutput .= $this->makeLink ( $url, $title ) . $this->getSeparator( 'section' );
 193+ }
181194 $urlDisplayed = true;
182195 }
183196 # place, but only if different from publication place.
@@ -187,15 +200,24 @@
188201 ) && (
189202 $authorDisplayed
190203 || $this->notNull ( $this->dWorkTitle['includedwork'] )
191 - )
 204+ ) && ( $this->citeType != 'news' )
192205 ) {
193 - if ( $this->notNull ( $this->dPublisher ) ) {
 206+ if ( $this->notNull ( $this->dPublisher )
 207+ && ( $this->citeType != 'news' ) ) {
194208 $this->mOutput .= wfMsg ( 'ta-citeplacepublisher', $this->dPlace,$this->dPublisher ) . $this->getSeparator ( 'section' );
195209 $publisherDisplayed = true;
196210 } else {
197211 $this->mOutput .= wfMsg ( 'ta-citewrittenat', $this->dPlace ) . $this->getSeparator ( 'section' );
198212 }
199213 }
 214+ if ( ( $this->citeType == 'news' )
 215+ && $this->notNull ( $this->dPublisher ) ) {
 216+ if ( $this->notNull ( $this->dPlace ) ) {
 217+ $this->mOutput .= wfMsg ( 'ta-newspublisherplace', $this->dPublisher, $this->dPlace ) . $this->getSeparator ( 'section' );
 218+ } else {
 219+ $this->mOutput .= wfMsg ( 'ta-newspublisher', $this->dPublisher ) . $this->getSeparator ( 'section' );
 220+ }
 221+ }
200222 # editor of complication... eerrr...
201223 # TODO: we'll do this later...
202224
@@ -250,8 +272,10 @@
251273 $this->mOutput .= $perArea;
252274 }
253275 # language
254 - if ( $this->notNull ( $this->dLanguage ) ) {
 276+ if ( $this->notNull ( $this->dLanguage )
 277+ && !$languageDisplayed ) {
255278 $this->mOutput .= wfMsg ( 'ta-citeinlanguage', $this->dLanguage );
 279+ $languageDisplayed = true;
256280 }
257281 # format
258282 if ( $this->notNull ( $this->dFormat ) ) {
@@ -478,8 +502,8 @@
479503 } elseif ( $this->mOutput[strlen($this->mOutput)-1] != $this->getSeparator ( 'end', false ) ) {
480504 $this->mOutput .= $this->getSeparator ( 'end', false );
481505 }
482 - # if the end 'separator' is blank
483 - $this->mOutput = trim($this->mOutput);
 506+ # if the end 'separator' is blank, so we trim
 507+ $this->mOutput = wfMsg ( 'ta-citationspan', trim($this->mOutput), $this->citeType );
484508 }
485509
486510 /**
@@ -539,9 +563,13 @@
540564 if ( $writer[1][0] != null )
541565 $tmp .= $this->getSeparator( 'name' ) . $writer[1][0];
542566 } else {
543 - # maybe we shan't support no surname/given name structure
544 - # in the future, but we'll leave it like this for now.
545 - $tmp .= $writer[1][1];
 567+ if ( is_array ( $writer[1] ) ) {
 568+ # maybe we shan't support no surname/given name structure
 569+ # in the future, but we'll leave it like this for now.
 570+ $tmp .= $writer[1][1];
 571+ } else {
 572+ $tmp .= $writer[1];
 573+ }
546574 }
547575 if ( isset ( $links[$i] ) )
548576 $tmp = "[{$links[$i]} $tmp]";
@@ -558,9 +586,7 @@
559587 }
560588
561589 private function notNull ( $check ) {
562 - if ( $check == null && $check == '' )
563 - return false;
564 - return true;
 590+ return !( $check == null && $check == '' );
565591 }
566592
567593 /**
@@ -672,6 +698,12 @@
673699 case 'title':
674700 $this->dWorkTitle['title'] = $value;
675701 break;
 702+ case 'transtitle':
 703+ $this->dWorkTitle['transtitle'] = $value;
 704+ break;
 705+ case 'language':
 706+ $this->dLanguage = $value;
 707+ break;
676708 case 'includedworktitle':
677709 $this->dWorkTitle['includedwork'] = $value;
678710 break;
@@ -681,6 +713,9 @@
682714 case 'year':
683715 $this->dYear = $value;
684716 break;
 717+ case 'date':
 718+ $this->dDate = $value;
 719+ break;
685720 case 'place':
686721 $this->dPlace = $value;
687722 break;
@@ -735,8 +770,10 @@
736771 case 'transitalic':
737772 case 'transtitle':
738773 case 'year':
 774+ case 'date':
739775 case 'place':
740776 case 'publisher':
 777+ case 'language':
741778 $this->addOtherStringValue( $name, $value );
742779 break;
743780 default:
@@ -745,6 +782,11 @@
746783 }
747784 return true;
748785 }
 786+
 787+ protected function handlePrimaryItem( $item ) {
 788+ if ( in_array ( $item, array ( 'news' ) ) )
 789+ $this->citeType = $item;
 790+ }
749791
750792 /**
751793 * This one parses the variable name given to optionParse to figure out
@@ -769,7 +811,8 @@
770812 'ta_cc_includedworktitle', 'ta_cc_periodical',
771813 'ta_cc_transitalic', 'ta_cc_transtitle',
772814 'ta_cc_year', 'ta_cc_publisher',
773 - 'ta_cc_place',
 815+ 'ta_cc_place', 'ta_cc_transtitle',
 816+ 'ta_cc_language', 'ta_cc_date',
774817 ) );
775818 }
776819

Follow-up revisions

RevisionCommit summaryAuthorDate
r86413Follow up to r86340 and 86344: Cleaned up variables, etc. and added comments...svip16:40, 19 April 2011
r86440Follow up to r86340. Added more functionality to Citation.php. STill not done.svip22:19, 19 April 2011

Status & tagging log