@@ -45,6 +45,13 @@ public function __construct($id, $chunk_size = 8192)
4545 */
4646 abstract protected function getFilename ($ rev = '' );
4747
48+ /**
49+ * Returns mode
50+ *
51+ * @return string RevisionInfo::MODE_MEDIA or RevisionInfo::MODE_PAGE
52+ */
53+ abstract protected function getMode ();
54+
4855 /**
4956 * Check whether given revision is the current page
5057 *
@@ -99,17 +106,20 @@ public function lastRevision()
99106 }
100107
101108 /**
102- * Save revision info to the cache pool
109+ * Parses a changelog line into its components and save revision info to the cache pool
103110 *
104- * @param array $info Revision info structure
105- * @return bool
111+ * @param string $value changelog line
112+ * @return array| bool parsed line or false
106113 */
107- protected function cacheRevisionInfo ( $ info )
114+ protected function parseAndCacheLogLine ( $ value )
108115 {
109- if (!is_array ($ info )) return false ;
110- //$this->cache[$this->id][$info['date']] ??= $info; // since php 7.4
111- $ this ->cache [$ this ->id ][$ info ['date ' ]] ??= $ info ;
112- return true ;
116+ $ info = static ::parseLogLine ($ value );
117+ if (is_array ($ info )) {
118+ $ info ['mode ' ] = $ this ->getMode ();
119+ $ this ->cache [$ this ->id ][$ info ['date ' ]] ??= $ info ;
120+ return $ info ;
121+ }
122+ return false ;
113123 }
114124
115125 /**
@@ -131,6 +141,8 @@ protected function cacheRevisionInfo($info)
131141 * - sum: edit summary (or action reason)
132142 * - extra: extra data (varies by line type)
133143 * - sizechange: change of filesize
144+ * additional:
145+ * - mode: page or media
134146 *
135147 * @author Ben Coburn <[email protected] > 136148 * @author Kate Arzamastseva <[email protected] > @@ -146,7 +158,7 @@ public function getRevisionInfo($rev, $retrieveCurrentRevInfo = true)
146158 }
147159
148160 // check if it's already in the memory cache
149- if (isset ($ this ->cache [$ this ->id ]) && isset ( $ this -> cache [ $ this -> id ] [$ rev ])) {
161+ if (isset ($ this ->cache [$ this ->id ][$ rev ])) {
150162 return $ this ->cache [$ this ->id ][$ rev ];
151163 }
152164
@@ -158,14 +170,11 @@ public function getRevisionInfo($rev, $retrieveCurrentRevInfo = true)
158170 if (empty ($ lines )) return false ;
159171
160172 // parse and cache changelog lines
161- foreach ($ lines as $ value ) {
162- $ info = static ::parseLogLine ($ value );
163- $ this ->cacheRevisionInfo ($ info );
164- }
165- if (!isset ($ this ->cache [$ this ->id ][$ rev ])) {
166- return false ;
173+ foreach ($ lines as $ line ) {
174+ $ this ->parseAndCacheLogLine ($ line );
167175 }
168- return $ this ->cache [$ this ->id ][$ rev ];
176+
177+ return $ this ->cache [$ this ->id ][$ rev ] ?? false ;
169178 }
170179
171180 /**
@@ -285,8 +294,8 @@ public function getRevisions($first, $num)
285294
286295 // handle lines in reverse order
287296 for ($ i = count ($ lines ) - 1 ; $ i >= 0 ; $ i --) {
288- $ info = static :: parseLogLine ($ lines [$ i ]);
289- if ($ this -> cacheRevisionInfo ($ info )) {
297+ $ info = $ this -> parseAndCacheLogLine ($ lines [$ i ]);
298+ if (is_array ($ info )) {
290299 $ revs [] = $ info ['date ' ];
291300 }
292301 }
@@ -342,8 +351,8 @@ public function getRelativeRevision($rev, $direction)
342351 $ step = -1 ;
343352 }
344353 for ($ i = $ start ; $ i >= 0 && $ i < $ count ; $ i += $ step ) {
345- $ info = static :: parseLogLine ($ lines [$ i ]);
346- if ($ this -> cacheRevisionInfo ($ info )) {
354+ $ info = $ this -> parseAndCacheLogLine ($ lines [$ i ]);
355+ if (is_array ($ info )) {
347356 //look for revs older/earlier then reference $rev and select $direction-th one
348357 if (($ direction > 0 && $ info ['date ' ] > $ rev ) || ($ direction < 0 && $ info ['date ' ] < $ rev )) {
349358 $ revCounter ++;
@@ -414,12 +423,14 @@ public function getRevisionsAround($rev1, $rev2, $max = 50)
414423 $ revs1 = $ allRevs ;
415424 while ($ head > 0 ) {
416425 for ($ i = count ($ lines ) - 1 ; $ i >= 0 ; $ i --) {
417- $ info = static :: parseLogLine ($ lines [$ i ]);
418- if ($ this -> cacheRevisionInfo ($ info )) {
426+ $ info = $ this -> parseAndCacheLogLine ($ lines [$ i ]);
427+ if (is_array ($ info )) {
419428 $ revs1 [] = $ info ['date ' ];
420429 $ index ++;
421430
422- if ($ index > (int ) ($ max / 2 )) break 2 ;
431+ if ($ index > (int ) ($ max / 2 )) {
432+ break 2 ;
433+ }
423434 }
424435 }
425436
@@ -490,16 +501,20 @@ protected function retrieveRevisionsAround($rev, $max)
490501 $ tail = $ startTail ;
491502 while (count ($ lines ) > 0 ) {
492503 foreach ($ lines as $ line ) {
493- $ info = static :: parseLogLine ($ line );
494- if ($ this -> cacheRevisionInfo ($ info )) {
504+ $ info = $ this -> parseAndCacheLogLine ($ line );
505+ if (is_array ($ info )) {
495506 $ revs [] = $ info ['date ' ];
496507 if ($ info ['date ' ] >= $ rev ) {
497508 //count revs after reference $rev
498509 $ afterCount ++;
499- if ($ afterCount == 1 ) $ beforeCount = count ($ revs );
510+ if ($ afterCount == 1 ) {
511+ $ beforeCount = count ($ revs );
512+ }
500513 }
501514 //enough revs after reference $rev?
502- if ($ afterCount > (int ) ($ max / 2 )) break 2 ;
515+ if ($ afterCount > (int ) ($ max / 2 )) {
516+ break 2 ;
517+ }
503518 }
504519 }
505520 //retrieve next chunk
@@ -530,12 +545,14 @@ protected function retrieveRevisionsAround($rev, $max)
530545 [$ lines , $ head , $ tail ] = $ this ->readAdjacentChunk ($ fp , $ head , $ tail , -1 );
531546
532547 for ($ i = count ($ lines ) - 1 ; $ i >= 0 ; $ i --) {
533- $ info = static :: parseLogLine ($ lines [$ i ]);
534- if ($ this -> cacheRevisionInfo ($ info )) {
548+ $ info = $ this -> parseAndCacheLogLine ($ lines [$ i ]);
549+ if (is_array ($ info )) {
535550 $ revs [] = $ info ['date ' ];
536551 $ beforeCount ++;
537552 //enough revs before reference $rev?
538- if ($ beforeCount > max ((int ) ($ max / 2 ), $ max - $ afterCount )) break 2 ;
553+ if ($ beforeCount > max ((int ) ($ max / 2 ), $ max - $ afterCount )) {
554+ break 2 ;
555+ }
539556 }
540557 }
541558 }
@@ -575,14 +592,18 @@ protected function retrieveRevisionsAround($rev, $max)
575592 * - extra: extra data (varies by line type)
576593 * - sizechange: change of filesize
577594 * - timestamp: unix timestamp or false (key set only for external edit occurred)
595+ * additional:
596+ * - mode: page or media
578597 *
579598 * @author Satoshi Sahara <[email protected] > 580599 */
581600 public function getCurrentRevisionInfo ()
582601 {
583602 global $ lang ;
584603
585- if (isset ($ this ->currentRevision )) return $ this ->getRevisionInfo ($ this ->currentRevision );
604+ if (isset ($ this ->currentRevision )) {
605+ return $ this ->getRevisionInfo ($ this ->currentRevision );
606+ }
586607
587608 // get revision id from the item file timestamp and changelog
588609 $ fileLastMod = $ this ->getFilename ();
@@ -616,6 +637,7 @@ public function getCurrentRevisionInfo()
616637 'extra ' => '' ,
617638 'sizechange ' => -io_getSizeFile ($ this ->getFilename ($ lastRev )),
618639 'timestamp ' => false ,
640+ 'mode ' => $ this ->getMode ()
619641 ];
620642 } else { // item file exists, with timestamp $fileRev
621643 // here, file timestamp $fileRev is different with last revision timestamp $lastRev in changelog
@@ -654,6 +676,7 @@ public function getCurrentRevisionInfo()
654676 'extra ' => '' ,
655677 'sizechange ' => $ sizechange ,
656678 'timestamp ' => $ timestamp ,
679+ 'mode ' => $ this ->getMode ()
657680 ];
658681 }
659682
0 commit comments