r80001 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80000‎ | r80001 | r80002 >
Date:13:04, 11 January 2011
Author:ialex
Status:resolved
Tags:
Comment:
Simplify a bit:
* replaced calls to Article::getLatest() by Title::getLatestRevID()
* introduced Skin::isRevisionCurrent()
* made checks on Skin::pageStats() more coherent
Modified paths:
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SkinTemplate.php
@@ -245,7 +245,7 @@
246246 $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
247247 $tpl->set( 'titletext', $this->mTitle->getText() );
248248 $tpl->set( 'articleid', $this->mTitle->getArticleId() );
249 - $tpl->set( 'currevisionid', isset( $wgArticle ) ? $wgArticle->getLatest() : 0 );
 249+ $tpl->set( 'currevisionid', $this->mTitle->getLatestRevID() );
250250
251251 $tpl->set( 'isarticle', $out->isArticle() );
252252
@@ -345,7 +345,7 @@
346346 $tpl->setRef( 'skin', $this );
347347 $tpl->set( 'logo', $this->logoText() );
348348 if ( $out->isArticle() && ( !isset( $oldid ) || isset( $diff ) ) &&
349 - $wgArticle && 0 != $wgArticle->getID() ){
 349+ $this->mTitle->exists() ){
350350 if ( !$wgDisableCounters ) {
351351 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
352352 if ( $viewcount ) {
@@ -784,7 +784,7 @@
785785 * @private
786786 */
787787 function buildContentNavigationUrls() {
788 - global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest, $wgArticle;
 788+ global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest;
789789 global $wgDisableLangConversion;
790790
791791 wfProfileIn( __METHOD__ );
@@ -879,7 +879,7 @@
880880 );
881881 // Checks if this is a current rev of talk page and we should show a new
882882 // section link
883 - if ( ( $isTalk && $wgArticle && $wgArticle->isCurrent() ) || ( $wgOut->showNewSectionLink() ) ) {
 883+ if ( ( $isTalk && $this->isRevisionCurrent() ) || ( $wgOut->showNewSectionLink() ) ) {
884884 // Checks if we should ever show a new section link
885885 if ( !$wgOut->forceHideNewSectionLink() ) {
886886 // Adds new section link
Index: trunk/phase3/includes/Skin.php
@@ -355,6 +355,15 @@
356356 }
357357
358358 /**
 359+ * Whether the revision displayed is the latest revision of the page
 360+ *
 361+ * @return Boolean
 362+ */
 363+ public function isRevisionCurrent() {
 364+ return $this->mRevisionId == 0 || $this->mRevisionId != $this->mTitle->getLatestRevID();
 365+ }
 366+
 367+ /**
359368 * Set the title
360369 * @param $t Title object to use
361370 */
@@ -484,7 +493,7 @@
485494 * You will only be adding bloat to the page and causing page caches to have to be purged on configuration changes.
486495 */
487496 static function makeGlobalVariablesScript( $skinName ) {
488 - global $wgTitle, $wgUser, $wgRequest, $wgArticle, $wgOut, $wgUseAjax, $wgEnableMWSuggest;
 497+ global $wgTitle, $wgUser, $wgRequest, $wgOut, $wgUseAjax, $wgEnableMWSuggest;
489498
490499 $ns = $wgTitle->getNamespace();
491500 $nsname = MWNamespace::exists( $ns ) ? MWNamespace::getCanonicalName( $ns ) : $wgTitle->getNsText();
@@ -500,7 +509,7 @@
501510 'wgIsArticle' => $wgOut->isArticle(),
502511 'wgUserName' => $wgUser->isAnon() ? null : $wgUser->getName(),
503512 'wgUserGroups' => $wgUser->getEffectiveGroups(),
504 - 'wgCurRevisionId' => isset( $wgArticle ) ? $wgArticle->getLatest() : 0,
 513+ 'wgCurRevisionId' => $wgTitle->getLatestRevID(),
505514 'wgCategories' => $wgOut->getCategories(),
506515 'wgBreakFrames' => $wgOut->getFrameOptions() == 'DENY',
507516 );
@@ -1473,25 +1482,14 @@
14741483 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
14751484 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
14761485
1477 - $oldid = $wgRequest->getVal( 'oldid' );
1478 - $diff = $wgRequest->getVal( 'diff' );
1479 -
1480 - if ( !$wgOut->isArticle() ) {
 1486+ if ( !is_null( $wgRequest->getVal( 'oldid' ) ) || !is_null( $wgRequest->getVal( 'diff' ) ) ) {
14811487 return '';
14821488 }
14831489
1484 - if ( !$wgArticle instanceof Article ) {
 1490+ if ( !$wgOut->isArticle() || !$this->mTitle->exists() ) {
14851491 return '';
14861492 }
14871493
1488 - if ( isset( $oldid ) || isset( $diff ) ) {
1489 - return '';
1490 - }
1491 -
1492 - if ( 0 == $wgArticle->getID() ) {
1493 - return '';
1494 - }
1495 -
14961494 $s = '';
14971495
14981496 if ( !$wgDisableCounters ) {
@@ -1530,13 +1528,12 @@
15311529 }
15321530
15331531 function getCopyright( $type = 'detect' ) {
1534 - global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
 1532+ global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
15351533
15361534 if ( $type == 'detect' ) {
15371535 $diff = $wgRequest->getVal( 'diff' );
1538 - $isCur = $wgArticle && $wgArticle->isCurrent();
15391536
1540 - if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
 1537+ if ( is_null( $diff ) && !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
15411538 $type = 'history';
15421539 } else {
15431540 $type = 'normal';
@@ -1619,8 +1616,8 @@
16201617 function lastModified() {
16211618 global $wgLang, $wgArticle;
16221619
1623 - if ( $this->mRevisionId && $this->mRevisionId != $wgArticle->getLatest() ) {
1624 - $timestamp = Revision::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId );
 1620+ if ( !$this->isRevisionCurrent() ) {
 1621+ $timestamp = Revision::getTimestampFromId( $this->mTitle, $this->mRevisionId );
16251622 } else {
16261623 $timestamp = $wgArticle->getTimestamp();
16271624 }
@@ -1803,11 +1800,9 @@
18041801 * @private
18051802 */
18061803 function editUrlOptions() {
1807 - global $wgArticle;
1808 -
18091804 $options = array( 'action' => 'edit' );
18101805
1811 - if ( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
 1806+ if ( !$this->isRevisionCurrent() ) {
18121807 $options['oldid'] = intval( $this->mRevisionId );
18131808 }
18141809

Follow-up revisions

RevisionCommit summaryAuthorDate
r80002Seems there was a logic error in r80001 :)ialex13:08, 11 January 2011

Status & tagging log