Tweaks for SiteConfiguration:
[lhc/web/wiklou.git] / includes / Title.php
index 349bce7..0713344 100644 (file)
@@ -10,12 +10,6 @@ if ( !class_exists( 'UtfNormal' ) ) {
 
 define ( 'GAID_FOR_UPDATE', 1 );
 
-/**
- * Title::newFromText maintains a cache to avoid expensive re-normalization of
- * commonly used titles. On a batch operation this can become a memory leak
- * if not bounded. After hitting this many titles reset the cache.
- */
-define( 'MW_TITLECACHE_MAX', 1000 );
 
 /**
  * Constants for pr_cascade bitfield
@@ -35,6 +29,14 @@ class Title {
        static private $interwikiCache=array();
        //@}
 
+       /**
+        * Title::newFromText maintains a cache to avoid expensive re-normalization of
+        * commonly used titles. On a batch operation this can become a memory leak
+        * if not bounded. After hitting this many titles reset the cache.
+        */
+       const CACHE_MAX = 1000;
+
+
        /**
         * @name Private member variables
         * Please use the accessor functions instead.
@@ -131,7 +133,7 @@ class Title {
                static $cachedcount = 0 ;
                if( $t->secureAndSplit() ) {
                        if( $defaultNamespace == NS_MAIN ) {
-                               if( $cachedcount >= MW_TITLECACHE_MAX ) {
+                               if( $cachedcount >= self::CACHE_MAX ) {
                                        # Avoid memory leaks on mass operations...
                                        Title::$titleCache = array();
                                        $cachedcount=0;
@@ -196,8 +198,8 @@ class Title {
 
        /**
         * Make an array of titles from an array of IDs
-        * @param $ids \arrayof{\int} Array of IDs
-        * @return \arrayof{Title} Array of Titles
+        * @param $ids \type{\arrayof{\int}} Array of IDs
+        * @return \type{\arrayof{Title}} Array of Titles
         */
        public static function newFromIDs( $ids ) {
                if ( !count( $ids ) ) {
@@ -408,6 +410,12 @@ class Title {
                global $wgInterwikiCache, $wgContLang;
                $fname = 'Title::getInterwikiLink';
 
+               if ( count( Title::$interwikiCache ) >= self::CACHE_MAX ) {
+                       // Don't use infinite memory
+                       reset( Title::$interwikiCache );
+                       unset( Title::$interwikiCache[ key( Title::$interwikiCache ) ] );
+               }
+
                $key = $wgContLang->lc( $key );
 
                $k = wfMemcKey( 'interwiki', $key );
@@ -877,7 +885,7 @@ class Title {
         * there's a fragment but the prefixed text is empty, we just return a link
         * to the fragment.
         *
-        * @param $query \arrayof{\string} An associative array of key => value pairs for the
+        * @param $query \type{\arrayof{\string}} An associative array of key => value pairs for the
         *   query string.  Keys and values will be escaped.
         * @param $variant \type{\string} Language variant of URL (for sr, zh..).  Ignored
         *   for external links.  Default is "false" (same variant as current page,
@@ -1069,7 +1077,7 @@ class Title {
 
        /**
         * Can $wgUser perform $action on this page?
-        * @param \type{\string} $action action that permission needs to be checked for
+        * @param $action \type{\string} action that permission needs to be checked for
         * @param $doExpensiveQueries \type{\bool} Set this to false to avoid doing unnecessary queries.
         * @return \type{\bool}
         */
@@ -1086,7 +1094,7 @@ class Title {
         * @param $action \type{\string}action that permission needs to be checked for
         * @param $user \type{User} user to check
         * @param $doExpensiveQueries \type{\bool} Set this to false to avoid doing unnecessary queries.
-        * @param $ignoreErrors \arrayof{\string} Set this to a list of message keys whose corresponding errors may be ignored.
+        * @param $ignoreErrors \type{\arrayof{\string}} Set this to a list of message keys whose corresponding errors may be ignored.
         * @return \type{\array} Array of arrays of the arguments to wfMsg to explain permissions problems.
         */
        public function getUserPermissionsErrors( $action, $user, $doExpensiveQueries = true, $ignoreErrors = array() ) {
@@ -1648,7 +1656,7 @@ class Title {
         * Cascading protection: Get the source of any cascading restrictions on this page.
         *
         * @param $get_pages \type{\bool} Whether or not to retrieve the actual pages that the restrictions have come from.
-        * @return \arrayof{mixed title array, restriction array} Array of the Title objects of the pages from 
+        * @return \type{\arrayof{mixed title array, restriction array}} Array of the Title objects of the pages from 
         *         which cascading restrictions have come, false for none, or true if such restrictions exist, but $get_pages was not set.
         *         The restriction array is an array of each type, each of which contains an array of unique groups.
         */
@@ -1873,7 +1881,7 @@ class Title {
         * Accessor/initialisation for mRestrictions
         *
         * @param $action \type{\string} action that permission needs to be checked for
-        * @return \arrayof{\string} the array of groups allowed to edit this article
+        * @return \type{\arrayof{\string}} the array of groups allowed to edit this article
         */
        public function getRestrictions( $action ) {
                if( !$this->mRestrictionsLoaded ) {
@@ -2301,7 +2309,7 @@ class Title {
         * On heavily-used templates it will max out the memory.
         *
         * @param $options \type{\string} may be FOR UPDATE
-        * @return \arrayof{Title} the Title objects linking here
+        * @return \type{\arrayof{Title}} the Title objects linking here
         */
        public function getLinksTo( $options = '', $table = 'pagelinks', $prefix = 'pl' ) {
                $linkCache = LinkCache::singleton();
@@ -2342,7 +2350,7 @@ class Title {
         * On heavily-used templates it will max out the memory.
         *
         * @param $options \type{\string} may be FOR UPDATE
-        * @return \arrayof{Title} the Title objects linking here
+        * @return \type{\arrayof{Title}} the Title objects linking here
         */
        public function getTemplateLinksTo( $options = '' ) {
                return $this->getLinksTo( $options, 'templatelinks', 'tl' );
@@ -2353,7 +2361,7 @@ class Title {
         *
         * @todo check if needed (used only in SpecialBrokenRedirects.php, and should use redirect table in this case)
         * @param $options \type{\string} may be FOR UPDATE
-        * @return \arrayof{Title} the Title objects
+        * @return \type{\arrayof{Title}} the Title objects
         */
        public function getBrokenLinksFrom( $options = '' ) {
                if ( $this->getArticleId() == 0 ) {
@@ -2396,7 +2404,7 @@ class Title {
         * Get a list of URLs to purge from the Squid cache when this
         * page changes
         *
-        * @return \arrayof{\string} the URLs
+        * @return \type{\arrayof{\string}} the URLs
         */
        public function getSquidURLs() {
                global $wgContLang;
@@ -2498,6 +2506,12 @@ class Title {
                                        $nt->getUserPermissionsErrors('edit', $wgUser));
                }
 
+               $match = EditPage::matchSpamRegex( $reason );
+               if( $match !== false ) {
+                       // This is kind of lame, won't display nice
+                       $errors[] = array('spamprotectiontext');
+               }
+               
                global $wgUser;
                $err = null;
                if( !wfRunHooks( 'AbortMove', array( $this, $nt, $wgUser, &$err, $reason ) ) ) {
@@ -2756,7 +2770,9 @@ class Title {
                $fname = 'MovePageForm::moveToNewTitle';
                $comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
                if ( $reason ) {
-                       $comment .= ": $reason";
+                       $comment .= wfMsgExt( 'colon-separator',
+                               array( 'escapenoentities', 'content' ) );
+                       $comment .= $reason;
                }
 
                $newid = $nt->getArticleID();
@@ -3117,11 +3133,12 @@ class Title {
 
        /**
         * Get the last touched timestamp
+        * @param Database $db, optional db
         * @return \type{\string} Last touched timestamp
         */
-       public function getTouched() {
-               $dbr = wfGetDB( DB_SLAVE );
-               $touched = $dbr->selectField( 'page', 'page_touched',
+       public function getTouched( $db = NULL ) {
+               $db = isset($db) ? $db : wfGetDB( DB_SLAVE );
+               $touched = $db->selectField( 'page', 'page_touched',
                        array(
                                'page_namespace' => $this->getNamespace(),
                                'page_title' => $this->getDBkey()
@@ -3255,7 +3272,7 @@ class Title {
         *
         * @param $ns \twotypes{\int,\null} Single namespace to consider; 
         *            NULL to consider all namespaces
-        * @return \arrayof{Title} Redirects to this title
+        * @return \type{\arrayof{Title}} Redirects to this title
         */
        public function getRedirectsHere( $ns = null ) {
                $redirs = array();