r44520 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44519‎ | r44520 | r44521 >
Date:02:40, 13 December 2008
Author:vyznev
Status:ok
Tags:
Comment:
(bug 5506) Make Title::isAlwaysKnown() return true for known special pages and files in foreign repos.

Besides fixing the display of the latter in logs, edit summaries and other places relying on Linker::link(),
the change should allow considerable simplification (not included in this commit) of that function, as
well as of several related functions e.g. in the Parser and Skin classes. To that end, I've also introduced
a new function Title::isKnown() to wrap the common condition "$title->exists() || $title->isAlwaysKnown()",
and have clarified the roles of the three methods.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Title.php
@@ -3093,7 +3093,12 @@
30943094 }
30953095
30963096 /**
3097 - * Check if page exists
 3097+ * Check if page exists. For historical reasons, this function simply
 3098+ * checks for the existence of the title in the page table, and will
 3099+ * thus return false for interwiki links, special pages and the like.
 3100+ * If you want to know if a title can be meaningfully viewed, you should
 3101+ * probably call the isKnown() method instead.
 3102+ *
30983103 * @return \type{\bool} TRUE or FALSE
30993104 */
31003105 public function exists() {
@@ -3101,24 +3106,54 @@
31023107 }
31033108
31043109 /**
3105 - * Do we know that this title definitely exists, or should we otherwise
3106 - * consider that it exists?
 3110+ * Should links to this title be shown as potentially viewable (i.e. as
 3111+ * "bluelinks"), even if there's no record by this title in the page
 3112+ * table?
31073113 *
 3114+ * This function is semi-deprecated for public use, as well as somewhat
 3115+ * misleadingly named. You probably just want to call isKnown(), which
 3116+ * calls this function internally.
 3117+ *
31083118 * @return \type{\bool} TRUE or FALSE
31093119 */
31103120 public function isAlwaysKnown() {
3111 - // If the page is form Mediawiki:message/lang, calling wfMsgWeirdKey causes
3112 - // the full l10n of that language to be loaded. That takes much memory and
3113 - // isn't needed. So we strip the language part away.
3114 - // Also, extension messages which are not loaded, are shown as red, because
3115 - // we don't call MessageCache::loadAllMessages.
3116 - list( $basename, /* rest */ ) = explode( '/', $this->mDbkeyform, 2 );
3117 - return $this->isExternal()
3118 - || ( $this->mNamespace == NS_MAIN && $this->mDbkeyform == '' )
3119 - || ( $this->mNamespace == NS_MEDIAWIKI && wfMsgWeirdKey( $basename ) );
 3121+ if( $this->mInterwiki != '' ) {
 3122+ return true; // any interwiki link might be viewable, for all we know
 3123+ }
 3124+ switch( $this->mNamespace ) {
 3125+ case NS_MEDIA:
 3126+ case NS_FILE:
 3127+ return wfFindFile( $this ); // file exists, possibly in a foreign repo
 3128+ case NS_SPECIAL:
 3129+ return SpecialPage::exists( $this->getDBKey() ); // valid special page
 3130+ case NS_MAIN:
 3131+ return $this->mDbkeyform == ''; // selflink, possibly with fragment
 3132+ case NS_MEDIAWIKI:
 3133+ // If the page is form Mediawiki:message/lang, calling wfMsgWeirdKey causes
 3134+ // the full l10n of that language to be loaded. That takes much memory and
 3135+ // isn't needed. So we strip the language part away.
 3136+ // Also, extension messages which are not loaded, are shown as red, because
 3137+ // we don't call MessageCache::loadAllMessages.
 3138+ list( $basename, /* rest */ ) = explode( '/', $this->mDbkeyform, 2 );
 3139+ return wfMsgWeirdKey( $basename ); // known system message
 3140+ default:
 3141+ return false;
 3142+ }
31203143 }
31213144
31223145 /**
 3146+ * Does this title refer to a page that can (or might) be meaningfully
 3147+ * viewed? In particular, this function may be used to determine if
 3148+ * links to the title should be rendered as "bluelinks" (as opposed to
 3149+ * "redlinks" to non-existent pages).
 3150+ *
 3151+ * @return \type{\bool} TRUE or FALSE
 3152+ */
 3153+ public function isKnown() {
 3154+ return $this->exists() || $this->isAlwaysKnown();
 3155+ }
 3156+
 3157+ /**
31233158 * Update page_touched timestamps and send squid purge messages for
31243159 * pages linking to this title. May be sent to the job queue depending
31253160 * on the number of links. Typically called on create and delete.
Index: trunk/phase3/RELEASE-NOTES
@@ -399,6 +399,8 @@
400400 new pages in the recent changes IRC feed
401401 * Ugly tooltips in Special:Statistics were phased out in favor of more direct
402402 information. Went ahead and rewrote SpecialStatistics to subclass SpecialPage
 403+* (bug 5506) Links to files on foreign repositories are now shown consistently
 404+ as bluelinks e.g. in logs and edit summaries
403405
404406 === API changes in 1.14 ===
405407

Follow-up revisions

RevisionCommit summaryAuthorDate
r44524followup to r44520: simplify various bits by removing checks now made redundantvyznev04:14, 13 December 2008

Status & tagging log