r65982 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65981‎ | r65982 | r65983 >
Date:11:58, 6 May 2010
Author:svip
Status:deferred
Tags:
Comment:
Provided more logic, but right now it will only load data and respond with 'not implemented' upon run.
Modified paths:
  • /trunk/extensions/TemplateAdventures/TemplateAdventures.i18n.magic.php (modified) (history)
  • /trunk/extensions/TemplateAdventures/Templates/CitationCore.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TemplateAdventures/TemplateAdventures.i18n.magic.php
@@ -3,6 +3,13 @@
44 $magicWords = array();
55
66 $magicWords['en'] = array(
7 - 'citationcore' => array( 1, 'citationcore' ),
8 - 'ta_cc_author' => array( 0, 'author' ),
 7+ 'citationcore' => array( 1, 'citationcore' ),
 8+ 'ta_cc_author' => array( 0, 'author' ),
 9+ 'ta_cc_authorsurname' => array( 0, 'surname' ),
 10+ 'ta_cc_authorgiven' => array( 0, 'given' ),
 11+ 'ta_cc_authorlink' => array( 0, 'authorlink' ),
 12+ 'ta_cc_editor' => array( 0, 'editor' ),
 13+ 'ta_cc_editorsurname' => array( 0, 'editorsurname' ),
 14+ 'ta_cc_editorgiven' => array( 0, 'editorgiven' ),
 15+ 'ta_cc_editorlink' => array( 0, 'editorlink' ),
916 );
Index: trunk/extensions/TemplateAdventures/Templates/CitationCore.php
@@ -2,18 +2,173 @@
33
44 class CitationCore extends TemplateAdventureBasic {
55
6 - private $dAuthors = array();
 6+ private $dSeparators = array( # separators between names, items, etc.
 7+ 'regular' => ', ',
 8+ 'author' => ', ',
 9+ 'ampersand' => ' & ',
 10+ );
 11+ private $dAuthorTruncate = 8; # the amount of authors it should display,
 12+ # if truncated, 'et al' will be used instead.
 13+ private $dAuthors = array(); # array of authors
 14+ private $dAuthorLinks = array(); # array of authorlinks (tied to authors).
 15+ private $dCoAuthors = array(); # array of coauthors
 16+ private $dEditors = array(); # array of editors
 17+ private $dEditorLinks = array(); # array of editorlinks (tied to editors).
 18+ private $dAuthorBlock = null; # authorblock of em length
 19+ private $dDate = null; # the date set
 20+ private $dAccessDate = null; # date accessed
 21+ private $dYear = null; # year of authorship or publication
 22+ private $dYearNote = null; # note to accompany the year
 23+ private $dWorkTitle = array( # data related to the title
 24+ 'title' => null,
 25+ 'transtitle' => null, # translated title (if original title is
 26+ # in a foreign language).
 27+ 'transitalic' => null, # translated title in italic
 28+ 'includedwork' => null,
 29+ 'type' => null, # the title type
 30+ );
 31+ private $dWorkLink = array( # data related to the link
 32+ 'url' => null,
 33+ 'originalurl' => null,
 34+ 'includedwork' => null,
 35+ 'at' => null, # wherein the source
 36+ );
 37+ private $dArchived = array( # information about its archiving if archived
 38+ 'url' => null,
 39+ 'date' => null,
 40+ );
 41+ private $dPubMed = array(
 42+ 'pmc' => null, # PMC link
 43+ 'pmid' => null, # PMID
 44+ );
 45+ private $dSeries = null; # whether it is part of a series
 46+ private $dQuote = null; # quote
 47+ private $dPublisher = null; # publisher
 48+ private $dPublication = array( # publication
 49+ 'data' => null,
 50+ 'place' => null,
 51+ );
 52+ private $dPlace = null; # place of writing
 53+ private $dPeriodical = array( # name of periodical, journal or magazine.
 54+ 'name' => null, # ensures it will be rendered as such
 55+ 'issue' => null,
 56+ 'issn' => null,
 57+ );
 58+ private $dLibrary = null; # library id
 59+ private $dISBN = null; # isbn number
 60+ private $dLay = array( # an article of the same publication, but
 61+ # written in more layman friendly fashion.
 62+ 'data' => null,
 63+ 'summary' => null
 64+ );
 65+ private $dLanguage = null; # language of the publication
 66+ private $dId = null; # misc id
 67+ private $dEdition = null; # edition
 68+ private $dDoi = array( # digital object identifier
 69+ 'id' => null,
 70+ 'broken' => null, # date broken
 71+ );
 72+ private $dBibcode = null; # bibcode id
 73+ private $dOther = null; # other stuff
774
875 public function parse() {
976 $this->readOptions( );
10 - $this->mOutput = "''{$this->dAuthors[0]}''";
 77+ $this->mOutput = "Not implemented!";
1178 }
1279
 80+ private function addEditorLink( $name, $value ) {
 81+ if ( $name[1] == null )
 82+ return;
 83+ $this->dEditorLinks[$name[1]] = $value;
 84+ }
 85+
 86+ private function addEditor( $name, $value ) {
 87+ $this->appendEditorData ( $name[1], $value );
 88+ }
 89+
 90+ private function addEditorSurname( $name, $value ) {
 91+ $this->appendEditorData ( $name[1], array ( null, $value ) );
 92+ }
 93+
 94+ private function addEditorGivenName ( $name, $value ) {
 95+ $this->appendEditorData ( $name[1], array ( $value, null ) );
 96+ }
 97+
 98+ private function appendEditorData( $num, $name ) {
 99+ $this->appendWriterData( $this->dEditors, $num, $name );
 100+ }
 101+
 102+ private function addAuthorLink( $name, $value ) {
 103+ if ( $name[1] == null )
 104+ return;
 105+ $this->dAuthorLinks[$name[1]] = $value;
 106+ }
 107+
 108+ private function addAuthor( $name, $value ) {
 109+ $this->appendAuthorData ( $name[1], $value );
 110+ }
 111+
 112+ private function addAuthorSurname( $name, $value ) {
 113+ $this->appendAuthorData ( $name[1], array ( null, $value ) );
 114+ }
 115+
 116+ private function addAuthorGivenName ( $name, $value ) {
 117+ $this->appendAuthorData ( $name[1], array ( $value, null ) );
 118+ }
 119+
 120+ private function appendAuthorData( $num, $name ) {
 121+ $this->appendWriterData( $this->dAuthors, $num, $name );
 122+ }
 123+
 124+ private function appendWriterData( &$array, $num, $name ) {
 125+ $split = is_array( $name );
 126+ if ( $num != null ) {
 127+ if ( isset($array[$num]) && $array[$num][0] ) {
 128+ if ( $name[0] != null )
 129+ $array[$num][1][0] = $name[0];
 130+ else
 131+ $array[$num][1][1] = $name[1];
 132+ } else {
 133+ $array[$num] = array (
 134+ $split,
 135+ $name
 136+ );
 137+ }
 138+ } else {
 139+ $array[] = array (
 140+ $split,
 141+ $name
 142+ );
 143+ }
 144+ }
 145+
13146 protected function optionParse( $var, $value ) {
14 - switch ( $name = self::parseOptionName( $var ) ) {
 147+ $name = self::parseOptionName( $var );
 148+ switch ( $name[0] ) {
15149 case 'author':
16 - $this->dAuthors[] = $value;
 150+ $this->addAuthor( $name, $value );
17151 break;
 152+ case 'authorsurname':
 153+ $this->addAuthorSurname( $name, $value );
 154+ break;
 155+ case 'authorgiven':
 156+ $this->addAuthorGivenName( $name, $value );
 157+ break;
 158+ case 'authorlink':
 159+ $this->addAuthorLink( $name, $value );
 160+ break;
 161+ case 'editor':
 162+ $this->addEditor( $name, $value );
 163+ break;
 164+ case 'editorsurname':
 165+ $this->addEditorSurname( $name, $value );
 166+ break;
 167+ case 'editorgiven':
 168+ $this->addEditorGivenName( $name, $value );
 169+ break;
 170+ case 'editorlink':
 171+ $this->addEditorLink( $name, $value );
 172+ break;
18173 default:
19174 # Wasn't an option after all
20175 return $arg instanceof PPNode_DOM
@@ -32,11 +187,22 @@
33188 ) );
34189 }
35190
36 - if ( $name = $magicWords->matchStartToEnd( trim($value) ) ) {
37 - return str_replace( 'ta_cc_', '', $name );
 191+ $num = preg_replace("@.*?([0-9]+)$@is", '\1', $value);
 192+ if (is_numeric( $num ))
 193+ $name = preg_replace("@(.*?)[0-9]+$@is", '\1', $value);
 194+ else {
 195+ $name = $value;
 196+ $num = null;
38197 }
 198+
 199+ if ( $name = $magicWords->matchStartToEnd( trim($name) ) ) {
 200+ return array(
 201+ str_replace( 'ta_cc_', '', $name ),
 202+ $num,
 203+ );
 204+ }
39205
40206 # blimey, so not an option!?
41 - return false;
 207+ return array( false, null );
42208 }
43209 }

Status & tagging log