Fandom

Wikia Developers Wiki

LastEdited

878pages on
this wiki
Add New Page
Talk139 Share

LastEdited adds details about the last edit to the current page. These details include the time (minutes/hours/days/months/years) ago the last edit was made, user who made the edit, edit summary given (if any), the current page size in bytes and a link to open a modal to review the changes. The modal includes a link to the actual diff page, a link to undo the edit and a link to rollback the edits if the user has the required rights.

The date and time are added by default and cannot be changed, while the other options can be configured.

Demo

A demo can be seen live at the header of this page, listing the last edited details of the page.

Installation

Add the following to your Special:MyPage/common.js for personal use, or MediaWiki:Common.js for site wide use:

importArticles({
    type: 'script',
    articles: [
        // ...
        'u:dev:LastEdited/code.js',
        // ...
    ]
});
importArticles — Best Practices for installing JavaScript on Fandom
The importArticles statement is designed to combine multiple HTTP requests into a single data transfer, allowing multiple scripts to load and execute faster. If you've been installing several different scripts, your JavaScript file has probably accumulated unnecessary import statements. Click "Expand" to learn how to efficiently batch import scripts to speed up performance and make your code look cleaner. One other approach is by using the MediaWiki:ImportJS.
If your JavaScript file has several lines of code that say importScript, importScriptPage, or importArticles, you may be able to combine them! By batch importing a collection of scripts with a single import, your JavaScript code will load faster and look cleaner. Consider the example below. On the left is an example of what your JavaScript file might currently look like. On the right is how you could improve that code.
Multiple imports — messy and slow One import — clean and efficient
importScriptPage('AjaxRC/code.js','dev');
 
importScript('MediaWiki:localScript.js');
 
importArticle({
  type: 'script',
  article: 'u:dev:FloatingToc/code.js'
});
 
importScriptPage('page1.js', 'wikiname');
 
importScriptPage('page2.js', 'wikiname');
importArticles({
    type: 'script',
    articles: [
        'u:dev:AjaxRC/code.js',
        'MediaWiki:localScript.js',
        'u:dev:FloatingToc/code.js',
        'u:wikiname:page1.js',
        'u:wikiname:page2.js'
    ]
});
Note: In this example, pay close attention to the placement of commas and other punctuation. For people who aren't familiar with programming (and even those who are!), a common mistake when writing code is to accidentally delete, forget, or misplace critical symbols like commas or quotation marks. This can cause a syntax error that breaks the code. Carefully follow the convention shown here when using importArticles.
But there's much more to importArticles than just this! For more examples and advanced usage, see the help page at Help:Including additional JavaScript and CSS.

Configuration

Key Description Type Possible values Default
avatar Editor's user avatar boolean true
false
true
avatarsize Size of the avatar integer None specific 15
size Current page size (in bytes) boolean true
false
true
diff Shows the diff modal
comment Edit summary given*
time Decides whether the time mentioned must be in the "time ago" format or a timestamp string timestamp
timeago
timeago
timezone Decides whether the timestamp shown is in local or UTC format* UTC local
lang Changes the language displayed* Any valid language code None specific
position.element Controls where the details will be added object Any valid element present on the page
position.method Controls whether the details need to be appended or prepended to the element defined in position.element string append
prepend
namespaces.exclude List of namespace ids to exclude array None specific []
namespaces.include List of namespaces to include*
pages List of pages to exclude

All configurations made to the script are to be stored in the lastEdited object, like so:

window.lastEdited = {
    avatar: true,
    avatarsize: 20,
    size: false,
    diff: true,
    comment: false,
    time: 'timestamp',
    timezone: 'UTC',
    lang: 'ja',
    position: {
        element: document.getElementById('WikiaPageHeader'),
        method: 'append'
    },
    namespaces: {
        include: [],
        exclude: []
    },
    pages: []
};

Notes

  • If edit summary is not given with the edit, the whole part will be omitted, regardless of the value of comment.
  • lang is meant for personal use only. Using it for site-wide use is not encouraged.
  • timezone is applicable only if time is set to timestamp.
  • By default, the script works on the following namespaces: mainspace (article), article talk, user, user talk, project/sitename, project talk/sitename talk, image/file, image talk/file talk, mediawiki, mediawiki talk, template, template talk, category, category talk, forum, forum talk, module, module talk and message wall greeting.
  • For custom namespaces, the namespace could be found by using the wgNamespaceIds object.
  • For any styling, the class of the outer div is lastEdited and that of the avatar icon is lastEdited-avatar.
  • Make sure to follow the customization policy while selecting position.element. If not provided, the default positions are below the title on pages, and below the edit button on userpages.
    • Please use the talkpage if you can't figure out how to get the details to show up at a particular place.
  • The table below shows a full list of default namespaces that can be used with the script with their ids for exclusion:
ID Namespace Description
-2 Media Used for direct linking to images. For example, Media:Wiki.png links directly to the image page.
-1 Special Special pages. Used by MediaWiki code and extensions
0 Mainspace Articles
1 Talk Article discussion
2 User Personal user pages
3 User talk Pages for discussion with users
4 Project/Sitename Wiki-related content
5 Project talk/Sitename talk Discussion of Project pages
6 Image/File File descriptions
7 Image talk/File talk File discussion
8 MediaWiki System messages and configuration
9 MediaWiki talk Discussion of MediaWiki pages
10 Template Templates
11 Template talk Template discussion
12 Help Help pages, also see Shared Help
13 Help talk Discussion about Help pages
14 Category Categories
15 Category talk Category discussion
110 Forum Old forum pages
111 Forum talk Discussion about old forum pages
500 User blog Blog pages
501 User blog comment User blog comments
502 Blog Blog listing pages
503 Blog talk Blog listing page discussion. Generally unused
828 Module Lua module pages
829 Module talk Lua module discussion pages
1200 Message Wall Pages used for the Wall extension. Touch only if you know what are you doing.
1201 Thread Message Wall thread namespace
1202 Message Wall Greeting Pages used for content above message boxes on Message Walls
2000 Board Board namespace. Used for storing board descriptions
2001 Board Thread Forum threads

Messages

The script uses the following messages. Use the talkpage to provide missing translations.

Key Message Notes
lastEdited Last edited by $1 $2
  • where $1 is the name of the user who made the edit
  • where $2 is the amount of time that has passed since the last edit
diff diff Used as the link for opening the modal—(diff)
minor m
comment Edit summary
size Current size Current page size
created Created page. Used to replace the auto-generated summary when a new page is created
loading Loading details of last edit
changes Changes Used as Changes: pagename
link Link
undo Undo
cancel Cancel

These messages can be compiled to a single object with the language code (use the name if you're not sure):

                en: {
                    lastEdited: 'Last edited by $1 $2',
                    diff: 'diff',
                    minor: 'm',
                    comment: 'Edit summary',
                    size: 'Current size',
                    created: 'Created page.',
                    loading: 'Loading details of last edit',
                    changes: 'Changes',
                    link: 'Link',
                    undo: 'Undo',
                    cancel: 'Cancel'
                }

Todo

  • Handle errors if rollback fails

Updates

November 27th, 2016
Added a few requested features
October 14th, 2016
Script rewritten; added functionalities:
  • Minor edits are now marked
  • Change in size is indicated
  • Position of the details can be configured
  • More responsive modal
  • Edits can be rollbacked from the modal
July 9th, 2015
Added monobook support.
April 4th, 2015
Date and time merged together to give an approximate time since the last edit using timeago.
April 3rd, 2015
Added i18n support.
Redid namespace support; added options to include/exclude namespaces and exclude pages.
April 2nd, 2015
Re-added previously removed editor's avatar.
December 30th, 2014
Added editor's avatar, per request.
December 1st, 2014
Namespace support.
November 15th, 2014
Features updated.
October 8th, 2014
Initial release.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.