Fix Status::getMessage accidentially returning string instead of Message
[lhc/web/wiklou.git] / includes / Title.php
index 79853df..a705aaa 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Representation a title within %MediaWiki.
+ * Representation of a title within %MediaWiki.
  *
  * See title.txt
  *
@@ -706,6 +706,8 @@ class Title {
        /**
         * Get the interwiki prefix
         *
+        * Use Title::isExternal to check if a interwiki is set
+        *
         * @return String Interwiki prefix
         */
        public function getInterwiki() {
@@ -1194,6 +1196,8 @@ class Title {
        /**
         * Get the Title fragment (i.e.\ the bit after the #) in text form
         *
+        * Use Title::hasFragment to check for a fragment
+        *
         * @return String Title fragment
         */
        public function getFragment() {
@@ -1496,9 +1500,7 @@ class Title {
         * Get a real URL referring to this title, with interwiki link and
         * fragment
         *
-        * See getLocalURL for the arguments.
-        *
-        * @see self::getLocalURL
+        * @see self::getLocalURL for the arguments.
         * @see wfExpandUrl
         * @param $query
         * @param $query2 bool
@@ -1524,8 +1526,12 @@ class Title {
        }
 
        /**
-        * Get a URL with no fragment or server name.  If this page is generated
-        * with action=render, $wgServer is prepended.
+        * Get a URL with no fragment or server name (relative URL) from a Title object.
+        * If this page is generated with action=render, however,
+        * $wgServer is prepended to make an absolute URL.
+        *
+        * @see self::getFullURL to always get an absolute URL.
+        * @see self::newFromText to produce a Title object.
         *
         * @param string|array $query an optional query string,
         *   not used for interwiki links. Can be specified as an associative array as well,
@@ -1538,7 +1544,7 @@ class Title {
         *   The second parameter is deprecated since 1.19. Pass it as a key,value
         *   pair in the first parameter array instead.
         *
-        * @return String the URL
+        * @return String of the URL.
         */
        public function getLocalURL( $query = '', $query2 = false ) {
                global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
@@ -1626,19 +1632,17 @@ class Title {
         * The result obviously should not be URL-escaped, but does need to be
         * HTML-escaped if it's being output in HTML.
         *
-        * See getLocalURL for the arguments.
-        *
         * @param $query
         * @param $query2 bool
         * @param $proto Protocol to use; setting this will cause a full URL to be used
-        * @see self::getLocalURL
+        * @see self::getLocalURL for the arguments.
         * @return String the URL
         */
        public function getLinkURL( $query = '', $query2 = false, $proto = PROTO_RELATIVE ) {
                wfProfileIn( __METHOD__ );
                if ( $this->isExternal() || $proto !== PROTO_RELATIVE ) {
                        $ret = $this->getFullURL( $query, $query2, $proto );
-               } elseif ( $this->getPrefixedText() === '' && $this->getFragment() !== '' ) {
+               } elseif ( $this->getPrefixedText() === '' && $this->hasFragment() ) {
                        $ret = $this->getFragmentForURL();
                } else {
                        $ret = $this->getLocalURL( $query, $query2 ) . $this->getFragmentForURL();
@@ -1651,9 +1655,7 @@ class Title {
         * Get an HTML-escaped version of the URL form, suitable for
         * using in a link, without a server name or fragment
         *
-        * See getLocalURL for the arguments.
-        *
-        * @see self::getLocalURL
+        * @see self::getLocalURL for the arguments.
         * @param $query string
         * @param $query2 bool|string
         * @return String the URL
@@ -1668,9 +1670,7 @@ class Title {
         * Get an HTML-escaped version of the URL form, suitable for
         * using in a link, including the server name and fragment
         *
-        * See getLocalURL for the arguments.
-        *
-        * @see self::getLocalURL
+        * @see self::getLocalURL for the arguments.
         * @return String the URL
         * @deprecated since 1.19
         */
@@ -1688,9 +1688,7 @@ class Title {
         * if $wgInternalServer is not set. If the server variable used is
         * protocol-relative, the URL will be expanded to http://
         *
-        * See getLocalURL for the arguments.
-        *
-        * @see self::getLocalURL
+        * @see self::getLocalURL for the arguments.
         * @return String the URL
         */
        public function getInternalURL( $query = '', $query2 = false ) {
@@ -1709,9 +1707,7 @@ class Title {
         *
         * NOTE: Unlike getInternalURL(), the canonical URL includes the fragment
         *
-        * See getLocalURL for the arguments.
-        *
-        * @see self::getLocalURL
+        * @see self::getLocalURL for the arguments.
         * @return string The URL
         * @since 1.18
         */
@@ -1725,9 +1721,7 @@ class Title {
        /**
         * HTML-escaped version of getCanonicalURL()
         *
-        * See getLocalURL for the arguments.
-        *
-        * @see self::getLocalURL
+        * @see self::getLocalURL for the arguments.
         * @since 1.18
         * @return string
         * @deprecated since 1.19
@@ -1776,7 +1770,6 @@ class Title {
         *
         * @deprecated in 1.19; use userCan(), quickUserCan() or getUserPermissionsErrors() instead
         * @return Bool
-        * @todo fold these checks into userCan()
         */
        public function userCanRead() {
                wfDeprecated( __METHOD__, '1.19' );
@@ -3210,7 +3203,8 @@ class Title {
                global $wgContLang, $wgLocalInterwiki;
 
                # Initialisation
-               $this->mInterwiki = $this->mFragment = '';
+               $this->mInterwiki = '';
+               $this->mFragment = '';
                $this->mNamespace = $this->mDefaultNamespace; # Usually NS_MAIN
 
                $dbkey = $this->mDbkeyform;
@@ -3305,10 +3299,6 @@ class Title {
                        break;
                } while ( true );
 
-               # We already know that some pages won't be in the database!
-               if ( $this->isExternal() || NS_SPECIAL == $this->mNamespace ) {
-                       $this->mArticleID = 0;
-               }
                $fragment = strstr( $dbkey, '#' );
                if ( false !== $fragment ) {
                        $this->setFragment( $fragment );
@@ -3378,9 +3368,9 @@ class Title {
                // there are numerous ways to present the same IP. Having sp:contribs scan
                // them all is silly and having some show the edits and others not is
                // inconsistent. Same for talk/userpages. Keep them normalized instead.
-               $dbkey = ( $this->mNamespace == NS_USER || $this->mNamespace == NS_USER_TALK )
-                       ? IP::sanitizeIP( $dbkey )
-                       : $dbkey;
+               if ( $this->mNamespace == NS_USER || $this->mNamespace == NS_USER_TALK ) {
+                       $dbkey = IP::sanitizeIP( $dbkey );
+               }
 
                // Any remaining initial :s are illegal.
                if ( $dbkey !== '' && ':' == $dbkey[0] ) {
@@ -3393,6 +3383,11 @@ class Title {
 
                $this->mTextform = str_replace( '_', ' ', $dbkey );
 
+               # We already know that some pages won't be in the database!
+               if ( $this->isExternal() || $this->mNamespace == NS_SPECIAL ) {
+                       $this->mArticleID = 0;
+               }
+
                return true;
        }
 
@@ -3871,7 +3866,20 @@ class Title {
                                $comment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $reason;
                        }
                        // @todo FIXME: $params?
-                       $log->addEntry( 'move_prot', $nt, $comment, array( $this->getPrefixedText() ), $wgUser );
+                       $logId = $log->addEntry( 'move_prot', $nt, $comment, array( $this->getPrefixedText() ), $wgUser );
+
+                       // reread inserted pr_ids for log relation
+                       $insertedPrIds = $dbw->select(
+                               'page_restrictions',
+                               'pr_id',
+                               array( 'pr_page' => $redirid ),
+                               __METHOD__
+                       );
+                       $logRelationsValues = array();
+                       foreach ( $insertedPrIds as $prid ) {
+                               $logRelationsValues[] = $prid->pr_id;
+                       }
+                       $log->addRelations( 'pr_id', $logRelationsValues, $logId );
                }
 
                # Update watchlists
@@ -3886,7 +3894,7 @@ class Title {
 
                $dbw->commit( __METHOD__ );
 
-               wfRunHooks( 'TitleMoveComplete', array( &$this, &$nt, &$wgUser, $pageid, $redirid ) );
+               wfRunHooks( 'TitleMoveComplete', array( &$this, &$nt, &$wgUser, $pageid, $redirid, $reason ) );
                return true;
        }
 
@@ -4057,7 +4065,7 @@ class Title {
                foreach ( $subpages as $oldSubpage ) {
                        $count++;
                        if ( $count > $wgMaximumMovedPages ) {
-                               $retval[$oldSubpage->getPrefixedTitle()] =
+                               $retval[$oldSubpage->getPrefixedText()] =
                                                array( 'movepage-max-pages',
                                                        $wgMaximumMovedPages );
                                break;
@@ -4425,9 +4433,11 @@ class Title {
        }
 
        /**
-        * Get the number of authors between the given revisions or revision IDs.
+        * Get the authors between the given revisions or revision IDs.
         * Used for diffs and other things that really need it.
         *
+        * @since 1.23
+        *
         * @param int|Revision $old Old revision or rev ID (first before range by default)
         * @param int|Revision $new New revision or rev ID (first after range by default)
         * @param int $limit Maximum number of authors
@@ -4436,9 +4446,9 @@ class Title {
         *     'include_new' Include $new in the range; $old is excluded.
         *     'include_both' Include both $old and $new in the range.
         *     Unknown option values are ignored.
-        * @return int Number of revision authors in the range; zero if not both revisions exist
+        * @return array|null Names of revision authors in the range; null if not both revisions exist
         */
-       public function countAuthorsBetween( $old, $new, $limit, $options = array() ) {
+       public function getAuthorsBetween( $old, $new, $limit, $options = array() ) {
                if ( !( $old instanceof Revision ) ) {
                        $old = Revision::newFromTitle( $this, (int)$old );
                }
@@ -4449,8 +4459,9 @@ class Title {
                // Add $old->getPage() != $new->getPage() || $old->getPage() != $this->getArticleID()
                // in the sanity check below?
                if ( !$old || !$new ) {
-                       return 0; // nothing to compare
+                       return null; // nothing to compare
                }
+               $authors = array();
                $old_cmp = '>';
                $new_cmp = '<';
                $options = (array)$options;
@@ -4466,12 +4477,19 @@ class Title {
                }
                // No DB query needed if $old and $new are the same or successive revisions:
                if ( $old->getId() === $new->getId() ) {
-                       return ( $old_cmp === '>' && $new_cmp === '<' ) ? 0 : 1;
+                       return ( $old_cmp === '>' && $new_cmp === '<' ) ? array() : array( $old->getRawUserText() );
                } elseif ( $old->getId() === $new->getParentId() ) {
-                       if ( $old_cmp === '>' || $new_cmp === '<' ) {
-                               return ( $old_cmp === '>' && $new_cmp === '<' ) ? 0 : 1;
+                       if ( $old_cmp === '>=' && $new_cmp === '<=' ) {
+                               $authors[] = $old->getRawUserText();
+                               if ( $old->getRawUserText() != $new->getRawUserText() ) {
+                                       $authors[] = $new->getRawUserText();
+                               }
+                       } elseif ( $old_cmp === '>=' ) {
+                               $authors[] = $old->getRawUserText();
+                       } elseif ( $new_cmp === '<=' ) {
+                               $authors[] = $new->getRawUserText();
                        }
-                       return ( $old->getRawUserText() === $new->getRawUserText() ) ? 1 : 2;
+                       return $authors;
                }
                $dbr = wfGetDB( DB_SLAVE );
                $res = $dbr->select( 'revision', 'DISTINCT rev_user_text',
@@ -4482,7 +4500,29 @@ class Title {
                        ), __METHOD__,
                        array( 'LIMIT' => $limit + 1 ) // add one so caller knows it was truncated
                );
-               return (int)$dbr->numRows( $res );
+               foreach ( $res as $row ) {
+                       $authors[] = $row->rev_user_text;
+               }
+               return $authors;
+       }
+
+       /**
+        * Get the number of authors between the given revisions or revision IDs.
+        * Used for diffs and other things that really need it.
+        *
+        * @param int|Revision $old Old revision or rev ID (first before range by default)
+        * @param int|Revision $new New revision or rev ID (first after range by default)
+        * @param int $limit Maximum number of authors
+        * @param string|array $options (Optional): Single option, or an array of options:
+        *     'include_old' Include $old in the range; $new is excluded.
+        *     'include_new' Include $new in the range; $old is excluded.
+        *     'include_both' Include both $old and $new in the range.
+        *     Unknown option values are ignored.
+        * @return int Number of revision authors in the range; zero if not both revisions exist
+        */
+       public function countAuthorsBetween( $old, $new, $limit, $options = array() ) {
+               $authors = $this->getAuthorsBetween( $old, $new, $limit, $options );
+               return $authors ? count( $authors ) : 0;
        }
 
        /**