r86472 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86471‎ | r86472 | r86473 >
Date:12:22, 20 April 2011
Author:svip
Status:deferred
Tags:
Comment:
Follow up to r86440: In an effort to clean up the code, sections are now in an array (to be put together later), but I am worried about if this will decrease performance significantly before proceeding too much. And if there are suggestions/comments before I change everything.
Modified paths:
  • /trunk/extensions/TemplateAdventures/Templates/Citation.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TemplateAdventures/Templates/Citation.php
@@ -69,8 +69,7 @@
7070 'isbn' => null,
7171 'page' => null
7272 );
73 - private $dISBN = null; # isbn number
74 - private $dLay = array( # an article of the same publication, but
 73+ private $dLayman = array( # an article of the same publication, but
7574 # written in more layman friendly fashion.
7675 'data' => null,
7776 'summary' => null
@@ -88,6 +87,9 @@
8988 'page' => null,
9089 );
9190 private $dOther = null; # other stuff
 91+
 92+ private $mSections = array(); # sections of the citation.
 93+ private $mTags = array(); # all tags
9294
9395 /**
9496 * Our construct function.
@@ -104,6 +106,45 @@
105107 $this->readOptions( );
106108 $this->parseData();
107109 }
 110+
 111+ /**
 112+ * Add a section to mSections.
 113+ *
 114+ * @param $content The content of section.
 115+ * @param $tags [default: array()] Some information regarding the content.
 116+ */
 117+ private function addCiteSection ( $content, $tags = array () ) {
 118+ $this->mSections[] = array (
 119+ $tags,
 120+ $content
 121+ );
 122+ $this->mTags = array_merge ( $this->mTags, $tags );
 123+ }
 124+
 125+ /**
 126+ * Detect if a tag has been set in a section.
 127+ *
 128+ * Note that parent means the first tag of a section's array tag, which
 129+ * describes - in most cases at least - what the content is, while the
 130+ * other tags further details this. It may sometimes be important to find
 131+ * a tag only if its parent tag is something specific.
 132+ *
 133+ * @param $tag Tag to search for.
 134+ * @param $parent [optional] The tag's parent.
 135+ * @return Boolean True if found, false if not.
 136+ */
 137+ private function isTagInSections ( $tag, $parent = null ) {
 138+ if ( $this->notNull ( $parent ) ) {
 139+ foreach ( $this->mSection as $section ) {
 140+ if ( in_array ( $tag, $section[0] )
 141+ && $section[0][0] == $parent )
 142+ return true;
 143+ }
 144+ return false;
 145+ } else {
 146+ return in_array ( $tag, $this->mTags );
 147+ }
 148+ }
108149
109150 /**
110151 * Render the data after the data have been read.
@@ -112,6 +153,8 @@
113154 */
114155 public function render() {
115156 # 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.
116159 $urlDisplayed = false; # whether the url has been displayed
117160 $authorDisplayed = false; # whether authors or editors have been
118161 # displayed
@@ -141,6 +184,8 @@
142185 $authorArea,
143186 $this->dYearNote );
144187 }
 188+ $this->addSection ( $authorArea, array ( 'writer', 'author' ) );
 189+ # TODO: remove this
145190 $this->mOutput .= $authorArea . $this->getSeparator ( 'section' );
146191 $authorDisplayed = true;
147192 # editors
@@ -164,6 +209,8 @@
165210 $editorArea .= wfMsg ( 'ta-citeauthoryearnote',
166211 $editorArea, $this->dYearNote );
167212 }
 213+ $this->addSection ( $editorArea, array ( 'writer', 'editor' ) );
 214+ # TODO: remove this
168215 $this->mOutput .= $editorArea . $this->getSeparator ( 'section' );
169216 $authorDisplayed = true;
170217 }
@@ -202,6 +249,9 @@
203250 }
204251 $title = $tmp;
205252 }
 253+ $this->addSection ( $this->makeLink ( $url, $title ),
 254+ array ( 'title', 'includedlink' ) );
 255+ # TODO: Remove this
206256 $this->mOutput .= $this->makeLink ( $url, $title ) . $this->getSeparator( 'section' );
207257 $urlDisplayed = true;
208258 } else if ( $this->notNull ( $this->dWorkTitle['title'] ) ) {
@@ -212,18 +262,31 @@
213263 $this->dWorkTitle['title'],
214264 $this->dWorkTitle['transtitle'] );
215265 if ( $this->notNull ( $this->dLanguage ) ) {
 266+ $this->addSection ( wfMsg ( 'ta-citeinlanguage',
 267+ $this->makeLink ( $url, $title ), $this->dLanguage ),
 268+ array ( 'title', 'transtitle', 'language' ) );
 269+ # TODO: Remove this
216270 $this->mOutput .= wfMsg ( 'ta-citeinlanguage', $this->makeLink ( $url, $title ), $this->dLanguage ) . $this->getSeparator( 'section' );
217271 $languageDisplayed = true;
218272 } else {
 273+ $this->addSection ( $this->makeLink ( $url, $title ),
 274+ array ( 'title', 'transtitle' ) );
 275+ # TODO: Remove this
219276 $this->mOutput .= $this->makeLink ( $url, $title ) . $this->getSeparator( 'section' );
220277 }
221278 } else {
222279 $title = $this->dWorkTitle['title'];
 280+ $this->addSection ( $this->makeLink ( $url, $title ),
 281+ array ( 'title' ) );
 282+ # TODO: Remove this
223283 $this->mOutput .= $this->makeLink ( $url, $title ) . $this->getSeparator( 'section' );
224284 }
225285 $urlDisplayed = true;
226286 } else if ( $this->citeType == 'book'
227287 && $this->notNull ( $this->dBook['title'] ) ) {
 288+ $this->addSection ( wfMsg ( 'ta-citebooktitle', $this->dBook['title'] ),
 289+ array ( 'title', 'book' ) );
 290+ # TODO: Remove this
228291 $this->mOutput .= wfMsg ( 'ta-citebooktitle', $this->dBook['title'] ) .$this->getSeparator ( 'section' );
229292 }
230293 # place, but only if different from publication place.
@@ -238,9 +301,16 @@
239302 ) {
240303 if ( $this->notNull ( $this->dPublisher )
241304 && ( $this->citeType != 'news' ) ) {
 305+ $this->addSection ( wfMsg ( 'ta-citeplacepublisher',
 306+ $this->dPlace, $this->dPublisher ),
 307+ array ( 'place', 'publisher' ) );
 308+ # TODO: Remove this
242309 $this->mOutput .= wfMsg ( 'ta-citeplacepublisher', $this->dPlace,$this->dPublisher ) . $this->getSeparator ( 'section' );
243310 $publisherDisplayed = true;
244311 } else {
 312+ $this->addSection ( wfMsg ( 'ta-citewrittenat', $this->dPlace ),
 313+ array ( 'place' ) );
 314+ # TODO: Remove this
245315 $this->mOutput .= wfMsg ( 'ta-citewrittenat', $this->dPlace ) . $this->getSeparator ( 'section' );
246316 }
247317 }

Follow-up revisions

RevisionCommit summaryAuthorDate
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
r86440Follow up to r86340. Added more functionality to Citation.php. STill not done.svip22:19, 19 April 2011

Status & tagging log