http://www.mediawiki.org/wiki/Special:Code/MediaWiki/96630

Revision: 96630
Author:   aaron
Date:     2011-09-08 23:37:31 +0000 (Thu, 08 Sep 2011)
Log Message:
-----------
* Moved $view->addStabilizationLink to BeforePageDisplay hook so it actually 
works. Output page no longer seems to accept changes this late.
* Call addReviewForm() from both BeforePageDisplay and SkinAfterContent hooks 
as needed. This fixes a similar problem with prepending to OutputPage too late.
* Removed old dead reviewNotes code (this feature was removed).
* Avoided use of $wgOut in FlaggedPageView.

Modified Paths:
--------------
    trunk/extensions/FlaggedRevs/presentation/FlaggedPageView.php
    trunk/extensions/FlaggedRevs/presentation/FlaggedRevsUI.hooks.php

Modified: trunk/extensions/FlaggedRevs/presentation/FlaggedPageView.php
===================================================================
--- trunk/extensions/FlaggedRevs/presentation/FlaggedPageView.php       
2011-09-08 23:33:10 UTC (rev 96629)
+++ trunk/extensions/FlaggedRevs/presentation/FlaggedPageView.php       
2011-09-08 23:37:31 UTC (rev 96630)
@@ -12,7 +12,6 @@
        protected $isDiffFromStable = false;
        protected $isMultiPageDiff = false;
        protected $reviewNotice = '';
-       protected $reviewNotes = '';
        protected $diffNoticeBox = '';
        protected $reviewFormRev = false;
 
@@ -44,20 +43,20 @@
        * Load the global FlaggedPage instance
        */
        protected function load() {
-               global $wgOut;
                if ( !$this->loaded ) {
                        $this->loaded = true;
                        $this->article = self::globalArticleInstance();
                        if ( $this->article == null ) {
                                throw new MWException( 'FlaggedPageView has no 
context article!' );
                        }
-                       $this->out = $wgOut;
+                       $this->out = RequestContext::getMain()->getOutput();
                }
        }
 
        /**
         * Get the FlaggedPage instance associated with $wgTitle,
         * or false if there isn't such a title
+        * @return FlaggedPage|null
         */
        public static function globalArticleInstance() {
                $title = RequestContext::getMain()->getTitle();
@@ -67,6 +66,14 @@
                return null;
        }
 
+       /*
+        * Check if the old and new diff revs are set for this page view
+        * @return bool
+        */
+       public function diffRevsAreSet() {
+               return (bool)$this->diffRevs;
+       }
+
        /**
         * Is this web response for a request to view a page where both:
         * (a) no specific page version was requested via URL params
@@ -1048,10 +1055,12 @@
        }
 
         /**
-        * Add review form to pages when necessary
-        * on a regular page view (action=view)
+        * Add review form to pages when necessary on a regular page view 
(action=view).
+        * If $output is an OutputPage then this prepends the form onto it.
+        * If $output is a string then this appends the review form to it.
+        * @param mixed string|OutputPage
         */
-       public function addReviewForm( &$data ) {
+       public function addReviewForm( &$output ) {
                global $wgRequest, $wgUser;
                $this->load();
                if ( $this->out->isPrintable() ) {
@@ -1108,11 +1117,11 @@
 
                        list( $html, $status ) = $form->getHtml();
                        # Diff action: place the form at the top of the page
-                       if ( $this->diffRevs ) {
-                               $this->out->prependHTML( $html );
+                       if ( $output instanceof OutputPage ) {
+                               $output->prependHTML( $html );
                        # View action: place the form at the bottom of the page
                        } else {
-                               $data .= $html;
+                               $output .= $html;
                        }
                }
                return true;
@@ -1121,7 +1130,7 @@
         /**
         * Add link to stable version setting to protection form
         */
-       public function addStabilizationLink( &$data ) {
+       public function addStabilizationLink() {
                global $wgRequest;
                $this->load();
                if ( FlaggedRevs::useProtectionLevels() ) {
@@ -1885,16 +1894,4 @@
                }
                return $editPage->fr_baseRevId;
        }
-
-        /**
-        * Adds brief review notes to a page.
-        * @param OutputPage $out
-        */
-       public function addReviewNotes( &$data ) {
-               $this->load();
-               if ( $this->reviewNotes ) {
-                       $data .= $this->reviewNotes;
-               }
-               return true;
-       }
 }

Modified: trunk/extensions/FlaggedRevs/presentation/FlaggedRevsUI.hooks.php
===================================================================
--- trunk/extensions/FlaggedRevs/presentation/FlaggedRevsUI.hooks.php   
2011-09-08 23:33:10 UTC (rev 96629)
+++ trunk/extensions/FlaggedRevs/presentation/FlaggedRevsUI.hooks.php   
2011-09-08 23:37:31 UTC (rev 96630)
@@ -101,7 +101,15 @@
        public static function onBeforePageDisplay( &$out, &$skin ) {
                if ( $out->getTitle()->getNamespace() != NS_SPECIAL ) {
                        $view = FlaggedPageView::singleton();
+                       $view->addStabilizationLink(); // link on protect form
                        $view->displayTag(); // show notice bar/icon in subtitle
+                       if ( $out->isArticleRelated() ) {
+                               // Only use this hook if we want to prepend the 
form.
+                               // We prepend the form for diffs, so only 
handle that case here.
+                               if ( $view->diffRevsAreSet() ) {
+                                       $view->addReviewForm( $out ); // form 
to be prepended
+                               }
+                       }
                        $view->setRobotPolicy(); // set indexing policy
                        self::injectStyleAndJS(); // full CSS/JS
                } else {
@@ -323,9 +331,11 @@
                        && FlaggedPageView::globalArticleInstance() != null )
                {
                        $view = FlaggedPageView::singleton();
-                       $view->addReviewNotes( $data );
-                       $view->addReviewForm( $data );
-                       $view->addStabilizationLink( $data );
+                       // Only use this hook if we want to append the form.
+                       // We *prepend* the form for diffs, so skip that case 
here.
+                       if ( !$view->diffRevsAreSet() ) {
+                               $view->addReviewForm( $data ); // form to be 
appended
+                       }
                }
                return true;
        }


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to