r86440 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86439‎ | r86440 | r86441 >
Date:22:19, 19 April 2011
Author:svip
Status:deferred
Tags:
Comment:
Follow up to r86340. Added more functionality to Citation.php. STill not done.
Modified paths:
  • /trunk/extensions/TemplateAdventures/TemplateAdventures.i18n.magic.php (modified) (history)
  • /trunk/extensions/TemplateAdventures/TemplateAdventures.i18n.php (modified) (history)
  • /trunk/extensions/TemplateAdventures/Templates/Citation.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TemplateAdventures/TemplateAdventures.i18n.php
@@ -18,6 +18,7 @@
1919 # citation messages
2020 'ta-citeetal' => "$1 ''et al''.", # $1 = list of authors
2121 'ta-citecoauthors' => '$1$2 $3', # $1 = authors, $2 = separator
 22+ 'ta-citealonedate' => '$1', # $1 = date
2223 'ta-citeauthordate' => '$1 ($2)', # $1 = authors or separator
2324 'ta-citeauthoryearnote' => '$1 [$2]', # $1 = date
2425 'ta-citeeditorsplural' => '$1, eds', # $1 = editors
@@ -31,10 +32,15 @@
3233 'ta-citeinlanguage' => '$1 (in $2)', # $1 = title/link
3334 'ta-citetitletrans' => '"$1 [$2]"', # $1 = title/link, $2 = transtitle
3435 'ta-citeformatrender' => '$1 ($2)', # $1 = title/link
35 - 'ta-newspublisherplace' => "''$1'' ($2)",
36 - 'ta-newspublisher' => "''$1''",
 36+ 'ta-citenewspublisherplace' => "''$1'' ($2)",
 37+ 'ta-citenewspublisher' => "''$1''",
3738 'ta-citeperiodical' => "''$1''",
3839 'ta-citeperiodicaltitle' => "''$1''",
 40+ 'ta-citebooktitle' => "''$1''",
 41+ 'ta-citebookpubplace' => '$1: $2', # $1 = location, $2 = publisher
 42+ 'ta-citebookpublisher' => '$1',
 43+ 'ta-citebookpage' => 'p. $1',
 44+ 'ta-citebookisbn' => '[[Special:BookSources/$1|ISBN $2]]',
3945 'ta-series' => '$1',
4046 'ta-citepublicationplaceandpublisher' => '($1: $2)',
4147 'ta-citepublicationplace' => '($1)',
@@ -50,6 +56,8 @@
5157 'ta-citepublicationdate' => '$1',
5258 'ta-citeretrievedupper' => 'Retrieved $1',
5359 'ta-citeretrievedlower' => 'retrieved $1',
 60+ 'ta-citejournal' => "''$1''",
 61+ 'ta-citejournalpage' => "''$1'': $2",
5462
5563 # citation span messages
5664 'ta-citationspan' => '<span class="citation $2">$1</span>',
Index: trunk/extensions/TemplateAdventures/Templates/Citation.php
@@ -64,6 +64,11 @@
6565 'issn' => null,
6666 );
6767 private $dLibrary = null; # library id
 68+ private $dBook = array( # a book
 69+ 'title' => null,
 70+ 'isbn' => null,
 71+ 'page' => null
 72+ );
6873 private $dISBN = null; # isbn number
6974 private $dLay = array( # an article of the same publication, but
7075 # written in more layman friendly fashion.
@@ -78,6 +83,10 @@
7984 'broken' => null, # date broken
8085 );
8186 private $dBibcode = null; # bibcode id
 87+ private $dJournal = array( # journal and its page
 88+ 'title' => null,
 89+ 'page' => null,
 90+ );
8291 private $dOther = null; # other stuff
8392
8493 /**
@@ -112,20 +121,35 @@
113122 $this->mOutput = '';
114123 # authors
115124 if ( count( $this->dAuthors ) > 1 ) {
116 - $authorArea = $this->createWriterSection ( $this->dAuthors, $this->dAuthorLinks, $this->dAuthorTruncate );
 125+ # remember element 0 is always set
 126+ $authorArea = $this->createWriterSection (
 127+ $this->dAuthors,
 128+ $this->dAuthorLinks,
 129+ $this->dAuthorTruncate );
117130 if ( $this->notNull ( $this->dCoAuthors ) )
118 - $authorArea = wfMsg ( 'ta-citecoauthors', $authorArea, $this->getSeparator( 'author' ), $this->dCoAuthors );
 131+ $authorArea = wfMsg ( 'ta-citecoauthors',
 132+ $authorArea,
 133+ $this->getSeparator( 'author' ),
 134+ $this->dCoAuthors );
119135 if ( $this->notNull ( $this->dDate )
120136 || $this->notNull ( $this->dYear ) ) {
121 - $authorArea = wfMsg ( 'ta-citeauthordate', $authorArea, $this->notNull ( $this->dDate ) ? $this->dDate : $this->dYear );
 137+ $authorArea = wfMsg ( 'ta-citeauthordate',
 138+ $authorArea,
 139+ $this->notNull ( $this->dDate ) ? $this->dDate : $this->dYear );
122140 if ( $this->notNull ( $this->dYearNote ) )
123 - $authorArea = wfMsg ( 'ta-citeauthoryearnote', $authorArea, $this->dYearNote );
 141+ $authorArea = wfMsg ( 'ta-citeauthoryearnote',
 142+ $authorArea,
 143+ $this->dYearNote );
124144 }
125145 $this->mOutput .= $authorArea . $this->getSeparator ( 'section' );
126146 $authorDisplayed = true;
127147 # editors
128148 } elseif ( count ( $this->dEditors ) > 1 ) {
129 - $editorArea = $this->createWriterSection ( $this->dEditors, $this->dEditorLinks, $this->dEditorTruncate );
 149+ # remember element 0 is always set
 150+ $editorArea = $this->createWriterSection (
 151+ $this->dEditors,
 152+ $this->dEditorLinks,
 153+ $this->dEditorTruncate );
130154 if ( count ( $this->dEditors ) > 2 )
131155 $editorArea = wfMsg ( 'ta-citeeditorsplural', $editorArea );
132156 else
@@ -133,9 +157,12 @@
134158 $editorArea .= $this->getSeparator ( 'section' );
135159 if ( $this->notNull ( $this->dDate )
136160 || $this->notNull ( $this->dYear ) ) {
137 - $editorArea = wfMsg ( 'ta-citeauthordate', $editorArea, $this->notNull ( $this->dDate ) ? $this->dDate : $this->dYear );
 161+ $editorArea = wfMsg ( 'ta-citeauthordate',
 162+ $editorArea,
 163+ $this->notNull ( $this->dDate ) ? $this->dDate : $this->dYear );
138164 if ( $this->notNull ( $this->dYearNote ) )
139 - $editorArea .= wfMsg ( 'ta-citeauthoryearnote', $editorArea, $this->dYearNote );
 165+ $editorArea .= wfMsg ( 'ta-citeauthoryearnote',
 166+ $editorArea, $this->dYearNote );
140167 }
141168 $this->mOutput .= $editorArea . $this->getSeparator ( 'section' );
142169 $authorDisplayed = true;
@@ -181,7 +208,9 @@
182209 # if only the title is set, assume url is the URL of the title
183210 $url = $this->dWorkLink['url'];
184211 if ( $this->notNull ( $this->dWorkTitle['transtitle'] ) ) {
185 - $title = wfMsg ( 'ta-citetitletrans', $this->dWorkTitle['title'], $this->dWorkTitle['transtitle'] );
 212+ $title = wfMsg ( 'ta-citetitletrans',
 213+ $this->dWorkTitle['title'],
 214+ $this->dWorkTitle['transtitle'] );
186215 if ( $this->notNull ( $this->dLanguage ) ) {
187216 $this->mOutput .= wfMsg ( 'ta-citeinlanguage', $this->makeLink ( $url, $title ), $this->dLanguage ) . $this->getSeparator( 'section' );
188217 $languageDisplayed = true;
@@ -190,9 +219,12 @@
191220 }
192221 } else {
193222 $title = $this->dWorkTitle['title'];
194 - $this->mOutput .= $this->makeLink ( $url, $title ) . $this->getSeparator( 'section' );
 223+ $this->mOutput .= $this->makeLink ( $url, $title ) . $this->getSeparator( 'section' );
195224 }
196225 $urlDisplayed = true;
 226+ } else if ( $this->citeType == 'book'
 227+ && $this->notNull ( $this->dBook['title'] ) ) {
 228+ $this->mOutput .= wfMsg ( 'ta-citebooktitle', $this->dBook['title'] ) .$this->getSeparator ( 'section' );
197229 }
198230 # place, but only if different from publication place.
199231 if ( $this->notNull( $this->dPlace )
@@ -202,7 +234,7 @@
203235 ) && (
204236 $authorDisplayed
205237 || $this->notNull ( $this->dWorkTitle['includedwork'] )
206 - ) && ( $this->citeType != 'news' )
 238+ ) && ( !in_array ( $this->citeType, array ( 'news', 'book' ) ) )
207239 ) {
208240 if ( $this->notNull ( $this->dPublisher )
209241 && ( $this->citeType != 'news' ) ) {
@@ -215,11 +247,33 @@
216248 if ( ( $this->citeType == 'news' )
217249 && $this->notNull ( $this->dPublisher ) ) {
218250 if ( $this->notNull ( $this->dPlace ) ) {
219 - $this->mOutput .= wfMsg ( 'ta-newspublisherplace', $this->dPublisher, $this->dPlace ) . $this->getSeparator ( 'section' );
 251+ $this->mOutput .= wfMsg ( 'ta-citenewspublisherplace', $this->dPublisher, $this->dPlace ) . $this->getSeparator ( 'section' );
220252 } else {
221 - $this->mOutput .= wfMsg ( 'ta-newspublisher', $this->dPublisher ) . $this->getSeparator ( 'section' );
 253+ $this->mOutput .= wfMsg ( 'ta-citenewspublisher', $this->dPublisher ) . $this->getSeparator ( 'section' );
222254 }
223255 }
 256+ if ( ( $this->citeType == 'journal' )
 257+ && $this->notNull ( $this->dJournal['title'] ) ) {
 258+ if ( $this->notNull ( $this->dJournal['page'] ) ) {
 259+ $this->mOutput .= wfMsg ( 'ta-citejournalpage',
 260+ $this->dJournal['title'],
 261+ $this->dJournal['page'] ) . $this->getSeparator ( 'section' );
 262+ } else {
 263+ $this->mOutput .= wfMsg ( 'ta-citejournal',
 264+ $this->dJournal['title'] ) . $this->getSeparator ( 'section' );
 265+ }
 266+ }
 267+ if ( ( $this->citeType == 'book' )
 268+ && $this->notNull ( $this->dPublisher ) ) {
 269+ if ( $this->notNull ( $this->dPlace ) ) {
 270+ $this->mOutput .= wfMsg ( 'ta-citebookpubplace', $this->dPlace, $this->dPublisher ) . $this->getSeparator ( 'section' );
 271+ } else {
 272+ $this->mOutput .= wfMsg ( 'ta-citebookpublisher', $this->dPublisher ) . $this->getSeparator ( 'section' );
 273+ }
 274+ if ( $this->notNull ( $this->dBook['page'] ) ) {
 275+ $this->mOutput .= wfMsg ( 'ta-citebookpage', $this->dBook['page'] ) . $this->getSeparator ( 'section' );
 276+ }
 277+ }
224278 # editor of complication... eerrr...
225279 # TODO: we'll do this later...
226280
@@ -382,11 +436,11 @@
383437 if ( !$authorDisplayed ) {
384438 if ( $this->notNull ( $this->dDate )
385439 || $this->notNull ( $this->dYear ) ) {
386 - $this->mOutput .= wfMsg ( 'ta-citeauthordate', $this->notNull ( $this->dDate ) ? $this->dDate : $this->dYear );
 440+ $tmp = wfMsg ( 'ta-citealonedate', $this->notNull ( $this->dDate ) ? $this->dDate : $this->dYear );
387441 if ( $this->notNull ( $this->dYearNote ) ) {
388 - $this->mOutput .= wfMsg ( 'ta-citeauthoryearnote', $this->dYearNote );
 442+ $tmp = wfMsg ( 'ta-citeauthoryearnote', $tmp, $this->dYearNote );
389443 }
390 - $this->mOutput .= $this->getSeparator ( 'section' );
 444+ $this->mOutput .= $tmp . $this->getSeparator ( 'section' );
391445 }
392446 }
393447 # publication date
@@ -424,15 +478,18 @@
425479 # |{{{Sep|,}}}&#32;{{{ID}}}
426480 # |{{{ID}}}
427481 # }}
 482+ # isbn
 483+ if ( $this->citeType == 'book'
 484+ && $this->notNull ( $this->dBook['isbn'] ) ) {
 485+ $this->mOutput .= wfMsg ( 'ta-citebookisbn',
 486+ $this->dBook['isbn'],
 487+ $this->createDisplayISBN ( $this->dBook['isbn'] )
 488+ ) . $this->getSeparator ( 'section' );
 489+ }
428490
429491 # more identifiers:
430492 # TODO: Do all this crap.
431493 /*
432 - {{
433 -<!--============ ISBN ============-->
434 - #if: {{{ISBN|}}}
435 - |{{{Sep|,}}}&#32;{{citation/identifier |identifier=isbn |input1={{{ISBN|}}} }}
436 -}}{{
437494 <!--============ ISSN ============-->
438495 #if: {{{ISSN|}}}
439496 |{{{Sep|,}}}&#32;{{citation/identifier |identifier=issn |input1={{{ISSN|}}} }}
@@ -481,10 +538,10 @@
482539 }
483540 }
484541 if ( $this->notNull ( $this->dAccessDate ) ) {
485 - if ( $this->getSeparator ( 'section' ) == '.' )
486 - $tmp = wfMsg ( 'ta-citeretrievedupper', $this->getSeparator ( 'section' ), $this->dAccessDate );
 542+ if ( $this->getSeparator ( 'section', false ) == '.' )
 543+ $tmp = wfMsg ( 'ta-citeretrievedupper', $this->dAccessDate );
487544 else
488 - $tmp = wfMsg ( 'ta-citeretrievedlower', $this->getSeparator ( 'section' ), $this->dAccessDate );
 545+ $tmp = wfMsg ( 'ta-citeretrievedlower', $this->dAccessDate );
489546 $this->mOutput .= wfMsg ( 'ta-citeaccessdatespan', $tmp );
490547 }
491548 }
@@ -507,6 +564,16 @@
508565 # if the end 'separator' is blank, so we trim
509566 $this->mOutput = wfMsg ( 'ta-citationspan', trim($this->mOutput), $this->citeType );
510567 }
 568+
 569+ /**
 570+ * Create the rendered version of an ISBN number.
 571+ *
 572+ * @param $isbn The raw ISBN number.
 573+ * @return $isbn The rendered version.
 574+ */
 575+ private function createDisplayISBN ( $isbn ) {
 576+ return $isbn[0] . '-' . $isbn[1] . $isbn[2] . $isbn[3] . $isbn[4] . '-' . $isbn[5] . $isbn[6] . $isbn[7] . $isbn[8] . '-' . $isbn[9];
 577+ }
511578
512579 /**
513580 * Surround the string in a span tag that tells the css not to render it
@@ -608,7 +675,7 @@
609676 * @return Boolean
610677 */
611678 private function notNull ( $check ) {
612 - return !( $check == null && $check === '' );
 679+ return !( $check == null && trim ( $check ) === '' );
613680 }
614681
615682 /**
@@ -788,7 +855,17 @@
789856 $this->dWorkLink['url'] = $value;
790857 break;
791858 case 'title':
792 - $this->dWorkTitle['title'] = $value;
 859+ switch ( $this->citeType ) {
 860+ case 'book':
 861+ $this->dBook['title'] = $value;
 862+ break;
 863+ case 'journal':
 864+ case 'web':
 865+ case 'news':
 866+ default:
 867+ $this->dWorkTitle['title'] = $value;
 868+ break;
 869+ }
793870 break;
794871 case 'transtitle':
795872 $this->dWorkTitle['transtitle'] = $value;
@@ -817,6 +894,25 @@
818895 case 'coauthors':
819896 $this->dCoAuthors = $value;
820897 break;
 898+ case 'accessdate':
 899+ $this->dAccessDate = $value;
 900+ break;
 901+ case 'journal':
 902+ $this->dJournal['title'] = $value;
 903+ break;
 904+ case 'page':
 905+ switch ( $this->citeType ) {
 906+ case 'journal':
 907+ $this->dJournal['page'] = $value;
 908+ break;
 909+ case 'book':
 910+ $this->dBook['page'] = $value;
 911+ break;
 912+ }
 913+ break;
 914+ case 'isbn':
 915+ $this->dBook['isbn'] = str_replace ( '-', '', $value );
 916+ break;
821917 }
822918 }
823919
@@ -828,6 +924,8 @@
829925 * @return True if option, false if not.
830926 */
831927 protected function optionParse( $var, $value ) {
 928+ if ( !$this->notNull ( $value ) )
 929+ return;
832930 $name = self::parseOptionName( $var );
833931 switch ( $name[0] ) {
834932 case 'author':
@@ -867,6 +965,10 @@
868966 case 'place':
869967 case 'publisher':
870968 case 'language':
 969+ case 'accessdate':
 970+ case 'journal':
 971+ case 'page':
 972+ case 'isbn':
871973 $this->addOtherStringValue( $name, $value );
872974 break;
873975 default:
@@ -886,7 +988,7 @@
887989 * @param $item The raw item.
888990 */
889991 protected function handlePrimaryItem( $item ) {
890 - if ( in_array ( $item, array ( 'news' ) ) )
 992+ if ( in_array ( $item, array ( 'web', 'news', 'journal', 'book' ) ) )
891993 $this->citeType = $item;
892994 }
893995
@@ -915,11 +1017,13 @@
9161018 'ta_cc_year', 'ta_cc_publisher',
9171019 'ta_cc_place', 'ta_cc_transtitle',
9181020 'ta_cc_language', 'ta_cc_date',
 1021+ 'ta_cc_accessdate', 'ta_cc_page',
 1022+ 'ta_cc_journal', 'ta_cc_isbn',
9191023 ) );
9201024 }
9211025
9221026 $num = preg_replace("@.*?([0-9]+)$@is", '\1', $value);
923 - if (is_numeric( $num ))
 1027+ if ( is_numeric( $num ) )
9241028 $name = preg_replace("@(.*?)[0-9]+$@is", '\1', $value);
9251029 else {
9261030 $name = $value;
Index: trunk/extensions/TemplateAdventures/TemplateAdventures.i18n.magic.php
@@ -11,9 +11,9 @@
1212 'ta_cc_authorlink' => array( 0, 'authorlink' ),
1313 'ta_cc_coauthors' => array( 0, 'coauthors' ),
1414 'ta_cc_editor' => array( 0, 'editor' ),
15 - 'ta_cc_editorsurname' => array( 0, 'editorsurname' ),
16 - 'ta_cc_editorgiven' => array( 0, 'editorgiven' ),
17 - 'ta_cc_editorlink' => array( 0, 'editorlink' ),
 15+ 'ta_cc_editorsurname' => array( 0, 'editorsurname', 'editor surname', 'editorlast', 'editor last' ),
 16+ 'ta_cc_editorgiven' => array( 0, 'editorgiven', 'editor given', 'editorfirst', 'editor first' ),
 17+ 'ta_cc_editorlink' => array( 0, 'editorlink', 'editor link' ),
1818 'ta_cc_url' => array( 0, 'url' ),
1919 'ta_cc_title' => array( 0, 'title' ),
2020 'ta_cc_pmc' => array( 0, 'pmc' ),
@@ -27,4 +27,8 @@
2828 'ta_cc_transtitle' => array( 0, 'transtitle', 'trans_title' ),
2929 'ta_cc_language' => array( 0, 'language' ),
3030 'ta_cc_date' => array( 0, 'date' ),
 31+ 'ta_cc_accessdate' => array( 0, 'accessdate' ),
 32+ 'ta_cc_journal' => array( 0, 'journal' ),
 33+ 'ta_cc_page' => array( 0, 'page' ),
 34+ 'ta_cc_isbn' => array( 0, 'isbn' ),
3135 );

Follow-up revisions

RevisionCommit summaryAuthorDate
r86441Merging from r83466 to r86440 of trunkawjrichards22:53, 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
r86706Continued follow up to r86440 and r86472, now using the sections array entire...svip13:48, 22 April 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r86340Added support for 'citation types' among other things.svip20:21, 18 April 2011

Status & tagging log