r87108 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87107‎ | r87108 | r87109 >
Date:00:40, 29 April 2011
Author:reedy
Status:deferred
Tags:
Comment:
Merge r70764
Modified paths:
  • /branches/iwtransclusion/phase3v2 (modified) (history)
  • /branches/iwtransclusion/phase3v2/includes/Article.php (modified) (history)
  • /branches/iwtransclusion/phase3v2/includes/EditPage.php (modified) (history)
  • /branches/iwtransclusion/phase3v2/includes/Linker.php (modified) (history)
  • /branches/iwtransclusion/phase3v2/includes/OutputPage.php (modified) (history)
  • /branches/iwtransclusion/phase3v2/includes/Title.php (modified) (history)
  • /branches/iwtransclusion/phase3v2/includes/db/Database.php (modified) (history)
  • /branches/iwtransclusion/phase3v2/includes/parser/Parser.php (modified) (history)
  • /branches/iwtransclusion/phase3v2/includes/parser/ParserOutput.php (modified) (history)
  • /branches/iwtransclusion/phase3v2/languages/messages/MessagesEn.php (modified) (history)
  • /branches/iwtransclusion/phase3v2/maintenance/archives/patch-globaltemplatelinks.sql (modified) (history)
  • /branches/iwtransclusion/phase3v2/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: branches/iwtransclusion/phase3v2/maintenance/archives/patch-globaltemplatelinks.sql
@@ -17,15 +17,19 @@
1818 -- Needed for display purposes
1919 gtl_from_title varchar(255) binary NOT NULL,
2020
21 - -- The wiki ID of the wiki that hosts the transcluded page
22 - gtl_to_wiki varchar(64) NOT NULL,
 21+ -- The interwiki prefix of the wiki that hosts the transcluded page
 22+ gtl_to_prefix varchar(32) NOT NULL,
2323
2424 -- The namespace of the transcluded page on that wiki
2525 gtl_to_namespace int NOT NULL,
2626
 27+ -- The namespace name of transcluded page
 28+ -- Needed for display purposes, since the local namespace ID doesn't necessarily match a distant one
 29+ gtl_to_namespacetext varchar(255) NOT NULL,
 30+
2731 -- The title of the transcluded page on that wiki
2832 gtl_to_title varchar(255) binary NOT NULL
2933 ) /*$wgDBTableOptions*/;
3034
31 -CREATE UNIQUE INDEX /*i*/gtl_to_from ON /*_*/globaltemplatelinks (gtl_to_wiki, gtl_to_namespace, gtl_to_title, gtl_from_wiki, gtl_from_page);
32 -CREATE UNIQUE INDEX /*i*/gtl_from_to ON /*_*/globaltemplatelinks (gtl_from_wiki, gtl_from_page, gtl_to_wiki, gtl_to_namespace, gtl_to_title);
 35+CREATE UNIQUE INDEX /*i*/gtl_to_from ON /*_*/globaltemplatelinks (gtl_to_prefix, gtl_to_namespace, gtl_to_title, gtl_from_wiki, gtl_from_page);
 36+CREATE UNIQUE INDEX /*i*/gtl_from_to ON /*_*/globaltemplatelinks (gtl_from_wiki, gtl_from_page, gtl_to_prefix, gtl_to_namespace, gtl_to_title);
Index: branches/iwtransclusion/phase3v2/maintenance/language/messages.inc
@@ -627,6 +627,9 @@
628628 'templatesused',
629629 'templatesusedpreview',
630630 'templatesusedsection',
 631+ 'distanttemplatesused',
 632+ 'distanttemplatesusedpreview',
 633+ 'distanttemplatesusedsection',
631634 'template-protected',
632635 'template-semiprotected',
633636 'hiddencategories',
Index: branches/iwtransclusion/phase3v2/includes/Article.php
@@ -3063,9 +3063,8 @@
30643064 * @param $commit boolean defaults to true, triggers transaction end
30653065 * @return boolean true if successful
30663066 */
3067 - public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
3068 - global $wgDeferredUpdateList, $wgUseTrackbacks;
3069 - global $wgUser;
 3067+ public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true ) {
 3068+ global $wgDeferredUpdateList, $wgUseTrackbacks, $wgEnableInterwikiTemplatesTracking, $wgGlobalDatabase;
30703069
30713070 wfDebug( __METHOD__ . "\n" );
30723071
@@ -3166,6 +3165,14 @@
31673166 $dbw->delete( 'langlinks', array( 'll_from' => $id ) );
31683167 $dbw->delete( 'iwlinks', array( 'iwl_from' => $id ) );
31693168 $dbw->delete( 'redirect', array( 'rd_from' => $id ) );
 3169+
 3170+ if ( $wgEnableInterwikiTemplatesTracking && $wgGlobalDatabase ) {
 3171+ $dbw2 = wfGetDB( DB_MASTER, array(), $wgGlobalDatabase );
 3172+ $dbw2->delete( 'globaltemplatelinks',
 3173+ array( 'gtl_from_wiki' => wfWikiID( ),
 3174+ 'gtl_from_page' => $id )
 3175+ );
 3176+ }
31703177 }
31713178
31723179 # If using cleanup triggers, we can skip some manual deletes
@@ -4149,6 +4156,42 @@
41504157 }
41514158
41524159 /**
 4160+ * Return a list of distant templates used by this article.
 4161+ * Uses the globaltemplatelinks table
 4162+ *
 4163+ * @return Array of Title objects
 4164+ */
 4165+ public function getUsedDistantTemplates() {
 4166+ global $wgGlobalDatabase;
 4167+
 4168+ $result = array();
 4169+
 4170+ if ( $wgGlobalDatabase ) {
 4171+ $id = $this->mTitle->getArticleID();
 4172+
 4173+ if ( $id == 0 ) {
 4174+ return array();
 4175+ }
 4176+
 4177+ $dbr = wfGetDB( DB_SLAVE, array(), $wgGlobalDatabase );
 4178+ $res = $dbr->select( array( 'globaltemplatelinks' ),
 4179+ array( 'gtl_to_prefix', 'gtl_to_namespace', 'gtl_to_title' ),
 4180+ array( 'gtl_from_wiki' => wfWikiID( ), 'gtl_from_page' => $id ),
 4181+ __METHOD__ );
 4182+
 4183+ if ( $res !== false ) {
 4184+ foreach ( $res as $row ) {
 4185+ $result[] = Title::makeTitle( $row->gtl_to_namespace, $row->gtl_to_title, null, $row->gtl_to_prefix );
 4186+ }
 4187+ }
 4188+
 4189+ $dbr->freeResult( $res );
 4190+ }
 4191+
 4192+ return $result;
 4193+ }
 4194+
 4195+ /**
41534196 * Returns a list of hidden categories this page is a member of.
41544197 * Uses the page_props and categorylinks tables.
41554198 *
Index: branches/iwtransclusion/phase3v2/includes/parser/Parser.php
@@ -3055,7 +3055,7 @@
30563056 * @private
30573057 */
30583058 function braceSubstitution( $piece, $frame ) {
3059 - global $wgContLang, $wgNonincludableNamespaces;
 3059+ global $wgContLang, $wgNonincludableNamespaces, $wgEnableInterwikiTranscluding, $wgEnableInterwikiTemplatesTracking;
30603060 wfProfileIn( __METHOD__ );
30613061 wfProfileIn( __METHOD__.'-setup' );
30623062
@@ -3269,11 +3269,15 @@
32703270 $text = "[[:$titleText]]";
32713271 $found = true;
32723272 }
3273 - } elseif ( $title->isTrans() ) {
 3273+ } elseif ( $wgEnableInterwikiTranscluding && $title->isTrans() ) {
32743274 // TODO: Work by Peter17 in progress
32753275
32763276 $text = Interwiki::interwikiTransclude( $title );
32773277
 3278+ if ( $wgEnableInterwikiTemplatesTracking ) {
 3279+ $this->registerDistantTemplate( $title );
 3280+ }
 3281+
32783282 if ( $text !== false ) {
32793283 # Preprocess it like a template
32803284 $text = $this->preprocessToDom( $text, self::PTD_FOR_INCLUSION );
@@ -3428,6 +3432,17 @@
34293433 * @param Title $title
34303434 * @return mixed string or false
34313435 */
 3436+ function registerDistantTemplate( $title ) {
 3437+ $stuff = Parser::distantTemplateCallback( $title, $this );
 3438+ $text = $stuff['text'];
 3439+ $finalTitle = isset( $stuff['finalTitle'] ) ? $stuff['finalTitle'] : $title;
 3440+ if ( isset( $stuff['deps'] ) ) {
 3441+ foreach ( $stuff['deps'] as $dep ) {
 3442+ $this->mOutput->addDistantTemplate( $dep['title'], $dep['page_id'], $dep['rev_id'] );
 3443+ }
 3444+ }
 3445+ }
 3446+
34323447 function fetchTemplate( $title ) {
34333448 $rv = $this->fetchTemplateAndTitle( $title );
34343449 return $rv[0];
Index: branches/iwtransclusion/phase3v2/includes/parser/ParserOutput.php
@@ -293,6 +293,31 @@
294294 $this->mTemplateIds[$ns][$dbk] = $rev_id; // For versioning
295295 }
296296
 297+ function addDistantTemplate( $title, $page_id, $rev_id ) {
 298+ $prefix = $title->getInterwiki();
 299+ if ( $prefix !=='' ) {
 300+ $ns = $title->getNamespace();
 301+ $dbk = $title->getDBkey();
 302+
 303+ if ( !isset( $this->mDistantTemplates[$prefix] ) ) {
 304+ $this->mDistantTemplates[$prefix] = array();
 305+ }
 306+ if ( !isset( $this->mDistantTemplates[$prefix][$ns] ) ) {
 307+ $this->mDistantTemplates[$prefix][$ns] = array();
 308+ }
 309+ $this->mDistantTemplates[$prefix][$ns][$dbk] = $page_id;
 310+
 311+ // For versioning
 312+ if ( !isset( $this->mDistantTemplateIds[$prefix] ) ) {
 313+ $this->mDistantTemplateIds[$prefix] = array();
 314+ }
 315+ if ( !isset( $this->mDistantTemplateIds[$prefix][$ns] ) ) {
 316+ $this->mDistantTemplateIds[$prefix][$ns] = array();
 317+ }
 318+ $this->mDistantTemplateIds[$prefix][$ns][$dbk] = $rev_id;
 319+ }
 320+ }
 321+
297322 /**
298323 * @param $title Title object, must be an interwiki link
299324 * @throws MWException if given invalid input
Index: branches/iwtransclusion/phase3v2/includes/Linker.php
@@ -1581,6 +1581,48 @@
15821582 }
15831583
15841584 /**
 1585+ * Returns HTML for the "templates used on this page" list.
 1586+ *
 1587+ * @param $templates Array of templates from Article::getUsedTemplate
 1588+ * or similar
 1589+ * @param $preview Boolean: whether this is for a preview
 1590+ * @param $section Boolean: whether this is for a section edit
 1591+ * @return String: HTML output
 1592+ */
 1593+ public function formatDistantTemplates( $templates, $preview = false, $section = false ) {
 1594+ wfProfileIn( __METHOD__ );
 1595+
 1596+ $outText = '';
 1597+ if ( count( $templates ) > 0 ) {
 1598+ # Do a batch existence check
 1599+ $batch = new LinkBatch;
 1600+ foreach( $templates as $title ) {
 1601+ $batch->addObj( $title );
 1602+ }
 1603+ $batch->execute();
 1604+
 1605+ # Construct the HTML
 1606+ $outText = '<div class="mw-templatesUsedExplanation">';
 1607+ if ( $preview ) {
 1608+ $outText .= wfMsgExt( 'distanttemplatesusedpreview', array( 'parse' ), count( $templates ) );
 1609+ } elseif ( $section ) {
 1610+ $outText .= wfMsgExt( 'distanttemplatesusedsection', array( 'parse' ), count( $templates ) );
 1611+ } else {
 1612+ $outText .= wfMsgExt( 'distanttemplatesused', array( 'parse' ), count( $templates ) );
 1613+ }
 1614+ $outText .= "</div><ul>\n";
 1615+
 1616+ usort( $templates, array( 'Title', 'compare' ) );
 1617+ foreach ( $templates as $titleObj ) {
 1618+ $outText .= '<li>' . $this->link( $titleObj ) . '</li>';
 1619+ }
 1620+ $outText .= '</ul>';
 1621+ }
 1622+ wfProfileOut( __METHOD__ );
 1623+ return $outText;
 1624+ }
 1625+
 1626+ /**
15851627 * Returns HTML for the "hidden categories on this page" list.
15861628 *
15871629 * @param $hiddencats Array of hidden categories from Article::getHiddenCategories
Index: branches/iwtransclusion/phase3v2/includes/db/Database.php
@@ -1456,6 +1456,31 @@
14571457 return false;
14581458 }
14591459 }
 1460+
 1461+ /**
 1462+ * Build a partial where clause from a 3-d array
 1463+ * The keys on each level may be either integers or strings.
 1464+ *
 1465+ * @param $data Array: organized as 3-d array(baseKeyVal => array(middleKeyVal => array(subKeyVal => <ignored>, ...), ...), ...)
 1466+ * @param $baseKey String: field name to match the base-level keys to (eg 'gtl_to_prefix')
 1467+ * @param $middleKey String: field name to match the middle-level keys to (eg 'gtl_to_namespace')
 1468+ * @param $subKey String: field name to match the sub-level keys to (eg 'gtl_to_title')
 1469+ * @return Mixed: string SQL fragment, or false if no items in array.
 1470+ */
 1471+ function makeWhereFrom3d( $data, $baseKey, $middleKey, $subKey ) {
 1472+ $conds = array();
 1473+ foreach ( $data as $base => $subdata ) {
 1474+ foreach ( $subdata as $middle => $sub ) {
 1475+ if ( count( $sub ) ) {
 1476+ $conds[] = $this->makeList(
 1477+ array( $baseKey => $base,
 1478+ $middleKey => $middle,
 1479+ $subKey => array_keys( $sub ) ),
 1480+ LIST_AND
 1481+ );
 1482+ }
 1483+ }
 1484+ }
14601485
14611486 /**
14621487 * Bitwise operations
Property changes on: branches/iwtransclusion/phase3v2/includes/db/Database.php
___________________________________________________________________
Modified: svn:mergeinfo
14631488 Merged /branches/iwtransclusion/phase3/includes/db/Database.php:r70764
Index: branches/iwtransclusion/phase3v2/includes/EditPage.php
@@ -1273,8 +1273,8 @@
12741274 * @param $formCallback Callback that takes an OutputPage parameter; will be called
12751275 * during form output near the top, for captchas and the like.
12761276 */
1277 - function showEditForm( $formCallback = null ) {
1278 - global $wgOut, $wgUser;
 1277+ function showEditForm( $formCallback=null ) {
 1278+ global $wgOut, $wgUser, $wgTitle, $wgEnableInterwikiTranscluding, $wgEnableInterwikiTemplatesTracking;
12791279
12801280 wfProfileIn( __METHOD__ );
12811281
@@ -1321,6 +1321,9 @@
13221322
13231323 $templates = $this->getTemplates();
13241324 $formattedtemplates = $sk->formatTemplates( $templates, $this->preview, $this->section != '');
 1325+
 1326+ $distantTemplates = $this->getDistantTemplates();
 1327+ $formattedDistantTemplates = $sk->formatDistantTemplates( $distantTemplates, $this->preview, $this->section != '' );
13251328
13261329 $hiddencats = $this->mArticle->getHiddenCategories();
13271330 $formattedhiddencats = $sk->formatHiddenCategories( $hiddencats );
@@ -1420,6 +1423,21 @@
14211424 <div class='templatesUsed'>
14221425 {$formattedtemplates}
14231426 </div>
 1427+HTML
 1428+);
 1429+
 1430+ if ( $wgEnableInterwikiTranscluding && $wgEnableInterwikiTemplatesTracking ) {
 1431+ $wgOut->addHTML( <<<HTML
 1432+{$this->editFormTextAfterTools}
 1433+<div class='distantTemplatesUsed'>
 1434+{$formattedDistantTemplates}
 1435+</div>
 1436+HTML
 1437+);
 1438+ }
 1439+
 1440+ $wgOut->addHTML( <<<HTML
 1441+{$this->editFormTextAfterTools}
14241442 <div class='hiddencats'>
14251443 {$formattedhiddencats}
14261444 </div>
@@ -2056,6 +2074,28 @@
20572075 return $this->mArticle->getUsedTemplates();
20582076 }
20592077 }
 2078+
 2079+ function getDistantTemplates() {
 2080+ global $wgEnableInterwikiTemplatesTracking;
 2081+ if ( !$wgEnableInterwikiTemplatesTracking ) {
 2082+ return array( );
 2083+ }
 2084+ if ( $this->preview || $this->section != '' ) {
 2085+ $templates = array();
 2086+ if ( !isset( $this->mParserOutput ) ) return $templates;
 2087+ $templatesList = $this->mParserOutput->getDistantTemplates();
 2088+ foreach( $templatesList as $prefix => $templatesbyns ) {
 2089+ foreach( $templatesbyns as $ns => $template ) {
 2090+ foreach( array_keys( $template ) as $dbk ) {
 2091+ $templates[] = Title::makeTitle( $ns, $dbk, null, $prefix );
 2092+ }
 2093+ }
 2094+ }
 2095+ return $templates;
 2096+ } else {
 2097+ return $this->mArticle->getUsedDistantTemplates();
 2098+ }
 2099+ }
20602100
20612101 /**
20622102 * Call the stock "user is blocked" page
Index: branches/iwtransclusion/phase3v2/includes/OutputPage.php
@@ -2098,6 +2098,9 @@
20992099 * @param $action String: action that was denied or null if unknown
21002100 */
21012101 public function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
 2102+ global $wgUser, $wgEnableInterwikiTranscluding, $wgEnableInterwikiTemplatesTracking;
 2103+ $skin = $wgUser->getSkin();
 2104+
21022105 $this->setRobotPolicy( 'noindex,nofollow' );
21032106 $this->setArticleRelated( false );
21042107
@@ -2143,6 +2146,12 @@
21442147 {$skin->formatTemplates( $article->getUsedTemplates() )}
21452148 </div>
21462149 " );
 2150+ if ( $wgEnableInterwikiTranscluding && $wgEnableInterwikiTemplatesTracking ) {
 2151+ $this->addHTML( "<div class='distantTemplatesUsed'>
 2152+{$skin->formatDistantTemplates( $article->getUsedDistantTemplates( ) )}
 2153+</div>
 2154+" );
 2155+ }
21472156 }
21482157
21492158 # If the title doesn't exist, it's fairly pointless to print a return
Property changes on: branches/iwtransclusion/phase3v2/includes/OutputPage.php
___________________________________________________________________
Modified: svn:mergeinfo
21502159 Merged /branches/iwtransclusion/phase3/includes/OutputPage.php:r70764
Index: branches/iwtransclusion/phase3v2/includes/Title.php
@@ -5,11 +5,16 @@
66 */
77
88 /**
9 - * @deprecated This used to be a define, but was moved to
10 - * Title::GAID_FOR_UPDATE in 1.17. This will probably be removed in 1.18
 9+ * @todo: determine if it is really necessary to load this. Appears to be left over from pre-autoloader versions, and
 10+ * is only really needed to provide access to constant UTF8_REPLACEMENT, which actually resides in UtfNormalDefines.php
 11+ * and is loaded by UtfNormalUtil.php, which is loaded by UtfNormal.php.
1112 */
12 -define( 'GAID_FOR_UPDATE', Title::GAID_FOR_UPDATE );
 13+if ( !class_exists( 'UtfNormal' ) ) {
 14+ require_once( dirname( __FILE__ ) . '/normal/UtfNormal.php' );
 15+}
1316
 17+define ( 'GAID_FOR_UPDATE', 1 );
 18+
1419 /**
1520 * Represents a title within MediaWiki.
1621 * Optionally may contain an interwiki designation or namespace.
@@ -31,13 +36,7 @@
3237 */
3338 const CACHE_MAX = 1000;
3439
35 - /**
36 - * Used to be GAID_FOR_UPDATE define. Used with getArticleID() and friends
37 - * to use the master DB
38 - */
39 - const GAID_FOR_UPDATE = 1;
4040
41 -
4241 /**
4342 * @name Private member variables
4443 * Please use the accessor functions instead.
@@ -63,11 +62,11 @@
6463 var $mCascadeSources; ///< Where are the cascading restrictions coming from on this page?
6564 var $mRestrictionsLoaded = false; ///< Boolean for initialisation on demand
6665 var $mPrefixedText; ///< Text form including namespace/interwiki, initialised on demand
67 - var $mTitleProtection; ///< Cached value for getTitleProtection (create protection)
 66+ var $mTitleProtection; ///< Cached value of getTitleProtection
6867 # Don't change the following default, NS_MAIN is hardcoded in several
6968 # places. See bug 696.
7069 var $mDefaultNamespace = NS_MAIN; // /< Namespace index when there is no namespace
71 - # Zero except in {{transclusion}} tags
 70+ # Zero except in {{transclusion}} tags
7271 var $mWatched = null; // /< Is $wgUser watching this page? null if unfilled, accessed through userIsWatching()
7372 var $mLength = -1; // /< The page length, 0 for special pages
7473 var $mRedirect = null; // /< Is the article at this title a redirect?
@@ -78,16 +77,17 @@
7978
8079 /**
8180 * Constructor
 81+ * @private
8282 */
83 - /*protected*/ function __construct() { }
 83+ /* private */ function __construct() { }
8484
8585 /**
8686 * Create a new Title from a prefixed DB key
8787 *
88 - * @param $key String the database key, which has underscores
 88+ * @param $key \type{\string} The database key, which has underscores
8989 * instead of spaces, possibly including namespace and
9090 * interwiki prefixes
91 - * @return Title, or NULL on an error
 91+ * @return \type{Title} the new object, or NULL on an error
9292 */
9393 public static function newFromDBkey( $key ) {
9494 $t = new Title();
@@ -103,13 +103,13 @@
104104 * Create a new Title from text, such as what one would find in a link. De-
105105 * codes any HTML entities in the text.
106106 *
107 - * @param $text String the link text; spaces, prefixes, and an
 107+ * @param $text string The link text; spaces, prefixes, and an
108108 * initial ':' indicating the main namespace are accepted.
109 - * @param $defaultNamespace Int the namespace to use if none is speci-
 109+ * @param $defaultNamespace int The namespace to use if none is speci-
110110 * fied by a prefix. If you want to force a specific namespace even if
111111 * $text might begin with a namespace prefix, use makeTitle() or
112112 * makeTitleSafe().
113 - * @return Title, or null on an error.
 113+ * @return Title The new object, or null on an error.
114114 */
115115 public static function newFromText( $text, $defaultNamespace = NS_MAIN ) {
116116 if ( is_object( $text ) ) {
@@ -128,7 +128,9 @@
129129 return Title::$titleCache[$text];
130130 }
131131
132 - # Convert things like &eacute; &#257; or &#x3017; into normalized (bug 14952) text
 132+ /**
 133+ * Convert things like &eacute; &#257; or &#x3017; into normalized(bug 14952) text
 134+ */
133135 $filteredText = Sanitizer::decodeCharReferencesAndNormalize( $text );
134136
135137 $t = new Title();
@@ -165,8 +167,8 @@
166168 * Create a new Title from URL-encoded text. Ensures that
167169 * the given title's length does not exceed the maximum.
168170 *
169 - * @param $url String the title, as might be taken from a URL
170 - * @return Title the new object, or NULL on an error
 171+ * @param $url \type{\string} the title, as might be taken from a URL
 172+ * @return \type{Title} the new object, or NULL on an error
171173 */
172174 public static function newFromURL( $url ) {
173175 global $wgLegalTitleChars;
@@ -190,12 +192,12 @@
191193 /**
192194 * Create a new Title from an article ID
193195 *
194 - * @param $id Int the page_id corresponding to the Title to create
195 - * @param $flags Int use Title::GAID_FOR_UPDATE to use master
196 - * @return Title the new object, or NULL on an error
 196+ * @param $id \type{\int} the page_id corresponding to the Title to create
 197+ * @param $flags \type{\int} use GAID_FOR_UPDATE to use master
 198+ * @return \type{Title} the new object, or NULL on an error
197199 */
198200 public static function newFromID( $id, $flags = 0 ) {
199 - $db = ( $flags & self::GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
 201+ $db = ( $flags & GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
200202 $row = $db->selectRow( 'page', '*', array( 'page_id' => $id ), __METHOD__ );
201203 if ( $row !== false ) {
202204 $title = Title::newFromRow( $row );
@@ -208,15 +210,15 @@
209211 /**
210212 * Make an array of titles from an array of IDs
211213 *
212 - * @param $ids Array of Int Array of IDs
213 - * @return Array of Titles
 214+ * @param $ids \type{\arrayof{\int}} Array of IDs
 215+ * @return \type{\arrayof{Title}} Array of Titles
214216 */
215217 public static function newFromIDs( $ids ) {
216218 if ( !count( $ids ) ) {
217219 return array();
218220 }
219221 $dbr = wfGetDB( DB_SLAVE );
220 -
 222+
221223 $res = $dbr->select(
222224 'page',
223225 array(
@@ -237,8 +239,8 @@
238240 /**
239241 * Make a Title object from a DB row
240242 *
241 - * @param $row Object database row (needs at least page_title,page_namespace)
242 - * @return Title corresponding Title
 243+ * @param $row \type{Row} (needs at least page_title,page_namespace)
 244+ * @return \type{Title} corresponding Title
243245 */
244246 public static function newFromRow( $row ) {
245247 $t = self::makeTitle( $row->page_namespace, $row->page_title );
@@ -258,11 +260,11 @@
259261 * For convenience, spaces are converted to underscores so that
260262 * eg user_text fields can be used directly.
261263 *
262 - * @param $ns Int the namespace of the article
263 - * @param $title String the unprefixed database key form
264 - * @param $fragment String the link fragment (after the "#")
265 - * @param $interwiki String the interwiki prefix
266 - * @return Title the new object
 264+ * @param $ns \type{\int} the namespace of the article
 265+ * @param $title \type{\string} the unprefixed database key form
 266+ * @param $fragment \type{\string} The link fragment (after the "#")
 267+ * @param $interwiki \type{\string} The interwiki prefix
 268+ * @return \type{Title} the new object
267269 */
268270 public static function &makeTitle( $ns, $title, $fragment = '', $interwiki = '' ) {
269271 $t = new Title();
@@ -281,11 +283,11 @@
282284 * The parameters will be checked for validity, which is a bit slower
283285 * than makeTitle() but safer for user-provided data.
284286 *
285 - * @param $ns Int the namespace of the article
286 - * @param $title String database key form
287 - * @param $fragment String the link fragment (after the "#")
288 - * @param $interwiki String interwiki prefix
289 - * @return Title the new object, or NULL on an error
 287+ * @param $ns \type{\int} the namespace of the article
 288+ * @param $title \type{\string} the database key form
 289+ * @param $fragment \type{\string} The link fragment (after the "#")
 290+ * @param $interwiki \type{\string} The interwiki prefix
 291+ * @return \type{Title} the new object, or NULL on an error
290292 */
291293 public static function makeTitleSafe( $ns, $title, $fragment = '', $interwiki = '' ) {
292294 $t = new Title();
@@ -300,7 +302,7 @@
301303 /**
302304 * Create a new Title for the Main Page
303305 *
304 - * @return Title the new object
 306+ * @return \type{Title} the new object
305307 */
306308 public static function newMainPage() {
307309 $title = Title::newFromText( wfMsgForContent( 'mainpage' ) );
@@ -317,8 +319,8 @@
318320 * This will only return the very next target, useful for
319321 * the redirect table and other checks that don't need full recursion
320322 *
321 - * @param $text String: Text with possible redirect
322 - * @return Title: The corresponding Title
 323+ * @param $text \type{\string} Text with possible redirect
 324+ * @return \type{Title} The corresponding Title
323325 */
324326 public static function newFromRedirect( $text ) {
325327 return self::newFromRedirectInternal( $text );
@@ -330,8 +332,8 @@
331333 * This will recurse down $wgMaxRedirects times or until a non-redirect target is hit
332334 * in order to provide (hopefully) the Title of the final destination instead of another redirect
333335 *
334 - * @param $text String Text with possible redirect
335 - * @return Title
 336+ * @param $text \type{\string} Text with possible redirect
 337+ * @return \type{Title} The corresponding Title
336338 */
337339 public static function newFromRedirectRecurse( $text ) {
338340 $titles = self::newFromRedirectArray( $text );
@@ -344,11 +346,15 @@
345347 * The last element in the array is the final destination after all redirects
346348 * have been resolved (up to $wgMaxRedirects times)
347349 *
348 - * @param $text String Text with possible redirect
349 - * @return Array of Titles, with the destination last
 350+ * @param $text \type{\string} Text with possible redirect
 351+ * @return \type{\array} Array of Titles, with the destination last
350352 */
351353 public static function newFromRedirectArray( $text ) {
352354 global $wgMaxRedirects;
 355+ // are redirects disabled?
 356+ if ( $wgMaxRedirects < 1 ) {
 357+ return null;
 358+ }
353359 $title = self::newFromRedirectInternal( $text );
354360 if ( is_null( $title ) ) {
355361 return null;
@@ -379,15 +385,10 @@
380386 * Really extract the redirect destination
381387 * Do not call this function directly, use one of the newFromRedirect* functions above
382388 *
383 - * @param $text String Text with possible redirect
384 - * @return Title
 389+ * @param $text \type{\string} Text with possible redirect
 390+ * @return \type{Title} The corresponding Title
385391 */
386392 protected static function newFromRedirectInternal( $text ) {
387 - global $wgMaxRedirects;
388 - if ( $wgMaxRedirects < 1 ) {
389 - //redirects are disabled, so quit early
390 - return null;
391 - }
392393 $redir = MagicWord::get( 'redirect' );
393394 $text = trim( $text );
394395 if ( $redir->matchStartAndRemove( $text ) ) {
@@ -400,7 +401,9 @@
401402 // and URL-decode links
402403 if ( strpos( $m[1], '%' ) !== false ) {
403404 // Match behavior of inline link parsing here;
404 - $m[1] = rawurldecode( ltrim( $m[1], ':' ) );
 405+ // don't interpret + as " " most of the time!
 406+ // It might be safe to just use rawurldecode instead, though.
 407+ $m[1] = urldecode( ltrim( $m[1], ':' ) );
405408 }
406409 $title = Title::newFromText( $m[1] );
407410 // If the title is a redirect to bad special pages or is invalid, return null
@@ -420,8 +423,9 @@
421424 /**
422425 * Get the prefixed DB key associated with an ID
423426 *
424 - * @param $id Int the page_id of the article
425 - * @return Title an object representing the article, or NULL if no such article was found
 427+ * @param $id \type{\int} the page_id of the article
 428+ * @return \type{Title} an object representing the article, or NULL
 429+ * if no such article was found
426430 */
427431 public static function nameOf( $id ) {
428432 $dbr = wfGetDB( DB_SLAVE );
@@ -443,7 +447,7 @@
444448 /**
445449 * Get a regex character class describing the legal characters in a link
446450 *
447 - * @return String the list of characters, not delimited
 451+ * @return \type{\string} the list of characters, not delimited
448452 */
449453 public static function legalChars() {
450454 global $wgLegalTitleChars;
@@ -454,9 +458,10 @@
455459 * Get a string representation of a title suitable for
456460 * including in a search index
457461 *
458 - * @param $ns Int a namespace index
459 - * @param $title String text-form main part
460 - * @return String a stripped-down title string ready for the search index
 462+ * @param $ns \type{\int} a namespace index
 463+ * @param $title \type{\string} text-form main part
 464+ * @return \type{\string} a stripped-down title string ready for the
 465+ * search index
461466 */
462467 public static function indexTitle( $ns, $title ) {
463468 global $wgContLang;
@@ -481,11 +486,11 @@
482487 /**
483488 * Make a prefixed DB key from a DB key and a namespace index
484489 *
485 - * @param $ns Int numerical representation of the namespace
486 - * @param $title String the DB key form the title
487 - * @param $fragment String The link fragment (after the "#")
488 - * @param $interwiki String The interwiki prefix
489 - * @return String the prefixed form of the title
 490+ * @param $ns \type{\int} numerical representation of the namespace
 491+ * @param $title \type{\string} the DB key form the title
 492+ * @param $fragment \type{\string} The link fragment (after the "#")
 493+ * @param $interwiki \type{\string} The interwiki prefix
 494+ * @return \type{\string} the prefixed form of the title
490495 */
491496 public static function makeName( $ns, $title, $fragment = '', $interwiki = '' ) {
492497 global $wgContLang;
@@ -505,7 +510,8 @@
506511 * Determine whether the object refers to a page within
507512 * this project.
508513 *
509 - * @return Bool TRUE if this is an in-project interwiki link or a wikilink, FALSE otherwise
 514+ * @return \type{\bool} TRUE if this is an in-project interwiki link
 515+ * or a wikilink, FALSE otherwise
510516 */
511517 public function isLocal() {
512518 if ( $this->mInterwiki != '' ) {
@@ -519,7 +525,7 @@
520526 * Determine whether the object refers to a page within
521527 * this project and is transcludable.
522528 *
523 - * @return Bool TRUE if this is transcludable
 529+ * @return \type{\bool} TRUE if this is transcludable
524530 */
525531 public function isTrans() {
526532 if ( $this->mInterwiki == '' ) {
@@ -528,11 +534,25 @@
529535
530536 return Interwiki::fetch( $this->mInterwiki )->isTranscludable();
531537 }
 538+
 539+ /**
 540+ * Returns the API URL of the distant wiki
 541+ * which owns the object.
 542+ *
 543+ * @return \type{\string} the API URL
 544+ */
 545+ public function getTransAPI() {
 546+ if ( $this->mInterwiki == '' )
 547+ return false;
532548
 549+ return Interwiki::fetch( $this->mInterwiki )->getAPI();
 550+ }
 551+
533552 /**
534 - * Returns the DB name of the distant wiki which owns the object.
 553+ * Returns the DB name of the distant wiki
 554+ * which owns the object.
535555 *
536 - * @return String the DB name
 556+ * @return \type{\string} the DB name
537557 */
538558 public function getTransWikiID() {
539559 if ( $this->mInterwiki == '' ) {
@@ -564,35 +584,35 @@
565585 /**
566586 * Get the text form (spaces not underscores) of the main part
567587 *
568 - * @return String Main part of the title
 588+ * @return \type{\string} Main part of the title
569589 */
570590 public function getText() { return $this->mTextform; }
571591
572592 /**
573593 * Get the URL-encoded form of the main part
574594 *
575 - * @return String Main part of the title, URL-encoded
 595+ * @return \type{\string} Main part of the title, URL-encoded
576596 */
577597 public function getPartialURL() { return $this->mUrlform; }
578598
579599 /**
580600 * Get the main part with underscores
581601 *
582 - * @return String: Main part of the title, with underscores
 602+ * @return \type{\string} Main part of the title, with underscores
583603 */
584604 public function getDBkey() { return $this->mDbkeyform; }
585605
586606 /**
587 - * Get the namespace index, i.e. one of the NS_xxxx constants.
 607+ * Get the namespace index, i.e.\ one of the NS_xxxx constants.
588608 *
589 - * @return Integer: Namespace index
 609+ * @return \type{\int} Namespace index
590610 */
591611 public function getNamespace() { return $this->mNamespace; }
592612
593613 /**
594614 * Get the namespace text
595615 *
596 - * @return String: Namespace text
 616+ * @return \type{\string} Namespace text
597617 */
598618 public function getNsText() {
599619 global $wgContLang;
@@ -608,20 +628,13 @@
609629 return MWNamespace::getCanonicalName( $this->mNamespace );
610630 }
611631 }
612 -
613 - if ( $wgContLang->needsGenderDistinction() &&
614 - MWNamespace::hasGenderDistinction( $this->mNamespace ) ) {
615 - $gender = GenderCache::singleton()->getGenderOf( $this->getText(), __METHOD__ );
616 - return $wgContLang->getGenderNsText( $this->mNamespace, $gender );
617 - }
618 -
619632 return $wgContLang->getNsText( $this->mNamespace );
620633 }
621634
622635 /**
623636 * Get the DB key with the initial letter case as specified by the user
624637 *
625 - * @return String DB key
 638+ * @return \type{\string} DB key
626639 */
627640 function getUserCaseDBKey() {
628641 return $this->mUserCaseDBKey;
@@ -630,7 +643,7 @@
631644 /**
632645 * Get the namespace text of the subject (rather than talk) page
633646 *
634 - * @return String Namespace text
 647+ * @return \type{\string} Namespace text
635648 */
636649 public function getSubjectNsText() {
637650 global $wgContLang;
@@ -640,7 +653,7 @@
641654 /**
642655 * Get the namespace text of the talk page
643656 *
644 - * @return String Namespace text
 657+ * @return \type{\string} Namespace text
645658 */
646659 public function getTalkNsText() {
647660 global $wgContLang;
@@ -650,7 +663,7 @@
651664 /**
652665 * Could this title have a corresponding talk page?
653666 *
654 - * @return Bool TRUE or FALSE
 667+ * @return \type{\bool} TRUE or FALSE
655668 */
656669 public function canTalk() {
657670 return( MWNamespace::canTalk( $this->mNamespace ) );
@@ -659,20 +672,20 @@
660673 /**
661674 * Get the interwiki prefix (or null string)
662675 *
663 - * @return String Interwiki prefix
 676+ * @return \type{\string} Interwiki prefix
664677 */
665678 public function getInterwiki() { return $this->mInterwiki; }
666679
667680 /**
668681 * Get the Title fragment (i.e.\ the bit after the #) in text form
669682 *
670 - * @return String Title fragment
 683+ * @return \type{\string} Title fragment
671684 */
672685 public function getFragment() { return $this->mFragment; }
673686
674687 /**
675688 * Get the fragment in URL form, including the "#" character if there is one
676 - * @return String Fragment in URL form
 689+ * @return \type{\string} Fragment in URL form
677690 */
678691 public function getFragmentForURL() {
679692 if ( $this->mFragment == '' ) {
@@ -685,14 +698,14 @@
686699 /**
687700 * Get the default namespace index, for when there is no namespace
688701 *
689 - * @return Int Default namespace index
 702+ * @return \type{\int} Default namespace index
690703 */
691704 public function getDefaultNamespace() { return $this->mDefaultNamespace; }
692705
693706 /**
694707 * Get title for search index
695708 *
696 - * @return String a stripped-down title string ready for the
 709+ * @return \type{\string} a stripped-down title string ready for the
697710 * search index
698711 */
699712 public function getIndexTitle() {
@@ -702,7 +715,7 @@
703716 /**
704717 * Get the prefixed database key form
705718 *
706 - * @return String the prefixed title, with underscores and
 719+ * @return \type{\string} the prefixed title, with underscores and
707720 * any interwiki and namespace prefixes
708721 */
709722 public function getPrefixedDBkey() {
@@ -715,7 +728,7 @@
716729 * Get the prefixed title with spaces.
717730 * This is the form usually used for display
718731 *
719 - * @return String the prefixed title, with spaces
 732+ * @return \type{\string} the prefixed title, with spaces
720733 */
721734 public function getPrefixedText() {
722735 if ( empty( $this->mPrefixedText ) ) { // FIXME: bad usage of empty() ?
@@ -744,7 +757,8 @@
745758 * Get the prefixed title with spaces, plus any fragment
746759 * (part beginning with '#')
747760 *
748 - * @return String the prefixed title, with spaces and the fragment, including '#'
 761+ * @return \type{\string} the prefixed title, with spaces and
 762+ * the fragment, including '#'
749763 */
750764 public function getFullText() {
751765 $text = $this->getPrefixedText();
@@ -757,7 +771,7 @@
758772 /**
759773 * Get the base name, i.e. the leftmost parts before the /
760774 *
761 - * @return String Base name
 775+ * @return \type{\string} Base name
762776 */
763777 public function getBaseText() {
764778 if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
@@ -775,7 +789,7 @@
776790 /**
777791 * Get the lowest-level subpage name, i.e. the rightmost part after /
778792 *
779 - * @return String Subpage name
 793+ * @return \type{\string} Subpage name
780794 */
781795 public function getSubpageText() {
782796 if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
@@ -788,7 +802,7 @@
789803 /**
790804 * Get a URL-encoded form of the subpage text
791805 *
792 - * @return String URL-encoded subpage name
 806+ * @return \type{\string} URL-encoded subpage name
793807 */
794808 public function getSubpageUrlForm() {
795809 $text = $this->getSubpageText();
@@ -799,7 +813,7 @@
800814 /**
801815 * Get a URL-encoded title (not an actual URL) including interwiki
802816 *
803 - * @return String the URL-encoded form
 817+ * @return \type{\string} the URL-encoded form
804818 */
805819 public function getPrefixedURL() {
806820 $s = $this->prefix( $this->mDbkeyform );
@@ -814,8 +828,8 @@
815829 * @param $query \twotypes{\string,\array} an optional query string, not used for interwiki
816830 * links. Can be specified as an associative array as well, e.g.,
817831 * array( 'action' => 'edit' ) (keys and values will be URL-escaped).
818 - * @param $variant String language variant of url (for sr, zh..)
819 - * @return String the URL
 832+ * @param $variant \type{\string} language variant of url (for sr, zh..)
 833+ * @return \type{\string} the URL
820834 */
821835 public function getFullURL( $query = '', $variant = false ) {
822836 global $wgServer, $wgRequest;
@@ -861,17 +875,25 @@
862876 * $wgArticlePath will be used. Can be specified as an associative array
863877 * as well, e.g., array( 'action' => 'edit' ) (keys and values will be
864878 * URL-escaped).
865 - * @param $variant String language variant of url (for sr, zh..)
866 - * @return String the URL
 879+ * @param $variant \type{\string} language variant of url (for sr, zh..)
 880+ * @return \type{\string} the URL
867881 */
868882 public function getLocalURL( $query = '', $variant = false ) {
869883 global $wgArticlePath, $wgScript, $wgServer, $wgRequest;
870 - global $wgVariantArticlePath, $wgContLang;
 884+ global $wgVariantArticlePath, $wgContLang, $wgUser;
871885
872886 if ( is_array( $query ) ) {
873887 $query = wfArrayToCGI( $query );
874888 }
875889
 890+ // internal links should point to same variant as current page (only anonymous users)
 891+ if ( !$variant && $wgContLang->hasVariants() && !$wgUser->isLoggedIn() ) {
 892+ $pref = $wgContLang->getPreferredVariant( false );
 893+ if ( $pref != $wgContLang->getCode() ) {
 894+ $variant = $pref;
 895+ }
 896+ }
 897+
876898 if ( $this->isExternal() ) {
877899 $url = $this->getFullURL();
878900 if ( $query ) {
@@ -942,12 +964,12 @@
943965 * The result obviously should not be URL-escaped, but does need to be
944966 * HTML-escaped if it's being output in HTML.
945967 *
946 - * @param $query Array of Strings An associative array of key => value pairs for the
 968+ * @param $query \type{\arrayof{\string}} An associative array of key => value pairs for the
947969 * query string. Keys and values will be escaped.
948 - * @param $variant String language variant of URL (for sr, zh..). Ignored
 970+ * @param $variant \type{\string} Language variant of URL (for sr, zh..). Ignored
949971 * for external links. Default is "false" (same variant as current page,
950972 * for anonymous users).
951 - * @return String the URL
 973+ * @return \type{\string} the URL
952974 */
953975 public function getLinkUrl( $query = array(), $variant = false ) {
954976 wfProfileIn( __METHOD__ );
@@ -966,8 +988,8 @@
967989 * Get an HTML-escaped version of the URL form, suitable for
968990 * using in a link, without a server name or fragment
969991 *
970 - * @param $query String an optional query string
971 - * @return String the URL
 992+ * @param $query \type{\string} an optional query string
 993+ * @return \type{\string} the URL
972994 */
973995 public function escapeLocalURL( $query = '' ) {
974996 return htmlspecialchars( $this->getLocalURL( $query ) );
@@ -977,8 +999,8 @@
9781000 * Get an HTML-escaped version of the URL form, suitable for
9791001 * using in a link, including the server name and fragment
9801002 *
981 - * @param $query String an optional query string
982 - * @return String the URL
 1003+ * @param $query \type{\string} an optional query string
 1004+ * @return \type{\string} the URL
9831005 */
9841006 public function escapeFullURL( $query = '' ) {
9851007 return htmlspecialchars( $this->getFullURL( $query ) );
@@ -989,14 +1011,13 @@
9901012 * - Used in various Squid-related code, in case we have a different
9911013 * internal hostname for the server from the exposed one.
9921014 *
993 - * @param $query String an optional query string
994 - * @param $variant String language variant of url (for sr, zh..)
995 - * @return String the URL
 1015+ * @param $query \type{\string} an optional query string
 1016+ * @param $variant \type{\string} language variant of url (for sr, zh..)
 1017+ * @return \type{\string} the URL
9961018 */
9971019 public function getInternalURL( $query = '', $variant = false ) {
998 - global $wgInternalServer, $wgServer;
999 - $server = $wgInternalServer !== false ? $wgInternalServer : $wgServer;
1000 - $url = $server . $this->getLocalURL( $query, $variant );
 1020+ global $wgInternalServer;
 1021+ $url = $wgInternalServer . $this->getLocalURL( $query, $variant );
10011022 wfRunHooks( 'GetInternalURL', array( &$this, &$url, $query ) );
10021023 return $url;
10031024 }
@@ -1004,7 +1025,7 @@
10051026 /**
10061027 * Get the edit URL for this Title
10071028 *
1008 - * @return String the URL, or a null string if this is an
 1029+ * @return \type{\string} the URL, or a null string if this is an
10091030 * interwiki link
10101031 */
10111032 public function getEditURL() {
@@ -1020,7 +1041,7 @@
10211042 * Get the HTML-escaped displayable text form.
10221043 * Used for the title field in <a> tags.
10231044 *
1024 - * @return String the text, including any prefixes
 1045+ * @return \type{\string} the text, including any prefixes
10251046 */
10261047 public function getEscapedText() {
10271048 return htmlspecialchars( $this->getPrefixedText() );
@@ -1029,7 +1050,7 @@
10301051 /**
10311052 * Is this Title interwiki?
10321053 *
1033 - * @return Bool
 1054+ * @return \type{\bool}
10341055 */
10351056 public function isExternal() {
10361057 return ( $this->mInterwiki != '' );
@@ -1038,8 +1059,8 @@
10391060 /**
10401061 * Is this page "semi-protected" - the *only* protection is autoconfirm?
10411062 *
1042 - * @param $action String Action to check (default: edit)
1043 - * @return Bool
 1063+ * @param $action \type{\string} Action to check (default: edit)
 1064+ * @return \type{\bool}
10441065 */
10451066 public function isSemiProtected( $action = 'edit' ) {
10461067 if ( $this->exists() ) {
@@ -1064,9 +1085,9 @@
10651086 /**
10661087 * Does the title correspond to a protected article?
10671088 *
1068 - * @param $action String the action the page is protected from,
 1089+ * @param $action \type{\string} the action the page is protected from,
10691090 * by default checks all actions.
1070 - * @return Bool
 1091+ * @return \type{\bool}
10711092 */
10721093 public function isProtected( $action = '' ) {
10731094 global $wgRestrictionLevels;
@@ -1096,7 +1117,7 @@
10971118 /**
10981119 * Is this a conversion table for the LanguageConverter?
10991120 *
1100 - * @return Bool
 1121+ * @return \type{\bool}
11011122 */
11021123 public function isConversionTable() {
11031124 if(
@@ -1113,7 +1134,7 @@
11141135 /**
11151136 * Is $wgUser watching this page?
11161137 *
1117 - * @return Bool
 1138+ * @return \type{\bool}
11181139 */
11191140 public function userIsWatching() {
11201141 global $wgUser;
@@ -1138,31 +1159,24 @@
11391160 *
11401161 * May provide false positives, but should never provide a false negative.
11411162 *
1142 - * @param $action String action that permission needs to be checked for
1143 - * @return Bool
 1163+ * @param $action \type{\string} action that permission needs to be checked for
 1164+ * @return \type{\bool}
11441165 */
11451166 public function quickUserCan( $action ) {
11461167 return $this->userCan( $action, false );
11471168 }
11481169
11491170 /**
1150 - * Determines if $user is unable to edit this page because it has been protected
 1171+ * Determines if $wgUser is unable to edit this page because it has been protected
11511172 * by $wgNamespaceProtection.
11521173 *
1153 - * @param $user User object, $wgUser will be used if not passed
1154 - * @return Bool
 1174+ * @return \type{\bool}
11551175 */
1156 - public function isNamespaceProtected( User $user = null ) {
1157 - global $wgNamespaceProtection;
1158 -
1159 - if ( $user === null ) {
1160 - global $wgUser;
1161 - $user = $wgUser;
1162 - }
1163 -
 1176+ public function isNamespaceProtected() {
 1177+ global $wgNamespaceProtection, $wgUser;
11641178 if ( isset( $wgNamespaceProtection[$this->mNamespace] ) ) {
11651179 foreach ( (array)$wgNamespaceProtection[$this->mNamespace] as $right ) {
1166 - if ( $right != '' && !$user->isAllowed( $right ) ) {
 1180+ if ( $right != '' && !$wgUser->isAllowed( $right ) ) {
11671181 return true;
11681182 }
11691183 }
@@ -1173,9 +1187,9 @@
11741188 /**
11751189 * Can $wgUser perform $action on this page?
11761190 *
1177 - * @param $action String action that permission needs to be checked for
1178 - * @param $doExpensiveQueries Bool Set this to false to avoid doing unnecessary queries.
1179 - * @return Bool
 1191+ * @param $action \type{\string} action that permission needs to be checked for
 1192+ * @param $doExpensiveQueries \type{\bool} Set this to false to avoid doing unnecessary queries.
 1193+ * @return \type{\bool}
11801194 */
11811195 public function userCan( $action, $doExpensiveQueries = true ) {
11821196 global $wgUser;
@@ -1187,13 +1201,21 @@
11881202 *
11891203 * FIXME: This *does not* check throttles (User::pingLimiter()).
11901204 *
1191 - * @param $action String action that permission needs to be checked for
1192 - * @param $user User to check
1193 - * @param $doExpensiveQueries Bool Set this to false to avoid doing unnecessary queries.
1194 - * @param $ignoreErrors Array of Strings Set this to a list of message keys whose corresponding errors may be ignored.
1195 - * @return Array of arguments to wfMsg to explain permissions problems.
 1205+ * @param $action \type{\string}action that permission needs to be checked for
 1206+ * @param $user \type{User} user to check
 1207+ * @param $doExpensiveQueries \type{\bool} Set this to false to avoid doing unnecessary queries.
 1208+ * @param $ignoreErrors \type{\arrayof{\string}} Set this to a list of message keys whose corresponding errors may be ignored.
 1209+ * @return \type{\array} Array of arrays of the arguments to wfMsg to explain permissions problems.
11961210 */
11971211 public function getUserPermissionsErrors( $action, $user, $doExpensiveQueries = true, $ignoreErrors = array() ) {
 1212+ if ( !StubObject::isRealObject( $user ) ) {
 1213+ // Since StubObject is always used on globals, we can
 1214+ // unstub $wgUser here and set $user = $wgUser
 1215+ global $wgUser;
 1216+ $wgUser->_unstub( '', 5 );
 1217+ $user = $wgUser;
 1218+ }
 1219+
11981220 $errors = $this->getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries );
11991221
12001222 // Remove the errors being ignored.
@@ -1265,6 +1287,8 @@
12661288 $errors[] = array( 'cant-move-to-user-page' );
12671289 }
12681290 } elseif ( !$user->isAllowed( $action ) ) {
 1291+ $return = null;
 1292+
12691293 // We avoid expensive display logic for quickUserCan's and such
12701294 $groups = false;
12711295 if ( !$short ) {
@@ -1315,18 +1339,10 @@
13161340
13171341 /**
13181342 * Check various permission hooks
1319 - *
1320 - * @param $action String the action to check
1321 - * @param $user User user to check
1322 - * @param $errors Array list of current errors
1323 - * @param $doExpensiveQueries Boolean whether or not to perform expensive queries
1324 - * @param $short Boolean short circuit on first error
1325 - *
1326 - * @return Array list of errors
 1343+ * @see checkQuickPermissions for parameter information
13271344 */
13281345 private function checkPermissionHooks( $action, $user, $errors, $doExpensiveQueries, $short ) {
13291346 // Use getUserPermissionsErrors instead
1330 - $result = '';
13311347 if ( !wfRunHooks( 'userCan', array( &$this, &$user, $action, &$result ) ) ) {
13321348 return $result ? array() : array( array( 'badaccess-group0' ) );
13331349 }
@@ -1345,14 +1361,7 @@
13461362
13471363 /**
13481364 * Check permissions on special pages & namespaces
1349 - *
1350 - * @param $action String the action to check
1351 - * @param $user User user to check
1352 - * @param $errors Array list of current errors
1353 - * @param $doExpensiveQueries Boolean whether or not to perform expensive queries
1354 - * @param $short Boolean short circuit on first error
1355 - *
1356 - * @return Array list of errors
 1365+ * @see checkQuickPermissions for parameter information
13571366 */
13581367 private function checkSpecialsAndNSPermissions( $action, $user, $errors, $doExpensiveQueries, $short ) {
13591368 # Only 'createaccount' and 'execute' can be performed on
@@ -1363,7 +1372,7 @@
13641373 }
13651374
13661375 # Check $wgNamespaceProtection for restricted namespaces
1367 - if ( $this->isNamespaceProtected( $user ) ) {
 1376+ if ( $this->isNamespaceProtected() ) {
13681377 $ns = $this->mNamespace == NS_MAIN ?
13691378 wfMsg( 'nstab-main' ) : $this->getNsText();
13701379 $errors[] = $this->mNamespace == NS_MEDIAWIKI ?
@@ -1375,14 +1384,7 @@
13761385
13771386 /**
13781387 * Check CSS/JS sub-page permissions
1379 - *
1380 - * @param $action String the action to check
1381 - * @param $user User user to check
1382 - * @param $errors Array list of current errors
1383 - * @param $doExpensiveQueries Boolean whether or not to perform expensive queries
1384 - * @param $short Boolean short circuit on first error
1385 - *
1386 - * @return Array list of errors
 1388+ * @see checkQuickPermissions for parameter information
13871389 */
13881390 private function checkCSSandJSPermissions( $action, $user, $errors, $doExpensiveQueries, $short ) {
13891391 # Protect css/js subpages of user pages
@@ -1406,14 +1408,7 @@
14071409 * Check against page_restrictions table requirements on this
14081410 * page. The user must possess all required rights for this
14091411 * action.
1410 - *
1411 - * @param $action String the action to check
1412 - * @param $user User user to check
1413 - * @param $errors Array list of current errors
1414 - * @param $doExpensiveQueries Boolean whether or not to perform expensive queries
1415 - * @param $short Boolean short circuit on first error
1416 - *
1417 - * @return Array list of errors
 1412+ * @see checkQuickPermissions for parameter information
14181413 */
14191414 private function checkPageRestrictions( $action, $user, $errors, $doExpensiveQueries, $short ) {
14201415 foreach ( $this->getRestrictions( $action ) as $right ) {
@@ -1440,14 +1435,7 @@
14411436
14421437 /**
14431438 * Check restrictions on cascading pages.
1444 - *
1445 - * @param $action String the action to check
1446 - * @param $user User to check
1447 - * @param $errors Array list of current errors
1448 - * @param $doExpensiveQueries Boolean whether or not to perform expensive queries
1449 - * @param $short Boolean short circuit on first error
1450 - *
1451 - * @return Array list of errors
 1439+ * @see checkQuickPermissions for parameter information
14521440 */
14531441 private function checkCascadingSourcesRestrictions( $action, $user, $errors, $doExpensiveQueries, $short ) {
14541442 if ( $doExpensiveQueries && !$this->isCssJsSubpage() ) {
@@ -1479,14 +1467,7 @@
14801468
14811469 /**
14821470 * Check action permissions not already checked in checkQuickPermissions
1483 - *
1484 - * @param $action String the action to check
1485 - * @param $user User to check
1486 - * @param $errors Array list of current errors
1487 - * @param $doExpensiveQueries Boolean whether or not to perform expensive queries
1488 - * @param $short Boolean short circuit on first error
1489 - *
1490 - * @return Array list of errors
 1471+ * @see checkQuickPermissions for parameter information
14911472 */
14921473 private function checkActionPermissions( $action, $user, $errors, $doExpensiveQueries, $short ) {
14931474 if ( $action == 'protect' ) {
@@ -1525,17 +1506,10 @@
15261507
15271508 /**
15281509 * Check that the user isn't blocked from editting.
1529 - *
1530 - * @param $action String the action to check
1531 - * @param $user User to check
1532 - * @param $errors Array list of current errors
1533 - * @param $doExpensiveQueries Boolean whether or not to perform expensive queries
1534 - * @param $short Boolean short circuit on first error
1535 - *
1536 - * @return Array list of errors
 1510+ * @see checkQuickPermissions for parameter information
15371511 */
15381512 private function checkUserBlock( $action, $user, $errors, $doExpensiveQueries, $short ) {
1539 - if( $short && count( $errors ) > 0 ) {
 1513+ if( $short ) {
15401514 return $errors;
15411515 }
15421516
@@ -1545,14 +1519,8 @@
15461520 $errors[] = array( 'confirmedittext' );
15471521 }
15481522
1549 - if ( in_array( $action, array( 'read', 'createaccount', 'unblock' ) ) ){
1550 - // Edit blocks should not affect reading.
1551 - // Account creation blocks handled at userlogin.
1552 - // Unblocking handled in SpecialUnblock
1553 - } elseif( ( $action == 'edit' || $action == 'create' ) && !$user->isBlockedFrom( $this ) ){
1554 - // Don't block the user from editing their own talk page unless they've been
1555 - // explicitly blocked from that too.
1556 - } elseif( $user->isBlocked() && $user->mBlock->prevents( $action ) !== false ) {
 1523+ // Edit blocks should not affect reading. Account creation blocks handled at userlogin.
 1524+ if ( $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this ) ) {
15571525 $block = $user->mBlock;
15581526
15591527 // This is from OutputPage::blockedPage
@@ -1572,16 +1540,29 @@
15731541 }
15741542
15751543 $link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]";
1576 - $blockid = $block->getId();
 1544+ $blockid = $block->mId;
15771545 $blockExpiry = $user->mBlock->mExpiry;
15781546 $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW, $user->mBlock->mTimestamp ), true );
15791547 if ( $blockExpiry == 'infinity' ) {
1580 - $blockExpiry = wfMessage( 'infiniteblock' )->text();
 1548+ // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite'
 1549+ $scBlockExpiryOptions = wfMsg( 'ipboptions' );
 1550+
 1551+ foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
 1552+ if ( !strpos( $option, ':' ) )
 1553+ continue;
 1554+
 1555+ list( $show, $value ) = explode( ':', $option );
 1556+
 1557+ if ( $value == 'infinite' || $value == 'indefinite' ) {
 1558+ $blockExpiry = $show;
 1559+ break;
 1560+ }
 1561+ }
15811562 } else {
15821563 $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW, $blockExpiry ), true );
15831564 }
15841565
1585 - $intended = strval( $user->mBlock->getTarget() );
 1566+ $intended = $user->mBlock->mAddress;
15861567
15871568 $errors[] = array( ( $block->mAuto ? 'autoblockedtext' : 'blockedtext' ), $link, $reason, $ip, $name,
15881569 $blockid, $blockExpiry, $intended, $blockTimestamp );
@@ -1595,11 +1576,11 @@
15961577 * which checks ONLY that previously checked by userCan (i.e. it leaves out
15971578 * checks on wfReadOnly() and blocks)
15981579 *
1599 - * @param $action String action that permission needs to be checked for
1600 - * @param $user User to check
1601 - * @param $doExpensiveQueries Bool Set this to false to avoid doing unnecessary queries.
1602 - * @param $short Bool Set this to true to stop after the first permission error.
1603 - * @return Array of arrays of the arguments to wfMsg to explain permissions problems.
 1580+ * @param $action \type{\string} action that permission needs to be checked for
 1581+ * @param $user \type{User} user to check
 1582+ * @param $doExpensiveQueries \type{\bool} Set this to false to avoid doing unnecessary queries.
 1583+ * @param $short \type{\bool} Set this to true to stop after the first permission error.
 1584+ * @return \type{\array} Array of arrays of the arguments to wfMsg to explain permissions problems.
16041585 */
16051586 protected function getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries = true, $short = false ) {
16061587 wfProfileIn( __METHOD__ );
@@ -1628,9 +1609,8 @@
16291610
16301611 /**
16311612 * Is this title subject to title protection?
1632 - * Title protection is the one applied against creation of such title.
16331613 *
1634 - * @return Mixed An associative array representing any existent title
 1614+ * @return \type{\mixed} An associative array representing any existent title
16351615 * protection, or false if there's none.
16361616 */
16371617 private function getTitleProtection() {
@@ -1659,9 +1639,9 @@
16601640 /**
16611641 * Update the title protection status
16621642 *
1663 - * @param $create_perm String Permission required for creation
1664 - * @param $reason String Reason for protection
1665 - * @param $expiry String Expiry timestamp
 1643+ * @param $create_perm \type{\string} Permission required for creation
 1644+ * @param $reason \type{\string} Reason for protection
 1645+ * @param $expiry \type{\string} Expiry timestamp
16661646 * @return boolean true
16671647 */
16681648 public function updateTitleProtection( $create_perm, $reason, $expiry ) {
@@ -1677,10 +1657,10 @@
16781658
16791659 $dbw = wfGetDB( DB_MASTER );
16801660
1681 - $encodedExpiry = $dbw->encodeExpiry( $expiry );
 1661+ $encodedExpiry = Block::encodeExpiry( $expiry, $dbw );
16821662
16831663 $expiry_description = '';
1684 - if ( $encodedExpiry != $dbw->getInfinity() ) {
 1664+ if ( $encodedExpiry != 'infinity' ) {
16851665 $expiry_description = ' (' . wfMsgForContent( 'protect-expiring', $wgContLang->timeanddate( $expiry ),
16861666 $wgContLang->date( $expiry ) , $wgContLang->time( $expiry ) ) . ')';
16871667 } else {
@@ -1689,23 +1669,21 @@
16901670
16911671 # Update protection table
16921672 if ( $create_perm != '' ) {
1693 - $this->mTitleProtection = array(
 1673+ $dbw->replace( 'protected_titles', array( array( 'pt_namespace', 'pt_title' ) ),
 1674+ array(
16941675 'pt_namespace' => $namespace,
16951676 'pt_title' => $title,
16961677 'pt_create_perm' => $create_perm,
1697 - 'pt_timestamp' => $dbw->encodeExpiry( wfTimestampNow() ),
 1678+ 'pt_timestamp' => Block::encodeExpiry( wfTimestampNow(), $dbw ),
16981679 'pt_expiry' => $encodedExpiry,
16991680 'pt_user' => $wgUser->getId(),
17001681 'pt_reason' => $reason,
1701 - );
1702 - $dbw->replace( 'protected_titles', array( array( 'pt_namespace', 'pt_title' ) ),
1703 - $this->mTitleProtection, __METHOD__ );
 1682+ ), __METHOD__
 1683+ );
17041684 } else {
17051685 $dbw->delete( 'protected_titles', array( 'pt_namespace' => $namespace,
17061686 'pt_title' => $title ), __METHOD__ );
1707 - $this->mTitleProtection = false;
17081687 }
1709 -
17101688 # Update the protection log
17111689 if ( $dbw->affectedRows() ) {
17121690 $log = new LogPage( 'protect' );
@@ -1732,14 +1710,13 @@
17331711 array( 'pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey() ),
17341712 __METHOD__
17351713 );
1736 - $this->mTitleProtection = false;
17371714 }
17381715
17391716 /**
17401717 * Would anybody with sufficient privileges be able to move this page?
17411718 * Some pages just aren't movable.
17421719 *
1743 - * @return Bool TRUE or FALSE
 1720+ * @return \type{\bool} TRUE or FALSE
17441721 */
17451722 public function isMovable() {
17461723 return MWNamespace::isMovable( $this->getNamespace() ) && $this->getInterwiki() == '';
@@ -1748,7 +1725,7 @@
17491726 /**
17501727 * Can $wgUser read this page?
17511728 *
1752 - * @return Bool
 1729+ * @return \type{\bool}
17531730 * @todo fold these checks into userCan()
17541731 */
17551732 public function userCanRead() {
@@ -1796,36 +1773,47 @@
17971774 } else {
17981775 global $wgWhitelistRead;
17991776
1800 - # Always grant access to the login page.
1801 - # Even anons need to be able to log in.
1802 - if ( $this->isSpecial( 'Userlogin' ) || $this->isSpecial( 'ChangePassword' ) ) {
 1777+ /**
 1778+ * Always grant access to the login page.
 1779+ * Even anons need to be able to log in.
 1780+ */
 1781+ if ( $this->isSpecial( 'Userlogin' ) || $this->isSpecial( 'Resetpass' ) ) {
18031782 return true;
18041783 }
18051784
1806 - # Bail out if there isn't whitelist
 1785+ /**
 1786+ * Bail out if there isn't whitelist
 1787+ */
18071788 if ( !is_array( $wgWhitelistRead ) ) {
18081789 return false;
18091790 }
18101791
1811 - # Check for explicit whitelisting
 1792+ /**
 1793+ * Check for explicit whitelisting
 1794+ */
18121795 $name = $this->getPrefixedText();
18131796 $dbName = $this->getPrefixedDBKey();
18141797 // Check with and without underscores
18151798 if ( in_array( $name, $wgWhitelistRead, true ) || in_array( $dbName, $wgWhitelistRead, true ) )
18161799 return true;
18171800
1818 - # Old settings might have the title prefixed with
1819 - # a colon for main-namespace pages
 1801+ /**
 1802+ * Old settings might have the title prefixed with
 1803+ * a colon for main-namespace pages
 1804+ */
18201805 if ( $this->getNamespace() == NS_MAIN ) {
18211806 if ( in_array( ':' . $name, $wgWhitelistRead ) ) {
18221807 return true;
18231808 }
18241809 }
18251810
1826 - # If it's a special page, ditch the subpage bit and check again
 1811+ /**
 1812+ * If it's a special page, ditch the subpage bit
 1813+ * and check again
 1814+ */
18271815 if ( $this->getNamespace() == NS_SPECIAL ) {
18281816 $name = $this->getDBkey();
1829 - list( $name, /* $subpage */ ) = SpecialPageFactory::resolveAlias( $name );
 1817+ list( $name, /* $subpage */ ) = SpecialPage::resolveAliasWithSubpage( $name );
18301818 if ( $name === false ) {
18311819 # Invalid special page, but we show standard login required message
18321820 return false;
@@ -1842,22 +1830,9 @@
18431831 }
18441832
18451833 /**
1846 - * Is this the mainpage?
1847 - * @note Title::newFromText seams to be sufficiently optimized by the title
1848 - * cache that we don't need to over-optimize by doing direct comparisons and
1849 - * acidentally creating new bugs where $title->equals( Title::newFromText() )
1850 - * ends up reporting something differently than $title->isMainPage();
1851 - *
1852 - * @return Bool
1853 - */
1854 - public function isMainPage() {
1855 - return $this->equals( Title::newMainPage() );
1856 - }
1857 -
1858 - /**
18591834 * Is this a talk page of some sort?
18601835 *
1861 - * @return Bool
 1836+ * @return \type{\bool}
18621837 */
18631838 public function isTalkPage() {
18641839 return MWNamespace::isTalk( $this->getNamespace() );
@@ -1866,7 +1841,7 @@
18671842 /**
18681843 * Is this a subpage?
18691844 *
1870 - * @return Bool
 1845+ * @return \type{\bool}
18711846 */
18721847 public function isSubpage() {
18731848 return MWNamespace::hasSubpages( $this->mNamespace )
@@ -1877,7 +1852,7 @@
18781853 /**
18791854 * Does this have subpages? (Warning, usually requires an extra DB query.)
18801855 *
1881 - * @return Bool
 1856+ * @return \type{\bool}
18821857 */
18831858 public function hasSubpages() {
18841859 if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) {
@@ -1903,7 +1878,7 @@
19041879 /**
19051880 * Get all subpages of this page.
19061881 *
1907 - * @param $limit Int maximum number of subpages to fetch; -1 for no limit
 1882+ * @param $limit Maximum number of subpages to fetch; -1 for no limit
19081883 * @return mixed TitleArray, or empty array if this page's namespace
19091884 * doesn't allow subpages
19101885 */
@@ -1933,7 +1908,7 @@
19341909 * Could this page contain custom CSS or JavaScript, based
19351910 * on the title?
19361911 *
1937 - * @return Bool
 1912+ * @return \type{\bool}
19381913 */
19391914 public function isCssOrJsPage() {
19401915 return $this->mNamespace == NS_MEDIAWIKI
@@ -1942,7 +1917,7 @@
19431918
19441919 /**
19451920 * Is this a .css or .js subpage of a user page?
1946 - * @return Bool
 1921+ * @return \type{\bool}
19471922 */
19481923 public function isCssJsSubpage() {
19491924 return ( NS_USER == $this->mNamespace and preg_match( "/\\/.*\\.(?:css|js)$/", $this->mTextform ) );
@@ -1950,12 +1925,21 @@
19511926
19521927 /**
19531928 * Is this a *valid* .css or .js subpage of a user page?
 1929+ * Check that the corresponding skin exists
19541930 *
1955 - * @return Bool
1956 - * @deprecated since 1.17
 1931+ * @return \type{\bool}
19571932 */
19581933 public function isValidCssJsSubpage() {
1959 - return $this->isCssJsSubpage();
 1934+ if ( $this->isCssJsSubpage() ) {
 1935+ $name = $this->getSkinFromCssJsSubpage();
 1936+ if ( $name == 'common' ) {
 1937+ return true;
 1938+ }
 1939+ $skinNames = Skin::getSkinNames();
 1940+ return array_key_exists( $name, $skinNames );
 1941+ } else {
 1942+ return false;
 1943+ }
19601944 }
19611945
19621946 /**
@@ -1972,7 +1956,7 @@
19731957 /**
19741958 * Is this a .css subpage of a user page?
19751959 *
1976 - * @return Bool
 1960+ * @return \type{\bool}
19771961 */
19781962 public function isCssSubpage() {
19791963 return ( NS_USER == $this->mNamespace && preg_match( "/\\/.*\\.css$/", $this->mTextform ) );
@@ -1981,7 +1965,7 @@
19821966 /**
19831967 * Is this a .js subpage of a user page?
19841968 *
1985 - * @return Bool
 1969+ * @return \type{\bool}
19861970 */
19871971 public function isJsSubpage() {
19881972 return ( NS_USER == $this->mNamespace && preg_match( "/\\/.*\\.js$/", $this->mTextform ) );
@@ -1991,12 +1975,12 @@
19921976 * Protect css subpages of user pages: can $wgUser edit
19931977 * this page?
19941978 *
1995 - * @return Bool
 1979+ * @return \type{\bool}
19961980 * @todo XXX: this might be better using restrictions
19971981 */
19981982 public function userCanEditCssSubpage() {
19991983 global $wgUser;
2000 - return ( ( $wgUser->isAllowedAll( 'editusercssjs', 'editusercss' ) )
 1984+ return ( ( $wgUser->isAllowed( 'editusercssjs' ) && $wgUser->isAllowed( 'editusercss' ) )
20011985 || preg_match( '/^' . preg_quote( $wgUser->getName(), '/' ) . '\//', $this->mTextform ) );
20021986 }
20031987
@@ -2004,19 +1988,19 @@
20051989 * Protect js subpages of user pages: can $wgUser edit
20061990 * this page?
20071991 *
2008 - * @return Bool
 1992+ * @return \type{\bool}
20091993 * @todo XXX: this might be better using restrictions
20101994 */
20111995 public function userCanEditJsSubpage() {
20121996 global $wgUser;
2013 - return ( ( $wgUser->isAllowedAll( 'editusercssjs', 'edituserjs' ) )
2014 - || preg_match( '/^' . preg_quote( $wgUser->getName(), '/' ) . '\//', $this->mTextform ) );
 1997+ return ( ( $wgUser->isAllowed( 'editusercssjs' ) && $wgUser->isAllowed( 'edituserjs' ) )
 1998+ || preg_match( '/^' . preg_quote( $wgUser->getName(), '/' ) . '\//', $this->mTextform ) );
20151999 }
20162000
20172001 /**
20182002 * Cascading protection: Return true if cascading restrictions apply to this page, false if not.
20192003 *
2020 - * @return Bool If the page is subject to cascading restrictions.
 2004+ * @return \type{\bool} If the page is subject to cascading restrictions.
20212005 */
20222006 public function isCascadeProtected() {
20232007 list( $sources, /* $restrictions */ ) = $this->getCascadeProtectionSources( false );
@@ -2026,15 +2010,15 @@
20272011 /**
20282012 * Cascading protection: Get the source of any cascading restrictions on this page.
20292013 *
2030 - * @param $getPages Bool Whether or not to retrieve the actual pages
 2014+ * @param $getPages \type{\bool} Whether or not to retrieve the actual pages
20312015 * that the restrictions have come from.
2032 - * @return Mixed Array of Title objects of the pages from which cascading restrictions
2033 - * have come, false for none, or true if such restrictions exist, but $getPages
2034 - * was not set. The restriction array is an array of each type, each of which
2035 - * contains a array of unique groups.
 2016+ * @return \type{\arrayof{mixed title array, restriction array}} Array of the Title
 2017+ * objects of the pages from which cascading restrictions have come,
 2018+ * false for none, or true if such restrictions exist, but $getPages was not set.
 2019+ * The restriction array is an array of each type, each of which contains a
 2020+ * array of unique groups.
20362021 */
20372022 public function getCascadeProtectionSources( $getPages = true ) {
2038 - global $wgContLang;
20392023 $pagerestrictions = array();
20402024
20412025 if ( isset( $this->mCascadeSources ) && $getPages ) {
@@ -2080,7 +2064,7 @@
20812065 $purgeExpired = false;
20822066
20832067 foreach ( $res as $row ) {
2084 - $expiry = $wgContLang->formatExpiry( $row->pr_expiry, TS_MW );
 2068+ $expiry = Block::decodeExpiry( $row->pr_expiry );
20852069 if ( $expiry > $now ) {
20862070 if ( $getPages ) {
20872071 $page_id = $row->pr_page;
@@ -2110,6 +2094,8 @@
21112095 Title::purgeExpiredRestrictions();
21122096 }
21132097
 2098+ wfProfileOut( __METHOD__ );
 2099+
21142100 if ( $getPages ) {
21152101 $this->mCascadeSources = $sources;
21162102 $this->mCascadingRestrictions = $pagerestrictions;
@@ -2117,7 +2103,6 @@
21182104 $this->mHasCascadingRestrictions = $sources;
21192105 }
21202106
2121 - wfProfileOut( __METHOD__ );
21222107 return array( $sources, $pagerestrictions );
21232108 }
21242109
@@ -2137,14 +2122,15 @@
21382123 /**
21392124 * Loads a string into mRestrictions array
21402125 *
2141 - * @param $res Resource restrictions as an SQL result.
2142 - * @param $oldFashionedRestrictions String comma-separated list of page
 2126+ * @param $res \type{Resource} restrictions as an SQL result.
 2127+ * @param $oldFashionedRestrictions string comma-separated list of page
21432128 * restrictions from page table (pre 1.10)
21442129 */
21452130 private function loadRestrictionsFromResultWrapper( $res, $oldFashionedRestrictions = null ) {
21462131 $rows = array();
 2132+ $dbr = wfGetDB( DB_SLAVE );
21472133
2148 - foreach ( $res as $row ) {
 2134+ while ( $row = $dbr->fetchObject( $res ) ) {
21492135 $rows[] = $row;
21502136 }
21512137
@@ -2153,22 +2139,20 @@
21542140
21552141 /**
21562142 * Compiles list of active page restrictions from both page table (pre 1.10)
2157 - * and page_restrictions table for this existing page.
2158 - * Public for usage by LiquidThreads.
 2143+ * and page_restrictions table
21592144 *
21602145 * @param $rows array of db result objects
21612146 * @param $oldFashionedRestrictions string comma-separated list of page
21622147 * restrictions from page table (pre 1.10)
21632148 */
21642149 public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) {
2165 - global $wgContLang;
21662150 $dbr = wfGetDB( DB_SLAVE );
21672151
21682152 $restrictionTypes = $this->getRestrictionTypes();
21692153
21702154 foreach ( $restrictionTypes as $type ) {
21712155 $this->mRestrictions[$type] = array();
2172 - $this->mRestrictionsExpiry[$type] = $wgContLang->formatExpiry( '', TS_MW );
 2156+ $this->mRestrictionsExpiry[$type] = Block::decodeExpiry( '' );
21732157 }
21742158
21752159 $this->mCascadeRestriction = false;
@@ -2202,16 +2186,17 @@
22032187 $now = wfTimestampNow();
22042188 $purgeExpired = false;
22052189
2206 - # Cycle through all the restrictions.
22072190 foreach ( $rows as $row ) {
 2191+ # Cycle through all the restrictions.
22082192
22092193 // Don't take care of restrictions types that aren't allowed
 2194+
22102195 if ( !in_array( $row->pr_type, $restrictionTypes ) )
22112196 continue;
22122197
22132198 // This code should be refactored, now that it's being used more generally,
22142199 // But I don't really see any harm in leaving it in Block for now -werdna
2215 - $expiry = $wgContLang->formatExpiry( $row->pr_expiry, TS_MW );
 2200+ $expiry = Block::decodeExpiry( $row->pr_expiry );
22162201
22172202 // Only apply the restrictions if they haven't expired!
22182203 if ( !$expiry || $expiry > $now ) {
@@ -2236,21 +2221,16 @@
22372222 /**
22382223 * Load restrictions from the page_restrictions table
22392224 *
2240 - * @param $oldFashionedRestrictions String comma-separated list of page
 2225+ * @param $oldFashionedRestrictions string comma-separated list of page
22412226 * restrictions from page table (pre 1.10)
22422227 */
22432228 public function loadRestrictions( $oldFashionedRestrictions = null ) {
2244 - global $wgContLang;
22452229 if ( !$this->mRestrictionsLoaded ) {
22462230 if ( $this->exists() ) {
22472231 $dbr = wfGetDB( DB_SLAVE );
22482232
2249 - $res = $dbr->select(
2250 - 'page_restrictions',
2251 - '*',
2252 - array( 'pr_page' => $this->getArticleId() ),
2253 - __METHOD__
2254 - );
 2233+ $res = $dbr->select( 'page_restrictions', '*',
 2234+ array( 'pr_page' => $this->getArticleId() ), __METHOD__ );
22552235
22562236 $this->loadRestrictionsFromResultWrapper( $res, $oldFashionedRestrictions );
22572237 } else {
@@ -2258,7 +2238,7 @@
22592239
22602240 if ( $title_protection ) {
22612241 $now = wfTimestampNow();
2262 - $expiry = $wgContLang->formatExpiry( $title_protection['pt_expiry'], TS_MW );
 2242+ $expiry = Block::decodeExpiry( $title_protection['pt_expiry'] );
22632243
22642244 if ( !$expiry || $expiry > $now ) {
22652245 // Apply the restrictions
@@ -2266,10 +2246,9 @@
22672247 $this->mRestrictions['create'] = explode( ',', trim( $title_protection['pt_create_perm'] ) );
22682248 } else { // Get rid of the old restrictions
22692249 Title::purgeExpiredRestrictions();
2270 - $this->mTitleProtection = false;
22712250 }
22722251 } else {
2273 - $this->mRestrictionsExpiry['create'] = $wgContLang->formatExpiry( '', TS_MW );
 2252+ $this->mRestrictionsExpiry['create'] = Block::decodeExpiry( '' );
22742253 }
22752254 $this->mRestrictionsLoaded = true;
22762255 }
@@ -2297,8 +2276,8 @@
22982277 /**
22992278 * Accessor/initialisation for mRestrictions
23002279 *
2301 - * @param $action String action that permission needs to be checked for
2302 - * @return Array of Strings the array of groups allowed to edit this article
 2280+ * @param $action \type{\string} action that permission needs to be checked for
 2281+ * @return \type{\arrayof{\string}} the array of groups allowed to edit this article
23032282 */
23042283 public function getRestrictions( $action ) {
23052284 if ( !$this->mRestrictionsLoaded ) {
@@ -2312,7 +2291,7 @@
23132292 /**
23142293 * Get the expiry time for the restriction against a given action
23152294 *
2316 - * @return String|Bool 14-char timestamp, or 'infinity' if the page is protected forever
 2295+ * @return 14-char timestamp, or 'infinity' if the page is protected forever
23172296 * or not protected at all, or false if the action is not recognised.
23182297 */
23192298 public function getRestrictionExpiry( $action ) {
@@ -2325,7 +2304,7 @@
23262305 /**
23272306 * Is there a version of this page in the deletion archive?
23282307 *
2329 - * @return Int the number of archived revisions
 2308+ * @return \type{\int} the number of archived revisions
23302309 */
23312310 public function isDeleted() {
23322311 if ( $this->getNamespace() < 0 ) {
@@ -2373,16 +2352,16 @@
23742353 * Get the article ID for this Title from the link cache,
23752354 * adding it if necessary
23762355 *
2377 - * @param $flags Int a bit field; may be Title::GAID_FOR_UPDATE to select
 2356+ * @param $flags \type{\int} a bit field; may be GAID_FOR_UPDATE to select
23782357 * for update
2379 - * @return Int the ID
 2358+ * @return \type{\int} the ID
23802359 */
23812360 public function getArticleID( $flags = 0 ) {
23822361 if ( $this->getNamespace() < 0 ) {
23832362 return $this->mArticleID = 0;
23842363 }
23852364 $linkCache = LinkCache::singleton();
2386 - if ( $flags & self::GAID_FOR_UPDATE ) {
 2365+ if ( $flags & GAID_FOR_UPDATE ) {
23872366 $oldUpdate = $linkCache->forUpdate( true );
23882367 $linkCache->clearLink( $this );
23892368 $this->mArticleID = $linkCache->addLinkObj( $this );
@@ -2399,8 +2378,8 @@
24002379 * Is this an article that is a redirect page?
24012380 * Uses link cache, adding it if necessary
24022381 *
2403 - * @param $flags Int a bit field; may be Title::GAID_FOR_UPDATE to select for update
2404 - * @return Bool
 2382+ * @param $flags \type{\int} a bit field; may be GAID_FOR_UPDATE to select for update
 2383+ * @return \type{\bool}
24052384 */
24062385 public function isRedirect( $flags = 0 ) {
24072386 if ( !is_null( $this->mRedirect ) ) {
@@ -2420,8 +2399,8 @@
24212400 * What is the length of this page?
24222401 * Uses link cache, adding it if necessary
24232402 *
2424 - * @param $flags Int a bit field; may be Title::GAID_FOR_UPDATE to select for update
2425 - * @return Int
 2403+ * @param $flags \type{\int} a bit field; may be GAID_FOR_UPDATE to select for update
 2404+ * @return \type{\bool}
24262405 */
24272406 public function getLength( $flags = 0 ) {
24282407 if ( $this->mLength != -1 ) {
@@ -2440,8 +2419,8 @@
24412420 /**
24422421 * What is the page_latest field for this page?
24432422 *
2444 - * @param $flags Int a bit field; may be Title::GAID_FOR_UPDATE to select for update
2445 - * @return Int or 0 if the page doesn't exist
 2423+ * @param $flags \type{\int} a bit field; may be GAID_FOR_UPDATE to select for update
 2424+ * @return \type{\int} or 0 if the page doesn't exist
24462425 */
24472426 public function getLatestRevID( $flags = 0 ) {
24482427 if ( $this->mLatestID !== false ) {
@@ -2461,11 +2440,7 @@
24622441 * This clears some fields in this object, and clears any associated
24632442 * keys in the "bad links" section of the link cache.
24642443 *
2465 - * - This is called from Article::doEdit() and Article::insertOn() to allow
2466 - * loading of the new page_id. It's also called from
2467 - * Article::doDeleteArticle()
2468 - *
2469 - * @param $newid Int the new Article ID
 2444+ * @param $newid \type{\int} the new Article ID
24702445 */
24712446 public function resetArticleID( $newid ) {
24722447 $linkCache = LinkCache::singleton();
@@ -2486,7 +2461,7 @@
24872462 /**
24882463 * Updates page_touched for this page; called from LinksUpdate.php
24892464 *
2490 - * @return Bool true if the update succeded
 2465+ * @return \type{\bool} true if the update succeded
24912466 */
24922467 public function invalidateCache() {
24932468 if ( wfReadOnly() ) {
@@ -2507,16 +2482,15 @@
25082483 * Prefix some arbitrary text with the namespace or interwiki prefix
25092484 * of this object
25102485 *
2511 - * @param $name String the text
2512 - * @return String the prefixed text
 2486+ * @param $name \type{\string} the text
 2487+ * @return \type{\string} the prefixed text
25132488 * @private
25142489 */
2515 - private function prefix( $name ) {
 2490+ /* private */ function prefix( $name ) {
25162491 $p = '';
25172492 if ( $this->mInterwiki != '' ) {
25182493 $p = $this->mInterwiki . ':';
25192494 }
2520 -
25212495 if ( 0 != $this->mNamespace ) {
25222496 $p .= $this->getNsText() . ':';
25232497 }
@@ -2528,7 +2502,7 @@
25292503 * Note that this doesn't pick up many things that could be wrong with titles, but that
25302504 * replacing this regex with something valid will make many titles valid.
25312505 *
2532 - * @return String regex string
 2506+ * @return string regex string
25332507 */
25342508 static function getTitleInvalidRegex() {
25352509 static $rxTc = false;
@@ -2553,7 +2527,7 @@
25542528 /**
25552529 * Capitalize a text string for a title if it belongs to a namespace that capitalizes
25562530 *
2557 - * @param $text String containing title to capitalize
 2531+ * @param $text string containing title to capitalize
25582532 * @param $ns int namespace index, defaults to NS_MAIN
25592533 * @return String containing capitalized title
25602534 */
@@ -2576,12 +2550,14 @@
25772551 * namespace prefixes, sets the other forms, and canonicalizes
25782552 * everything.
25792553 *
2580 - * @return Bool true on success
 2554+ * @return \type{\bool} true on success
25812555 */
25822556 private function secureAndSplit() {
25832557 global $wgContLang, $wgLocalInterwiki;
25842558
25852559 # Initialisation
 2560+ $rxTc = self::getTitleInvalidRegex();
 2561+
25862562 $this->mInterwiki = $this->mFragment = '';
25872563 $this->mNamespace = $this->mDefaultNamespace; # Usually NS_MAIN
25882564
@@ -2596,6 +2572,7 @@
25972573 # Note: use of the /u option on preg_replace here will cause
25982574 # input with invalid UTF-8 sequences to be nullified out in PHP 5.2.x,
25992575 # conveniently disabling them.
 2576+ #
26002577 $dbkey = preg_replace( '/[ _\xA0\x{1680}\x{180E}\x{2000}-\x{200A}\x{2028}\x{2029}\x{202F}\x{205F}\x{3000}]+/u', '_', $dbkey );
26012578 $dbkey = trim( $dbkey, '_' );
26022579
@@ -2632,11 +2609,9 @@
26332610 # For Talk:X pages, check if X has a "namespace" prefix
26342611 if ( $ns == NS_TALK && preg_match( $prefixRegexp, $dbkey, $x ) ) {
26352612 if ( $wgContLang->getNsIndex( $x[1] ) ) {
2636 - # Disallow Talk:File:x type titles...
2637 - return false;
 2613+ return false; # Disallow Talk:File:x type titles...
26382614 } else if ( Interwiki::isValidInterwiki( $x[1] ) ) {
2639 - # Disallow Talk:Interwiki:x type titles...
2640 - return false;
 2615+ return false; # Disallow Talk:Interwiki:x type titles...
26412616 }
26422617 }
26432618 } elseif ( Interwiki::isValidInterwiki( $p ) ) {
@@ -2651,9 +2626,7 @@
26522627 $this->mInterwiki = $wgContLang->lc( $p );
26532628
26542629 # Redundant interwiki prefix to the local wiki
2655 - if ( $wgLocalInterwiki !== false
2656 - && 0 == strcasecmp( $this->mInterwiki, $wgLocalInterwiki ) )
2657 - {
 2630+ if ( 0 == strcasecmp( $this->mInterwiki, $wgLocalInterwiki ) ) {
26582631 if ( $dbkey == '' ) {
26592632 # Can't have an empty self-link
26602633 return false;
@@ -2678,12 +2651,13 @@
26792652 } while ( true );
26802653
26812654 # We already know that some pages won't be in the database!
 2655+ #
26822656 if ( $this->mInterwiki != '' || NS_SPECIAL == $this->mNamespace ) {
26832657 $this->mArticleID = 0;
26842658 }
26852659 $fragment = strstr( $dbkey, '#' );
26862660 if ( false !== $fragment ) {
2687 - $this->setFragment( $fragment );
 2661+ $this->setFragment( preg_replace( '/^#_*/', '#', $fragment ) );
26882662 $dbkey = substr( $dbkey, 0, strlen( $dbkey ) - strlen( $fragment ) );
26892663 # remove whitespace again: prevents "Foo_bar_#"
26902664 # becoming "Foo_bar_"
@@ -2691,65 +2665,79 @@
26922666 }
26932667
26942668 # Reject illegal characters.
2695 - $rxTc = self::getTitleInvalidRegex();
 2669+ #
26962670 if ( preg_match( $rxTc, $dbkey ) ) {
26972671 return false;
26982672 }
26992673
2700 - # Pages with "/./" or "/../" appearing in the URLs will often be un-
2701 - # reachable due to the way web browsers deal with 'relative' URLs.
2702 - # Also, they conflict with subpage syntax. Forbid them explicitly.
 2674+ /**
 2675+ * Pages with "/./" or "/../" appearing in the URLs will often be un-
 2676+ * reachable due to the way web browsers deal with 'relative' URLs.
 2677+ * Also, they conflict with subpage syntax. Forbid them explicitly.
 2678+ */
27032679 if ( strpos( $dbkey, '.' ) !== false &&
2704 - ( $dbkey === '.' || $dbkey === '..' ||
2705 - strpos( $dbkey, './' ) === 0 ||
2706 - strpos( $dbkey, '../' ) === 0 ||
2707 - strpos( $dbkey, '/./' ) !== false ||
2708 - strpos( $dbkey, '/../' ) !== false ||
2709 - substr( $dbkey, -2 ) == '/.' ||
2710 - substr( $dbkey, -3 ) == '/..' ) )
 2680+ ( $dbkey === '.' || $dbkey === '..' ||
 2681+ strpos( $dbkey, './' ) === 0 ||
 2682+ strpos( $dbkey, '../' ) === 0 ||
 2683+ strpos( $dbkey, '/./' ) !== false ||
 2684+ strpos( $dbkey, '/../' ) !== false ||
 2685+ substr( $dbkey, -2 ) == '/.' ||
 2686+ substr( $dbkey, -3 ) == '/..' ) )
27112687 {
27122688 return false;
27132689 }
27142690
2715 - # Magic tilde sequences? Nu-uh!
 2691+ /**
 2692+ * Magic tilde sequences? Nu-uh!
 2693+ */
27162694 if ( strpos( $dbkey, '~~~' ) !== false ) {
27172695 return false;
27182696 }
27192697
2720 - # Limit the size of titles to 255 bytes. This is typically the size of the
2721 - # underlying database field. We make an exception for special pages, which
2722 - # don't need to be stored in the database, and may edge over 255 bytes due
2723 - # to subpage syntax for long titles, e.g. [[Special:Block/Long name]]
 2698+ /**
 2699+ * Limit the size of titles to 255 bytes.
 2700+ * This is typically the size of the underlying database field.
 2701+ * We make an exception for special pages, which don't need to be stored
 2702+ * in the database, and may edge over 255 bytes due to subpage syntax
 2703+ * for long titles, e.g. [[Special:Block/Long name]]
 2704+ */
27242705 if ( ( $this->mNamespace != NS_SPECIAL && strlen( $dbkey ) > 255 ) ||
27252706 strlen( $dbkey ) > 512 )
27262707 {
27272708 return false;
27282709 }
27292710
2730 - # Normally, all wiki links are forced to have an initial capital letter so [[foo]]
2731 - # and [[Foo]] point to the same place. Don't force it for interwikis, since the
2732 - # other site might be case-sensitive.
 2711+ /**
 2712+ * Normally, all wiki links are forced to have
 2713+ * an initial capital letter so [[foo]] and [[Foo]]
 2714+ * point to the same place.
 2715+ *
 2716+ * Don't force it for interwikis, since the other
 2717+ * site might be case-sensitive.
 2718+ */
27332719 $this->mUserCaseDBKey = $dbkey;
27342720 if ( $this->mInterwiki == '' ) {
27352721 $dbkey = self::capitalize( $dbkey, $this->mNamespace );
27362722 }
27372723
2738 - # Can't make a link to a namespace alone... "empty" local links can only be
2739 - # self-links with a fragment identifier.
2740 - if ( $dbkey == '' && $this->mInterwiki == '' && $this->mNamespace != NS_MAIN ) {
 2724+ /**
 2725+ * Can't make a link to a namespace alone...
 2726+ * "empty" local links can only be self-links
 2727+ * with a fragment identifier.
 2728+ */
 2729+ if ( $dbkey == '' &&
 2730+ $this->mInterwiki == '' &&
 2731+ $this->mNamespace != NS_MAIN ) {
27412732 return false;
27422733 }
2743 -
27442734 // Allow IPv6 usernames to start with '::' by canonicalizing IPv6 titles.
27452735 // IP names are not allowed for accounts, and can only be referring to
27462736 // edits from the IP. Given '::' abbreviations and caps/lowercaps,
27472737 // there are numerous ways to present the same IP. Having sp:contribs scan
27482738 // them all is silly and having some show the edits and others not is
27492739 // inconsistent. Same for talk/userpages. Keep them normalized instead.
2750 - $dbkey = ( $this->mNamespace == NS_USER || $this->mNamespace == NS_USER_TALK )
2751 - ? IP::sanitizeIP( $dbkey )
2752 - : $dbkey;
2753 -
 2740+ $dbkey = ( $this->mNamespace == NS_USER || $this->mNamespace == NS_USER_TALK ) ?
 2741+ IP::sanitizeIP( $dbkey ) : $dbkey;
27542742 // Any remaining initial :s are illegal.
27552743 if ( $dbkey !== '' && ':' == $dbkey { 0 } ) {
27562744 return false;
@@ -2772,7 +2760,7 @@
27732761 * Deprecated for public use, use Title::makeTitle() with fragment parameter.
27742762 * Still in active use privately.
27752763 *
2776 - * @param $fragment String text
 2764+ * @param $fragment \type{\string} text
27772765 */
27782766 public function setFragment( $fragment ) {
27792767 $this->mFragment = str_replace( '_', ' ', substr( $fragment, 1 ) );
@@ -2785,7 +2773,7 @@
27862774 /**
27872775 * Get a Title object associated with the talk page of this article
27882776 *
2789 - * @return Title the object for the talk page
 2777+ * @return \type{Title} the object for the talk page
27902778 */
27912779 public function getTalkPage() {
27922780 return Title::makeTitle( MWNamespace::getTalk( $this->getNamespace() ), $this->getDBkey() );
@@ -2795,7 +2783,7 @@
27962784 * Get a title object associated with the subject page of this
27972785 * talk page
27982786 *
2799 - * @return Title the object for the subject page
 2787+ * @return \type{Title} the object for the subject page
28002788 */
28012789 public function getSubjectPage() {
28022790 // Is this the same title?
@@ -2816,7 +2804,7 @@
28172805 * @param $options Array: may be FOR UPDATE
28182806 * @param $table String: table name
28192807 * @param $prefix String: fields prefix
2820 - * @return Array of Title objects linking here
 2808+ * @return \type{\arrayof{Title}} the Title objects linking here
28212809 */
28222810 public function getLinksTo( $options = array(), $table = 'pagelinks', $prefix = 'pl' ) {
28232811 $linkCache = LinkCache::singleton();
@@ -2841,13 +2829,13 @@
28422830 $retVal = array();
28432831 if ( $db->numRows( $res ) ) {
28442832 foreach ( $res as $row ) {
2845 - $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title );
2846 - if ( $titleObj ) {
 2833+ if ( $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title ) ) {
28472834 $linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redirect, $row->page_latest );
28482835 $retVal[] = $titleObj;
28492836 }
28502837 }
28512838 }
 2839+ $db->freeResult( $res );
28522840 return $retVal;
28532841 }
28542842
@@ -2859,7 +2847,7 @@
28602848 * On heavily-used templates it will max out the memory.
28612849 *
28622850 * @param $options Array: may be FOR UPDATE
2863 - * @return Array of Title the Title objects linking here
 2851+ * @return \type{\arrayof{Title}} the Title objects linking here
28642852 */
28652853 public function getTemplateLinksTo( $options = array() ) {
28662854 return $this->getLinksTo( $options, 'templatelinks', 'tl' );
@@ -2869,7 +2857,7 @@
28702858 * Get an array of Title objects referring to non-existent articles linked from this page
28712859 *
28722860 * @todo check if needed (used only in SpecialBrokenRedirects.php, and should use redirect table in this case)
2873 - * @return Array of Title the Title objects
 2861+ * @return \type{\arrayof{Title}} the Title objects
28742862 */
28752863 public function getBrokenLinksFrom() {
28762864 if ( $this->getArticleId() == 0 ) {
@@ -2906,7 +2894,7 @@
29072895 * Get a list of URLs to purge from the Squid cache when this
29082896 * page changes
29092897 *
2910 - * @return Array of String the URLs
 2898+ * @return \type{\arrayof{\string}} the URLs
29112899 */
29122900 public function getSquidURLs() {
29132901 global $wgContLang;
@@ -2942,8 +2930,8 @@
29432931 /**
29442932 * Move this page without authentication
29452933 *
2946 - * @param $nt Title the new page Title
2947 - * @return Mixed true on success, getUserPermissionsErrors()-like array on failure
 2934+ * @param $nt \type{Title} the new page Title
 2935+ * @return \type{\mixed} true on success, getUserPermissionsErrors()-like array on failure
29482936 */
29492937 public function moveNoAuth( &$nt ) {
29502938 return $this->moveTo( $nt, false );
@@ -2953,11 +2941,11 @@
29542942 * Check whether a given move operation would be valid.
29552943 * Returns true if ok, or a getUserPermissionsErrors()-like array otherwise
29562944 *
2957 - * @param $nt Title the new title
2958 - * @param $auth Bool indicates whether $wgUser's permissions
 2945+ * @param $nt \type{Title} the new title
 2946+ * @param $auth \type{\bool} indicates whether $wgUser's permissions
29592947 * should be checked
2960 - * @param $reason String is the log summary of the move, used for spam checking
2961 - * @return Mixed True on success, getUserPermissionsErrors()-like array on failure
 2948+ * @param $reason \type{\string} is the log summary of the move, used for spam checking
 2949+ * @return \type{\mixed} True on success, getUserPermissionsErrors()-like array on failure
29622950 */
29632951 public function isValidMoveOperation( &$nt, $auth = true, $reason = '' ) {
29642952 global $wgUser;
@@ -2989,13 +2977,28 @@
29902978 }
29912979 if ( ( $this->getDBkey() == '' ) ||
29922980 ( !$oldid ) ||
2993 - ( $nt->getDBkey() == '' ) ) {
 2981+ ( $nt->getDBkey() == '' ) ) {
29942982 $errors[] = array( 'badarticleerror' );
29952983 }
29962984
29972985 // Image-specific checks
29982986 if ( $this->getNamespace() == NS_FILE ) {
2999 - $errors = array_merge( $errors, $this->validateFileMoveOperation( $nt ) );
 2987+ if ( $nt->getNamespace() != NS_FILE ) {
 2988+ $errors[] = array( 'imagenocrossnamespace' );
 2989+ }
 2990+ $file = wfLocalFile( $this );
 2991+ if ( $file->exists() ) {
 2992+ if ( $nt->getText() != wfStripIllegalFilenameChars( $nt->getText() ) ) {
 2993+ $errors[] = array( 'imageinvalidfilename' );
 2994+ }
 2995+ if ( !File::checkExtensionCompatibility( $file, $nt->getDBkey() ) ) {
 2996+ $errors[] = array( 'imagetypemismatch' );
 2997+ }
 2998+ }
 2999+ $destfile = wfLocalFile( $nt );
 3000+ if ( !$wgUser->isAllowed( 'reupload-shared' ) && !$destfile->exists() && wfFindFile( $nt ) ) {
 3001+ $errors[] = array( 'file-exists-sharedrepo' );
 3002+ }
30003003 }
30013004
30023005 if ( $nt->getNamespace() == NS_FILE && $this->getNamespace() != NS_FILE ) {
@@ -3043,56 +3046,25 @@
30443047 }
30453048
30463049 /**
3047 - * Check if the requested move target is a valid file move target
3048 - * @param Title $nt Target title
3049 - * @return array List of errors
3050 - */
3051 - protected function validateFileMoveOperation( $nt ) {
3052 - global $wgUser;
3053 -
3054 - $errors = array();
3055 -
3056 - if ( $nt->getNamespace() != NS_FILE ) {
3057 - $errors[] = array( 'imagenocrossnamespace' );
3058 - }
3059 -
3060 - $file = wfLocalFile( $this );
3061 - if ( $file->exists() ) {
3062 - if ( $nt->getText() != wfStripIllegalFilenameChars( $nt->getText() ) ) {
3063 - $errors[] = array( 'imageinvalidfilename' );
3064 - }
3065 - if ( !File::checkExtensionCompatibility( $file, $nt->getDBkey() ) ) {
3066 - $errors[] = array( 'imagetypemismatch' );
3067 - }
3068 - }
3069 -
3070 - $destFile = wfLocalFile( $nt );
3071 - if ( !$wgUser->isAllowed( 'reupload-shared' ) && !$destFile->exists() && wfFindFile( $nt ) ) {
3072 - $errors[] = array( 'file-exists-sharedrepo' );
3073 - }
3074 -
3075 - return $errors;
3076 - }
3077 -
3078 - /**
30793050 * Move a title to a new location
30803051 *
3081 - * @param $nt Title the new title
3082 - * @param $auth Bool indicates whether $wgUser's permissions
 3052+ * @param $nt \type{Title} the new title
 3053+ * @param $auth \type{\bool} indicates whether $wgUser's permissions
30833054 * should be checked
3084 - * @param $reason String the reason for the move
3085 - * @param $createRedirect Bool Whether to create a redirect from the old title to the new title.
 3055+ * @param $reason \type{\string} The reason for the move
 3056+ * @param $createRedirect \type{\bool} Whether to create a redirect from the old title to the new title.
30863057 * Ignored if the user doesn't have the suppressredirect right.
3087 - * @return Mixed true on success, getUserPermissionsErrors()-like array on failure
 3058+ * @return \type{\mixed} true on success, getUserPermissionsErrors()-like array on failure
30883059 */
30893060 public function moveTo( &$nt, $auth = true, $reason = '', $createRedirect = true ) {
 3061+ global $wgContLang, $wgEnableInterwikiTemplatesTracking, $wgGlobalDatabase;
 3062+
30903063 $err = $this->isValidMoveOperation( $nt, $auth, $reason );
30913064 if ( is_array( $err ) ) {
30923065 return $err;
30933066 }
30943067
3095 - // If it is a file, move it first. It is done before all other moving stuff is
3096 - // done because it's hard to revert
 3068+ // If it is a file, move it first. It is done before all other moving stuff is done because it's hard to revert
30973069 $dbw = wfGetDB( DB_MASTER );
30983070 if ( $this->getNamespace() == NS_FILE ) {
30993071 $file = wfLocalFile( $this );
@@ -3104,42 +3076,43 @@
31053077 }
31063078 }
31073079
3108 - $dbw->begin(); # If $file was a LocalFile, its transaction would have closed our own.
3109 - $pageid = $this->getArticleID( GAID_FOR_UPDATE );
 3080+ $pageid = $this->getArticleID();
31103081 $protected = $this->isProtected();
3111 - $pageCountChange = ( $createRedirect ? 1 : 0 ) - ( $nt->exists() ? 1 : 0 );
 3082+ if ( $nt->exists() ) {
 3083+ $err = $this->moveOverExistingRedirect( $nt, $reason, $createRedirect );
 3084+ $pageCountChange = ( $createRedirect ? 0 : -1 );
 3085+ } else { # Target didn't exist, do normal move.
 3086+ $err = $this->moveToNewTitle( $nt, $reason, $createRedirect );
 3087+ $pageCountChange = ( $createRedirect ? 1 : 0 );
 3088+ }
31123089
3113 - // Do the actual move
3114 - $err = $this->moveToInternal( $nt, $reason, $createRedirect );
31153090 if ( is_array( $err ) ) {
3116 - # FIXME: What about the File we have already moved?
3117 - $dbw->rollback();
31183091 return $err;
31193092 }
3120 -
31213093 $redirid = $this->getArticleID();
31223094
31233095 // Refresh the sortkey for this row. Be careful to avoid resetting
31243096 // cl_timestamp, which may disturb time-based lists on some sites.
3125 - $prefixes = $dbw->select(
 3097+ $prefix = $dbw->selectField(
31263098 'categorylinks',
3127 - array( 'cl_sortkey_prefix', 'cl_to' ),
 3099+ 'cl_sortkey_prefix',
31283100 array( 'cl_from' => $pageid ),
31293101 __METHOD__
31303102 );
3131 - foreach ( $prefixes as $prefixRow ) {
3132 - $prefix = $prefixRow->cl_sortkey_prefix;
3133 - $catTo = $prefixRow->cl_to;
3134 - $dbw->update( 'categorylinks',
3135 - array(
3136 - 'cl_sortkey' => Collation::singleton()->getSortKey(
3137 - $nt->getCategorySortkey( $prefix ) ),
3138 - 'cl_timestamp=cl_timestamp' ),
3139 - array(
3140 - 'cl_from' => $pageid,
3141 - 'cl_to' => $catTo ),
3142 - __METHOD__
3143 - );
 3103+ $dbw->update( 'categorylinks',
 3104+ array(
 3105+ 'cl_sortkey' => $wgContLang->convertToSortkey( $nt->getCategorySortkey( $prefix ) ),
 3106+ 'cl_timestamp=cl_timestamp' ),
 3107+ array( 'cl_from' => $pageid ),
 3108+ __METHOD__ );
 3109+
 3110+ if ( $wgEnableInterwikiTemplatesTracking && $wgGlobalDatabase ) {
 3111+ $dbw2 = wfGetDB( DB_MASTER, array(), $wgGlobalDatabase );
 3112+ $dbw2->update( 'globaltemplatelinks',
 3113+ array( 'gtl_from_namespace' => $nt->getNsText(),
 3114+ 'gtl_from_title' => $nt->getText() ),
 3115+ array ( 'gtl_from_page' => $pageid ),
 3116+ __METHOD__ );
31443117 }
31453118
31463119 if ( $protected ) {
@@ -3182,8 +3155,6 @@
31833156 $u = new SearchUpdate( $redirid, $this->getPrefixedDBkey(), '' );
31843157 $u->doUpdate();
31853158
3186 - $dbw->commit();
3187 -
31883159 # Update site_stats
31893160 if ( $this->isContentPage() && !$nt->isContentPage() ) {
31903161 # No longer a content page
@@ -3204,19 +3175,20 @@
32053176 $u->doUpdate();
32063177 }
32073178 # Update message cache for interface messages
3208 - if ( $this->getNamespace() == NS_MEDIAWIKI ) {
 3179+ if ( $nt->getNamespace() == NS_MEDIAWIKI ) {
 3180+ global $wgMessageCache;
 3181+
32093182 # @bug 17860: old article can be deleted, if this the case,
32103183 # delete it from message cache
32113184 if ( $this->getArticleID() === 0 ) {
3212 - MessageCache::singleton()->replace( $this->getDBkey(), false );
 3185+ $wgMessageCache->replace( $this->getDBkey(), false );
32133186 } else {
32143187 $oldarticle = new Article( $this );
3215 - MessageCache::singleton()->replace( $this->getDBkey(), $oldarticle->getContent() );
 3188+ $wgMessageCache->replace( $this->getDBkey(), $oldarticle->getContent() );
32163189 }
3217 - }
3218 - if ( $nt->getNamespace() == NS_MEDIAWIKI ) {
 3190+
32193191 $newarticle = new Article( $nt );
3220 - MessageCache::singleton()->replace( $nt->getDBkey(), $newarticle->getContent() );
 3192+ $wgMessageCache->replace( $nt->getDBkey(), $newarticle->getContent() );
32213193 }
32223194
32233195 global $wgUser;
@@ -3225,74 +3197,72 @@
32263198 }
32273199
32283200 /**
3229 - * Move page to a title which is either a redirect to the
3230 - * source page or nonexistent
 3201+ * Move page to a title which is at present a redirect to the
 3202+ * source page
32313203 *
3232 - * @param $nt Title the page to move to, which should be a redirect or nonexistent
3233 - * @param $reason String The reason for the move
3234 - * @param $createRedirect Bool Whether to leave a redirect at the old title. Ignored
3235 - * if the user doesn't have the suppressredirect right
 3204+ * @param $nt \type{Title} the page to move to, which should currently
 3205+ * be a redirect
 3206+ * @param $reason \type{\string} The reason for the move
 3207+ * @param $createRedirect \type{\bool} Whether to leave a redirect at the old title.
 3208+ * Ignored if the user doesn't have the suppressredirect right
32363209 */
3237 - private function moveToInternal( &$nt, $reason = '', $createRedirect = true ) {
3238 - global $wgUser, $wgContLang;
 3210+ private function moveOverExistingRedirect( &$nt, $reason = '', $createRedirect = true ) {
 3211+ global $wgUseSquid, $wgUser, $wgContLang, $wgEnableInterwikiTemplatesTracking, $wgGlobalDatabase;
32393212
3240 - $moveOverRedirect = $nt->exists();
 3213+ $comment = wfMsgForContent( '1movedto2_redir', $this->getPrefixedText(), $nt->getPrefixedText() );
32413214
3242 - $commentMsg = ( $moveOverRedirect ? '1movedto2_redir' : '1movedto2' );
3243 - $comment = wfMsgForContent( $commentMsg, $this->getPrefixedText(), $nt->getPrefixedText() );
3244 -
32453215 if ( $reason ) {
32463216 $comment .= wfMsgForContent( 'colon-separator' ) . $reason;
32473217 }
3248 - # Truncate for whole multibyte characters.
3249 - $comment = $wgContLang->truncate( $comment, 255 );
 3218+ # Truncate for whole multibyte characters. +5 bytes for ellipsis
 3219+ $comment = $wgContLang->truncate( $comment, 250 );
32503220
 3221+ $now = wfTimestampNow();
 3222+ $newid = $nt->getArticleID();
32513223 $oldid = $this->getArticleID();
32523224 $latest = $this->getLatestRevID();
32533225
3254 - $oldns = $this->getNamespace();
3255 - $olddbk = $this->getDBkey();
3256 -
32573226 $dbw = wfGetDB( DB_MASTER );
32583227
3259 - if ( $moveOverRedirect ) {
3260 - $rcts = $dbw->timestamp( $nt->getEarliestRevTime() );
 3228+ $rcts = $dbw->timestamp( $nt->getEarliestRevTime() );
 3229+ $newns = $nt->getNamespace();
 3230+ $newdbk = $nt->getDBkey();
32613231
3262 - $newid = $nt->getArticleID();
3263 - $newns = $nt->getNamespace();
3264 - $newdbk = $nt->getDBkey();
3265 -
3266 - # Delete the old redirect. We don't save it to history since
3267 - # by definition if we've got here it's rather uninteresting.
3268 - # We have to remove it so that the next step doesn't trigger
3269 - # a conflict on the unique namespace+title index...
3270 - $dbw->delete( 'page', array( 'page_id' => $newid ), __METHOD__ );
3271 - if ( !$dbw->cascadingDeletes() ) {
3272 - $dbw->delete( 'revision', array( 'rev_page' => $newid ), __METHOD__ );
3273 - global $wgUseTrackbacks;
3274 - if ( $wgUseTrackbacks ) {
3275 - $dbw->delete( 'trackbacks', array( 'tb_page' => $newid ), __METHOD__ );
3276 - }
3277 - $dbw->delete( 'pagelinks', array( 'pl_from' => $newid ), __METHOD__ );
3278 - $dbw->delete( 'imagelinks', array( 'il_from' => $newid ), __METHOD__ );
3279 - $dbw->delete( 'categorylinks', array( 'cl_from' => $newid ), __METHOD__ );
3280 - $dbw->delete( 'templatelinks', array( 'tl_from' => $newid ), __METHOD__ );
3281 - $dbw->delete( 'externallinks', array( 'el_from' => $newid ), __METHOD__ );
3282 - $dbw->delete( 'langlinks', array( 'll_from' => $newid ), __METHOD__ );
3283 - $dbw->delete( 'redirect', array( 'rd_from' => $newid ), __METHOD__ );
 3232+ # Delete the old redirect. We don't save it to history since
 3233+ # by definition if we've got here it's rather uninteresting.
 3234+ # We have to remove it so that the next step doesn't trigger
 3235+ # a conflict on the unique namespace+title index...
 3236+ $dbw->delete( 'page', array( 'page_id' => $newid ), __METHOD__ );
 3237+ if ( !$dbw->cascadingDeletes() ) {
 3238+ $dbw->delete( 'revision', array( 'rev_page' => $newid ), __METHOD__ );
 3239+ global $wgUseTrackbacks;
 3240+ if ( $wgUseTrackbacks ) {
 3241+ $dbw->delete( 'trackbacks', array( 'tb_page' => $newid ), __METHOD__ );
32843242 }
3285 - // If the target page was recently created, it may have an entry in recentchanges still
3286 - $dbw->delete( 'recentchanges',
3287 - array( 'rc_timestamp' => $rcts, 'rc_namespace' => $newns, 'rc_title' => $newdbk, 'rc_new' => 1 ),
3288 - __METHOD__
3289 - );
 3243+ $dbw->delete( 'pagelinks', array( 'pl_from' => $newid ), __METHOD__ );
 3244+ $dbw->delete( 'imagelinks', array( 'il_from' => $newid ), __METHOD__ );
 3245+ $dbw->delete( 'categorylinks', array( 'cl_from' => $newid ), __METHOD__ );
 3246+ $dbw->delete( 'templatelinks', array( 'tl_from' => $newid ), __METHOD__ );
 3247+ $dbw->delete( 'externallinks', array( 'el_from' => $newid ), __METHOD__ );
 3248+ $dbw->delete( 'langlinks', array( 'll_from' => $newid ), __METHOD__ );
 3249+ $dbw->delete( 'redirect', array( 'rd_from' => $newid ), __METHOD__ );
 3250+
 3251+ if ( $wgEnableInterwikiTemplatesTracking && $wgGlobalDatabase ) {
 3252+ $dbw2 = wfGetDB( DB_MASTER, array(), $wgGlobalDatabase );
 3253+ $dbw2->delete( 'globaltemplatelinks',
 3254+ array( 'gtl_from_wiki' => wfWikiID( ),
 3255+ 'gtl_from_page' => $newid ),
 3256+ __METHOD__ );
 3257+ }
32903258 }
 3259+ // If the redirect was recently created, it may have an entry in recentchanges still
 3260+ $dbw->delete( 'recentchanges',
 3261+ array( 'rc_timestamp' => $rcts, 'rc_namespace' => $newns, 'rc_title' => $newdbk, 'rc_new' => 1 ),
 3262+ __METHOD__
 3263+ );
32913264
32923265 # Save a null revision in the page's history notifying of the move
32933266 $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true );
3294 - if ( !is_object( $nullRevision ) ) {
3295 - throw new MWException( 'No valid null revision produced in ' . __METHOD__ );
3296 - }
32973267 $nullRevId = $nullRevision->insertOn( $dbw );
32983268
32993269 $article = new Article( $this );
@@ -3301,7 +3271,7 @@
33023272 # Change the name of the target page:
33033273 $dbw->update( 'page',
33043274 /* SET */ array(
3305 - 'page_touched' => $dbw->timestamp(),
 3275+ 'page_touched' => $dbw->timestamp( $now ),
33063276 'page_namespace' => $nt->getNamespace(),
33073277 'page_title' => $nt->getDBkey(),
33083278 'page_latest' => $nullRevId,
@@ -3337,34 +3307,110 @@
33383308 __METHOD__ );
33393309 $redirectSuppressed = false;
33403310 } else {
3341 - // Get rid of old new page entries in Special:NewPages and RC.
3342 - // Needs to be before $this->resetArticleID( 0 ).
3343 - $dbw->delete( 'recentchanges', array(
3344 - 'rc_timestamp' => $dbw->timestamp( $this->getEarliestRevTime() ),
3345 - 'rc_namespace' => $oldns,
3346 - 'rc_title' => $olddbk,
3347 - 'rc_new' => 1
3348 - ),
3349 - __METHOD__
3350 - );
3351 -
33523311 $this->resetArticleID( 0 );
33533312 $redirectSuppressed = true;
33543313 }
33553314
33563315 # Log the move
33573316 $log = new LogPage( 'move' );
3358 - $logType = ( $moveOverRedirect ? 'move_redir' : 'move' );
3359 - $log->addEntry( $logType, $this, $reason, array( 1 => $nt->getPrefixedText(), 2 => $redirectSuppressed ) );
 3317+ $log->addEntry( 'move_redir', $this, $reason, array( 1 => $nt->getPrefixedText(), 2 => $redirectSuppressed ) );
33603318
3361 - # Purge caches for old and new titles
3362 - if ( $moveOverRedirect ) {
3363 - # A simple purge is enough when moving over a redirect
3364 - $nt->purgeSquid();
 3319+ # Purge squid
 3320+ if ( $wgUseSquid ) {
 3321+ $urls = array_merge( $nt->getSquidURLs(), $this->getSquidURLs() );
 3322+ $u = new SquidUpdate( $urls );
 3323+ $u->doUpdate();
 3324+ }
 3325+
 3326+ }
 3327+
 3328+ /**
 3329+ * Move page to non-existing title.
 3330+ *
 3331+ * @param $nt \type{Title} the new Title
 3332+ * @param $reason \type{\string} The reason for the move
 3333+ * @param $createRedirect \type{\bool} Whether to create a redirect from the old title to the new title
 3334+ * Ignored if the user doesn't have the suppressredirect right
 3335+ */
 3336+ private function moveToNewTitle( &$nt, $reason = '', $createRedirect = true ) {
 3337+ global $wgUser, $wgContLang;
 3338+
 3339+ $comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
 3340+ if ( $reason ) {
 3341+ $comment .= wfMsgExt( 'colon-separator',
 3342+ array( 'escapenoentities', 'content' ) );
 3343+ $comment .= $reason;
 3344+ }
 3345+ # Truncate for whole multibyte characters. +5 bytes for ellipsis
 3346+ $comment = $wgContLang->truncate( $comment, 250 );
 3347+
 3348+ $newid = $nt->getArticleID();
 3349+ $oldid = $this->getArticleID();
 3350+ $latest = $this->getLatestRevId();
 3351+
 3352+ $dbw = wfGetDB( DB_MASTER );
 3353+ $now = $dbw->timestamp();
 3354+
 3355+ # Save a null revision in the page's history notifying of the move
 3356+ $nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true );
 3357+ if ( !is_object( $nullRevision ) ) {
 3358+ throw new MWException( 'No valid null revision produced in ' . __METHOD__ );
 3359+ }
 3360+ $nullRevId = $nullRevision->insertOn( $dbw );
 3361+
 3362+ $article = new Article( $this );
 3363+ wfRunHooks( 'NewRevisionFromEditComplete', array( $article, $nullRevision, $latest, $wgUser ) );
 3364+
 3365+ # Rename page entry
 3366+ $dbw->update( 'page',
 3367+ /* SET */ array(
 3368+ 'page_touched' => $now,
 3369+ 'page_namespace' => $nt->getNamespace(),
 3370+ 'page_title' => $nt->getDBkey(),
 3371+ 'page_latest' => $nullRevId,
 3372+ ),
 3373+ /* WHERE */ array( 'page_id' => $oldid ),
 3374+ __METHOD__
 3375+ );
 3376+ $nt->resetArticleID( $oldid );
 3377+
 3378+ if ( $createRedirect || !$wgUser->isAllowed( 'suppressredirect' ) ) {
 3379+ # Insert redirect
 3380+ $mwRedir = MagicWord::get( 'redirect' );
 3381+ $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
 3382+ $redirectArticle = new Article( $this );
 3383+ $newid = $redirectArticle->insertOn( $dbw );
 3384+ $redirectRevision = new Revision( array(
 3385+ 'page' => $newid,
 3386+ 'comment' => $comment,
 3387+ 'text' => $redirectText ) );
 3388+ $redirectRevision->insertOn( $dbw );
 3389+ $redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
 3390+
 3391+ wfRunHooks( 'NewRevisionFromEditComplete', array( $redirectArticle, $redirectRevision, false, $wgUser ) );
 3392+
 3393+ # Record the just-created redirect's linking to the page
 3394+ $dbw->insert( 'pagelinks',
 3395+ array(
 3396+ 'pl_from' => $newid,
 3397+ 'pl_namespace' => $nt->getNamespace(),
 3398+ 'pl_title' => $nt->getDBkey() ),
 3399+ __METHOD__ );
 3400+ $redirectSuppressed = false;
33653401 } else {
3366 - # Purge caches as per article creation, including any pages that link to this title
3367 - Article::onArticleCreate( $nt );
 3402+ $this->resetArticleID( 0 );
 3403+ $redirectSuppressed = true;
33683404 }
 3405+
 3406+ # Log the move
 3407+ $log = new LogPage( 'move' );
 3408+ $log->addEntry( 'move', $this, $reason, array( 1 => $nt->getPrefixedText(), 2 => $redirectSuppressed ) );
 3409+
 3410+ # Purge caches as per article creation
 3411+ Article::onArticleCreate( $nt );
 3412+
 3413+ # Purge old title from squid
 3414+ # The new title, and links to the new title, are purged in Article::onArticleCreate()
33693415 $this->purgeSquid();
33703416 }
33713417
@@ -3374,11 +3420,10 @@
33753421 * @param $nt Title Move target
33763422 * @param $auth bool Whether $wgUser's permissions should be checked
33773423 * @param $reason string The reason for the move
3378 - * @param $createRedirect bool Whether to create redirects from the old subpages to
3379 - * the new ones Ignored if the user doesn't have the 'suppressredirect' right
 3424+ * @param $createRedirect bool Whether to create redirects from the old subpages to the new ones
 3425+ * Ignored if the user doesn't have the 'suppressredirect' right
33803426 * @return mixed array with old page titles as keys, and strings (new page titles) or
3381 - * arrays (errors) as values, or an error array with numeric indices if no pages
3382 - * were moved
 3427+ * arrays (errors) as values, or an error array with numeric indices if no pages were moved
33833428 */
33843429 public function moveSubpages( $nt, $auth = true, $reason = '', $createRedirect = true ) {
33853430 global $wgMaximumMovedPages;
@@ -3445,7 +3490,7 @@
34463491 * Checks if this page is just a one-rev redirect.
34473492 * Adds lock, so don't use just for light purposes.
34483493 *
3449 - * @return Bool
 3494+ * @return \type{\bool}
34503495 */
34513496 public function isSingleRevRedirect() {
34523497 $dbw = wfGetDB( DB_MASTER );
@@ -3482,8 +3527,8 @@
34833528 * Checks if $this can be moved to a given Title
34843529 * - Selects for update, so don't call it unless you mean business
34853530 *
3486 - * @param $nt Title the new title to check
3487 - * @return Bool
 3531+ * @param $nt \type{Title} the new title to check
 3532+ * @return \type{\bool} TRUE or FALSE
34883533 */
34893534 public function isValidMoveTarget( $nt ) {
34903535 # Is it an existing file?
@@ -3524,7 +3569,7 @@
35253570 /**
35263571 * Can this title be added to a user's watchlist?
35273572 *
3528 - * @return Bool TRUE or FALSE
 3573+ * @return \type{\bool} TRUE or FALSE
35293574 */
35303575 public function isWatchable() {
35313576 return !$this->isExternal() && MWNamespace::isWatchable( $this->getNamespace() );
@@ -3534,35 +3579,31 @@
35353580 * Get categories to which this Title belongs and return an array of
35363581 * categories' names.
35373582 *
3538 - * @return Array of parents in the form:
3539 - * $parent => $currentarticle
 3583+ * @return \type{\array} array an array of parents in the form:
 3584+ * $parent => $currentarticle
35403585 */
35413586 public function getParentCategories() {
35423587 global $wgContLang;
35433588
3544 - $data = array();
3545 -
3546 - $titleKey = $this->getArticleId();
3547 -
3548 - if ( $titleKey === 0 ) {
3549 - return $data;
3550 - }
3551 -
 3589+ $titlekey = $this->getArticleId();
35523590 $dbr = wfGetDB( DB_SLAVE );
 3591+ $categorylinks = $dbr->tableName( 'categorylinks' );
35533592
3554 - $res = $dbr->select( 'categorylinks', '*',
3555 - array(
3556 - 'cl_from' => $titleKey,
3557 - ),
3558 - __METHOD__,
3559 - array()
3560 - );
 3593+ # NEW SQL
 3594+ $sql = "SELECT * FROM $categorylinks"
 3595+ . " WHERE cl_from='$titlekey'"
 3596+ . " AND cl_from <> '0'"
 3597+ . " ORDER BY cl_sortkey";
35613598
 3599+ $res = $dbr->query( $sql );
 3600+
35623601 if ( $dbr->numRows( $res ) > 0 ) {
3563 - foreach ( $res as $row ) {
 3602+ foreach ( $res as $row )
35643603 // $data[] = Title::newFromText($wgContLang->getNSText ( NS_CATEGORY ).':'.$row->cl_to);
35653604 $data[$wgContLang->getNSText( NS_CATEGORY ) . ':' . $row->cl_to] = $this->getFullText();
3566 - }
 3605+ $dbr->freeResult( $res );
 3606+ } else {
 3607+ $data = array();
35673608 }
35683609 return $data;
35693610 }
@@ -3570,8 +3611,8 @@
35713612 /**
35723613 * Get a tree of parent categories
35733614 *
3574 - * @param $children Array with the children in the keys, to check for circular refs
3575 - * @return Array Tree of parent categories
 3615+ * @param $children \type{\array} an array with the children in the keys, to check for circular refs
 3616+ * @return \type{\array} Tree of parent categories
35763617 */
35773618 public function getParentCategoryTree( $children = array() ) {
35783619 $stack = array();
@@ -3589,16 +3630,18 @@
35903631 }
35913632 }
35923633 }
 3634+ return $stack;
 3635+ } else {
 3636+ return array();
35933637 }
3594 -
3595 - return $stack;
35963638 }
35973639
 3640+
35983641 /**
35993642 * Get an associative array for selecting this title from
36003643 * the "page" table
36013644 *
3602 - * @return Array suitable for the $where parameter of DB::select()
 3645+ * @return \type{\array} Selection array
36033646 */
36043647 public function pageCond() {
36053648 if ( $this->mArticleID > 0 ) {
@@ -3612,12 +3655,12 @@
36133656 /**
36143657 * Get the revision ID of the previous revision
36153658 *
3616 - * @param $revId Int Revision ID. Get the revision that was before this one.
3617 - * @param $flags Int Title::GAID_FOR_UPDATE
3618 - * @return Int|Bool Old revision ID, or FALSE if none exists
 3659+ * @param $revId \type{\int} Revision ID. Get the revision that was before this one.
 3660+ * @param $flags \type{\int} GAID_FOR_UPDATE
 3661+ * @return \twotypes{\int,\bool} Old revision ID, or FALSE if none exists
36193662 */
36203663 public function getPreviousRevisionID( $revId, $flags = 0 ) {
3621 - $db = ( $flags & self::GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
 3664+ $db = ( $flags & GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
36223665 return $db->selectField( 'revision', 'rev_id',
36233666 array(
36243667 'rev_page' => $this->getArticleId( $flags ),
@@ -3631,12 +3674,12 @@
36323675 /**
36333676 * Get the revision ID of the next revision
36343677 *
3635 - * @param $revId Int Revision ID. Get the revision that was after this one.
3636 - * @param $flags Int Title::GAID_FOR_UPDATE
3637 - * @return Int|Bool Next revision ID, or FALSE if none exists
 3678+ * @param $revId \type{\int} Revision ID. Get the revision that was after this one.
 3679+ * @param $flags \type{\int} GAID_FOR_UPDATE
 3680+ * @return \twotypes{\int,\bool} Next revision ID, or FALSE if none exists
36383681 */
36393682 public function getNextRevisionID( $revId, $flags = 0 ) {
3640 - $db = ( $flags & self::GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
 3683+ $db = ( $flags & GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
36413684 return $db->selectField( 'revision', 'rev_id',
36423685 array(
36433686 'rev_page' => $this->getArticleId( $flags ),
@@ -3650,37 +3693,28 @@
36513694 /**
36523695 * Get the first revision of the page
36533696 *
3654 - * @param $flags Int Title::GAID_FOR_UPDATE
3655 - * @return Revision|Null if page doesn't exist
 3697+ * @param $flags \type{\int} GAID_FOR_UPDATE
 3698+ * @return Revision (or NULL if page doesn't exist)
36563699 */
36573700 public function getFirstRevision( $flags = 0 ) {
 3701+ $db = ( $flags & GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
36583702 $pageId = $this->getArticleId( $flags );
3659 - if ( $pageId ) {
3660 - $db = ( $flags & self::GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
3661 - $row = $db->selectRow( 'revision', '*',
3662 - array( 'rev_page' => $pageId ),
3663 - __METHOD__,
3664 - array( 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 1 )
3665 - );
3666 - if ( $row ) {
3667 - return new Revision( $row );
3668 - }
 3703+ if ( !$pageId ) {
 3704+ return null;
36693705 }
3670 - return null;
 3706+ $row = $db->selectRow( 'revision', '*',
 3707+ array( 'rev_page' => $pageId ),
 3708+ __METHOD__,
 3709+ array( 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 1 )
 3710+ );
 3711+ if ( !$row ) {
 3712+ return null;
 3713+ } else {
 3714+ return new Revision( $row );
 3715+ }
36713716 }
36723717
36733718 /**
3674 - * Get the oldest revision timestamp of this page
3675 - *
3676 - * @param $flags Int Title::GAID_FOR_UPDATE
3677 - * @return String: MW timestamp
3678 - */
3679 - public function getEarliestRevTime( $flags = 0 ) {
3680 - $rev = $this->getFirstRevision( $flags );
3681 - return $rev ? $rev->getTimestamp() : null;
3682 - }
3683 -
3684 - /**
36853719 * Check if this is a new page
36863720 *
36873721 * @return bool
@@ -3691,70 +3725,45 @@
36923726 }
36933727
36943728 /**
3695 - * Get the number of revisions between the given revision.
3696 - * Used for diffs and other things that really need it.
 3729+ * Get the oldest revision timestamp of this page
36973730 *
3698 - * @param $old int|Revision Old revision or rev ID (first before range)
3699 - * @param $new int|Revision New revision or rev ID (first after range)
3700 - * @return Int Number of revisions between these revisions.
 3731+ * @return String: MW timestamp
37013732 */
3702 - public function countRevisionsBetween( $old, $new ) {
3703 - if ( !( $old instanceof Revision ) ) {
3704 - $old = Revision::newFromTitle( $this, (int)$old );
3705 - }
3706 - if ( !( $new instanceof Revision ) ) {
3707 - $new = Revision::newFromTitle( $this, (int)$new );
3708 - }
3709 - if ( !$old || !$new ) {
3710 - return 0; // nothing to compare
3711 - }
 3733+ public function getEarliestRevTime() {
37123734 $dbr = wfGetDB( DB_SLAVE );
3713 - return (int)$dbr->selectField( 'revision', 'count(*)',
3714 - array(
3715 - 'rev_page' => $this->getArticleId(),
3716 - 'rev_timestamp > ' . $dbr->addQuotes( $dbr->timestamp( $old->getTimestamp() ) ),
3717 - 'rev_timestamp < ' . $dbr->addQuotes( $dbr->timestamp( $new->getTimestamp() ) )
3718 - ),
3719 - __METHOD__
3720 - );
 3735+ if ( $this->exists() ) {
 3736+ $min = $dbr->selectField( 'revision',
 3737+ 'MIN(rev_timestamp)',
 3738+ array( 'rev_page' => $this->getArticleId() ),
 3739+ __METHOD__ );
 3740+ return wfTimestampOrNull( TS_MW, $min );
 3741+ }
 3742+ return null;
37213743 }
37223744
37233745 /**
3724 - * Get the number of authors between the given revision IDs.
 3746+ * Get the number of revisions between the given revision IDs.
37253747 * Used for diffs and other things that really need it.
37263748 *
3727 - * @param $old int|Revision Old revision or rev ID (first before range)
3728 - * @param $new int|Revision New revision or rev ID (first after range)
3729 - * @param $limit Int Maximum number of authors
3730 - * @return Int Number of revision authors between these revisions.
 3749+ * @param $old \type{\int} Revision ID.
 3750+ * @param $new \type{\int} Revision ID.
 3751+ * @return \type{\int} Number of revisions between these IDs.
37313752 */
3732 - public function countAuthorsBetween( $old, $new, $limit ) {
3733 - if ( !( $old instanceof Revision ) ) {
3734 - $old = Revision::newFromTitle( $this, (int)$old );
3735 - }
3736 - if ( !( $new instanceof Revision ) ) {
3737 - $new = Revision::newFromTitle( $this, (int)$new );
3738 - }
3739 - if ( !$old || !$new ) {
3740 - return 0; // nothing to compare
3741 - }
 3753+ public function countRevisionsBetween( $old, $new ) {
37423754 $dbr = wfGetDB( DB_SLAVE );
3743 - $res = $dbr->select( 'revision', 'DISTINCT rev_user_text',
3744 - array(
3745 - 'rev_page' => $this->getArticleID(),
3746 - 'rev_timestamp > ' . $dbr->addQuotes( $dbr->timestamp( $old->getTimestamp() ) ),
3747 - 'rev_timestamp < ' . $dbr->addQuotes( $dbr->timestamp( $new->getTimestamp() ) )
3748 - ), __METHOD__,
3749 - array( 'LIMIT' => $limit + 1 ) // add one so caller knows it was truncated
 3755+ return (int)$dbr->selectField( 'revision', 'count(*)',
 3756+ 'rev_page = ' . intval( $this->getArticleId() ) .
 3757+ ' AND rev_id > ' . intval( $old ) .
 3758+ ' AND rev_id < ' . intval( $new ),
 3759+ __METHOD__
37503760 );
3751 - return (int)$dbr->numRows( $res );
37523761 }
37533762
37543763 /**
37553764 * Compare with another title.
37563765 *
3757 - * @param $title Title
3758 - * @return Bool
 3766+ * @param $title \type{Title}
 3767+ * @return \type{\bool} TRUE or FALSE
37593768 */
37603769 public function equals( Title $title ) {
37613770 // Note: === is necessary for proper matching of number-like titles.
@@ -3765,10 +3774,7 @@
37663775
37673776 /**
37683777 * Callback for usort() to do title sorts by (namespace, title)
3769 - *
3770 - * @param $a Title
3771 - * @param $b Title
3772 - *
 3778+ *
37733779 * @return Integer: result of string comparison, or namespace comparison
37743780 */
37753781 public static function compare( $a, $b ) {
@@ -3782,7 +3788,7 @@
37833789 /**
37843790 * Return a string representation of this title
37853791 *
3786 - * @return String representation of this title
 3792+ * @return \type{\string} String representation of this title
37873793 */
37883794 public function __toString() {
37893795 return $this->getPrefixedText();
@@ -3795,7 +3801,7 @@
37963802 * If you want to know if a title can be meaningfully viewed, you should
37973803 * probably call the isKnown() method instead.
37983804 *
3799 - * @return Bool
 3805+ * @return \type{\bool}
38003806 */
38013807 public function exists() {
38023808 return $this->getArticleId() != 0;
@@ -3815,28 +3821,28 @@
38163822 * existing code, but we might want to add an optional parameter to skip
38173823 * it and any other expensive checks.)
38183824 *
3819 - * @return Bool
 3825+ * @return \type{\bool}
38203826 */
38213827 public function isAlwaysKnown() {
38223828 if ( $this->mInterwiki != '' ) {
38233829 return true; // any interwiki link might be viewable, for all we know
38243830 }
38253831 switch( $this->mNamespace ) {
3826 - case NS_MEDIA:
3827 - case NS_FILE:
3828 - // file exists, possibly in a foreign repo
3829 - return (bool)wfFindFile( $this );
3830 - case NS_SPECIAL:
3831 - // valid special page
3832 - return SpecialPageFactory::exists( $this->getDBkey() );
3833 - case NS_MAIN:
3834 - // selflink, possibly with fragment
3835 - return $this->mDbkeyform == '';
3836 - case NS_MEDIAWIKI:
3837 - // known system message
3838 - return $this->getDefaultMessageText() !== false;
3839 - default:
3840 - return false;
 3832+ case NS_MEDIA:
 3833+ case NS_FILE:
 3834+ return (bool)wfFindFile( $this ); // file exists, possibly in a foreign repo
 3835+ case NS_SPECIAL:
 3836+ return SpecialPage::exists( $this->getDBkey() ); // valid special page
 3837+ case NS_MAIN:
 3838+ return $this->mDbkeyform == ''; // selflink, possibly with fragment
 3839+ case NS_MEDIAWIKI:
 3840+ // If the page is form Mediawiki:message/lang, calling wfMsgWeirdKey causes
 3841+ // the full l10n of that language to be loaded. That takes much memory and
 3842+ // isn't needed. So we strip the language part away.
 3843+ list( $basename, /* rest */ ) = explode( '/', $this->mDbkeyform, 2 );
 3844+ return (bool)wfMsgWeirdKey( $basename ); // known system message
 3845+ default:
 3846+ return false;
38413847 }
38423848 }
38433849
@@ -3846,10 +3852,10 @@
38473853 * links to the title should be rendered as "bluelinks" (as opposed to
38483854 * "redlinks" to non-existent pages).
38493855 *
3850 - * @return Bool
 3856+ * @return \type{\bool}
38513857 */
38523858 public function isKnown() {
3853 - return $this->isAlwaysKnown() || $this->exists();
 3859+ return $this->exists() || $this->isAlwaysKnown();
38543860 }
38553861
38563862 /**
@@ -3865,38 +3871,20 @@
38663872 if ( $this->mNamespace == NS_MEDIAWIKI ) {
38673873 // If the page doesn't exist but is a known system message, default
38683874 // message content will be displayed, same for language subpages
3869 - return $this->getDefaultMessageText() !== false;
 3875+ // Also, if the page is form Mediawiki:message/lang, calling wfMsgWeirdKey
 3876+ // causes the full l10n of that language to be loaded. That takes much
 3877+ // memory and isn't needed. So we strip the language part away.
 3878+ list( $basename, /* rest */ ) = explode( '/', $this->mDbkeyform, 2 );
 3879+ return (bool)wfMsgWeirdKey( $basename );
38703880 }
38713881
38723882 return false;
38733883 }
38743884
38753885 /**
3876 - * Get the default message text or false if the message doesn't exist
3877 - *
3878 - * @return String or false
3879 - */
3880 - public function getDefaultMessageText() {
3881 - global $wgContLang;
3882 -
3883 - if ( $this->getNamespace() != NS_MEDIAWIKI ) { // Just in case
3884 - return false;
3885 - }
3886 -
3887 - list( $name, $lang ) = MessageCache::singleton()->figureMessage( $wgContLang->lcfirst( $this->getText() ) );
3888 - $message = wfMessage( $name )->inLanguage( $lang )->useDatabase( false );
3889 -
3890 - if ( $message->exists() ) {
3891 - return $message->plain();
3892 - } else {
3893 - return false;
3894 - }
3895 - }
3896 -
3897 - /**
38983886 * Is this in a namespace that allows actual pages?
38993887 *
3900 - * @return Bool
 3888+ * @return \type{\bool}
39013889 * @internal note -- uses hardcoded namespace index instead of constants
39023890 */
39033891 public function canExist() {
@@ -3922,7 +3910,7 @@
39233911 * Get the last touched timestamp
39243912 *
39253913 * @param $db DatabaseBase: optional db
3926 - * @return String last-touched timestamp
 3914+ * @return \type{\string} Last touched timestamp
39273915 */
39283916 public function getTouched( $db = null ) {
39293917 $db = isset( $db ) ? $db : wfGetDB( DB_SLAVE );
@@ -3934,7 +3922,7 @@
39353923 * Get the timestamp when this page was updated since the user last saw it.
39363924 *
39373925 * @param $user User
3938 - * @return String|Null
 3926+ * @return Mixed: string/null
39393927 */
39403928 public function getNotificationTimestamp( $user = null ) {
39413929 global $wgUser, $wgShowUpdatedMarker;
@@ -3944,8 +3932,7 @@
39453933 }
39463934 // Check cache first
39473935 $uid = $user->getId();
3948 - // avoid isset here, as it'll return false for null entries
3949 - if ( array_key_exists( $uid, $this->mNotificationTimestamp ) ) {
 3936+ if ( isset( $this->mNotificationTimestamp[$uid] ) ) {
39503937 return $this->mNotificationTimestamp[$uid];
39513938 }
39523939 if ( !$uid || !$wgShowUpdatedMarker ) {
@@ -3970,7 +3957,7 @@
39713958 /**
39723959 * Get the trackback URL for this page
39733960 *
3974 - * @return String Trackback URL
 3961+ * @return \type{\string} Trackback URL
39753962 */
39763963 public function trackbackURL() {
39773964 global $wgScriptPath, $wgServer, $wgScriptExtension;
@@ -3982,7 +3969,7 @@
39833970 /**
39843971 * Get the trackback RDF for this page
39853972 *
3986 - * @return String Trackback RDF
 3973+ * @return \type{\string} Trackback RDF
39873974 */
39883975 public function trackbackRDF() {
39893976 $url = htmlspecialchars( $this->getFullURL() );
@@ -3996,8 +3983,8 @@
39973984 // Spec: http://www.sixapart.com/pronet/docs/trackback_spec
39983985 return "<!--
39993986 <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"
4000 - xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
4001 - xmlns:trackback=\"http://madskills.com/public/xml/rss/module/trackback/\">
 3987+ xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
 3988+ xmlns:trackback=\"http://madskills.com/public/xml/rss/module/trackback/\">
40023989 <rdf:Description
40033990 rdf:about=\"$url\"
40043991 dc:identifier=\"$url\"
@@ -4011,7 +3998,7 @@
40123999 * Generate strings used for xml 'id' names in monobook tabs
40134000 *
40144001 * @param $prepend string defaults to 'nstab-'
4015 - * @return String XML 'id' name
 4002+ * @return \type{\string} XML 'id' name
40164003 */
40174004 public function getNamespaceKey( $prepend = 'nstab-' ) {
40184005 global $wgContLang;
@@ -4050,12 +4037,12 @@
40514038 /**
40524039 * Returns true if this title resolves to the named special page
40534040 *
4054 - * @param $name String The special page name
 4041+ * @param $name \type{\string} The special page name
40554042 * @return boolean
40564043 */
40574044 public function isSpecial( $name ) {
40584045 if ( $this->getNamespace() == NS_SPECIAL ) {
4059 - list( $thisName, /* $subpage */ ) = SpecialPageFactory::resolveAlias( $this->getDBkey() );
 4046+ list( $thisName, /* $subpage */ ) = SpecialPage::resolveAliasWithSubpage( $this->getDBkey() );
40604047 if ( $name == $thisName ) {
40614048 return true;
40624049 }
@@ -4064,16 +4051,16 @@
40654052 }
40664053
40674054 /**
4068 - * If the Title refers to a special page alias which is not the local default, resolve
4069 - * the alias, and localise the name as necessary. Otherwise, return $this
 4055+ * If the Title refers to a special page alias which is not the local default,
40704056 *
4071 - * @return Title
 4057+ * @return \type{Title} A new Title which points to the local default.
 4058+ * Otherwise, returns $this.
40724059 */
40734060 public function fixSpecialName() {
40744061 if ( $this->getNamespace() == NS_SPECIAL ) {
4075 - list( $canonicalName, /*...*/ ) = SpecialPageFactory::resolveAlias( $this->mDbkeyform );
 4062+ $canonicalName = SpecialPage::resolveAlias( $this->mDbkeyform );
40764063 if ( $canonicalName ) {
4077 - $localName = SpecialPageFactory::getLocalNameFor( $canonicalName );
 4064+ $localName = SpecialPage::getLocalNameFor( $canonicalName );
40784065 if ( $localName != $this->mDbkeyform ) {
40794066 return Title::makeTitle( NS_SPECIAL, $localName );
40804067 }
@@ -4087,7 +4074,7 @@
40884075 * In other words, is this a content page, for the purposes of calculating
40894076 * statistics, etc?
40904077 *
4091 - * @return Boolean
 4078+ * @return \type{\bool}
40924079 */
40934080 public function isContentPage() {
40944081 return MWNamespace::isContent( $this->getNamespace() );
@@ -4096,8 +4083,9 @@
40974084 /**
40984085 * Get all extant redirects to this Title
40994086 *
4100 - * @param $ns Int|Null Single namespace to consider; NULL to consider all namespaces
4101 - * @return Array of Title redirects to this title
 4087+ * @param $ns \twotypes{\int,\null} Single namespace to consider;
 4088+ * NULL to consider all namespaces
 4089+ * @return \type{\arrayof{Title}} Redirects to this title
41024090 */
41034091 public function getRedirectsHere( $ns = null ) {
41044092 $redirs = array();
@@ -4119,6 +4107,7 @@
41204108 __METHOD__
41214109 );
41224110
 4111+
41234112 foreach ( $res as $row ) {
41244113 $redirs[] = self::newFromRow( $row );
41254114 }
@@ -4128,7 +4117,7 @@
41294118 /**
41304119 * Check if this Title is a valid redirect target
41314120 *
4132 - * @return Bool
 4121+ * @return \type{\bool}
41334122 */
41344123 public function isValidRedirectTarget() {
41354124 global $wgInvalidRedirectTargets;
@@ -4160,7 +4149,8 @@
41614150 }
41624151
41634152 /**
4164 - * Whether the magic words __INDEX__ and __NOINDEX__ function for this page.
 4153+ * Whether the magic words __INDEX__ and __NOINDEX__ function for
 4154+ * this page.
41654155 *
41664156 * @return Boolean
41674157 */
@@ -4181,47 +4171,21 @@
41824172 * @return array applicable restriction types
41834173 */
41844174 public function getRestrictionTypes() {
4185 - if ( $this->getNamespace() == NS_SPECIAL ) {
4186 - return array();
4187 - }
 4175+ global $wgRestrictionTypes;
 4176+ $types = $this->exists() ? $wgRestrictionTypes : array( 'create' );
41884177
4189 - $types = self::getFilteredRestrictionTypes( $this->exists() );
4190 -
4191 - if ( $this->getNamespace() != NS_FILE ) {
4192 - # Remove the upload restriction for non-file titles
4193 - $types = array_diff( $types, array( 'upload' ) );
 4178+ if ( $this->getNamespace() == NS_FILE ) {
 4179+ $types[] = 'upload';
41944180 }
41954181
41964182 wfRunHooks( 'TitleGetRestrictionTypes', array( $this, &$types ) );
41974183
4198 - wfDebug( __METHOD__ . ': applicable restriction types for ' .
4199 - $this->getPrefixedText() . ' are ' . implode( ',', $types ) . "\n" );
4200 -
42014184 return $types;
42024185 }
4203 - /**
4204 - * Get a filtered list of all restriction types supported by this wiki.
4205 - * @param bool $exists True to get all restriction types that apply to
4206 - * titles that do exist, False for all restriction types that apply to
4207 - * titles that do not exist
4208 - * @return array
4209 - */
4210 - public static function getFilteredRestrictionTypes( $exists = true ) {
4211 - global $wgRestrictionTypes;
4212 - $types = $wgRestrictionTypes;
4213 - if ( $exists ) {
4214 - # Remove the create restriction for existing titles
4215 - $types = array_diff( $types, array( 'create' ) );
4216 - } else {
4217 - # Only the create and upload restrictions apply to non-existing titles
4218 - $types = array_intersect( $types, array( 'create', 'upload' ) );
4219 - }
4220 - return $types;
4221 - }
42224186
42234187 /**
42244188 * Returns the raw sort key to be used for categories, with the specified
4225 - * prefix. This will be fed to Collation::getSortKey() to get a
 4189+ * prefix. This will be fed to Language::convertToSortkey() to get a
42264190 * binary sortkey that can be used for actual sorting.
42274191 *
42284192 * @param $prefix string The prefix to be used, specified using
@@ -4232,47 +4196,11 @@
42334197 public function getCategorySortkey( $prefix = '' ) {
42344198 $unprefixed = $this->getText();
42354199 if ( $prefix !== '' ) {
4236 - # Separate with a line feed, so the unprefixed part is only used as
4237 - # a tiebreaker when two pages have the exact same prefix.
4238 - # In UCA, tab is the only character that can sort above LF
4239 - # so we strip both of them from the original prefix.
4240 - $prefix = strtr( $prefix, "\n\t", ' ' );
4241 - return "$prefix\n$unprefixed";
 4200+ # Separate with a null byte, so the unprefixed part is only used as
 4201+ # a tiebreaker when two pages have the exact same prefix -- null
 4202+ # sorts before everything else (hopefully).
 4203+ return "$prefix\0$unprefixed";
42424204 }
42434205 return $unprefixed;
42444206 }
42454207 }
4246 -
4247 -/**
4248 - * A BadTitle is generated in MediaWiki::parseTitle() if the title is invalid; the
4249 - * software uses this to display an error page. Internally it's basically a Title
4250 - * for an empty special page
4251 - */
4252 -class BadTitle extends Title {
4253 - public function __construct(){
4254 - $this->mTextform = '';
4255 - $this->mUrlform = '';
4256 - $this->mDbkeyform = '';
4257 - $this->mNamespace = NS_SPECIAL; // Stops talk page link, etc, being shown
4258 - }
4259 -
4260 - public function exists(){
4261 - return false;
4262 - }
4263 -
4264 - public function getPrefixedText(){
4265 - return '';
4266 - }
4267 -
4268 - public function getText(){
4269 - return '';
4270 - }
4271 -
4272 - public function getPrefixedURL(){
4273 - return '';
4274 - }
4275 -
4276 - public function getPrefixedDBKey(){
4277 - return '';
4278 - }
4279 -}
Property changes on: branches/iwtransclusion/phase3v2/includes/Title.php
___________________________________________________________________
Modified: svn:mergeinfo
42804208 Merged /branches/iwtransclusion/phase3/includes/Title.php:r70764
Index: branches/iwtransclusion/phase3v2/languages/messages/MessagesEn.php
@@ -1399,6 +1399,9 @@
14001400 'templatesused' => '{{PLURAL:$1|Template|Templates}} used on this page:',
14011401 'templatesusedpreview' => '{{PLURAL:$1|Template|Templates}} used in this preview:',
14021402 'templatesusedsection' => '{{PLURAL:$1|Template|Templates}} used in this section:',
 1403+'distanttemplatesused' => 'Distant {{PLURAL:$1|template|templates}} used on this page:',
 1404+'distanttemplatesusedpreview' => 'Distant {{PLURAL:$1|template|templates}} used in this preview:',
 1405+'distanttemplatesusedsection' => 'Distant {{PLURAL:$1|template|templates}} used in this section:',
14031406 'template-protected' => '(protected)',
14041407 'template-semiprotected' => '(semi-protected)',
14051408 'hiddencategories' => 'This page is a member of {{PLURAL:$1|1 hidden category|$1 hidden categories}}:',
Property changes on: branches/iwtransclusion/phase3v2
___________________________________________________________________
Modified: svn:mergeinfo
14061409 Merged /branches/iwtransclusion/phase3:r70764

Follow-up revisions

RevisionCommit summaryAuthorDate
r92990Merge r87108, Merge r70764reedy17:38, 24 July 2011
r92993Merge r87108, which merged r70764reedy18:15, 24 July 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r70764Fix remarks about r70576; display the distant templates below the edit textareapeter1714:46, 9 August 2010

Status & tagging log