In FlaggedRevs:
authorTim Starling <tstarling@users.mediawiki.org>
Fri, 23 May 2008 09:03:49 +0000 (09:03 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Fri, 23 May 2008 09:03:49 +0000 (09:03 +0000)
* Moved the FlaggedRevs class to its own file
* Removed $wgFlaggedArticle, store an instance inside the Article object instead. Also store a reference in the Title object, since some hooks only have a Title available.
* Modified all hooks which were previously calling $wgFlaggedArticle directly to go via an instance loader function.
* Merged hook functions for ArticleViewHeader and DiffViewHeader
* Changed the way FlaggedRevs sets the right image version in ImagePage, to avoid a function call on startup
* Some coding style changes, such as consistent variable case, consistent indenting style, meaningful variable names, etc.
* Fixed typo in updateAutoPromote.php
* Removed the $wgFlaggedRevsVisible feature, this doesn't seem to be in keeping with our mission so I couldn't see the point in spending a lot of time fixing its bugs. Revert if necessary.
* Use Xml::encodeJsVar() to transfer data from PHP to JS, don't DIY
* Use OutputPage::addHeadItem() instead of an infinite-lifetime variable to ensure that only one copy of the header item is added. OutputPage objects may come and go.

includes/Article.php
includes/DifferenceEngine.php
includes/ImagePage.php
includes/PageHistory.php

index 82cf979..bc2d594 100644 (file)
@@ -1324,10 +1324,10 @@ class Article {
                                }
                        }
 
-                       $extraq = ''; // Give extensions a chance to modify URL query on update
-                       wfRunHooks( 'ArticleUpdateBeforeRedirect', array( $this, &$sectionanchor, &$extraq ) );
+                       $extraQuery = ''; // Give extensions a chance to modify URL query on update
+                       wfRunHooks( 'ArticleUpdateBeforeRedirect', array( $this, &$sectionanchor, &$extraQuery ) );
 
-                       $this->doRedirect( $this->isRedirect( $text ), $sectionanchor, $extraq );
+                       $this->doRedirect( $this->isRedirect( $text ), $sectionanchor, $extraQuery );
                }
                return $good;
        }
@@ -1573,16 +1573,16 @@ class Article {
         *
         * @param boolean $noRedir Add redirect=no
         * @param string $sectionAnchor section to redirect to, including "#"
-        * @param string $extraq, extra query params
+        * @param string $extraQuery, extra query params
         */
-       function doRedirect( $noRedir = false, $sectionAnchor = '', $extraq = '' ) {
+       function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) {
                global $wgOut;
                if ( $noRedir ) {
                        $query = 'redirect=no';
-                       if( $extraq )
+                       if( $extraQuery )
                                $query .= "&$query";
                } else {
-                       $query = $extraq;
+                       $query = $extraQuery;
                }
                $wgOut->redirect( $this->mTitle->getFullURL( $query ) . $sectionAnchor );
        }
index 7a2f3f7..09f8849 100644 (file)
@@ -73,6 +73,10 @@ class DifferenceEngine {
                $this->mRefreshCache = $refreshCache;
        }
 
+       function getTitle() {
+               return $this->mTitle;
+       }
+
        function showDiffPage( $diffOnly = false ) {
                global $wgUser, $wgOut, $wgUseExternalEditor, $wgUseRCPatrol;
                wfProfileIn( __METHOD__ );
index 3b0c6b7..cec94c7 100644 (file)
@@ -13,45 +13,36 @@ class ImagePage extends Article {
        /* private */ var $img;  // Image object
        /* private */ var $displayImg;
        /* private */ var $repo;
-       /* private */ var $time;
        /* private */ var $fileLoaded;
        var $mExtraDescription = false;
        var $dupes;
 
-       function __construct( $title, $time = null ) {
+       function __construct( $title ) {
                parent::__construct( $title );
 
                global $wgRequest;
-               $time = is_null($time) ? $wgRequest->getVal( 'filetimestamp' ) : $time;
-               $time = $time ? $time : false; // be clear about type
-               $this->time = $time;
                $this->dupes = null;
                $this->repo = null;
        }
-       
+
        protected function loadFile() {
                if ( $this->fileLoaded ) {
                        return true;
                }
-               $this->displayImg = wfFindFile( $this->mTitle, $this->time );
-               # If none found, and no time given, use a valid local placeholder
-               if ( !$this->displayImg && !$this->time ) {
-                       $this->displayImg = wfLocalFile( $this->mTitle );
-                       $this->img = $this->displayImg;
-               # If none found, and time given, try current
-               } else if ( !$this->displayImg && $this->time ) {
-                       $this->displayImg = wfFindFile( $this->mTitle );
-                       # If none found, use a valid local placeholder
-                       if( !$this->displayImg ) {
-                               $this->displayImg = wfLocalFile( $this->mTitle ); // fallback to current
+               $this->fileLoaded = true;
+
+               $this->displayImg = $this->img = false;
+               wfRunHooks( 'ImagePageFindFile', array( $this, &$this->img, &$this->displayImg ) );
+               if ( !$this->img ) {
+                       $this->img = wfFindFile( $this->mTitle );
+                       if ( !$this->img ) {
+                               $this->img = wfLocalFile( $this->mTitle );
                        }
-                       $this->img = $this->displayImg;
-               # If found, set $this->img. This will be the same if no time given
-               } else {
-                       $this->img = $this->time ? wfFindFile( $this->mTitle ) : $this->displayImg;
+               }
+               if ( !$this->displayImg ) {
+                       $this->displayImg = $this->img;
                }
                $this->repo = $this->img->getRepo();
-               $this->fileLoaded = true;
        }
 
        /**
@@ -609,13 +600,11 @@ EOT
         */
        function imageHistory()
        {
-               global $wgUser, $wgOut, $wgUseExternalEditor;
-
-               $sk = $wgUser->getSkin();
+               global $wgOut, $wgUseExternalEditor;
 
                $this->loadFile();
                if ( $this->img->exists() ) {
-                       $list = new ImageHistoryList( $sk, $this->img, $this->displayImg );
+                       $list = new ImageHistoryList( $this );
                        $file = $this->img;
                        $dims = $file->getDimensionsString();
                        $s = $list->beginImageHistoryList();
@@ -786,13 +775,27 @@ EOT
  */
 class ImageHistoryList {
 
-       protected $img, $skin, $title, $repo;
+       protected $imagePage, $img, $skin, $title, $repo;
+
+       public function __construct( $imagePage ) {
+               global $wgUser;
+               $this->skin = $wgUser->getSkin();
+               $this->current = $imagePage->getFile();
+               $this->img = $imagePage->getDisplayedFile();
+               $this->title = $imagePage->getTitle();
+               $this->imagePage = $imagePage;
+       }
+
+       function getImagePage() {
+               return $this->imagePage;
+       }
+
+       function getSkin() {
+               return $this->skin;
+       }
 
-       public function __construct( $skin, $curimg, $img ) {
-               $this->skin = $skin;
-               $this->current = $curimg;
-               $this->img = $img;
-               $this->title = $img->getTitle();
+       function getFile() {
+               return $this->img;
        }
 
        public function beginImageHistoryList() {
@@ -936,9 +939,9 @@ class ImageHistoryList {
                }
                $row .= '</td>';
 
-               wfRunHooks( 'ImagePageFileHistoryLine', array( &$file, &$row, &$css ) );
-               $trCSS = $css ? " class='$css'" : "";
+               wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) );
+               $classAttr = $rowClass ? " class='$rowClass'" : "";
 
-               return "<tr{$trCSS}>{$row}</tr>\n";
+               return "<tr{$classAttr}>{$row}</tr>\n";
        }
 }
index 9f9bbbe..7f7548d 100644 (file)
@@ -41,6 +41,10 @@ class PageHistory {
                $this->preCacheMessages();
        }
 
+       function getArticle() {
+               return $this->mArticle;
+       }
+
        /**
         * As we use the same small set of messages in various methods and that
         * they are called often, we call them once and save them in $this->message
@@ -281,7 +285,7 @@ class PageHistory {
                        $s .= ' (' . implode( ' | ', $tools ) . ')';
                }
 
-               wfRunHooks( 'PageHistoryLineEnding', array( &$row , &$s ) );
+               wfRunHooks( 'PageHistoryLineEnding', array( $this, &$row , &$s ) );
 
                return "<li>$s</li>\n";
        }