~ubuntu-branches/ubuntu/saucy/mediawiki-extensions/saucy

« back to all changes in this revision

Viewing changes to dist/mediawiki-extensions-base/usr/share/mediawiki-extensions/base/NewestPages/NewestPages.page.php

  • Committer: Bazaar Package Importer
  • Author(s): Romain Beauxis
  • Date: 2010-05-04 15:13:35 UTC
  • mfrom: (0.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100504151335-54qeucg3ec108q28
Tags: 2.2
* Added Replaces:/Conflicts: to allow a proper upgrade.
Closes: #580066
* Fixed package descriptions.
Closes: #579667
* Patched mediawiki-extensions-fckeditor to make it work with
  php 5.3. The fix may not be perfect but at least it work.
  Not closing the bug (#579822) for now..

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * Class definition file for the Newest Pages extension
 
5
 * This doesn't use recent changes so the items don't expire
 
6
 *
 
7
 * @addtogroup Extensions
 
8
 * @author Rob Church <robchur@gmail.com>
 
9
 * @copyright © 2006 Rob Church
 
10
 * @licence GNU General Public Licence 2.0
 
11
 */
 
12
 
 
13
class NewestPages extends IncludableSpecialPage {
 
14
 
 
15
        var $limit = NULL;
 
16
        var $namespace = NULL;
 
17
        var $redirects = NULL;
 
18
 
 
19
        public function __construct() {
 
20
                IncludableSpecialPage::SpecialPage( 'Newestpages', '', true, false, 'default', true );
 
21
        }
 
22
 
 
23
        public function execute( $par ) {
 
24
                global $wgRequest, $wgOut, $wgContLang;
 
25
 
 
26
                wfLoadExtensionMessages( 'NewestPages' );
 
27
 
 
28
                # Decipher input passed to the page
 
29
                $this->decipherParams( $par );
 
30
                $this->setOptions( $wgRequest );
 
31
 
 
32
                $dbr =& wfGetDB( DB_SLAVE );
 
33
                $page = $dbr->tableName( 'page' );
 
34
                $nsf = $this->getNsFragment();
 
35
                $redir = $this->redirects ? '' : ' AND page_is_redirect = 0';
 
36
                $res = $dbr->query( "SELECT page_namespace, page_title, page_is_redirect FROM $page WHERE {$nsf}{$redir} ORDER BY page_id DESC LIMIT 0,{$this->limit}" );
 
37
                $count = $dbr->numRows( $res );
 
38
 
 
39
                # Don't show the navigation if we're including the page
 
40
                if( !$this->mIncluding ) {
 
41
                        $this->setHeaders();
 
42
                        if( $this->namespace > 0 ) {
 
43
                                $wgOut->addWikiText( wfMsgExt( 'newestpages-ns-header', array( 'parsemag' ), $this->limit, $wgContLang->getFormattedNsText( $this->namespace ) ) );
 
44
                        } else {
 
45
                                $wgOut->addWikiText( wfMsgExt( 'newestpages-header', array( 'parsemag' ), $this->limit ) );
 
46
                        }
 
47
                        $wgOut->addHTML( $this->makeNamespaceForm() );
 
48
                        $wgOut->addHTML( '<p>' . $this->makeLimitLinks() );
 
49
                        $wgOut->addHTML( '<br />' . $this->makeRedirectToggle() . '</p>' );
 
50
                }
 
51
 
 
52
                if( $count > 0 ) {
 
53
                        # Make list
 
54
                        if( !$this->mIncluding )
 
55
                                $wgOut->addWikiText( wfMsgExt( 'newestpages-showing', array( 'parsemag' ), $count ) );
 
56
                        $wgOut->addHTML( "<ol>" );
 
57
                        while( $row = $dbr->fetchObject( $res ) )
 
58
                                $wgOut->addHTML( $this->makeListItem( $row ) );
 
59
                        $wgOut->addHTML( "</ol>" );
 
60
                } else {
 
61
                        $wgOut->addWikiText( wfMsg( 'newestpages-none' ) );
 
62
                }
 
63
                $dbr->freeResult( $res );
 
64
        }
 
65
 
 
66
        function setOptions( &$req ) {
 
67
                global $wgNewestPagesLimit;
 
68
                if( !isset( $this->limit ) )
 
69
                        $this->limit = $this->sanitiseLimit( $req->getInt( 'limit', $wgNewestPagesLimit ) );
 
70
                if( !isset( $this->namespace ) )
 
71
                        $this->namespace = $this->extractNamespace( $req->getVal( 'namespace', -1 ) );
 
72
                if( !isset( $this->redirects ) )
 
73
                        $this->redirects = (bool)$req->getInt( 'redirects', 1 );
 
74
        }
 
75
 
 
76
        function sanitiseLimit( $limit ) {
 
77
                return min( (int)$limit, 5000 );
 
78
        }
 
79
 
 
80
        function decipherParams( $par ) {
 
81
                if( $par ) {
 
82
                        $bits = explode( '/', $par );
 
83
                        foreach( $bits as $bit ) {
 
84
                                if( is_numeric( $bit ) ) {
 
85
                                        $this->limit = $this->sanitiseLimit( $bit );
 
86
                                } else {
 
87
                                        $this->namespace = $this->extractNamespace( $bit );
 
88
                                }
 
89
                        }
 
90
                }
 
91
        }
 
92
 
 
93
        function extractNamespace( $namespace ) {
 
94
                global $wgContLang;
 
95
                if( is_numeric( $namespace ) ) {
 
96
                        return $namespace;
 
97
                } elseif( $wgContLang->getNsIndex( $namespace ) !== false ) {
 
98
                        return $wgContLang->getNsIndex( $namespace );
 
99
                } elseif( $namespace == '-' ) {
 
100
                        return NS_MAIN;
 
101
                } else {
 
102
                        return -1;
 
103
                }
 
104
        }
 
105
 
 
106
        function getNsFragment() {
 
107
                $this->namespace = (int)$this->namespace;
 
108
                return $this->namespace > -1 ? "page_namespace = {$this->namespace}" : "page_namespace != 8";
 
109
        }
 
110
 
 
111
        function makeListItem( $row ) {
 
112
                global $wgUser;
 
113
                $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
 
114
                if( !is_null( $title ) ) {
 
115
                        $skin = $wgUser->getSkin();
 
116
                        $link = $row->page_is_redirect
 
117
                                        ? '<span class="allpagesredirect">' . $skin->makeKnownLinkObj( $title ) . '</span>'
 
118
                                        : $skin->makeKnownLinkObj( $title );
 
119
                        return( "<li>{$link}</li>\n" );
 
120
                } else {
 
121
                        return( "<!-- Invalid title " . htmlspecialchars( $row->page_title ) . " in namespace " . htmlspecialchars( $row->page_namespace ) . " -->\n" );
 
122
                }
 
123
        }
 
124
 
 
125
        function makeLimitLinks() {
 
126
                global $wgLang;
 
127
 
 
128
                $limits = array( 10, 20, 30, 50, 100, 150 );
 
129
                foreach( $limits as $limit ) {
 
130
                        if( $limit != $this->limit ) {
 
131
                                $links[] = $this->makeSelfLink( $limit, 'limit', $limit );
 
132
                        } else {
 
133
                                $links[] = (string)$limit;
 
134
                        }
 
135
                }
 
136
                return( wfMsgHtml( 'newestpages-limitlinks', $wgLang->pipeList( $links ) ) );
 
137
        }
 
138
 
 
139
        function makeRedirectToggle() {
 
140
                $label = wfMsgHtml( $this->redirects ? 'newestpages-hideredir' : 'newestpages-showredir' );
 
141
                return $this->makeSelfLink( $label, 'redirects', (int)!$this->redirects );
 
142
        }
 
143
 
 
144
        function makeSelfLink( $label, $oname = false, $oval = false ) {
 
145
                global $wgUser;
 
146
                $skin =& $wgUser->getSkin();
 
147
                $self = Title::makeTitle( NS_SPECIAL, $this->getName() );
 
148
                $attr['limit'] = $this->limit;
 
149
                $attr['namespace'] = $this->namespace;
 
150
                if( !$this->redirects )
 
151
                        $attr['redirects'] = 0;
 
152
                if( $oname )
 
153
                        $attr[$oname] = $oval;
 
154
                foreach( $attr as $aname => $aval )
 
155
                        $attribs[] = "{$aname}={$aval}";
 
156
                return $skin->makeKnownLinkObj( $self, $label, implode( '&', $attribs ) );
 
157
        }
 
158
 
 
159
        function makeNamespaceForm() {
 
160
                $self = Title::makeTitle( NS_SPECIAL, $this->getName() );
 
161
                $form  = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) );
 
162
                $form .= Xml::label( wfMsg( 'newestpages-namespace' ), 'namespace' ) . '&nbsp;';
 
163
                $form .= Xml::namespaceSelector( $this->namespace, 'all' );
 
164
                $form .= Xml::hidden( 'limit', $this->limit );
 
165
                $form .= Xml::hidden( 'redirects', $this->redirects );
 
166
                $form .= Xml::submitButton( wfMsg( 'newestpages-submit' ) ) . '</form>';
 
167
                return $form;
 
168
        }
 
169
}