Commit graph

1518 commits

Author SHA1 Message Date
daniel
fbc1449653 Make Titles with an unknown namespace ID refer to Special:Badtitle.
Without this patch, Title::getPrefixedText() would return ":Foo"
if the namespace was unknown, potentially creating a misleading
link to the main namespace. With this change, getPrefixedText()
will return something like "Special:Badtitle/NS12345:Foo".

Note that round trip behavior is broken either way.

Bug: T165149
Change-Id: I0d491a2b58ff45f207f83ee62ca6e7e6ffbf790a
2017-06-14 04:31:07 +00:00
Brad Jorsch
6d52171806 Have Title::get(Next|Previous)RevisionID sort by timestamp
Revision IDs are usually increasing as timestamp increases, but not
always. Callers almost certainly want next/previous timestamp when the
two differ.

This also takes care of a minor bug in the nearby getFirstRevision()
where it'll choose an arbitrary tied revision ID if there were multiple
revisions made in the same second.

Bug: T4930
Bug: T163532
Bug: T159319
Change-Id: Iab2060a0ad5e45edbaa0ff36e863cb014b8e876f
2017-05-08 05:33:07 +00:00
Fomafix
5c41b29993 Use isSpecialPage() where possible
Change-Id: Ie4d0838acf96a7ed4a1fe4cfdc901c77d3312174
2017-04-29 22:31:42 +02:00
jenkins-bot
0697e41485 Merge "Move Database and subclasses to Rdbms namespace" 2017-04-12 18:07:43 +00:00
Aaron Schulz
d735dc562d Move Database and subclasses to Rdbms namespace
Change-Id: I52bef87512f9ddd155d1f4cc0052f6b7a0db5b42
2017-04-12 10:43:57 -07:00
Fomafix
464f0c72a5 Remove multiple spaces in PHP files
Change-Id: Id9c26ec5ca730a9536f8fdccb8853eb03cbe87a4
2017-04-12 17:27:19 +02:00
zppix1
0a6f7f5796 Remove "editusercssjs" user right
Deprecated since MediaWiki1.16

Change-Id: Ic9851d53affe0f4ece7a79f541ec5cb39133b109
2017-04-11 14:54:43 +01:00
Brian Wolff
55035e01e5 SECURITY: Do not allow users to undelete a page they can't edit or create
If the page exists, it only checks edit rights, otherwise it
checks both edit and create rights.

This would only matter on wikis that have a non-default rights
configuration where there are users with undelete rights but a
restriction level enabled that prevents them from creating/editing
pages (or they otherwise aren't allowed to edit/create)

It should be noted that the error messages aren't used in the
normal UI currently, but they could be in the future, and
extensions could potentially be using them (The backend functions
return them, but the UI functions in Special:Undelete ignore
them)

Bug: T108138
Change-Id: I164b80534cf89e0afca264e9de07431484af8508
2017-04-06 13:44:55 -07:00
Brian Wolff
14beae88b5 SECURITY: Do not directly redirect to interwikis, but use splash page
Directly redirecting based on a url paramter might potentially
be used in a phishing attack to confuse users.

Bug: T109140
Bug: T122209
Change-Id: I6c604439320fa876719933cc7f3a3ff04fb1a6ad
2017-04-06 13:42:38 -07:00
jenkins-bot
d1380bfdd1 Merge "Implement WikiPage::getOldestRevision() in terms of Title::getFirstRevision()" 2017-03-30 18:36:34 +00:00
jenkins-bot
142e89424e Merge "Make Title::getFirstRevision() ignore the rev_timestamp index" 2017-03-29 16:23:38 +00:00
Roan Kattouw
09f14cba52 Implement WikiPage::getOldestRevision() in terms of Title::getFirstRevision()
They were both doing the same thing, except that getOldestRevision()
checks the master if the revision is missing on the replica.

Change-Id: I21a118c6cd5c98fb846a0a2765574c0dbdbf7220
2017-03-29 11:53:08 -04:00
Roan Kattouw
dee457713b Make Title::getFirstRevision() ignore the rev_timestamp index
We want the page_timestamp index to be used in this case, but sometimes
the rev_timestamp is chosen which leads to bad performance.

Also update WikiPage::getOldestRevision() which uses the exact same query.
I'll implement one in terms of the other in a follow-up commit.

Bug: T159319
Change-Id: I7c5c0a9b1af99ce2b5f4bdcc99710d8400ca8bcf
2017-03-29 11:40:12 -04:00
Aaron Schulz
488a647831 Move IDatabase/IMaintainableDatabase to Rdbms namespace
Change-Id: If7e8a8ff574661fd827de8bcec11d2c39a687300
2017-03-28 15:32:38 -07:00
jenkins-bot
17eba67ef3 Merge "Change Title::getPreviousRevisionID (and next) to ignore PRIMARY" 2017-03-28 15:09:28 +00:00
Bartosz Dziewoński
8dd52aa4dc Title: Remove outdated comment in loadRestrictionsFromRows()
It has been refactored, and decodeExpiry() is now a method of Database.

Change-Id: I357b303317c877be944474db1331855adb1eb8fd
2017-03-14 02:37:40 +00:00
Jcrespo
80b9ad3a8a Change Title::getPreviousRevisionID (and next) to ignore PRIMARY
Both Title::getPreviousRevisionID and Title::getNextRevisionID
have bad performance under certain versions of MySQL/MariaDB
when the page has many revisions (in the order of dozens of
thousands). This is good enough in most cases.

However, on a contributions slave, where it has an explicity
defined extended secondary key with the primary key, the
performance is really, really bad, performing a full table scan.

By ignoring the PRIMARY KEY index, contributions slaves go from the
worst case to the best case, while not affecting the plan of regular
slaves. It is believed that more recent versions of MySQL chose the 
right indexes automatically, because they can use the extended primary
key automatically, without adding it explicitly. If that doesn't
happen, we can consider adding it explicitly to the regular slaves,
too.

In any case, not using the PRIMARY gives always a much better or at
least the same performance (this never causes a regression, unlike
FORCE'ing a specific index).

Bug: T159319
Change-Id: Ibb6e5240b87bd8e2d680fc4d58fcb3db1a4721cc
2017-03-10 08:07:37 +00:00
Brad Jorsch
e89b499351 Fix Title::loadRestrictions() for create-protected titles
Title::loadRestrictions() returns restriction levels, not the
corresponding user rights. These are mostly identical except for the
backwards-compatibility levels "sysop" and "autoconfirmed".

For create protection it calls Title::getTitleProtection() to fetch
them, but Ic5026384 changed that to return rights. Split that function
into two, an internal method that returns restriction levels for
loadRestrictions() to call and the public method that converts levels
into rights.

Bug: T85108
Change-Id: I3ea4cb9c5e37b746402744dd7a883763ee07195a
2017-03-02 17:09:30 +00:00
jenkins-bot
aa3319c4c0 Merge "Miscellaneous indentation tweaks" 2017-02-28 18:38:36 +00:00
Bartosz Dziewoński
ecdef925bb Miscellaneous indentation tweaks
I was bored. What? Don't look at me that way.

I mostly targetted mixed tabs and spaces, but others were not spared.
Note that some of the whitespace changes are inside HTML output,
extended regexps or SQL snippets.

Change-Id: Ie206cc946459f6befcfc2d520e35ad3ea3c0f1e0
2017-02-27 19:23:54 +01:00
James D. Forrester
9635dda73a includes: Replace implicit Bugzilla bug numbers with Phab ones
It's unreasonable to expect newbies to know that "bug 12345" means "Task T14345"
except where it doesn't, so let's just standardise on the real numbers.

Change-Id: I6f59febaf8fc96e80f8cfc11f4356283f461142a
2017-02-21 18:13:24 +00:00
This, that and the other
73224f4f8b User group memberships that expire
This patch adds an ug_expiry column to the user_groups table, a timestamp
giving a date when the user group expires. A new UserGroupMembership class,
based on the Block class, manages entries in this table.

When the expiry date passes, the row in user_groups is ignored, and will
eventually be purged from the DB when UserGroupMembership::insert is next
called. Old, expired user group memberships are not kept; instead, the log
entries are available to find the history of these memberships, similar
to the way it has always worked for blocks and protections.

Anyone getting user group info through the User object will get correct
information. However, code that reads the user_groups table directly will
now need to skip over rows with ug_expiry < wfTimestampNow(). See
UsersPager for an example of how to do this.

NULL is used to represent infinite (no) expiry, rather than a string
'infinity' or similar (except in the API). This allows existing user group
assignments and log entries, which are all infinite in duration, to be
treated the same as new, infinite-length memberships, without special
casing everything.

The whole thing is behind the temporary feature flag
$wgDisableUserGroupExpiry, in accordance with the WMF schema change policy.

The opportunity has been taken to refactor some static user-group-related
functions out of User into UserGroupMembership, and also to add a primary
key (ug_user, ug_group) to the user_groups table.

There are a few breaking changes:
- UserRightsProxy-like objects are now required to have a
  getGroupMemberships() function.
- $user->mGroups (on a User object) is no longer present.
- Some protected functions in UsersPager are altered or removed.
- The UsersPagerDoBatchLookups hook (unused in any Wikimedia Git-hosted
  extension) has a change of parameter.

Bug: T12493
Depends-On: Ia9616e1e35184fed9058d2d39afbe1038f56d7fa
Depends-On: I86eb1d5619347ce54a5f33a591417742ebe5d6f8
Change-Id: I93c955dc7a970f78e32aa503c01c67da30971d1a
2017-01-27 09:24:20 +00:00
rlot
99800a9e03 Removed deprecated ContentHandler hooks.
Plus removed unused "ContentHandler::runLegacyHooks"

Bug: T154498
Change-Id: Ie398fd4e06d3e286fe8e24112d0c8b4ac7d883dc
2017-01-18 21:19:17 +00:00
jenkins-bot
892b17237b Merge "Add parameter to API modules to apply change tags to log entries" 2017-01-13 17:42:04 +00:00
This, that and the other
f3f2df07ec Add parameter to API modules to apply change tags to log entries
Adds support for tagging log entries for the block, import,
managetags, and move API modules, using a 'tags' parameter.

Bug: T97720
Change-Id: I9d75d2cece317a7704c4bc6d734ad3cafe24544e
2017-01-12 16:30:17 -06:00
awu42
c3f7cebf69 Removed deprecated Title::moveNoAuth function
(deprecated since 1.25)

Bug: T61113
Change-Id: I7a007dd87ea3bcbb1121738c84b0e654ba17ccbf
2017-01-01 18:13:33 +00:00
awu42
529d946e69 Replaced &$this with $this
Replaced &$this in includes/Title.php to avoid error in PHP 7.1

Bug: T153505
Change-Id: I76eaae609a817af42687d87bcf0d13da7ba01c05
2016-12-30 11:55:28 -05:00
Brad Jorsch
d5423f43d0 Title: Fix subpage move error reporting
Title::moveSubpages() sometimes returns a single message-specifier array
and sometimes returns an array of such arrays. This is extremely
difficult for a caller to deal with. Since nothing in Gerrit other than
ApiMove calls this, let's just fix it.

Also, it seems that messages were never created for the errors returned
by this method. So let's create them.

Change-Id: I4e55483c4476a1bb96c87266a4661871776fbf9b
2016-12-20 13:41:36 -05:00
jenkins-bot
8e622749cf Merge "Fix type annotations" 2016-12-16 17:18:00 +00:00
Max Semenik
f23a964170 Fix type annotations
Change-Id: Ib72c98358b2f0b3b73b6f105adea47346373d46d
2016-12-15 14:11:12 -08:00
Erik Bernhardson
d67197fa11 Cleanup some incorrect return annotations
Most of these are simply changing annotations to reflect
reality. If a function can return false to indicate failure
the @return should indicate it.

Some are fixing preg_match calls, preg match returns 1, 0 or false,
but the functions all claim to return booleans.

This is far from all the incorrect return types in mediawiki, there
are around 250 detected by phan, but have to start somewhere.

Change-Id: I1bbdfee6190747bde460f8a7084212ccafe169ef
2016-12-12 10:15:05 -08:00
umherirrender
34fe90ac52 Remove empty lines at end of functions
It looks like there is something missing after the last statement
Also remove some other empty lines at begin of functions, ifs or loops
while at these files

Change-Id: Ib00b5cfd31ca4dcd0c32ce33754d3c80bae70641
2016-11-05 11:55:10 +01:00
Aaron Schulz
0852a000a5 Add caching to ResourceLoaderWikiModule::preloadTitleInfo()
This is one of the top three DB queries showing up in xenon
reverse flamegraph profiling.

It works via a per-wiki check key that is bumped whenever
someone changes a .js or .css page on that wiki.

Change-Id: I73f419558864ba3403b4601a098f6aaf84a3e7c1
2016-10-20 20:54:11 +00:00
jenkins-bot
3d653e8ab5 Merge "Ensure users are able to edit the page after changing the content model" 2016-09-23 06:16:11 +00:00
Kunal Mehta
2108c55ec5 Ensure users are able to edit the page after changing the content model
It is possible for page restrictions to be dependent upon the content
model a page. The best example of this is user JavaScript and CSS
subpages. This adds a Title::setContentModel() function which allows
mocking a Title's content model for the purpose of permission checks.

EditPage and Special:ChangeContentModel were updated to ensure the user
can edit the page with the newly proposed content model before making
the change.

Title::$mContentModel was made private to make sure nothing else mucks
around with it. There were no uses outside of Title anyways.

Bug: T145316
Change-Id: I28c46f408cadf65ed1868401cd00dc15e5acd2fe
2016-09-22 22:22:48 -07:00
addshore
a36e01c63a phpdoc Title::inNamespaces also allows array
Change-Id: I201dbaf9c0dee5b47c4edde73ff68b88560e8a0f
2016-09-20 13:34:14 +01:00
Reedy
3c27ff94fa Replace WikiPage::doEdit() usages
Update/add some comments

Bug: T145737
Change-Id: Ib3b2b69906074cbb51917dc57204c989fd6c58b2
2016-09-15 21:25:32 +01:00
jenkins-bot
bae9c5aca6 Merge "Add caching to Title::loadRestrictions()" 2016-09-14 19:14:40 +00:00
Kunal Mehta
5d52874ddf Title: Document that Title::compare() can be used for LinkTargets
It only depends upon functions that are all in the LinkTarget interface.

Change-Id: I95e598ea6014ced8f1b947c283dd0b542756b8e2
2016-09-08 21:58:55 -07:00
Aaron Schulz
8ebec93fea Cache NS_TEMPLATE/NS_FILE titles in LinkCache persistently
Queries from parsing are the top use of selectRow() according
to reverse flame graphs on xenon. This does not bother with
pages in namespaces less likely to be included.

Change-Id: Ica5d6e52c830cd71effff21933b8c64691082c11
2016-09-07 00:20:26 -07:00
Aaron Schulz
62b9d21ccc Add caching to Title::loadRestrictions()
Change-Id: Id9dac9b67cf969cddaaa8d412cb7fd033146f17d
2016-09-06 05:52:00 -07:00
Aaron Schulz
950cf6016c Rename DB_SLAVE constant to DB_REPLICA
This is more consistent with LoadBalancer, modern, and inclusive
of master/master mysql, NDB cluster, and MariaDB galera cluster.

The old constant is an alias now.

Change-Id: I0b37299ecb439cc446ffbe8c341365d1eef45849
2016-09-05 22:55:53 -07:00
Aaron Schulz
16266edff3 Change "slave" => "replica DB" in /includes
Change-Id: Icb716219c9335ff8fa447b1733d04b71d9712bf9
2016-09-05 21:01:01 +00:00
Brian Wolff
b675be2083 SECURITY: Make $wgBlockDisablesLogin also restrict logged in permissions
Does both Title and user related methods, so it catches things that only
call $wgUser->isAllowed( 'read' ), as well as giving a nicer error message
for things that use $title->userCan().

Otherwise, the user can still do stuff and read pages if they have an
ongoing session.

Issue reported by Multichill

Bug: T129738
Change-Id: Ic929a385fa81c27cbc6ac3a0862f51190d3ae993
2016-08-22 18:41:01 -07:00
Florian
f2598a0b21 AuthManager: Always whitelist some special pages
Special:UserLogout should be whitelisted, if Special:UserLogin is whitelisted,
as otherwise the user is able to login, but not able to logout anymore (given,
that the sys-admin hasn't change the $wgWhitelistRead config variable).

Special:ChangePassword redirects to Special:ChangeCredentials. Instead of
adding this special page, it should be done explicitly in the
wiki configuration (LocalSettings.php). For this reason, the whitelist is
removed, too.

Change-Id: I271efb517bf0ec0022e6fe29673570ca08e8fe1a
2016-08-11 18:35:28 +02:00
Erik Bernhardson
968f846834 Remove return by reference in Title::makeTitle
This made sense back in php4, but has no useful effect anymore
with our minimum php version being 5.5. This also has the effect
of searching for 'function makeTitle' now actually finding something.

Change-Id: I0ea02a2e7dff285341b0e5b5b7773da78bfaaff3
2016-07-29 13:30:32 -07:00
Aaron Schulz
3c21f0e8e5 Add AutoCommitUpdate class and replace some onTransactionIdle callers
* This puts the complex logic here after the commit step for
  all DBs, making the main multi-DB transaction more likely
  to be atomic.
* Made some cleanups to AtomicSectionUpdate and made it cancel
  if the transaction is rolled back as it should.
* Also cleaned up some closures for PHP 5.4.

Change-Id: If2f7bb6b1ba6daf1cfdc934f27c32b0b10431a3d
2016-07-21 05:24:28 +00:00
jenkins-bot
0124c6ce75 Merge "Title::getLinkURL(): Allow expanding PROTO_RELATIVE too" 2016-07-20 21:56:21 +00:00
jenkins-bot
7dd1914e73 Merge "Don't use $wgContentNamespaces directly" 2016-07-12 23:26:38 +00:00
Kunal Mehta
8091e9c6db Don't use $wgContentNamespaces directly
Change-Id: If8ed1bf7e7c6429c405c956413af07a191ec9c40
2016-07-12 15:50:29 -07:00