Brian Wolff has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/68936


Change subject: (Optionally) Use {{DISPLAYTITLE:...}} whenever linking to a page
......................................................................

(Optionally) Use {{DISPLAYTITLE:...}} whenever linking to a page

Note: This is disabled by default via $wgAlwaysUseDisplayTitle

This makes displaytitle be used on Category pages, and pretty much
anywhere that Linker::link is used, without specifying the text
of the link. Note, this does not include [[Foo]] links being
made by the Parser. This does include links on RC (which some might
consider a bad thing. On the other hand iPad would be spelled right
in RC. The bad would come when people use make title invisible hacks).

The restrictions on normal DISPLAYTITLE are also used here.

This adds some extra db queries (quite a few). If anyone actually decides
they want this on a Wikimedia wiki, I could add code to make sure
those queries are batched.

Bug: 17212
Change-Id: Ic1f61879cf5848f4ec6e61f0b80c24019d0e8a13
---
M RELEASE-NOTES-1.22
M includes/DefaultSettings.php
M includes/Linker.php
M includes/Title.php
4 files changed, 55 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/36/68936/1

diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22
index 1b434d9..2d28548 100644
--- a/RELEASE-NOTES-1.22
+++ b/RELEASE-NOTES-1.22
@@ -111,6 +111,8 @@
 ** editmyuserjs controls whether a user may edit their own JS subpages.
 * Add new hook AbortTalkPageEmailNotification, this will be used to determine
   whether to send the regular talk page email notification
+* (bug 17212) Add $wgAlwaysUseDisplayTitle so that the displaytitle is used on
+  category listing, recent changes, etc.
 
 === Bug fixes in 1.22 ===
 * Disable Special:PasswordReset when $wgEnableEmail is false. Previously one
diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index b560baf..0b6129f 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -3521,6 +3521,15 @@
 $wgRestrictDisplayTitle = true;
 
 /**
+ * Use DISPLAYTITLE outside of the current page.
+ * For example, Category listings. Most places that link to a page using the
+ * full page name.
+ *
+ * May increase the number of DB queries.
+ */
+$wgAlwaysUseDisplayTitle = false;
+
+/**
  * Maximum number of calls per parse to expensive parser functions such as
  * PAGESINCATEGORY.
  */
diff --git a/includes/Linker.php b/includes/Linker.php
index 3529d28..2a89501 100644
--- a/includes/Linker.php
+++ b/includes/Linker.php
@@ -168,7 +168,8 @@
         * @param $html          string The HTML contents of the <a> element, 
i.e.,
         *   the link text.  This is raw HTML and will not be escaped.  If null,
         *   defaults to the prefixed text of the Title; or if the Title is 
just a
-        *   fragment, the contents of the fragment.
+        *   fragment, the contents of the fragment. If 
$wgAlwaysUseDisplayTitle is
+        *   set to true, the default will be the pages {{DEFAULTTITLE:..}} if 
set.
         * @param array $customAttribs  A key => value array of extra HTML 
attributes,
         *   such as title and class.  (href is ignored.)  Classes will be
         *   merged with the default classes, while other attributes will 
replace
@@ -380,6 +381,7 @@
         * @return string
         */
        private static function linkText( $target ) {
+               global $wgAlwaysUseDisplayTitle;
                // We might be passed a non-Title by make*LinkObj().  Fail 
gracefully.
                if ( !$target instanceof Title ) {
                        return '';
@@ -390,7 +392,12 @@
                if ( $target->getPrefixedText() === '' && 
$target->getFragment() !== '' ) {
                        return htmlspecialchars( $target->getFragment() );
                }
-               return htmlspecialchars( $target->getPrefixedText() );
+               if ( $wgAlwaysUseDisplayTitle ) {
+                       // Note, this returns html, that we want to output 
without escaping.
+                       return $target->getDisplayTitle();
+               } else {
+                       return htmlspecialchars( $target->getPrefixedText() );
+               }
        }
 
        /**
diff --git a/includes/Title.php b/includes/Title.php
index 9d42b2f..ffddb17 100644
--- a/includes/Title.php
+++ b/includes/Title.php
@@ -86,6 +86,7 @@
        var $mRedirect = null;            // /< Is the article at this title a 
redirect?
        var $mNotificationTimestamp = array(); // /< Associative array of user 
ID -> timestamp/false
        var $mHasSubpage;                 // /< Whether a page has any subpages
+       var $mDisplayTitle = null;        // /< HTML for the page's 
{{DISPLAYTITLE:...}}
        // @}
 
        /**
@@ -4785,4 +4786,38 @@
                }
                return $notices;
        }
+
+       /**
+        * Returns the display title if it exists, or $this->getPrefixedText().
+        *
+        * @note may return HTML. The result should be safe
+        *
+        * @return String display title, or $this->getPrefixedText() escaped.
+        */
+       public function getDisplayTitle() {
+               if ( is_null( $this->mDisplayTitle ) ) {
+                       $id = $this->getArticleId();
+                       if ( $id === 0 ) {
+                               // Not an existing page.
+                               $this->mDisplayTitle = false;
+                       } else {
+                               $dbr = wfGetDB( DB_SLAVE );
+                               $this->mDisplayTitle = $dbr->selectField(
+                                       'page_props',
+                                       'pp_value',
+                                       array(
+                                               'pp_page' => 
$this->getArticleId(),
+                                               'pp_propname' => 'displaytitle'
+                                       ),
+                                       __METHOD__
+                               );
+                       }
+               }
+               if ( $this->mDisplayTitle === false ) {
+                       // Since this is the "default" display title in a sense.
+                       return htmlspecialchars( $this->getPrefixedText() );
+               } else {
+                       return $this->mDisplayTitle;
+               }
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/68936
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic1f61879cf5848f4ec6e61f0b80c24019d0e8a13
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Brian Wolff <[email protected]>

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

Reply via email to