r104334 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104333‎ | r104334 | r104335 >
Date:09:39, 27 November 2011
Author:ialex
Status:ok (Comments)
Tags:
Comment:
* Use WikiPage instead of Article in Skin and SkinTemplate
* Added $context parameter to Action::factory() to allow callers passing a WikiPage object in addition to Article (otherwise this would throw a fatal error in getContext() since WikiPage::getContext() does not exist)
Modified paths:
  • /trunk/phase3/includes/Action.php (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SkinTemplate.php
@@ -329,9 +329,9 @@
330330 $tpl->set( 'numberofwatchingusers', false );
331331 if ( $out->isArticle() && $this->getTitle()->exists() ) {
332332 if ( $this->isRevisionCurrent() ) {
333 - $article = new Article( $this->getTitle(), 0 );
 333+ $page = WikiPage::factory( $this->getTitle() );
334334 if ( !$wgDisableCounters ) {
335 - $viewcount = $article->getCount();
 335+ $viewcount = $page->getCount();
336336 if ( $viewcount ) {
337337 $tpl->set( 'viewcount', $this->msg( 'viewcount' )->numParams( $viewcount )->parse() );
338338 }
@@ -351,9 +351,9 @@
352352 }
353353
354354 if ( $wgMaxCredits != 0 ) {
355 - $tpl->set( 'credits', Action::factory( 'credits', $article )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
 355+ $tpl->set( 'credits', Action::factory( 'credits', $page, $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
356356 } else {
357 - $tpl->set( 'lastmod', $this->lastModified( $article ) );
 357+ $tpl->set( 'lastmod', $this->lastModified( $page ) );
358358 }
359359 }
360360 $tpl->set( 'copyright', $this->getCopyright() );
Index: trunk/phase3/includes/Skin.php
@@ -790,14 +790,14 @@
791791 /**
792792 * Get the timestamp of the latest revision, formatted in user language
793793 *
794 - * @param $article Article object. Used if we're working with the current revision
 794+ * @param $page WikiPage object. Used if we're working with the current revision
795795 * @return String
796796 */
797 - protected function lastModified( $article ) {
 797+ protected function lastModified( $page ) {
798798 if ( !$this->isRevisionCurrent() ) {
799799 $timestamp = Revision::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
800800 } else {
801 - $timestamp = $article->getTimestamp();
 801+ $timestamp = $page->getTimestamp();
802802 }
803803
804804 if ( $timestamp ) {
Index: trunk/phase3/includes/Action.php
@@ -27,7 +27,7 @@
2828
2929 /**
3030 * Page on which we're performing the action
31 - * @var Article
 31+ * @var Page
3232 */
3333 protected $page;
3434
@@ -72,14 +72,15 @@
7373 /**
7474 * Get an appropriate Action subclass for the given action
7575 * @param $action String
76 - * @param $page Article
 76+ * @param $page Page
 77+ * @param $context IContextSource
7778 * @return Action|false|null false if the action is disabled, null
7879 * if it is not recognised
7980 */
80 - public final static function factory( $action, Page $page ) {
 81+ public final static function factory( $action, Page $page, IContextSource $context = null ) {
8182 $class = self::getClass( $action, $page->getActionOverrides() );
8283 if ( $class ) {
83 - $obj = new $class( $page );
 84+ $obj = new $class( $page, $context );
8485 return $obj;
8586 }
8687 return $class;
@@ -183,10 +184,12 @@
184185 /**
185186 * Protected constructor: use Action::factory( $action, $page ) to actually build
186187 * these things in the real world
187 - * @param Page $page
 188+ * @param $page Page
 189+ * @param $context IContextSource
188190 */
189 - protected function __construct( Page $page ) {
 191+ protected function __construct( Page $page, IContextSource $context = null ) {
190192 $this->page = $page;
 193+ $this->context = $context;
191194 }
192195
193196 /**

Comments

#Comment by Dantman (talk | contribs)   11:18, 27 November 2011

This pattern of passing both a WikiPage referring to a title and a Context which contains a title looks completely messed up.

I started a wikitech-l discussion on a better way to do this: http://thread.gmane.org/gmane.science.linguistics.wikipedia.technical/56890

#Comment by Aaron Schulz (talk | contribs)   00:41, 14 December 2011

Can we stop changing Action related things? There is pending RfC to replace those with SpecialPages.

Status & tagging log