Cicalese has uploaded a new change for review.

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

Change subject: added page_props access class; set link text from displaytitle 
page property
......................................................................

added page_props access class; set link text from displaytitle page property

Change-Id: I96186d4156e7106ec6fe8bd09ba8dcbf8658d5e4
---
M includes/Linker.php
A includes/PageProps.php
M includes/actions/InfoAction.php
3 files changed, 190 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/46/246246/1

diff --git a/includes/Linker.php b/includes/Linker.php
index 2e33bd1..554a040 100644
--- a/includes/Linker.php
+++ b/includes/Linker.php
@@ -150,6 +150,40 @@
        }
 
        /**
+        * If custom link text has not be provided and displaytitle page 
property
+        * is set, use display title for link text.
+        *
+        * @param Title $target
+        * @param &$text
+        */
+       private static function getDisplayTitleLinkText( Title $target, &$text 
) {
+
+               if ( isset( $text ) ) {
+                       if ( is_string( $text ) ) {
+                               $title = Title::newFromText( $text );
+                               if ( is_null( $title ) ||
+                                       $title->getText() != $target->getText() 
) {
+                                       return;
+                               }
+                               if ( $title->getSubjectNsText() == 
$target->getSubjectNsText()
+                                       || $title->getSubjectNsText() == '' ) {
+                                       $props = new PageProps( 
$target->getArticleID() );
+                                       $value = $props->getProperty( 
'displaytitle' );
+                                       if ( $value !== false ) {
+                                               $text = $value;
+                                       }
+                               }
+                       }
+               } else {
+                       $props = new PageProps( $target->getArticleID() );
+                       $value = $props->getProperty( 'displaytitle' );
+                       if ( $value !== false ) {
+                               $text = $value;
+                       }
+               }
+       }
+
+       /**
         * This function returns an HTML link to the given target.  It serves a 
few
         * purposes:
         *   1) If $target is a Title, the correct URL to link to will be 
figured
@@ -213,6 +247,9 @@
                ) {
                        return $ret;
                }
+
+               # If displaytitle page property is set, use if for link text
+               self::getDisplayTitleLinkText( $target, $html );
 
                # Normalize the Title if it's a special page
                $target = self::normaliseSpecialPage( $target );
@@ -404,6 +441,14 @@
                        return $ret;
                }
 
+               if ( $html == '' || $html == $nt->getPrefixedText() ) {
+                       $props = new PageProps( $nt->getArticleID() );
+                       $value = $props->getProperty( 'displaytitle' );
+                       if ( $value !== false ) {
+                               $html = $value;
+                       }
+               }
+
                if ( $html == '' ) {
                        $html = htmlspecialchars( $nt->getPrefixedText() );
                }
diff --git a/includes/PageProps.php b/includes/PageProps.php
new file mode 100644
index 0000000..bdfbde0
--- /dev/null
+++ b/includes/PageProps.php
@@ -0,0 +1,143 @@
+<?php
+/**
+ * Access to properties of a page.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * Gives access to properties of a page.
+ */
+class PageProps {
+
+       private $id;
+
+       /**
+        * Create a PageProps object
+        *
+        * @param $id
+        *
+       **/
+       public function __construct( $id ) {
+               $this->id = $id;
+       }
+
+       /**
+        * Get all page property values.
+        *
+        * @return property value array or false if not found
+        *
+        */
+       public function getProperties() {
+
+               $dbr = wfGetDB( DB_SLAVE );
+               $result = $dbr->select(
+                       'page_props',
+                       array(
+                               'pp_propname',
+                               'pp_value'
+                       ),
+                       array(
+                               'pp_page' => $this->id
+                       ),
+                       __METHOD__
+               );
+
+               $pageProperties = array();
+
+               foreach ( $result as $row ) {
+                       $pageProperties[$row->pp_propname] = $row->pp_value;
+               }
+
+               return $pageProperties;
+       }
+
+       /**
+        * Get page property value for a given property name.
+        *
+        * @param $propertyName
+        *
+        * @return property value or false if not found
+        *
+        */
+       public function getProperty( $propertyName ) {
+
+               $dbr = wfGetDB( DB_SLAVE );
+               $result = $dbr->select(
+                       'page_props',
+                       array( 'pp_value' ),
+                       array(
+                               'pp_page' => $this->id,
+                               'pp_propname' => $propertyName
+                       ),
+                       __METHOD__
+               );
+
+               if ( $result->numRows() > 0 ) {
+                       $row = $result->fetchRow();
+                       $value = $row['pp_value'];
+                       return $value;
+               }
+
+               return false;
+       }
+
+       /**
+        * Set page property value.
+        *
+        * @param $propertyName
+        * @param $propertyValue
+        *
+        */
+        public function setProperty( $propertyName, $propertyValue ) {
+
+               $old_value = $this->getProperty( $propertyName );
+
+               if ( $old_value === false ) {
+                       
+                       $dbw = wfGetDB( DB_MASTER );
+                       $result = $dbw->insert(
+                               'page_props',
+                               array(
+                                       'pp_page' => $this->id,
+                                       'pp_propname' => $propertyName,
+                                       'pp_value' => $propertyValue
+                               ),
+                               __METHOD__
+                       );
+
+               } else if ( $old_value !== $propertyValue ) {
+
+                       $dbw = wfGetDB( DB_MASTER );
+                       $result = $dbw->update(
+                               'page_props',
+                               array(
+                                       'pp_value' => $propertyValue
+                               ),
+                               array(
+                                       'pp_page' => $this->id,
+                                       'pp_propname' => $propertyName
+                               ),
+                               __METHOD__
+                       );
+
+               }
+
+       }
+
+}
diff --git a/includes/actions/InfoAction.php b/includes/actions/InfoAction.php
index 7389ae2..fe71c20 100644
--- a/includes/actions/InfoAction.php
+++ b/includes/actions/InfoAction.php
@@ -203,19 +203,9 @@
 
                $pageCounts = $this->pageCounts( $this->page );
 
-               // Get page properties
-               $dbr = wfGetDB( DB_SLAVE );
-               $result = $dbr->select(
-                       'page_props',
-                       array( 'pp_propname', 'pp_value' ),
-                       array( 'pp_page' => $id ),
-                       __METHOD__
-               );
-
                $pageProperties = array();
-               foreach ( $result as $row ) {
-                       $pageProperties[$row->pp_propname] = $row->pp_value;
-               }
+               $props = new PageProps( $title->getArticleID() );
+               $pageProperties = $props->getProperties();
 
                // Basic information
                $pageInfo = array();

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

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

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

Reply via email to