+ Reply to Thread
Results 1 to 9 of 9

Thread: Customizing edit and preview pages

Share/Bookmark
  1. #1
    Member Burkhard is an unknown quantity at this point
    Join Date
    Mar 2010
    Location
    near Frankfurt, Germany.
    Posts
    66
    Rep Power
    1

    Default Customizing edit and preview pages

    Hi
    In my company intranet wiki, I want to display a wikitext-formatted template on all edit and preview pages (similar to the MediaWiki:Sitenotice but that displays on *all* pages). The message would be some editing guidance and help (with links) and should show below the page headline.

    What I found out myself:
    • I could use the "this is only a preview" message but that shows on preview pages only.
    • Wikipedia does similar things but differently on edit pages and preview pages. Didn't find out how they do it, anyway.
    • I conceived a complicated solution based on javascript and hijacking the "sitesub" message and "#sitesub" style sheet but didn't try it yet - hoping there's an easier way.
    Initially I thought this is a simple and straightforward idea but couldn't find a solution anywhere on Wikipedia nor Meta nor mediawiki.org nor throwing suitable keywords at Google.

    Is there a simple solution to this?

    Thanks in advance & greetings from Germany
    Burkhard

    Versions:
    Mediawiki 1.8.2 (can upgrade)
    PHP 5.1.6
    MySQL 5.0.24a
    Apache 2.2.3
    MS Windows Server 2003 SP2

  2. #2
    Site Owner hoggwild is a jewel in the rough hoggwild is a jewel in the rough hoggwild is a jewel in the rough hoggwild's Avatar
    Join Date
    Jan 2007
    Location
    Tennessee
    Posts
    1,788
    Rep Power
    7

    Default

    There is not currently a solution that is part of the MediaWiki core; however this can be done without the use of JavaScript by writing a simple extension that uses one of the hooks on the edit page to display this message.

    http://www.mediawiki.org/wiki/Manual...itForm:initial

    For a simple hook, you can structure something like this:

    PHP Code:
    $wgHooks['EditPage::showEditForm:initial'][] = 'fnEditInstructions';

    function 
    fnEditInstructions( &$editpage ) {
      
    $editpage->editFormPageTop .= '<div id="editInstructions">
            These instructions will be shown at the top of every edit page.
        </div>'
    ;
        return 
    true;

    The above extension function will position the text "These instructions will be shown at the top of every edit page." after the page title "Edit Page Name", but above the toolbar.

    You can use HTML to lay out any text assigned to $editPage->editFormPageTop; accompanying stylesheet instructions can be placed in MediaWiki:Common.css for formatting the instructions.

    If you want the instructions to vary based on namespace, simply build in logic to select different instructions based on the namespace id. You can also use other selection criteria, such as user groups, etc.
    Last edited by hoggwild; March 1st, 2010 at 15:10.
    User: Hoggwild/aka Lhridley (site owner and administrator)
    MediaWiki: the latest version (under development), PHP: 5.2.12, MySQL: 5.0.67, Apache ver 2.2.14, CentOS (Linux)
    Host: http://www.VPSNext.com
    Web application developer/programmer/php developer
    http://wiki.chattamac.org

    BEFORE POSTING QUESTIONS, PLEASE READ:
    http://www.mwusers.com/forums/conten...MW-Users-Forum

    The forums are for questions -- please don't submit questions via PM -- they will be ignored.

  3. #3
    Member Burkhard is an unknown quantity at this point
    Join Date
    Mar 2010
    Location
    near Frankfurt, Germany.
    Posts
    66
    Rep Power
    1

    Default

    wow that was fast .... thanks a lot
    Writing a "simple extension" will take me a while (new to PHP) but then, I came here to learn...

    In the meantine: Can I conclude that this piece of code would display its text no matter if I am writing a new page, editing an existing one, or after I click "preview"? Or are these different hooks?

    Thanks again!

  4. #4
    Site Owner hoggwild is a jewel in the rough hoggwild is a jewel in the rough hoggwild is a jewel in the rough hoggwild's Avatar
    Join Date
    Jan 2007
    Location
    Tennessee
    Posts
    1,788
    Rep Power
    7

    Default

    Yes, the example I gave you using that particular hook and assigning values to that particular variable will show the text regardless of whether you are creating a page, editing an existing page, or previewing a page after editing but before saving.
    User: Hoggwild/aka Lhridley (site owner and administrator)
    MediaWiki: the latest version (under development), PHP: 5.2.12, MySQL: 5.0.67, Apache ver 2.2.14, CentOS (Linux)
    Host: http://www.VPSNext.com
    Web application developer/programmer/php developer
    http://wiki.chattamac.org

    BEFORE POSTING QUESTIONS, PLEASE READ:
    http://www.mwusers.com/forums/conten...MW-Users-Forum

    The forums are for questions -- please don't submit questions via PM -- they will be ignored.

  5. #5
    Member Burkhard is an unknown quantity at this point
    Join Date
    Mar 2010
    Location
    near Frankfurt, Germany.
    Posts
    66
    Rep Power
    1

    Default

    Hi again
    My goal is to use a page from the wiki itself for this purpose, something similar to MediaWiki:sitenotice ... editable in the wiki itself, that is. Didn't want to post too trivial questions though so I wandered through the PHP sources to find how MW does that (copying tested code is easier than writing it).

    I came up with function wfMsgWikiHtml( $key ) from GlobalFunctions.php. The comment says "Return an HTML version of message" which seems to be just what I need in the suggested extension.

    So, assuming I create a page named editpagenotice in the MediaWiki namespace that contains all HTML and Wikitext formatting I need, I would then say...

    PHP Code:
    $wgHooks['EditPage::showEditForm:initial'][] = 'fnEditInstructions';

    function 
    fnEditInstructions( &$editpage ) {
      
    $editpage->editFormPageTop .= wfMsgWikiHtml('editpagenotice');
        return 
    true;

    ... and of course amend a "require_once(...)" in LocalSettings.php.

    My questions:
    • Is it safe to create a page in the MediaWiki namespace or will that be lost in an MW upgrade?
    • Can I call an MW core function just like that?
    • Is it safe to do that, considering an MW upgrade from our 1.8.2 to whatever will be the latest then?
    Thanks once more for your patience!

  6. #6
    Site Owner hoggwild is a jewel in the rough hoggwild is a jewel in the rough hoggwild is a jewel in the rough hoggwild's Avatar
    Join Date
    Jan 2007
    Location
    Tennessee
    Posts
    1,788
    Rep Power
    7

    Default

    Is it safe to create a page in the MediaWiki namespace or will that be lost in an MW upgrade
    It is safe. Pages created in the MediaWiki namespace are stored in the database and should persist after an upgrade.
    Can I call an MW core function just like that?
    yes, but a better one to look at may be wfMsg() instead.
    Is it safe to do that, considering an MW upgrade from our 1.8.2 to whatever will be the latest then?
    Yes, although your extension would have t be modified slightly to work once you upgrade. MediaWiki underwent a major change in the way it handles return values from hooks around version 1.13 or so; prior to that returning a value from hook extension was optional depending on the structure of the hook; how it is required.
    User: Hoggwild/aka Lhridley (site owner and administrator)
    MediaWiki: the latest version (under development), PHP: 5.2.12, MySQL: 5.0.67, Apache ver 2.2.14, CentOS (Linux)
    Host: http://www.VPSNext.com
    Web application developer/programmer/php developer
    http://wiki.chattamac.org

    BEFORE POSTING QUESTIONS, PLEASE READ:
    http://www.mwusers.com/forums/conten...MW-Users-Forum

    The forums are for questions -- please don't submit questions via PM -- they will be ignored.

  7. #7
    Member Burkhard is an unknown quantity at this point
    Join Date
    Mar 2010
    Location
    near Frankfurt, Germany.
    Posts
    66
    Rep Power
    1

    Default

    Hi again
    I created the mediawiki:editpagenotice page which is there and can be quoted using {{MediaWiki:Editpagenotice}}. I wrote the extension and added the require_once() in LocalSettings.php. Here's the script:
    PHP Code:
    <?php

    $wgExtensionCredits
    ['other'][] = array(
          
    'name' => 'EdipageInstructions',
          
    'author' =>'Burkhard'
          
    'url' => 'http://www.mwusers.com/forums/showthread.php?14326-Customizing-edit-and-preview-pages'
          
    'description' => 'Display MediaWiki:editpagenotice on top of every edit/preview page'
          
    );
     
    $wgHooks['EditPage::showEditForm:initial'][] = 'fnEditInstructions';

    function 
    fnEditInstructions( &$editpage ) {
    ##   $editpage->editFormPageTop .= wfMsgWikiHtml('editpagenotice');
           
    $editpage->editFormPageTop .= wfMsg('editpagenotice');
    ##   $editpage->editFormPageTop .= '<br>Test<br>';
           
    return true;
    }
    ?>
    Comments removed for brevity. In Special:Version, I can see the extension and the hook used but I don't see the output on any edit page. None of the three above versions seem to work (although I frequently invalidate the cache with ctrl-shift-r (Firefox 3.5.8) or even logout/login. Writing editpagenotice with a capital E didn't help either.

    What's wrong?

  8. #8
    Site Owner hoggwild is a jewel in the rough hoggwild is a jewel in the rough hoggwild is a jewel in the rough hoggwild's Avatar
    Join Date
    Jan 2007
    Location
    Tennessee
    Posts
    1,788
    Rep Power
    7

    Default

    I'm sorry. I mislead you earlier. The method I outlined for you wasn't available until MediaWiki version 1.12. To do this you will either need to modify the actual EditPage.php script of your installation, or you can upgraded to a more recent version that supports this capability easily through a simple extension.

    if you decide to upgrade, a better choice would be to use "editFormTextBeforeContent" instead of "editFormPageTop" to add your custom message.
    User: Hoggwild/aka Lhridley (site owner and administrator)
    MediaWiki: the latest version (under development), PHP: 5.2.12, MySQL: 5.0.67, Apache ver 2.2.14, CentOS (Linux)
    Host: http://www.VPSNext.com
    Web application developer/programmer/php developer
    http://wiki.chattamac.org

    BEFORE POSTING QUESTIONS, PLEASE READ:
    http://www.mwusers.com/forums/conten...MW-Users-Forum

    The forums are for questions -- please don't submit questions via PM -- they will be ignored.

  9. #9
    Member Burkhard is an unknown quantity at this point
    Join Date
    Mar 2010
    Location
    near Frankfurt, Germany.
    Posts
    66
    Rep Power
    1

    Default

    No problem. We are using an old version installed a few years ago, and like they say, don't fix it if it ain't broken.

    Encouraged by your last post, I traced the MW use of the 'missingcommenttext' and 'missingsummary' system messages because they appear where I want my custom message. I came up with a spot in EditPage.php and added one line:
    PHP Code:
    .
    .
    $wgOut->setPageTitle$s );
    ## One line added 05.03.2010 /Burkhard  ####################################
    $wgOut->addWikiTextwfMsg'editpagenotice' ) );
    if ( 
    $this->missingComment ) {
           
    $wgOut->addWikiTextwfMsg'missingcommenttext' ) );
    }
    .

    That does the job. Thanks for your support. You're quite a resourceful and patient ... well ... cat ;-))

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Replies: 1
    Last Post: January 20th, 2010, 15:29
  2. Customizing Edit Page / Text boxes
    By Olga Kasprzyk in forum MediaWiki Hacks
    Replies: 1
    Last Post: March 5th, 2008, 22:54
  3. IRC Bot, Add and Edit Pages
    By bugg_tb in forum Customizing MediaWiki
    Replies: 0
    Last Post: December 5th, 2007, 12:18
  4. Customizing the Blank Page Edit Screen
    By sakshale in forum Customizing MediaWiki
    Replies: 0
    Last Post: November 25th, 2007, 05:43
  5. Replies: 4
    Last Post: March 16th, 2006, 13:30

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts